aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-01-29 23:52:28 +0100
committerRobin Jarry <robin@jarry.cc>2024-02-11 22:03:56 +0100
commit05874f867c76c8e9b8c1e67a57dc702e63d6d54b (patch)
treeedb8ba9a4800511f30810c5be90a709df695147e /commands
parent635fe05d4e8ee5a6dbadf7d10b6d8340efcbc84d (diff)
downloadaerc-05874f867c76c8e9b8c1e67a57dc702e63d6d54b.tar.gz
commands: add align
Add a new :align command that aligns the selected message vertically at the top, center, or bottom of the message list. The command requires a position argument that can either be: "top", "center", or "bottom". Create the following default keybinds: zz = :align center<Enter> zt = :align top<Enter> zb = :align bottom<Enter> Changelog-added: Add new `:align` command to align the selected message at the top, center, or bottom of the message list. Suggested-by: Ángel Castañeda <angel@acsq.me> Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Jason Cox <me@jasoncarloscox.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r--commands/account/align.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/commands/account/align.go b/commands/account/align.go
new file mode 100644
index 00000000..7f835b71
--- /dev/null
+++ b/commands/account/align.go
@@ -0,0 +1,60 @@
+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{})
+}
+
+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.ACCOUNT
+}
+
+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
+}