Refactor App to use unified AppChannels for events

App now receives an AppChannels struct; AppEvent enum removed.

Event handling, tick generation, and audio communication are now
performed through dedicated channels.
This commit is contained in:
2026-05-03 22:27:08 +02:00
parent 7fb001faab
commit 7541db79d8
9 changed files with 123 additions and 105 deletions
+11 -21
View File
@@ -1,30 +1,20 @@
use ratatui::crossterm::event::KeyEvent;
use ratatui::crossterm::event::{Event, read};
use ratatui::crossterm::event::{Event, KeyEvent, read};
use std::sync::mpsc::Sender;
pub enum AppEvent {
Input(KeyEvent),
Resize(u16, u16),
Tick,
}
/// Reads *all* crossterm events and forwards the ones we care about.
pub fn handle_events(tx: Sender<AppEvent>) {
pub fn handle_ct_events(input_tx: Sender<KeyEvent>, resize_tx: Sender<(u16, u16)>) {
loop {
match read() {
Ok(ev) => match ev {
Event::Key(key) => {
if tx.send(AppEvent::Input(key)).is_err() {
break;
}
Ok(Event::Key(k)) => {
if input_tx.send(k).is_err() {
break;
}
Event::Resize(cols, rows) => {
if tx.send(AppEvent::Resize(cols, rows)).is_err() {
break;
}
}
Ok(Event::Resize(cols, rows)) => {
if resize_tx.send((cols, rows)).is_err() {
break;
}
_ => {}
},
}
Ok(_) => {}
Err(_) => continue,
}
}