diff options
| author | andromeda <andromeda@lenovo> | 2026-04-15 11:30:12 +0200 |
|---|---|---|
| committer | andromeda <andromeda@lenovo> | 2026-04-15 11:30:12 +0200 |
| commit | dfe95e2a89b26a9ecc5dc44ef9d0370516a2d29b (patch) | |
| tree | 82efdaee53d2bea83fa1ac9871e6e9badf703e66 /src | |
| parent | cdfd807e77197629f0ffc506887607f82fd6e6ce (diff) | |
use nanohtml2text fork instead of html2text
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs index 9a95134..3eb93b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use crossterm::{ style::*, terminal::*, }; +use nanohtml2text::html2text; use std::io::stdout; const GOOD: char = '3'; @@ -39,7 +40,7 @@ fn init(anki: &AnkiClient) { fn prompt(anki: &AnkiClient) { let card = anki.request(GuiCurrentCardRequest {}).unwrap(); clear_screen(); - display_question(&card); + display_html(&card.question); loop { match event::read().unwrap() { Event::Key(e) => match e.code { @@ -51,7 +52,11 @@ fn prompt(anki: &AnkiClient) { } anki.request(GuiShowAnswerRequest {}).unwrap(); clear_screen(); - display_answer(&card); + { + let length = html2text(&card.question).len(); + let text = &html2text(&card.answer)[(2 + length)..]; + display_text(&text); + } display_prompt_text(":"); let ease = loop { let ease = match event::read().unwrap() { @@ -80,21 +85,12 @@ fn display_prompt_text(text: &str) { ); } -fn display_question(card: &GuiCurrentCardResponse) { - let text = html2text::from_read(card.question.as_bytes(), 80).unwrap(); - execute!( - stdout(), - SetForegroundColor(Color::DarkYellow), - Print(text), - ResetColor - ); +fn display_html(html: &str) { + let text = html2text(html); + display_text(&text); } -fn display_answer(card: &GuiCurrentCardResponse) { - let length = html2text::from_read(card.question.as_bytes(), 80) - .unwrap() - .len(); - let text = &html2text::from_read(card.answer.as_bytes(), 80).unwrap()[length..]; +fn display_text(text: &str) { execute!( stdout(), SetForegroundColor(Color::DarkYellow), |
