summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorandromeda <andromeda@lenovo>2026-04-19 13:19:06 +0200
committerandromeda <andromeda@lenovo>2026-04-19 13:19:06 +0200
commit364c022ceee8422e95dd468bf85ec733a02811eb (patch)
tree465f4636151fc38c7cde49e091d9b88130ed6b6e /src
parentbcd83506ea691861562ade66ce23f57b27e57ee2 (diff)
properly flush read buffer
Diffstat (limited to 'src')
-rw-r--r--src/main.rs14
1 files 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) {