From 6e6181887c890e46fccf4fbbd086a4add65f7fca Mon Sep 17 00:00:00 2001 From: GarandPLG Date: Thu, 9 Apr 2026 10:07:24 +0200 Subject: [PATCH] Consolidate event handling into events.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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`. --- src/app/threads/events.rs | 24 ++++++++++++++++++++++++ src/app/threads/handle_events.rs | 25 ------------------------- src/app/threads/mod.rs | 4 +--- 3 files changed, 25 insertions(+), 28 deletions(-) delete mode 100644 src/app/threads/handle_events.rs diff --git a/src/app/threads/events.rs b/src/app/threads/events.rs index d18136e..57f17c4 100644 --- a/src/app/threads/events.rs +++ b/src/app/threads/events.rs @@ -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) { + 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, + } + } +} diff --git a/src/app/threads/handle_events.rs b/src/app/threads/handle_events.rs deleted file mode 100644 index 27d7b1f..0000000 --- a/src/app/threads/handle_events.rs +++ /dev/null @@ -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) { - 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, - } - } -} diff --git a/src/app/threads/mod.rs b/src/app/threads/mod.rs index e2798ce..96543b9 100644 --- a/src/app/threads/mod.rs +++ b/src/app/threads/mod.rs @@ -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};