From e7604afcb6ad05346c2b031a8fce81d064690fa1 Mon Sep 17 00:00:00 2001 From: lesleyrs <19632758+lesleyrs@users.noreply.github.com> Date: Thu, 6 Apr 2023 01:12:21 +0200 Subject: [PATCH 1/3] temp? fix windows and examples --- examples/interactive-demo/src/main.rs | 5 ++++- src/event/sys/windows/parse.rs | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/interactive-demo/src/main.rs b/examples/interactive-demo/src/main.rs index 2dd3105a6..1d54f0450 100644 --- a/examples/interactive-demo/src/main.rs +++ b/examples/interactive-demo/src/main.rs @@ -2,6 +2,7 @@ use std::io::{self, Write}; +use crossterm::event::KeyEventKind; pub use crossterm::{ cursor, event::{self, Event, KeyCode, KeyEvent}, @@ -80,7 +81,9 @@ pub fn read_char() -> Result { loop { if let Ok(Event::Key(KeyEvent { code: KeyCode::Char(c), - .. + kind: KeyEventKind::Press, + modifiers: _, + state: _, })) = event::read() { return Ok(c); diff --git a/src/event/sys/windows/parse.rs b/src/event/sys/windows/parse.rs index beb0b51af..feb111fa4 100644 --- a/src/event/sys/windows/parse.rs +++ b/src/event/sys/windows/parse.rs @@ -290,7 +290,11 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option KeyEventKind::Release }; let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind); - return Some(WindowsKeyEvent::KeyEvent(key_event)); + if key_event + != KeyEvent::new_with_kind(KeyCode::Enter, KeyModifiers::NONE, KeyEventKind::Release) + { + return Some(WindowsKeyEvent::KeyEvent(key_event)); + } } None From c722698d3c2e52feeb8c71e513b0c336800a953d Mon Sep 17 00:00:00 2001 From: lesleyrs <19632758+lesleyrs@users.noreply.github.com> Date: Thu, 6 Apr 2023 02:42:09 +0200 Subject: [PATCH 2/3] never mind, this doesn't even happen on cmd --- src/event/sys/windows/parse.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/event/sys/windows/parse.rs b/src/event/sys/windows/parse.rs index feb111fa4..878cd5c07 100644 --- a/src/event/sys/windows/parse.rs +++ b/src/event/sys/windows/parse.rs @@ -290,11 +290,7 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option KeyEventKind::Release }; let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind); - if key_event - != KeyEvent::new_with_kind(KeyCode::Enter, KeyModifiers::NONE, KeyEventKind::Release) - { return Some(WindowsKeyEvent::KeyEvent(key_event)); - } } None From f06627e4d96eb1b7e3a86d6fbf2472e4af50b54e Mon Sep 17 00:00:00 2001 From: lesleyrs <19632758+lesleyrs@users.noreply.github.com> Date: Thu, 6 Apr 2023 03:29:30 +0200 Subject: [PATCH 3/3] restore cursor after exiting demo + fmt --- examples/interactive-demo/src/main.rs | 5 ++++- src/event/sys/windows/parse.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/interactive-demo/src/main.rs b/examples/interactive-demo/src/main.rs index 1d54f0450..ec3967fef 100644 --- a/examples/interactive-demo/src/main.rs +++ b/examples/interactive-demo/src/main.rs @@ -62,7 +62,10 @@ where '3' => test::attribute::run(w)?, '4' => test::event::run(w)?, '5' => test::synchronized_output::run(w)?, - 'q' => break, + 'q' => { + execute!(w, cursor::SetCursorStyle::DefaultUserShape).unwrap(); + break; + } _ => {} }; } diff --git a/src/event/sys/windows/parse.rs b/src/event/sys/windows/parse.rs index 878cd5c07..beb0b51af 100644 --- a/src/event/sys/windows/parse.rs +++ b/src/event/sys/windows/parse.rs @@ -290,7 +290,7 @@ fn parse_key_event_record(key_event: &KeyEventRecord) -> Option KeyEventKind::Release }; let key_event = KeyEvent::new_with_kind(key_code, modifiers, kind); - return Some(WindowsKeyEvent::KeyEvent(key_event)); + return Some(WindowsKeyEvent::KeyEvent(key_event)); } None