diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-10-17 15:16:11 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-10-18 22:25:35 +0200 |
commit | bad694e466705db83da2e864a3988255eb97055a (patch) | |
tree | 2898491fa51a998c5f034399ed17a8991abddc1b /commands/account/split.go | |
parent | 7016c6f86ae09b3e49eab665aa013628db4ee102 (diff) | |
download | aerc-bad694e466705db83da2e864a3988255eb97055a.tar.gz |
ui: add :split and :vsplit view options
Add :split and :vsplit commands, which split the message list view to
include a message viewer. Each command takes an int, or a delta value
("+1", "-1"). The int value is the resulting size of the message list,
and a new message viewer will be displayed below / to the right of the
message list. This viewer *does not* set seen flags.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands/account/split.go')
-rw-r--r-- | commands/account/split.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/commands/account/split.go b/commands/account/split.go new file mode 100644 index 00000000..2b802256 --- /dev/null +++ b/commands/account/split.go @@ -0,0 +1,63 @@ +package account + +import ( + "errors" + "strconv" + "strings" + + "git.sr.ht/~rjarry/aerc/widgets" +) + +type Split struct{} + +func init() { + register(Split{}) +} + +func (Split) Aliases() []string { + return []string{"split", "vsplit"} +} + +func (Split) Complete(aerc *widgets.Aerc, args []string) []string { + return nil +} + +func (Split) Execute(aerc *widgets.Aerc, args []string) error { + if len(args) > 2 { + return errors.New("Usage: [v]split n") + } + acct := aerc.SelectedAccount() + if acct == nil { + return errors.New("No account selected") + } + n := 0 + var err error + if len(args) > 1 { + delta := false + if strings.HasPrefix(args[1], "+") || strings.HasPrefix(args[1], "-") { + delta = true + } + n, err = strconv.Atoi(args[1]) + if err != nil { + return errors.New("Usage: [v]split n") + } + if delta { + n = acct.SplitSize() + n + // Maintain split direction when using deltas + if acct.SplitSize() > 0 { + args[0] = acct.SplitDirection() + } + } + } + if n == acct.SplitSize() { + // Repeated commands of the same size have the effect of + // toggling the split + n = 0 + } + if args[0] == "split" { + acct.Split(n) + return nil + } + acct.Vsplit(n) + return nil +} |