aerc/commands/next-folder.go

44 lines
706 B
Go
Raw Normal View History

2019-03-11 02:15:24 +01:00
package commands
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-11 02:23:22 +01: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 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 {
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 02:15:24 +01:00
acct := aerc.SelectedAccount()
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
}