diff options
author | Robin Jarry <robin@jarry.cc> | 2023-09-16 00:15:42 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-09-19 16:49:59 +0200 |
commit | d4e49c79a69c399702c3c781920c8eae5b9e22ba (patch) | |
tree | 74af2ee50e0b2b6c5ef6d25131d2236162944b3d /config/binds.go | |
parent | 34c718d72b357b6a64f4273ef72b4415ad721fd2 (diff) | |
download | aerc-d4e49c79a69c399702c3c781920c8eae5b9e22ba.tar.gz |
binds: improve display of key sequences
Do not replace all spaces by <space>, it makes the bindings completely
unreadable. Only replace trailing and leading spaces with <space> 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 <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'config/binds.go')
-rw-r--r-- | config/binds.go | 24 |
1 files changed, 20 insertions, 4 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 = "<enter>" case "c-i": - name = "tab" + s = "<tab>" + 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 <space> keystrokes + buf := sb.String() + match := spaceTrimRe.FindStringSubmatch(buf) + if len(match) == 4 { + prefix := strings.ReplaceAll(match[1], " ", "<space>") + suffix := strings.ReplaceAll(match[3], " ", "<space>") + 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, ';'}, |