@@ -15,6 +15,7 @@ use crate::{
15
15
cmd:: CmdRunner ,
16
16
exercise:: { OUTPUT_CAPACITY , RunnableExercise } ,
17
17
info_file:: { ExerciseInfo , InfoFile } ,
18
+ term:: ProgressCounter ,
18
19
} ;
19
20
20
21
const MAX_N_EXERCISES : usize = 999 ;
@@ -217,10 +218,7 @@ fn check_exercises_unsolved(
217
218
. collect :: < Result < Vec < _ > , _ > > ( )
218
219
. context ( "Failed to spawn a thread to check if an exercise is already solved" ) ?;
219
220
220
- let n_handles = handles. len ( ) ;
221
- write ! ( stdout, "Progress: 0/{n_handles}" ) ?;
222
- stdout. flush ( ) ?;
223
- let mut handle_num = 1 ;
221
+ let mut progress_counter = ProgressCounter :: new ( & mut stdout, handles. len ( ) ) ?;
224
222
225
223
for ( exercise_name, handle) in handles {
226
224
let Ok ( result) = handle. join ( ) else {
@@ -235,11 +233,8 @@ fn check_exercises_unsolved(
235
233
Err ( e) => return Err ( e) ,
236
234
}
237
235
238
- write ! ( stdout, "\r Progress: {handle_num}/{n_handles}" ) ?;
239
- stdout. flush ( ) ?;
240
- handle_num += 1 ;
236
+ progress_counter. increment ( ) ?;
241
237
}
242
- stdout. write_all ( b"\n " ) ?;
243
238
244
239
Ok ( ( ) )
245
240
}
@@ -318,10 +313,7 @@ fn check_solutions(
318
313
. arg ( "always" )
319
314
. stdin ( Stdio :: null ( ) ) ;
320
315
321
- let n_handles = handles. len ( ) ;
322
- write ! ( stdout, "Progress: 0/{n_handles}" ) ?;
323
- stdout. flush ( ) ?;
324
- let mut handle_num = 1 ;
316
+ let mut progress_counter = ProgressCounter :: new ( & mut stdout, handles. len ( ) ) ?;
325
317
326
318
for ( exercise_info, handle) in info_file. exercises . iter ( ) . zip ( handles) {
327
319
let Ok ( check_result) = handle. join ( ) else {
@@ -338,7 +330,7 @@ fn check_solutions(
338
330
}
339
331
SolutionCheck :: MissingOptional => ( ) ,
340
332
SolutionCheck :: RunFailure { output } => {
341
- stdout . write_all ( b" \n \n " ) ? ;
333
+ drop ( progress_counter ) ;
342
334
stdout. write_all ( & output) ?;
343
335
bail ! (
344
336
"Running the solution of the exercise {} failed with the error above" ,
@@ -348,11 +340,8 @@ fn check_solutions(
348
340
SolutionCheck :: Err ( e) => return Err ( e) ,
349
341
}
350
342
351
- write ! ( stdout, "\r Progress: {handle_num}/{n_handles}" ) ?;
352
- stdout. flush ( ) ?;
353
- handle_num += 1 ;
343
+ progress_counter. increment ( ) ?;
354
344
}
355
- stdout. write_all ( b"\n " ) ?;
356
345
357
346
let n_solutions = sol_paths. len ( ) ;
358
347
let handle = thread:: Builder :: new ( )
0 commit comments