aerc/commands/next-folder.go

47 lines
812 B
Go
Raw Normal View History

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)
}
2019-03-15 03:41:25 +00:00
func nextPrevFolderUsage(cmd string) error {
2019-03-11 01:23:22 +00:00
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 {
2019-03-15 03:41:25 +00:00
return nextPrevFolderUsage(args[0])
2019-03-11 01:23:22 +00:00
}
var (
n int = 1
err error
)
if len(args) > 1 {
n, err = strconv.Atoi(args[1])
if err != nil {
2019-03-15 03:41:25 +00:00
return nextPrevFolderUsage(args[0])
2019-03-11 01:23:22 +00:00
}
}
2019-03-11 01:15:24 +00:00
acct := aerc.SelectedAccount()
if acct == nil {
return errors.New("No account selected")
}
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
}