Pass actions to components
This commit is contained in:
parent
832eb17a68
commit
0c5e8ab544
@ -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(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
#[derive(Default, Clone, Copy)]
|
||||
#[derive(Default, Clone)]
|
||||
pub enum AppAction {
|
||||
StatusBarMessage(String),
|
||||
StatusBarError(String),
|
||||
StatusBarInput(String),
|
||||
#[default]
|
||||
Quit,
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ pub trait Component {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn handle_action(&mut self, action: AppAction) {}
|
||||
|
||||
#[allow(unused)]
|
||||
fn handle_event(&mut self, event: AppEvent) -> Result<Option<AppAction>> {
|
||||
match event {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user