summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorandromeda <andromeda@lenovo>2026-04-14 23:12:55 +0200
committerandromeda <andromeda@lenovo>2026-04-14 23:12:55 +0200
commitf32d5dd7aa1eb4b87c2cc6f49e3357fe46d18aa0 (patch)
treea40c2d221173e16d5b45e2a852396743bcae1670 /src
parent46a69826aceb4dd05b2826d81bac484799bb64b7 (diff)
mvp
Diffstat (limited to 'src')
-rw-r--r--src/main.rs73
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();
}