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

fix #109 typing twice in windows with crossterm-0.26+ #110

Merged
merged 1 commit into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/irust/src/irust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ impl IRust {
self.execute(Command::HandleCtrlC)?;
}
Event::Key(key_event) => match key_event {
KeyEvent {
kind: KeyEventKind::Release,
..
} => (),
KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::NONE,
Expand Down
14 changes: 13 additions & 1 deletion crates/irust/src/irust/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashMap, io::Write};

use crossterm::{
cursor::SetCursorStyle,
event::{Event, KeyCode, KeyEvent, KeyModifiers},
event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
style::Color,
terminal::ClearType,
};
Expand Down Expand Up @@ -369,6 +369,10 @@ impl IRust {

if let Ok(key_event) = crossterm::event::read() {
match key_event {
Event::Key(KeyEvent {
kind: KeyEventKind::Release,
..
}) => continue,
Event::Key(KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::NONE,
Expand Down Expand Up @@ -461,6 +465,10 @@ impl IRust {

if let Ok(key_event) = crossterm::event::read() {
match key_event {
Event::Key(KeyEvent {
kind: KeyEventKind::Release,
..
}) => (),
Event::Key(KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::NONE,
Expand Down Expand Up @@ -695,6 +703,10 @@ impl IRust {
// 1 - wait for the macro key
let macro_key = loop {
match crossterm::event::read()? {
Event::Key(KeyEvent {
kind: KeyEventKind::Release,
..
}) => (),
Event::Key(KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::NONE,
Expand Down
6 changes: 5 additions & 1 deletion crates/irust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,17 @@ fn _balanced_quotes(s: &str) -> bool {
}

pub fn ctrlc_cancel(process: &mut std::process::Child) -> Result<()> {
use crossterm::event::{Event, KeyCode, KeyEvent};
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind};
// Running a command as Command::new().output takes at minimum 1ms
// So Polling should take a similar order of magnitude
if let Ok(event) = crossterm::event::poll(std::time::Duration::from_millis(1)) {
if event {
if let Ok(event) = crossterm::event::read() {
match event {
Event::Key(KeyEvent {
kind: KeyEventKind::Release,
..
}) => (),
Event::Key(KeyEvent {
code: KeyCode::Char('c'),
modifiers: crossterm::event::KeyModifiers::CONTROL,
Expand Down
6 changes: 5 additions & 1 deletion crates/printer/examples/shell.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
use crossterm::style::Color;
use printer::{
buffer::Buffer,
Expand All @@ -17,6 +17,10 @@ fn main() -> Result<()> {
let inp = crossterm::event::read()?;
match inp {
crossterm::event::Event::Key(key) => match key {
KeyEvent {
kind: KeyEventKind::Release,
..
} => (),
KeyEvent {
code: KeyCode::Char(c),
modifiers: KeyModifiers::NONE,
Expand Down
4 changes: 4 additions & 0 deletions script_examples/irust_vim_dylib/src/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl Vim {

let cmd = (|| match event {
Event::Key(key) => match key {
KeyEvent {
kind: KeyEventKind::Release,
..
} => None,
KeyEvent {
code: KeyCode::Char(c),
modifiers,
Expand Down