aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2022-12-02 12:24:11 +0100
committerRobin Jarry <robin@jarry.cc>2022-12-02 22:59:44 +0100
commiteffff93eef5f0789428a78894c8d7d3cf9f35d1d (patch)
tree81e2d68f283b75a53360ea4d60c567dbd931b94d /widgets
parentc2c5cbd4c0d6254ce4553e56f1b2b010858eb869 (diff)
downloadaerc-effff93eef5f0789428a78894c8d7d3cf9f35d1d.tar.gz
compose: show relevant bindings on review screen
Currently compose will always show only some hardcoded default commands. If hardcoded command is not bound to any key remove it from the list. If user adds new bindings to compose::review add them - without help text - at the bottom. Signed-off-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets')
-rw-r--r--widgets/compose.go68
1 files changed, 48 insertions, 20 deletions
diff --git a/widgets/compose.go b/widgets/compose.go
index c52c381f..30c5268d 100644
--- a/widgets/compose.go
+++ b/widgets/compose.go
@@ -7,6 +7,7 @@ import (
"net/textproto"
"os"
"os/exec"
+ "strconv"
"strings"
"sync"
"time"
@@ -1239,17 +1240,6 @@ type reviewMessage struct {
grid *ui.Grid
}
-var reviewCommands = [][]string{
- {":send<enter>", "Send"},
- {":edit<enter>", "Edit"},
- {":attach<space>", "Add attachment"},
- {":detach<space>", "Remove attachment"},
- {":postpone<enter>", "Postpone"},
- {":preview<enter>", "Preview message"},
- {":abort<enter>", "Abort (discard message, no confirmation)"},
- {":choose -o d discard abort -o p postpone postpone<enter>", "Abort or postpone"},
-}
-
func newReviewMessage(composer *Composer, err error) *reviewMessage {
bindings := composer.config.MergeContextualBinds(
composer.config.Bindings.ComposeReview,
@@ -1258,18 +1248,56 @@ func newReviewMessage(composer *Composer, err error) *reviewMessage {
"compose::review",
)
+ reviewCommands := [][]string{
+ {":send<enter>", "Send", ""},
+ {":edit<enter>", "Edit", ""},
+ {":attach<space>", "Add attachment", ""},
+ {":detach<space>", "Remove attachment", ""},
+ {":postpone<enter>", "Postpone", ""},
+ {":preview<enter>", "Preview message", ""},
+ {":abort<enter>", "Abort (discard message, no confirmation)", ""},
+ {":choose -o d discard abort -o p postpone postpone<enter>", "Abort or postpone", ""},
+ }
var actions []string
+ for _, binding := range bindings.Bindings {
+ inputs := config.FormatKeyStrokes(binding.Input)
+ outputs := config.FormatKeyStrokes(binding.Output)
+ outputs = strings.ReplaceAll(outputs, "<space>", " ")
+ found := false
+ for i, rcmd := range reviewCommands {
+ if outputs == rcmd[0] {
+ found = true
+ if reviewCommands[i][2] == "" {
+ reviewCommands[i][2] = inputs
+ } else {
+ reviewCommands[i][2] += ", " + inputs
+ }
+ break
+ }
+ }
+ if !found {
+ rcmd := []string{outputs, "", inputs}
+ reviewCommands = append(reviewCommands, rcmd)
+ }
+ }
+ longest := 0
+ for _, rcmd := range reviewCommands {
+ if len(rcmd[2]) > longest {
+ longest = len(rcmd[2])
+ }
+ }
+
+ width := longest
+ if longest < 6 {
+ width = 6
+ }
+ widthstr := strconv.Itoa(width)
- for _, command := range reviewCommands {
- cmd := command[0]
- name := command[1]
- strokes, _ := config.ParseKeyStrokes(cmd)
- var inputs []string
- for _, input := range bindings.GetReverseBindings(strokes) {
- inputs = append(inputs, config.FormatKeyStrokes(input))
+ for _, rcmd := range reviewCommands {
+ if rcmd[2] != "" {
+ actions = append(actions, fmt.Sprintf(" %-"+widthstr+"s %-40s %s",
+ rcmd[2], rcmd[1], rcmd[0]))
}
- actions = append(actions, fmt.Sprintf(" %-6s %-40s %s",
- strings.Join(inputs, ", "), name, cmd))
}
spec := []ui.GridSpec{