File: move-tab.go

package info (click to toggle)
aerc 0.20.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,164 kB
  • sloc: ansic: 1,148; python: 1,000; sh: 553; awk: 330; makefile: 23
file content (46 lines) | stat: -rw-r--r-- 793 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package commands

import (
	"strconv"
	"strings"

	"git.sr.ht/~rjarry/aerc/app"
)

type MoveTab struct {
	Index    int `opt:"index" metavar:"[+|-]<index>" action:"ParseIndex"`
	Relative bool
}

func init() {
	Register(MoveTab{})
}

func (MoveTab) Description() string {
	return "Move the selected tab to the given index."
}

func (MoveTab) Context() CommandContext {
	return GLOBAL
}

func (m *MoveTab) ParseIndex(arg string) error {
	i, err := strconv.ParseInt(arg, 10, 64)
	if err != nil {
		return err
	}
	m.Index = int(i)
	if strings.HasPrefix(arg, "+") || strings.HasPrefix(arg, "-") {
		m.Relative = true
	}
	return nil
}

func (MoveTab) Aliases() []string {
	return []string{"move-tab"}
}

func (m MoveTab) Execute(args []string) error {
	app.MoveTab(m.Index, m.Relative)
	return nil
}