Skip to content

Commit 1ed25c4

Browse files
Alyx-MLclaude
authored andcommitted
perf(server): colored terminal output no longer copies history one character at a time (pingdotgg#21209)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit c6dfda8)
1 parent 5bc5bdf commit 1ed25c4

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎apps/server/src/terminal/Manager.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ function findEscapeSequenceEndIndex(input: string, start: number): number | null
11181118

11191119
// eslint-disable-next-line no-control-regex -- Terminal sequence introducers must reach the parser.
11201120
const HISTORY_SEQUENCE_START = /[\u001b\u0090\u009b\u009d\u009e\u009f]/;
1121+
const NEXT_HISTORY_SEQUENCE_START = new RegExp(HISTORY_SEQUENCE_START.source, "g");
11211122

11221123
function sanitizeTerminalHistoryChunk(
11231124
pendingControlSequence: string,
@@ -1234,8 +1235,11 @@ function sanitizeTerminalHistoryChunk(
12341235
continue;
12351236
}
12361237

1237-
append(input[index] ?? "");
1238-
index += 1;
1238+
// One slice per printable run: every chunk of coloured output reaches this loop.
1239+
NEXT_HISTORY_SEQUENCE_START.lastIndex = index + 1;
1240+
const nextSequenceStart = NEXT_HISTORY_SEQUENCE_START.exec(input)?.index ?? input.length;
1241+
append(input.slice(index, nextSequenceStart));
1242+
index = nextSequenceStart;
12391243
}
12401244

12411245
return { visibleText, pendingControlSequence: "" };

0 commit comments

Comments
 (0)