fix(tmux): read a one-binding key table from the full listing

A tmux built from master (`tmux -V`: next-3.7) prints nothing, exit 0,
for `list-keys -T <table>` when the table holds exactly one binding.
tmux 3.4 prints the line. One binding is the shape
restrictTmuxPrefixTable leaves behind (`<prefix> send-prefix`), so on
that tmux the reduced table read as needing a reset and every session
create reset it again. `codeman tui` read its prefix table the same
way, so readPrefixBinding called a bound key free and readDetachKey
found no detach key.

A blank answer is now read from the full `list-keys` listing, keeping
only that table's lines. The parsers already match on `-T <table>`.

Tests: recorded-command cases for the blank answer (reduced table kept,
stray binding still reset) and TuiClient cases for both reads. The
real-tmux helper reads tables through the same fallback, and the
escaped `C-\` check accepts the unescaped form the full listing prints.
This commit is contained in:
Aamer Akhter committed 2026-11-15 15:06:07 -05:00
1 parent e99b42c387
commit c497869ee5
6 files changed
+111 -9

No files matched your search

+32
View File
@@ -1015,3 +1015,35 @@ describe('resumeSession', () => {
expect(recorded).toHaveLength(1);
});
});
describe('TuiClient key-table reads on a tmux that lists a one-binding table as nothing', () => {
// A tmux `next-3.7` build prints nothing for `list-keys -T prefix` when the table
// holds exactly one binding, which is how Codeman leaves it. Reading that as "free"
// would let the TUI claim a key the user has bound.
const fullListing =
'bind-key -T copy-mode C-a send-keys -X start-of-line\n' +
'bind-key -T prefix C-b send-prefix\n' +
'bind-key -T root F1 detach-client\n';
function client(direct: string) {
const calls: string[][] = [];
const exec = async (_file: string, args: readonly string[]) => {
calls.push([...args]);
return { stdout: args.includes('-T') ? direct : fullListing, stderr: '' };
};
return { tui: new TuiClient({ socket: 'cod563', exec }), calls };
}
it('falls back to the full listing when the table answer is blank', async () => {
const { tui, calls } = client('');
expect(await tui.readPrefixBinding('C-b')).toBe('send-prefix');
expect(await tui.readPrefixBinding('F1', 'root')).toBe('detach-client');
expect(await tui.readPrefixBinding('x')).toBeNull();
expect(calls.some((args) => args.length === 3 && args[2] === 'list-keys')).toBe(true);
});
it('keeps the table answer when there is one, with no second call', async () => {
const { tui, calls } = client('bind-key -T prefix d detach-client\n');
expect(await tui.readDetachKey()).toBe('d');
expect(calls).toEqual([['-L', 'cod563', 'list-keys', '-T', 'prefix']]);
});
});