Skip to content

Commit

Permalink
Ignore unused control characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Verseth committed Jul 1, 2023
1 parent c357357 commit eb43008
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 7 additions & 0 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"os"
"time"
"unicode"
"unicode/utf8"

"github.com/c-bata/go-prompt/internal/debug"
)
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit eb43008

Please sign in to comment.