counter_cli/
lib.rs

1use crossterm::{cursor, ExecutableCommand};
2
3pub mod loading_bar;
4pub mod cli;
5pub mod basic_counters;
6
7pub fn on_key_press(expected_key: char, mut f: impl FnMut() -> bool) {
8    use crossterm::{terminal, event::{self, Event, KeyCode}};
9    terminal::enable_raw_mode().unwrap();
10    loop {
11        if let Event::Key(key) = event::read().unwrap() {
12            match key.code {
13                KeyCode::Char(x) if expected_key == x => if f() { break },
14                KeyCode::Char('x') | KeyCode::Esc | KeyCode::Char('c') | KeyCode::Char('q') => break,
15                _ => (),
16            }
17        }
18    } terminal::disable_raw_mode().unwrap();
19    std::io::stdout().execute(cursor::Show).unwrap();
20}