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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use colored::Colorize;
static mut SECTION: i32 = 0;
#[inline]
pub fn title(title: &str, term_width: usize) {
let title = title.to_uppercase();
let (left_bar, right_bar) = if term_width < ((title.len() * 2) + 11) {
(4, 4)
} else {
let left_bar = (term_width - (title.len() * 2) - 3) / 2;
(left_bar, term_width - (title.len() * 2) - 3 - left_bar)
};
print!("{} ", "\u{2588}".repeat(left_bar));
for (pos, ch) in title.chars().enumerate() {
match pos % 6 {
0 => print!(" {}", format!("{}", ch).bright_red().bold()),
1 => print!(" {}", format!("{}", ch).bright_yellow().bold()),
2 => print!(" {}", format!("{}", ch).bright_green().bold()),
3 => print!(" {}", format!("{}", ch).bright_cyan().bold()),
4 => print!(" {}", format!("{}", ch).bright_blue().bold()),
5 => print!(" {}", format!("{}", ch).bright_magenta().bold()),
_ => unreachable!(),
}
}
println!(" {}", "\u{2588}".repeat(right_bar));
}
#[inline]
pub fn section(title: &str, term_width: usize) {
let title = title.to_uppercase();
unsafe {
SECTION += 1;
}
print!("====");
print!(" {}", colour(&title).bold());
let mut cur_len = 5 + title.len();
if cur_len >= term_width {
println!();
return;
}
print!(" ");
cur_len += 1;
while cur_len < term_width {
print!("=");
cur_len += 1;
}
println!();
}
#[inline]
pub fn sub_section(title: &str, term_width: usize) {
println!(
"---- {} {}",
colour(title).bold(),
"-".repeat(term_width - 6 - title.len())
);
}
#[inline]
pub fn sub_sub_section(title: &str) {
println!("---- {}", colour(title));
}
#[inline]
#[must_use]
fn colour(string: &str) -> String {
match unsafe { SECTION } % 6 {
0 => format!("{}", string.bright_magenta()),
1 => format!("{}", string.bright_red()),
2 => format!("{}", string.bright_yellow()),
3 => format!("{}", string.bright_green()),
4 => format!("{}", string.bright_cyan()),
5 => format!("{}", string.bright_blue()),
_ => unreachable!(),
}
}