2019-06-26 20:50:27 -04:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"git.sr.ht/~sircmpwn/aerc/widgets"
|
|
|
|
)
|
|
|
|
|
2019-06-27 10:33:11 -07:00
|
|
|
type NextPrevResult struct{}
|
|
|
|
|
2019-06-26 20:50:27 -04:00
|
|
|
func init() {
|
2019-06-27 10:33:11 -07:00
|
|
|
register(NextPrevResult{})
|
2019-06-26 20:50:27 -04:00
|
|
|
}
|
|
|
|
|
2019-09-03 16:34:03 -03:00
|
|
|
func (NextPrevResult) Aliases() []string {
|
2019-06-27 10:33:11 -07:00
|
|
|
return []string{"next-result", "prev-result"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 16:34:03 -03:00
|
|
|
func (NextPrevResult) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-06-27 10:33:11 -07:00
|
|
|
return nil
|
2019-06-26 20:50:27 -04:00
|
|
|
}
|
|
|
|
|
2019-09-03 16:34:03 -03:00
|
|
|
func (NextPrevResult) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-06-26 20:50:27 -04: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 20:13:13 +01:00
|
|
|
acct.Messages().Invalidate()
|
2019-06-26 20:50:27 -04:00
|
|
|
} else {
|
|
|
|
store := acct.Store()
|
|
|
|
if store != nil {
|
|
|
|
store.NextResult()
|
|
|
|
}
|
2020-06-09 20:13:13 +01:00
|
|
|
acct.Messages().Invalidate()
|
2019-06-26 20:50:27 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2019-06-27 10:33:11 -07:00
|
|
|
|
|
|
|
func nextPrevResultUsage(cmd string) error {
|
2019-09-03 16:34:04 -03:00
|
|
|
return fmt.Errorf("Usage: %s [<n>[%%]]", cmd)
|
2019-06-27 10:33:11 -07:00
|
|
|
}
|