Skip to content

Commit

Permalink
Fix input being handled twice (fixes #1)
Browse files Browse the repository at this point in the history
The root cause for this turned out to be crossterm-rs/crossterm#745, which now emits additional events for keyup
  • Loading branch information
holly-hacker committed Jul 24, 2023
1 parent cefe46a commit f0bb066
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions td-tui/src/ui/mod.rs
Expand Up @@ -75,18 +75,29 @@ impl AppState {
) -> Result<(), Box<dyn Error>> {
let mut root_component = LayoutRoot::new();

loop {
'main_loop: loop {
let mut frame_storage = FrameLocalStorage::default();
root_component.pre_render(self, &mut frame_storage);

terminal.draw(|f| root_component.render(f, f.size(), self, &frame_storage))?;

if let Event::Key(key) = event::read()? {
// while loop so we only check for key-down events, not key-up
while let Event::Key(key) = event::read()? {
// if key even is release, don't use it as input
match key.kind {
event::KeyEventKind::Press => (),
event::KeyEventKind::Repeat => (),
event::KeyEventKind::Release => continue,
};

_ = root_component.process_input(key, self, &frame_storage);

if self.should_exit {
break;
break 'main_loop;
}

// we handled an actionable key event, exit out of the input loop
break;
}
}

Expand Down

0 comments on commit f0bb066

Please sign in to comment.