Fix fish prompt OSC highlighting (#998)

This commit is contained in:
ZacharyZcR
2026-07-10 08:07:07 +08:00
committed by GitHub
parent bc4e42f59f
commit 55867ffd7b
2 changed files with 12 additions and 0 deletions
@@ -76,6 +76,16 @@ describe("highlightTerminalOutput", () => {
expect(highlightTerminalOutput(chunk)).toBe(chunk);
});
it("skips OSC current-directory sequences used by fish prompts", () => {
const chunk = `${ESC}]7;file://server/home/user/docker/sonarr\x07user@server ~/docker/sonarr> `;
expect(highlightTerminalOutput(chunk)).toBe(chunk);
});
it("skips OSC title sequences", () => {
const chunk = `${ESC}]0;user@server:/var/log\x07ERROR after title`;
expect(highlightTerminalOutput(chunk)).toBe(chunk);
});
it("highlights text that already has ANSI codes", () => {
let heavy = "";
for (let i = 0; i < 12; i++) heavy += `${ESC}[32mgreen${ESC}[0m `;
@@ -62,6 +62,7 @@ const MAX_LINE_LENGTH = 2000;
// extra SGR bytes into a full-screen redraw and corrupt xterm's cursor state.
const TUI_SEQUENCE = /\x1b\[(?:[\d;]*[ABCDEFGHJKST]|\?[\d;]*[hl])/;
const TUI_FRAME_SEQUENCE = /[\u2500-\u257f]|\x1b[()][0B]|\x1b\[[0-9;]*[~`]/;
const CONTROL_STRING_SEQUENCE = /\x1b[\]P^_]/;
// A bare \r (not immediately followed by \n) means the terminal is overwriting
// the current line (shell prompts, progress bars). Highlighting mid-rewrite
@@ -400,6 +401,7 @@ export function highlightTerminalOutput(
if (TUI_SEQUENCE.test(text)) return text;
if (TUI_FRAME_SEQUENCE.test(text)) return text;
if (CONTROL_STRING_SEQUENCE.test(text)) return text;
if (MID_LINE_CR.test(text)) return text;
const activePatterns = buildActivePatterns(options);