Compare commits

...

2 Commits

Author SHA1 Message Date
andromeda
2dbe2c7811 fix bug 2026-04-15 12:01:53 +02:00
andromeda
a6afe8626b make deck selection more intuitive 2026-04-15 11:47:13 +02:00

View File

@@ -1,6 +1,6 @@
use anki_bridge::{AnkiClient, AnkiRequestable, prelude::*}; use anki_bridge::{AnkiClient, AnkiRequestable, prelude::*};
use crossterm::{ use crossterm::{
cursor::*, cursor,
event::{self, Event, KeyCode}, event::{self, Event, KeyCode},
execute, execute,
style::*, style::*,
@@ -22,7 +22,14 @@ fn main() {
fn init(anki: &AnkiClient) { fn init(anki: &AnkiClient) {
clear_screen(); clear_screen();
display_prompt_text("Name des Stapels: "); let decks = anki.request(DeckNamesRequest {}).unwrap();
for (index, title) in decks.clone().into_iter().enumerate() {
// 0th index is Default, which is not predictable
if index > 0 {
println!("{:?}: {}", index, title);
}
}
display_prompt_text("deck index:");
let mut input = "".to_string(); let mut input = "".to_string();
loop { loop {
match event::read().unwrap() { match event::read().unwrap() {
@@ -34,10 +41,15 @@ fn init(anki: &AnkiClient) {
_ => (), _ => (),
} }
} }
anki.request(GuiDeckReviewRequest { name: input }).unwrap(); anki.request(GuiDeckReviewRequest {
name: decks[input.parse::<usize>().unwrap()].clone(),
})
.unwrap();
} }
fn prompt(anki: &AnkiClient) { fn prompt(anki: &AnkiClient) {
// needs to be done twice to account for lag on the other end
anki.request(GuiCurrentCardRequest {}).unwrap();
let card = anki.request(GuiCurrentCardRequest {}).unwrap(); let card = anki.request(GuiCurrentCardRequest {}).unwrap();
clear_screen(); clear_screen();
display_html(&card.question); display_html(&card.question);
@@ -73,7 +85,12 @@ fn prompt(anki: &AnkiClient) {
} }
fn clear_screen() { fn clear_screen() {
execute!(stdout(), Clear(ClearType::All), MoveTo(0, 0)); execute!(
stdout(),
Clear(ClearType::All),
cursor::MoveTo(0, 0),
cursor::Hide
);
} }
fn display_prompt_text(text: &str) { fn display_prompt_text(text: &str) {