Refactor to View enum and add keybindings

Replace the `default_window` string field with a `View` enum throughout
the
application. Introduce a new keybinding module providing `Action`,
`KeyBinding` structs and helper functions, and integrate a keybindings
widget
into the main menu. Update the CLI to accept a `View` value enum and
adjust
imports and event handling accordingly. Add a release profile in
`Cargo.toml` with LTO, single codegen unit, higher optimisation level
and
binary stripping for smaller, faster builds.
This commit is contained in:
2026-03-10 14:26:18 +01:00
parent 64eb906b5f
commit de42569a51
10 changed files with 147 additions and 43 deletions
+21 -4
View File
@@ -1,6 +1,8 @@
use crate::app::{Action, event_to_action};
use clap::ValueEnum;
use ratatui::{
DefaultTerminal, Frame,
crossterm::event::{self, KeyCode, KeyEvent, KeyEventKind},
crossterm::event::{self, KeyEvent},
};
use std::{
io::Result,
@@ -9,7 +11,7 @@ use std::{
pub struct App {
pub exit: bool,
pub default_window: String,
pub window: View,
pub username: String,
pub game_mode: String,
pub map_width: u8,
@@ -22,6 +24,15 @@ pub struct App {
pub skill_points_limit: u16,
}
#[derive(Debug, Clone, ValueEnum)]
pub enum View {
MainMenu,
Skirmish,
PerkDecks,
SkillsConfig,
Settings,
}
pub enum Event {
Input(KeyEvent),
}
@@ -48,8 +59,14 @@ impl App {
}
fn handle_key_event(&mut self, key_event: KeyEvent) -> Result<()> {
if key_event.kind == KeyEventKind::Press && key_event.code == KeyCode::Char('q') {
self.exit = true;
// if key_event.kind == KeyEventKind::Press && key_event.code == KeyCode::Char('q') {
// self.exit = true;
// }
if let Some(action) = event_to_action(&key_event) {
match action {
Action::Quit => self.exit = true,
}
}
Ok(())