2019-07-17 09:35:50 +02:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2022-02-22 20:10:54 +01:00
|
|
|
|
2022-03-18 22:35:33 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/lib/statusline"
|
2021-11-05 10:19:46 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
2022-04-16 00:22:20 +02:00
|
|
|
"git.sr.ht/~sircmpwn/getopt"
|
2019-07-17 09:35:50 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Clear struct{}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
register(Clear{})
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (Clear) Aliases() []string {
|
2019-07-17 09:35:50 +02:00
|
|
|
return []string{"clear"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (Clear) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-07-17 09:35:50 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (Clear) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-07-17 09:35:50 +02:00
|
|
|
acct := aerc.SelectedAccount()
|
|
|
|
if acct == nil {
|
|
|
|
return errors.New("No account selected")
|
|
|
|
}
|
|
|
|
store := acct.Store()
|
|
|
|
if store == nil {
|
|
|
|
return errors.New("Cannot perform action. Messages still loading")
|
|
|
|
}
|
2022-04-16 00:22:20 +02:00
|
|
|
|
|
|
|
clearSelected := false
|
|
|
|
opts, optind, err := getopt.Getopts(args, "s")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
2022-07-31 14:32:48 +02:00
|
|
|
if opt.Option == 's' {
|
2022-04-16 00:22:20 +02:00
|
|
|
clearSelected = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(args) != optind {
|
|
|
|
return errors.New("Usage: clear [-s]")
|
|
|
|
}
|
|
|
|
|
|
|
|
if clearSelected {
|
|
|
|
defer store.Select(0)
|
|
|
|
}
|
2019-07-17 09:35:50 +02:00
|
|
|
store.ApplyClear()
|
2022-03-18 22:35:33 +01:00
|
|
|
acct.SetStatus(statusline.SearchFilterClear())
|
|
|
|
|
2019-07-17 09:35:50 +02:00
|
|
|
return nil
|
|
|
|
}
|