From f586b0c3b632645a01cbaa407c07ed3f01ba59e9 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Fri, 10 Jul 2026 08:01:22 +0800 Subject: [PATCH] Fix MC syntax highlighting artifacts (#996) --- src/ui/lib/terminal-syntax-highlighter.test.ts | 10 ++++++++++ src/ui/lib/terminal-syntax-highlighter.ts | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/ui/lib/terminal-syntax-highlighter.test.ts b/src/ui/lib/terminal-syntax-highlighter.test.ts index 609be80b..fc2b55f8 100644 --- a/src/ui/lib/terminal-syntax-highlighter.test.ts +++ b/src/ui/lib/terminal-syntax-highlighter.test.ts @@ -66,6 +66,16 @@ describe("highlightTerminalOutput", () => { expect(highlightTerminalOutput(chunk)).toBe(chunk); }); + it("skips TUI frames with box-drawing characters", () => { + const chunk = `┌─ /var/log ─┐\n│ ERROR file │`; + expect(highlightTerminalOutput(chunk)).toBe(chunk); + }); + + it("skips DEC line-drawing charset frames", () => { + const chunk = `${ESC}(0lqq /var/log qk${ESC}(B`; + 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 `; diff --git a/src/ui/lib/terminal-syntax-highlighter.ts b/src/ui/lib/terminal-syntax-highlighter.ts index a1479f70..aaba3615 100644 --- a/src/ui/lib/terminal-syntax-highlighter.ts +++ b/src/ui/lib/terminal-syntax-highlighter.ts @@ -61,6 +61,7 @@ const MAX_LINE_LENGTH = 2000; // (mc, nano, vim, htop). If a chunk contains these, highlighting can inject // 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;]*[~`]/; // A bare \r (not immediately followed by \n) means the terminal is overwriting // the current line (shell prompts, progress bars). Highlighting mid-rewrite @@ -398,6 +399,7 @@ export function highlightTerminalOutput( if (hasIncompleteAnsiSequence(text)) return text; if (TUI_SEQUENCE.test(text)) return text; + if (TUI_FRAME_SEQUENCE.test(text)) return text; if (MID_LINE_CR.test(text)) return text; const activePatterns = buildActivePatterns(options);