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
use colored::*;
pub struct Colorizer;
impl Colorizer {
pub fn colorize_used(input: String, percent_disk: f64) -> ColoredString {
if percent_disk > 90.0 {
input.red()
} else if percent_disk > 75.0 {
input.yellow()
} else {
input.green()
}
}
pub fn colorize_cached(input: String, percent_disk: f64) -> ColoredString {
if percent_disk > 80.0 {
input.on_magenta()
} else {
input.on_blue()
}
}
pub fn colorize_bar(
bar_length: usize,
bar_unit: &str,
bar_units_usage: usize,
bar_units_cache: usize,
percent_usage: f64,
percent_cache: f64,
) -> String {
let mut result = "".to_string();
for i in 0..bar_length {
if i < bar_units_usage {
result = format!(
"{}{}",
result,
Colorizer::colorize_used(bar_unit.to_string(), percent_usage)
);
} else {
result = format!("{}{}", result, bar_unit.white().dimmed());
}
if i < bar_units_cache {
result = format!("{}", Colorizer::colorize_cached(result, percent_cache));
}
}
result
}
}