Add style::force_color_output()
API to override NO_COLOR. (#802)
This commit is contained in:
parent
00f7d06151
commit
f3c0754bf5
12
src/style.rs
12
src/style.rs
@ -166,6 +166,18 @@ pub fn available_color_count() -> u16 {
|
|||||||
.unwrap_or(8)
|
.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.
|
/// A command that sets the the foreground color.
|
||||||
///
|
///
|
||||||
/// See [`Color`](enum.Color.html) for more info.
|
/// See [`Color`](enum.Color.html) for more info.
|
||||||
|
@ -86,7 +86,6 @@ impl Colored {
|
|||||||
ANSI_COLOR_DISABLED.load(Ordering::SeqCst)
|
ANSI_COLOR_DISABLED.load(Ordering::SeqCst)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub fn set_ansi_color_disabled(val: bool) {
|
pub fn set_ansi_color_disabled(val: bool) {
|
||||||
// Force the one-time initializer to run.
|
// Force the one-time initializer to run.
|
||||||
_ = Self::ansi_color_disabled_memoized();
|
_ = Self::ansi_color_disabled_memoized();
|
||||||
|
Loading…
Reference in New Issue
Block a user