aerc/commands/account/next-folder.go

47 lines
811 B
Go
Raw Normal View History

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