This commit is contained in:
andromeda
2026-04-14 23:12:55 +02:00
parent 46a69826ac
commit f32d5dd7aa
3 changed files with 897 additions and 1 deletions

View File

@@ -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();
}