mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-06-17 00:07:35 +02:00
feat!: Add progress indicator
closes #360 BREAKING CHANGE: verify() has a new function signature so it can know the current completion progress
This commit is contained in:
13
src/main.rs
13
src/main.rs
@ -214,7 +214,7 @@ fn main() {
|
||||
}
|
||||
|
||||
Subcommands::Verify(_subargs) => {
|
||||
verify(&exercises, verbose).unwrap_or_else(|_| std::process::exit(1));
|
||||
verify(&exercises, (0, exercises.len()), verbose).unwrap_or_else(|_| std::process::exit(1));
|
||||
}
|
||||
|
||||
Subcommands::Watch(_subargs) => match watch(&exercises, verbose) {
|
||||
@ -351,7 +351,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
clear_screen();
|
||||
|
||||
let to_owned_hint = |t: &Exercise| t.hint.to_owned();
|
||||
let failed_exercise_hint = match verify(exercises.iter(), verbose) {
|
||||
let failed_exercise_hint = match verify(exercises.iter(), (0, exercises.len()), verbose) {
|
||||
Ok(_) => return Ok(WatchStatus::Finished),
|
||||
Err(exercise) => Arc::new(Mutex::new(Some(to_owned_hint(exercise)))),
|
||||
};
|
||||
@ -362,17 +362,16 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<WatchStatus> {
|
||||
DebouncedEvent::Create(b) | DebouncedEvent::Chmod(b) | DebouncedEvent::Write(b) => {
|
||||
if b.extension() == Some(OsStr::new("rs")) && b.exists() {
|
||||
let filepath = b.as_path().canonicalize().unwrap();
|
||||
let pending_exercises = exercises
|
||||
.iter()
|
||||
.skip_while(|e| !filepath.ends_with(&e.path))
|
||||
// .filter(|e| filepath.ends_with(&e.path))
|
||||
let pending_exercises = exercises.iter()
|
||||
.find(|e| filepath.ends_with(&e.path)).into_iter()
|
||||
.chain(
|
||||
exercises
|
||||
.iter()
|
||||
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)),
|
||||
);
|
||||
let num_done = exercises.iter().filter(|e| e.looks_done()).count();
|
||||
clear_screen();
|
||||
match verify(pending_exercises, verbose) {
|
||||
match verify(pending_exercises, (num_done, exercises.len()), verbose) {
|
||||
Ok(_) => return Ok(WatchStatus::Finished),
|
||||
Err(exercise) => {
|
||||
let mut failed_exercise_hint = failed_exercise_hint.lock().unwrap();
|
||||
|
Reference in New Issue
Block a user