Skip to content

Commit

Permalink
Fix for CrosstermEvent issue on Windows (#9)
Browse files Browse the repository at this point in the history
CrosstermEvent sends an event for both key press and key release on Windows, creating duplicated keyboard input. Implemented the recommended fix from Ratatui's FAQ.
  • Loading branch information
saintmuntzer authored Jul 6, 2024
1 parent 8b7b6a1 commit cdcd6d5
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::types::{AppResult, SystemTimeTick, Tick};
use crossterm::event::{self, Event as CrosstermEvent, KeyEvent, MouseEvent};
use crossterm::event::{self, Event as CrosstermEvent, KeyEvent, KeyEventKind, MouseEvent};
use futures::Future;
use std::pin::Pin;
use std::sync::mpsc;
Expand Down Expand Up @@ -49,7 +49,11 @@ impl EventHandler {
thread::spawn(move || loop {
if event::poll(TIME_STEP).expect("no events available") {
match event::read().expect("unable to read event") {
CrosstermEvent::Key(e) => sender.send(TerminalEvent::Key(e)),
CrosstermEvent::Key(key) => {
if key.kind == KeyEventKind::Press {
sender.send(TerminalEvent::Key(key))
} else { Ok(()) }
},
CrosstermEvent::Mouse(e) => sender.send(TerminalEvent::Mouse(e)),
CrosstermEvent::Resize(w, h) => sender.send(TerminalEvent::Resize(w, h)),
_ => unimplemented!(),
Expand Down

0 comments on commit cdcd6d5

Please sign in to comment.