diff options
author | Koni Marti <koni.marti@gmail.com> | 2022-08-08 22:04:04 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-08-22 09:30:37 +0200 |
commit | 5c8a749cfa97b3ad9184f0f80a7d5c7921e8c073 (patch) | |
tree | c54468ed058024138b37fdada9e98ac0459fcd85 /widgets/aerc.go | |
parent | e31dbe9f3138f9576a48bc1fbc3a018e833ee0db (diff) | |
download | aerc-5c8a749cfa97b3ad9184f0f80a7d5c7921e8c073.tar.gz |
binds: display active keybinds in a dialog box
Show contextual keybinds in a textbox when using the ':help keys'
command. This command is bound to '?' by default.
Fixes: https://todo.sr.ht/~rjarry/aerc/42
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'widgets/aerc.go')
-rw-r--r-- | widgets/aerc.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go index 1e2a4cdd..f0bc1ba7 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net/url" + "sort" "strings" "time" @@ -199,6 +200,40 @@ func (aerc *Aerc) Draw(ctx *ui.Context) { } } +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" + for _, bind := range binds.Bindings { + result = append(result, fmt.Sprintf(fmtStr, + format(config.FormatKeyStrokes(bind.Input)), + format(config.FormatKeyStrokes(bind.Output)), + )) + } + if binds.Globals && aerc.conf.Bindings.Global != nil { + for _, bind := range aerc.conf.Bindings.Global.Bindings { + result = append(result, fmt.Sprintf(fmtStr+" (Globals)", + format(config.FormatKeyStrokes(bind.Input)), + format(config.FormatKeyStrokes(bind.Output)), + )) + } + } + result = append(result, fmt.Sprintf(fmtStr, + "$ex", + fmt.Sprintf("'%c'", binds.ExKey.Rune), + )) + result = append(result, fmt.Sprintf(fmtStr, + "Globals", + fmt.Sprintf("%v", binds.Globals), + )) + sort.Strings(result) + return result +} + func (aerc *Aerc) getBindings() *config.KeyBindings { selectedAccountName := "" if aerc.SelectedAccount() != nil { |