1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Terminal I/O, with colors!

use std::io::Write;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};

/// Print an OK message, in green.
pub fn print_ok(msg: &str) {
    let mut stdout = StandardStream::stdout(ColorChoice::Auto);

    stdout
        .set_color(ColorSpec::new().set_fg(Some(Color::Green)))
        .expect("set color");
    writeln!(&mut stdout, "OK    {}", msg).expect("write message");

    stdout.reset().expect("reset color");
}

/// Print a warning message, in yellow.
pub fn print_warn(msg: &str) {
    let mut stdout = StandardStream::stdout(ColorChoice::Auto);

    stdout
        .set_color(ColorSpec::new().set_fg(Some(Color::Yellow)))
        .expect("set color");
    writeln!(&mut stdout, "WARN  {}", msg).expect("write message");

    stdout.reset().expect("reset color");
}

/// Print a warning message, in red.
pub fn print_err(msg: &str) {
    let mut stdout = StandardStream::stdout(ColorChoice::Auto);

    stdout
        .set_color(ColorSpec::new().set_fg(Some(Color::Red)))
        .expect("set color");
    writeln!(&mut stdout, "ERROR {}", msg).expect("write message");

    stdout.reset().expect("reset color");
}