Skip to content

Commit

Permalink
scarb-ui: Add methods for accessing stderr color preferences
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Kaput <[email protected]>
  • Loading branch information
mkaput committed Jan 18, 2024
1 parent e1ecf0b commit 3bbf1b1
Showing 1 changed file with 19 additions and 0 deletions.
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()
}
}

0 comments on commit 3bbf1b1

Please sign in to comment.