Skip to content

Commit

Permalink
Fix double-events on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lasantosr committed Mar 18, 2023
1 parent 13e3149 commit 33d7aa1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 6 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 33d7aa1

Please sign in to comment.