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:
2026-04-09 10:07:24 +02:00
parent 1be72a4596
commit 6e6181887c
3 changed files with 25 additions and 28 deletions
+24
View File
@@ -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,
}
}
}
-25
View File
@@ -1,25 +0,0 @@
use crate::app::threads::AppEvent;
use ratatui::crossterm::event::{Event, read};
use std::sync::mpsc::Sender;
/// 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,
}
}
}
+1 -3
View File
@@ -1,7 +1,5 @@
pub mod audio;
pub mod events;
pub mod handle_events;
pub use audio::{AudioCmd, SoundrackParts, Soundtrack, handle_audio};
pub use events::AppEvent;
pub use handle_events::handle_events;
pub use events::{AppEvent, handle_events};