Crossterm event polling

This commit is contained in:
2026-07-15 07:35:41 +02:00
parent 0236eb7cb0
commit d0bb988750
2 changed files with 11 additions and 5 deletions
+7 -5
View File
@@ -1,4 +1,4 @@
use std::any::Any;
use std::{any::Any, time::Duration};
use tokio::sync::mpsc;
@@ -38,10 +38,12 @@ pub async fn run<A: App>(create_app: impl FnOnce(&state::Context) -> A) {
crossterm::terminal::enable_raw_mode().unwrap();
tokio::spawn(async move {
loop {
tx.send(Box::new(crossterm::event::read().unwrap()))
.await
.unwrap();
while !tx.is_closed() {
if crossterm::event::poll(Duration::from_millis(100)).unwrap() {
tx.send(Box::new(crossterm::event::read().unwrap()))
.await
.unwrap();
}
}
});