Skip to content

Commit c0b8af2

Browse files
committed
Fix indicatif
1 parent c655612 commit c0b8af2

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/run.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::process::Command;
2+
use std::time::Duration;
23

34
use crate::exercise::{Exercise, Mode};
45
use crate::verify::test;
@@ -36,7 +37,7 @@ pub fn reset(exercise: &Exercise) -> Result<(), ()> {
3637
fn compile_and_run(exercise: &Exercise) -> Result<(), ()> {
3738
let progress_bar = ProgressBar::new_spinner();
3839
progress_bar.set_message(format!("Compiling {exercise}..."));
39-
progress_bar.enable_steady_tick(100);
40+
progress_bar.enable_steady_tick(Duration::from_millis(100));
4041

4142
let compilation_result = exercise.compile();
4243
let compilation = match compilation_result {

src/verify.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
22
use console::style;
33
use indicatif::{ProgressBar, ProgressStyle};
4-
use std::env;
4+
use std::{env, time::Duration};
55

66
// Verify that the provided container of Exercise objects
77
// can be compiled and run without any failures.
@@ -17,9 +17,11 @@ pub fn verify<'a>(
1717
let (num_done, total) = progress;
1818
let bar = ProgressBar::new(total as u64);
1919
let mut percentage = num_done as f32 / total as f32 * 100.0;
20-
bar.set_style(ProgressStyle::default_bar()
21-
.template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}")
22-
.progress_chars("#>-")
20+
bar.set_style(
21+
ProgressStyle::default_bar()
22+
.template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}")
23+
.expect("Progressbar template should be valid!")
24+
.progress_chars("#>-"),
2325
);
2426
bar.set_position(num_done as u64);
2527
bar.set_message(format!("({:.1} %)", percentage));
@@ -55,7 +57,7 @@ pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
5557
fn compile_only(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
5658
let progress_bar = ProgressBar::new_spinner();
5759
progress_bar.set_message(format!("Compiling {exercise}..."));
58-
progress_bar.enable_steady_tick(100);
60+
progress_bar.enable_steady_tick(Duration::from_millis(100));
5961

6062
let _ = compile(exercise, &progress_bar)?;
6163
progress_bar.finish_and_clear();
@@ -67,7 +69,7 @@ fn compile_only(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
6769
fn compile_and_run_interactively(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
6870
let progress_bar = ProgressBar::new_spinner();
6971
progress_bar.set_message(format!("Compiling {exercise}..."));
70-
progress_bar.enable_steady_tick(100);
72+
progress_bar.enable_steady_tick(Duration::from_millis(100));
7173

7274
let compilation = compile(exercise, &progress_bar)?;
7375

@@ -85,15 +87,24 @@ fn compile_and_run_interactively(exercise: &Exercise, success_hints: bool) -> Re
8587
}
8688
};
8789

88-
Ok(prompt_for_completion(exercise, Some(output.stdout), success_hints))
90+
Ok(prompt_for_completion(
91+
exercise,
92+
Some(output.stdout),
93+
success_hints,
94+
))
8995
}
9096

9197
// Compile the given Exercise as a test harness and display
9298
// the output if verbose is set to true
93-
fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool, success_hints: bool) -> Result<bool, ()> {
99+
fn compile_and_test(
100+
exercise: &Exercise,
101+
run_mode: RunMode,
102+
verbose: bool,
103+
success_hints: bool,
104+
) -> Result<bool, ()> {
94105
let progress_bar = ProgressBar::new_spinner();
95106
progress_bar.set_message(format!("Testing {exercise}..."));
96-
progress_bar.enable_steady_tick(100);
107+
progress_bar.enable_steady_tick(Duration::from_millis(100));
97108

98109
let compilation = compile(exercise, &progress_bar)?;
99110
let result = compilation.run();
@@ -143,7 +154,11 @@ fn compile<'a, 'b>(
143154
}
144155
}
145156

146-
fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>, success_hints: bool) -> bool {
157+
fn prompt_for_completion(
158+
exercise: &Exercise,
159+
prompt_output: Option<String>,
160+
success_hints: bool,
161+
) -> bool {
147162
let context = match exercise.state() {
148163
State::Done => return true,
149164
State::Pending(context) => context,

0 commit comments

Comments
 (0)