use keybinds::{Key, KeyInput, Keybinds};
use std::io::{self, Read};
#[derive(Debug)]
enum Action {
SayHello,
ExitApp,
}
fn main() -> io::Result<()> {
let mut keybinds = Keybinds::default();
keybinds.bind("h e l l o", Action::SayHello).unwrap();
keybinds.bind("Esc", Action::ExitApp).unwrap();
println!("Type inputs and send it by hitting Enter key. Send Esc to exit");
for b in io::stdin().lock().bytes() {
let input = match b? {
b'\x1b' => KeyInput::from(Key::Esc),
b => KeyInput::from(b as char),
};
println!("Key input: {input:?}");
if let Some(action) = keybinds.dispatch(input) {
println!("Dispatched action: {action:?}");
match action {
Action::SayHello => println!("Hello!"),
Action::ExitApp => break,
}
}
}
Ok(())
}