diff options
author | Jelle Besseling <jelle@pingiun.com> | 2019-08-04 16:09:48 +0200 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-08-07 15:10:24 +0900 |
commit | 507c90537c66289633af4b26abddcfd50a2a29d0 (patch) | |
tree | 10ac19bd89b0911ade88c6999d3c37544e6058a3 /commands/account | |
parent | 3650b72ca64b9fb6a7e7b058ad6ef67894c2866d (diff) | |
download | aerc-507c90537c66289633af4b26abddcfd50a2a29d0.tar.gz |
Implement next-message in msgview using account
This makes sure that the next-message command accepts the same arguments in the account view and the msgview
Diffstat (limited to 'commands/account')
-rw-r--r-- | commands/account/next.go | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/commands/account/next.go b/commands/account/next.go index f306b48..7b1f230 100644 --- a/commands/account/next.go +++ b/commands/account/next.go @@ -24,8 +24,20 @@ func (_ NextPrevMsg) Complete(aerc *widgets.Aerc, args []string) []string { } func (_ NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error { + var err, n, pct = ParseNextPrevMessage(args) + if err != nil { + return err + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + return ExecuteNextPrevMessage(args, acct, pct, n) +} + +func ParseNextPrevMessage(args []string) (error, int, bool) { if len(args) > 2 { - return nextPrevMessageUsage(args[0]) + return nextPrevMessageUsage(args[0]), 0, false } var ( n int = 1 @@ -39,30 +51,28 @@ func (_ NextPrevMsg) Execute(aerc *widgets.Aerc, args []string) error { } n, err = strconv.Atoi(args[1]) if err != nil { - return nextPrevMessageUsage(args[0]) + return nextPrevMessageUsage(args[0]), 0, false } } - acct := aerc.SelectedAccount() - if acct == nil { - return errors.New("No account selected") - } + return nil, n, pct +} + +func ExecuteNextPrevMessage(args []string, acct *widgets.AccountView, pct bool, n int) error { if pct { n = int(float64(acct.Messages().Height()) * (float64(n) / 100.0)) } - for ; n > 0; n-- { - if args[0] == "prev-message" || args[0] == "prev" { - store := acct.Store() - if store != nil { - store.Prev() - } - acct.Messages().Scroll() - } else { - store := acct.Store() - if store != nil { - store.Next() - } - acct.Messages().Scroll() + if args[0] == "prev-message" || args[0] == "prev" { + store := acct.Store() + if store != nil { + store.NextPrev(-n) + } + acct.Messages().Scroll() + } else { + store := acct.Store() + if store != nil { + store.NextPrev(n) } + acct.Messages().Scroll() } return nil } |