go-prompt icon indicating copy to clipboard operation
go-prompt copied to clipboard

[Bug] go-prompt panics when both OptionCompletionOnDown() and OptionHistory() are used.

Open karimra opened this issue 3 years ago • 0 comments

Bug reports

There seems to be a clash between the OptionCompletionOnDown() and OptionHistory() options. When there are both a command completion suggestion as well as a next command in the history, go-prompt panics

Expected Behavior

Does not panic, a suggestion priority should be defined between history and command completion.

Current Behavior and Steps to Reproduce

  • Both OptionCompletionOnDown() and OptionHistory() are used
  • Browse the history (with arrow up) to a command that pops a suggestion box
  • Press arrow down

gnmic> versionpanic: runtime error: index out of range [0] with length 0

goroutine 1 [running]: github.com/c-bata/go-prompt.(*CompletionManager).GetSelectedSuggestion(0xc00021f450, 0xc00009ab40, 0xc00021f450, 0xe, 0x1a9794a, 0xc0001b4800) /Users/karim/go/pkg/mod/github.com/c-bata/[email protected]/completion.go:51 +0x108 github.com/c-bata/go-prompt.(*Render).Render(0xc0003fab60, 0xc00009ab40, 0xc00021f450) /Users/karim/go/pkg/mod/github.com/c-bata/[email protected]/render.go:207 +0x3bb github.com/c-bata/go-prompt.(*Prompt).Run(0xc0002bc6c0) /Users/karim/go/pkg/mod/github.com/c-bata/[email protected]/prompt.go:100 +0x731 github.com/karimra/gnmic/cmd.cmdPrompt.Run(0x24ea400, 0xc0003dbae0, 0x14, 0x14) /Users/karim/Documents/github.com/karimra/gnmic/cmd/prompt.go:425 +0xf4 github.com/karimra/gnmic/cmd.ExecutePrompt() /Users/karim/Documents/github.com/karimra/gnmic/cmd/prompt.go:392 +0x539 github.com/karimra/gnmic/cmd.Execute() /Users/karim/Documents/github.com/karimra/gnmic/cmd/root.go:143 +0x4d main.main() /Users/karim/Documents/github.com/karimra/gnmic/main.go:29 +0x3a exit status 2

Context

  • Operating System: Centos7 and MacOS10.15.6
  • Terminal Emulator: xterm and iTerm2
  • tag of go-prompt or commit revision: v0.2.5

karimra avatar Oct 19 '20 09:10 karimra