Skip to content

Commit

Permalink
Add style::force_color_output() API to override NO_COLOR.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-vigor committed Jul 28, 2023
1 parent 1efdce7 commit 5c4686c
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 5c4686c

Please sign in to comment.