aboutsummaryrefslogblamecommitdiffstats
path: root/commands/account/align.go
blob: 83bb5b64745ad9e1478a6073ee5a0213dacffd24 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                                                                              



                                             




















                                                                      
                                    



















                                                              
package account

import (
	"errors"

	"git.sr.ht/~rjarry/aerc/app"
	"git.sr.ht/~rjarry/aerc/commands"
	"git.sr.ht/~rjarry/aerc/lib/ui"
)

type Align struct {
	Pos app.AlignPosition `opt:"pos" metavar:"top|center|bottom" action:"ParsePos" complete:"CompletePos"`
}

func init() {
	commands.Register(Align{})
}

func (Align) Description() string {
	return "Align the message list view."
}

var posNames []string = []string{"top", "center", "bottom"}

func (a *Align) ParsePos(arg string) error {
	switch arg {
	case "top":
		a.Pos = app.AlignTop
	case "center":
		a.Pos = app.AlignCenter
	case "bottom":
		a.Pos = app.AlignBottom
	default:
		return errors.New("invalid alignment")
	}
	return nil
}

func (a *Align) CompletePos(arg string) []string {
	return commands.FilterList(posNames, arg, commands.QuoteSpace)
}

func (Align) Context() commands.CommandContext {
	return commands.MESSAGE_LIST
}

func (Align) Aliases() []string {
	return []string{"align"}
}

func (a Align) Execute(args []string) error {
	acct := app.SelectedAccount()
	if acct == nil {
		return errors.New("no account selected")
	}
	msgList := acct.Messages()
	if msgList == nil {
		return errors.New("no message list available")
	}
	msgList.AlignMessage(a.Pos)
	ui.Invalidate()

	return nil
}