fix(tui,coding-agent): add OSC 133 user message markers support closes #1805

This commit is contained in:
Mario Zechner 2026-03-04 18:33:22 +01:00
parent 689e7b4ac2
commit 4cb1a56b53
5 changed files with 41 additions and 6 deletions

View file

@ -115,12 +115,21 @@ export function visibleWidth(str: string): number {
clean = clean.replace(/\t/g, " ");
}
if (clean.includes("\x1b")) {
// Strip SGR codes (\x1b[...m) and cursor codes (\x1b[...G/K/H/J)
clean = clean.replace(/\x1b\[[0-9;]*[mGKHJ]/g, "");
// Strip OSC 8 hyperlinks: \x1b]8;;URL\x07 and \x1b]8;;\x07
clean = clean.replace(/\x1b\]8;;[^\x07]*\x07/g, "");
// Strip APC sequences: \x1b_...\x07 or \x1b_...\x1b\\ (used for cursor marker)
clean = clean.replace(/\x1b_[^\x07\x1b]*(?:\x07|\x1b\\)/g, "");
// Strip supported ANSI/OSC/APC escape sequences in one pass.
// This covers CSI styling/cursor codes, OSC hyperlinks and prompt markers,
// and APC sequences like CURSOR_MARKER.
let stripped = "";
let i = 0;
while (i < clean.length) {
const ansi = extractAnsiCode(clean, i);
if (ansi) {
i += ansi.length;
continue;
}
stripped += clean[i];
i++;
}
clean = stripped;
}
// Calculate width