diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs index e7a11a9..d586213 100644 --- a/src/main.rs +++ b/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(); } |
