summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
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),