diff --git a/src/main.rs b/src/main.rs index 4778bc9..53fc6d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ use clap::{Parser, ValueEnum}; -use console::style; +// use console::style; use image::{GenericImageView, Pixel}; +use indicatif::ParallelProgressIterator; use indicatif::{HumanDuration, MultiProgress, ProgressBar, ProgressStyle}; -// use indicatif::{ParallelProgressIterator, ProgressBar, ProgressStyle}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; // use image::ImageEncoder; use kmeans_colors::{get_kmeans_hamerly, Kmeans, Sort}; @@ -19,7 +19,8 @@ use std::path::PathBuf; use std::collections::HashSet; use std::path::Path; -use std::thread; +// use std::rc::Rc; +// use std::thread; use std::time::{Duration, Instant}; /// CLI for extracting a color palette from an image and exporting it. @@ -84,9 +85,11 @@ impl RichColor { fn main() { let started = Instant::now(); - let spinner_style = ProgressStyle::with_template("{prefix:.bold.dim} {spinner} {wide_msg}") - .unwrap() - .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ "); + let spinner_style = ProgressStyle::with_template( + "[{elapsed_precise}] {spinner} {bar:40.cyan/blue} {pos}/{len} [{prefix:.bold.dim}]", + ) + .unwrap() + .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ "); let cli = Cli::parse(); let export_path = match cli.export { @@ -113,27 +116,29 @@ fn main() { }; let m = MultiProgress::new(); - // let style = ProgressStyle::default_bar(); - let handles: Vec<_> = cli + let pb_general = ProgressBar::new(cli.image.len() as u64) + // let pb_general = ProgressBar:: + .with_style(spinner_style.clone()) + // pb_general.set_style(spinner_style.clone()); + .with_prefix("Images being processed"); + m.add(pb_general.clone()); + pb_general.enable_steady_tick(Duration::from_millis(100)); + let colorblobs: Vec<_> = cli .image .par_iter() + .progress_with(pb_general.clone()) .map(|image| { let pb = m.add(ProgressBar::new(8)); // TODO: Not use 8 for passes and have it as parameter - // pb.set_style(spinner_style.clone()); + pb.enable_steady_tick(Duration::from_millis(100)); + pb.set_style(spinner_style.clone()); pb.set_prefix(format!("[{:?}]", image)); // Make shorter by def - let image = image.clone(); - thread::spawn(move || function(&image, cli.nb_colors, &pb)) + // pb_general.inc(1); + function(image, cli.nb_colors, &pb) }) - .collect(); - // .collect::>(); - for h in handles { - let _ = h.join(); - } - m.clear().unwrap(); - - // export(export_path, colorblobs); + .collect::>(); println!("Done in {}", HumanDuration(started.elapsed())); + export(export_path, colorblobs); } fn extract_kcluster(image: &PathBuf, nb_colors: Option, pb: &ProgressBar) -> ColorIndex {