summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-04-10 00:51:41 +0200
committermo8it <mo8it@proton.me>2024-04-10 00:51:41 +0200
commit533a009257adba0714292d326f57671f77cffbd3 (patch)
tree6b0a8182d765a4ccfa0a96d42049dbe6dec0eb07
parent4a80bf64411f228c35c173b6188df5114d4c52fa (diff)
Show the progress in the progress bar, not the current exercise index
-rw-r--r--src/watch/state.rs9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/watch/state.rs b/src/watch/state.rs
index 24978bb..4db9440 100644
--- a/src/watch/state.rs
+++ b/src/watch/state.rs
@@ -20,6 +20,7 @@ pub struct WatchState<'a> {
exercises: &'static [Exercise],
exercise: &'static Exercise,
current_exercise_ind: usize,
+ progress: u16,
stdout: Option<Vec<u8>>,
stderr: Option<Vec<u8>>,
message: Option<String>,
@@ -29,6 +30,7 @@ pub struct WatchState<'a> {
impl<'a> WatchState<'a> {
pub fn new(state_file: &StateFile, exercises: &'static [Exercise]) -> Self {
let current_exercise_ind = state_file.next_exercise_ind();
+ let progress = state_file.progress().iter().filter(|done| **done).count() as u16;
let exercise = &exercises[current_exercise_ind];
let writer = io::stdout().lock();
@@ -46,6 +48,7 @@ impl<'a> WatchState<'a> {
exercises,
exercise,
current_exercise_ind,
+ progress,
stdout: None,
stderr: None,
message: None,
@@ -139,11 +142,7 @@ You can keep working on this exercise or jump into the next one by removing the
self.writer.write_all(b"\n")?;
let line_width = size()?.0;
- let progress_bar = progress_bar(
- self.current_exercise_ind as u16,
- self.exercises.len() as u16,
- line_width,
- )?;
+ let progress_bar = progress_bar(self.progress, self.exercises.len() as u16, line_width)?;
self.writer.write_all(progress_bar.as_bytes())?;
self.show_prompt()?;