diff --git a/crates/puffin/src/main.rs b/crates/puffin/src/main.rs index e2b5ce0c6..98fbfb982 100644 --- a/crates/puffin/src/main.rs +++ b/crates/puffin/src/main.rs @@ -57,14 +57,46 @@ struct Cli { #[arg(global = true, long, short, conflicts_with = "quiet")] verbose: bool, - /// Disable colors. - #[arg(global = true, long)] + /// Disable colors; provided for compatibility with `pip`. + #[arg(global = true, long, hide = true, conflicts_with = "color")] no_color: bool, + /// Control colors in output. + #[arg( + global = true, + long, + value_enum, + default_value = "auto", + conflicts_with = "no_color" + )] + color: ColorChoice, + #[command(flatten)] cache_args: CacheArgs, } +#[derive(Debug, Clone, clap::ValueEnum)] +pub enum ColorChoice { + /// Enables colored output only when the output is going to a terminal or TTY with support. + Auto, + + /// Enables colored output regardless of the detected environment. + Always, + + /// Disables colored output. + Never, +} + +impl ColorChoice { + fn to_anstream(&self) -> anstream::ColorChoice { + match self { + Self::Auto => anstream::ColorChoice::Auto, + Self::Always => anstream::ColorChoice::Always, + Self::Never => anstream::ColorChoice::Never, + } + } +} + #[derive(Subcommand)] #[allow(clippy::large_enum_variant)] enum Commands { @@ -558,6 +590,8 @@ async fn inner() -> Result { if cli.no_color { anstream::ColorChoice::write_global(anstream::ColorChoice::Never); + } else { + anstream::ColorChoice::write_global(cli.color.to_anstream()); } miette::set_hook(Box::new(|_| {