summary refs log tree commit diff stats
path: root/aerc.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-21 16:30:23 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-21 16:30:23 -0400
commit8126d82956636a2525263e2d0d985d721fdb8074 (patch)
tree2c5f5c2e2fb2e5ecfb4c12eb8ef6bc575edc39f8 /aerc.go
parentfe79a9a5879936a7f5b16cc6a8be1d93ec1bfae7 (diff)
downloadaerc-8126d82956636a2525263e2d0d985d721fdb8074.tar.gz
Add context-specific commands
Diffstat (limited to 'aerc.go')
-rw-r--r--aerc.go36
1 files changed, 31 insertions, 5 deletions
diff --git a/aerc.go b/aerc.go
index 0da80e9..d086f85 100644
--- a/aerc.go
+++ b/aerc.go
@@ -11,10 +11,23 @@ import (
 
 	"git.sr.ht/~sircmpwn/aerc2/config"
 	"git.sr.ht/~sircmpwn/aerc2/commands"
+	"git.sr.ht/~sircmpwn/aerc2/commands/account"
 	libui "git.sr.ht/~sircmpwn/aerc2/lib/ui"
 	"git.sr.ht/~sircmpwn/aerc2/widgets"
 )
 
+func getCommands(selected libui.Drawable) []*commands.Commands {
+	switch selected.(type) {
+	case *widgets.AccountView:
+		return []*commands.Commands{
+			commands.GlobalCommands,
+			account.AccountCommands,
+		}
+	default:
+		return []*commands.Commands{commands.GlobalCommands}
+	}
+}
+
 func main() {
 	var (
 		logOut io.Writer
@@ -38,12 +51,25 @@ func main() {
 		ui   *libui.UI
 	)
 	aerc = widgets.NewAerc(conf, logger, func(cmd string) error {
-		err = commands.ExecuteCommand(aerc, cmd)
-		if _, ok := err.(commands.ErrorExit); ok {
-			ui.Exit = true
-			return nil
+		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 = true
+				return nil
+			} else if err != nil {
+				return err
+			} else {
+				break
+			}
 		}
-		return err
+		return nil
 	})
 
 	ui, err = libui.Initialize(conf, aerc)