aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorJoris2022-02-12 17:21:29 +0100
committerJoris2022-02-12 17:21:29 +0100
commit87e12144440b9525cbabdca5a9f79038a9a0f0e0 (patch)
tree8414fe44230448eae35e72ae2904cf93753dd552 /src/gui
parent3adf3f9697c4e2beb10e652947046d5fddda2ed4 (diff)
Show current progress after the deck name
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.rs20
-rw-r--r--src/gui/message.rs4
-rw-r--r--src/gui/question.rs4
3 files changed, 21 insertions, 7 deletions
diff --git a/src/gui/gui.rs b/src/gui/gui.rs
index 88333bb..94e15d8 100644
--- a/src/gui/gui.rs
+++ b/src/gui/gui.rs
@@ -14,12 +14,16 @@ pub fn start(conn: &Connection, deck_name: &String) -> Result<()> {
let events = Events::new();
+ let mut answers = 0;
+
loop {
let now = time::now()?;
+ let title = title(deck_name, answers, db::count_available(&conn).unwrap_or(0));
match db::next_ready(&conn) {
Some(card) if card.ready <= now => {
- let difficulty = question::ask(&mut terminal, &events, &card, deck_name)?;
+ let difficulty = question::ask(&mut terminal, &events, &title, &card)?;
+ answers += 1;
db::update(
&conn,
&card.question,
@@ -31,12 +35,12 @@ pub fn start(conn: &Connection, deck_name: &String) -> Result<()> {
"Prochaine carte disponible dans {}.",
time::pp_duration(card.ready - now)
);
- let _ = message::show(&mut terminal, &events, &message, deck_name);
+ let _ = message::show(&mut terminal, &events, &title, &message);
break;
}
None => {
let message = format!("Aucune carte n’est disponible. Votre deck est-il vide ?");
- let _ = message::show(&mut terminal, &events, &message, deck_name);
+ let _ = message::show(&mut terminal, &events, &title, &message);
break;
}
}
@@ -44,3 +48,13 @@ pub fn start(conn: &Connection, deck_name: &String) -> Result<()> {
Ok(())
}
+
+fn title(deck_name: &String, answers: i32, available_cards: i32) -> String {
+ if answers == 0 && available_cards == 0 {
+ deck_name.to_string()
+ } else if available_cards == 0 {
+ format!("{} ({} / {})", deck_name, answers, answers + available_cards)
+ } else {
+ format!("{} ({} / {})", deck_name, answers + 1, answers + available_cards)
+ }
+}
diff --git a/src/gui/message.rs b/src/gui/message.rs
index 158416e..01d124e 100644
--- a/src/gui/message.rs
+++ b/src/gui/message.rs
@@ -12,8 +12,8 @@ use tui::{
pub fn show<B: Backend>(
terminal: &mut Terminal<B>,
events: &Events,
+ title: &String,
message: &String,
- deck_name: &String,
) -> Result<()> {
loop {
terminal.draw(|f| {
@@ -23,7 +23,7 @@ pub fn show<B: Backend>(
.constraints([Constraint::Length(1), Constraint::Percentage(50)].as_ref())
.split(f.size());
- let d1 = util::title(deck_name);
+ let d1 = util::title(title);
f.render_widget(d1, chunks[0]);
let message = Paragraph::new(util::center_vertically(chunks[1], &message))
diff --git a/src/gui/question.rs b/src/gui/question.rs
index e88d6e5..211bcda 100644
--- a/src/gui/question.rs
+++ b/src/gui/question.rs
@@ -28,8 +28,8 @@ enum Answer {
pub fn ask<B: Backend>(
terminal: &mut Terminal<B>,
events: &Events,
+ title: &String,
card: &Card,
- deck_name: &String,
) -> Result<Difficulty> {
let mut state = State {
input: String::new(),
@@ -53,7 +53,7 @@ pub fn ask<B: Backend>(
)
.split(f.size());
- let d1 = util::title(deck_name);
+ let d1 = util::title(title);
f.render_widget(d1, chunks[0]);
let question = Paragraph::new(util::center_vertically(chunks[1], &card.question))