From c2acb446e7868b67e5743d54cee5c64c469e5a18 Mon Sep 17 00:00:00 2001 From: Shav Kinderlehrer Date: Wed, 6 Mar 2024 14:14:07 -0500 Subject: Add keyboard commands --- src/app.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/app.rs') diff --git a/src/app.rs b/src/app.rs index 22a8c40..a1fd1e4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -6,12 +6,14 @@ use crate::app_action::AppAction; use crate::app_event::AppEvent; use crate::component::Component; use crate::components; +use crate::keys::key_commands::KeyCommand; use crate::tui; pub struct App { pub tui: tui::Tui, pub tick_rate: Duration, pub components: Vec>, + pub key_commands: Vec, should_quit: bool, } @@ -20,13 +22,24 @@ impl App { pub fn new(tick_rate: Duration) -> Result { let tui = tui::init()?; - let global_keys = components::global_keys::GlobalKeys::default(); + let mut key_commands = vec![KeyCommand { + key_code: "q".to_string(), + description: "Quit molehole".to_string(), + action: Some(AppAction::Quit), + }]; + + let global_keys = components::global_keys::GlobalKeys { + key_commands: key_commands.clone(), + ..Default::default() + }; let hello_world = components::hello_world::HelloWorld::default(); Ok(Self { tui, tick_rate, components: vec![Box::new(hello_world), Box::new(global_keys)], + key_commands, + should_quit: false, }) } -- cgit v1.2.3