From d4e49c79a69c399702c3c781920c8eae5b9e22ba Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Sat, 16 Sep 2023 00:15:42 +0200 Subject: binds: improve display of key sequences Do not replace all spaces by , it makes the bindings completely unreadable. Only replace trailing and leading spaces with since these are the only one that actually matter. The others are implicit and it improves the readability level by over 9000. Signed-off-by: Robin Jarry Tested-by: Inwit --- config/binds.go | 24 ++++++++++++++++++++---- widgets/aerc.go | 1 - 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/config/binds.go b/config/binds.go index 78f68eb4..1e9727a5 100644 --- a/config/binds.go +++ b/config/binds.go @@ -393,11 +393,16 @@ func FormatKeyStrokes(keystrokes []KeyStroke) string { if ks.Modifiers == stroke.Modifiers && ks.Key == stroke.Key && ks.Rune == stroke.Rune { switch name { case "cr", "c-m": - name = "enter" + s = "" case "c-i": - name = "tab" + s = "" + case "space": + s = " " + case "semicolon": + s = ";" + default: + s = fmt.Sprintf("<%s>", name) } - s = fmt.Sprintf("<%s>", name) break } } @@ -407,9 +412,20 @@ func FormatKeyStrokes(keystrokes []KeyStroke) string { sb.WriteString(s) } - return sb.String() + // replace leading & trailing spaces with explicit keystrokes + buf := sb.String() + match := spaceTrimRe.FindStringSubmatch(buf) + if len(match) == 4 { + prefix := strings.ReplaceAll(match[1], " ", "") + suffix := strings.ReplaceAll(match[3], " ", "") + buf = prefix + match[2] + suffix + } + + return buf } +var spaceTrimRe = regexp.MustCompile(`^(\s*)(.*?)(\s*)$`) + var keyNames = map[string]KeyStroke{ "space": {tcell.ModNone, tcell.KeyRune, ' '}, "semicolon": {tcell.ModNone, tcell.KeyRune, ';'}, diff --git a/widgets/aerc.go b/widgets/aerc.go index faec403e..efa13194 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -209,7 +209,6 @@ func (aerc *Aerc) HumanReadableBindings() []string { var result []string binds := aerc.getBindings() format := func(s string) string { - s = strings.ReplaceAll(s, "", " ") return strings.ReplaceAll(s, "%", "%%") } fmtStr := "%10s %s" -- cgit v1.2.3-54-g00ecf