bitwarden_cli/
color.rs

1use clap::ValueEnum;
2
3/// Color configuration for the CLI
4#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
5pub enum Color {
6    /// Force colors off
7    No,
8    /// Force colors on
9    Yes,
10    /// Automatically detect if colors are supported in the terminal.
11    Auto,
12}
13
14impl Color {
15    /**
16     * Evaluate if colors are supported
17     */
18    pub fn is_enabled(self) -> bool {
19        match self {
20            Color::No => false,
21            Color::Yes => true,
22            Color::Auto => supports_color::on(supports_color::Stream::Stdout).is_some(),
23        }
24    }
25}
26
27/**
28 * Installs color_eyre, if Color is disabled we use an empty theme to disable error colors.
29 */
30pub fn install_color_eyre(color: Color) -> color_eyre::Result<(), color_eyre::Report> {
31    if color.is_enabled() {
32        color_eyre::install()
33    } else {
34        // Use an empty theme to disable error coloring
35        color_eyre::config::HookBuilder::new()
36            .theme(color_eyre::config::Theme::new())
37            .install()
38    }
39}