diff --git a/packages/tui/src/terminal.ts b/packages/tui/src/terminal.ts index 7e1d2368c..d5204fe9c 100644 --- a/packages/tui/src/terminal.ts +++ b/packages/tui/src/terminal.ts @@ -1100,9 +1100,9 @@ export class ProcessTerminal implements Terminal { const reportedFlags = parseInt(match[1]!, 10); this.#kittyProtocolActive = true; setKittyProtocolActive(true); - if (reportedFlags >= 3) { - // Already enriched (Ghostty/foot may keep flags from a parent app). - // Push level-2 to lock in event reporting. + if ((reportedFlags & 2) !== 0) { + // Preserve event-type reporting already enabled by a parent app. + // Push level-2 to keep its shortcuts reporting consistently. this.#kittyEnableSeq = "\x1b[>7u"; this.#safeWrite(this.#kittyEnableSeq); } else { diff --git a/packages/tui/test/kitty-keyboard-da1-ordering.test.ts b/packages/tui/test/kitty-keyboard-da1-ordering.test.ts index c3a654a8b..2b83b2097 100644 --- a/packages/tui/test/kitty-keyboard-da1-ordering.test.ts +++ b/packages/tui/test/kitty-keyboard-da1-ordering.test.ts @@ -60,6 +60,28 @@ describe("ProcessTerminal kitty keyboard progressive-enhancement ordering", () = expect(out).not.toContain("\x1b[>4;2m"); }); + it("keeps alternate-key reporting without enabling event types after a previous session", async () => { + harness = createProcessTerminalRenderHarness(100, 30); + await harness.settle(); + harness.writes.length = 0; + + await harness.feed("\x1b[?5u"); + + const out = harness.writes.join(""); + expect(out).toContain("\x1b[>5u"); + expect(out).not.toContain("\x1b[>7u"); + }); + + it("preserves event-type reporting enabled by a parent app", async () => { + harness = createProcessTerminalRenderHarness(100, 30); + await harness.settle(); + harness.writes.length = 0; + + await harness.feed("\x1b[?3u"); + + expect(harness.writes.join("")).toContain("\x1b[>7u"); + }); + it("enables kitty when the DA1 sentinel arrives before the kitty reply (#2042)", async () => { harness = createProcessTerminalRenderHarness(100, 30); await harness.settle();