From 7160f98a9081bcab05904484eae790ec0a006b87 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Fri, 20 Dec 2019 13:21:33 -0500 Subject: Show textinput completions in popovers Rather than showing completions inline in the text input, show them in a popover which can be scrolled by repeatedly pressing the tab key. The selected completion can be executed by pressing enter. --- widgets/aerc.go | 4 ++-- widgets/exline.go | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'widgets') diff --git a/widgets/aerc.go b/widgets/aerc.go index 9d955e1..da3f56f 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -372,7 +372,7 @@ func (aerc *Aerc) focus(item ui.Interactive) { func (aerc *Aerc) BeginExCommand(cmd string) { previous := aerc.focused - exline := NewExLine(cmd, func(cmd string) { + exline := NewExLine(aerc.conf, cmd, func(cmd string) { parts, err := shlex.Split(cmd) if err != nil { aerc.PushStatus(" "+err.Error(), 10*time.Second). @@ -399,7 +399,7 @@ func (aerc *Aerc) BeginExCommand(cmd string) { } func (aerc *Aerc) RegisterPrompt(prompt string, cmd []string) { - p := NewPrompt(prompt, func(text string) { + p := NewPrompt(aerc.conf, prompt, func(text string) { if text != "" { cmd = append(cmd, text) } diff --git a/widgets/exline.go b/widgets/exline.go index f2c7249..6def938 100644 --- a/widgets/exline.go +++ b/widgets/exline.go @@ -3,6 +3,7 @@ package widgets import ( "github.com/gdamore/tcell" + "git.sr.ht/~sircmpwn/aerc/config" "git.sr.ht/~sircmpwn/aerc/lib" "git.sr.ht/~sircmpwn/aerc/lib/ui" ) @@ -16,11 +17,14 @@ type ExLine struct { input *ui.TextInput } -func NewExLine(cmd string, commit func(cmd string), finish func(), +func NewExLine(conf *config.AercConfig, cmd string, commit func(cmd string), finish func(), tabcomplete func(cmd string) []string, cmdHistory lib.History) *ExLine { - input := ui.NewTextInput("").Prompt(":").TabComplete(tabcomplete).Set(cmd) + input := ui.NewTextInput("").Prompt(":").Set(cmd) + if conf.Ui.CompletionPopovers { + input.TabComplete(tabcomplete, conf.Ui.CompletionDelay) + } exline := &ExLine{ commit: commit, finish: finish, @@ -34,10 +38,13 @@ func NewExLine(cmd string, commit func(cmd string), finish func(), return exline } -func NewPrompt(prompt string, commit func(text string), +func NewPrompt(conf *config.AercConfig, prompt string, commit func(text string), tabcomplete func(cmd string) []string) *ExLine { - input := ui.NewTextInput("").Prompt(prompt).TabComplete(tabcomplete) + input := ui.NewTextInput("").Prompt(prompt) + if conf.Ui.CompletionPopovers { + input.TabComplete(tabcomplete, conf.Ui.CompletionDelay) + } exline := &ExLine{ commit: commit, tabcomplete: tabcomplete, -- cgit v1.2.3