generated from GarandPLG/rust-flake-template
Consolidate event handling into events.rs
The event loop function is now defined in `events.rs`, the redundant `handle_events.rs` file is removed, and the module re‑exports are updated to expose `handle_events` from `events`.
This commit is contained in:
@@ -1,6 +1,30 @@
|
||||
use ratatui::crossterm::event::KeyEvent;
|
||||
use ratatui::crossterm::event::{Event, read};
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub enum AppEvent {
|
||||
Input(KeyEvent),
|
||||
Resize(u16, u16),
|
||||
}
|
||||
|
||||
/// Reads *all* crossterm events and forwards the ones we care about.
|
||||
pub fn handle_events(tx: Sender<AppEvent>) {
|
||||
loop {
|
||||
match read() {
|
||||
Ok(ev) => match ev {
|
||||
Event::Key(key) => {
|
||||
if tx.send(AppEvent::Input(key)).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Event::Resize(cols, rows) => {
|
||||
if tx.send(AppEvent::Resize(cols, rows)).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
Err(_) => continue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user