diff --git a/Cargo.lock b/Cargo.lock index 9d69fa63..401f768c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,7 +101,7 @@ dependencies = [ "anstyle-parse", "anstyle-wincon", "concolor-override", - "concolor-query 0.2.0", + "concolor-query 0.3.0", "criterion", "is-terminal", "owo-colors", @@ -313,9 +313,9 @@ checksum = "82a90734b3d5dcf656e7624cca6bce9c3a90ee11f900e80141a7427ccfb3d317" [[package]] name = "concolor-query" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71cd70b9f86dd588a4a08471ebbd5847cb25f0116aaddeace95470cce096ff7d" +checksum = "534eb40da54945b820debad8620cdcf0b2be6f174f139d34f373a29ab688a1d3" dependencies = [ "windows-sys 0.45.0", ] diff --git a/crates/anstyle-stream/Cargo.toml b/crates/anstyle-stream/Cargo.toml index 09cbfc0b..f068191a 100644 --- a/crates/anstyle-stream/Cargo.toml +++ b/crates/anstyle-stream/Cargo.toml @@ -34,7 +34,7 @@ anstyle = { version = "0.3.0", path = "../anstyle" } anstyle-parse = { version = "0.1.0", path = "../anstyle-parse" } anstyle-wincon = { version = "0.1.0", path = "../anstyle-wincon", optional = true } concolor-override = { version = "1.0.0", optional = true } -concolor-query = { version = "0.2.0", optional = true } +concolor-query = { version = "0.3.0", optional = true } is-terminal = { version = "0.4.4", optional = true } utf8parse = "0.2.1" diff --git a/crates/anstyle-stream/src/auto.rs b/crates/anstyle-stream/src/auto.rs index 84dabd15..88129c9e 100644 --- a/crates/anstyle-stream/src/auto.rs +++ b/crates/anstyle-stream/src/auto.rs @@ -30,7 +30,15 @@ where pub fn new(raw: S, choice: ColorChoice) -> Self { match choice { ColorChoice::Auto => { - if raw.is_terminal() { + let clicolor = concolor_query::clicolor(); + let clicolor_enabled = clicolor.unwrap_or(false); + let clicolor_disabled = !clicolor.unwrap_or(true); + if raw.is_terminal() + && !concolor_query::no_color() + && !clicolor_disabled + && (concolor_query::term_supports_color() || clicolor_enabled) + || concolor_query::clicolor_force() + { Self::always(raw) } else { Self::never(raw) @@ -71,16 +79,21 @@ where /// Force color, no matter what the inner `Write` supports. #[inline] pub fn always(raw: S) -> Self { - #[cfg(feature = "wincon")] - { - if raw.is_terminal() && !concolor_query::windows::enable_ansi_colors().unwrap_or(true) { + if cfg!(windows) { + #[cfg(feature = "auto")] + let use_wincon = raw.is_terminal() + && !concolor_query::windows::enable_ansi_colors().unwrap_or(true) + && !concolor_query::term_supports_ansi_color(); + #[cfg(not(feature = "auto"))] + let use_wincon = true; + if use_wincon { Self::wincon(raw).unwrap_or_else(|raw| Self::always_ansi_(raw)) } else { Self::always_ansi_(raw) } + } else { + Self::always_ansi(raw) } - #[cfg(not(feature = "wincon"))] - Self::always_ansi(raw) } /// Only pass printable data to the inner `Write`. @@ -91,7 +104,6 @@ where } #[inline] - #[cfg(feature = "wincon")] fn wincon(raw: S) -> Result { #[cfg(feature = "wincon")] {