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) {