Skip to content

Commit f5f8365

Browse files
fix(shared): ignore unsupported command output erase modes
1 parent 71646e0 commit f5f8365

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages/shared/src/terminalOutput.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ describe("appendTerminalOutput", () => {
8484
});
8585

8686
describe("appendTerminalOutput edge cases from review", () => {
87+
it("leaves the screen and cursor alone for unsupported erase modes", () => {
88+
for (const sequence of ["3K", "4J", "99K", "99J"]) {
89+
const input = `a\nb\nc\u001b[${sequence}X`;
90+
expect(feed([input]).text).toBe("a\nb\ncX");
91+
for (let cut = 1; cut < input.length; cut += 1) {
92+
expect(feed([input.slice(0, cut), input.slice(cut)]).text).toBe("a\nb\ncX");
93+
}
94+
}
95+
});
96+
8797
it("clears only scrollback on ESC[3J", () => {
8898
const lines = Array.from({ length: 70 }, (_, index) => `line ${index}`).join("\n");
8999
const state = feed([lines, "\u001b[3J"]);

‎packages/shared/src/terminalOutput.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function eraseLine(line: Line, col: number, mode: number): Line {
132132
for (const run of sliceLine(line, col + 1, length)) pushRun(runs, run);
133133
return runs;
134134
}
135-
return [];
135+
return mode === 2 ? [] : line;
136136
}
137137

138138
function serializeLine(line: Line): string {
@@ -443,7 +443,7 @@ class Terminal {
443443
if (this.settledHead !== "" || this.settledTail !== "") this.dropped = true;
444444
this.settledHead = "";
445445
this.settledTail = "";
446-
} else {
446+
} else if (mode === 2) {
447447
this.lines = [[]];
448448
this.row = 0;
449449
this.col = 0;

0 commit comments

Comments
 (0)