Merge pull request #141 from VonC/arrow

Down Arrow for first completion
This commit is contained in:
Masashi SHIBATA 2020-02-20 16:53:46 +09:00 committed by GitHub
commit b662637d18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -206,6 +206,14 @@ func OptionSwitchKeyBindMode(m KeyBindMode) Option {
}
}
// OptionCompletionOnDown allows for Down arrow key to trigger completion.
func OptionCompletionOnDown() Option {
return func(p *Prompt) error {
p.completionOnDown = true
return nil
}
}
// SwitchKeyBindMode to set a key bind mode.
// Deprecated: Please use OptionSwitchKeyBindMode.
var SwitchKeyBindMode = OptionSwitchKeyBindMode

View File

@ -25,6 +25,7 @@ type Prompt struct {
keyBindings []KeyBind
ASCIICodeBindings []ASCIICodeBind
keyBindMode KeyBindMode
completionOnDown bool
}
// Exec is the struct contains user input context.
@ -148,7 +149,7 @@ func (p *Prompt) feed(b []byte) (shouldExit bool, exec *Exec) {
func (p *Prompt) handleCompletionKeyBinding(key Key, completing bool) {
switch key {
case Down:
if completing {
if completing || p.completionOnDown {
p.completion.Next()
}
case Tab, ControlI: