fix bugs: reset buffer after trigger io.EOF/ErrInterrupt

This commit is contained in:
Cheney 2015-11-20 11:25:30 +08:00
parent 7a18498f5b
commit db2e5eae91
2 changed files with 19 additions and 2 deletions

View File

@ -203,7 +203,8 @@ func (o *Operation) ioloop() {
}
// treat as EOF
o.buf.WriteString("^D\n")
o.buf.WriteString(o.cfg.EOFPrompt + "\n")
o.buf.Reset()
o.errchan <- io.EOF
case CharInterrupt:
if o.IsSearchMode() {
@ -219,7 +220,8 @@ func (o *Operation) ioloop() {
}
o.buf.MoveToLineEnd()
o.buf.Refresh(nil)
o.buf.WriteString("^C\n")
o.buf.WriteString(o.cfg.InterruptPrompt + "\n")
o.buf.Reset()
o.errchan <- ErrInterrupt
default:
if o.IsSearchMode() {

View File

@ -23,6 +23,9 @@ type Config struct {
// If VimMode is true, readline will in vim.insert mode by default
VimMode bool
InterruptPrompt string
EOFPrompt string
Stdout io.Writer
Stderr io.Writer
@ -43,6 +46,18 @@ func (c *Config) Init() error {
if c.HistoryLimit <= 0 {
c.HistoryLimit = 500
}
if c.InterruptPrompt == "" {
c.InterruptPrompt = "^C"
} else if c.InterruptPrompt == "\n" {
c.InterruptPrompt = ""
}
if c.EOFPrompt == "" {
c.EOFPrompt = "^D"
} else if c.EOFPrompt == "\n" {
c.EOFPrompt = ""
}
return nil
}