diff --git a/src/app/app.rs b/src/app/app.rs index c223eee..f9bb9f9 100644 --- a/src/app/app.rs +++ b/src/app/app.rs @@ -1,8 +1,5 @@ use crate::{ - app::{ - GameStates, - keybindings::{Action, event_to_action, main_menu_keybindings}, - }, + app::{GameStates, handle_keybindings}, cli::Cli, }; use clap::ValueEnum; @@ -103,21 +100,7 @@ impl App { } fn handle_key_event(&mut self, key_event: KeyEvent) -> Result<()> { - match self.view { - View::MainMenu => main_menu_keybindings(self, &key_event), - _ => { - if let Some(action) = event_to_action(&key_event) { - match action { - Action::Quit => self.exit = true, - Action::Quit2 => self.exit = true, - Action::Esc => self.view = View::MainMenu, - _ => (), - } - } - } - } - - Ok(()) + handle_keybindings(self, key_event) } } diff --git a/src/app/keybind.rs b/src/app/keybind.rs new file mode 100644 index 0000000..91b21e6 --- /dev/null +++ b/src/app/keybind.rs @@ -0,0 +1,24 @@ +use crate::app::{ + App, View, + keybindings::{Action, event_to_action, main_menu_keybindings}, +}; +use ratatui::crossterm::event::KeyEvent; +use std::io::Result; + +pub fn handle_keybindings(app: &mut App, key_event: KeyEvent) -> Result<()> { + match app.view { + View::MainMenu => main_menu_keybindings(app, &key_event), + _ => { + if let Some(action) = event_to_action(&key_event) { + match action { + Action::Quit => app.exit = true, + Action::Quit2 => app.exit = true, + Action::Esc => app.view = View::MainMenu, + _ => (), + } + } + } + } + + Ok(()) +} diff --git a/src/app/mod.rs b/src/app/mod.rs index 745c56a..56c8397 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,5 +1,6 @@ pub mod app; pub mod game_states; +pub mod keybind; pub mod keybindings; pub mod widget; pub mod widgets; @@ -8,3 +9,4 @@ pub use app::{App, Event, GameMode, PerkDecks, View, handle_input_events}; pub use game_states::{ GameStates, MainMenuState, PerkDecksState, SettingsState, SkillsConfigState, SkirmishState, }; +pub use keybind::handle_keybindings;