summary refs log tree commit diff stats
path: root/commands
diff options
context:
space:
mode:
Diffstat (limited to 'commands')
-rw-r--r--commands/commands.go28
-rw-r--r--commands/next-folder.go15
-rw-r--r--commands/prev-folder.go15
3 files changed, 58 insertions, 0 deletions
diff --git a/commands/commands.go b/commands/commands.go
new file mode 100644
index 0000000..71dabe4
--- /dev/null
+++ b/commands/commands.go
@@ -0,0 +1,28 @@
+package commands
+
+import (
+	"errors"
+
+	"git.sr.ht/~sircmpwn/aerc2/widgets"
+)
+
+type AercCommand func(aerc *widgets.Aerc, cmd string) error
+
+var (
+	commands map[string]AercCommand
+)
+
+func init() {
+	commands = make(map[string]AercCommand)
+}
+
+func Register(name string, cmd AercCommand) {
+	commands[name] = cmd
+}
+
+func ExecuteCommand(aerc *widgets.Aerc, cmd string) error {
+	if fn, ok := commands[cmd]; ok {
+		return fn(aerc, cmd)
+	}
+	return errors.New("Unknown command " + cmd)
+}
diff --git a/commands/next-folder.go b/commands/next-folder.go
new file mode 100644
index 0000000..02975e1
--- /dev/null
+++ b/commands/next-folder.go
@@ -0,0 +1,15 @@
+package commands
+
+import (
+	"git.sr.ht/~sircmpwn/aerc2/widgets"
+)
+
+func init() {
+	Register("next-folder", NextFolder)
+}
+
+func NextFolder(aerc *widgets.Aerc, cmd string) error {
+	acct := aerc.SelectedAccount()
+	acct.Directories().Next()
+	return nil
+}
diff --git a/commands/prev-folder.go b/commands/prev-folder.go
new file mode 100644
index 0000000..a38214f
--- /dev/null
+++ b/commands/prev-folder.go
@@ -0,0 +1,15 @@
+package commands
+
+import (
+	"git.sr.ht/~sircmpwn/aerc2/widgets"
+)
+
+func init() {
+	Register("prev-folder", PrevFolder)
+}
+
+func PrevFolder(aerc *widgets.Aerc, cmd string) error {
+	acct := aerc.SelectedAccount()
+	acct.Directories().Prev()
+	return nil
+}