From a7bc6d53a56e105b4d8ad558ef533ee7ecb6aaea Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 13 May 2024 16:39:38 +0200 Subject: [PATCH] Only send `Unrecognized` on ENTER if the last input wasn't valid --- src/watch/terminal_event.rs | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/watch/terminal_event.rs b/src/watch/terminal_event.rs index 29a672a0..f54af17a 100644 --- a/src/watch/terminal_event.rs +++ b/src/watch/terminal_event.rs @@ -13,6 +13,9 @@ pub enum InputEvent { } pub fn terminal_event_handler(tx: Sender, manual_run: bool) { + // Only send `Unrecognized` on ENTER if the last input wasn't valid. + let mut last_input_valid = false; + let last_input_event = loop { let terminal_event = match event::read() { Ok(v) => v, @@ -32,22 +35,42 @@ pub fn terminal_event_handler(tx: Sender, manual_run: bool) { } if key.modifiers != KeyModifiers::NONE { + last_input_valid = false; continue; } - if let KeyCode::Char(c) = key.code { - let input_event = match c { - 'n' => InputEvent::Next, - 'h' => InputEvent::Hint, - 'l' => break InputEvent::List, - 'q' => break InputEvent::Quit, - 'r' if manual_run => InputEvent::Run, - _ => InputEvent::Unrecognized, - }; + let input_event = match key.code { + KeyCode::Enter => { + if last_input_valid { + continue; + } - if tx.send(WatchEvent::Input(input_event)).is_err() { - return; + InputEvent::Unrecognized } + KeyCode::Char(c) => { + let input_event = match c { + 'n' => InputEvent::Next, + 'h' => InputEvent::Hint, + 'l' => break InputEvent::List, + 'q' => break InputEvent::Quit, + 'r' if manual_run => InputEvent::Run, + _ => { + last_input_valid = false; + continue; + } + }; + + last_input_valid = true; + input_event + } + _ => { + last_input_valid = false; + continue; + } + }; + + if tx.send(WatchEvent::Input(input_event)).is_err() { + return; } } Event::Resize(_, _) => {