2019-07-17 07:35:50 +00:00
|
|
|
package account
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2022-02-22 19:10:54 +00:00
|
|
|
|
2022-03-18 21:35:33 +00:00
|
|
|
"git.sr.ht/~rjarry/aerc/lib/statusline"
|
2021-11-05 09:19:46 +00:00
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
2022-04-15 22:22:20 +00:00
|
|
|
"git.sr.ht/~sircmpwn/getopt"
|
2019-07-17 07:35:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Clear struct{}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
register(Clear{})
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (Clear) Aliases() []string {
|
2019-07-17 07:35:50 +00:00
|
|
|
return []string{"clear"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (Clear) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-07-17 07:35:50 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-09-03 19:34:03 +00:00
|
|
|
func (Clear) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-07-17 07:35:50 +00: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-15 22:22:20 +00:00
|
|
|
|
|
|
|
clearSelected := false
|
|
|
|
opts, optind, err := getopt.Getopts(args, "s")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
switch opt.Option {
|
|
|
|
case 's':
|
|
|
|
clearSelected = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(args) != optind {
|
|
|
|
return errors.New("Usage: clear [-s]")
|
|
|
|
}
|
|
|
|
|
|
|
|
if clearSelected {
|
|
|
|
defer store.Select(0)
|
|
|
|
}
|
2019-07-17 07:35:50 +00:00
|
|
|
store.ApplyClear()
|
2022-03-18 21:35:33 +00:00
|
|
|
acct.SetStatus(statusline.SearchFilterClear())
|
|
|
|
|
2019-07-17 07:35:50 +00:00
|
|
|
return nil
|
|
|
|
}
|