mirror of https://github.com/chzyer/readline.git
fix bugs: reset buffer after trigger io.EOF/ErrInterrupt
This commit is contained in:
parent
7a18498f5b
commit
db2e5eae91
|
@ -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() {
|
||||
|
|
15
readline.go
15
readline.go
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue