Hide mode when listing single-mode binds (#2226)

This commit is contained in:
CatsDeservePets authored and GitHub committed 2025-10-26 09:43:04 +01:00
1 parent d8a23be926
commit ff169a80b9
1 file changed
+14 -3
+14 -3
View File
@@ -1329,6 +1329,7 @@ func listBinds(binds map[string]map[string]expr) string {
t := new(tabwriter.Writer) t := new(tabwriter.Writer)
b := new(bytes.Buffer) b := new(bytes.Buffer)
// merge keys by command across modes
m := make(map[string]map[string]string) m := make(map[string]map[string]string)
for mode, keys := range binds { for mode, keys := range binds {
for key, expr := range keys { for key, expr := range keys {
@@ -1343,6 +1344,7 @@ func listBinds(binds map[string]map[string]expr) string {
mode, key, cmd string mode, key, cmd string
} }
// collect normalized entries
var entries []entry var entries []entry
for key, cmds := range m { for key, cmds := range m {
for cmd, modes := range cmds { for cmd, modes := range cmds {
@@ -1360,9 +1362,18 @@ func listBinds(binds map[string]map[string]expr) string {
}) })
t.Init(b, 0, gOpts.tabstop, 2, '\t', 0) t.Init(b, 0, gOpts.tabstop, 2, '\t', 0)
fmt.Fprintln(t, "mode\tkeys\tcommand")
for _, e := range entries { if len(binds) == 1 {
fmt.Fprintf(t, "%s\t%s\t%s\n", e.mode, e.key, e.cmd) fmt.Fprintln(t, "keys\tcommand")
for _, e := range entries {
fmt.Fprintf(t, "%s\t%s\n", e.key, e.cmd)
}
} else {
// include mode field when listing combined maps
fmt.Fprintln(t, "mode\tkeys\tcommand")
for _, e := range entries {
fmt.Fprintf(t, "%s\t%s\t%s\n", e.mode, e.key, e.cmd)
}
} }
t.Flush() t.Flush()