Skip to content

Commit 8cac215

Browse files
committed
Small improvements to showing progress
1 parent 396ee4d commit 8cac215

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

src/app_state.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ impl AppState {
520520
}
521521

522522
self.write()?;
523-
stdout.write_all(b"\n")?;
524523

525524
Ok(first_pending_exercise_ind)
526525
}

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,15 @@ fn main() -> Result<ExitCode> {
151151
app_state.set_current_exercise_ind(first_pending_exercise_ind)?;
152152
}
153153

154+
stdout.write_all(b"\n\n")?;
155+
154156
let pending = app_state.n_pending();
155157
if pending == 1 {
156158
stdout.write_all(b"One exercise pending: ")?;
157159
} else {
158160
write!(
159161
stdout,
160-
"{pending}/{} exercises are pending. The first: ",
162+
"{pending}/{} exercises pending. The first: ",
161163
app_state.exercises().len(),
162164
)?;
163165
}

src/term.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,26 +164,34 @@ pub fn show_exercises_check_progress(
164164

165165
let mut exercise_num = 1;
166166
for exercise_progress in progresses {
167-
let color = match exercise_progress {
168-
ExerciseCheckProgress::None => Color::Reset,
169-
ExerciseCheckProgress::Checking => Color::Blue,
170-
ExerciseCheckProgress::Done => Color::Green,
171-
ExerciseCheckProgress::Pending => Color::Red,
172-
};
173-
174-
stdout.queue(SetForegroundColor(color))?;
167+
match exercise_progress {
168+
ExerciseCheckProgress::None => (),
169+
ExerciseCheckProgress::Checking => {
170+
stdout.queue(SetForegroundColor(Color::Blue))?;
171+
}
172+
ExerciseCheckProgress::Done => {
173+
stdout.queue(SetForegroundColor(Color::Green))?;
174+
}
175+
ExerciseCheckProgress::Pending => {
176+
stdout.queue(SetForegroundColor(Color::Red))?;
177+
}
178+
}
179+
175180
write!(stdout, "{exercise_num:<3}")?;
181+
stdout.queue(ResetColor)?;
176182

177-
if exercise_num % n_cols == 0 {
178-
stdout.write_all(b"\n")?;
179-
} else {
180-
stdout.write_all(b" ")?;
181-
}
183+
if exercise_num != progresses.len() {
184+
if exercise_num % n_cols == 0 {
185+
stdout.write_all(b"\n")?;
186+
} else {
187+
stdout.write_all(b" ")?;
188+
}
182189

183-
exercise_num += 1;
190+
exercise_num += 1;
191+
}
184192
}
185193

186-
stdout.queue(ResetColor)?.flush()
194+
stdout.flush()
187195
}
188196

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

0 commit comments

Comments
 (0)