mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
Fix indicatif
This commit is contained in:
parent
c655612d2d
commit
c0b8af2c42
|
@ -1,4 +1,5 @@
|
|||
use std::process::Command;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::exercise::{Exercise, Mode};
|
||||
use crate::verify::test;
|
||||
|
@ -36,7 +37,7 @@ pub fn reset(exercise: &Exercise) -> Result<(), ()> {
|
|||
fn compile_and_run(exercise: &Exercise) -> Result<(), ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Compiling {exercise}..."));
|
||||
progress_bar.enable_steady_tick(100);
|
||||
progress_bar.enable_steady_tick(Duration::from_millis(100));
|
||||
|
||||
let compilation_result = exercise.compile();
|
||||
let compilation = match compilation_result {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::exercise::{CompiledExercise, Exercise, Mode, State};
|
||||
use console::style;
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use std::env;
|
||||
use std::{env, time::Duration};
|
||||
|
||||
// Verify that the provided container of Exercise objects
|
||||
// can be compiled and run without any failures.
|
||||
|
@ -17,9 +17,11 @@ pub fn verify<'a>(
|
|||
let (num_done, total) = progress;
|
||||
let bar = ProgressBar::new(total as u64);
|
||||
let mut percentage = num_done as f32 / total as f32 * 100.0;
|
||||
bar.set_style(ProgressStyle::default_bar()
|
||||
.template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}")
|
||||
.progress_chars("#>-")
|
||||
bar.set_style(
|
||||
ProgressStyle::default_bar()
|
||||
.template("Progress: [{bar:60.green/red}] {pos}/{len} {msg}")
|
||||
.expect("Progressbar template should be valid!")
|
||||
.progress_chars("#>-"),
|
||||
);
|
||||
bar.set_position(num_done as u64);
|
||||
bar.set_message(format!("({:.1} %)", percentage));
|
||||
|
@ -55,7 +57,7 @@ pub fn test(exercise: &Exercise, verbose: bool) -> Result<(), ()> {
|
|||
fn compile_only(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Compiling {exercise}..."));
|
||||
progress_bar.enable_steady_tick(100);
|
||||
progress_bar.enable_steady_tick(Duration::from_millis(100));
|
||||
|
||||
let _ = compile(exercise, &progress_bar)?;
|
||||
progress_bar.finish_and_clear();
|
||||
|
@ -67,7 +69,7 @@ fn compile_only(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
|
|||
fn compile_and_run_interactively(exercise: &Exercise, success_hints: bool) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Compiling {exercise}..."));
|
||||
progress_bar.enable_steady_tick(100);
|
||||
progress_bar.enable_steady_tick(Duration::from_millis(100));
|
||||
|
||||
let compilation = compile(exercise, &progress_bar)?;
|
||||
|
||||
|
@ -85,15 +87,24 @@ fn compile_and_run_interactively(exercise: &Exercise, success_hints: bool) -> Re
|
|||
}
|
||||
};
|
||||
|
||||
Ok(prompt_for_completion(exercise, Some(output.stdout), success_hints))
|
||||
Ok(prompt_for_completion(
|
||||
exercise,
|
||||
Some(output.stdout),
|
||||
success_hints,
|
||||
))
|
||||
}
|
||||
|
||||
// Compile the given Exercise as a test harness and display
|
||||
// the output if verbose is set to true
|
||||
fn compile_and_test(exercise: &Exercise, run_mode: RunMode, verbose: bool, success_hints: bool) -> Result<bool, ()> {
|
||||
fn compile_and_test(
|
||||
exercise: &Exercise,
|
||||
run_mode: RunMode,
|
||||
verbose: bool,
|
||||
success_hints: bool,
|
||||
) -> Result<bool, ()> {
|
||||
let progress_bar = ProgressBar::new_spinner();
|
||||
progress_bar.set_message(format!("Testing {exercise}..."));
|
||||
progress_bar.enable_steady_tick(100);
|
||||
progress_bar.enable_steady_tick(Duration::from_millis(100));
|
||||
|
||||
let compilation = compile(exercise, &progress_bar)?;
|
||||
let result = compilation.run();
|
||||
|
@ -143,7 +154,11 @@ fn compile<'a, 'b>(
|
|||
}
|
||||
}
|
||||
|
||||
fn prompt_for_completion(exercise: &Exercise, prompt_output: Option<String>, success_hints: bool) -> bool {
|
||||
fn prompt_for_completion(
|
||||
exercise: &Exercise,
|
||||
prompt_output: Option<String>,
|
||||
success_hints: bool,
|
||||
) -> bool {
|
||||
let context = match exercise.state() {
|
||||
State::Done => return true,
|
||||
State::Pending(context) => context,
|
||||
|
|
Loading…
Reference in a new issue