Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrofitted to pure Rust #58

Merged
merged 11 commits into from
Nov 13, 2023
Prev Previous commit
Next Next commit
fix: ignore key release event
7sDream committed Nov 13, 2023
commit 7271dfb3cbf50a503224d3b014e7b8e8c9d2b17a
9 changes: 6 additions & 3 deletions src/preview/terminal/ui/event.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@

use std::{io::Result as CTResult, ops::Deref, sync::mpsc, thread, time::Duration};

use crossterm::event::{self, Event as CTEvent, KeyEvent as CTKeyEvent};
use crossterm::event::{self, Event as CTEvent, KeyEvent as CTKeyEvent, KeyEventKind};

#[derive(Debug, Copy, Clone, PartialOrd, Eq, PartialEq, Hash)]
pub enum TerminalEvent {
@@ -54,8 +54,11 @@ fn keyboard_event_generator(tick_interval: Duration, tx: mpsc::Sender<CTResult<T
match event::poll(tick_interval) {
Ok(true) => {
if let CTEvent::Key(key) = event::read().unwrap() {
if tx.send(Ok(TerminalEvent::Key(key))).is_err() {
break;
#[allow(clippy::collapsible_if)]
if key.kind != KeyEventKind::Release {
if tx.send(Ok(TerminalEvent::Key(key))).is_err() {
break;
}
}
}
}