~rjarry/aerc-devel

aerc: binds: improve display of key sequences v1 NEEDS REVISION

Robin Jarry: 1
 binds: improve display of key sequences

 2 files changed, 20 insertions(+), 5 deletions(-)
#1058202 alpine-edge.yml failed
#1058203 openbsd.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~rjarry/aerc-devel/patches/44776/mbox | git am -3
Learn more about email & git

[PATCH aerc] binds: improve display of key sequences Export this patch

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 readability level by over 9000.

Signed-off-by: Robin Jarry <robin@jarry.cc>
---
 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 9188bf49ffd4..0fcfd8196a19 100644
--- a/config/binds.go
+++ b/config/binds.go
@@ -405,11 +405,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
			}
		}
@@ -419,7 +424,18 @@ func FormatKeyStrokes(keystrokes []KeyStroke) string {
		sb.WriteString(s)
	}

	return sb.String()
	// replace leading & trailing spaces with explicit <space> keystrokes
	var prefix, suffix string
	buf, found := strings.CutSuffix(sb.String(), " ")
	for ; found; buf, found = strings.CutSuffix(buf, " ") {
		suffix += "<space>"
	}
	buf, found = strings.CutPrefix(buf, " ")
	for ; found; buf, found = strings.CutPrefix(buf, " ") {
		prefix += "<space>"
	}

	return prefix + buf + suffix
}

var keyNames = map[string]KeyStroke{
diff --git a/widgets/aerc.go b/widgets/aerc.go
index faec403e47fd..efa1319415e3 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, "<space>", " ")
		return strings.ReplaceAll(s, "%", "%%")
	}
	fmtStr := "%10s %s"
-- 
2.41.0
Robin Jarry, Sep 16, 2023 at 00:17:
aerc/patches: FAILED in 4m46s

[binds: improve display of key sequences][0] from [Robin Jarry][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/44776
[1]: mailto:robin@jarry.cc

✓ #1058203 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1058203
✗ #1058202 FAILED  aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1058202