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
49
50
use console::{style, StyledObject};
#[derive(Default)]
pub struct Ui {
level: u32,
}
impl Ui {
pub fn nest(&self) -> Self {
Ui {
level: self.level + 1,
}
}
pub fn print_indent(&self) {
for _ in 0..self.level {
eprint!(" ");
}
}
pub fn get_indent(&self) -> String {
" ".repeat(self.level as usize)
}
pub fn println(&self, msg: &str) {
self.print_indent();
eprintln!("{msg}");
}
pub fn info(&self, msg: &str) {
self.print_with_indicator(style("[I]").blue(), msg);
}
pub fn warn(&self, msg: &str) {
self.print_with_indicator(style("[!]").yellow(), msg);
}
pub fn error(&self, msg: &str) {
self.print_with_indicator(style("[X]").red(), msg);
}
fn print_with_indicator(&self, indicator: StyledObject<&str>, msg: &str) {
self.print_indent();
eprintln!("{indicator} {msg}");
}
}