properly flush read buffer

This commit is contained in:
andromeda
2026-04-19 13:19:06 +02:00
parent bcd83506ea
commit 364c022cee

View File

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