fix(cli): honor NO_COLOR/--no-color and go plain when stdout is piped (#1306)
List commands (status, query, callers, callees, impact, files) embedded ANSI color codes even when stdout was a pipe, and NO_COLOR had no effect. One switch now decides color for all codegraph-authored output: --no-color > --color > NO_COLOR > FORCE_COLOR > stdout TTY > CI. Piped init/index/sync also stop emitting shimmer animation frames (\r + erase-line rewrites) and print one plain line per phase instead; a TTY with NO_COLOR keeps the animation but drops the color codes. The detection mirrors picocolors' so @clack frames and our own lines agree within a run. Fixes #1281 Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
5736e24bb6
commit
d6efd437b3
@@ -28,6 +28,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as https from 'https';
|
||||
import { spawnSync } from 'child_process';
|
||||
import { ansiColorsEnabled } from '../ui/color';
|
||||
|
||||
export const REPO = 'colbymchenry/codegraph';
|
||||
export const NPM_PACKAGE = '@colbymchenry/codegraph';
|
||||
@@ -305,12 +306,14 @@ export interface UpgradeDeps {
|
||||
offerBetaSignup?: () => Promise<void>;
|
||||
}
|
||||
|
||||
// Colors off when piped / NO_COLOR / --no-color (#1281).
|
||||
const useColor = ansiColorsEnabled();
|
||||
const c = {
|
||||
bold: (s: string) => `\x1b[1m${s}\x1b[0m`,
|
||||
dim: (s: string) => `\x1b[2m${s}\x1b[0m`,
|
||||
green: (s: string) => `\x1b[32m${s}\x1b[0m`,
|
||||
yellow: (s: string) => `\x1b[33m${s}\x1b[0m`,
|
||||
cyan: (s: string) => `\x1b[36m${s}\x1b[0m`,
|
||||
bold: (s: string) => (useColor ? `\x1b[1m${s}\x1b[0m` : s),
|
||||
dim: (s: string) => (useColor ? `\x1b[2m${s}\x1b[0m` : s),
|
||||
green: (s: string) => (useColor ? `\x1b[32m${s}\x1b[0m` : s),
|
||||
yellow: (s: string) => (useColor ? `\x1b[33m${s}\x1b[0m` : s),
|
||||
cyan: (s: string) => (useColor ? `\x1b[36m${s}\x1b[0m` : s),
|
||||
};
|
||||
|
||||
/** The honest, additive re-index reminder shown after a successful upgrade. */
|
||||
|
||||
Reference in New Issue
Block a user