summary refs log tree commit diff stats
path: root/commands/next-message.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-14 23:41:25 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-14 23:41:25 -0400
commit24daef89e0fc6056c3ff7b94880ed12b4ec3eaa6 (patch)
tree82bffc5ee8ec795d07833734929907db0f659f85 /commands/next-message.go
parent4c8feb9aa54ddb162558482905c4723e2743e657 (diff)
downloadaerc-24daef89e0fc6056c3ff7b94880ed12b4ec3eaa6.tar.gz
Implement :{next,prev}-message
Diffstat (limited to 'commands/next-message.go')
-rw-r--r--commands/next-message.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/commands/next-message.go b/commands/next-message.go
new file mode 100644
index 0000000..86cd678
--- /dev/null
+++ b/commands/next-message.go
@@ -0,0 +1,43 @@
+package commands
+
+import (
+	"errors"
+	"fmt"
+	"strconv"
+
+	"git.sr.ht/~sircmpwn/aerc2/widgets"
+)
+
+func init() {
+	Register("next-message", NextPrevMessage)
+	Register("prev-message", NextPrevMessage)
+}
+
+func nextPrevMessageUsage(cmd string) error {
+	return errors.New(fmt.Sprintf("Usage: %s [n]", cmd))
+}
+
+func NextPrevMessage(aerc *widgets.Aerc, args []string) error {
+	if len(args) > 2 {
+		return nextPrevMessageUsage(args[0])
+	}
+	var (
+		n   int = 1
+		err error
+	)
+	if len(args) > 1 {
+		n, err = strconv.Atoi(args[1])
+		if err != nil {
+			return nextPrevMessageUsage(args[0])
+		}
+	}
+	acct := aerc.SelectedAccount()
+	for ; n > 0; n-- {
+		if args[0] == "prev-message" {
+			acct.Messages().Prev()
+		} else {
+			acct.Messages().Next()
+		}
+	}
+	return nil
+}