feat(claudbg-37cj): add --[no-]color global flag and NO_COLOR support

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
main
Elijah Voigt 2 months ago
parent 9c9f61efd1
commit 8d72b0e971

@ -0,0 +1,11 @@
---
# claudbg-37cj
title: Add --[no-]color global flag and NO_COLOR env var support
status: todo
type: task
created_at: 2026-03-31T00:32:57Z
updated_at: 2026-03-31T00:32:57Z
parent: claudbg-qpfe
---
Add `--color` / `--no-color` as a global CLI flag (available on all commands). When not specified, auto-detect: enable color if stdout is a tty and NO_COLOR is unset/empty. Honor the NO_COLOR environment variable (any non-empty value → disable color), per the NO_COLOR spec. This flag controls all ANSI output in the CLI (transcripts etc).

@ -116,6 +116,37 @@ pub struct GlobalOpts {
/// Valid values: thinking, output. Example: --include thinking,output /// Valid values: thinking, output. Example: --include thinking,output
#[arg(long, global = true, default_value = "")] #[arg(long, global = true, default_value = "")]
pub include: IncludeList, pub include: IncludeList,
/// Force color output even when not writing to a terminal.
#[arg(long, global = true, overrides_with = "no_color")]
pub color: bool,
/// Disable color output (also honored via the NO_COLOR env var).
#[arg(long = "no-color", global = true, overrides_with = "color")]
pub no_color: bool,
}
impl GlobalOpts {
/// Determine whether color output should be enabled.
///
/// Priority (highest → lowest):
/// 1. `NO_COLOR` env var set to a non-empty value → disabled.
/// 2. `--no-color` flag passed → disabled.
/// 3. `--color` flag passed → enabled.
/// 4. Auto-detect: enabled iff stdout is a TTY.
pub fn color_enabled(&self) -> bool {
use std::io::IsTerminal as _;
// NO_COLOR spec: any non-empty value disables color.
if std::env::var("NO_COLOR").is_ok_and(|v| !v.is_empty()) {
return false;
}
if self.no_color {
return false;
}
if self.color {
return true;
}
std::io::stdout().is_terminal()
}
} }
/// Top-level subcommands. /// Top-level subcommands.

@ -464,6 +464,8 @@ mod tests {
output: OutputFormat::Table, output: OutputFormat::Table,
verbose: false, verbose: false,
include: IncludeList::default(), include: IncludeList::default(),
color: false,
no_color: false,
} }
} }

@ -647,6 +647,8 @@ mod tests {
output: OutputFormat::Table, output: OutputFormat::Table,
verbose: false, verbose: false,
include: IncludeList::default(), include: IncludeList::default(),
color: false,
no_color: false,
} }
} }

Loading…
Cancel
Save