From 916613773b6054aa55578b1a4bfd4a3db694c627 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 12 Mar 2023 14:13:55 +0100 Subject: [PATCH] Add Progressbar --- schemsearch-cli/Cargo.toml | 1 + schemsearch-cli/src/main.rs | 3 ++- schemsearch-lib/src/lib.rs | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/schemsearch-cli/Cargo.toml b/schemsearch-cli/Cargo.toml index f328a1b..471392e 100644 --- a/schemsearch-cli/Cargo.toml +++ b/schemsearch-cli/Cargo.toml @@ -15,6 +15,7 @@ clap = { version = "4.1.8", features = ["cargo"] } futures = { version = "0.3", optional = true } sqlx = { version = "0.6", features = [ "runtime-async-std-native-tls" , "mysql" ], optional = true } rayon = "1.7.0" +indicatif = { version = "0.17.3", features = ["rayon"] } [features] sql = ["dep:schemsearch-sql", "dep:futures", "dep:sqlx"] diff --git a/schemsearch-cli/src/main.rs b/schemsearch-cli/src/main.rs index 8841b0f..ca155b2 100644 --- a/schemsearch-cli/src/main.rs +++ b/schemsearch-cli/src/main.rs @@ -36,6 +36,7 @@ use schemsearch_sql::filter::SchematicFilter; use schemsearch_sql::load_all_schematics; #[cfg(feature = "sql")] use crate::types::SqlSchematicSupplier; +use indicatif::{ProgressBar, ParallelProgressIterator, ProgressStyle}; fn main() { #[allow(unused_mut)] @@ -256,7 +257,7 @@ fn main() { } ThreadPoolBuilder::new().num_threads(*matches.get_one::("threads").expect("Could not get threads")).build_global().unwrap(); - let matches: Vec = schematics.par_iter().map(|schem| { + let matches: Vec = schematics.par_iter().progress_with_style(ProgressStyle::default_bar()).map(|schem| { match schem { SchematicSupplierType::PATH(schem) => { let schematic = match load_schem(&schem.path) { diff --git a/schemsearch-lib/src/lib.rs b/schemsearch-lib/src/lib.rs index e082d6c..4318366 100644 --- a/schemsearch-lib/src/lib.rs +++ b/schemsearch-lib/src/lib.rs @@ -120,14 +120,14 @@ pub fn parse_schematic(data: &Vec) -> Schematic { #[allow(unused_imports)] #[cfg(test)] mod tests { - use std::path::Path; + use std::path::{Path, PathBuf}; use schemsearch_files::Schematic; use crate::pattern_mapper::strip_data; use super::*; #[test] fn read_schematic() { - let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); + let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap(); assert_eq!(schematic.width as usize * schematic.height as usize * schematic.length as usize, schematic.block_data.len()); assert_eq!(schematic.palette_max, schematic.palette.len() as i32); } @@ -142,7 +142,7 @@ mod tests { #[test] fn test_strip_schem() { - let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); + let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap(); let stripped = strip_data(&schematic); assert_eq!(stripped.palette.keys().any(|k| k.contains('[')), false); @@ -150,24 +150,24 @@ mod tests { #[test] fn test_match_palette() { - let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); - let endstone = Schematic::load(Path::new("../tests/endstone.schem")).unwrap(); + let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap(); + let endstone = Schematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap(); let _ = match_palette(&schematic, &endstone, true); } #[test] fn test_match_palette_ignore_data() { - let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); - let endstone = Schematic::load(Path::new("../tests/endstone.schem")).unwrap(); + let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap(); + let endstone = Schematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap(); let _ = match_palette(&schematic, &endstone, false); } #[test] pub fn test_big_search() { - let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); - let endstone = Schematic::load(Path::new("../tests/endstone.schem")).unwrap(); + let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap(); + let endstone = Schematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap(); let _ = search(schematic, &endstone, SearchBehavior { ignore_block_data: true, @@ -181,8 +181,8 @@ mod tests { #[test] pub fn test_search() { - let schematic = Schematic::load(Path::new("../tests/Random.schem")).unwrap(); - let pattern = Schematic::load(Path::new("../tests/Pattern.schem")).unwrap(); + let schematic = Schematic::load(&PathBuf::from("../tests/Random.schem")).unwrap(); + let pattern = Schematic::load(&PathBuf::from("../tests/Pattern.schem")).unwrap(); let matches = search(schematic, &pattern, SearchBehavior { ignore_block_data: true, @@ -200,8 +200,8 @@ mod tests { #[test] pub fn test_search_ws() { - let schematic = Schematic::load(Path::new("../tests/warships/GreyFly-by-Bosslar.schem")).unwrap(); - let pattern = Schematic::load(Path::new("../tests/gray_castle_complex.schem")).unwrap(); + let schematic = Schematic::load(&PathBuf::from("../tests/warships/GreyFly-by-Bosslar.schem")).unwrap(); + let pattern = Schematic::load(&PathBuf::from("../tests/gray_castle_complex.schem")).unwrap(); let matches = search(schematic, &pattern, SearchBehavior { ignore_block_data: false,