mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-25 23:04:17 -05:00
feat(list): added progress info
Added a progress info at the bottom of the list for command: rustlings list closes #705
This commit is contained in:
parent
f2ad3a6a0b
commit
c0e3daacaf
1 changed files with 15 additions and 2 deletions
17
src/main.rs
17
src/main.rs
|
@ -138,13 +138,19 @@ fn main() {
|
||||||
println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status");
|
println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status");
|
||||||
}
|
}
|
||||||
let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase();
|
let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase();
|
||||||
|
let mut exercises_done: u16 = 0;
|
||||||
exercises.iter().for_each(|e| {
|
exercises.iter().for_each(|e| {
|
||||||
let fname = format!("{}", e.path.display());
|
let fname = format!("{}", e.path.display());
|
||||||
let filter_cond = filters
|
let filter_cond = filters
|
||||||
.split(',')
|
.split(',')
|
||||||
.filter(|f| !f.trim().is_empty())
|
.filter(|f| !f.trim().is_empty())
|
||||||
.any(|f| e.name.contains(&f) || fname.contains(&f));
|
.any(|f| e.name.contains(&f) || fname.contains(&f));
|
||||||
let status = if e.looks_done() { "Done" } else { "Pending" };
|
let status = if e.looks_done() {
|
||||||
|
exercises_done = exercises_done + 1;
|
||||||
|
"Done"
|
||||||
|
} else {
|
||||||
|
"Pending"
|
||||||
|
};
|
||||||
let solve_cond = {
|
let solve_cond = {
|
||||||
(e.looks_done() && list_m.is_present("solved"))
|
(e.looks_done() && list_m.is_present("solved"))
|
||||||
|| (!e.looks_done() && list_m.is_present("unsolved"))
|
|| (!e.looks_done() && list_m.is_present("unsolved"))
|
||||||
|
@ -173,6 +179,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
let percentage_progress = exercises_done as f32 / exercises.len() as f32;
|
||||||
|
println!(
|
||||||
|
"Progress: You completed {} / {} exercises ({:.2} %).",
|
||||||
|
exercises_done,
|
||||||
|
exercises.len(),
|
||||||
|
percentage_progress
|
||||||
|
);
|
||||||
std::process::exit(0);
|
std::process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +327,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {
|
||||||
.chain(
|
.chain(
|
||||||
exercises
|
exercises
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path))
|
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)),
|
||||||
);
|
);
|
||||||
clear_screen();
|
clear_screen();
|
||||||
match verify(pending_exercises, verbose) {
|
match verify(pending_exercises, verbose) {
|
||||||
|
|
Loading…
Reference in a new issue