Fix input events and drop spawning tokio
This commit is contained in:
@@ -38,9 +38,11 @@ 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();
|
||||
}
|
||||
});
|
||||
|
||||
let mut app = create_app(&ctx);
|
||||
|
||||
@@ -59,7 +59,9 @@ impl<'a, T> std::ops::DerefMut for StateGuard<'a, T> {
|
||||
impl<'a, T> Drop for StateGuard<'a, T> {
|
||||
fn drop(&mut self) {
|
||||
if self.is_mutated {
|
||||
self.tx.blocking_send(Box::new(Refresh)).unwrap()
|
||||
let tx = self.tx.clone();
|
||||
|
||||
tokio::spawn(async move { tx.send(Box::new(Refresh)).await.unwrap() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -1,9 +1,9 @@
|
||||
use std::any::Any;
|
||||
|
||||
use pulse_ui::{
|
||||
App,
|
||||
App, get_screen,
|
||||
layout::{LayoutItem, layout},
|
||||
state::State,
|
||||
state::{Refresh, State},
|
||||
unit::Size,
|
||||
widget::outline::Outline,
|
||||
};
|
||||
@@ -16,7 +16,11 @@ impl App for PulseTradeApp {
|
||||
async fn init(&mut self, ctx: &pulse_ui::state::Context) {}
|
||||
|
||||
async fn update(&mut self, ctx: &pulse_ui::state::Context, event: Box<dyn Any + Send + Sync>) {
|
||||
ctx.close().await
|
||||
if let Some(Refresh) = event.downcast_ref() {
|
||||
return;
|
||||
}
|
||||
|
||||
*self.count.lock().await += 1;
|
||||
}
|
||||
|
||||
async fn layout(&self) -> pulse_ui::layout::LayoutItem {
|
||||
@@ -33,7 +37,7 @@ impl App for PulseTradeApp {
|
||||
}
|
||||
|
||||
async fn render(&mut self, layout: pulse_ui::layout::Allocation) {
|
||||
layout.draw(1, "Yo");
|
||||
layout.draw(1, format!("{:?}", *self.count.lock().await).as_str());
|
||||
layout.draw_frame(1, Outline);
|
||||
layout.draw_frame(2, Outline);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user