Skip to content

Commit

Permalink
Ignore queued rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
itome committed Jun 5, 2024
1 parent 93624b3 commit a2adc73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ impl App {

loop {
let state = store.state_cloned().await;
if let Some(e) = tui.next().await {
match e {
for event in tui.next().await {
match event {
tui::Event::Quit => tui_action_tx.send(TuiAction::Quit)?,
tui::Event::Tick => tui_action_tx.send(TuiAction::Tick)?,
tui::Event::Render => tui_action_tx.send(TuiAction::Render)?,
Expand All @@ -239,10 +239,11 @@ impl App {
_ => {}
}
for (_, component) in self.components.iter_mut() {
component.handle_events(&e, &state)?;
component.handle_events(&event, &state)?;
}
}

let mut rendered = false;
while let Ok(action) = tui_action_rx.try_recv() {
match action {
TuiAction::Quit => self.should_quit = true,
Expand All @@ -253,7 +254,10 @@ impl App {
self.draw(&mut tui, &state)?;
}
TuiAction::Render => {
self.draw(&mut tui, &state)?;
if !rendered {
rendered = true;
self.draw(&mut tui, &state)?;
}
}
_ => {}
}
Expand Down
6 changes: 4 additions & 2 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ impl Tui {
Ok(())
}

pub async fn next(&mut self) -> Option<Event> {
self.event_rx.recv().await
pub async fn next(&mut self) -> Vec<Event> {
let mut buffer: Vec<Event> = Vec::with_capacity(10000);
self.event_rx.recv_many(&mut buffer, 10000).await;
return buffer;
}
}

Expand Down

0 comments on commit a2adc73

Please sign in to comment.