diff --git a/app/compose.go b/app/compose.go index 66735758..2e219549 100644 --- a/app/compose.go +++ b/app/compose.go @@ -9,7 +9,6 @@ import ( "net/textproto" "os" "os/exec" - "strconv" "strings" "sync" "sync/atomic" @@ -1602,62 +1601,35 @@ type reviewMessage struct { grid *ui.Grid } +var reviewCommands = [][]string{ + {":send", "Send"}, + {":edit", "Edit"}, + {":attach", "Add attachment"}, + {":detach", "Remove attachment"}, + {":postpone", "Postpone"}, + {":preview", "Preview message"}, + {":abort", "Abort (discard message, no confirmation)"}, + {":choose -o d discard abort -o p postpone postpone", "Abort or postpone"}, +} + func newReviewMessage(composer *Composer, err error) *reviewMessage { bindings := config.Binds.ComposeReview.ForAccount( composer.acctConfig.Name, ) bindings = bindings.ForFolder(composer.SelectedDirectory()) - reviewCommands := [][]string{ - {":send", "Send", ""}, - {":edit", "Edit", ""}, - {":attach", "Add attachment", ""}, - {":detach", "Remove attachment", ""}, - {":postpone", "Postpone", ""}, - {":preview", "Preview message", ""}, - {":abort", "Abort (discard message, no confirmation)", ""}, - {":choose -o d discard abort -o p postpone postpone", "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, "", " ") - 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 _, rcmd := range reviewCommands { - if rcmd[2] != "" { - actions = append(actions, fmt.Sprintf(" %-"+widthstr+"s %-40s %s", - rcmd[2], rcmd[1], rcmd[0])) + 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)) } + actions = append(actions, fmt.Sprintf(" %-6s %-40s %s", + strings.Join(inputs, ", "), name, cmd)) } spec := []ui.GridSpec{