Skip to content
TypeScript

fix(shared): ignore unsupported command output erase modes (#29737)

Romil16ca47b3d359
diff --git a/packages/shared/src/terminalOutput.test.ts b/packages/shared/src/terminalOutput.test.ts
index 233ee6cbb53..578db819614 100644
--- a/packages/shared/src/terminalOutput.test.ts
+++ b/packages/shared/src/terminalOutput.test.ts
@@ -87,6 +87,16 @@ describe("appendTerminalOutput", () => {
});
describe("appendTerminalOutput edge cases from review", () => {
+ it("leaves the screen and cursor alone for unsupported erase modes", () => {
+ for (const sequence of ["3K", "4J", "99K", "99J"]) {
+ const input = `a\nb\nc\u001b[${sequence}X`;
+ expect(feed([input]).text).toBe("a\nb\ncX");
+ for (let cut = 1; cut < input.length; cut += 1) {
+ expect(feed([input.slice(0, cut), input.slice(cut)]).text).toBe("a\nb\ncX");
+ }
+ }
+ });
+
it("clears only scrollback on ESC[3J", () => {
const lines = Array.from({ length: 70 }, (_, index) => `line ${index}`).join("\n");
const state = feed([lines, "\u001b[3J"]);
diff --git a/packages/shared/src/terminalOutput.ts b/packages/shared/src/terminalOutput.ts
index 6bf4e318ef6..afeee8fdf34 100644
--- a/packages/shared/src/terminalOutput.ts
+++ b/packages/shared/src/terminalOutput.ts
@@ -132,7 +132,7 @@ function eraseLine(line: Line, col: number, mode: number): Line {
for (const run of sliceLine(line, col + 1, length)) pushRun(runs, run);
return runs;
}
- return [];
+ return mode === 2 ? [] : line;
}
function serializeLine(line: Line): string {
@@ -443,7 +443,7 @@ class Terminal {
if (this.settledHead !== "" || this.settledTail !== "") this.dropped = true;
this.settledHead = "";
this.settledTail = "";
- } else {
+ } else if (mode === 2) {
this.lines = [[]];
this.row = 0;
this.col = 0;