#[path = "./backend/mod.rs"]
mod backend;
#[path = "./action.rs"]
mod action;
use crate::backend::{print, quit, run};
use action::Action;
use keymap::{DerivedConfig, KeyMapConfig};
pub(crate) const CONFIG: &str = r#"
Jump = { keys = ["j"], description = "Jump!" }
"#;
fn main() -> std::io::Result<()> {
println!("# Example: Key Group Capturing using .get_bound()");
println!("- Press any key to see it captured by Action::Shoot(char)");
println!("- Press 'j' to see Action::Jump (unit variant)");
println!("- Press 'q' or 'esc' to quit");
let config: DerivedConfig<Action> = toml::from_str(CONFIG).unwrap();
run(|key| match config.get_bound(&key) {
Some(action) => match action {
Action::Quit => quit("quit!"),
Action::Shoot(c) => print(&format!("Matched @any! Captured character: '{c}'")),
Action::Jump | Action::Up | Action::Down | Action::Left | Action::Right => {
print(&format!(
"Action: {action:?} (Description: {})",
action.keymap_item().description
))
}
},
None => print(&format!("Unknown key {key:?}")),
})
}