From 364c022ceee8422e95dd468bf85ec733a02811eb Mon Sep 17 00:00:00 2001 From: andromeda Date: Sun, 19 Apr 2026 13:19:06 +0200 Subject: [PATCH] properly flush read buffer --- src/main.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 69a10cd..70ccdfa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,6 +77,7 @@ fn init(anki: &AnkiClient) { } fn prompt(anki: &AnkiClient) { + flush_read(); // needs to be done twice to account for lag on the other end anki.request(GuiCurrentCardRequest {}).unwrap(); let card = anki.request(GuiCurrentCardRequest {}).unwrap(); @@ -88,7 +89,6 @@ fn prompt(anki: &AnkiClient) { KeyCode::Enter => break, KeyCode::Char('u') => { anki.request(GuiUndoRequest {}).unwrap(); - event::read().unwrap(); return; } _ => (), @@ -111,7 +111,6 @@ fn prompt(anki: &AnkiClient) { KeyCode::Char(GOOD) => break Ease::Good, KeyCode::Char('u') => { anki.request(GuiUndoRequest {}).unwrap(); - event::read().unwrap(); return; } _ => (), @@ -120,7 +119,16 @@ fn prompt(anki: &AnkiClient) { }; }; anki.request(GuiAnswerCardRequest { ease: ease }).unwrap(); - event::read().unwrap(); +} + +fn flush_read() { + loop { + if event::poll(Duration::from_secs(0)).unwrap() { + event::read().unwrap(); + } else { + break; + } + } } fn clear_with_bar(anki: &AnkiClient, current_card: &GuiCurrentCardResponse) {