diff --git a/completion.go b/completion.go index 0405b90d..0ae50f21 100644 --- a/completion.go +++ b/completion.go @@ -42,15 +42,14 @@ type CompletionManager struct { // GetSelectedSuggestion returns the selected item. func (c *CompletionManager) GetSelectedSuggestion() (s Suggest, ok bool) { - if c.selected == -1 { + if c.selected == -1 || c.selected >= len(c.tmp) { return Suggest{}, false } else if c.selected < -1 { debug.Assert(false, "must not reach here") c.selected = -1 return Suggest{}, false - } else if c.selected >= len(c.tmp) { - return Suggest{}, false } + return c.tmp[c.selected], true } diff --git a/prompt.go b/prompt.go index 3c9c4460..5427917d 100644 --- a/prompt.go +++ b/prompt.go @@ -4,6 +4,8 @@ import ( "bytes" "os" "time" + "unicode" + "unicode/utf8" "github.com/c-bata/go-prompt/internal/debug" ) @@ -157,6 +159,11 @@ func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) { if p.handleASCIICodeBinding(b) { return } + char, _ := utf8.DecodeRune(b) + if unicode.IsControl(char) { + return + } + p.buf.InsertText(string(b), false, true) }