Crossterm event polling
This commit is contained in:
+4
-2
@@ -1,4 +1,4 @@
|
|||||||
use std::any::Any;
|
use std::{any::Any, time::Duration};
|
||||||
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
@@ -38,11 +38,13 @@ pub async fn run<A: App>(create_app: impl FnOnce(&state::Context) -> A) {
|
|||||||
crossterm::terminal::enable_raw_mode().unwrap();
|
crossterm::terminal::enable_raw_mode().unwrap();
|
||||||
|
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
loop {
|
while !tx.is_closed() {
|
||||||
|
if crossterm::event::poll(Duration::from_millis(100)).unwrap() {
|
||||||
tx.send(Box::new(crossterm::event::read().unwrap()))
|
tx.send(Box::new(crossterm::event::read().unwrap()))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut app = create_app(&ctx);
|
let mut app = create_app(&ctx);
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ impl App for PulseTradeApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*self.count.lock().await += 1;
|
*self.count.lock().await += 1;
|
||||||
|
|
||||||
|
if *self.count.lock().await > 10 {
|
||||||
|
ctx.close().await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn layout(&self) -> pulse_ui::layout::LayoutItem {
|
async fn layout(&self) -> pulse_ui::layout::LayoutItem {
|
||||||
|
|||||||
Reference in New Issue
Block a user