@devries-cameron20 / t3code-1 / commits / 449deb635e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): modified F3 reaches ncurses terminal bindings (#37211)

Julius Marminge committed Nov 15, 2026 at 05:22 UTC 449deb635ec0fc7735b42671afcdb7ee73eebf45
2 files changed +42 -1
apps/web/src/terminal/ghostty/core.test.ts
+28
@@ -165,6 +165,34 @@ describe("GhosttyTerminalCore snapshots", () => {
165 },
166 );
167
168 + // smkx is what ncurses keypad(True) sends; a raw-mode parser such as Crossterm never does.
169 + it.each([
170 + { mode: "", ctrlKey: true, expected: "\x1b[13;5~" },
171 + { mode: "\x1b[?1h\x1b=", ctrlKey: true, expected: "\x1b[1;5R" },
172 + { mode: "\x1b[?1h\x1b=", shiftKey: true, expected: "\x1b[1;2R" },
173 + { mode: "\x1b[?1h\x1b=\x1b[?1l\x1b>", ctrlKey: true, expected: "\x1b[13;5~" },
174 + { mode: "\x1b[?1h\x1b=\x1b[>1u", ctrlKey: true, expected: "\x1b[13;5~" },
175 + ])(
176 + "encodes modified F3 as $expected after $mode",
177 + async ({ mode, ctrlKey = false, shiftKey = false, expected }) => {
178 + const core = await createCore();
179 + core.write(mode);
180 + const event = {
181 + code: "F3",
182 + key: "F3",
183 + repeat: false,
184 + shiftKey,
185 + ctrlKey,
186 + altKey: false,
187 + metaKey: false,
188 + isComposing: false,
189 + getModifierState: () => false,
190 + } as unknown as KeyboardEvent;
191 +
192 + expect(core.encodeKey(event)).toBe(expected);
193 + },
194 + );
195 +
196 it.each(["", "\x1b[>1u"])("encodes macOS Option text with keyboard mode %j", async (mode) => {
197 using _platform = vi.spyOn(navigator, "platform", "get").mockReturnValue("MacIntel");
198 const core = await createCore();
apps/web/src/terminal/ghostty/core.ts
+14 -1
@@ -162,6 +162,11 @@ export interface GhosttyMouseInput {
162 readonly anyButtonPressed: boolean;
163 }
164
165 +// Ghostty sends modified F3 as CSI 13;m ~ to stay clear of cursor position reports, but the PTY
166 +// advertises xterm-256color, whose kf15/kf27/... are CSI 1;m R. Terminfo keys only apply in
167 +// keypad-transmit mode (smkx), so that mode marks a terminfo reader; raw parsers never set it.
168 +const MODIFIED_F3 = /^\x1b\[13;(\d+)~$/;
169 +
170 const decoder = new TextDecoder("utf-8", { ignoreBOM: true });
171 const encoder = new TextEncoder();
172
@@ -602,7 +607,9 @@ export class GhosttyTerminalCore {
607 );
608 this.runtime.call("ghostty_wasm_free_usize", written);
609 if (textPointer !== 0) this.runtime.free(textPointer, textBytes.length);
605 - return encoded;
610 + return MODIFIED_F3.test(encoded) && this.modeEnabled(66) && this.kittyKeyboardFlags() === 0
611 + ? encoded.replace(MODIFIED_F3, "\x1b[1;$1R")
612 + : encoded;
613 }
614
615 encodePaste(data: string): string {
@@ -1040,6 +1047,12 @@ export class GhosttyTerminalCore {
1047 }
1048 }
1049
1050 + private kittyKeyboardFlags(): number {
1051 + this.runtime.bytes(this.scratch, 1)[0] = 0;
1052 + this.runtime.call("ghostty_terminal_get", this.terminal, 8, this.scratch);
1053 + return this.runtime.bytes(this.scratch, 1)[0]!;
1054 + }
1055 +
1056 /** Reads a DEC private mode; an unknown mode reads as off. */
1057 private modeEnabled(mode: number): boolean {
1058 this.runtime.bytes(this.scratch, 1)[0] = 0;