list-keys prints enum tags; mapCommandToAction only accepts command namesSeverity: MEDIUM
Status: ✅ FIXED
Files: src/cmd/cmd.zig:726, src/cmd/cmd.zig:735, src/key_binding.zig:474-526
list-keys renders the action’s Zig enum tag as if it were a command:
// src/cmd/cmd.zig:726
const line = std.fmt.bufPrint(&line_buf, "bind-key -T prefix {s} {s}\n", .{ key_str, @tagName(b.action) }) catch return .err;
Output is therefore of the form:
bind-key -T prefix C-b new_window
bind-key -T prefix % split_horizontal
But the reverse mapping matches hyphenated tmux names only:
// src/key_binding.zig:479
if (std.mem.eql(u8, name, "new-window") or std.mem.eql(u8, name, "neww")) return .new_window;
mapCommandToAction("new_window") returns null, so re-sourcing the output
fails with bind-key: unknown command. tmux guarantees list-keys output is
valid configuration; this breaks that contract and makes the command useless for
its main purpose (inspecting and editing the key table).
The gap is wider than the naming mismatch. mapCommandToAction has no
mapping for send-prefix, rotate-window, reflow-pane, resize-pane, or
swap-pane, so the default bindings for send_prefix, rotate_window,
reflow_pane and the resize_* / swap_pane_* variants cannot be expressed in
a config file at all — only through the built-in defaults.
Add an actionToCommand(action) []const u8 reverse table next to
mapCommandToAction, and have list-keys print that. Extend
mapCommandToAction with the five missing commands so the round trip closes in
both directions. A test that renders list-keys, feeds each line back through
mapCommandToAction, and asserts a non-null result would lock this down.
A canonical reverse mapping was added next to the forward one:
// src/key_binding.zig
pub fn actionToCommand(action: Action) []const u8 {
return switch (action) {
.new_window => "new-window",
.split_horizontal => "split-window -h",
...
.resize_left => "resize-pane -L",
.rotate_window => "rotate-window",
.send_prefix => "send-prefix",
.reflow_pane => "reflow-pane",
};
}
It is an exhaustive switch, so adding an Action variant without giving it a
command string is a compile error. The ten select_window_* variants index a
comptime array of "select-window -t N" strings.
list-keys (src/cmd/cmd.zig) now emits actionToCommand(b.action) for both
the prefix and root tables instead of @tagName(b.action).
mapCommandToAction gained the five commands it was missing — rotate-window,
send-prefix, reflow-pane, resize-pane -L/-R/-U/-D, and swap-pane -U/-D
— so the round trip closes in both directions and those actions are expressible
in a config file for the first time.
Interactive bind-key and unbind-key (src/cmd/cmd.zig) were also updated to
accept -T prefix and -T root flags (matching list-keys output) and to join
multi-token command arguments (e.g. split-window -v, select-pane -L),
preventing interactive re-sourcing from dropping arguments or silently flipping
split_vertical to split_horizontal.
every action round-trips through actionToCommand and mapCommandToAction — bug
#517 (src/key_binding.zig) walks every variant by ordinal and asserts
mapCommandToAction(actionToCommand(a)) == a. Iterating by ordinal means a
newly added variant is covered automatically.list-keys emits re-bindable command names, not enum tags — bug #517
(src/cmd/cmd.zig) runs the command and asserts no enum tag (new_window,
split_vertical, select_window_, …) leaks into the output.bind-key preserves command arguments and -T flags — bug #517 follow-up
(src/cmd/cmd.zig) asserts bind-key C-x split-window -v maps to
.split_vertical, -T prefix and -T root bind and unbind correctly, and
every line emitted by list-keys re-sources cleanly through parse + exec.Verified with the full suite on Zig 0.16.0 and 0.17.0: 1057/1057 passing on both.
Bugs #47, #48 and #326 were earlier defects in mapCommandToAction’s parsing;
this is the inverse direction of the same table.