From d0f14855fd2d98fff8089252543c9f6a43854a3e Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sun, 8 Sep 2024 14:26:37 +0200 Subject: [PATCH] Adds threading max count and better naming --- Palettes/Palettes.html | 35 +++++++++++++++++++++++++++++++++++ src/main.rs | 12 +++++++++++- src/utilities.rs | 29 +++++++++++++++++++++++++---- 3 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 Palettes/Palettes.html diff --git a/Palettes/Palettes.html b/Palettes/Palettes.html new file mode 100644 index 0000000..6dbc56d --- /dev/null +++ b/Palettes/Palettes.html @@ -0,0 +1,35 @@ +Palette: Palettes +

Beach

+ #787A7C +
+ #798086 +
+ #838484 +
+ #9D9C9E +
+ #71808E +
+ #A2A09F +
\ No newline at end of file diff --git a/src/main.rs b/src/main.rs index bf74269..8c922f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,10 @@ struct Cli { /// Extra Verbosity #[arg(short, default_value_t = false)] verbosity: bool, + + /// Number of threads (Defaults to the max number of threads) + #[arg(long)] + threads: Option, } fn main() { @@ -51,6 +55,12 @@ fn main() { .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ "); let cli = Cli::parse(); + if let Some(t) = cli.threads { + rayon::ThreadPoolBuilder::new() + .num_threads(t) + .build_global() + .unwrap(); + } let export_path = match cli.export.clone() { Some(e) => e, None => cli.image[0] @@ -91,7 +101,7 @@ fn main() { let pb = m.add(ProgressBar::new(cli.runs.unwrap_or(8))); pb.enable_steady_tick(Duration::from_millis(100)); pb.set_style(spinner_style.clone()); - pb.set_prefix(format!("[{:?}]", small_name(image))); + pb.set_prefix(small_name(image)); let r = function(image, &cli, &pb); pb_general.inc(1); r diff --git a/src/utilities.rs b/src/utilities.rs index 3295eda..d0563ef 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -1,4 +1,5 @@ use std::{ + borrow::Cow, fs::File, io::{BufWriter, Write}, path::{Path, PathBuf}, @@ -8,8 +9,29 @@ use crate::structs::ColorIndex; /// Make a smaller name pub(crate) fn small_name(name: &Path) -> String { - let os = format!("{:?}", name.to_string_lossy()); - os + let ancs = name.ancestors().collect::>(); + let l = ancs.len(); + let (beg, end, file_name) = if l > 2 { + ( + ancs[l - 2].to_string_lossy(), + ancs[1].file_name().unwrap().to_string_lossy(), + ancs[0].file_name().unwrap().to_string_lossy(), + ) + } else { + ( + Cow::Borrowed(""), + Cow::Borrowed(""), + ancs[0].file_name().unwrap().to_string_lossy(), + ) + }; + + if l > 3 { + format!("{}/../{}/{}", beg, end, file_name) + } else if l > 2 { + format!("{}/{}", beg, file_name) + } else { + format!("{}", file_name) + } } /// Extract the image name @@ -17,8 +39,7 @@ pub(crate) fn extract_name(image: &Path) -> String { image .file_name() .unwrap() - .to_str() - .unwrap() + .to_string_lossy() .split(".") .next() .unwrap()