generated from GarandPLG/rust-flake-template
Rename input event handler to handle_events
Rename the input event handler module and function. Update imports, re‑exports, and main.rs to use handle_events. Add a brief doc comment for the new function.
This commit is contained in:
@@ -2,7 +2,8 @@ use crate::app::threads::AppEvent;
|
|||||||
use ratatui::crossterm::event::{Event, read};
|
use ratatui::crossterm::event::{Event, read};
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
pub fn handle_input_events(tx: Sender<AppEvent>) {
|
/// Reads *all* crossterm events and forwards the ones we care about.
|
||||||
|
pub fn handle_events(tx: Sender<AppEvent>) {
|
||||||
loop {
|
loop {
|
||||||
match read() {
|
match read() {
|
||||||
Ok(ev) => match ev {
|
Ok(ev) => match ev {
|
||||||
@@ -11,8 +12,8 @@ pub fn handle_input_events(tx: Sender<AppEvent>) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::Resize(c, r) => {
|
Event::Resize(cols, rows) => {
|
||||||
if tx.send(AppEvent::Resize(c, r)).is_err() {
|
if tx.send(AppEvent::Resize(cols, rows)).is_err() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod handle_input_events;
|
pub mod handle_events;
|
||||||
|
|
||||||
pub use events::AppEvent;
|
pub use events::AppEvent;
|
||||||
pub use handle_input_events::handle_input_events;
|
pub use handle_events::handle_events;
|
||||||
|
|||||||
+7
-8
@@ -1,13 +1,13 @@
|
|||||||
use ratatui::{Terminal, prelude::CrosstermBackend};
|
use ratatui::{Terminal, prelude::CrosstermBackend};
|
||||||
use std::{
|
use std::{
|
||||||
io::{Result, Stdout},
|
io::{Result, Stdout},
|
||||||
sync::mpsc::{Sender, channel},
|
sync::mpsc::channel,
|
||||||
thread::{self, JoinHandle},
|
thread::{self, JoinHandle},
|
||||||
};
|
};
|
||||||
use war_in_tunnels::{
|
use war_in_tunnels::{
|
||||||
app::{
|
app::{
|
||||||
App,
|
App,
|
||||||
threads::{AppEvent, handle_input_events},
|
threads::{AppEvent, handle_events},
|
||||||
},
|
},
|
||||||
cli::{Cli, get_args},
|
cli::{Cli, get_args},
|
||||||
logs::init_logger,
|
logs::init_logger,
|
||||||
@@ -27,17 +27,16 @@ fn main() -> Result<()> {
|
|||||||
let mut terminal: Terminal<CrosstermBackend<Stdout>> = ratatui::init();
|
let mut terminal: Terminal<CrosstermBackend<Stdout>> = ratatui::init();
|
||||||
let mut app: App = App::new(args);
|
let mut app: App = App::new(args);
|
||||||
|
|
||||||
let (event_tx, event_rx) = channel::<AppEvent>();
|
let (app_event_tx, app_event_rx) = channel::<AppEvent>();
|
||||||
|
|
||||||
let tx_to_input_events: Sender<AppEvent> = event_tx.clone();
|
let app_event_thread: JoinHandle<()> = thread::spawn(move || {
|
||||||
let input_thread: JoinHandle<()> = thread::spawn(move || {
|
handle_events(app_event_tx);
|
||||||
handle_input_events(tx_to_input_events);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let app_result: Result<()> = app.run(&mut terminal, event_rx);
|
let app_result: Result<()> = app.run(&mut terminal, app_event_rx);
|
||||||
ratatui::restore();
|
ratatui::restore();
|
||||||
|
|
||||||
let _ = input_thread.join();
|
let _ = app_event_thread.join();
|
||||||
|
|
||||||
app_result
|
app_result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user