mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-05 06:59:42 +02:00
fix(tui): advertise the key that actually detaches, and stop tmux painting it green
Two things the attach status bar got wrong, both found in a beta test. The bar read `Ctrl+B D`. tmux key tables are case-sensitive: lowercase `d` is `detach-client`, capital `D` is `choose-client`. Pressing what the bar said opened a client chooser and left the tester attached, with the way out on screen and inert. The key is now READ from `list-keys -T prefix` the same way the prefix already was, rather than hardcoded, so a rebound tmux is followed too and the label cannot drift from the binding again. It never goes through formatPrefixKey(), which uppercases. The bar also rendered as a full-width bright green slab. Only `status-format[0]` was styled, so tmux's stock `status-style` (`bg=green,fg=black`) stayed underneath it and won; `#[reverse]` on top could not undo it. `status-style` is now set explicitly to `bg=default,fg=default` and snapshotted/restored with the rest, so the bar sits on the terminal's own background and reads as a hint line. Tests pin both: that the chord ends in lowercase `d` and never ` D`, that a rebound key prints verbatim, that `status-style` is part of the banner, and that parseDetachKey() picks `d` out of verbatim tmux 3.4 `list-keys` output while ignoring `detach-client -a`/`-P`, which act on other clients.
This commit is contained in:
@@ -471,20 +471,45 @@ describe('the way out of an attach', () => {
|
||||
});
|
||||
|
||||
it('names the chord, not just the prefix', () => {
|
||||
expect(detachChord('C-a')).toBe('Ctrl+A D');
|
||||
expect(detachChord()).toBe('Ctrl+B D');
|
||||
expect(detachChord('C-a', 'd')).toBe('Ctrl+A then d');
|
||||
expect(detachChord()).toBe('Ctrl+B then d');
|
||||
});
|
||||
|
||||
it('names the LOWERCASE detach key, because capital D is choose-client', () => {
|
||||
// Regression: the bar shipped reading `Ctrl+B D`, and a beta tester pressing
|
||||
// exactly that landed in tmux's client chooser while staying attached. tmux
|
||||
// key tables are case-sensitive and `D` is bound to a different command.
|
||||
expect(detachChord()).not.toContain(' D');
|
||||
expect(detachChord()).toMatch(/ then d$/);
|
||||
expect(buildAttachBanner({})['status-format[0]']).not.toContain('#[bold]Ctrl+B D#[nobold]');
|
||||
});
|
||||
|
||||
it('prints a rebound detach key verbatim, never uppercased like the prefix', () => {
|
||||
// formatPrefixKey() uppercases (`C-a` → `Ctrl+A`); running the detach key
|
||||
// through it would reintroduce the same class of bug on a rebound tmux.
|
||||
expect(detachChord('C-a', 'q')).toBe('Ctrl+A then q');
|
||||
expect(buildAttachBanner({ prefix: 'C-a', detachKey: 'q' })['status-format[0]']).toContain('Ctrl+A then q');
|
||||
});
|
||||
|
||||
it('builds ONE status-format option, so tmux draws no window list beside it', () => {
|
||||
const banner = buildAttachBanner({ prefix: 'C-b', label: 'w3-codeman' });
|
||||
expect(Object.keys(banner).sort()).toEqual(['status', 'status-format[0]']);
|
||||
expect(Object.keys(banner).sort()).toEqual(['status', 'status-format[0]', 'status-style']);
|
||||
expect(banner.status).toBe('on');
|
||||
expect(banner['status-format[0]']).toContain('#[bold]Ctrl+B D#[nobold]');
|
||||
expect(banner['status-format[0]']).toContain('#[bold]Ctrl+B then d#[nobold]');
|
||||
expect(banner['status-format[0]']).toContain('#[align=right] w3-codeman ');
|
||||
});
|
||||
|
||||
it('sets status-style, or tmux paints its stock green bar under the bar', () => {
|
||||
// Regression: styling only status-format[0] left tmux's default
|
||||
// `bg=green,fg=black` status-style underneath, which a beta tester saw as a
|
||||
// full-width bright green slab across the bottom of the pane.
|
||||
const banner = buildAttachBanner({ prefix: 'C-b' });
|
||||
expect(banner['status-style']).toBe('bg=default,fg=default');
|
||||
expect(banner['status-format[0]']).not.toContain('#[reverse]');
|
||||
});
|
||||
|
||||
it('carries the remapped prefix into the bar', () => {
|
||||
expect(buildAttachBanner({ prefix: 'C-a' })['status-format[0]']).toContain('Ctrl+A D');
|
||||
expect(buildAttachBanner({ prefix: 'C-a' })['status-format[0]']).toContain('Ctrl+A then d');
|
||||
});
|
||||
|
||||
it('escapes a label that would otherwise open a tmux format', () => {
|
||||
@@ -506,11 +531,11 @@ describe('the way out of an attach', () => {
|
||||
});
|
||||
|
||||
it("tells the help overlay how to get back, in the socket's own prefix", () => {
|
||||
const keys = helpKeysFor(GLYPHS, { server: true, detach: 'Ctrl+A D' });
|
||||
const detach = keys.find(([key]) => key === 'Ctrl+A D');
|
||||
const keys = helpKeysFor(GLYPHS, { server: true, detach: 'Ctrl+A then d' });
|
||||
const detach = keys.find(([key]) => key === 'Ctrl+A then d');
|
||||
expect(detach?.[1]).toContain('detach');
|
||||
// Degraded mode still attaches, so it still needs the way out.
|
||||
expect(helpKeysFor(GLYPHS, { server: false }).map(([key]) => key)).toContain('Ctrl+B D');
|
||||
expect(helpKeysFor(GLYPHS, { server: false }).map(([key]) => key)).toContain('Ctrl+B then d');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
parseEnvFile,
|
||||
arrayOptionBase,
|
||||
parseSessionOptions,
|
||||
parseDetachKey,
|
||||
parseTmuxSessionList,
|
||||
parseWindowSizing,
|
||||
readCodemanCredentials,
|
||||
@@ -599,6 +600,47 @@ describe('attach window sizing', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('parseDetachKey', () => {
|
||||
// Verbatim from `tmux -L codeman list-keys -T prefix` on tmux 3.4, trimmed to
|
||||
// the two lines that matter. They differ only by case, which is the whole
|
||||
// point: `D` is choose-client and advertising it leaves the tester attached.
|
||||
const REAL_TMUX_34 = [
|
||||
'bind-key -T prefix C-b send-prefix',
|
||||
'bind-key -T prefix d detach-client',
|
||||
'bind-key -T prefix D choose-client -Z',
|
||||
'bind-key -T prefix x confirm-before -p "kill-pane #P? (y/n)" kill-pane',
|
||||
].join('\n');
|
||||
|
||||
it('picks the lowercase detach-client binding out of real tmux output', () => {
|
||||
expect(parseDetachKey(REAL_TMUX_34)).toBe('d');
|
||||
});
|
||||
|
||||
it('follows a rebound detach key rather than assuming d', () => {
|
||||
expect(parseDetachKey('bind-key -T prefix Q detach-client')).toBe('Q');
|
||||
});
|
||||
|
||||
it('tolerates the -r repeat flag ahead of -T', () => {
|
||||
expect(parseDetachKey('bind-key -r -T prefix d detach-client')).toBe('d');
|
||||
});
|
||||
|
||||
it('ignores detach-client bindings that carry arguments', () => {
|
||||
// `-a` detaches OTHER clients and `-P` kills the pane's process; neither is
|
||||
// what the bar promises, so a socket with only those reports nothing.
|
||||
expect(parseDetachKey('bind-key -T prefix X detach-client -a')).toBeNull();
|
||||
expect(parseDetachKey('bind-key -T prefix Y detach-client -P')).toBeNull();
|
||||
});
|
||||
|
||||
it('prefers a single-character binding over a named key', () => {
|
||||
const both = 'bind-key -T prefix F1 detach-client\nbind-key -T prefix d detach-client';
|
||||
expect(parseDetachKey(both)).toBe('d');
|
||||
});
|
||||
|
||||
it('is null when nothing detaches, so the caller can fall back', () => {
|
||||
expect(parseDetachKey('')).toBeNull();
|
||||
expect(parseDetachKey('bind-key -T prefix D choose-client -Z')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('attach status bar options', () => {
|
||||
function optionsClient(exec: TuiExecFile): TuiClient {
|
||||
return new TuiClient({ baseUrl: BASE_URL, socket: 'codeman-beta', exec });
|
||||
|
||||
Reference in New Issue
Block a user