Add tab completion to textinputs

This adds tab completion to textinput components. They can be configured
with a completion function. This function is called when the user
presses <tab>. The first completion is initially shown to the user
inserted into the text. Repeated presses of <tab> or <backtab> cycle
through the completions list. The completions list is invalidated when
any other non-tab-like key is pressed.

Also changed is some logic for current completion generation so that
all available commands are returned when <tab> is pressed with no
current text and similarly for arguments of commands.
This commit is contained in:
Jeffas 2019-07-26 14:29:40 +01:00 committed by Drew DeVault
parent aabe3d9b3a
commit cded067bc3
4 changed files with 92 additions and 20 deletions
commands

View file

@ -19,6 +19,9 @@ func (_ ChangeTab) Aliases() []string {
}
func (_ ChangeTab) Complete(aerc *widgets.Aerc, args []string) []string {
if len(args) == 0 {
return aerc.TabNames()
}
out := make([]string, 0)
for _, tab := range aerc.TabNames() {
if strings.HasPrefix(tab, args[0]) {