From 3bbf1b11281be9ae5402ac04806dd91c5cd36752 Mon Sep 17 00:00:00 2001 From: Marek Kaput Date: Thu, 18 Jan 2024 12:09:25 +0100 Subject: [PATCH] scarb-ui: Add methods for accessing stderr color preferences Signed-off-by: Marek Kaput --- utils/scarb-ui/src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/utils/scarb-ui/src/lib.rs b/utils/scarb-ui/src/lib.rs index 78a2fb8b5..5278192d2 100644 --- a/utils/scarb-ui/src/lib.rs +++ b/utils/scarb-ui/src/lib.rs @@ -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() + } }