properly flush read buffer
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -77,6 +77,7 @@ fn init(anki: &AnkiClient) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prompt(anki: &AnkiClient) {
|
fn prompt(anki: &AnkiClient) {
|
||||||
|
flush_read();
|
||||||
// needs to be done twice to account for lag on the other end
|
// needs to be done twice to account for lag on the other end
|
||||||
anki.request(GuiCurrentCardRequest {}).unwrap();
|
anki.request(GuiCurrentCardRequest {}).unwrap();
|
||||||
let card = anki.request(GuiCurrentCardRequest {}).unwrap();
|
let card = anki.request(GuiCurrentCardRequest {}).unwrap();
|
||||||
@@ -88,7 +89,6 @@ fn prompt(anki: &AnkiClient) {
|
|||||||
KeyCode::Enter => break,
|
KeyCode::Enter => break,
|
||||||
KeyCode::Char('u') => {
|
KeyCode::Char('u') => {
|
||||||
anki.request(GuiUndoRequest {}).unwrap();
|
anki.request(GuiUndoRequest {}).unwrap();
|
||||||
event::read().unwrap();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
@@ -111,7 +111,6 @@ fn prompt(anki: &AnkiClient) {
|
|||||||
KeyCode::Char(GOOD) => break Ease::Good,
|
KeyCode::Char(GOOD) => break Ease::Good,
|
||||||
KeyCode::Char('u') => {
|
KeyCode::Char('u') => {
|
||||||
anki.request(GuiUndoRequest {}).unwrap();
|
anki.request(GuiUndoRequest {}).unwrap();
|
||||||
event::read().unwrap();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
@@ -120,7 +119,16 @@ fn prompt(anki: &AnkiClient) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
anki.request(GuiAnswerCardRequest { ease: ease }).unwrap();
|
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) {
|
fn clear_with_bar(anki: &AnkiClient, current_card: &GuiCurrentCardResponse) {
|
||||||
|
|||||||
Reference in New Issue
Block a user