Added ExtensionContext #26

This commit is contained in:
2025-08-04 04:45:55 -05:00
parent 14602f95c8
commit 48397c06fa
5 changed files with 68 additions and 22 deletions
+5 -6
View File
@@ -1,20 +1,19 @@
use crate::extensions::Extension;
use crate::extensions::{Extension, ExtensionContext};
pub struct InputExtension;
impl Extension for InputExtension {
fn init(&mut self, screen: std::sync::Arc<crate::Screen>) {
fn init(&mut self, ctx: &ExtensionContext) {
let ctx = ctx.clone();
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() {
widget.event(&e);
}
ctx.event(&e);
}
});
}
fn on_close(&mut self, _screen: std::sync::Arc<crate::Screen>) {
fn on_close(&mut self) {
crossterm::terminal::disable_raw_mode().unwrap();
}
}