stabilize ui progress bars

This commit is contained in:
sreedev
2023-02-06 09:35:24 -05:00
parent 6e3fe4a37d
commit a65e22269c
2 changed files with 53 additions and 10 deletions

View File

@@ -48,18 +48,25 @@ fn scan(app_opts: &Params) -> Result<Vec<File>> {
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));
progress.enable_steady_tick(Duration::from_millis(50));
let files = walker
.progress_with(progress)
.filter_map(Result::ok)
.map(|file| file.into_path())
.filter(|fpath| fpath.is_file())
.collect::<Vec<PathBuf>>()
.collect::<Vec<PathBuf>>();
let scan_progress = ProgressBar::new(files.len() as u64);
let scan_progress_style = ProgressStyle::with_template(
"{spinner:.green} [processing mapped paths] [{wide_bar:.cyan/blue}] {pos}/{len} files",
)?;
scan_progress.set_style(scan_progress_style);
scan_progress.enable_steady_tick(Duration::from_millis(50));
let scan_results = files
.into_par_iter()
.progress_with_style(ProgressStyle::with_template(
"{spinner:.green} [processing mapped paths] [{wide_bar:.cyan/blue}] {pos}/{len} files",
)?)
.progress_with(scan_progress)
.map(|fpath| File {
path: fpath.clone(),
hash: None,
@@ -72,7 +79,7 @@ fn scan(app_opts: &Params) -> Result<Vec<File>> {
.filter(|file| filters::is_file_gt_min_size(app_opts, file))
.collect();
Ok(files)
Ok(scan_results)
}
fn process_file_index(
@@ -102,11 +109,16 @@ fn index_files(
index_criteria: IndexCritera,
) -> Result<DashMap<String, Vec<File>>> {
let store: DashMap<String, Vec<File>> = DashMap::new();
let index_progress = ProgressBar::new(files.len() as u64);
let index_progress_style = ProgressStyle::with_template(
"{spinner:.green} [indexing files] [{wide_bar:.cyan/blue}] {pos}/{len} files",
)?;
index_progress.set_style(index_progress_style);
index_progress.enable_steady_tick(Duration::from_millis(50));
files
.into_par_iter()
.progress_with_style(ProgressStyle::with_template(
"{spinner:.green} [indexing files] [{wide_bar:.cyan/blue}] {pos}/{len} files",
)?)
.progress_with(index_progress)
.for_each(|file| process_file_index(file, &store, index_criteria));
Ok(store)