input handling #17

This commit is contained in:
2025-08-02 06:47:03 -05:00
parent d00fbb6565
commit 911968a1cb
4 changed files with 30 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
use crate::{extensions::Extension, prelude::Handler};
pub struct InputExtension;
impl Extension for InputExtension {
fn init(&mut self, screen: std::sync::Arc<crate::Screen>) {
crossterm::terminal::enable_raw_mode().unwrap();
std::thread::spawn(move || loop {
if let Ok(e) = crossterm::event::read() {
for widget in screen.widgets.lock().unwrap().iter() {
if let Some(h) = widget.get::<Handler<crossterm::event::Event>>() {
h.call(widget, &e);
}
}
}
});
}
}
impl crate::extensions::Event for crossterm::event::Event {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}