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
41
42
43
44
45
46
47
48
//! Fancy progress bar functionality.

use console::style;
use emoji;

/// Synchronized progress bar and status message printing.
pub struct ProgressOutput;

impl ProgressOutput {
    /// Print the given message.
    fn message(&self, message: &str) {
        eprintln!("{}", message);
    }

    /// Add an informational message.
    pub fn info(&self, message: &str) {
        let info = format!("{}: {}", style("[INFO]").bold().dim(), message,);
        self.message(&info);
    }

    /// Add a warning message.
    pub fn warn(&self, message: &str) {
        let warn = format!(
            "{} {}: {}",
            emoji::WARN,
            style("[WARN]").bold().dim(),
            message
        );
        self.message(&warn);
    }

    /// Add an error message.
    pub fn error(&self, message: &str) {
        let err = format!(
            "{} {}: {}",
            emoji::ERROR,
            style("[ERR]").bold().dim(),
            message
        );
        self.message(&err);
    }
}

impl Default for ProgressOutput {
    fn default() -> Self {
        ProgressOutput
    }
}