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

scarb-ui: Add methods for accessing stderr color preferences #1065

Merged
merged 1 commit into from
Jan 19, 2024
Merged
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
19 changes: 19 additions & 0 deletions utils/scarb-ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,23 @@ impl Ui {
pub fn has_colors_enabled(&self) -> bool {
console::colors_enabled()
}

/// Forces colorization on or off for stdout.
///
/// This overrides the default for the current process and changes the return value of
/// the [`Ui::has_colors_enabled`] function.
pub fn force_colors_enabled_stderr(&self, enable: bool) {
console::set_colors_enabled_stderr(enable);
}

/// Returns `true` if colors should be enabled for stderr.
///
/// This honors the [clicolors spec](http://bixense.com/clicolors/).
///
/// * `CLICOLOR != 0`: ANSI colors are supported and should be used when the program isn't piped.
/// * `CLICOLOR == 0`: Don't output ANSI color escape codes.
/// * `CLICOLOR_FORCE != 0`: ANSI colors should be enabled no matter what.
pub fn has_colors_enabled_stderr(&self) -> bool {
console::colors_enabled_stderr()
}
}