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"
|
|
|
|
|
2021-11-05 10:19:46 +01:00
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
2019-03-11 02:15:24 +01:00
|
|
|
)
|
|
|
|
|
2019-06-27 19:33:11 +02:00
|
|
|
type NextPrevFolder struct{}
|
|
|
|
|
2019-03-11 02:15:24 +01:00
|
|
|
func init() {
|
2019-06-27 19:33:11 +02:00
|
|
|
register(NextPrevFolder{})
|
2019-03-11 02:23:22 +01:00
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (NextPrevFolder) Aliases() []string {
|
2019-06-27 19:33:11 +02:00
|
|
|
return []string{"next-folder", "prev-folder"}
|
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (NextPrevFolder) Complete(aerc *widgets.Aerc, args []string) []string {
|
2019-06-27 19:33:11 +02:00
|
|
|
return nil
|
2019-03-11 02:15:24 +01:00
|
|
|
}
|
|
|
|
|
2019-09-03 21:34:03 +02:00
|
|
|
func (NextPrevFolder) Execute(aerc *widgets.Aerc, args []string) error {
|
2019-03-11 02:23:22 +01:00
|
|
|
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()
|
2019-03-17 19:57:05 +01: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-11 02:23:22 +01:00
|
|
|
}
|
2019-03-11 02:15:24 +01:00
|
|
|
return nil
|
|
|
|
}
|
2019-06-27 19:33:11 +02:00
|
|
|
|
|
|
|
func nextPrevFolderUsage(cmd string) error {
|
2019-09-03 21:34:04 +02:00
|
|
|
return fmt.Errorf("Usage: %s [n]", cmd)
|
2019-06-27 19:33:11 +02:00
|
|
|
}
|