Fix terminal color query replies

Answer OSC color queries from the daemon and suppress browser-side replies so response bytes do not race back into the shell prompt as user input.
This commit is contained in:
Mohamed Boudra
2026-05-26 09:32:15 +07:00
parent 48d4e3e408
commit 6e56ee9e32
5 changed files with 136 additions and 0 deletions
+14
View File
@@ -17,6 +17,11 @@ let nodePtySpawnHelperChecked = false;
const TERMINAL_TITLE_DEBOUNCE_MS = 150;
const TERMINAL_EXIT_OUTPUT_LINE_LIMIT = 12;
const TERMINAL_EXIT_OUTPUT_CHAR_LIMIT = 16000;
const TERMINAL_OSC_COLOR_QUERY_RESPONSES = new Map<number, string>([
[10, "rgb:e6e6/e6e6/e6e6"],
[11, "rgb:0b0b/0b0b/0b0b"],
[12, "rgb:e6e6/e6e6/e6e6"],
]);
export interface TerminalExitInfo {
exitCode: number | null;
@@ -681,6 +686,15 @@ export async function createTerminal(options: CreateTerminalOptions): Promise<Te
ptyProcess.write(`\x1b[?${buffer.cursorY + 1};${buffer.cursorX + 1}R`);
return true;
});
for (const [code, response] of TERMINAL_OSC_COLOR_QUERY_RESPONSES) {
terminal.parser.registerOscHandler(code, (data) => {
if (data.trim() !== "?") {
return false;
}
ptyProcess.write(`\x1b]${code};${response}\x1b\\`);
return true;
});
}
if (titleMode === "auto") {
titleChangeSubscription = terminal.onTitleChange((nextTitle) => {