Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading