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::KeyEvent;
|
||||||
|
use ratatui::crossterm::event::{Event, read};
|
||||||
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
pub enum AppEvent {
|
pub enum AppEvent {
|
||||||
Input(KeyEvent),
|
Input(KeyEvent),
|
||||||
Resize(u16, u16),
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -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,7 +1,5 @@
|
|||||||
pub mod audio;
|
pub mod audio;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod handle_events;
|
|
||||||
|
|
||||||
pub use audio::{AudioCmd, SoundrackParts, Soundtrack, handle_audio};
|
pub use audio::{AudioCmd, SoundrackParts, Soundtrack, handle_audio};
|
||||||
pub use events::AppEvent;
|
pub use events::{AppEvent, handle_events};
|
||||||
pub use handle_events::handle_events;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user