Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(shared): fold command output without copying scrollback per chunk #26691

Mergedhieu-lee(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/26691/headmerged by maria-rcks View on GitHub

Showing 2 changed files with 50 additions and 14 deletions.

x
0 of 2 viewed, 2 left
3 additions and 0 deletionspackages/shared/src/terminalOutput.test.tsModified
View file
@@ -52,6 +52,9 @@
expect(state.text.length).toBeLessThanOrEqual(1_000);
expect(state.text.startsWith("line ")).toBe(true);
expect(state.text.endsWith("line 1999")).toBe(true);
+ // A newline a quarter of the budget past the cut is too far to start on.
+ expect(feed(["abcdefgh\nij\nklmnop"], 8).text).toBe("klmnop");
+ expect(feed(["abcdefgh\nijk\nlmnop"], 8).text).toBe("jk\nlmnop");
});
​
it("stays bounded across many appends of huge output, including one endless line", () => {
47 additions and 14 deletionspackages/shared/src/terminalOutput.tsModified
View file
@@ -17,8 +17,9 @@
type Line = ReadonlyArray<Run>;
​
interface TerminalScreen {
- /** Scrolled-out lines, each ending in newline. */
- readonly settled: string;
+ /** Scrolled-out lines, each ending in newline, as head + tail. Only the tail grows, so a cut
+ * usually slices the head instead of copying all scrollback on every chunk. */
+ readonly settled: readonly [head: string, tail: string];
/** Never empty. */
readonly lines: ReadonlyArray<Line>;
readonly row: number;
@@ -31,7 +32,7 @@
text: "",
truncated: false,