compose: show annotations on the review screen

Customize annotations on the review screen. Annotations will overwrite
the default descriptions. Replace the [][]string construct with a named
struct for better readability.

Fixes: https://todo.sr.ht/~rjarry/aerc/118
Changelog-deprecated: Built-in descriptions for the default
 keybinds shown on the review screen will be deprecated in a future
 release. Descriptions can be added to those keybinds with inline
 comments in binds.conf.
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Koni Marti
2024-01-28 00:52:21 +01:00
committed by Robin Jarry
parent 28ee8e65a4
commit 64502d9e8b
2 changed files with 44 additions and 27 deletions

View File

@@ -1615,7 +1615,14 @@ func newReviewMessage(composer *Composer, err error) *reviewMessage {
)
bindings = bindings.ForFolder(composer.SelectedDirectory())
reviewCommands := [][]string{
const maxInputWidth = 6
type reviewCmd struct {
output string
annotation string
input string
}
reviewCmds := []reviewCmd{
{":send<enter>", "Send", ""},
{":edit<enter>", "Edit", ""},
{":attach<space>", "Add attachment", ""},
@@ -1625,50 +1632,59 @@ func newReviewMessage(composer *Composer, err error) *reviewMessage {
{":abort<enter>", "Abort (discard message, no confirmation)", ""},
{":choose -o d discard abort -o p postpone postpone<enter>", "Abort or postpone", ""},
}
knownCommands := len(reviewCommands)
knownCommands := len(reviewCmds)
var actions []string
for _, binding := range bindings.Bindings {
inputs := config.FormatKeyStrokes(binding.Input)
outputs := config.FormatKeyStrokes(binding.Output)
found := false
for i, rcmd := range reviewCommands {
if outputs == rcmd[0] {
for i, rcmd := range reviewCmds {
if outputs == rcmd.output {
found = true
if reviewCommands[i][2] == "" {
reviewCommands[i][2] = inputs
if reviewCmds[i].input == "" {
reviewCmds[i].input = inputs
} else {
reviewCommands[i][2] += ", " + inputs
reviewCmds[i].input += ", " + inputs
}
if binding.Annotation != "" {
// overwrite default description with
// user annotations if present
reviewCmds[i].annotation = binding.Annotation
}
break
}
}
if !found {
rcmd := []string{outputs, "", inputs}
reviewCommands = append(reviewCommands, rcmd)
rcmd := reviewCmd{
output: outputs,
annotation: binding.Annotation,
input: inputs,
}
reviewCmds = append(reviewCmds, rcmd)
}
}
unknownCommands := reviewCommands[knownCommands:]
unknownCommands := reviewCmds[knownCommands:]
sort.Slice(unknownCommands, func(i, j int) bool {
return unknownCommands[i][2] < unknownCommands[j][2]
return unknownCommands[i].input < unknownCommands[j].input
})
longest := 0
for _, rcmd := range reviewCommands {
if len(rcmd[2]) > longest {
longest = len(rcmd[2])
for _, rcmd := range reviewCmds {
if len(rcmd.input) > longest {
longest = len(rcmd.input)
}
}
width := longest
if longest < 6 {
width = 6
if longest < maxInputWidth {
width = maxInputWidth
}
widthstr := strconv.Itoa(width)
for _, rcmd := range reviewCommands {
if rcmd[2] != "" {
for _, rcmd := range reviewCmds {
if rcmd.input != "" {
actions = append(actions, fmt.Sprintf(" %-"+widthstr+"s %-40s %s",
rcmd[2], rcmd[1], rcmd[0]))
rcmd.input, rcmd.annotation, rcmd.output))
}
}

View File

@@ -158,14 +158,15 @@ $ex = <C-x>
[compose::review]
# Keybindings used when reviewing a message to be sent
y = :send<Enter>
n = :abort<Enter>
v = :preview<Enter>
p = :postpone<Enter>
q = :choose -o d discard abort -o p postpone postpone<Enter>
e = :edit<Enter>
a = :attach<space>
d = :detach<space>
# Inline comments are used as descriptions on the review screen
y = :send<Enter> # Send
n = :abort<Enter> # Abort (discard message, no confirmation)
v = :preview<Enter> # Preview message
p = :postpone<Enter> # Postpone
q = :choose -o d discard abort -o p postpone postpone<Enter> # Abort or postpone
e = :edit<Enter> # Edit
a = :attach<space> # Add attachment
d = :detach<space> # Remove attachment
[terminal]
$noinherit = true