1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use crossterm::{cursor, ExecutableCommand};

pub mod loading_bar;
pub mod cli;
pub mod basic_counters;

pub fn on_key_press(expected_key: char, mut f: impl FnMut() -> bool) {
    use crossterm::{terminal, event::{self, Event, KeyCode}};
    terminal::enable_raw_mode().unwrap();
    loop {
        if let Event::Key(key) = event::read().unwrap() {
            match key.code {
                KeyCode::Char(x) if expected_key == x => if f() { break },
                KeyCode::Char('x') | KeyCode::Esc | KeyCode::Char('c') | KeyCode::Char('q') => break,
                _ => (),
            }
        }
    } terminal::disable_raw_mode().unwrap();
    std::io::stdout().execute(cursor::Show).unwrap();
}