@@ -5,10 +5,6 @@ import type {
55 FileEditErrorCode,
66 } from "../internal/file-edit/exact-text.ts";
77
8-function shouldColorize(): boolean {
9- return process.env.FORCE_COLOR === "1" || process.env.FORCE_COLOR === "true";
10-}
11-
128 export interface StructuredOutputWriter {
139 stdout: (text: string) => void;
1410 stderr: (text: string) => void;
@@ -63,6 +59,7 @@ export function renderUnifiedDiff(
6359 filePath: string,
6460 before: string,
6561 after: string,
62+ options?: { colorize?: boolean },
6663 ): string {
6764 if (before === after) {
6865 return "(no changes)";
@@ -80,7 +77,7 @@ export function renderUnifiedDiff(
8077 },
8178 );
8279 const lines = normalizePatchLines(patchText);
83- if (shouldColorize()) {
80+ if (options?.colorize) {
8481 return lines.map(colorizeDiffLine).join("\n");
8582 }
8683 return lines.join("\n");
@@ -107,8 +104,12 @@ export function writeFileEditResult(
107104 result: FileEditCliSuccess | FileEditCliFailure,
108105 ): void {
109106 if (result.ok) {
107+ const colorize =
108+ process.env.FORCE_COLOR === "1" || process.env.FORCE_COLOR === "true";
110109 const sections = [
111- renderUnifiedDiff(result.path, result.before, result.after),
110+ renderUnifiedDiff(result.path, result.before, result.after, {
111+ colorize,
112+ }),
112113 renderMetadataBlock(result),
113114 ];
114115 io.stdout(`${sections.join("\n\n")}\n`);