xonecas.io
64875
Mc

mini-coder / commit 34c89c6

refactor: use yoctocolors instead of raw ANSI codes in structured-output

xonecas2026-03-18 34c89c6ead5c169bcea2f253e3c91291c8db1994 parent 9f09926

1 file changed

src/cli/structured-output.ts+5−12
@@ -1,4 +1,5 @@
11 import { createTwoFilesPatch } from "diff";
2+import * as c from "yoctocolors";
23 import type {
34 ApplyExactTextEditResult,
45 FileEditErrorCode,
@@ -8,14 +9,6 @@ function shouldColorize(): boolean {
89 return process.env.FORCE_COLOR === "1" || process.env.FORCE_COLOR === "true";
910 }
1011
11-/** Raw ANSI codes for diff coloring (works in piped subprocesses). */
12-const ansi = {
13- red: (s: string) => `\x1b[31m${s}\x1b[39m`,
14- green: (s: string) => `\x1b[32m${s}\x1b[39m`,
15- cyan: (s: string) => `\x1b[36m${s}\x1b[39m`,
16- dim: (s: string) => `\x1b[2m${s}\x1b[22m`,
17-};
18-
1912 export interface StructuredOutputWriter {
2013 stdout: (text: string) => void;
2114 stderr: (text: string) => void;
@@ -59,10 +52,10 @@ function normalizePatchLines(patchText: string): string[] {
5952 }
6053
6154 function colorizeDiffLine(line: string): string {
62- if (line.startsWith("---") || line.startsWith("+++")) return ansi.dim(line);
63- if (line.startsWith("@@")) return ansi.cyan(line);
64- if (line.startsWith("+")) return ansi.green(line);
65- if (line.startsWith("-")) return ansi.red(line);
55+ if (line.startsWith("---") || line.startsWith("+++")) return c.dim(line);
56+ if (line.startsWith("@@")) return c.cyan(line);
57+ if (line.startsWith("+")) return c.green(line);
58+ if (line.startsWith("-")) return c.red(line);
6659 return line;
6760 }