Add style::force_color_output() API to override NO_COLOR. (#802)

This commit is contained in:
Kevin Vigor 2023-08-05 07:38:17 -06:00 committed by GitHub
parent 00f7d06151
commit f3c0754bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -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.

View File

@ -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();