diff --git a/README.md b/README.md index 9f7f190..699a074 100644 --- a/README.md +++ b/README.md @@ -133,3 +133,5 @@ These benchmarks were run using [hyperfine](https://github.com/sharkdp/hyperfine - [ ] restore json output - [ ] update documentation - [x] remove color output +- [ ] progress bar improvements + - [ ] use progress bar groups diff --git a/src/processor.rs b/src/processor.rs index 1bf7809..ad0d5f1 100644 --- a/src/processor.rs +++ b/src/processor.rs @@ -1,6 +1,8 @@ use anyhow::Result; use dashmap::DashMap; -use indicatif::{ParallelProgressIterator, ProgressBar, ProgressFinish, ProgressStyle}; +use indicatif::{ + MultiProgress, ParallelProgressIterator, ProgressBar, ProgressFinish, ProgressStyle, +}; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; use std::borrow::Cow; use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; @@ -17,9 +19,10 @@ impl Processor { app_args: Arc, sw_store: Arc>>, hw_store: Arc>>, + progress_bar_box: Arc, ) -> Result<()> { let progress_bar = match app_args.progress { - true => ProgressBar::new_spinner(), + true => progress_bar_box.add(ProgressBar::new_spinner()), false => ProgressBar::hidden(), }; @@ -69,9 +72,10 @@ impl Processor { store: Arc>>, files: Arc>>, max_file_size: Arc, + progress_bar_box: Arc, ) -> Result<()> { let progress_bar = match app_args.progress { - true => ProgressBar::new_spinner(), + true => progress_bar_box.add(ProgressBar::new_spinner()), false => ProgressBar::hidden(), }; @@ -118,6 +122,7 @@ impl Processor { mod tests { use anyhow::Result; use dashmap::DashMap; + use indicatif::MultiProgress; use rand::Rng; use std::fs::File; use std::io::Write; @@ -162,6 +167,7 @@ mod tests { dupstore.clone(), file_queue, Arc::new(AtomicU64::new(0)), + Arc::new(MultiProgress::new()), )?; assert_eq!(dupstore.len(), 2); diff --git a/src/scanner.rs b/src/scanner.rs index 829aa94..d5703d5 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,7 +1,7 @@ #![allow(unused)] use crate::{fileinfo::FileInfo, params::Params}; use anyhow::Result; -use indicatif::{ProgressBar, ProgressStyle}; +use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use std::sync::{Arc, Mutex}; use std::{fs, path::PathBuf, time::Duration}; @@ -102,11 +102,16 @@ impl Scanner { Ok(walker.build()?) } - pub fn scan(&self, files: Arc>>) -> Result<()> { + pub fn scan( + &self, + files: Arc>>, + progress_bar_box: Arc, + ) -> Result<()> { let progress_bar = match self.progress { - true => ProgressBar::new_spinner(), + true => progress_bar_box.add(ProgressBar::new_spinner()), false => ProgressBar::hidden(), }; + let progress_style = ProgressStyle::with_template("[{elapsed_precise}] {pos:>7} {msg}")?; progress_bar.set_style(progress_style); progress_bar.enable_steady_tick(Duration::from_millis(50)); diff --git a/src/server.rs b/src/server.rs index f02bc41..deac0fe 100644 --- a/src/server.rs +++ b/src/server.rs @@ -5,6 +5,7 @@ use crate::processor::Processor; use crate::scanner::Scanner; use anyhow::Result; use dashmap::DashMap; +use indicatif::MultiProgress; use threadpool::ThreadPool; use crate::fileinfo::FileInfo; @@ -32,6 +33,8 @@ impl Server { } pub fn start(&self) -> Result<()> { + let progbarbox = Arc::new(MultiProgress::new()); + let app_args_clone_for_sc = self.app_args.clone(); let app_args_clone_for_pr = self.app_args.clone(); let file_queue_clone_sc = self.filequeue.clone(); @@ -46,15 +49,19 @@ impl Server { let store_dupl_hw = self.hw_duplicate_set.clone(); let max_file_path_len_clone = self.max_file_path_len.clone(); + let progbarbox_sc_clone = progbarbox.clone(); + self.threadpool.execute(move || { Scanner::build(app_args_clone_for_sc) .unwrap() - .scan(file_queue_clone_sc) + .scan(file_queue_clone_sc, progbarbox_sc_clone) .unwrap(); sfin_sc_tr_cl.store(true, std::sync::atomic::Ordering::Relaxed); }); + let progbarbox_pr_clone = progbarbox.clone(); + self.threadpool.execute(move || { Processor::sizewise( app_args_clone_for_pr.clone(), @@ -62,11 +69,17 @@ impl Server { store_dupl_sw_for_sw, file_queue_clone_pr, max_file_path_len_clone, + progbarbox_pr_clone.clone(), ) .unwrap(); - Processor::hashwise(app_args_clone_for_pr, store_dupl_sw_for_hw, store_dupl_hw) - .unwrap(); + Processor::hashwise( + app_args_clone_for_pr, + store_dupl_sw_for_hw, + store_dupl_hw, + progbarbox_pr_clone, + ) + .unwrap(); }); self.threadpool.join();