slightly improved structure and added a few more elements

This commit is contained in:
2025-06-27 12:10:25 -05:00
parent dfb17ab48e
commit 15b61d57c8
11 changed files with 242 additions and 14 deletions
+9 -6
View File
@@ -1,16 +1,19 @@
use crossterm::event::{KeyCode, KeyModifiers};
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use crate::{
event,
events::{Close, EventManager},
events::{Close, Event, EventManager},
extensions::Extension,
Screen,
};
event!(KeyPress(pub crossterm::event::KeyEvent));
impl Event for KeyEvent {
fn as_any(self: Box<Self>) -> Box<dyn std::any::Any> {
self
}
}
pub trait KeyPressEventHandler {
fn on_keypress(&mut self, event: KeyPress);
fn on_keypress(&mut self, event: Box<KeyEvent>);
}
pub struct KeyPressExtension;
@@ -36,7 +39,7 @@ impl Extension for KeyPressExtension {
if e.modifiers.contains(KeyModifiers::CONTROL) && e.code == KeyCode::Char('c') {
events.dispatch(Close);
} else {
events.dispatch(KeyPress(e));
events.dispatch(e);
}
}
_ => {}