Fix three-byte escape sequences leaking final byte into history

Handle ECMA-48 escape sequences with intermediate bytes (0x20-0x2F)
such as ESC ( B (select ASCII for G0), ESC ) 0 (select DEC Special
Graphics for G1), and ESC # 8 (DECALN). These are commonly emitted by
ncurses programs (vim, less, htop) on exit. Previously only 2 bytes
were consumed, causing the final byte to leak into visibleText.
This commit is contained in:
Cursor Agent committed 2026-03-24 17:02:14 +00:00
1 parent b71705580a
commit 87caa1b78f
1 file changed
+16
@@ -321,6 +321,22 @@ function sanitizeTerminalHistoryChunk(
continue;
}
if (nextCodePoint >= 0x20 && nextCodePoint <= 0x2f) {
let cursor = index + 2;
while (
cursor < input.length &&
input.charCodeAt(cursor) >= 0x20 &&
input.charCodeAt(cursor) <= 0x2f
) {
cursor++;
}
if (cursor >= input.length) {
return { visibleText, pendingControlSequence: input.slice(index) };
}
index = cursor + 1;
continue;
}
index += 2;
continue;
}