rustian_roulette/
printer.rs

1use std::io::{self, Write};
2use std::process::exit;
3use std::thread;
4use std::time::Duration;
5
6pub fn confirmation() {
7    print!("If you are unlucky, this will delete random file(s) in above path. Are you sure you want to play? <Y,y,YES,yes>: ");
8    io::stdout().flush().unwrap();
9    let mut input = String::new();
10    io::stdin()
11        .read_line(&mut input)
12        .expect("failed to read input");
13
14    match input.trim().as_ref() {
15        "Y" | "YES" | "y" | "yes" => {
16            return;
17        }
18        _ => {
19            println!("Probably a wise choice...");
20            exit(0);
21        }
22    };
23}
24
25pub fn print_prob(path: &str, chambers: usize) {
26    println!(
27        "Path = {}, Chances = 1/{} ({:.2}%)",
28        path,
29        chambers,
30        (1.0 / chambers as f32) * 100.0,
31    );
32}
33pub fn count_down(from: usize, file: &str) {
34    for i in (1..=from).rev() {
35        print!("\r");
36        io::stdout().flush().unwrap();
37        print!(
38            "{} {} {}{} \x1b[0;31m{}\x1b[0m ",
39            "_".repeat(file.len() + 4),
40            '\u{1F52B}',
41            "-".repeat(i - 1),
42            '\u{1F525}',
43            i
44        );
45        io::stdout().flush().unwrap();
46        thread::sleep(Duration::from_secs(1));
47    }
48    print!("\r");
49    io::stdout().flush().unwrap();
50    print!("{}\n", " ".repeat(100));
51}
52
53pub fn rest_in_peace(file: &str) {
54    println!(
55        "{}{}\x1b[0;31m{}\x1b[0m{}{} *BANG*\n",
56        '\u{271D}', '\u{1F480}', file, '\u{1F480}', '\u{271D}'
57    );
58}
59
60pub fn alive(file: &str) {
61    println!(
62        "{}{}\x1b[033;92m{}\x1b[0m{}{} *CLICK*\n",
63        '\u{1F340}', '\u{1F340}', file, '\u{1F340}', '\u{1F340}'
64    );
65}