From 8e5ddebddb275cfc2a5b446f563f88750eeb18af Mon Sep 17 00:00:00 2001 From: Javier Sagredo Date: Wed, 4 Dec 2024 00:05:10 +0100 Subject: [PATCH] Ignore `KeyEventKind::Release` events when reading a char --- src/machine/system_calls.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 24798919..371b97e1 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -68,7 +68,7 @@ use cpu_time::ProcessTime; use std::time::{Duration, SystemTime}; #[cfg(feature = "repl")] -use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyModifiers}; +use crossterm::event::{read, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers}; #[cfg(feature = "repl")] use crossterm::terminal::{disable_raw_mode, enable_raw_mode}; @@ -111,12 +111,14 @@ pub(crate) fn get_key() -> KeyEvent { loop { let key_ = read(); if let Ok(Event::Key(key_)) = key_ { - match key_.code { - KeyCode::Char(_) | KeyCode::Enter | KeyCode::Tab => { - key = key_; - break; + if key_.kind != KeyEventKind::Release { + match key_.code { + KeyCode::Char(_) | KeyCode::Enter | KeyCode::Tab => { + key = key_; + break; + } + _ => (), } - _ => (), } } } -- 2.54.0