use nanohtml2text fork instead of html2text

This commit is contained in:
andromeda
2026-04-15 11:30:12 +02:00
parent cdfd807e77
commit dfe95e2a89
3 changed files with 18 additions and 181 deletions

View File

@@ -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),