Skip to content

Commit ddc77c2

Browse files
fix(shared): keep tab stops past the default output budget
Clamp cursor moves to the terminal's own budget rather than the default 64 KiB, so a tab past column 65,536 under a larger budget no longer moves the cursor backward. Trim the tab tests to the cases that guard distinct behavior. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 66d6010 commit ddc77c2

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,21 @@ describe("appendTerminalOutput", () => {
2626

2727
it.each([
2828
{ chunks: ["A\tB"], text: "A B", col: 9 },
29-
{ chunks: ["abcdefgh\tX"], text: "abcdefgh X", col: 17 },
3029
{ chunks: ["A\t"], text: "A", col: 8 },
3130
{ chunks: ["A\tB\rXY"], text: "XY B", col: 2 },
32-
{ chunks: ["A\tB", "\u001b[9GX"], text: "A X", col: 9 },
33-
{ chunks: ["A\tB", "\u001b[1;9HX"], text: "A X", col: 9 },
3431
{ chunks: ["abcdefghij\rA\tX"], text: "AbcdefghXj", col: 9 },
35-
])("moves tabs to the next eight-column stop: $chunks", ({ chunks, text, col }) => {
36-
const state = feed(chunks);
32+
{
33+
chunks: [`${"a".repeat(70_000)}\tX`],
34+
maxChars: 100_000,
35+
text: `${"a".repeat(70_000)} X`,
36+
col: 70_009,
37+
},
38+
])("moves tabs to the next eight-column stop (col $col)", ({ chunks, maxChars, text, col }) => {
39+
const state = feed(chunks, maxChars);
3740
expect(state.text).toBe(text);
3841
expect(state.screen.col).toBe(col);
39-
expect(
40-
appendTerminalOutput(
41-
appendTerminalOutput(EMPTY_TERMINAL_OUTPUT, terminalOutputResumeText(state)),
42-
"Z",
43-
).text,
44-
).toBe(appendTerminalOutput(state, "Z").text);
42+
const resumed = feed([terminalOutputResumeText(state), "Z"], maxChars);
43+
expect(resumed.text).toBe(appendTerminalOutput(state, "Z", maxChars).text);
4544
});
4645

4746
it("redraws several lines in place when the cursor moves up", () => {
@@ -215,7 +214,7 @@ describe("appendTerminalOutput under adversarial output", () => {
215214

216215
it("gives the same result however the output is split into chunks", () => {
217216
const input =
218-
"A\tB\rXY\nA\tB\u001b[9GX\nA\tB\u001b[1;9HX\nabcdefghij\rA\tX\n" +
217+
"A\tB\rXY\nabcdefghij\rA\tX\n" +
219218
"abcdef\rX\u001b[31mred\u001b[0m\nnext line\r\u001b[2Kdone\n" +
220219
"\u001b[1;31mbold red\u001b[mplain\u001b[38:2::12:34:56mrgb\u001b[0m\n" +
221220
"\u001b[1;31mbold red again\u001b[mplain again\u001b[38:2::12:34:56mrgb again\u001b[0m";

‎packages/shared/src/terminalOutput.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class Terminal {
432432
moveTo(row: number, col: number): void {
433433
this.row = Math.max(0, Math.min(this.lines.length - 1, row));
434434
// A huge column (ESC[999999999C) would otherwise pad a line past any string limit.
435-
this.col = Math.max(0, Math.min(TERMINAL_OUTPUT_TAIL_CHARS, col));
435+
this.col = Math.max(0, Math.min(this.maxChars, col));
436436
}
437437

438438
csi(params: string, final: string): void {

0 commit comments

Comments
 (0)