~rjarry/aerc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH aerc v2] binds: improve display of key sequences

Details
Message ID
<20230918224829.369597-2-robin@jarry.cc>
DKIM signature
missing
Download raw message
Patch: +20 -5
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>
---

Notes:
    v2: fix build with go 1.18

 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..158665b27e9c 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,9 +424,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, ';'},
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

[aerc/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CVMEVHDQY0M1.1XKSJX1CES3ZZ@cirno2>
In-Reply-To
<20230918224829.369597-2-robin@jarry.cc> (view parent)
DKIM signature
missing
Download raw message
aerc/patches: SUCCESS in 4m45s

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

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

✓ #1059542 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1059542
✓ #1059541 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1059541
Details
Message ID
<CVMYS2HO5PZV.15D0WUC7N510Q@sindominio.net>
In-Reply-To
<20230918224829.369597-2-robin@jarry.cc> (view parent)
DKIM signature
missing
Download raw message
This is nice too!

Tested-By: inwit <inwit@sindominio.net>
Details
Message ID
<CVMZ7RVECB9O.XNJZFUWSGJKI@ringo>
In-Reply-To
<CVMYS2HO5PZV.15D0WUC7N510Q@sindominio.net> (view parent)
DKIM signature
missing
Download raw message
inwit, Sep 19, 2023 at 16:30:
> This is nice too!
>
> Tested-By: inwit <inwit@sindominio.net> 

Applied. Thanks!
Reply to thread Export thread (mbox)