2019-06-27 02:50:27 +02:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
2022-10-07 18:00:31 +02:00
|
|
|
"git.sr.ht/~rjarry/aerc/lib/ui"
|
2021-11-05 10:19:46 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
2019-06-27 02:50:27 +02:00
|
|
|
)
|
|
|
|
|
2019-06-27 19:33:11 +02:00
|
|
|
type NextPrevResult struct{}
|
|
|
|
|
2019-06-27 02:50:27 +02:00
|
|
|
func init() {
|
2019-06-27 19:33:11 +02:00
|
|
|
register(NextPrevResult{})
|
2019-06-27 02:50:27 +02:00
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (NextPrevResult) Aliases() []string {
|
2019-06-27 19:33:11 +02:00
|
|
|
return []string{"next-result", "prev-result"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (NextPrevResult) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-06-27 19:33:11 +02:00
|
|
|
return nil
|
2019-06-27 02:50:27 +02:00
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (NextPrevResult) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-06-27 02:50:27 +02:00
|
|
|
if len(args) > 1 {
|
|
|
|
return nextPrevResultUsage(args[0])
|
|
|
|
}
|
|
|
|
acct := aerc.SelectedAccount()
|
|
|
|
if acct == nil {
|
|
|
|
return errors.New("No account selected")
|
|
|
|
}
|
|
|
|
if args[0] == "prev-result" {
|
|
|
|
store := acct.Store()
|
|
|
|
if store != nil {
|
|
|
|
store.PrevResult()
|
|
|
|
}
|
2022-10-07 18:00:31 +02:00
|
|
|
ui.Invalidate()
|
2019-06-27 02:50:27 +02:00
|
|
|
} else {
|
|
|
|
store := acct.Store()
|
|
|
|
if store != nil {
|
|
|
|
store.NextResult()
|
|
|
|
}
|
2022-10-07 18:00:31 +02:00
|
|
|
ui.Invalidate()
|
2019-06-27 02:50:27 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-06-27 19:33:11 +02:00
|
|
|
|
|
|
|
func nextPrevResultUsage(cmd string) error {
|
2019-09-03 21:34:04 +02:00
|
|
|
return fmt.Errorf("Usage: %s [<n>[%%]]", cmd)
|
2019-06-27 19:33:11 +02:00
|
|
|
}
|