2019-06-27 02:50:27 +02:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/widgets"
|
|
|
|
)
|
|
|
|
|
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()
|
|
|
|
}
|
2020-06-09 21:13:13 +02:00
|
|
|
acct.Messages().Invalidate()
|
2019-06-27 02:50:27 +02:00
|
|
|
} else {
|
|
|
|
store := acct.Store()
|
|
|
|
if store != nil {
|
|
|
|
store.NextResult()
|
|
|
|
}
|
2020-06-09 21:13:13 +02:00
|
|
|
acct.Messages().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
|
|
|
}
|