summary refs log tree commit diff stats
path: root/commands/account/next-message.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 /commands/account/next-message.go
parentfe79a9a5879936a7f5b16cc6a8be1d93ec1bfae7 (diff)
downloadaerc-8126d82956636a2525263e2d0d985d721fdb8074.tar.gz
Add context-specific commands
Diffstat (limited to 'commands/account/next-message.go')
-rw-r--r--commands/account/next-message.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/commands/account/next-message.go b/commands/account/next-message.go
new file mode 100644
index 0000000..d2c006f
--- /dev/null
+++ b/commands/account/next-message.go
@@ -0,0 +1,55 @@
+package account
+
+import (
+	"errors"
+	"fmt"
+	"strconv"
+	"strings"
+
+	"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
+		pct bool
+	)
+	if len(args) > 1 {
+		if strings.HasSuffix(args[1], "%") {
+			pct = true
+			args[1] = args[1][:len(args[1])-1]
+		}
+		n, err = strconv.Atoi(args[1])
+		if err != nil {
+			return nextPrevMessageUsage(args[0])
+		}
+	}
+	acct := aerc.SelectedAccount()
+	if acct == nil {
+		return errors.New("No account selected")
+	}
+	if pct {
+		n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0))
+	}
+	for ; n > 0; n-- {
+		if args[0] == "prev-message" {
+			acct.Messages().Prev()
+		} else {
+			acct.Messages().Next()
+		}
+	}
+	return nil
+}
om> 2010-12-22 03:16:12 +0100 committer hut <hut@lavabit.com> 2010-12-22 03:16:12 +0100 updated doc/colorschemes.txt' href='/akspecs/ranger/commit/doc/colorschemes.txt?h=v1.9.2&id=f597489c7f5093c0df6c5bbddcc48bf5b1a8a35c'>f597489c ^
efdc7b16 ^
29b05d00 ^


efdc7b16 ^
f597489c ^


efdc7b16 ^

a8f9cf2c ^

efdc7b16 ^






f597489c ^
efdc7b16 ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92