Add OptionShowCompletionAtStart option

This commit is contained in:
rhysd 2018-10-18 19:41:40 +09:00
parent 407ba3c83c
commit c7e4448406
3 changed files with 17 additions and 0 deletions

View File

@ -36,6 +36,7 @@ type CompletionManager struct {
verticalScroll int
wordSeparator string
showAtStart bool
}
// GetSelectedSuggestion returns the selected item.

View File

@ -226,6 +226,14 @@ func OptionAddASCIICodeBind(b ...ASCIICodeBind) Option {
}
}
// OptionShowCompletionAtStart to set completion window is open at start.
func OptionShowCompletionAtStart() Option {
return func(p *Prompt) error {
p.completion.showAtStart = true
return nil
}
}
// New returns a Prompt with powerful auto-completion.
func New(executor Executor, completer Completer, opts ...Option) *Prompt {
defaultWriter := NewStdoutWriter()

View File

@ -51,6 +51,10 @@ func (p *Prompt) Run() {
p.setUp()
defer p.tearDown()
if p.completion.showAtStart {
p.completion.Update(*p.buf.Document())
}
p.renderer.Render(p.buf, p.completion)
bufCh := make(chan []byte, 128)
@ -232,6 +236,10 @@ func (p *Prompt) Input() string {
p.setUp()
defer p.tearDown()
if p.completion.showAtStart {
p.completion.Update(*p.buf.Document())
}
p.renderer.Render(p.buf, p.completion)
bufCh := make(chan []byte, 128)
stopReadBufCh := make(chan struct{})