From 10329015f7d6ccc753b072fb82f3d413c65c9769 Mon Sep 17 00:00:00 2001 From: sreedev Date: Mon, 23 Jan 2023 18:29:41 -0500 Subject: [PATCH] added more progress bars to avoid blank states --- src/output.rs | 9 +++++++++ src/scanner.rs | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/output.rs b/src/output.rs index 872b849..8767bfb 100644 --- a/src/output.rs +++ b/src/output.rs @@ -5,6 +5,7 @@ use chrono::offset::Utc; use chrono::DateTime; use colored::Colorize; use dashmap::DashMap; +use indicatif::{ProgressBar, ProgressIterator, ProgressStyle}; use itertools::Itertools; use prettytable::{format, row, Table}; use std::io::Write; @@ -153,10 +154,18 @@ pub fn print(duplicates: DashMap>, opts: &Params) { } let mut output_table = Table::new(); + let progress_bar = ProgressBar::new(duplicates.len() as u64); + let progress_style = ProgressStyle::default_bar() + .template("{spinner:.green} [generating output] [{wide_bar:.cyan/blue}] {pos}/{len} files") + .unwrap(); + + progress_bar.set_style(progress_style); output_table.set_titles(row!["hash", "duplicates"]); + duplicates .into_iter() .sorted_unstable_by_key(|(_, f)| f.first().and_then(|ff| ff.size).unwrap_or_default()) + .progress_with(progress_bar) .for_each(|(hash, group)| { let mut inner_table = Table::new(); inner_table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR); diff --git a/src/scanner.rs b/src/scanner.rs index eb99b7f..27ac8f5 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -2,10 +2,11 @@ use crate::{file_manager::File, filters, params::Params}; use anyhow::Result; use dashmap::DashMap; use fxhash::hash64 as hasher; -use indicatif::{ParallelProgressIterator, ProgressStyle}; +use indicatif::{ParallelProgressIterator, ProgressBar, ProgressIterator, ProgressStyle}; use memmap2::Mmap; use rayon::prelude::*; use std::hash::Hasher; +use std::time::Duration; use std::{fs, path::PathBuf}; #[derive(Clone, Copy)] @@ -40,14 +41,21 @@ pub fn duplicates(app_opts: &Params) -> Result>> { fn scan(app_opts: &Params) -> Result> { let walker = app_opts.get_glob_walker()?; + let progress = ProgressBar::new_spinner(); + let progress_style = + ProgressStyle::with_template("{spinner:.green} [mapping paths] {pos} paths")?; + progress.set_style(progress_style); + progress.enable_steady_tick(Duration::from_millis(100)); + let files = walker + .progress_with(progress) .filter_map(Result::ok) .map(|file| file.into_path()) .filter(|fpath| fpath.is_file()) .collect::>() .into_par_iter() .progress_with_style(ProgressStyle::with_template( - "{spinner:.green} [processing scan results] [{wide_bar:.cyan/blue}] {pos}/{len} files", + "{spinner:.green} [processing mapped paths] [{wide_bar:.cyan/blue}] {pos}/{len} files", )?) .map(|fpath| fpath.display().to_string()) .map(|fpath| File {