Terminal: consume unsupported escape bytes in tables
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user