Skip to content

Commit

Permalink
Add style::force_color_output() API to override NO_COLOR. (#802)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-vigor committed Aug 5, 2023
1 parent 00f7d06 commit f3c0754
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/style.rs
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/style/types/colored.rs
Expand Up @@ -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();
Expand Down

0 comments on commit f3c0754

Please sign in to comment.