diff --git a/src/style.rs b/src/style.rs index 9555cab..72c2281 100644 --- a/src/style.rs +++ b/src/style.rs @@ -166,6 +166,18 @@ pub fn available_color_count() -> u16 { .unwrap_or(8) } +/// Forces colored output on or off globally, overriding NO_COLOR. +/// +/// # Notes +/// +/// crossterm supports NO_COLOR (https://no-color.org/) to disabled colored output. +/// +/// This API allows applications to override that behavior and force colorized output +/// even if NO_COLOR is set. +pub fn force_color_output(enabled: bool) { + Colored::set_ansi_color_disabled(!enabled) +} + /// A command that sets the the foreground color. /// /// See [`Color`](enum.Color.html) for more info. diff --git a/src/style/types/colored.rs b/src/style/types/colored.rs index 2830d09..85f921b 100644 --- a/src/style/types/colored.rs +++ b/src/style/types/colored.rs @@ -86,7 +86,6 @@ impl Colored { ANSI_COLOR_DISABLED.load(Ordering::SeqCst) } - #[cfg(test)] pub fn set_ansi_color_disabled(val: bool) { // Force the one-time initializer to run. _ = Self::ansi_color_disabled_memoized();