From 33d7aa189d09fdffbbef5aa14cb8febb0c9fffc6 Mon Sep 17 00:00:00 2001 From: Luis Alberto Santos Date: Sat, 18 Mar 2023 18:05:19 +0100 Subject: [PATCH] Fix double-events on windows --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/common.rs | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc06e59..38f1866 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -345,7 +345,7 @@ dependencies = [ [[package]] name = "intelli-shell" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "clap", diff --git a/Cargo.toml b/Cargo.toml index 35ebf05..480504c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "intelli-shell" description = "Like IntelliSense, but for shells" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "Apache-2.0" readme = "README.md" diff --git a/src/common.rs b/src/common.rs index 75d49f9..ce39839 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use crossterm::event::{self, Event, KeyCode, KeyModifiers}; +use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers}; use regex::{CaptureMatches, Captures, Regex}; use tui::{backend::Backend, layout::Rect, text::Text, widgets::ListState, Frame, Terminal}; use unicode_width::UnicodeWidthStr; @@ -81,9 +81,13 @@ pub trait Widget { self.render(f, area, inline, theme); })?; - // Exit on Ctrl+C let event = event::read()?; if let Event::Key(k) = &event { + // Ignore release & repeat events, we're only counting Press + if k.kind != KeyEventKind::Press { + continue; + } + // Exit on Ctrl+C if let KeyCode::Char(c) = k.code { if c == 'c' && k.modifiers.contains(KeyModifiers::CONTROL) { return Ok(WidgetOutput::empty());