use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use std::io::Write;
fn better_todo(todo: &str) {
let mut stdout = StandardStream::stdout(ColorChoice::Always);
let mut color_spec = ColorSpec::new();
color_spec.set_fg(Some(Color::Red));
stdout.set_color(&color_spec).unwrap();
writeln!(&mut stdout, "{}", todo).unwrap();
}
fn color_print(msg: &str, mut color: &str ) {
let color_conversion: Color = match color.to_lowercase().as_str() {
"black" => Color::Black,
"blue" => Color::Blue,
"green" => Color::Green,
"red" => Color::Red,
"cyan" => Color::Cyan,
"magenta" => Color::Magenta,
"yellow" => Color::Yellow,
"white" => Color::White,
_ => unreachable!(),
};
let mut stdout = StandardStream::stdout(ColorChoice::Always);
let mut color_spec = ColorSpec::new();
color_spec.set_fg(Some(color_conversion));
stdout.set_color(&color_spec).unwrap();
writeln!(&mut stdout, "{}", msg).unwrap();
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_better_todo() {
let result = better_todo("hi testing");
assert_eq!(result, ());
}
#[test]
fn test_color_print() {
let result = color_print("hi testing", "blue");
assert_eq!(result, ());
}
#[test]
fn test_color_print_capitalization() {
let result = color_print("hi testing", "BLUE");
assert_eq!(result, ());
}
}