Skip to content

Commit b3bc9ed

Browse files
committed
Update cleanup progress style & spinner
- Format the cleanup process in the same way as the size calculation progress - Change the non-verbose scan progress spinner back to the same design as before
1 parent 790a6bd commit b3bc9ed

File tree

1 file changed

+38
-17
lines changed

1 file changed

+38
-17
lines changed

src/main.rs

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ use std::{
1010
time::{Duration, SystemTime},
1111
};
1212

13+
const SPINNER_TICK_STRS: &[&'static str] = &[
14+
"[=---------]",
15+
"[-=--------]",
16+
"[--=-------]",
17+
"[---=------]",
18+
"[----=-----]",
19+
"[-----=----]",
20+
"[------=---]",
21+
"[-------=--]",
22+
"[--------=-]",
23+
"[---------=]",
24+
"[--------=-]",
25+
"[-------=--]",
26+
"[------=---]",
27+
"[-----=----]",
28+
"[----=-----]",
29+
"[---=------]",
30+
"[--=-------]",
31+
"[-=--------]",
32+
"[=---------]",
33+
];
34+
1335
#[derive(Debug, Parser)]
1436
#[clap(author, version, about, bin_name = "cargo clean-all", long_about = None)]
1537
struct AppArgs {
@@ -139,7 +161,7 @@ fn main() {
139161

140162
let spinner = ProgressBar::new_spinner()
141163
.with_message(format!("Scanning for projects in {}", args.root_dir))
142-
.with_style(ProgressStyle::default_spinner());
164+
.with_style(ProgressStyle::default_spinner().tick_strings(SPINNER_TICK_STRS));
143165

144166
if !args.verbose {
145167
spinner.enable_steady_tick(Duration::from_millis(100));
@@ -154,9 +176,8 @@ fn main() {
154176
multi_progress.clear().unwrap();
155177
spinner.finish_and_clear();
156178

157-
let pb = ProgressBar::new(cargo_projects.len() as u64);
158179
println!("Computing size of target/ for project");
159-
pb.set_style(
180+
let pb = ProgressBar::new(cargo_projects.len() as u64).with_style(
160181
ProgressStyle::with_template("[{elapsed}] [{bar:.cyan/blue}] {pos}/{len}: {msg}")
161182
.expect("Invalid template syntax")
162183
.progress_chars("#>-"),
@@ -259,15 +280,6 @@ fn main() {
259280

260281
println!("Starting cleanup...");
261282

262-
let clean_progress = ProgressBar::new(selected.len() as u64)
263-
.with_message("Deleting target directories")
264-
.with_style(
265-
ProgressStyle::default_bar()
266-
.template("{msg} [{bar:20}] {pos:>3}/{len:3}")
267-
.unwrap()
268-
.progress_chars("=> "),
269-
);
270-
271283
// Saves the executables in another folder before cleaning the target folder
272284
if args.executable {
273285
for project in selected.iter() {
@@ -331,14 +343,23 @@ fn main() {
331343
}
332344
}
333345

346+
let clean_progress = ProgressBar::new(selected.len() as u64).with_style(
347+
ProgressStyle::with_template("[{elapsed}] [{bar:}] {pos}/{len}: {msg}")
348+
.expect("Invalid template syntax")
349+
.progress_chars("#>-"),
350+
);
351+
334352
let failed_cleanups = selected.iter().filter_map(|tgt| {
335-
clean_progress.inc(1);
336-
remove_dir_all::remove_dir_all(&tgt.project_path.join("target"))
353+
clean_progress.set_message(format!("{}", tgt.project_path.display()));
354+
let res = remove_dir_all::remove_dir_all(&tgt.project_path.join("target"))
337355
.err()
338-
.map(|e| (tgt.clone(), e))
356+
.map(|e| (tgt.clone(), e));
357+
clean_progress.inc(1);
358+
res
339359
});
340360

341-
clean_progress.finish();
361+
clean_progress.finish_and_clear();
362+
println!("");
342363

343364
// The current leftover size calculation assumes that a failed deletion didn't delete anything.
344365
// This will not be true in most cases as a recursive deletion might delet stuff before failing.
@@ -350,7 +371,7 @@ fn main() {
350371
}
351372

352373
println!(
353-
"\nAll projects cleaned. Reclaimed {} of disk space",
374+
"\nProjects cleaned. Reclaimed {} of disk space",
354375
bytefmt::format(will_free_size - leftover_size).bold()
355376
);
356377
}

0 commit comments

Comments
 (0)