Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(shared): preserve the command-output cursor when clearing the display #27496

Openmacodev00(GitHub profile, opens in a new tab)wants to merge 6 commits intomain fromrefs/pull/27496/headopened View on GitHub

Showing 2 changed files with 57 additions and 9 deletions.

x
0 of 2 viewed, 2 left
40 additions and 0 deletionspackages/shared/src/terminalOutput.test.tsModified
View file
@@ -144,6 +144,34 @@
});
​
+ it("erases the display without moving the cursor", () => {
+ const state = feed(["line1\nline2\u001b[2", "J"]);
+ expect(state.text).toBe("\n");
+ const continued = appendTerminalOutput(state, "X\u001b[1A\rY");
+ expect(continued.text).toBe("Y\n X");
+ const resumed = appendTerminalOutput(EMPTY_TERMINAL_OUTPUT, terminalOutputResumeText(state));
+ expect(appendTerminalOutput(resumed, "X\u001b[1A\rY").text).toBe(continued.text);
+ for (const clear of ["\u001b[H\u001b[2J\u001b[3J", "\u001b[2J\u001b[3J\u001b[H"]) {
+ const lines = Array.from({ length: 50 }, (_, index) => `line ${index}`).join("\n");
+ expect(feed([lines, clear, "hello\nworld"]).text).toBe("hello\nworld");
+ }
+ for (const [input, maxChars, next] of [
+ ["\n".repeat(10) + "\u001b[2J", 3, "\u001b[8AX"],
+ ["\n".repeat(10) + "\u001b[8A\u001b[2Jx", 3, "X"],
+ ["\n".repeat(100) + "\u001b[2J", 64, "X"],
+ ] as const) {
+ const bounded = feed([input], maxChars);
+ const boundedResume = appendTerminalOutput(
+ EMPTY_TERMINAL_OUTPUT,
+ terminalOutputResumeText(bounded),
+ maxChars,
+ );
+ expect(appendTerminalOutput(boundedResume, next, maxChars).text).toBe(
+ appendTerminalOutput(bounded, next, maxChars).text,
+ );
+ }