Skip to content

Commit 90cd37c

Browse files
author
yourname
committed
feat(list): added progress info
Added a progress info at the bottom of the list for command: rustlings list closes rust-lang#705
1 parent e1f1f5d commit 90cd37c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/main.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,19 @@ fn main() {
138138
println!("{:<17}\t{:<46}\t{:<7}", "Name", "Path", "Status");
139139
}
140140
let filters = list_m.value_of("filter").unwrap_or_default().to_lowercase();
141+
let mut exercises_done: u16 = 0;
141142
exercises.iter().for_each(|e| {
142143
let fname = format!("{}", e.path.display());
143144
let filter_cond = filters
144145
.split(',')
145146
.filter(|f| !f.trim().is_empty())
146147
.any(|f| e.name.contains(&f) || fname.contains(&f));
147-
let status = if e.looks_done() { "Done" } else { "Pending" };
148+
let status = if e.looks_done() {
149+
exercises_done = exercises_done + 1;
150+
"Done"
151+
} else {
152+
"Pending"
153+
};
148154
let solve_cond = {
149155
(e.looks_done() && list_m.is_present("solved"))
150156
|| (!e.looks_done() && list_m.is_present("unsolved"))
@@ -173,6 +179,13 @@ fn main() {
173179
}
174180
}
175181
});
182+
let percentage_progress = exercises_done as f32 / exercises.len() as f32;
183+
println!(
184+
"Progress: You completed {} / {} exercises ({:.2} %).",
185+
exercises_done,
186+
exercises.len(),
187+
percentage_progress
188+
);
176189
std::process::exit(0);
177190
}
178191

@@ -314,7 +327,7 @@ fn watch(exercises: &[Exercise], verbose: bool) -> notify::Result<()> {
314327
.chain(
315328
exercises
316329
.iter()
317-
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path))
330+
.filter(|e| !e.looks_done() && !filepath.ends_with(&e.path)),
318331
);
319332
clear_screen();
320333
match verify(pending_exercises, verbose) {

0 commit comments

Comments
 (0)