2019-03-21 16:30:23 -04:00
|
|
|
package account
|
2019-03-10 21:15:24 -04:00
|
|
|
|
|
|
|
import (
|
2019-03-10 21:23:22 -04:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2021-11-05 10:19:46 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
2019-03-10 21:15:24 -04:00
|
|
|
)
|
|
|
|
|
2019-06-27 10:33:11 -07:00
|
|
|
type NextPrevFolder struct{}
|
|
|
|
|
2019-03-10 21:15:24 -04:00
|
|
|
func init() {
|
2019-06-27 10:33:11 -07:00
|
|
|
register(NextPrevFolder{})
|
2019-03-10 21:23:22 -04:00
|
|
|
}
|
|
|
|
|
2019-09-03 16:34:03 -03:00
|
|
|
func (NextPrevFolder) Aliases() []string {
|
2019-06-27 10:33:11 -07:00
|
|
|
return []string{"next-folder", "prev-folder"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 16:34:03 -03:00
|
|
|
func (NextPrevFolder) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-06-27 10:33:11 -07:00
|
|
|
return nil
|
2019-03-10 21:15:24 -04:00
|
|
|
}
|
|
|
|
|
2019-09-03 16:34:03 -03:00
|
|
|
func (NextPrevFolder) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-03-10 21:23:22 -04:00
|
|
|
if len(args) > 2 {
|
2019-03-14 23:41:25 -04:00
|
|
|
return nextPrevFolderUsage(args[0])
|
2019-03-10 21:23:22 -04:00
|
|
|
}
|
|
|
|
var (
|
|
|
|
n int = 1
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if len(args) > 1 {
|
|
|
|
n, err = strconv.Atoi(args[1])
|
|
|
|
if err != nil {
|
2019-03-14 23:41:25 -04:00
|
|
|
return nextPrevFolderUsage(args[0])
|
2019-03-10 21:23:22 -04:00
|
|
|
}
|
|
|
|
}
|
2019-03-10 21:15:24 -04:00
|
|
|
acct := aerc.SelectedAccount()
|
2019-03-17 14:57:05 -04:00
|
|
|
if acct == nil {
|
|
|
|
return errors.New("No account selected")
|
|
|
|
}
|
2019-08-04 16:05:06 +02:00
|
|
|
if args[0] == "prev-folder" {
|
|
|
|
acct.Directories().NextPrev(-n)
|
|
|
|
} else {
|
|
|
|
acct.Directories().NextPrev(n)
|
2019-03-10 21:23:22 -04:00
|
|
|
}
|
2019-03-10 21:15:24 -04:00
|
|
|
return nil
|
|
|
|
}
|
2019-06-27 10:33:11 -07:00
|
|
|
|
|
|
|
func nextPrevFolderUsage(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
|
|
|
}
|