@devries-cameron20 / t3code-1 / commits / 6ef66b6cd1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(shared): count terminal resume lines without allocations (#28539)

Hieu Le committed Nov 1, 2026 at 22:55 UTC 6ef66b6cd1d10a6464d792dce8223889097deecb
1 file changed +8 -2
packages/shared/src/terminalOutput.ts
+8 -2
@@ -631,8 +631,14 @@ export function terminalOutputResumeText(state: TerminalOutputState): string {
631 const { screen } = state;
632 const lastRow = screen.lines.length - 1;
633 // Moves are relative to the last line, and a viewer only holds the lines in `text`.
634 - const shownLines = state.text.split("\n").length;
635 - const reachable = Math.min(LIVE_LINES, shownLines) - 1;
634 + let reachable = 0;
635 + let cursor = 0;
636 + while (reachable < LIVE_LINES - 1) {
637 + const newline = state.text.indexOf("\n", cursor);
638 + if (newline === -1) break;
639 + reachable += 1;
640 + cursor = newline + 1;
641 + }
642 const up = (row: number) => Math.min(lastRow - row, reachable);
643 const goTo = (row: number, col: number) =>
644 (up(row) > 0 ? `${ESC}[${up(row)}A` : "") + `${ESC}[${col + 1}G`;