From 8cac21511cbcc148ea7a4c8c6d196c9c0bf17255 Mon Sep 17 00:00:00 2001 From: mo8it Date: Mon, 14 Oct 2024 00:42:49 +0200 Subject: [PATCH] Small improvements to showing progress --- src/app_state.rs | 1 - src/main.rs | 4 +++- src/term.rs | 40 ++++++++++++++++++++++++---------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/app_state.rs b/src/app_state.rs index db9d1f10..41231ef9 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -520,7 +520,6 @@ impl AppState { } self.write()?; - stdout.write_all(b"\n")?; Ok(first_pending_exercise_ind) } diff --git a/src/main.rs b/src/main.rs index 075e7265..5616d264 100644 --- a/src/main.rs +++ b/src/main.rs @@ -151,13 +151,15 @@ fn main() -> Result { app_state.set_current_exercise_ind(first_pending_exercise_ind)?; } + stdout.write_all(b"\n\n")?; + let pending = app_state.n_pending(); if pending == 1 { stdout.write_all(b"One exercise pending: ")?; } else { write!( stdout, - "{pending}/{} exercises are pending. The first: ", + "{pending}/{} exercises pending. The first: ", app_state.exercises().len(), )?; } diff --git a/src/term.rs b/src/term.rs index 0294017b..8a2f8c59 100644 --- a/src/term.rs +++ b/src/term.rs @@ -164,26 +164,34 @@ pub fn show_exercises_check_progress( let mut exercise_num = 1; for exercise_progress in progresses { - let color = match exercise_progress { - ExerciseCheckProgress::None => Color::Reset, - ExerciseCheckProgress::Checking => Color::Blue, - ExerciseCheckProgress::Done => Color::Green, - ExerciseCheckProgress::Pending => Color::Red, - }; - - stdout.queue(SetForegroundColor(color))?; - write!(stdout, "{exercise_num:<3}")?; - - if exercise_num % n_cols == 0 { - stdout.write_all(b"\n")?; - } else { - stdout.write_all(b" ")?; + match exercise_progress { + ExerciseCheckProgress::None => (), + ExerciseCheckProgress::Checking => { + stdout.queue(SetForegroundColor(Color::Blue))?; + } + ExerciseCheckProgress::Done => { + stdout.queue(SetForegroundColor(Color::Green))?; + } + ExerciseCheckProgress::Pending => { + stdout.queue(SetForegroundColor(Color::Red))?; + } } - exercise_num += 1; + write!(stdout, "{exercise_num:<3}")?; + stdout.queue(ResetColor)?; + + if exercise_num != progresses.len() { + if exercise_num % n_cols == 0 { + stdout.write_all(b"\n")?; + } else { + stdout.write_all(b" ")?; + } + + exercise_num += 1; + } } - stdout.queue(ResetColor)?.flush() + stdout.flush() } pub fn clear_terminal(stdout: &mut StdoutLock) -> io::Result<()> {