From e780c6ee96ae086fc668aadcd61fb1777d1cbe43 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 15 Mar 2019 21:41:18 -0400 Subject: Implement :next-message n% --- commands/next-message.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'commands/next-message.go') diff --git a/commands/next-message.go b/commands/next-message.go index 86cd678..81725c0 100644 --- a/commands/next-message.go +++ b/commands/next-message.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "strconv" + "strings" "git.sr.ht/~sircmpwn/aerc2/widgets" ) @@ -14,7 +15,7 @@ func init() { } func nextPrevMessageUsage(cmd string) error { - return errors.New(fmt.Sprintf("Usage: %s [n]", cmd)) + return errors.New(fmt.Sprintf("Usage: %s [[%]]", cmd)) } func NextPrevMessage(aerc *widgets.Aerc, args []string) error { @@ -24,14 +25,22 @@ func NextPrevMessage(aerc *widgets.Aerc, args []string) error { 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 pct { + n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0)) + } for ; n > 0; n-- { if args[0] == "prev-message" { acct.Messages().Prev() -- cgit v1.2.3