Debian Codegraph @

commands/account/align.go

raw
1 package account
2
3 import (
4 "errors"
5
6 "git.sr.ht/~rjarry/aerc/app"
7 "git.sr.ht/~rjarry/aerc/commands"
8 "git.sr.ht/~rjarry/aerc/lib/ui"
9 )
10
11 type Align struct {
12 Pos app.AlignPosition `opt:"pos" metavar:"top|center|bottom" action:"ParsePos" complete:"CompletePos" desc:"Position."`
13 }
14
15 func init() {
16 commands.Register(Align{})
17 }
18
19 func (Align) Description() string {
20 return "Align the message list view."
21 }
22
23 var posNames []string = []string{"top", "center", "bottom"}
24
25 func (a *Align) ParsePos(arg string) error {
26 switch arg {
27 case "top":
28 a.Pos = app.AlignTop
29 case "center":
30 a.Pos = app.AlignCenter
31 case "bottom":
32 a.Pos = app.AlignBottom
33 default:
34 return errors.New("invalid alignment")
35 }
36 return nil
37 }
38
39 func (a *Align) CompletePos(arg string) []string {
40 return commands.FilterList(posNames, arg, nil)
41 }
42
43 func (Align) Context() commands.CommandContext {
44 return commands.MESSAGE_LIST
45 }
46
47 func (Align) Aliases() []string {
48 return []string{"align"}
49 }
50
51 func (a Align) Execute(args []string) error {
52 acct := app.SelectedAccount()
53 if acct == nil {
54 return errors.New("no account selected")
55 }
56 msgList := acct.Messages()
57 if msgList == nil {
58 return errors.New("no message list available")
59 }
60 msgList.AlignMessage(a.Pos)
61 ui.Invalidate()
62
63 return nil
64 }