The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 08:15 UTC
perf(shared): skip parsing cached terminal styles (#27041)
Utkarsh Patil committed
Nov 2, 2026 at 03:11 UTC
e8b08568700cb999c6faaf45748da4c791727511
2 files changed
+22
-17
packages/shared/src/terminalOutput.test.ts
+9
-4
@@ -106,10 +106,15 @@ describe("appendTerminalOutput edge cases from review", () => {
106
107
describe("appendTerminalOutput under adversarial output", () => {
108
it("gives the same result however the output is split into chunks", () => {
109
- const input = "abcdef\rX\u001b[31mred\u001b[0m\nnext line\r\u001b[2Kdone\n";
110
- const whole = feed([input], 3).text;
111
- for (let cut = 1; cut < input.length; cut += 1) {
112
- expect(feed([input.slice(0, cut), input.slice(cut)], 3).text).toBe(whole);
109
+ const input =
110
+ "abcdef\rX\u001b[31mred\u001b[0m\nnext line\r\u001b[2Kdone\n" +
111
+ "\u001b[1;31mbold red\u001b[mplain\u001b[38:2::12:34:56mrgb\u001b[0m\n" +
112
+ "\u001b[1;31mbold red again\u001b[mplain again\u001b[38:2::12:34:56mrgb again\u001b[0m";
113
+ for (const maxChars of [3, 1_024]) {
114
+ const whole = feed([input], maxChars).text;
115
+ for (let cut = 1; cut < input.length; cut += 1) {
116
+ expect(feed([input.slice(0, cut), input.slice(cut)], maxChars).text).toBe(whole);
117
+ }
118
}
119
expect(feed(["abcdef", "\rX"], 3).text).toBe(feed(["abcdef\rX"], 3).text);
120
});
packages/shared/src/terminalOutput.ts
+13
-13
@@ -394,22 +394,22 @@ class Terminal {
394
395
csi(params: string, final: string): void {
396
if (/^[?>=]/u.test(params)) return; // Mode switches (cursor visibility, bracketed paste).
397
+ if (final === "m") {
398
+ const key = `${this.pen}|${params}`;
399
+ let pen = penTransitions.get(key);
400
+ if (pen === undefined) {
401
+ const attributes = parsePen(this.pen);
402
+ applySgr(attributes, params === "" ? [] : csiParams(params));
403
+ pen = formatPen(attributes);
404
+ if (penTransitions.size >= 512) penTransitions.clear();
405
+ penTransitions.set(key, pen);
406
+ }
407
+ this.pen = pen;
408
+ return;
409
+ }
410
const numbers = params === "" ? [] : csiParams(params);
411
const count = Math.max(1, numbers[0] || 1);
412
switch (final) {
400
- case "m": {
401
- const key = `${this.pen}|${params}`;
402
- let pen = penTransitions.get(key);
403
- if (pen === undefined) {
404
- const attributes = parsePen(this.pen);
405
- applySgr(attributes, numbers);
406
- pen = formatPen(attributes);
407
- if (penTransitions.size >= 512) penTransitions.clear();
408
- penTransitions.set(key, pen);
409
- }
410
- this.pen = pen;
411
- return;
412
- }
413
case "A":
414
return this.moveTo(this.row - count, this.col);
415
case "B":