Terminal: consume unsupported escape bytes in tables

This commit is contained in:
Vincent Koc
2026-03-11 09:11:25 -04:00
parent accabda65c
commit 361f3109a5
2 changed files with 21 additions and 0 deletions

View File

@@ -156,6 +156,20 @@ describe("renderTable", () => {
expect(visibleWidth(line)).toBe(width);
}
});
it("consumes unsupported escape sequences without hanging", () => {
const out = renderTable({
width: 48,
columns: [
{ key: "K", header: "K", minWidth: 6 },
{ key: "V", header: "V", minWidth: 12, flex: true },
],
rows: [{ K: "row", V: "before \x1b[2J after" }],
});
expect(out).toContain("before");
expect(out).toContain("after");
});
});
describe("wrapNoteMessage", () => {

View File

@@ -98,6 +98,13 @@ function wrapLine(text: string, width: number): string[] {
if (nextEsc < 0) {
nextEsc = text.length;
}
if (nextEsc === i) {
// Consume unsupported escape bytes as plain characters so wrapping
// cannot stall on unknown ANSI/control sequences.
tokens.push({ kind: "char", value: ESC });
i += ESC.length;
continue;
}
const plainChunk = text.slice(i, nextEsc);
for (const grapheme of splitGraphemes(plainChunk)) {
tokens.push({ kind: "char", value: grapheme });