Skip to content

Commit

Permalink
Add OptionShowCompletionAtStart option
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 18, 2018
1 parent 09daf6a commit dab0b55
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type CompletionManager struct {

verticalScroll int
wordSeparator string
showAtStart bool
}

// GetSelectedSuggestion returns the selected item.
Expand Down
9 changes: 9 additions & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ func OptionAddASCIICodeBind(b ...ASCIICodeBind) Option {
}
}

// OptionShowCompletionAtStart to set whether completion window is open at start or not.
// This option only affects Prompt.Input().
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 {
pt := &Prompt{
Expand Down
3 changes: 3 additions & 0 deletions prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ 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{})
Expand Down

0 comments on commit dab0b55

Please sign in to comment.