aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2024-03-11 09:21:46 -0400
committerShav Kinderlehrer <[email protected]>2024-03-11 09:21:46 -0400
commit0c5e8ab544823fbb4936c536ee1d8a66298f7e51 (patch)
tree438182a818577a80e01bba75ff19e2847bc3ec47
parent832eb17a68e37f287206ec319a316ea91247808a (diff)
downloadmolehole-0c5e8ab544823fbb4936c536ee1d8a66298f7e51.tar.gz
Pass actions to components
-rw-r--r--src/app.rs6
-rw-r--r--src/app_action.rs5
-rw-r--r--src/component.rs3
-rw-r--r--src/components/global_keys.rs2
-rw-r--r--src/main.rs3
5 files changed, 15 insertions, 4 deletions
diff --git a/src/app.rs b/src/app.rs
index 17c8bc3..5e6ab1f 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -128,6 +128,12 @@ impl App {
fn handle_action(&mut self, action: AppAction) -> Result<()> {
match action {
AppAction::Quit => Ok(self.quit()?),
+ _ => {
+ for component in &mut self.components {
+ component.handle_action(action.clone());
+ }
+ Ok(())
+ }
}
}
}
diff --git a/src/app_action.rs b/src/app_action.rs
index 8bbe9dd..93131ac 100644
--- a/src/app_action.rs
+++ b/src/app_action.rs
@@ -1,5 +1,8 @@
-#[derive(Default, Clone, Copy)]
+#[derive(Default, Clone)]
pub enum AppAction {
+ StatusBarMessage(String),
+ StatusBarError(String),
+ StatusBarInput(String),
#[default]
Quit,
}
diff --git a/src/component.rs b/src/component.rs
index 8ec7d26..65d865c 100644
--- a/src/component.rs
+++ b/src/component.rs
@@ -11,6 +11,9 @@ pub trait Component {
}
#[allow(unused)]
+ fn handle_action(&mut self, action: AppAction) {}
+
+ #[allow(unused)]
fn handle_event(&mut self, event: AppEvent) -> Result<Option<AppAction>> {
match event {
AppEvent::Key(key_event) => Ok(self.handle_key_event(key_event)?),
diff --git a/src/components/global_keys.rs b/src/components/global_keys.rs
index 6537339..d0a5800 100644
--- a/src/components/global_keys.rs
+++ b/src/components/global_keys.rs
@@ -77,7 +77,7 @@ impl Component for GlobalKeys {
for key_command in &mut self.key_commands {
if key_command.key_code == key_event {
- return Ok(key_command.action);
+ return Ok(key_command.action.clone());
}
}
}
diff --git a/src/main.rs b/src/main.rs
index 96ac2f0..ca87db6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,7 +10,6 @@ use eyre::Result;
fn main() -> Result<()> {
let mut app = app::App::new(std::time::Duration::from_millis(10))?;
- app.run()?;
- app.quit()
+ app.run()
}