Skip to content

Commit 554301b

Browse files
committed
Clear terminal before final check in watch mode
1 parent a55e848 commit 554301b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/app_state.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl AppState {
381381

382382
// Return the exercise index of the first pending exercise found.
383383
fn check_all_exercises(&self, stdout: &mut StdoutLock) -> Result<Option<usize>> {
384-
stdout.write_all(RERUNNING_ALL_EXERCISES_MSG)?;
384+
stdout.write_all(FINAL_CHECK_MSG)?;
385385
let n_exercises = self.exercises.len();
386386

387387
let status = thread::scope(|s| {
@@ -441,7 +441,10 @@ impl AppState {
441441
/// Mark the current exercise as done and move on to the next pending exercise if one exists.
442442
/// If all exercises are marked as done, run all of them to make sure that they are actually
443443
/// done. If an exercise which is marked as done fails, mark it as pending and continue on it.
444-
pub fn done_current_exercise(&mut self, stdout: &mut StdoutLock) -> Result<ExercisesProgress> {
444+
pub fn done_current_exercise<const CLEAR_BEFORE_FINAL_CHECK: bool>(
445+
&mut self,
446+
stdout: &mut StdoutLock,
447+
) -> Result<ExercisesProgress> {
445448
let exercise = &mut self.exercises[self.current_exercise_ind];
446449
if !exercise.done {
447450
exercise.done = true;
@@ -453,6 +456,12 @@ impl AppState {
453456
return Ok(ExercisesProgress::NewPending);
454457
}
455458

459+
if CLEAR_BEFORE_FINAL_CHECK {
460+
clear_terminal(stdout)?;
461+
} else {
462+
stdout.write_all(b"\n")?;
463+
}
464+
456465
if let Some(pending_exercise_ind) = self.check_all_exercises(stdout)? {
457466
stdout.write_all(b"\n\n")?;
458467

@@ -482,8 +491,7 @@ impl AppState {
482491

483492
const BAD_INDEX_ERR: &str = "The current exercise index is higher than the number of exercises";
484493
const STATE_FILE_HEADER: &[u8] = b"DON'T EDIT THIS FILE!\n\n";
485-
const RERUNNING_ALL_EXERCISES_MSG: &[u8] = b"
486-
All exercises seem to be done.
494+
const FINAL_CHECK_MSG: &[u8] = b"All exercises seem to be done.
487495
Recompiling and running all exercises to make sure that all of them are actually done.
488496
";
489497
const FENISH_LINE: &str = "+----------------------------------------------------+

src/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn run(app_state: &mut AppState) -> Result<()> {
4444
stdout.write_all(b"\n")?;
4545
}
4646

47-
match app_state.done_current_exercise(&mut stdout)? {
47+
match app_state.done_current_exercise::<false>(&mut stdout)? {
4848
ExercisesProgress::NewPending | ExercisesProgress::CurrentPending => {
4949
stdout.write_all(b"Next exercise: ")?;
5050
app_state

src/watch/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a> WatchState<'a> {
113113
return Ok(ExercisesProgress::CurrentPending);
114114
}
115115

116-
self.app_state.done_current_exercise(stdout)
116+
self.app_state.done_current_exercise::<true>(stdout)
117117
}
118118

119119
fn show_prompt(&self, stdout: &mut StdoutLock) -> io::Result<()> {

0 commit comments

Comments
 (0)