Skip to content

Commit 947ca19

Browse files
Alyx-MLclaude
andcommitted
perf(server): colored terminal output no longer copies history one character at a time
Chunks carrying escape sequences skip the plain-text fast path, so the history sanitizer appended every printable character on its own. Append each printable run up to the next sequence introducer as one slice. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9c16146 commit 947ca19

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
@@ -1061,6 +1061,7 @@ function findEscapeSequenceEndIndex(input: string, start: number): number | null
10611061

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

10651066
function sanitizeTerminalHistoryChunk(
10661067
pendingControlSequence: string,
@@ -1175,8 +1176,11 @@ function sanitizeTerminalHistoryChunk(
11751176
continue;
11761177
}
11771178

1178-
append(input[index] ?? "");
1179-
index += 1;
1179+
// One slice per printable run: every chunk of coloured output reaches this loop.
1180+
NEXT_HISTORY_SEQUENCE_START.lastIndex = index + 1;
1181+
const nextSequenceStart = NEXT_HISTORY_SEQUENCE_START.exec(input)?.index ?? input.length;
1182+
append(input.slice(index, nextSequenceStart));
1183+
index = nextSequenceStart;
11801184
}
11811185

11821186
return { visibleText, pendingControlSequence: "" };

0 commit comments

Comments
 (0)