2019-03-11 01:15:24 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2019-03-11 01:23:22 +00:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
2019-03-11 01:15:24 +00:00
|
|
|
"git.sr.ht/~sircmpwn/aerc2/widgets"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-03-11 01:23:22 +00:00
|
|
|
Register("next-folder", NextPrevFolder)
|
|
|
|
Register("prev-folder", NextPrevFolder)
|
|
|
|
}
|
|
|
|
|
|
|
|
func usage(cmd string) error {
|
|
|
|
return errors.New(fmt.Sprintf("Usage: %s [n]", cmd))
|
2019-03-11 01:15:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 01:23:22 +00:00
|
|
|
func NextPrevFolder(aerc *widgets.Aerc, args []string) error {
|
|
|
|
if len(args) > 2 {
|
|
|
|
return usage(args[0])
|
|
|
|
}
|
|
|
|
var (
|
|
|
|
n int = 1
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if len(args) > 1 {
|
|
|
|
n, err = strconv.Atoi(args[1])
|
|
|
|
if err != nil {
|
|
|
|
return usage(args[0])
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 01:15:24 +00:00
|
|
|
acct := aerc.SelectedAccount()
|
2019-03-11 01:23:22 +00:00
|
|
|
for ; n > 0; n-- {
|
|
|
|
if args[0] == "prev-folder" {
|
|
|
|
acct.Directories().Prev()
|
|
|
|
} else {
|
|
|
|
acct.Directories().Next()
|
|
|
|
}
|
|
|
|
}
|
2019-03-11 01:15:24 +00:00
|
|
|
return nil
|
|
|
|
}
|