aboutsummaryrefslogtreecommitdiff
path: root/aerc.go
diff options
context:
space:
mode:
authorGregory Mullen <greg@cmdline.org>2019-06-27 10:33:11 -0700
committerDrew DeVault <sir@cmpwn.com>2019-06-29 14:24:19 -0400
commit2a0961701c4cabecc53d134ed1782e5612e64580 (patch)
tree57952ac82fb7104113ca7fc0e25dc3d225f77ea7 /aerc.go
parent177651bddab145c8a56cdfeb0d57b5fd95a6d0e2 (diff)
Implement basic tab completion support
Tab completion currently only works on commands. Contextual completion will be added in the future.
Diffstat (limited to 'aerc.go')
-rw-r--r--aerc.go60
1 files changed, 40 insertions, 20 deletions
diff --git a/aerc.go b/aerc.go
index 20e2bb1..a248e18 100644
--- a/aerc.go
+++ b/aerc.go
@@ -51,6 +51,41 @@ func getCommands(selected libui.Drawable) []*commands.Commands {
}
}
+func execCommand(aerc *widgets.Aerc, ui *libui.UI, cmd string) error {
+ cmds := getCommands((*aerc).SelectedTab())
+ for i, set := range cmds {
+ err := set.ExecuteCommand(aerc, cmd)
+ if _, ok := err.(commands.NoSuchCommand); ok {
+ if i == len(cmds)-1 {
+ return err
+ }
+ continue
+ } else if _, ok := err.(commands.ErrorExit); ok {
+ ui.Exit()
+ return nil
+ } else if err != nil {
+ return err
+ } else {
+ break
+ }
+ }
+ return nil
+}
+
+func getCompletions(aerc *widgets.Aerc, cmd string) []string {
+ cmds := getCommands((*aerc).SelectedTab())
+ completions := make([]string, 0)
+ for _, set := range cmds {
+ opts := set.GetCompletions(aerc, cmd)
+ if len(opts) > 0 {
+ for _, opt := range opts {
+ completions = append(completions, opt)
+ }
+ }
+ }
+ return completions
+}
+
var (
Prefix string
ShareDir string
@@ -96,27 +131,12 @@ func main() {
aerc *widgets.Aerc
ui *libui.UI
)
+
aerc = widgets.NewAerc(conf, logger, func(cmd string) error {
- cmds := getCommands(aerc.SelectedTab())
- for i, set := range cmds {
- err := set.ExecuteCommand(aerc, cmd)
- if _, ok := err.(commands.NoSuchCommand); ok {
- if i == len(cmds)-1 {
- return err
- } else {
- continue
- }
- } else if _, ok := err.(commands.ErrorExit); ok {
- ui.Exit()
- return nil
- } else if err != nil {
- return err
- } else {
- break
- }
- }
- return nil
- })
+ return execCommand(aerc, ui, cmd)
+ }, func(cmd string) []string {
+ return getCompletions(aerc, cmd)
+ })
ui, err = libui.Initialize(conf, aerc)
if err != nil {