Skip to content

Commit

Permalink
Small improvements to showing progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mo8it committed Oct 13, 2024
1 parent 396ee4d commit 8cac215
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ impl AppState {
}

self.write()?;
stdout.write_all(b"\n")?;

Ok(first_pending_exercise_ind)
}
Expand Down
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ fn main() -> Result<ExitCode> {
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(),
)?;
}
Expand Down
38 changes: 23 additions & 15 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
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))?;
}
}

write!(stdout, "{exercise_num:<3}")?;
stdout.queue(ResetColor)?;

if exercise_num % n_cols == 0 {
stdout.write_all(b"\n")?;
} else {
stdout.write_all(b" ")?;
}
if exercise_num != progresses.len() {
if exercise_num % n_cols == 0 {
stdout.write_all(b"\n")?;
} else {
stdout.write_all(b" ")?;
}

exercise_num += 1;
exercise_num += 1;
}
}

stdout.queue(ResetColor)?.flush()
stdout.flush()
}

pub fn clear_terminal(stdout: &mut StdoutLock) -> io::Result<()> {
Expand Down

0 comments on commit 8cac215

Please sign in to comment.