#[path = "./backend/mod.rs"]
mod backend;
#[path = "./action.rs"]
mod action;
use crate::backend::{print, quit, run};
use action::Action;
use keymap::{Config, KeyMapConfig};
pub(crate) const CONFIG: &str = r#"
Jump = { keys = ["j"], description = "Jump Jump!" }
Quit = { keys = ["esc"], description = "Quit with ESC only!" }
"#;
fn main() -> std::io::Result<()> {
println!("# Example: External configuration with Config<T>");
let config: Config<Action> = toml::from_str(CONFIG).unwrap();
run(|key| match config.get(&key) {
Some(action) => match action {
Action::Quit => quit("quit!"),
Action::Up | Action::Down | Action::Left | Action::Right | Action::Jump => print(
&format!("{action:?} = {}", action.keymap_item().description),
),
Action::Shoot(_) => print("Shoot! (Use .get_bound() to capture the character)"),
},
None => print(&format!("Unknown key {key:?}")),
})
}