Skip to content

Commit

Permalink
Implement ValueEnum for ColorChoice
Browse files Browse the repository at this point in the history
  • Loading branch information
tmccombs committed Nov 3, 2022
1 parent 033438e commit 2ca618d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/util/color.rs
@@ -1,3 +1,6 @@
use crate::builder::PossibleValue;
use crate::derive::ValueEnum;

/// Represents the color preferences for program output
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum ColorChoice {
Expand Down Expand Up @@ -60,3 +63,17 @@ impl Default for ColorChoice {
Self::Auto
}
}

impl ValueEnum for ColorChoice {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Auto, Self::Always, Self::Never]
}

fn to_possible_value(&self) -> Option<PossibleValue> {
Some(match self {
Self::Auto => PossibleValue::new("auto").help("Enables colored output only when the output is going to a terminal/TTY"),
Self::Always => PossibleValue::new("always").help("Enables colored output regardless of whether or not the output is going to a terminal/TTY"),
Self::Never => PossibleValue::new("never").help("Disables colored output regardless of whether or not the output is going to a terminal/TTY"),
})
}
}

0 comments on commit 2ca618d

Please sign in to comment.