mvp
This commit is contained in:
73
src/main.rs
73
src/main.rs
@@ -1,3 +1,74 @@
|
||||
use anki_bridge::{AnkiClient, AnkiRequestable, prelude::*};
|
||||
use crossterm::{
|
||||
event::{self, Event, KeyCode},
|
||||
execute,
|
||||
style::*,
|
||||
};
|
||||
use std::io::stdout;
|
||||
|
||||
const GOOD: char = '3';
|
||||
const AGAIN: char = '1';
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
// Creates a client to connect to the Anki instance running on the local computer
|
||||
let anki = AnkiClient::default();
|
||||
|
||||
// Fetch the names of all the active decks
|
||||
let decks = anki.request(DeckNamesRequest {}).unwrap();
|
||||
dbg!(&decks);
|
||||
|
||||
// Fetch statistics about the decks above
|
||||
let deck_stats = anki.request(GetDeckStatsRequest { decks }).unwrap();
|
||||
dbg!(&deck_stats);
|
||||
|
||||
execute!(
|
||||
stdout(),
|
||||
SetForegroundColor(Color::DarkMagenta),
|
||||
Print("Welcome to anki-cli\n"),
|
||||
ResetColor
|
||||
)
|
||||
.unwrap();
|
||||
loop {
|
||||
prompt(&anki);
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt(anki: &AnkiClient) {
|
||||
let card = anki.request(GuiCurrentCardRequest {}).unwrap();
|
||||
execute!(
|
||||
stdout(),
|
||||
SetForegroundColor(Color::DarkYellow),
|
||||
Print(card.question),
|
||||
Print("\n"),
|
||||
ResetColor
|
||||
);
|
||||
loop {
|
||||
match event::read().unwrap() {
|
||||
Event::Key(e) => match e.code {
|
||||
KeyCode::Char(' ') => break,
|
||||
_ => (),
|
||||
},
|
||||
e => (),
|
||||
};
|
||||
}
|
||||
execute!(
|
||||
stdout(),
|
||||
SetForegroundColor(Color::DarkYellow),
|
||||
Print(card.answer),
|
||||
SetForegroundColor(Color::Blue),
|
||||
Print("\nEnter the answer:\n"),
|
||||
ResetColor
|
||||
);
|
||||
let ease = loop {
|
||||
let ease = match event::read().unwrap() {
|
||||
Event::Key(e) => match e.code {
|
||||
KeyCode::Char(AGAIN) => break Ease::Again,
|
||||
KeyCode::Char(GOOD) => break Ease::Good,
|
||||
_ => (),
|
||||
},
|
||||
e => (),
|
||||
};
|
||||
};
|
||||
anki.request(GuiShowAnswerRequest {}).unwrap();
|
||||
anki.request(GuiAnswerCardRequest { ease: ease }).unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user