From 28c8a3b112e49ed6041e11b44adccdb0d096792e Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 15 Jul 2023 09:26:15 +0200 Subject: Only show remaining cards, not progress I am generally interested on decreasing the count of remaining cards, and I sometimes closed and re-opened the app to have a clear view of the remaining count. --- src/gui/mod.rs | 20 +++++--------------- src/main.rs | 6 +++--- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/gui/mod.rs b/src/gui/mod.rs index b500706..caf97f8 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -30,24 +30,20 @@ pub fn start( conn: &Connection, term: &mut Term, deck_name: &str, - hide_progress: bool, + hide_remaining: bool, ) -> Result<()> { - let mut answers = 0; - loop { let now = time::seconds_since_unix_epoch()?; let title = title( deck_name, - answers, db::count_available(conn).unwrap_or(0), - hide_progress, + hide_remaining, ); match db::pick_random_ready(conn) { Some(card) => match question::ask(term, &title, &card)? { question::Response::Aborted => break, question::Response::Answered { difficulty } => { - answers += 1; db::update( conn, &card.question, @@ -72,16 +68,10 @@ pub fn start( Ok(()) } -fn title(deck_name: &str, answers: i32, available_cards: i32, hide_progress: bool) -> String { - if answers == 0 && available_cards == 0 || hide_progress { +fn title(deck_name: &str, available_cards: i32, hide_remaining: bool) -> String { + if available_cards == 0 || hide_remaining { deck_name.to_string() - } else if available_cards == 0 { - let from = answers; - let to = answers + available_cards; - format!("{deck_name} ({from} / {to})") } else { - let from = answers + 1; - let to = answers + available_cards; - format!("{deck_name} ({from} / {to})") + format!("{deck_name} ({available_cards})") } } diff --git a/src/main.rs b/src/main.rs index c671d0e..ddc6edc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,9 +17,9 @@ struct Opt { #[clap(long, default_value = "deck.deck")] deck: String, - /// Hide current and remaining card counts + /// Hide remaining card counts #[clap(long)] - hide_progress: bool, + hide_remaining: bool, } fn main() -> Result<()> { @@ -32,7 +32,7 @@ fn main() -> Result<()> { let mut term = gui::setup_terminal()?; - match gui::start(&conn, &mut term, &deck_name, args.hide_progress) { + match gui::start(&conn, &mut term, &deck_name, args.hide_remaining) { Ok(()) => (), Err(msg) => { // Show errors in TUI, otherwise they are hidden -- cgit v1.2.3