/
bootlog.rs
56 lines (48 loc) 路 1.71 KB
/
bootlog.rs
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
/// Module that pretends to boot a system.
use rand::prelude::*;
use yansi::Paint;
use crate::parse_args::AppConfig;
use crate::utils::{csleep, dprint};
use crate::BOOTLOG_LIST;
pub fn run(appconfig: &AppConfig) {
let mut rng = thread_rng();
let num_lines = rng.gen_range(50, 200);
let mut burst_mode = false;
let mut count_burst_lines = 0;
for _ in 1..num_lines {
let choice = BOOTLOG_LIST.choose(&mut rng).unwrap_or(&"");
let mut line_sleep_length = rng.gen_range(10, 1000);
let mut char_sleep_length = 5;
let burst_lines = rng.gen_range(10, 50);
if burst_mode && count_burst_lines < burst_lines {
line_sleep_length = 30;
char_sleep_length = 0;
} else if count_burst_lines == burst_lines {
burst_mode = false;
count_burst_lines = 0;
} else if !burst_mode {
burst_mode = rng.gen_bool(1.0 / 20.0);
}
let is_error = rng.gen_bool(0.01);
if is_error {
dprint(format!("{}", Paint::red(format!("ERROR: {}", choice))), 10);
} else {
let has_bold_word = rng.gen_bool(0.1);
if has_bold_word {
let mut words: Vec<String> = choice.split_whitespace().map(String::from).collect();
words[0] = format!("{}", Paint::new(&words[0]).bold());
dprint(words.join(" ").to_string(), char_sleep_length);
} else {
dprint(choice.to_string(), char_sleep_length);
}
}
println!();
if burst_mode {
count_burst_lines += 1;
}
csleep(line_sleep_length);
if appconfig.should_exit() {
return;
}
}
}