example: change (Ctrl+C), (Ctrl+D) to shell-like

This commit is contained in:
Cheney 2015-11-20 11:26:58 +08:00
parent db2e5eae91
commit 5660cc8cb6
1 changed files with 6 additions and 4 deletions

View File

@ -46,9 +46,11 @@ var completer = readline.NewPrefixCompleter(
func main() { func main() {
l, err := readline.NewEx(&readline.Config{ l, err := readline.NewEx(&readline.Config{
Prompt: "\033[31m»\033[0m ", Prompt: "\033[31m»\033[0m ",
HistoryFile: "/tmp/readline.tmp", HistoryFile: "/tmp/readline.tmp",
AutoComplete: completer, AutoComplete: completer,
InterruptPrompt: "\nInterrupt",
EOFPrompt: "exit",
}) })
if err != nil { if err != nil {
panic(err) panic(err)
@ -58,7 +60,7 @@ func main() {
log.SetOutput(l.Stderr()) log.SetOutput(l.Stderr())
for { for {
line, err := l.Readline() line, err := l.Readline()
if err != nil { if err == io.EOF {
break break
} }
line = strings.TrimSpace(line) line = strings.TrimSpace(line)