2020-03-02 19:54:42 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2021-11-05 09:19:46 +00:00
|
|
|
"git.sr.ht/~rjarry/aerc/widgets"
|
2020-03-02 19:54:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MoveTab struct{}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
register(MoveTab{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (MoveTab) Aliases() []string {
|
|
|
|
return []string{"move-tab"}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (MoveTab) Complete(aerc *widgets.Aerc, args []string) []string {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (MoveTab) Execute(aerc *widgets.Aerc, args []string) error {
|
|
|
|
if len(args) == 1 {
|
|
|
|
return fmt.Errorf("Usage: %s [+|-]<index>", args[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
joinedArgs := strings.Join(args[1:], "")
|
|
|
|
|
|
|
|
n, err := strconv.Atoi(joinedArgs)
|
|
|
|
if err != nil {
|
2022-07-31 13:15:27 +00:00
|
|
|
return fmt.Errorf("failed to parse index argument: %w", err)
|
2020-03-02 19:54:42 +00:00
|
|
|
}
|
|
|
|
|
2022-07-14 16:29:56 +00:00
|
|
|
var relative bool
|
|
|
|
if strings.HasPrefix(joinedArgs, "+") || strings.HasPrefix(joinedArgs, "-") {
|
|
|
|
relative = true
|
2020-03-02 19:54:42 +00:00
|
|
|
}
|
2022-07-14 16:29:56 +00:00
|
|
|
aerc.MoveTab(n, relative)
|
2020-03-02 19:54:42 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|