From d0bb988750863869353c0261656675bf5db1e6ad Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Wed, 15 Jul 2026 07:35:41 +0200 Subject: [PATCH] Crossterm event polling --- pulse-ui/src/lib.rs | 12 +++++++----- src/main.rs | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pulse-ui/src/lib.rs b/pulse-ui/src/lib.rs index 5336b83..fa05603 100644 --- a/pulse-ui/src/lib.rs +++ b/pulse-ui/src/lib.rs @@ -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(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(); + } } }); diff --git a/src/main.rs b/src/main.rs index 2af3330..21980b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,6 +21,10 @@ impl App for PulseTradeApp { } *self.count.lock().await += 1; + + if *self.count.lock().await > 10 { + ctx.close().await; + } } async fn layout(&self) -> pulse_ui::layout::LayoutItem {