From dfa2de220cddc6a56e70278e2f67afc7887331de Mon Sep 17 00:00:00 2001 From: Arijit Dey Date: Tue, 2 Jul 2024 18:41:07 +0530 Subject: [PATCH] fix: first char does not appear after pressing / This occurs becuase the event reading thread still waits for events causing the search input reading thread to not read anything. This reverts commit 99d163d20a52b1c79ae0c673119f4a8d51d01147. --- src/core/init.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/core/init.rs b/src/core/init.rs index e1c029d..bbd6039 100644 --- a/src/core/init.rs +++ b/src/core/init.rs @@ -336,24 +336,28 @@ fn event_reader( } } - let ev = event::read().map_err(|e| MinusError::HandleEvent(e.into()))?; - let mut guard = ps.lock(); - // Get the events - let input = guard.input_classifier.classify_input(ev, &guard); - if let Some(iev) = input { - if let InputEvent::Number(n) = iev { - guard.prefix_num.push(n); - guard.format_prompt(); + if event::poll(std::time::Duration::from_millis(100)) + .map_err(|e| MinusError::HandleEvent(e.into()))? + { + let ev = event::read().map_err(|e| MinusError::HandleEvent(e.into()))?; + let mut guard = ps.lock(); + // Get the events + let input = guard.input_classifier.classify_input(ev, &guard); + if let Some(iev) = input { + if let InputEvent::Number(n) = iev { + guard.prefix_num.push(n); + guard.format_prompt(); + } else if !guard.prefix_num.is_empty() { + guard.prefix_num.clear(); + guard.format_prompt(); + } + if let Err(TrySendError::Disconnected(_)) = evtx.try_send(Command::UserInput(iev)) { + break; + } } else if !guard.prefix_num.is_empty() { guard.prefix_num.clear(); guard.format_prompt(); } - if let Err(TrySendError::Disconnected(_)) = evtx.try_send(Command::UserInput(iev)) { - break; - } - } else if !guard.prefix_num.is_empty() { - guard.prefix_num.clear(); - guard.format_prompt(); } } Result::<(), MinusError>::Ok(())