aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-05-10 23:56:23 +0200
committerRobin Jarry <robin@jarry.cc>2023-05-16 13:39:17 +0200
commit5c9d22bb84eb8a6ddd4477bae3c081964d6e7b51 (patch)
tree263083c1f55d60d55d2b005d6504c64393432186 /main.go
parentcd68adc4630ed834eeac33f09ef58891c18c2dee (diff)
downloadaerc-5c9d22bb84eb8a6ddd4477bae3c081964d6e7b51.tar.gz
aerc-5c9d22bb84eb8a6ddd4477bae3c081964d6e7b51.zip
commands: add OptionsProvider and OptionCompleter
Improve command completion by supporting option flags and option arguments completion. Option completion is activated when the command implements the OptionsProvider interface. Implementing the OptionCompleter allows the completion of individual option arguments. The completion interfaces harmonizes the completion behavior in aerc, makes the completion code clearer and simplifies the completion functionality. With this patch, the Complete method on commands will only have to deal with the actual completion, i.e. paths, folders, etc and not worry about options. To remove all options and its mandatory arguments from args, use commands.Operands(). Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'main.go')
-rw-r--r--main.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/main.go b/main.go
index 99557d2b..9dd166fe 100644
--- a/main.go
+++ b/main.go
@@ -88,13 +88,18 @@ func execCommand(
return nil
}
-func getCompletions(aerc *widgets.Aerc, cmd string) []string {
+func getCompletions(aerc *widgets.Aerc, cmd string) ([]string, string) {
var completions []string
+ var prefix string
for _, set := range getCommands(aerc.SelectedTabContent()) {
- completions = append(completions, set.GetCompletions(aerc, cmd)...)
+ options, s := set.GetCompletions(aerc, cmd)
+ if s != "" {
+ prefix = s
+ }
+ completions = append(completions, options...)
}
sort.Strings(completions)
- return completions
+ return completions, prefix
}
// set at build time
@@ -198,7 +203,7 @@ func main() {
msg *models.MessageInfo,
) error {
return execCommand(aerc, ui, cmd, acct, msg)
- }, func(cmd string) []string {
+ }, func(cmd string) ([]string, string) {
return getCompletions(aerc, cmd)
}, &commands.CmdHistory, deferLoop)