use ansi_term::{Colour, Style};
use serde::Deserialize;
use std::env;
#[derive(Clone, Copy, Deserialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum Color {
Always,
Never,
Auto,
}
impl Color {
pub fn bold_fg(self, text: &str, colour: Colour) -> String {
if self.should_color() {
Style::new().bold().fg(colour).paint(text).to_string()
} else {
text.to_owned()
}
}
pub fn bold(self, text: &str) -> String {
if self.should_color() {
Style::new().bold().paint(text).to_string()
} else {
text.to_owned()
}
}
fn should_color(self) -> bool {
match self {
Self::Always => true,
Self::Never => false,
Self::Auto => match env::var_os("TERM") {
None => false,
Some(k) if k == "dumb" => false,
Some(_) if env::var_os("NO_COLOR").is_some() => false,
Some(_) => true,
},
}
}
}