From e15493dd8e065b6331a392a309642f65c49c30ba Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:06:07 +0300 Subject: [PATCH 01/59] add set_alpha filter --- src/util/filters.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/util/filters.rs b/src/util/filters.rs index b21d0b8..91b07c2 100644 --- a/src/util/filters.rs +++ b/src/util/filters.rs @@ -1,3 +1,4 @@ +use colorsys::ColorAlpha; use colorsys::ColorTransform; use colorsys::Hsl; use colorsys::Rgb; @@ -7,7 +8,8 @@ use upon::Value; use crate::util::template::{check_string_value, parse_color}; use crate::util::color::{ - format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba, + format_hex, format_hex_stripped, format_hsl, format_hsla, format_hsla_float, format_rgb, + format_rgba, format_rgba_float, }; pub fn set_lightness(value: &Value, amount: f64) -> Result { @@ -67,3 +69,37 @@ pub fn set_lightness(value: &Value, amount: f64) -> Result { v => Ok(v.to_string()), } } + +pub fn set_alpha(value: &Value, amount: f64) -> Result { + let string = check_string_value(value).unwrap(); + + let format = parse_color(string); + + debug!("Setting alpha on string {} by {}", string, amount); + + if format.is_none() { + return Ok(string.to_string()); + } + + if !(0.0..=1.0).contains(&amount) { + return Err("alpha must be in range [0.0 to 1.0]".to_string()); + } + + match format.unwrap() { + "hex" => Err("cannot set alpha on hex color".to_string()), + "hex_stripped" => Err("cannot set alpha on hex color".to_string()), + "rgb" => Err("cannot set alpha on rgb color, use rgba".to_string()), + "rgba" => { + let mut color = Rgb::from_str(string).unwrap(); + color.set_alpha(amount); + Ok(format_rgba_float(&color)) + } + "hsl" => Err("cannot set alpha on hsl color, use hsla".to_string()), + "hsla" => { + let mut color = Hsl::from_str(string).unwrap(); + color.set_alpha(amount); + Ok(format_hsla_float(&color)) + } + v => Ok(v.to_string()), + } +} From 27b34c61b0ed620eb58e66084658eb871242472f Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:07:16 +0300 Subject: [PATCH 02/59] add format_rgba_float and format_hsla_float functions to format the alpha value as a float instead of u8 --- src/util/color.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/color.rs b/src/util/color.rs index a5b0a5d..fbef8bc 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -64,6 +64,16 @@ pub fn format_rgba(color: &Rgb) -> String { ) } +pub fn format_rgba_float(color: &Rgb) -> String { + format!( + "rgba({:?}, {:?}, {:?}, {:.1})", + color.red() as u8, + color.green() as u8, + color.blue() as u8, + color.alpha() + ) +} + pub fn format_hsl(color: &Hsl) -> String { format!( "hsl({:?}, {:?}%, {:?}%)", @@ -83,6 +93,16 @@ pub fn format_hsla(color: &Hsl) -> String { ) } +pub fn format_hsla_float(color: &Hsl) -> String { + format!( + "hsla({:?}, {:?}%, {:?}%, {:.1})", + color.hue() as u8, + color.saturation() as u8, + color.lightness() as u8, + color.alpha() + ) +} + pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { let c1 = Lab::from(Argb::from_str(c1).unwrap()); let c2 = Lab::from(Argb::from_str(c2).unwrap()); From 844b1c7b96e278cf0ebde16f1e0b6ab442b4b0c8 Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:08:52 +0300 Subject: [PATCH 03/59] add the set_alpha filter to the engine --- src/util/template.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/template.rs b/src/util/template.rs index cae13ba..5c77049 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -12,7 +12,7 @@ use upon::Value; use crate::util::color; use crate::util::color::color_to_string; -use crate::util::filters::set_lightness; +use crate::util::filters::{set_alpha, set_lightness}; use crate::util::variables::format_hook_text; use std::fs::canonicalize; @@ -302,6 +302,7 @@ fn export_template( fn add_engine_filters(engine: &mut Engine) { engine.add_filter("set_lightness", set_lightness); + engine.add_filter("set_alpha", set_alpha); engine.add_filter("to_upper", str::to_uppercase); engine.add_filter("to_lower", str::to_lowercase); engine.add_filter("replace", |s: String, from: String, to: String| { From e7a33e4d883badc36465e7fff61bab7ff8300612 Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:09:34 +0300 Subject: [PATCH 04/59] add set_alpha filter example --- example/colors.whatever-extension | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/colors.whatever-extension b/example/colors.whatever-extension index 8bcc5f7..63a4e3b 100644 --- a/example/colors.whatever-extension +++ b/example/colors.whatever-extension @@ -22,4 +22,8 @@ source_color {{colors.source_color.default.hex}}; <* for name, value in colors *> {{name | replace: "_", "-" }} {{value.default.hex}}; -<* endfor *> \ No newline at end of file +<* endfor *> + +Only works with rgba and hsla +{{ colors.source_color.default.rgba | set_alpha 0.5 }} +Output: rgba(r, g, b, 0.5) From 0609eaaca109d9207d087045b55ebc64d04a74b8 Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:13:08 +0300 Subject: [PATCH 05/59] update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 129b840..daa450e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- add `set_alpha` filter + + ## [2.3.0](https://github.com/InioX/matugen/compare/v2.2.0...v2.3.0) - 2024-05-29 ### Added From 5e20275a1f9a35e0f240e621b6360042249e9e27 Mon Sep 17 00:00:00 2001 From: zootedb0t <05kraken@proton.me> Date: Fri, 2 Aug 2024 14:18:22 +0530 Subject: [PATCH 06/59] feat: add mako live reload close #96 --- src/reload/unix.rs | 4 ++++ src/util/config.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/src/reload/unix.rs b/src/reload/unix.rs index 1502cd7..85543c0 100644 --- a/src/reload/unix.rs +++ b/src/reload/unix.rs @@ -30,6 +30,10 @@ pub fn reload(args: &Cli, config: &ConfigFile) -> Result<(), Report> { reload_gtk_theme(args)?; } + if reload_apps_list.mako == Some(true) || reload_apps_list.waybar.is_none() { + reload_app("mako", "SIGUSR2")?; + } + Ok(()) } diff --git a/src/util/config.rs b/src/util/config.rs index 8085c22..82d2a7a 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -67,6 +67,7 @@ pub struct Apps { pub waybar: Option, pub gtk_theme: Option, pub dunst: Option, + pub mako: Option, } #[derive(Serialize, Deserialize, Debug)] From f4a8d44c99397e1716befd43221991c9cdd13298 Mon Sep 17 00:00:00 2001 From: InioX Date: Sun, 4 Aug 2024 20:53:12 +0200 Subject: [PATCH 07/59] chore: bump `material-colors` to 0.4.0 --- Cargo.lock | 21 +++++++++++---------- Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f8fcf0..76ce943 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -998,12 +998,12 @@ dependencies = [ [[package]] name = "image" -version = "0.25.1" +version = "0.25.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11" +checksum = "99314c8a2152b8ddb211f924cdae532d8c5e4c8bb54728e12fff1b0cd5963a10" dependencies = [ "bytemuck", - "byteorder", + "byteorder-lite", "color_quant", "exr", "gif", @@ -1231,13 +1231,14 @@ dependencies = [ [[package]] name = "material-colors" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e07152b52508b3926ea2b79486f8b52f035ea790a7bbd29a95747236664805d" +checksum = "5353fb14a2b40a703a5e2dd855ca0ec7f488a79c9c965ee28d861bb7c05c06b7" dependencies = [ "ahash", - "image 0.25.1", + "image 0.25.2", "indexmap", + "serde", ] [[package]] @@ -1915,18 +1916,18 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 8a90e03..aeada78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,6 @@ clap = { version = "4.2.4", features = ["derive"] } serde = { version = "1.0.160", features = ["derive"] } serde_json = "1.0.107" toml = "0.8.8" -material-colors = { version = "0.3.2", features = ["image"] } +material-colors = { version = "0.4.0", features = ["image"] } regex = "1.10.5" execute = "0.2.13" From da313f6398b86c7c7116552a2d3df2bf88c6b885 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sun, 4 Aug 2024 15:23:39 +0300 Subject: [PATCH 08/59] Nix module: add package option This allows users to set a different package, for example pkgs.matugen. Co-authored-by: Amadej Kastelic --- module.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/module.nix b/module.nix index 212becb..d00d2df 100644 --- a/module.nix +++ b/module.nix @@ -39,7 +39,7 @@ matugen: { cd $out export HOME=$(pwd) - ${pkg}/bin/matugen \ + ${cfg.package}/bin/matugen \ image ${cfg.wallpaper} \ ${ if cfg.templates != {} @@ -57,6 +57,12 @@ in { options.programs.matugen = { enable = lib.mkEnableOption "Matugen declarative theming"; + package = + lib.mkPackageOption pkgs "matugen" {} + // { + default = pkg; + }; + wallpaper = lib.mkOption { description = "Path to `wallpaper` that matugen will generate the colorschemes from"; type = lib.types.path; From 14599ecf38624ee2c388068788dbd3795990b649 Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:06:07 +0300 Subject: [PATCH 09/59] add set_alpha filter --- src/util/filters.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/util/filters.rs b/src/util/filters.rs index b21d0b8..91b07c2 100644 --- a/src/util/filters.rs +++ b/src/util/filters.rs @@ -1,3 +1,4 @@ +use colorsys::ColorAlpha; use colorsys::ColorTransform; use colorsys::Hsl; use colorsys::Rgb; @@ -7,7 +8,8 @@ use upon::Value; use crate::util::template::{check_string_value, parse_color}; use crate::util::color::{ - format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba, + format_hex, format_hex_stripped, format_hsl, format_hsla, format_hsla_float, format_rgb, + format_rgba, format_rgba_float, }; pub fn set_lightness(value: &Value, amount: f64) -> Result { @@ -67,3 +69,37 @@ pub fn set_lightness(value: &Value, amount: f64) -> Result { v => Ok(v.to_string()), } } + +pub fn set_alpha(value: &Value, amount: f64) -> Result { + let string = check_string_value(value).unwrap(); + + let format = parse_color(string); + + debug!("Setting alpha on string {} by {}", string, amount); + + if format.is_none() { + return Ok(string.to_string()); + } + + if !(0.0..=1.0).contains(&amount) { + return Err("alpha must be in range [0.0 to 1.0]".to_string()); + } + + match format.unwrap() { + "hex" => Err("cannot set alpha on hex color".to_string()), + "hex_stripped" => Err("cannot set alpha on hex color".to_string()), + "rgb" => Err("cannot set alpha on rgb color, use rgba".to_string()), + "rgba" => { + let mut color = Rgb::from_str(string).unwrap(); + color.set_alpha(amount); + Ok(format_rgba_float(&color)) + } + "hsl" => Err("cannot set alpha on hsl color, use hsla".to_string()), + "hsla" => { + let mut color = Hsl::from_str(string).unwrap(); + color.set_alpha(amount); + Ok(format_hsla_float(&color)) + } + v => Ok(v.to_string()), + } +} From 5e1355c756c3707fd3fbd79e9819bf4cb8924138 Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:07:16 +0300 Subject: [PATCH 10/59] add format_rgba_float and format_hsla_float functions to format the alpha value as a float instead of u8 --- src/util/color.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/util/color.rs b/src/util/color.rs index a5b0a5d..fbef8bc 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -64,6 +64,16 @@ pub fn format_rgba(color: &Rgb) -> String { ) } +pub fn format_rgba_float(color: &Rgb) -> String { + format!( + "rgba({:?}, {:?}, {:?}, {:.1})", + color.red() as u8, + color.green() as u8, + color.blue() as u8, + color.alpha() + ) +} + pub fn format_hsl(color: &Hsl) -> String { format!( "hsl({:?}, {:?}%, {:?}%)", @@ -83,6 +93,16 @@ pub fn format_hsla(color: &Hsl) -> String { ) } +pub fn format_hsla_float(color: &Hsl) -> String { + format!( + "hsla({:?}, {:?}%, {:?}%, {:.1})", + color.hue() as u8, + color.saturation() as u8, + color.lightness() as u8, + color.alpha() + ) +} + pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { let c1 = Lab::from(Argb::from_str(c1).unwrap()); let c2 = Lab::from(Argb::from_str(c2).unwrap()); From b68b4aa0c5908bd91f6bcc7855a57df488bc1021 Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:08:52 +0300 Subject: [PATCH 11/59] add the set_alpha filter to the engine --- src/util/template.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/template.rs b/src/util/template.rs index cae13ba..5c77049 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -12,7 +12,7 @@ use upon::Value; use crate::util::color; use crate::util::color::color_to_string; -use crate::util::filters::set_lightness; +use crate::util::filters::{set_alpha, set_lightness}; use crate::util::variables::format_hook_text; use std::fs::canonicalize; @@ -302,6 +302,7 @@ fn export_template( fn add_engine_filters(engine: &mut Engine) { engine.add_filter("set_lightness", set_lightness); + engine.add_filter("set_alpha", set_alpha); engine.add_filter("to_upper", str::to_uppercase); engine.add_filter("to_lower", str::to_lowercase); engine.add_filter("replace", |s: String, from: String, to: String| { From 3d41b27dfad2192640033d31a9ccc1cb63eb3c09 Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:09:34 +0300 Subject: [PATCH 12/59] add set_alpha filter example --- example/colors.whatever-extension | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/example/colors.whatever-extension b/example/colors.whatever-extension index 8bcc5f7..63a4e3b 100644 --- a/example/colors.whatever-extension +++ b/example/colors.whatever-extension @@ -22,4 +22,8 @@ source_color {{colors.source_color.default.hex}}; <* for name, value in colors *> {{name | replace: "_", "-" }} {{value.default.hex}}; -<* endfor *> \ No newline at end of file +<* endfor *> + +Only works with rgba and hsla +{{ colors.source_color.default.rgba | set_alpha 0.5 }} +Output: rgba(r, g, b, 0.5) From 66db24dba90ec47f1e2b7f13cf823f772d287008 Mon Sep 17 00:00:00 2001 From: Fadi Asaad Date: Fri, 26 Jul 2024 15:13:08 +0300 Subject: [PATCH 13/59] update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 129b840..daa450e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- add `set_alpha` filter + + ## [2.3.0](https://github.com/InioX/matugen/compare/v2.2.0...v2.3.0) - 2024-05-29 ### Added From f22dd21cde844270abeb1987fa1e3cfcbee18c85 Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 13 Aug 2024 17:47:12 +0200 Subject: [PATCH 14/59] fix: set_alpha missing a `:` in example (#95) --- example/colors.whatever-extension | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/example/colors.whatever-extension b/example/colors.whatever-extension index 63a4e3b..6add080 100644 --- a/example/colors.whatever-extension +++ b/example/colors.whatever-extension @@ -25,5 +25,7 @@ source_color {{colors.source_color.default.hex}}; <* endfor *> Only works with rgba and hsla -{{ colors.source_color.default.rgba | set_alpha 0.5 }} + +{{ colors.source_color.default.rgba | set_alpha: 0.5 }} + Output: rgba(r, g, b, 0.5) From 26b2f92b4d4121dbb94f039b769f6e2961c6aff9 Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 13 Aug 2024 17:49:37 +0200 Subject: [PATCH 15/59] refactor: add float parameter for `format_hsla` and `format_rgba` (#95) --- src/util/color.rs | 52 ++++++++++++++++++++++++++++++-------------- src/util/filters.rs | 8 +++---- src/util/template.rs | 4 ++-- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/util/color.rs b/src/util/color.rs index fbef8bc..6620095 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -54,14 +54,24 @@ pub fn format_rgb(color: &Rgb) -> String { ) } -pub fn format_rgba(color: &Rgb) -> String { - format!( - "rgba({:?}, {:?}, {:?}, {:?})", - color.red() as u8, - color.green() as u8, - color.blue() as u8, - color.alpha() as u8 - ) +pub fn format_rgba(color: &Rgb, float: bool) -> String { + if float { + format!( + "rgba({:?}, {:?}, {:?}, {:?})", + color.red() as u8, + color.green() as u8, + color.blue() as u8, + color.alpha() + ) + } else { + format!( + "rgba({:?}, {:?}, {:?}, {:?})", + color.red() as u8, + color.green() as u8, + color.blue() as u8, + color.alpha() as u8 + ) + } } pub fn format_rgba_float(color: &Rgb) -> String { @@ -83,14 +93,24 @@ pub fn format_hsl(color: &Hsl) -> String { ) } -pub fn format_hsla(color: &Hsl) -> String { - format!( - "hsla({:?}, {:?}%, {:?}%, {:?})", - color.hue() as u8, - color.saturation() as u8, - color.lightness() as u8, - color.alpha() as u8 - ) +pub fn format_hsla(color: &Hsl, float: bool) -> String { + if float { + format!( + "hsla({:?}, {:?}%, {:?}%, {:?})", + color.hue() as u8, + color.saturation() as u8, + color.lightness() as u8, + color.alpha() + ) + } else { + format!( + "hsla({:?}, {:?}%, {:?}%, {:?})", + color.hue() as u8, + color.saturation() as u8, + color.lightness() as u8, + color.alpha() as u8 + ) + } } pub fn format_hsla_float(color: &Hsl) -> String { diff --git a/src/util/filters.rs b/src/util/filters.rs index 91b07c2..b54faca 100644 --- a/src/util/filters.rs +++ b/src/util/filters.rs @@ -50,7 +50,7 @@ pub fn set_lightness(value: &Value, amount: f64) -> Result { color.lighten(amount); - Ok(format_rgba(&color)) + Ok(format_rgba(&color, true)) } "hsl" => { let mut color = Hsl::from_str(string).unwrap(); @@ -64,7 +64,7 @@ pub fn set_lightness(value: &Value, amount: f64) -> Result { color.lighten(amount); - Ok(format_hsla(&color)) + Ok(format_hsla(&color, true)) } v => Ok(v.to_string()), } @@ -92,13 +92,13 @@ pub fn set_alpha(value: &Value, amount: f64) -> Result { "rgba" => { let mut color = Rgb::from_str(string).unwrap(); color.set_alpha(amount); - Ok(format_rgba_float(&color)) + Ok(format_rgba(&color, true)) } "hsl" => Err("cannot set alpha on hsl color, use hsla".to_string()), "hsla" => { let mut color = Hsl::from_str(string).unwrap(); color.set_alpha(amount); - Ok(format_hsla_float(&color)) + Ok(format_hsla(&color, true)) } v => Ok(v.to_string()), } diff --git a/src/util/template.rs b/src/util/template.rs index 5c77049..30354f0 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -403,9 +403,9 @@ fn generate_color_strings(color: Argb) -> Colora { hex: format_hex(&base_color), hex_stripped: format_hex_stripped(&base_color), rgb: format_rgb(&base_color), - rgba: format_rgba(&base_color), + rgba: format_rgba(&base_color, true), hsl: format_hsl(&hsl_color), - hsla: format_hsla(&hsl_color), + hsla: format_hsla(&hsl_color, true), red: format!("{:?}", base_color.red() as u8), green: format!("{:?}", base_color.green() as u8), blue: format!("{:?}", base_color.blue() as u8), From c5b38385202629e4aa5e304c59b24566aa4bcb80 Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 13 Aug 2024 18:06:17 +0200 Subject: [PATCH 16/59] fix: divide all alpha values by 255 for output (#95) --- src/util/color.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/color.rs b/src/util/color.rs index 6620095..01b7265 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -61,7 +61,7 @@ pub fn format_rgba(color: &Rgb, float: bool) -> String { color.red() as u8, color.green() as u8, color.blue() as u8, - color.alpha() + color.alpha() / 255. ) } else { format!( @@ -100,7 +100,7 @@ pub fn format_hsla(color: &Hsl, float: bool) -> String { color.hue() as u8, color.saturation() as u8, color.lightness() as u8, - color.alpha() + color.alpha() / 255. ) } else { format!( From a0bda952fa8d73612e6c0056e984da7239f83877 Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 13 Aug 2024 18:27:53 +0200 Subject: [PATCH 17/59] fix: wrong display of alpha channel for `set_alpha` (#95) --- src/util/color.rs | 20 ++++++++++---------- src/util/filters.rs | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/util/color.rs b/src/util/color.rs index 01b7265..391c4bd 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -54,10 +54,10 @@ pub fn format_rgb(color: &Rgb) -> String { ) } -pub fn format_rgba(color: &Rgb, float: bool) -> String { - if float { +pub fn format_rgba(color: &Rgb, divide: bool) -> String { + if divide { format!( - "rgba({:?}, {:?}, {:?}, {:?})", + "rgba({:?}, {:?}, {:?}, {:.1})", color.red() as u8, color.green() as u8, color.blue() as u8, @@ -65,11 +65,11 @@ pub fn format_rgba(color: &Rgb, float: bool) -> String { ) } else { format!( - "rgba({:?}, {:?}, {:?}, {:?})", + "rgba({:?}, {:?}, {:?}, {:.1})", color.red() as u8, color.green() as u8, color.blue() as u8, - color.alpha() as u8 + color.alpha() ) } } @@ -93,10 +93,10 @@ pub fn format_hsl(color: &Hsl) -> String { ) } -pub fn format_hsla(color: &Hsl, float: bool) -> String { - if float { +pub fn format_hsla(color: &Hsl, divide: bool) -> String { + if divide { format!( - "hsla({:?}, {:?}%, {:?}%, {:?})", + "hsla({:?}, {:?}%, {:?}%, {:.1})", color.hue() as u8, color.saturation() as u8, color.lightness() as u8, @@ -104,11 +104,11 @@ pub fn format_hsla(color: &Hsl, float: bool) -> String { ) } else { format!( - "hsla({:?}, {:?}%, {:?}%, {:?})", + "hsla({:?}, {:?}%, {:?}%, {:.1})", color.hue() as u8, color.saturation() as u8, color.lightness() as u8, - color.alpha() as u8 + color.alpha() ) } } diff --git a/src/util/filters.rs b/src/util/filters.rs index b54faca..670aadc 100644 --- a/src/util/filters.rs +++ b/src/util/filters.rs @@ -92,13 +92,13 @@ pub fn set_alpha(value: &Value, amount: f64) -> Result { "rgba" => { let mut color = Rgb::from_str(string).unwrap(); color.set_alpha(amount); - Ok(format_rgba(&color, true)) + Ok(format_rgba(&color, false)) } "hsl" => Err("cannot set alpha on hsl color, use hsla".to_string()), "hsla" => { let mut color = Hsl::from_str(string).unwrap(); color.set_alpha(amount); - Ok(format_hsla(&color, true)) + Ok(format_hsla(&color, false)) } v => Ok(v.to_string()), } From af18a3cd70ce3bb5af2167a4120534aa477ffa89 Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 13 Aug 2024 18:37:17 +0200 Subject: [PATCH 18/59] oops bad merge (#95) --- src/util/color.rs | 20 -------------------- src/util/filters.rs | 36 +----------------------------------- 2 files changed, 1 insertion(+), 55 deletions(-) diff --git a/src/util/color.rs b/src/util/color.rs index 8612b7c..391c4bd 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -84,16 +84,6 @@ pub fn format_rgba_float(color: &Rgb) -> String { ) } -pub fn format_rgba_float(color: &Rgb) -> String { - format!( - "rgba({:?}, {:?}, {:?}, {:.1})", - color.red() as u8, - color.green() as u8, - color.blue() as u8, - color.alpha() - ) -} - pub fn format_hsl(color: &Hsl) -> String { format!( "hsl({:?}, {:?}%, {:?}%)", @@ -133,16 +123,6 @@ pub fn format_hsla_float(color: &Hsl) -> String { ) } -pub fn format_hsla_float(color: &Hsl) -> String { - format!( - "hsla({:?}, {:?}%, {:?}%, {:.1})", - color.hue() as u8, - color.saturation() as u8, - color.lightness() as u8, - color.alpha() - ) -} - pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { let c1 = Lab::from(Argb::from_str(c1).unwrap()); let c2 = Lab::from(Argb::from_str(c2).unwrap()); diff --git a/src/util/filters.rs b/src/util/filters.rs index 5958d68..2636ba2 100644 --- a/src/util/filters.rs +++ b/src/util/filters.rs @@ -102,38 +102,4 @@ pub fn set_alpha(value: &Value, amount: f64) -> Result { } v => Ok(v.to_string()), } -} - -pub fn set_alpha(value: &Value, amount: f64) -> Result { - let string = check_string_value(value).unwrap(); - - let format = parse_color(string); - - debug!("Setting alpha on string {} by {}", string, amount); - - if format.is_none() { - return Ok(string.to_string()); - } - - if !(0.0..=1.0).contains(&amount) { - return Err("alpha must be in range [0.0 to 1.0]".to_string()); - } - - match format.unwrap() { - "hex" => Err("cannot set alpha on hex color".to_string()), - "hex_stripped" => Err("cannot set alpha on hex color".to_string()), - "rgb" => Err("cannot set alpha on rgb color, use rgba".to_string()), - "rgba" => { - let mut color = Rgb::from_str(string).unwrap(); - color.set_alpha(amount); - Ok(format_rgba_float(&color)) - } - "hsl" => Err("cannot set alpha on hsl color, use hsla".to_string()), - "hsla" => { - let mut color = Hsl::from_str(string).unwrap(); - color.set_alpha(amount); - Ok(format_hsla_float(&color)) - } - v => Ok(v.to_string()), - } -} +} \ No newline at end of file From 5429ebdcbc81552c81106e1a3d114712e095bbc3 Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 13 Aug 2024 18:42:33 +0200 Subject: [PATCH 19/59] feat: add `pre_hook` and `post_hook` (#100) --- example/config.toml | 3 ++- src/util/template.rs | 14 ++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/example/config.toml b/example/config.toml index a3d791a..b500d2b 100644 --- a/example/config.toml +++ b/example/config.toml @@ -30,7 +30,8 @@ colors_to_compare = [ { name = "purple", color = "#800080" }, ] compare_to = "{{colors.primary.default.hex}}" -hook = 'echo "source color {{colors.source_color.default.hex}}, source image {{image}}, closest color {{closest_color}}"' +pre_hook = 'echo "source color {{colors.source_color.default.hex}}, source image {{image}}, closest color {{closest_color}}"' +post_hook = 'echo "after gen"' # Only hex values [config.custom_colors] diff --git a/src/util/template.rs b/src/util/template.rs index 30354f0..e77e8e8 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -54,7 +54,8 @@ pub struct Template { pub mode: Option, pub colors_to_compare: Option>, pub compare_to: Option, - pub hook: Option, + pub pre_hook: Option, + pub post_hook: Option, } #[derive(Serialize, Deserialize, Debug)] @@ -186,8 +187,8 @@ impl Template { (template.input_path.try_resolve()?.to_path_buf(), template.output_path.try_resolve()?.to_path_buf()) }; - if template.hook.is_some() { - format_hook(template, &engine, &mut render_data)?; + if template.pre_hook.is_some() { + format_hook(template, &engine, &mut render_data, template.pre_hook.as_ref().unwrap())?; } if !input_path_absolute.exists() { @@ -241,6 +242,10 @@ impl Template { i, templates, )?; + + if template.post_hook.is_some() { + format_hook(template, &engine, &mut render_data, template.post_hook.as_ref().unwrap())?; + } } Ok(()) } @@ -314,6 +319,7 @@ fn format_hook( template: &Template, engine: &Engine, render_data: &mut Value, + hook: &String ) -> Result<(), Report> { let closest_color: Option = if template.colors_to_compare.is_some() && template.compare_to.is_some() { @@ -327,7 +333,7 @@ fn format_hook( None }; - let t = engine.compile(template.hook.as_ref().unwrap())?; + let t = engine.compile(hook)?; let res = if template.colors_to_compare.is_some() && template.compare_to.is_some() { format_hook_text(render_data, closest_color, t) } else { From 9782a3d09fe7a7f7163b42c134e5c278b3818514 Mon Sep 17 00:00:00 2001 From: InioX Date: Wed, 14 Aug 2024 22:46:03 +0200 Subject: [PATCH 20/59] chore: run cargo fmt + clippy fix --- src/main.rs | 9 ++++--- src/util/color.rs | 16 ++++++------- src/util/config.rs | 5 +++- src/util/filters.rs | 18 +++----------- src/util/mod.rs | 2 +- src/util/template.rs | 56 ++++++++++++++++++++++++++++++------------- src/util/variables.rs | 22 +++++++++-------- 7 files changed, 72 insertions(+), 56 deletions(-) diff --git a/src/main.rs b/src/main.rs index fbc600f..9397ed1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,9 +87,8 @@ fn main() -> Result<(), Report> { .iter() .map(|(name, color)| { make_custom_color( - color - .to_custom_color(name.to_string()) - .expect(&format!("Failed to parse custom color: {}, {:?}", name, color)), + color.to_custom_color(name.to_string()).unwrap_or_else(|_| panic!("Failed to parse custom color: {}, {:?}", + name, color)), &args.r#type, source_color, args.contrast, @@ -142,7 +141,7 @@ fn main() -> Result<(), Report> { &default_scheme, &config.config.custom_keywords, &args.prefix, - config_path + config_path, )?; if config.config.reload_apps == Some(true) { @@ -171,7 +170,7 @@ fn main() -> Result<(), Report> { }; #[cfg(target_os = "windows")] - wallpaper::windows::set(&path)?; + wallpaper::windows::set(path)?; #[cfg(target_os = "macos")] wallpaper::macos::set(&path)?; diff --git a/src/util/color.rs b/src/util/color.rs index 391c4bd..2704c5c 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -131,7 +131,7 @@ pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { let a: f64 = c1.a - c2.a; let b: f64 = c1.b - c2.b; - return f64::sqrt((l * l) + (a * a) + (b * b)); + f64::sqrt((l * l) + (a * a) + (b * b)) } // for rgb - useless but ill keep it here @@ -153,7 +153,7 @@ pub fn color_to_string(colors_to_compare: &Vec, compare_to: &St let mut closest_color: &str = ""; for c in colors_to_compare { - let distance = get_color_distance_lab(&c.color, &compare_to); + let distance = get_color_distance_lab(&c.color, compare_to); if closest_distance.is_none() || closest_distance.unwrap() > distance { closest_distance = Some(distance); closest_color = &c.name; @@ -164,7 +164,7 @@ pub fn color_to_string(colors_to_compare: &Vec, compare_to: &St "closest distance: {:?}, closest color: {}", closest_distance, closest_color ); - return closest_color.to_string(); + closest_color.to_string() } pub fn generate_dynamic_scheme( @@ -218,7 +218,10 @@ pub fn make_custom_color( let light = generate_dynamic_scheme(scheme_type, value, false, contrast_level); let dark = generate_dynamic_scheme(scheme_type, value, true, contrast_level); - let custom_color = CustomColorGroup { + + + // debug!("custom_color: {:#?}", &custom_color); + CustomColorGroup { color, value, light: ColorGroup { @@ -233,10 +236,7 @@ pub fn make_custom_color( color_container: MaterialDynamicColors::primary_container().get_argb(&dark), on_color_container: MaterialDynamicColors::on_primary_container().get_argb(&dark), }, - }; - - // debug!("custom_color: {:#?}", &custom_color); - custom_color + } } pub fn show_color(schemes: &Schemes, source_color: &Argb) { diff --git a/src/util/config.rs b/src/util/config.rs index 82d2a7a..8469064 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -87,7 +87,10 @@ const DEFAULT_CONFIG: &str = r#" impl ConfigFile { pub fn read(args: &Cli) -> Result<(ConfigFile, Option), Report> { match &args.config { - Some(config_file) => Ok((Self::read_from_custom_path(config_file)?, Some(config_file.to_path_buf()))), + Some(config_file) => Ok(( + Self::read_from_custom_path(config_file)?, + Some(config_file.to_path_buf()), + )), None => Ok(Self::read_from_proj_path()?), } } diff --git a/src/util/filters.rs b/src/util/filters.rs index 2636ba2..bb19cf1 100644 --- a/src/util/filters.rs +++ b/src/util/filters.rs @@ -8,8 +8,8 @@ use upon::Value; use crate::util::template::{check_string_value, parse_color}; use crate::util::color::{ - format_hex, format_hex_stripped, format_hsl, format_hsla, format_hsla_float, format_rgb, - format_rgba, format_rgba_float, + format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, + format_rgba, }; pub fn set_lightness(value: &Value, amount: f64) -> Result { @@ -26,44 +26,32 @@ pub fn set_lightness(value: &Value, amount: f64) -> Result { match format.unwrap() { "hex" => { let mut color = Rgb::from_hex_str(string).unwrap(); - color.lighten(amount); - Ok(format_hex(&color)) } "hex_stripped" => { let mut color = Rgb::from_hex_str(string).unwrap(); - color.lighten(amount); - Ok(format_hex_stripped(&color)) } "rgb" => { let mut color = Rgb::from_str(string).unwrap(); - color.lighten(amount); - Ok(format_rgb(&color)) } "rgba" => { let mut color = Rgb::from_str(string).unwrap(); - color.lighten(amount); - Ok(format_rgba(&color, true)) } "hsl" => { let mut color = Hsl::from_str(string).unwrap(); - color.lighten(amount); - Ok(format_hsl(&color)) } "hsla" => { let mut color = Hsl::from_str(string).unwrap(); - color.lighten(amount); - Ok(format_hsla(&color, true)) } v => Ok(v.to_string()), @@ -102,4 +90,4 @@ pub fn set_alpha(value: &Value, amount: f64) -> Result { } v => Ok(v.to_string()), } -} \ No newline at end of file +} diff --git a/src/util/mod.rs b/src/util/mod.rs index 08948e8..a74c76f 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -3,4 +3,4 @@ pub mod color; pub mod config; pub mod filters; pub mod template; -pub mod variables; \ No newline at end of file +pub mod variables; diff --git a/src/util/template.rs b/src/util/template.rs index e77e8e8..d88fdc6 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -10,16 +10,14 @@ use serde::{Deserialize, Serialize}; use upon::Value; -use crate::util::color; use crate::util::color::color_to_string; use crate::util::filters::{set_alpha, set_lightness}; use crate::util::variables::format_hook_text; -use std::fs::canonicalize; use std::path::Path; use std::str; -use std::process::{Command, Stdio}; +use std::process::{Stdio}; use execute::{shell, Execute}; @@ -84,7 +82,10 @@ struct ColorVariants { use super::color::rgb_from_argb; -pub trait StripCanonicalization where Self: AsRef { +pub trait StripCanonicalization +where + Self: AsRef, +{ #[cfg(not(target_os = "windows"))] fn strip_canonicalization(&self) -> PathBuf { self.as_ref().to_path_buf() @@ -137,7 +138,7 @@ impl Template { default_scheme: &SchemesEnum, custom_keywords: &Option>, path_prefix: &Option, - config_path: Option + config_path: Option, ) -> Result<(), Report> { let default_prefix = "@".to_string(); @@ -181,14 +182,33 @@ impl Template { let output_path_absolute = template.output_path.try_resolve()?; let (input_path_absolute, output_path_absolute) = if config_path.is_some() { - let base = std::fs::canonicalize(&config_path.as_ref().unwrap())?; - (template.input_path.try_resolve_in(&base)?.to_path_buf().strip_canonicalization(), template.output_path.try_resolve_in(&base)?.to_path_buf().strip_canonicalization()) + let base = std::fs::canonicalize(config_path.as_ref().unwrap())?; + ( + template + .input_path + .try_resolve_in(&base)? + .to_path_buf() + .strip_canonicalization(), + template + .output_path + .try_resolve_in(&base)? + .to_path_buf() + .strip_canonicalization(), + ) } else { - (template.input_path.try_resolve()?.to_path_buf(), template.output_path.try_resolve()?.to_path_buf()) + ( + template.input_path.try_resolve()?.to_path_buf(), + template.output_path.try_resolve()?.to_path_buf(), + ) }; if template.pre_hook.is_some() { - format_hook(template, &engine, &mut render_data, template.pre_hook.as_ref().unwrap())?; + format_hook( + template, + &engine, + &mut render_data, + template.pre_hook.as_ref().unwrap(), + )?; } if !input_path_absolute.exists() { @@ -244,7 +264,12 @@ impl Template { )?; if template.post_hook.is_some() { - format_hook(template, &engine, &mut render_data, template.post_hook.as_ref().unwrap())?; + format_hook( + template, + &engine, + &mut render_data, + template.post_hook.as_ref().unwrap(), + )?; } } Ok(()) @@ -277,8 +302,7 @@ fn export_template( })?; let out = if path_prefix.is_some() && !cfg!(windows) { let prefix_path = PathBuf::from(path_prefix.as_ref().unwrap()); - rebase(&output_path_absolute, &prefix_path, None) - .expect("failed to rebase output path") + rebase(&output_path_absolute, &prefix_path, None).expect("failed to rebase output path") } else { output_path_absolute.to_path_buf() }; @@ -319,14 +343,14 @@ fn format_hook( template: &Template, engine: &Engine, render_data: &mut Value, - hook: &String + hook: &String, ) -> Result<(), Report> { let closest_color: Option = if template.colors_to_compare.is_some() && template.compare_to.is_some() { let s = engine.compile(template.compare_to.as_ref().unwrap())?; - let compare_to = s.render(&engine, &render_data).to_string()?; + let compare_to = s.render(engine, &render_data).to_string()?; Some(color_to_string( - &template.colors_to_compare.as_ref().unwrap(), + template.colors_to_compare.as_ref().unwrap(), &compare_to, )) } else { @@ -353,7 +377,7 @@ fn format_hook( } else { eprintln!("Interrupted!"); } - + Ok(()) } diff --git a/src/util/variables.rs b/src/util/variables.rs index 3efe64f..eabc962 100644 --- a/src/util/variables.rs +++ b/src/util/variables.rs @@ -73,22 +73,24 @@ use upon::{Engine, Syntax, Template, Value}; // return result.to_string(); // } -pub fn format_hook_text(render_data: &mut Value, closest_color: Option, template: Template<'_>) -> String { +pub fn format_hook_text( + render_data: &mut Value, + closest_color: Option, + template: Template<'_>, +) -> String { let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build(); - let mut engine = Engine::with_syntax(syntax); - + let engine = Engine::with_syntax(syntax); + match render_data { Value::Map(ref mut map) => { - map.insert("closest_color".to_string(), Value::from(closest_color)); - }, + map.insert("closest_color".to_string(), Value::from(closest_color)); + } _ => { debug!("not map") } } - let data = template - .render(&engine,&render_data) - .to_string().unwrap(); + let data = template.render(&engine, &render_data).to_string().unwrap(); - return data -} \ No newline at end of file + data +} From 00740d4992c61e4b918361393ab90c442acb1349 Mon Sep 17 00:00:00 2001 From: InioX Date: Wed, 14 Aug 2024 22:52:56 +0200 Subject: [PATCH 21/59] refactor: remove useless stuff, add clippy rules --- src/main.rs | 2 ++ src/util/arguments.rs | 1 + src/util/color.rs | 22 +--------------------- src/util/template.rs | 6 ++---- 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9397ed1..3e7a919 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::too_many_arguments)] + extern crate pretty_env_logger; #[macro_use] extern crate paris_log; diff --git a/src/util/arguments.rs b/src/util/arguments.rs index 0034af8..62abbea 100644 --- a/src/util/arguments.rs +++ b/src/util/arguments.rs @@ -1,6 +1,7 @@ use clap::{arg, ArgAction, Parser, Subcommand}; use std::path::PathBuf; +#[allow(clippy::enum_variant_names)] #[derive(Clone, clap::ValueEnum, Debug, Copy)] pub enum SchemeTypes { SchemeContent, diff --git a/src/util/color.rs b/src/util/color.rs index 2704c5c..b7c3ea6 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -74,16 +74,6 @@ pub fn format_rgba(color: &Rgb, divide: bool) -> String { } } -pub fn format_rgba_float(color: &Rgb) -> String { - format!( - "rgba({:?}, {:?}, {:?}, {:.1})", - color.red() as u8, - color.green() as u8, - color.blue() as u8, - color.alpha() - ) -} - pub fn format_hsl(color: &Hsl) -> String { format!( "hsl({:?}, {:?}%, {:?}%)", @@ -113,16 +103,6 @@ pub fn format_hsla(color: &Hsl, divide: bool) -> String { } } -pub fn format_hsla_float(color: &Hsl) -> String { - format!( - "hsla({:?}, {:?}%, {:?}%, {:.1})", - color.hue() as u8, - color.saturation() as u8, - color.lightness() as u8, - color.alpha() - ) -} - pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { let c1 = Lab::from(Argb::from_str(c1).unwrap()); let c2 = Lab::from(Argb::from_str(c2).unwrap()); @@ -148,7 +128,7 @@ pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { // return f64::sqrt(weightR * i64::pow(r1-r2, 2) as f64 + weightG * i64::pow(g1-g2, 2) as f64 + weightB * i64::pow(b1-b2, 2) as f64) // } -pub fn color_to_string(colors_to_compare: &Vec, compare_to: &String) -> String { +pub fn color_to_string(colors_to_compare: &Vec, compare_to: &str) -> String { let mut closest_distance: Option = None; let mut closest_color: &str = ""; diff --git a/src/util/template.rs b/src/util/template.rs index d88fdc6..ba67f18 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -82,6 +82,7 @@ struct ColorVariants { use super::color::rgb_from_argb; +#[allow(clippy::manual_strip)] pub trait StripCanonicalization where Self: AsRef, @@ -112,7 +113,7 @@ pub fn check_string_value(value: &Value) -> Option<&String> { } } -pub fn parse_color(string: &String) -> Option<&str> { +pub fn parse_color(string: &str) -> Option<&str> { if let Some(_s) = string.strip_prefix('#') { return Some("hex"); } @@ -178,9 +179,6 @@ impl Template { // debug!("render_data: {:#?}", &render_data); for (i, (name, template)) in templates.iter().enumerate() { - let input_path_absolute = template.input_path.try_resolve()?; - let output_path_absolute = template.output_path.try_resolve()?; - let (input_path_absolute, output_path_absolute) = if config_path.is_some() { let base = std::fs::canonicalize(config_path.as_ref().unwrap())?; ( From 957785e5396c23734da5c4770e9180662f3ebc85 Mon Sep 17 00:00:00 2001 From: InioX Date: Wed, 14 Aug 2024 23:42:59 +0200 Subject: [PATCH 22/59] feat: add more info to debug mode --- src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3e7a919..2693fa1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -207,11 +207,16 @@ fn check_version() { } fn setup_logging(log_level: LevelFilter) -> Result<(), Report> { - pretty_env_logger::env_logger::builder() - .format_module_path(false) - .format_timestamp(None) - .filter_level(log_level) - .format(|buf, record| writeln!(buf, "{}", record.args())) - .try_init()?; + let mut logger = pretty_env_logger::env_logger::builder(); + + logger.format_timestamp(None).filter_level(log_level); + + if log_level != LevelFilter::Debug { + logger.format_module_path(false); + logger.format(|buf, record| writeln!(buf, "{}", record.args())); + } + + logger.try_init()?; + Ok(()) } From b3b30232628708970bbc4485634e4c43d8f6ae94 Mon Sep 17 00:00:00 2001 From: InioX Date: Wed, 14 Aug 2024 23:55:33 +0200 Subject: [PATCH 23/59] feat: add timestamp to debug logs --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 2693fa1..ae74002 100644 --- a/src/main.rs +++ b/src/main.rs @@ -209,9 +209,10 @@ fn check_version() { fn setup_logging(log_level: LevelFilter) -> Result<(), Report> { let mut logger = pretty_env_logger::env_logger::builder(); - logger.format_timestamp(None).filter_level(log_level); + logger.filter_level(log_level); if log_level != LevelFilter::Debug { + logger.format_timestamp(None); logger.format_module_path(false); logger.format(|buf, record| writeln!(buf, "{}", record.args())); } From 21261475aec279f4091fed24ba882ff4c7c0172b Mon Sep 17 00:00:00 2001 From: InioX Date: Fri, 16 Aug 2024 18:49:47 +0200 Subject: [PATCH 24/59] refactor: move some stuff into lib instead --- src/color/color.rs | 210 ++++++++++++++ src/color/format.rs | 77 ++++++ src/color/math.rs | 29 ++ src/color/mod.rs | 4 + src/color/parse.rs | 24 ++ src/exec/command.rs | 0 src/exec/hook.rs | 72 +++++ src/exec/mod.rs | 2 + src/filters/alpha.rs | 43 +++ src/{util/filters.rs => filters/lightness.rs} | 50 +--- src/filters/mod.rs | 2 + src/helpers.rs | 89 ++++++ src/lib.rs | 10 + src/main.rs | 175 ++---------- src/scheme/mod.rs | 1 + src/scheme/scheme.rs | 94 +++++++ src/util/arguments.rs | 30 +- src/util/color.rs | 258 +----------------- src/util/config.rs | 32 +-- src/util/mod.rs | 2 - src/util/template.rs | 194 +++++-------- src/util/variables.rs | 96 ------- 22 files changed, 748 insertions(+), 746 deletions(-) create mode 100644 src/color/color.rs create mode 100644 src/color/format.rs create mode 100644 src/color/math.rs create mode 100644 src/color/mod.rs create mode 100644 src/color/parse.rs create mode 100644 src/exec/command.rs create mode 100644 src/exec/hook.rs create mode 100644 src/exec/mod.rs create mode 100644 src/filters/alpha.rs rename src/{util/filters.rs => filters/lightness.rs} (50%) create mode 100644 src/filters/mod.rs create mode 100644 src/helpers.rs create mode 100644 src/lib.rs create mode 100644 src/scheme/mod.rs create mode 100644 src/scheme/scheme.rs delete mode 100644 src/util/variables.rs diff --git a/src/color/color.rs b/src/color/color.rs new file mode 100644 index 0000000..4988085 --- /dev/null +++ b/src/color/color.rs @@ -0,0 +1,210 @@ +use material_colors::{ + blend::harmonize, color::Argb, dynamic_color::{DynamicScheme, MaterialDynamicColors}, hct::Hct, image::{FilterType, ImageReader}, scheme::variant::{ + SchemeContent, SchemeExpressive, SchemeFidelity, SchemeFruitSalad, SchemeMonochrome, + SchemeNeutral, SchemeRainbow, SchemeTonalSpot, + }, theme::{ColorGroup, CustomColor, CustomColorGroup} +}; + +use colorsys::{Hsl, Rgb}; +use std::str::FromStr; + +use crate::{color::math::get_color_distance_lab, scheme::scheme::SchemeTypes}; + +#[derive(clap::Parser, Debug)] +pub enum ColorFormat { + Hex { string: String }, + Rgb { string: String }, + Hsl { string: String }, +} + +#[derive(clap::Subcommand, Debug)] +pub enum Source { + /// The image to use for generating a color scheme + Image { path: String }, + /// The image to fetch from web and use for generating a color scheme + WebImage { url: String }, + /// The source color to use for generating a color scheme + #[clap(subcommand)] + Color(crate::color::color::ColorFormat), +} + +#[derive(serde::Serialize, serde::Deserialize, Debug)] +pub struct ColorDefinition { + pub name: String, + pub color: String, +} + +#[derive(serde::Serialize, serde::Deserialize, Debug)] +#[serde(untagged)] +pub enum OwnCustomColor { + Color(String), + Options { color: String, blend: bool }, +} + +impl OwnCustomColor { + pub fn to_custom_color( + &self, + name: String, + ) -> Result { + Ok(match self { + OwnCustomColor::Color(color) => material_colors::theme::CustomColor { + value: Argb::from_str(color)?, + blend: true, + name, + }, + OwnCustomColor::Options { color, blend } => material_colors::theme::CustomColor { + value: Argb::from_str(color)?, + blend: *blend, + name, + }, + }) + } +} + +pub fn get_source_color(source: &Source) -> Result> { + let source_color: Argb = match &source { + Source::Image { path } => { + // test + info!("Opening image in {}", path); + crate::color::color::get_source_color_from_image(path).expect("Could not get source color from image") + } + Source::WebImage { url } => { + info!("Fetching image from {}", url); + crate::color::color::get_source_color_from_web_image(url).expect("Could not get source color from web image") + } + Source::Color(color) => { + crate::color::color::get_source_color_from_color(color).expect("Could not get source color from color") + } + }; + Ok(source_color) +} + +pub fn get_source_color_from_image(path: &str) -> Result> { + Ok(ImageReader::extract_color(ImageReader::open(path)?.resize( + 128, + 128, + FilterType::Lanczos3, + ))) +} + +pub fn get_source_color_from_web_image(url: &str) -> Result> { + let bytes = reqwest::blocking::get(url)?.bytes()?; + Ok(ImageReader::extract_color(ImageReader::read(&bytes)?.resize( + 128, + 128, + FilterType::Lanczos3, + ))) +} + +pub fn get_source_color_from_color(color: &ColorFormat) -> Result> { + match color { + ColorFormat::Hex { string } => { + Ok(Argb::from_str(string).expect("Invalid hex color string provided")) + } + ColorFormat::Rgb { string } => { + Ok(string.parse().expect("Invalid rgb color string provided")) + } + ColorFormat::Hsl { string } => { + let rgb: Rgb = Hsl::from_str(string) + .expect("Invalid hsl color string provided") + .into(); + Ok(Argb { + red: rgb.red() as u8, + green: rgb.green() as u8, + blue: rgb.blue() as u8, + alpha: 255, + }) + } + } +} + +pub fn generate_dynamic_scheme( + scheme_type: &Option, + source_color: Argb, + is_dark: bool, + contrast_level: Option, +) -> DynamicScheme { + match scheme_type.unwrap() { + SchemeTypes::SchemeContent => { + SchemeContent::new(Hct::new(source_color), is_dark, contrast_level).scheme + } + SchemeTypes::SchemeExpressive => { + SchemeExpressive::new(Hct::new(source_color), is_dark, contrast_level).scheme + } + SchemeTypes::SchemeFidelity => { + SchemeFidelity::new(Hct::new(source_color), is_dark, contrast_level).scheme + } + SchemeTypes::SchemeFruitSalad => { + SchemeFruitSalad::new(Hct::new(source_color), is_dark, contrast_level).scheme + } + SchemeTypes::SchemeMonochrome => { + SchemeMonochrome::new(Hct::new(source_color), is_dark, contrast_level).scheme + } + SchemeTypes::SchemeNeutral => { + SchemeNeutral::new(Hct::new(source_color), is_dark, contrast_level).scheme + } + SchemeTypes::SchemeRainbow => { + SchemeRainbow::new(Hct::new(source_color), is_dark, contrast_level).scheme + } + SchemeTypes::SchemeTonalSpot => { + SchemeTonalSpot::new(Hct::new(source_color), is_dark, contrast_level).scheme + } + } +} + +pub fn make_custom_color( + color: CustomColor, + scheme_type: &Option, + source_color: Argb, + contrast_level: Option, +) -> CustomColorGroup { + // debug!("make_custom_color: {:#?}", &color); + + let value = if color.blend { + harmonize(color.value, source_color) + } else { + color.value + }; + + let light = generate_dynamic_scheme(scheme_type, value, false, contrast_level); + let dark = generate_dynamic_scheme(scheme_type, value, true, contrast_level); + + + + // debug!("custom_color: {:#?}", &custom_color); + CustomColorGroup { + color, + value, + light: ColorGroup { + color: MaterialDynamicColors::primary().get_argb(&light), + on_color: MaterialDynamicColors::on_primary().get_argb(&light), + color_container: MaterialDynamicColors::primary_container().get_argb(&light), + on_color_container: MaterialDynamicColors::on_primary_container().get_argb(&light), + }, + dark: ColorGroup { + color: MaterialDynamicColors::primary().get_argb(&dark), + on_color: MaterialDynamicColors::on_primary().get_argb(&dark), + color_container: MaterialDynamicColors::primary_container().get_argb(&dark), + on_color_container: MaterialDynamicColors::on_primary_container().get_argb(&dark), + }, + } +} + +pub fn color_to_string(colors_to_compare: &Vec, compare_to: &str) -> String { + let mut closest_distance: Option = None; + let mut closest_color: &str = ""; + + for c in colors_to_compare { + let distance = get_color_distance_lab(&c.color, compare_to); + if closest_distance.is_none() || closest_distance.unwrap() > distance { + closest_distance = Some(distance); + closest_color = &c.name; + } + debug!("distance: {}, name: {}", distance, c.name) + } + debug!( + "closest distance: {:?}, closest color: {}", + closest_distance, closest_color + ); + closest_color.to_string() +} \ No newline at end of file diff --git a/src/color/format.rs b/src/color/format.rs new file mode 100644 index 0000000..5aefb2a --- /dev/null +++ b/src/color/format.rs @@ -0,0 +1,77 @@ +use material_colors::color::Argb; +use colorsys::{ColorAlpha, Hsl, Rgb}; + +pub fn rgb_from_argb(color: Argb) -> Rgb { + Rgb::from([ + color.red as f64, + color.green as f64, + color.blue as f64, + color.alpha as f64, + ]) +} + +pub fn format_hex(color: &Rgb) -> String { + color.to_hex_string() +} + +pub fn format_hex_stripped(color: &Rgb) -> String { + color.to_hex_string()[1..].to_string() +} + +pub fn format_rgb(color: &Rgb) -> String { + format!( + "rgb({:?}, {:?}, {:?})", + color.red() as u8, + color.green() as u8, + color.blue() as u8, + ) +} + +pub fn format_rgba(color: &Rgb, divide: bool) -> String { + if divide { + format!( + "rgba({:?}, {:?}, {:?}, {:.1})", + color.red() as u8, + color.green() as u8, + color.blue() as u8, + color.alpha() / 255. + ) + } else { + format!( + "rgba({:?}, {:?}, {:?}, {:.1})", + color.red() as u8, + color.green() as u8, + color.blue() as u8, + color.alpha() + ) + } +} + +pub fn format_hsl(color: &Hsl) -> String { + format!( + "hsl({:?}, {:?}%, {:?}%)", + color.hue() as u8, + color.saturation() as u8, + color.lightness() as u8, + ) +} + +pub fn format_hsla(color: &Hsl, divide: bool) -> String { + if divide { + format!( + "hsla({:?}, {:?}%, {:?}%, {:.1})", + color.hue() as u8, + color.saturation() as u8, + color.lightness() as u8, + color.alpha() / 255. + ) + } else { + format!( + "hsla({:?}, {:?}%, {:?}%, {:.1})", + color.hue() as u8, + color.saturation() as u8, + color.lightness() as u8, + color.alpha() + ) + } +} \ No newline at end of file diff --git a/src/color/math.rs b/src/color/math.rs new file mode 100644 index 0000000..910908b --- /dev/null +++ b/src/color/math.rs @@ -0,0 +1,29 @@ +use material_colors::color::{Argb, Lab}; +use std::str::FromStr; +use colorsys::Rgb; + +pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { + let c1 = Lab::from(Argb::from_str(c1).unwrap()); + let c2 = Lab::from(Argb::from_str(c2).unwrap()); + + let l: f64 = c1.l - c2.l; + let a: f64 = c1.a - c2.a; + let b: f64 = c1.b - c2.b; + + f64::sqrt((l * l) + (a * a) + (b * b)) +} + +// for rgb - useless but ill keep it here + +#[allow(dead_code)] +pub fn get_color_distance(c1: &Rgb, c2: &Rgb) -> f64 { + let (r1, g1, b1) = (c1.red() as i64, c1.blue() as i64, c1.green() as i64); + let (r2, g2, b2) = (c2.red() as i64, c2.green() as i64, c2.blue() as i64); + + let rmean: f64 = ((r1 + r2) / 2) as f64; + let weight_r: f64 = 2.0 + rmean / 256.0; + let weight_g: f64 = 4.0; + let weight_b: f64 = 2.0 + (255.0 - rmean) / 256.0; + + return f64::sqrt(weight_r * i64::pow(r1-r2, 2) as f64 + weight_g * i64::pow(g1-g2, 2) as f64 + weight_b * i64::pow(b1-b2, 2) as f64) +} \ No newline at end of file diff --git a/src/color/mod.rs b/src/color/mod.rs new file mode 100644 index 0000000..47c6b4c --- /dev/null +++ b/src/color/mod.rs @@ -0,0 +1,4 @@ +pub mod format; +pub mod math; +pub mod color; +pub mod parse; \ No newline at end of file diff --git a/src/color/parse.rs b/src/color/parse.rs new file mode 100644 index 0000000..ec61641 --- /dev/null +++ b/src/color/parse.rs @@ -0,0 +1,24 @@ +use upon::Value; + +pub fn parse_color(string: &str) -> Option<&str> { + if let Some(_s) = string.strip_prefix('#') { + return Some("hex"); + } + + if let (Some(i), Some(s)) = (string.find('('), string.strip_suffix(')')) { + let fname = s[..i].trim_end(); + Some(fname) + } else if string.len() == 6 { + // Does not matter if it is actually a stripped hex or not, we handle it somewhere else. + return Some("hex_stripped"); + } else { + None + } +} + +pub fn check_string_value(value: &Value) -> Option<&String> { + match value { + Value::String(v) => Some(v), + _v => None, + } +} \ No newline at end of file diff --git a/src/exec/command.rs b/src/exec/command.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/exec/hook.rs b/src/exec/hook.rs new file mode 100644 index 0000000..a045764 --- /dev/null +++ b/src/exec/hook.rs @@ -0,0 +1,72 @@ +use std::process::Stdio; + +use execute::{shell, Execute}; +use upon::{Engine, Syntax, Template, Value}; + +use crate::color::color::color_to_string; + + +pub fn format_hook( + engine: &Engine, + render_data: &mut Value, + hook: &String, + colors_to_compare: &Option>, + compare_to: &Option, +) -> Result<(), Box> { + let closest_color: Option = + if colors_to_compare.is_some() && compare_to.is_some() { + let s = engine.compile(compare_to.as_ref().unwrap())?; + let compare_to = s.render(engine, &render_data).to_string()?; + Some(color_to_string( + colors_to_compare.as_ref().unwrap(), + &compare_to, + )) + } else { + None + }; + + let t = engine.compile(hook)?; + let res = if colors_to_compare.is_some() && compare_to.is_some() { + format_hook_text(render_data, closest_color, t) + } else { + format_hook_text(render_data, None, t) + }; + + let mut command = shell(&res); + + command.stdout(Stdio::inherit()); + + let output = command.execute_output()?; + + if let Some(exit_code) = output.status.code() { + if exit_code != 0 { + error!("Failed executing command: {:?}", &res) + } + } else { + eprintln!("Interrupted!"); + } + + Ok(()) +} + +pub fn format_hook_text( + render_data: &mut Value, + closest_color: Option, + template: Template<'_>, +) -> String { + let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build(); + let engine = Engine::with_syntax(syntax); + + match render_data { + Value::Map(ref mut map) => { + map.insert("closest_color".to_string(), Value::from(closest_color)); + } + _ => { + debug!("not map") + } + } + + let data = template.render(&engine, &render_data).to_string().unwrap(); + + data +} diff --git a/src/exec/mod.rs b/src/exec/mod.rs new file mode 100644 index 0000000..f48796c --- /dev/null +++ b/src/exec/mod.rs @@ -0,0 +1,2 @@ +pub mod hook; +pub mod command; \ No newline at end of file diff --git a/src/filters/alpha.rs b/src/filters/alpha.rs new file mode 100644 index 0000000..2bee22b --- /dev/null +++ b/src/filters/alpha.rs @@ -0,0 +1,43 @@ +use upon::Value; + +use colorsys::{ColorAlpha, Hsl, Rgb}; +use std::str::FromStr; + +use crate::color::{ + parse::{parse_color, check_string_value}, + format::{format_rgba, format_hsla}, +}; + +pub fn set_alpha(value: &Value, amount: f64) -> Result { + let string = check_string_value(value).unwrap(); + + let format = parse_color(string); + + debug!("Setting alpha on string {} by {}", string, amount); + + if format.is_none() { + return Ok(string.to_string()); + } + + if !(0.0..=1.0).contains(&amount) { + return Err("alpha must be in range [0.0 to 1.0]".to_string()); + } + + match format.unwrap() { + "hex" => Err("cannot set alpha on hex color".to_string()), + "hex_stripped" => Err("cannot set alpha on hex color".to_string()), + "rgb" => Err("cannot set alpha on rgb color, use rgba".to_string()), + "rgba" => { + let mut color = Rgb::from_str(string).unwrap(); + color.set_alpha(amount); + Ok(format_rgba(&color, false)) + } + "hsl" => Err("cannot set alpha on hsl color, use hsla".to_string()), + "hsla" => { + let mut color = Hsl::from_str(string).unwrap(); + color.set_alpha(amount); + Ok(format_hsla(&color, false)) + } + v => Ok(v.to_string()), + } +} diff --git a/src/util/filters.rs b/src/filters/lightness.rs similarity index 50% rename from src/util/filters.rs rename to src/filters/lightness.rs index bb19cf1..1b32392 100644 --- a/src/util/filters.rs +++ b/src/filters/lightness.rs @@ -1,15 +1,11 @@ -use colorsys::ColorAlpha; -use colorsys::ColorTransform; -use colorsys::Hsl; -use colorsys::Rgb; -use std::str::FromStr; use upon::Value; -use crate::util::template::{check_string_value, parse_color}; +use colorsys::{Hsl, Rgb, ColorTransform}; +use std::str::FromStr; -use crate::util::color::{ - format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, - format_rgba, +use crate::color::{ + parse::{parse_color, check_string_value}, + format::{format_hex, format_hex_stripped, format_rgb, format_rgba, format_hsl, format_hsla}, }; pub fn set_lightness(value: &Value, amount: f64) -> Result { @@ -56,38 +52,4 @@ pub fn set_lightness(value: &Value, amount: f64) -> Result { } v => Ok(v.to_string()), } -} - -pub fn set_alpha(value: &Value, amount: f64) -> Result { - let string = check_string_value(value).unwrap(); - - let format = parse_color(string); - - debug!("Setting alpha on string {} by {}", string, amount); - - if format.is_none() { - return Ok(string.to_string()); - } - - if !(0.0..=1.0).contains(&amount) { - return Err("alpha must be in range [0.0 to 1.0]".to_string()); - } - - match format.unwrap() { - "hex" => Err("cannot set alpha on hex color".to_string()), - "hex_stripped" => Err("cannot set alpha on hex color".to_string()), - "rgb" => Err("cannot set alpha on rgb color, use rgba".to_string()), - "rgba" => { - let mut color = Rgb::from_str(string).unwrap(); - color.set_alpha(amount); - Ok(format_rgba(&color, false)) - } - "hsl" => Err("cannot set alpha on hsl color, use hsla".to_string()), - "hsla" => { - let mut color = Hsl::from_str(string).unwrap(); - color.set_alpha(amount); - Ok(format_hsla(&color, false)) - } - v => Ok(v.to_string()), - } -} +} \ No newline at end of file diff --git a/src/filters/mod.rs b/src/filters/mod.rs new file mode 100644 index 0000000..b68afde --- /dev/null +++ b/src/filters/mod.rs @@ -0,0 +1,2 @@ +pub mod lightness; +pub mod alpha; \ No newline at end of file diff --git a/src/helpers.rs b/src/helpers.rs new file mode 100644 index 0000000..f57aad0 --- /dev/null +++ b/src/helpers.rs @@ -0,0 +1,89 @@ +use color_eyre::{eyre::Result, Report}; +use log::LevelFilter; +use matugen::{color::color::Source, wallpaper}; +use update_informer::{registry, Check}; +use std::io::Write; + +use crate::util::arguments::Cli; + + +pub fn get_log_level(args: &Cli) -> LevelFilter { + let log_level: LevelFilter = if args.verbose == Some(true) { + LevelFilter::Info + } else if args.quiet == Some(true) { + LevelFilter::Off + } else if args.debug == Some(true) { + LevelFilter::Debug + } else { + LevelFilter::Warn + }; + log_level +} + +pub fn check_version() { + let name = env!("CARGO_PKG_NAME"); + let current_version = env!("CARGO_PKG_VERSION"); + // for testing + // let current_version = "2.2.0"; + + let informer = update_informer::new(registry::Crates, name, current_version); + + if let Some(version) = informer.check_version().ok().flatten() { + warn!( + "New version is available: {} -> {}", + current_version, version + ); + } +} + +pub fn setup_logging(args: &Cli) -> Result<(), Report> { + let log_level = get_log_level(&args); + + let mut logger = pretty_env_logger::env_logger::builder(); + + logger.filter_level(log_level); + + if log_level != LevelFilter::Debug { + logger.format_module_path(false); + logger.format(|buf, record| writeln!(buf, "{}", record.args())); + } else { + // logger.format_timestamp(Some(pretty_env_logger::env_logger::fmt::TimestampPrecision::Nanos)); + logger.format_timestamp_micros(); + } + + logger.try_init()?; + + Ok(()) +} + +pub fn set_wallpaper(source: &Source) -> Result<(), Report> { + let path = match &source { + Source::Image { path } => path, + Source::Color { .. } => return Ok(()), + Source::WebImage { .. } => return Ok(()), + }; + #[cfg(any(target_os = "linux", target_os = "netbsd"))] + let wallpaper_tool = match &config.config.wallpaper_tool { + Some(wallpaper_tool) => wallpaper_tool, + None => { + if cfg!(windows) { + return Ok(()); + } + return Ok(warn!( + "Wallpaper tool not set, not setting wallpaper..." + )); + } + }; + #[cfg(target_os = "windows")] + wallpaper::windows::set(path)?; + #[cfg(target_os = "macos")] + wallpaper::macos::set(&path)?; + #[cfg(any(target_os = "linux", target_os = "netbsd"))] + wallpaper::unix::set( + path, + wallpaper_tool, + &config.config.feh_options, + &config.config.swww_options, + )?; + Ok(()) +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ad344ad --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,10 @@ +pub mod reload; +pub mod wallpaper; +pub mod color; +pub mod filters; +pub mod scheme; +pub mod exec; + +extern crate pretty_env_logger; +#[macro_use] +extern crate paris_log; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ae74002..9a4cdd9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,55 +5,30 @@ extern crate pretty_env_logger; extern crate paris_log; mod reload; -mod util; +mod helpers; mod wallpaper; +mod util; + +use helpers::{check_version, set_wallpaper, setup_logging}; +use matugen::{color::color::get_source_color, scheme::scheme::{get_custom_color_schemes, get_schemes}}; use crate::util::{ - arguments::{Cli, Source}, - color::{dump_json, get_source_color, show_color}, + arguments::Cli, + color::{dump_json, show_color}, config::ConfigFile, template::Template, }; -use indexmap::IndexMap; - -use material_colors::{color::Argb, scheme::Scheme}; - -use clap::{Parser, ValueEnum}; +use clap::Parser; use color_eyre::{eyre::Result, Report}; -use log::LevelFilter; -use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, io::Write}; -use update_informer::{registry, Check}; - -use util::color::{generate_dynamic_scheme, make_custom_color}; - -pub struct Schemes { - pub light: IndexMap, - pub dark: IndexMap, -} -#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] -pub enum SchemesEnum { - Light, - Dark, -} +use matugen::scheme::scheme::{SchemesEnum, Schemes}; fn main() -> Result<(), Report> { color_eyre::install()?; let args = Cli::parse(); - let log_level: LevelFilter = if args.verbose == Some(true) { - LevelFilter::Info - } else if args.quiet == Some(true) { - LevelFilter::Off - } else if args.debug == Some(true) { - LevelFilter::Debug - } else { - LevelFilter::Warn - }; - - setup_logging(log_level)?; + setup_logging(&args)?; let (config, config_path) = ConfigFile::read(&args)?; @@ -61,69 +36,15 @@ fn main() -> Result<(), Report> { check_version(); } - let source_color = get_source_color(&args.source)?; - - let scheme_dark = Scheme::from(generate_dynamic_scheme( - &args.r#type, - source_color, - true, - args.contrast, - )); - let scheme_light = Scheme::from(generate_dynamic_scheme( - &args.r#type, - source_color, - false, - args.contrast, - )); + let source_color = get_source_color(&args.source).unwrap(); + + let (scheme_dark, scheme_light) = get_schemes(source_color, &args.r#type, &args.contrast); let default_scheme = args .mode .expect("Something went wrong while parsing the mode"); - let empty = HashMap::new(); - let custom_colors = config - .config - .custom_colors - .as_ref() - .unwrap_or(&empty) - .iter() - .map(|(name, color)| { - make_custom_color( - color.to_custom_color(name.to_string()).unwrap_or_else(|_| panic!("Failed to parse custom color: {}, {:?}", - name, color)), - &args.r#type, - source_color, - args.contrast, - ) - }); - macro_rules! from_color { - ($color: expr, $variant: ident) => { - [ - (format!("{}_source", $color.color.name), $color.color.value), - (format!("{}_value", $color.color.name), $color.color.value), - (format!("{}", $color.color.name), $color.$variant.color), - ( - format!("on_{}", $color.color.name), - $color.$variant.on_color, - ), - ( - format!("{}_container", $color.color.name), - $color.$variant.color_container, - ), - ( - format!("on_{}_container", $color.color.name), - $color.$variant.on_color_container, - ), - ] - }; - } - let custom_colors_dark = custom_colors.clone().flat_map(|c| from_color!(c, dark)); - let custom_colors_light = custom_colors.flat_map(|c| from_color!(c, light)); - - let schemes: Schemes = Schemes { - dark: IndexMap::from_iter(scheme_dark.into_iter().chain(custom_colors_dark)), - light: IndexMap::from_iter(scheme_light.into_iter().chain(custom_colors_light)), - }; + let schemes = get_custom_color_schemes(source_color, scheme_dark, scheme_light, &config.config.custom_colors, &args.r#type, &args.contrast); if args.show_colors == Some(true) { show_color(&schemes, &source_color); @@ -138,7 +59,6 @@ fn main() -> Result<(), Report> { &schemes, &config.templates, &args.source, - &config.config.prefix, &source_color, &default_scheme, &config.config.custom_keywords, @@ -152,72 +72,9 @@ fn main() -> Result<(), Report> { } if config.config.set_wallpaper == Some(true) { - let path = match &args.source { - Source::Image { path } => path, - Source::Color { .. } => return Ok(()), - Source::WebImage { .. } => return Ok(()), - }; - - #[cfg(any(target_os = "linux", target_os = "netbsd"))] - let wallpaper_tool = match &config.config.wallpaper_tool { - Some(wallpaper_tool) => wallpaper_tool, - None => { - if cfg!(windows) { - return Ok(()); - } - return Ok(warn!( - "Wallpaper tool not set, not setting wallpaper..." - )); - } - }; - - #[cfg(target_os = "windows")] - wallpaper::windows::set(path)?; - - #[cfg(target_os = "macos")] - wallpaper::macos::set(&path)?; - - #[cfg(any(target_os = "linux", target_os = "netbsd"))] - wallpaper::unix::set( - path, - wallpaper_tool, - &config.config.feh_options, - &config.config.swww_options, - )?; + set_wallpaper(&args.source)?; } } Ok(()) -} - -fn check_version() { - let name = env!("CARGO_PKG_NAME"); - let current_version = env!("CARGO_PKG_VERSION"); - // for testing - // let current_version = "2.2.0"; - - let informer = update_informer::new(registry::Crates, name, current_version); - - if let Some(version) = informer.check_version().ok().flatten() { - warn!( - "New version is available: {} -> {}", - current_version, version - ); - } -} - -fn setup_logging(log_level: LevelFilter) -> Result<(), Report> { - let mut logger = pretty_env_logger::env_logger::builder(); - - logger.filter_level(log_level); - - if log_level != LevelFilter::Debug { - logger.format_timestamp(None); - logger.format_module_path(false); - logger.format(|buf, record| writeln!(buf, "{}", record.args())); - } - - logger.try_init()?; - - Ok(()) -} +} \ No newline at end of file diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs new file mode 100644 index 0000000..aec0480 --- /dev/null +++ b/src/scheme/mod.rs @@ -0,0 +1 @@ +pub mod scheme; \ No newline at end of file diff --git a/src/scheme/scheme.rs b/src/scheme/scheme.rs new file mode 100644 index 0000000..ed72a9f --- /dev/null +++ b/src/scheme/scheme.rs @@ -0,0 +1,94 @@ +use std::collections::HashMap; + +use indexmap::IndexMap; +use material_colors::scheme::Scheme; + +use crate::color::color::{generate_dynamic_scheme, make_custom_color, OwnCustomColor}; + +#[allow(clippy::enum_variant_names)] +#[derive(Clone, clap::ValueEnum, Debug, Copy)] +pub enum SchemeTypes { + SchemeContent, + SchemeExpressive, + SchemeFidelity, + SchemeFruitSalad, + SchemeMonochrome, + SchemeNeutral, + SchemeRainbow, + SchemeTonalSpot, +} +pub struct Schemes { + pub light: IndexMap, + pub dark: IndexMap, +} + +#[derive(serde::Serialize, serde::Deserialize, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)] +pub enum SchemesEnum { + Light, + Dark, +} + +pub fn get_custom_color_schemes(source_color: material_colors::color::Argb, scheme_dark: Scheme, scheme_light: Scheme, custom_colors: &Option>, scheme_type: &Option, contrast: &Option) -> Schemes { + macro_rules! from_color { + ($color: expr, $variant: ident) => { + [ + (format!("{}_source", $color.color.name), $color.color.value), + (format!("{}_value", $color.color.name), $color.color.value), + (format!("{}", $color.color.name), $color.$variant.color), + ( + format!("on_{}", $color.color.name), + $color.$variant.on_color, + ), + ( + format!("{}_container", $color.color.name), + $color.$variant.color_container, + ), + ( + format!("on_{}_container", $color.color.name), + $color.$variant.on_color_container, + ), + ] + }; + } + + let empty = HashMap::new(); + let custom_colors = custom_colors + .as_ref() + .unwrap_or(&empty) + .iter() + .map(|(name, color)| { + make_custom_color( + color.to_custom_color(name.to_string()).unwrap_or_else(|_| panic!("Failed to parse custom color: {}, {:?}", + name, color)), + &scheme_type, + source_color, + *contrast, + ) + }); + + let custom_colors_dark = custom_colors.clone().flat_map(|c| from_color!(c, dark)); + let custom_colors_light = custom_colors.flat_map(|c| from_color!(c, light)); + + let schemes: Schemes = Schemes { + dark: IndexMap::from_iter(scheme_dark.into_iter().chain(custom_colors_dark)), + light: IndexMap::from_iter(scheme_light.into_iter().chain(custom_colors_light)), + }; + schemes +} + +pub fn get_schemes(source_color: material_colors::color::Argb, scheme_type: &Option + , contrast: &Option) -> (Scheme, Scheme) { + let scheme_dark = Scheme::from(generate_dynamic_scheme( + &scheme_type, + source_color, + true, + *contrast, + )); + let scheme_light = Scheme::from(generate_dynamic_scheme( + &scheme_type, + source_color, + false, + *contrast, + )); + (scheme_dark, scheme_light) +} \ No newline at end of file diff --git a/src/util/arguments.rs b/src/util/arguments.rs index 62abbea..3c227ab 100644 --- a/src/util/arguments.rs +++ b/src/util/arguments.rs @@ -1,19 +1,6 @@ -use clap::{arg, ArgAction, Parser, Subcommand}; +use clap::{arg, ArgAction, Parser}; use std::path::PathBuf; -#[allow(clippy::enum_variant_names)] -#[derive(Clone, clap::ValueEnum, Debug, Copy)] -pub enum SchemeTypes { - SchemeContent, - SchemeExpressive, - SchemeFidelity, - SchemeFruitSalad, - SchemeMonochrome, - SchemeNeutral, - SchemeRainbow, - SchemeTonalSpot, -} - use crate::SchemesEnum; #[derive(Parser)] @@ -22,7 +9,7 @@ pub struct Cli { /// Optional name to operate on // name: Option, #[command(subcommand)] - pub source: Source, + pub source: matugen::color::color::Source, /// Sets a custom color scheme type #[arg( @@ -32,7 +19,7 @@ pub struct Cli { global = true, default_value = "scheme-tonal-spot" )] - pub r#type: Option, + pub r#type: Option, /// Sets a custom config file #[arg(short, long, value_name = "FILE", global = true)] @@ -89,17 +76,6 @@ pub struct Cli { pub json: Option, } -#[derive(Subcommand, Debug)] -pub enum Source { - /// The image to use for generating a color scheme - Image { path: String }, - /// The image to fetch from web and use for generating a color scheme - WebImage { url: String }, - /// The source color to use for generating a color scheme - #[clap(subcommand)] - Color(ColorFormat), -} - #[derive(Parser, Debug)] pub enum ColorFormat { Hex { string: String }, diff --git a/src/util/color.rs b/src/util/color.rs index b7c3ea6..bfc5b1f 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -1,223 +1,16 @@ -use material_colors::color::Lab; -use material_colors::dynamic_color::dynamic_scheme::DynamicScheme; -use material_colors::dynamic_color::material_dynamic_colors::MaterialDynamicColors; -use material_colors::theme::{ColorGroup, CustomColor, CustomColorGroup}; -use material_colors::{ - color::Argb, - hct::Hct, - image::FilterType, - image::ImageReader, - scheme::variant::{ - SchemeContent, SchemeExpressive, SchemeFidelity, SchemeFruitSalad, SchemeMonochrome, - SchemeNeutral, SchemeRainbow, SchemeTonalSpot, - }, -}; +use material_colors::color::Argb; use owo_colors::{OwoColorize, Style}; use prettytable::{format, Cell, Row, Table}; use crate::Schemes; -use super::arguments::{ColorFormat, Format, SchemeTypes, Source}; -use super::template::ColorDefinition; -use color_eyre::{eyre::Result, Report}; +use super::arguments::Format; use colorsys::{ColorAlpha, Hsl, Rgb}; use serde_json::json; use std::collections::HashMap; -use std::str::FromStr; -use material_colors::blend::harmonize; - -pub fn rgb_from_argb(color: Argb) -> Rgb { - Rgb::from([ - color.red as f64, - color.green as f64, - color.blue as f64, - color.alpha as f64, - ]) -} - -pub fn format_hex(color: &Rgb) -> String { - color.to_hex_string() -} - -pub fn format_hex_stripped(color: &Rgb) -> String { - color.to_hex_string()[1..].to_string() -} - -pub fn format_rgb(color: &Rgb) -> String { - format!( - "rgb({:?}, {:?}, {:?})", - color.red() as u8, - color.green() as u8, - color.blue() as u8, - ) -} - -pub fn format_rgba(color: &Rgb, divide: bool) -> String { - if divide { - format!( - "rgba({:?}, {:?}, {:?}, {:.1})", - color.red() as u8, - color.green() as u8, - color.blue() as u8, - color.alpha() / 255. - ) - } else { - format!( - "rgba({:?}, {:?}, {:?}, {:.1})", - color.red() as u8, - color.green() as u8, - color.blue() as u8, - color.alpha() - ) - } -} - -pub fn format_hsl(color: &Hsl) -> String { - format!( - "hsl({:?}, {:?}%, {:?}%)", - color.hue() as u8, - color.saturation() as u8, - color.lightness() as u8, - ) -} - -pub fn format_hsla(color: &Hsl, divide: bool) -> String { - if divide { - format!( - "hsla({:?}, {:?}%, {:?}%, {:.1})", - color.hue() as u8, - color.saturation() as u8, - color.lightness() as u8, - color.alpha() / 255. - ) - } else { - format!( - "hsla({:?}, {:?}%, {:?}%, {:.1})", - color.hue() as u8, - color.saturation() as u8, - color.lightness() as u8, - color.alpha() - ) - } -} - -pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { - let c1 = Lab::from(Argb::from_str(c1).unwrap()); - let c2 = Lab::from(Argb::from_str(c2).unwrap()); - - let l: f64 = c1.l - c2.l; - let a: f64 = c1.a - c2.a; - let b: f64 = c1.b - c2.b; - - f64::sqrt((l * l) + (a * a) + (b * b)) -} - -// for rgb - useless but ill keep it here - -// pub fn get_color_distance(c1: &Rgb, c2: &Rgb) -> f64 { -// let (r1, g1, b1) = (c1.red() as i64, c1.blue() as i64, c1.green() as i64); -// let (r2, g2, b2) = (c2.red() as i64, c2.green() as i64, c2.blue() as i64); - -// let rmean: f64 = ((r1 + r2) / 2) as f64; -// let weightR: f64 = 2.0 + rmean / 256.0; -// let weightG: f64 = 4.0; -// let weightB: f64 = 2.0 + (255.0 - rmean) / 256.0; - -// return f64::sqrt(weightR * i64::pow(r1-r2, 2) as f64 + weightG * i64::pow(g1-g2, 2) as f64 + weightB * i64::pow(b1-b2, 2) as f64) -// } - -pub fn color_to_string(colors_to_compare: &Vec, compare_to: &str) -> String { - let mut closest_distance: Option = None; - let mut closest_color: &str = ""; - - for c in colors_to_compare { - let distance = get_color_distance_lab(&c.color, compare_to); - if closest_distance.is_none() || closest_distance.unwrap() > distance { - closest_distance = Some(distance); - closest_color = &c.name; - } - debug!("distance: {}, name: {}", distance, c.name) - } - debug!( - "closest distance: {:?}, closest color: {}", - closest_distance, closest_color - ); - closest_color.to_string() -} - -pub fn generate_dynamic_scheme( - scheme_type: &Option, - source_color: Argb, - is_dark: bool, - contrast_level: Option, -) -> DynamicScheme { - match scheme_type.unwrap() { - SchemeTypes::SchemeContent => { - SchemeContent::new(Hct::new(source_color), is_dark, contrast_level).scheme - } - SchemeTypes::SchemeExpressive => { - SchemeExpressive::new(Hct::new(source_color), is_dark, contrast_level).scheme - } - SchemeTypes::SchemeFidelity => { - SchemeFidelity::new(Hct::new(source_color), is_dark, contrast_level).scheme - } - SchemeTypes::SchemeFruitSalad => { - SchemeFruitSalad::new(Hct::new(source_color), is_dark, contrast_level).scheme - } - SchemeTypes::SchemeMonochrome => { - SchemeMonochrome::new(Hct::new(source_color), is_dark, contrast_level).scheme - } - SchemeTypes::SchemeNeutral => { - SchemeNeutral::new(Hct::new(source_color), is_dark, contrast_level).scheme - } - SchemeTypes::SchemeRainbow => { - SchemeRainbow::new(Hct::new(source_color), is_dark, contrast_level).scheme - } - SchemeTypes::SchemeTonalSpot => { - SchemeTonalSpot::new(Hct::new(source_color), is_dark, contrast_level).scheme - } - } -} - -pub fn make_custom_color( - color: CustomColor, - scheme_type: &Option, - source_color: Argb, - contrast_level: Option, -) -> CustomColorGroup { - // debug!("make_custom_color: {:#?}", &color); - - let value = if color.blend { - harmonize(color.value, source_color) - } else { - color.value - }; - - let light = generate_dynamic_scheme(scheme_type, value, false, contrast_level); - let dark = generate_dynamic_scheme(scheme_type, value, true, contrast_level); - - - - // debug!("custom_color: {:#?}", &custom_color); - CustomColorGroup { - color, - value, - light: ColorGroup { - color: MaterialDynamicColors::primary().get_argb(&light), - on_color: MaterialDynamicColors::on_primary().get_argb(&light), - color_container: MaterialDynamicColors::primary_container().get_argb(&light), - on_color_container: MaterialDynamicColors::on_primary_container().get_argb(&light), - }, - dark: ColorGroup { - color: MaterialDynamicColors::primary().get_argb(&dark), - on_color: MaterialDynamicColors::on_primary().get_argb(&dark), - color_container: MaterialDynamicColors::primary_container().get_argb(&dark), - on_color_container: MaterialDynamicColors::on_primary_container().get_argb(&dark), - }, - } -} +use matugen::color::format::rgb_from_argb; pub fn show_color(schemes: &Schemes, source_color: &Argb) { let mut table: Table = generate_table_format(); @@ -343,48 +136,3 @@ fn generate_style(color: &Rgb) -> Style { Style::new().white().on_color(owo_color) } } - -pub fn get_source_color(source: &Source) -> Result { - let source_color: Argb = match &source { - Source::Image { path } => { - // test - info!("Opening image in {}", path); - ImageReader::extract_color(ImageReader::open(path)?.resize( - 128, - 128, - FilterType::Lanczos3, - )) - } - Source::WebImage { url } => { - // test - info!("Fetching image from {}", url); - - let bytes = reqwest::blocking::get(url)?.bytes()?; - ImageReader::extract_color(ImageReader::read(&bytes)?.resize( - 128, - 128, - FilterType::Lanczos3, - )) - } - Source::Color(color) => match color { - ColorFormat::Hex { string } => { - Argb::from_str(string).expect("Invalid hex color string provided") - } - ColorFormat::Rgb { string } => { - string.parse().expect("Invalid rgb color string provided") - } - ColorFormat::Hsl { string } => { - let rgb: Rgb = Hsl::from_str(string) - .expect("Invalid hsl color string provided") - .into(); - Argb { - red: rgb.red() as u8, - green: rgb.green() as u8, - blue: rgb.blue() as u8, - alpha: 255, - } - } - }, - }; - Ok(source_color) -} diff --git a/src/util/config.rs b/src/util/config.rs index 8469064..92c3486 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -1,8 +1,7 @@ use directories::ProjectDirs; -use material_colors::color::Argb; use std::fs; use std::path::PathBuf; -use std::{collections::HashMap, str::FromStr}; +use std::{collections::HashMap}; use color_eyre::{Help, Report}; @@ -19,33 +18,6 @@ pub enum WallpaperTool { Feh, } -#[derive(Serialize, Deserialize, Debug)] -#[serde(untagged)] -pub enum CustomColor { - Color(String), - Options { color: String, blend: bool }, -} - -impl CustomColor { - pub fn to_custom_color( - &self, - name: String, - ) -> Result { - Ok(match self { - CustomColor::Color(color) => material_colors::theme::CustomColor { - value: Argb::from_str(color)?, - blend: true, - name, - }, - CustomColor::Options { color, blend } => material_colors::theme::CustomColor { - value: Argb::from_str(color)?, - blend: *blend, - name, - }, - }) - } -} - #[derive(Serialize, Deserialize, Debug)] pub struct Config { pub reload_apps: Option, @@ -58,7 +30,7 @@ pub struct Config { pub feh_options: Option>, pub prefix: Option, pub custom_keywords: Option>, - pub custom_colors: Option>, + pub custom_colors: Option>, } #[derive(Deserialize, Serialize, Debug)] diff --git a/src/util/mod.rs b/src/util/mod.rs index a74c76f..5f42aca 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,6 +1,4 @@ pub mod arguments; pub mod color; pub mod config; -pub mod filters; pub mod template; -pub mod variables; diff --git a/src/util/template.rs b/src/util/template.rs index ba67f18..6192a6a 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -10,17 +10,12 @@ use serde::{Deserialize, Serialize}; use upon::Value; -use crate::util::color::color_to_string; -use crate::util::filters::{set_alpha, set_lightness}; -use crate::util::variables::format_hook_text; +use matugen::filters::{alpha::set_alpha, lightness::set_lightness}; +use matugen::exec::hook::format_hook; use std::path::Path; use std::str; -use std::process::{Stdio}; - -use execute::{shell, Execute}; - use std::collections::HashMap; use std::fs::create_dir_all; use std::fs::read_to_string; @@ -28,29 +23,23 @@ use std::fs::OpenOptions; use std::io::Write; use std::path::PathBuf; -use crate::util::color::{ +use matugen::color::format::{ format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba, }; -use crate::util::arguments::Source; +use matugen::color::color::Source; use resolve_path::PathResolveExt; use crate::{Schemes, SchemesEnum}; use upon::{Engine, Syntax}; -#[derive(Serialize, Deserialize, Debug)] -pub struct ColorDefinition { - pub name: String, - pub color: String, -} - #[derive(Serialize, Deserialize, Debug)] pub struct Template { pub input_path: PathBuf, pub output_path: PathBuf, pub mode: Option, - pub colors_to_compare: Option>, + pub colors_to_compare: Option>, pub compare_to: Option, pub pre_hook: Option, pub post_hook: Option, @@ -80,7 +69,7 @@ struct ColorVariants { pub default: Colora, } -use super::color::rgb_from_argb; +use matugen::color::format::rgb_from_argb; #[allow(clippy::manual_strip)] pub trait StripCanonicalization @@ -106,48 +95,17 @@ where impl StripCanonicalization for PathBuf {} -pub fn check_string_value(value: &Value) -> Option<&String> { - match value { - Value::String(v) => Some(v), - _v => None, - } -} - -pub fn parse_color(string: &str) -> Option<&str> { - if let Some(_s) = string.strip_prefix('#') { - return Some("hex"); - } - - if let (Some(i), Some(s)) = (string.find('('), string.strip_suffix(')')) { - let fname = s[..i].trim_end(); - Some(fname) - } else if string.len() == 6 { - // Does not matter if it is actually a stripped hex or not, we handle it somewhere else. - return Some("hex_stripped"); - } else { - None - } -} - impl Template { pub fn generate( schemes: &Schemes, templates: &HashMap, source: &Source, - prefix: &Option, source_color: &Argb, default_scheme: &SchemesEnum, custom_keywords: &Option>, path_prefix: &Option, config_path: Option, ) -> Result<(), Report> { - let default_prefix = "@".to_string(); - - let _prefix: &String = match &prefix { - Some(prefix) => prefix, - None => &default_prefix, - }; - info!("Loaded {} templates.", &templates.len()); let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build(); @@ -175,38 +133,17 @@ impl Template { colors: &colors, image: image, custom: &custom, }; - // let default_fill_value = String::from("-"); - // debug!("render_data: {:#?}", &render_data); - for (i, (name, template)) in templates.iter().enumerate() { - let (input_path_absolute, output_path_absolute) = if config_path.is_some() { - let base = std::fs::canonicalize(config_path.as_ref().unwrap())?; - ( - template - .input_path - .try_resolve_in(&base)? - .to_path_buf() - .strip_canonicalization(), - template - .output_path - .try_resolve_in(&base)? - .to_path_buf() - .strip_canonicalization(), - ) - } else { - ( - template.input_path.try_resolve()?.to_path_buf(), - template.output_path.try_resolve()?.to_path_buf(), - ) - }; + let (input_path_absolute, output_path_absolute) = get_absolute_paths(&config_path, template)?; if template.pre_hook.is_some() { format_hook( - template, &engine, &mut render_data, template.pre_hook.as_ref().unwrap(), - )?; + &template.colors_to_compare, + &template.compare_to + ).unwrap(); } if !input_path_absolute.exists() { @@ -234,22 +171,6 @@ impl Template { output_path_absolute.display() ); - let parent_folder = &output_path_absolute - .parent() - .wrap_err("Could not get the parent of the output path.")?; - - if !parent_folder.exists() { - error!( - "The {} folder doesnt exist, trying to create...", - &parent_folder.display() - ); - debug!("{}", parent_folder.display()); - let _ = create_dir_all(parent_folder).wrap_err(format!( - "Failed to create the {} folders.", - &output_path_absolute.display() - )); - } - export_template( &engine, name, @@ -263,17 +184,59 @@ impl Template { if template.post_hook.is_some() { format_hook( - template, &engine, &mut render_data, template.post_hook.as_ref().unwrap(), - )?; + &template.colors_to_compare, + &template.compare_to + ).unwrap(); } } Ok(()) } } +fn create_missing_folders(output_path_absolute: &PathBuf) -> Result<(), Report> { + let parent_folder = &output_path_absolute + .parent() + .wrap_err("Could not get the parent of the output path.")?; + Ok(if !parent_folder.exists() { + error!( + "The {} folder doesnt exist, trying to create...", + &parent_folder.display() + ); + debug!("{}", parent_folder.display()); + let _ = create_dir_all(parent_folder).wrap_err(format!( + "Failed to create the {} folders.", + &output_path_absolute.display() + )); + }) +} + +fn get_absolute_paths(config_path: &Option, template: &Template) -> Result<(PathBuf, PathBuf), Report> { + let (input_path_absolute, output_path_absolute) = if config_path.is_some() { + let base = std::fs::canonicalize(config_path.as_ref().unwrap())?; + ( + template + .input_path + .try_resolve_in(&base)? + .to_path_buf() + .strip_canonicalization(), + template + .output_path + .try_resolve_in(&base)? + .to_path_buf() + .strip_canonicalization(), + ) + } else { + ( + template.input_path.try_resolve()?.to_path_buf(), + template.output_path.try_resolve()?.to_path_buf(), + ) + }; + Ok((input_path_absolute, output_path_absolute)) +} + fn export_template( engine: &Engine, name: &String, @@ -298,24 +261,30 @@ fn export_template( Report::new(error).wrap_err(message) })?; + let out = if path_prefix.is_some() && !cfg!(windows) { let prefix_path = PathBuf::from(path_prefix.as_ref().unwrap()); rebase(&output_path_absolute, &prefix_path, None).expect("failed to rebase output path") } else { output_path_absolute.to_path_buf() }; + + create_missing_folders(&out)?; + debug!("out: {:?}", out); let mut output_file = OpenOptions::new() .create(true) .truncate(true) .write(true) .open(out)?; + if output_file.metadata()?.permissions().readonly() { error!( "The {} file is Read-Only", &output_path_absolute.display() ); } + output_file.write_all(data.as_bytes())?; success!( "[{}/{}] Exported the {} template to {}", @@ -324,6 +293,7 @@ fn export_template( name, output_path_absolute.display() ); + Ok(()) } @@ -337,48 +307,6 @@ fn add_engine_filters(engine: &mut Engine) { }); } -fn format_hook( - template: &Template, - engine: &Engine, - render_data: &mut Value, - hook: &String, -) -> Result<(), Report> { - let closest_color: Option = - if template.colors_to_compare.is_some() && template.compare_to.is_some() { - let s = engine.compile(template.compare_to.as_ref().unwrap())?; - let compare_to = s.render(engine, &render_data).to_string()?; - Some(color_to_string( - template.colors_to_compare.as_ref().unwrap(), - &compare_to, - )) - } else { - None - }; - - let t = engine.compile(hook)?; - let res = if template.colors_to_compare.is_some() && template.compare_to.is_some() { - format_hook_text(render_data, closest_color, t) - } else { - format_hook_text(render_data, None, t) - }; - - let mut command = shell(&res); - - command.stdout(Stdio::inherit()); - - let output = command.execute_output()?; - - if let Some(exit_code) = output.status.code() { - if exit_code != 0 { - error!("Failed executing command: {:?}", &res) - } - } else { - eprintln!("Interrupted!"); - } - - Ok(()) -} - fn generate_colors( schemes: &Schemes, source_color: &Argb, diff --git a/src/util/variables.rs b/src/util/variables.rs deleted file mode 100644 index eabc962..0000000 --- a/src/util/variables.rs +++ /dev/null @@ -1,96 +0,0 @@ -use upon::{Engine, Syntax, Template, Value}; - -// use regex::{Captures, Regex}; -// use material_colors::color::Argb; -// use super::color::{format_hex, rgb_from_argb}; - -// pub enum Variables { -// Invalid, -// ComparedColor, -// SourceImage, -// SourceColor, -// } - -// impl Variables { -// fn from(mut input: &str) -> Self { -// if input.starts_with("{") && input.ends_with("}") { -// input = input.remove_first_char().remove_last_char(); -// } - -// match input { -// "closest_color" => Variables::ComparedColor, -// "source_image" => Variables::SourceImage, -// "source_color" => Variables::SourceColor, -// _ => { -// error!("Invalid variable: {{{}}}", input); -// Variables::Invalid -// } -// } -// } -// } - -// trait StrExt { -// fn remove_last_char(&self) -> &str; -// fn remove_first_char(&self) -> &str; -// } - -// impl StrExt for str { -// fn remove_last_char(&self) -> &str { -// match self.char_indices().next_back() { -// Some((i, _)) => &self[..i], -// None => self, -// } -// } -// fn remove_first_char(&self) -> &str { -// self.chars() -// .next() -// .map(|c| &self[c.len_utf8()..]) -// .unwrap_or("") -// } -// } - -// pub fn replace_hook_keywords( -// input: &str, -// default_value: &String, -// src_img: Option<&String>, -// closest_color: Option<&String>, -// source_color: &Argb, -// ) -> String { -// let re = Regex::new(r"\{.*?\}").unwrap(); - -// let source_formatted = format_hex(&rgb_from_argb(*source_color)); - -// let result = re.replace_all(input, |cap: &Captures| { -// match Variables::from(&cap[0]) { -// Variables::Invalid => &cap[0], -// Variables::ComparedColor => closest_color.unwrap_or(default_value), -// Variables::SourceImage => src_img.unwrap_or(default_value), -// Variables::SourceColor => &source_formatted, -// } -// .to_string() -// }); - -// return result.to_string(); -// } - -pub fn format_hook_text( - render_data: &mut Value, - closest_color: Option, - template: Template<'_>, -) -> String { - let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build(); - let engine = Engine::with_syntax(syntax); - - match render_data { - Value::Map(ref mut map) => { - map.insert("closest_color".to_string(), Value::from(closest_color)); - } - _ => { - debug!("not map") - } - } - - let data = template.render(&engine, &render_data).to_string().unwrap(); - - data -} From 942efee51bb33ee79c04c438708ff1de9f6d3b97 Mon Sep 17 00:00:00 2001 From: InioX Date: Fri, 16 Aug 2024 21:41:12 +0200 Subject: [PATCH 25/59] feat(filters): add `invert`, `grayscale and `set_hue` --- example/colors.whatever-extension | 14 +++++++- src/filters/grayscale.rs | 53 +++++++++++++++++++++++++++ src/filters/hue.rs | 60 +++++++++++++++++++++++++++++++ src/filters/invert.rs | 53 +++++++++++++++++++++++++++ src/filters/mod.rs | 5 ++- src/util/template.rs | 9 +++++ 6 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 src/filters/grayscale.rs create mode 100644 src/filters/hue.rs create mode 100644 src/filters/invert.rs diff --git a/example/colors.whatever-extension b/example/colors.whatever-extension index 6add080..c8090a8 100644 --- a/example/colors.whatever-extension +++ b/example/colors.whatever-extension @@ -28,4 +28,16 @@ Only works with rgba and hsla {{ colors.source_color.default.rgba | set_alpha: 0.5 }} -Output: rgba(r, g, b, 0.5) +- 180 +{{ colors.source_color.default.rgba | set_hue: -180.0 }} + ++ 90 +{{ colors.source_color.default.rgba | set_hue: 90.0 }} + +grayscale +{{ colors.source_color.default.rgba | grayscale }} + +invert +{{ colors.source_color.default.rgba | invert }} + +chain together {{ colors.source_color.default.rgba | set_alpha: 0.7 | set_hue: -180.0 | invert }} \ No newline at end of file diff --git a/src/filters/grayscale.rs b/src/filters/grayscale.rs new file mode 100644 index 0000000..cc4e212 --- /dev/null +++ b/src/filters/grayscale.rs @@ -0,0 +1,53 @@ +use upon::Value; + +use colorsys::{ColorTransform, Hsl, Rgb}; +use std::str::FromStr; + +use crate::color::{ + parse::{parse_color, check_string_value}, + format::{format_hex, format_hex_stripped, format_rgb, format_rgba, format_hsl, format_hsla}, +}; + +pub fn grayscale(value: &Value) -> Result { + let string = check_string_value(value).unwrap(); + + let format = parse_color(string); + + if format.is_none() { + return Ok(string.to_string()); + } + + match format.unwrap() { + "hex" => { + let mut color = Rgb::from_hex_str(string).unwrap(); + color.grayscale_simple(); + Ok(format_hex(&color)) + } + "hex_stripped" => { + let mut color = Rgb::from_hex_str(string).unwrap(); + color.grayscale_simple(); + Ok(format_hex_stripped(&color)) + } + "rgb" => { + let mut color = Rgb::from_str(string).unwrap(); + color.grayscale_simple(); + Ok(format_rgb(&color)) + } + "rgba" => { + let mut color = Rgb::from_str(string).unwrap(); + color.grayscale_simple(); + Ok(format_rgba(&color, false)) + } + "hsl" => { + let mut color = Hsl::from_str(string).unwrap(); + color.grayscale_simple(); + Ok(format_hsl(&color)) + } + "hsla" => { + let mut color = Hsl::from_str(string).unwrap(); + color.grayscale_simple(); + Ok(format_hsla(&color, false)) + } + v => Ok(v.to_string()), + } +} \ No newline at end of file diff --git a/src/filters/hue.rs b/src/filters/hue.rs new file mode 100644 index 0000000..30de81a --- /dev/null +++ b/src/filters/hue.rs @@ -0,0 +1,60 @@ +use upon::Value; + +use colorsys::{ColorTransform, Hsl, Rgb}; +use std::str::FromStr; + +use crate::color::{ + parse::{parse_color, check_string_value}, + format::{format_hex, format_hex_stripped, format_rgb, format_rgba, format_hsl, format_hsla}, +}; + +pub fn set_hue(value: &Value, amount: f64) -> Result { + let string = check_string_value(value).unwrap(); + + let format = parse_color(string); + + debug!("Setting alpha on string {} by {}", string, amount); + + if format.is_none() { + error!("Could not detect the format for string {:?}", string); + return Ok(string.to_string()); + } + + if !(-360.0..=360.0).contains(&amount) { + return Err("alpha must be in range [-360.0 to 360.0]".to_string()); + } + + match format.unwrap() { + "hex" => { + let mut color = Rgb::from_hex_str(string).unwrap(); + color.adjust_hue(amount); + Ok(format_hex(&color)) + } + "hex_stripped" => { + let mut color = Rgb::from_hex_str(string).unwrap(); + color.adjust_hue(amount); + Ok(format_hex_stripped(&color)) + } + "rgb" => { + let mut color = Rgb::from_str(string).unwrap(); + color.adjust_hue(amount); + Ok(format_rgb(&color)) + } + "rgba" => { + let mut color = Rgb::from_str(string).unwrap(); + color.adjust_hue(amount); + Ok(format_rgba(&color, false)) + } + "hsl" => { + let mut color = Hsl::from_str(string).unwrap(); + color.adjust_hue(amount); + Ok(format_hsl(&color)) + } + "hsla" => { + let mut color = Hsl::from_str(string).unwrap(); + color.adjust_hue(amount); + Ok(format_hsla(&color, false)) + } + v => Ok(v.to_string()), + } +} diff --git a/src/filters/invert.rs b/src/filters/invert.rs new file mode 100644 index 0000000..23b9eae --- /dev/null +++ b/src/filters/invert.rs @@ -0,0 +1,53 @@ +use upon::Value; + +use colorsys::{ColorTransform, Hsl, Rgb}; +use std::str::FromStr; + +use crate::color::{ + parse::{parse_color, check_string_value}, + format::{format_hex, format_hex_stripped, format_rgb, format_rgba, format_hsl, format_hsla}, +}; + +pub fn invert(value: &Value) -> Result { + let string = check_string_value(value).unwrap(); + + let format = parse_color(string); + + if format.is_none() { + return Ok(string.to_string()); + } + + match format.unwrap() { + "hex" => { + let mut color = Rgb::from_hex_str(string).unwrap(); + color.invert(); + Ok(format_hex(&color)) + } + "hex_stripped" => { + let mut color = Rgb::from_hex_str(string).unwrap(); + color.invert(); + Ok(format_hex_stripped(&color)) + } + "rgb" => { + let mut color = Rgb::from_str(string).unwrap(); + color.invert(); + Ok(format_rgb(&color)) + } + "rgba" => { + let mut color = Rgb::from_str(string).unwrap(); + color.invert(); + Ok(format_rgba(&color, false)) + } + "hsl" => { + let mut color = Hsl::from_str(string).unwrap(); + color.invert(); + Ok(format_hsl(&color)) + } + "hsla" => { + let mut color = Hsl::from_str(string).unwrap(); + color.invert(); + Ok(format_hsla(&color, false)) + } + v => Ok(v.to_string()), + } +} \ No newline at end of file diff --git a/src/filters/mod.rs b/src/filters/mod.rs index b68afde..9d3beb2 100644 --- a/src/filters/mod.rs +++ b/src/filters/mod.rs @@ -1,2 +1,5 @@ pub mod lightness; -pub mod alpha; \ No newline at end of file +pub mod alpha; +pub mod hue; +pub mod grayscale; +pub mod invert; \ No newline at end of file diff --git a/src/util/template.rs b/src/util/template.rs index 6192a6a..32481e0 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -5,6 +5,9 @@ use color_eyre::{eyre::Result, Report}; use colorsys::{ColorAlpha, Hsl}; use material_colors::color::Argb; +use matugen::filters::grayscale::grayscale; +use matugen::filters::hue::set_hue; +use matugen::filters::invert::invert; use proper_path_tools::path::rebase; use serde::{Deserialize, Serialize}; @@ -298,8 +301,14 @@ fn export_template( } fn add_engine_filters(engine: &mut Engine) { + // Color manipulation engine.add_filter("set_lightness", set_lightness); engine.add_filter("set_alpha", set_alpha); + engine.add_filter("set_hue", set_hue); + engine.add_filter("grayscale", grayscale); + engine.add_filter("invert", invert); + + // String manipulation engine.add_filter("to_upper", str::to_uppercase); engine.add_filter("to_lower", str::to_lowercase); engine.add_filter("replace", |s: String, from: String, to: String| { From 0bd628f263b1d97f238849315f2ce3ab4439784e Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 17 Aug 2024 18:08:09 +0000 Subject: [PATCH 26/59] fix: made unix version compile --- src/helpers.rs | 18 +++++++++--------- src/lib.rs | 6 ++---- src/main.rs | 24 +++++++++++++++++------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index f57aad0..bdeaaa1 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,12 +1,12 @@ +use crate::{util::config::Config, wallpaper}; use color_eyre::{eyre::Result, Report}; use log::LevelFilter; -use matugen::{color::color::Source, wallpaper}; -use update_informer::{registry, Check}; +use matugen::color::color::Source; use std::io::Write; +use update_informer::{registry, Check}; use crate::util::arguments::Cli; - pub fn get_log_level(args: &Cli) -> LevelFilter { let log_level: LevelFilter = if args.verbose == Some(true) { LevelFilter::Info @@ -40,7 +40,7 @@ pub fn setup_logging(args: &Cli) -> Result<(), Report> { let log_level = get_log_level(&args); let mut logger = pretty_env_logger::env_logger::builder(); - + logger.filter_level(log_level); if log_level != LevelFilter::Debug { @@ -56,14 +56,14 @@ pub fn setup_logging(args: &Cli) -> Result<(), Report> { Ok(()) } -pub fn set_wallpaper(source: &Source) -> Result<(), Report> { +pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { let path = match &source { Source::Image { path } => path, Source::Color { .. } => return Ok(()), Source::WebImage { .. } => return Ok(()), }; #[cfg(any(target_os = "linux", target_os = "netbsd"))] - let wallpaper_tool = match &config.config.wallpaper_tool { + let wallpaper_tool = match &config.wallpaper_tool { Some(wallpaper_tool) => wallpaper_tool, None => { if cfg!(windows) { @@ -82,8 +82,8 @@ pub fn set_wallpaper(source: &Source) -> Result<(), Report> { wallpaper::unix::set( path, wallpaper_tool, - &config.config.feh_options, - &config.config.swww_options, + &config.feh_options, + &config.swww_options, )?; Ok(()) -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index ad344ad..130e470 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,8 @@ -pub mod reload; -pub mod wallpaper; pub mod color; +pub mod exec; pub mod filters; pub mod scheme; -pub mod exec; extern crate pretty_env_logger; #[macro_use] -extern crate paris_log; \ No newline at end of file +extern crate paris_log; diff --git a/src/main.rs b/src/main.rs index 9a4cdd9..fa01c06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,13 +4,16 @@ extern crate pretty_env_logger; #[macro_use] extern crate paris_log; -mod reload; mod helpers; -mod wallpaper; +mod reload; mod util; +mod wallpaper; use helpers::{check_version, set_wallpaper, setup_logging}; -use matugen::{color::color::get_source_color, scheme::scheme::{get_custom_color_schemes, get_schemes}}; +use matugen::{ + color::color::get_source_color, + scheme::scheme::{get_custom_color_schemes, get_schemes}, +}; use crate::util::{ arguments::Cli, @@ -22,7 +25,7 @@ use crate::util::{ use clap::Parser; use color_eyre::{eyre::Result, Report}; -use matugen::scheme::scheme::{SchemesEnum, Schemes}; +use matugen::scheme::scheme::{Schemes, SchemesEnum}; fn main() -> Result<(), Report> { color_eyre::install()?; @@ -44,7 +47,14 @@ fn main() -> Result<(), Report> { .mode .expect("Something went wrong while parsing the mode"); - let schemes = get_custom_color_schemes(source_color, scheme_dark, scheme_light, &config.config.custom_colors, &args.r#type, &args.contrast); + let schemes = get_custom_color_schemes( + source_color, + scheme_dark, + scheme_light, + &config.config.custom_colors, + &args.r#type, + &args.contrast, + ); if args.show_colors == Some(true) { show_color(&schemes, &source_color); @@ -72,9 +82,9 @@ fn main() -> Result<(), Report> { } if config.config.set_wallpaper == Some(true) { - set_wallpaper(&args.source)?; + set_wallpaper(&args.source, &config.config)?; } } Ok(()) -} \ No newline at end of file +} From f3570a7e16588520f85555fedf0a0b5b0dd9ab16 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 17 Aug 2024 21:54:05 +0200 Subject: [PATCH 27/59] fix: cargo fmt & alejandra (nix formatter) --- default.nix | 16 ++++++++-------- flake.nix | 33 ++++++++++++++++++--------------- shell.nix | 10 +++++----- src/color/color.rs | 37 +++++++++++++++++++++---------------- src/color/format.rs | 4 ++-- src/color/math.rs | 10 +++++++--- src/color/mod.rs | 4 ++-- src/color/parse.rs | 2 +- src/exec/command.rs | 1 + src/exec/hook.rs | 22 ++++++++++------------ src/exec/mod.rs | 2 +- src/filters/alpha.rs | 4 ++-- src/filters/grayscale.rs | 6 +++--- src/filters/hue.rs | 4 ++-- src/filters/invert.rs | 6 +++--- src/filters/lightness.rs | 8 ++++---- src/filters/mod.rs | 6 +++--- src/scheme/mod.rs | 2 +- src/scheme/scheme.rs | 40 +++++++++++++++++++++++++++++++--------- src/util/config.rs | 2 +- 20 files changed, 126 insertions(+), 93 deletions(-) diff --git a/default.nix b/default.nix index 6831937..a6c99f0 100644 --- a/default.nix +++ b/default.nix @@ -1,9 +1,9 @@ -{ pkgs ? import { } }: -let manifest = (pkgs.lib.importTOML ./Cargo.toml).package; +{pkgs ? import {}}: let + manifest = (pkgs.lib.importTOML ./Cargo.toml).package; in -pkgs.rustPlatform.buildRustPackage rec { - pname = manifest.name; - version = manifest.version; - cargoLock.lockFile = ./Cargo.lock; - src = pkgs.lib.cleanSource ./.; -} \ No newline at end of file + pkgs.rustPlatform.buildRustPackage rec { + pname = manifest.name; + version = manifest.version; + cargoLock.lockFile = ./Cargo.lock; + src = pkgs.lib.cleanSource ./.; + } diff --git a/flake.nix b/flake.nix index 6456e56..fb0d9a1 100644 --- a/flake.nix +++ b/flake.nix @@ -4,20 +4,23 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; systems.url = "github:nix-systems/default-linux"; }; - outputs = { self, nixpkgs, systems }: - let - forAllSystems = nixpkgs.lib.genAttrs (import systems); - pkgsFor = nixpkgs.legacyPackages; - in { - packages = forAllSystems (system: { - default = pkgsFor.${system}.callPackage ./. { }; - }); - devShells = forAllSystems (system: { - default = pkgsFor.${system}.callPackage ./shell.nix { }; - }); - nixosModules = { - matugen = import ./module.nix self; - default = self.nixosModules.matugen; - }; + outputs = { + self, + nixpkgs, + systems, + }: let + forAllSystems = nixpkgs.lib.genAttrs (import systems); + pkgsFor = nixpkgs.legacyPackages; + in { + packages = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./. {}; + }); + devShells = forAllSystems (system: { + default = pkgsFor.${system}.callPackage ./shell.nix {}; + }); + nixosModules = { + matugen = import ./module.nix self; + default = self.nixosModules.matugen; }; + }; } diff --git a/shell.nix b/shell.nix index ae7efa1..9827ff0 100644 --- a/shell.nix +++ b/shell.nix @@ -1,11 +1,11 @@ -{ pkgs ? import { } }: +{pkgs ? import {}}: pkgs.mkShell { # Get dependencies from the main package - inputsFrom = [ (pkgs.callPackage ./default.nix { }) ]; + inputsFrom = [(pkgs.callPackage ./default.nix {})]; # Additional tooling buildInputs = with pkgs; [ rust-analyzer # LSP Server - rustfmt # Formatter - clippy # Linter + rustfmt # Formatter + clippy # Linter ]; -} \ No newline at end of file +} diff --git a/src/color/color.rs b/src/color/color.rs index 4988085..22cb4a6 100644 --- a/src/color/color.rs +++ b/src/color/color.rs @@ -1,8 +1,14 @@ use material_colors::{ - blend::harmonize, color::Argb, dynamic_color::{DynamicScheme, MaterialDynamicColors}, hct::Hct, image::{FilterType, ImageReader}, scheme::variant::{ + blend::harmonize, + color::Argb, + dynamic_color::{DynamicScheme, MaterialDynamicColors}, + hct::Hct, + image::{FilterType, ImageReader}, + scheme::variant::{ SchemeContent, SchemeExpressive, SchemeFidelity, SchemeFruitSalad, SchemeMonochrome, SchemeNeutral, SchemeRainbow, SchemeTonalSpot, - }, theme::{ColorGroup, CustomColor, CustomColorGroup} + }, + theme::{ColorGroup, CustomColor, CustomColorGroup}, }; use colorsys::{Hsl, Rgb}; @@ -66,15 +72,16 @@ pub fn get_source_color(source: &Source) -> Result { // test info!("Opening image in {}", path); - crate::color::color::get_source_color_from_image(path).expect("Could not get source color from image") + crate::color::color::get_source_color_from_image(path) + .expect("Could not get source color from image") } Source::WebImage { url } => { info!("Fetching image from {}", url); - crate::color::color::get_source_color_from_web_image(url).expect("Could not get source color from web image") - } - Source::Color(color) => { - crate::color::color::get_source_color_from_color(color).expect("Could not get source color from color") + crate::color::color::get_source_color_from_web_image(url) + .expect("Could not get source color from web image") } + Source::Color(color) => crate::color::color::get_source_color_from_color(color) + .expect("Could not get source color from color"), }; Ok(source_color) } @@ -89,14 +96,14 @@ pub fn get_source_color_from_image(path: &str) -> Result Result> { let bytes = reqwest::blocking::get(url)?.bytes()?; - Ok(ImageReader::extract_color(ImageReader::read(&bytes)?.resize( - 128, - 128, - FilterType::Lanczos3, - ))) + Ok(ImageReader::extract_color( + ImageReader::read(&bytes)?.resize(128, 128, FilterType::Lanczos3), + )) } -pub fn get_source_color_from_color(color: &ColorFormat) -> Result> { +pub fn get_source_color_from_color( + color: &ColorFormat, +) -> Result> { match color { ColorFormat::Hex { string } => { Ok(Argb::from_str(string).expect("Invalid hex color string provided")) @@ -169,8 +176,6 @@ pub fn make_custom_color( let light = generate_dynamic_scheme(scheme_type, value, false, contrast_level); let dark = generate_dynamic_scheme(scheme_type, value, true, contrast_level); - - // debug!("custom_color: {:#?}", &custom_color); CustomColorGroup { color, @@ -207,4 +212,4 @@ pub fn color_to_string(colors_to_compare: &Vec, compare_to: &st closest_distance, closest_color ); closest_color.to_string() -} \ No newline at end of file +} diff --git a/src/color/format.rs b/src/color/format.rs index 5aefb2a..84eef73 100644 --- a/src/color/format.rs +++ b/src/color/format.rs @@ -1,5 +1,5 @@ -use material_colors::color::Argb; use colorsys::{ColorAlpha, Hsl, Rgb}; +use material_colors::color::Argb; pub fn rgb_from_argb(color: Argb) -> Rgb { Rgb::from([ @@ -74,4 +74,4 @@ pub fn format_hsla(color: &Hsl, divide: bool) -> String { color.alpha() ) } -} \ No newline at end of file +} diff --git a/src/color/math.rs b/src/color/math.rs index 910908b..20832f7 100644 --- a/src/color/math.rs +++ b/src/color/math.rs @@ -1,6 +1,6 @@ +use colorsys::Rgb; use material_colors::color::{Argb, Lab}; use std::str::FromStr; -use colorsys::Rgb; pub fn get_color_distance_lab(c1: &str, c2: &str) -> f64 { let c1 = Lab::from(Argb::from_str(c1).unwrap()); @@ -25,5 +25,9 @@ pub fn get_color_distance(c1: &Rgb, c2: &Rgb) -> f64 { let weight_g: f64 = 4.0; let weight_b: f64 = 2.0 + (255.0 - rmean) / 256.0; - return f64::sqrt(weight_r * i64::pow(r1-r2, 2) as f64 + weight_g * i64::pow(g1-g2, 2) as f64 + weight_b * i64::pow(b1-b2, 2) as f64) -} \ No newline at end of file + return f64::sqrt( + weight_r * i64::pow(r1 - r2, 2) as f64 + + weight_g * i64::pow(g1 - g2, 2) as f64 + + weight_b * i64::pow(b1 - b2, 2) as f64, + ); +} diff --git a/src/color/mod.rs b/src/color/mod.rs index 47c6b4c..4a8f2fd 100644 --- a/src/color/mod.rs +++ b/src/color/mod.rs @@ -1,4 +1,4 @@ +pub mod color; pub mod format; pub mod math; -pub mod color; -pub mod parse; \ No newline at end of file +pub mod parse; diff --git a/src/color/parse.rs b/src/color/parse.rs index ec61641..59cbdad 100644 --- a/src/color/parse.rs +++ b/src/color/parse.rs @@ -21,4 +21,4 @@ pub fn check_string_value(value: &Value) -> Option<&String> { Value::String(v) => Some(v), _v => None, } -} \ No newline at end of file +} diff --git a/src/exec/command.rs b/src/exec/command.rs index e69de29..8b13789 100644 --- a/src/exec/command.rs +++ b/src/exec/command.rs @@ -0,0 +1 @@ + diff --git a/src/exec/hook.rs b/src/exec/hook.rs index a045764..78e3292 100644 --- a/src/exec/hook.rs +++ b/src/exec/hook.rs @@ -5,7 +5,6 @@ use upon::{Engine, Syntax, Template, Value}; use crate::color::color::color_to_string; - pub fn format_hook( engine: &Engine, render_data: &mut Value, @@ -13,17 +12,16 @@ pub fn format_hook( colors_to_compare: &Option>, compare_to: &Option, ) -> Result<(), Box> { - let closest_color: Option = - if colors_to_compare.is_some() && compare_to.is_some() { - let s = engine.compile(compare_to.as_ref().unwrap())?; - let compare_to = s.render(engine, &render_data).to_string()?; - Some(color_to_string( - colors_to_compare.as_ref().unwrap(), - &compare_to, - )) - } else { - None - }; + let closest_color: Option = if colors_to_compare.is_some() && compare_to.is_some() { + let s = engine.compile(compare_to.as_ref().unwrap())?; + let compare_to = s.render(engine, &render_data).to_string()?; + Some(color_to_string( + colors_to_compare.as_ref().unwrap(), + &compare_to, + )) + } else { + None + }; let t = engine.compile(hook)?; let res = if colors_to_compare.is_some() && compare_to.is_some() { diff --git a/src/exec/mod.rs b/src/exec/mod.rs index f48796c..6709139 100644 --- a/src/exec/mod.rs +++ b/src/exec/mod.rs @@ -1,2 +1,2 @@ +pub mod command; pub mod hook; -pub mod command; \ No newline at end of file diff --git a/src/filters/alpha.rs b/src/filters/alpha.rs index 2bee22b..9363968 100644 --- a/src/filters/alpha.rs +++ b/src/filters/alpha.rs @@ -4,8 +4,8 @@ use colorsys::{ColorAlpha, Hsl, Rgb}; use std::str::FromStr; use crate::color::{ - parse::{parse_color, check_string_value}, - format::{format_rgba, format_hsla}, + format::{format_hsla, format_rgba}, + parse::{check_string_value, parse_color}, }; pub fn set_alpha(value: &Value, amount: f64) -> Result { diff --git a/src/filters/grayscale.rs b/src/filters/grayscale.rs index cc4e212..116e915 100644 --- a/src/filters/grayscale.rs +++ b/src/filters/grayscale.rs @@ -4,8 +4,8 @@ use colorsys::{ColorTransform, Hsl, Rgb}; use std::str::FromStr; use crate::color::{ - parse::{parse_color, check_string_value}, - format::{format_hex, format_hex_stripped, format_rgb, format_rgba, format_hsl, format_hsla}, + format::{format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba}, + parse::{check_string_value, parse_color}, }; pub fn grayscale(value: &Value) -> Result { @@ -50,4 +50,4 @@ pub fn grayscale(value: &Value) -> Result { } v => Ok(v.to_string()), } -} \ No newline at end of file +} diff --git a/src/filters/hue.rs b/src/filters/hue.rs index 30de81a..955b446 100644 --- a/src/filters/hue.rs +++ b/src/filters/hue.rs @@ -4,8 +4,8 @@ use colorsys::{ColorTransform, Hsl, Rgb}; use std::str::FromStr; use crate::color::{ - parse::{parse_color, check_string_value}, - format::{format_hex, format_hex_stripped, format_rgb, format_rgba, format_hsl, format_hsla}, + format::{format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba}, + parse::{check_string_value, parse_color}, }; pub fn set_hue(value: &Value, amount: f64) -> Result { diff --git a/src/filters/invert.rs b/src/filters/invert.rs index 23b9eae..436f194 100644 --- a/src/filters/invert.rs +++ b/src/filters/invert.rs @@ -4,8 +4,8 @@ use colorsys::{ColorTransform, Hsl, Rgb}; use std::str::FromStr; use crate::color::{ - parse::{parse_color, check_string_value}, - format::{format_hex, format_hex_stripped, format_rgb, format_rgba, format_hsl, format_hsla}, + format::{format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba}, + parse::{check_string_value, parse_color}, }; pub fn invert(value: &Value) -> Result { @@ -50,4 +50,4 @@ pub fn invert(value: &Value) -> Result { } v => Ok(v.to_string()), } -} \ No newline at end of file +} diff --git a/src/filters/lightness.rs b/src/filters/lightness.rs index 1b32392..2fd8ffd 100644 --- a/src/filters/lightness.rs +++ b/src/filters/lightness.rs @@ -1,11 +1,11 @@ use upon::Value; -use colorsys::{Hsl, Rgb, ColorTransform}; +use colorsys::{ColorTransform, Hsl, Rgb}; use std::str::FromStr; use crate::color::{ - parse::{parse_color, check_string_value}, - format::{format_hex, format_hex_stripped, format_rgb, format_rgba, format_hsl, format_hsla}, + format::{format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba}, + parse::{check_string_value, parse_color}, }; pub fn set_lightness(value: &Value, amount: f64) -> Result { @@ -52,4 +52,4 @@ pub fn set_lightness(value: &Value, amount: f64) -> Result { } v => Ok(v.to_string()), } -} \ No newline at end of file +} diff --git a/src/filters/mod.rs b/src/filters/mod.rs index 9d3beb2..f43bcaf 100644 --- a/src/filters/mod.rs +++ b/src/filters/mod.rs @@ -1,5 +1,5 @@ -pub mod lightness; pub mod alpha; -pub mod hue; pub mod grayscale; -pub mod invert; \ No newline at end of file +pub mod hue; +pub mod invert; +pub mod lightness; diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs index aec0480..5453ae6 100644 --- a/src/scheme/mod.rs +++ b/src/scheme/mod.rs @@ -1 +1 @@ -pub mod scheme; \ No newline at end of file +pub mod scheme; diff --git a/src/scheme/scheme.rs b/src/scheme/scheme.rs index ed72a9f..9a9a4ff 100644 --- a/src/scheme/scheme.rs +++ b/src/scheme/scheme.rs @@ -22,13 +22,31 @@ pub struct Schemes { pub dark: IndexMap, } -#[derive(serde::Serialize, serde::Deserialize, Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)] +#[derive( + serde::Serialize, + serde::Deserialize, + Debug, + Copy, + Clone, + PartialEq, + Eq, + PartialOrd, + Ord, + clap::ValueEnum, +)] pub enum SchemesEnum { Light, Dark, } -pub fn get_custom_color_schemes(source_color: material_colors::color::Argb, scheme_dark: Scheme, scheme_light: Scheme, custom_colors: &Option>, scheme_type: &Option, contrast: &Option) -> Schemes { +pub fn get_custom_color_schemes( + source_color: material_colors::color::Argb, + scheme_dark: Scheme, + scheme_light: Scheme, + custom_colors: &Option>, + scheme_type: &Option, + contrast: &Option, +) -> Schemes { macro_rules! from_color { ($color: expr, $variant: ident) => { [ @@ -50,7 +68,7 @@ pub fn get_custom_color_schemes(source_color: material_colors::color::Argb, sche ] }; } - + let empty = HashMap::new(); let custom_colors = custom_colors .as_ref() @@ -58,8 +76,9 @@ pub fn get_custom_color_schemes(source_color: material_colors::color::Argb, sche .iter() .map(|(name, color)| { make_custom_color( - color.to_custom_color(name.to_string()).unwrap_or_else(|_| panic!("Failed to parse custom color: {}, {:?}", - name, color)), + color.to_custom_color(name.to_string()).unwrap_or_else(|_| { + panic!("Failed to parse custom color: {}, {:?}", name, color) + }), &scheme_type, source_color, *contrast, @@ -75,9 +94,12 @@ pub fn get_custom_color_schemes(source_color: material_colors::color::Argb, sche }; schemes } - -pub fn get_schemes(source_color: material_colors::color::Argb, scheme_type: &Option - , contrast: &Option) -> (Scheme, Scheme) { + +pub fn get_schemes( + source_color: material_colors::color::Argb, + scheme_type: &Option, + contrast: &Option, +) -> (Scheme, Scheme) { let scheme_dark = Scheme::from(generate_dynamic_scheme( &scheme_type, source_color, @@ -91,4 +113,4 @@ pub fn get_schemes(source_color: material_colors::color::Argb, scheme_type: &Opt *contrast, )); (scheme_dark, scheme_light) -} \ No newline at end of file +} diff --git a/src/util/config.rs b/src/util/config.rs index 92c3486..82d2602 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -1,7 +1,7 @@ use directories::ProjectDirs; +use std::collections::HashMap; use std::fs; use std::path::PathBuf; -use std::{collections::HashMap}; use color_eyre::{Help, Report}; From b168f8a1c5100b6e6d54372d18cc124ff945db8e Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 17 Aug 2024 21:22:51 +0200 Subject: [PATCH 28/59] fix: removed unused dependency --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index aeada78..de9d40a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,5 +46,4 @@ serde = { version = "1.0.160", features = ["derive"] } serde_json = "1.0.107" toml = "0.8.8" material-colors = { version = "0.4.0", features = ["image"] } -regex = "1.10.5" execute = "0.2.13" From f2ed19c0fec38bf6466cb80dc96e1ddfb2d3b52b Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 17 Aug 2024 21:53:37 +0200 Subject: [PATCH 29/59] chore: removed dependency proper-path-tools --- Cargo.lock | 206 +------------------------------------------ Cargo.toml | 1 - src/util/template.rs | 35 +++++--- 3 files changed, 25 insertions(+), 217 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76ce943..ec41859 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -258,12 +258,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "cfg_aliases" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" - [[package]] name = "clap" version = "4.4.11" @@ -304,30 +298,6 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" -[[package]] -name = "clone_dyn" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31adddd0b3cd1c78af1d6453f6692b499d3e69b8a5ed700216e2e8d6d3884dac" -dependencies = [ - "clone_dyn_meta", -] - -[[package]] -name = "clone_dyn_meta" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53eb47fea25038f358707de269cc6f4d94ca9cc8d24743a6d6db221fe627b02d" -dependencies = [ - "macro_tools", -] - -[[package]] -name = "collection_tools" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f130b4ae48eeff4c38ea3f5e43112bc86207a20ac82831b9d105892a6985e597" - [[package]] name = "color-eyre" version = "0.6.2" @@ -359,35 +329,6 @@ version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "54261aba646433cb567ec89844be4c4825ca92a4f8afba52fc4dd88436e31bbd" -[[package]] -name = "const_format" -version = "0.2.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" -dependencies = [ - "const_format_proc_macros", -] - -[[package]] -name = "const_format_proc_macros" -version = "0.2.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "convert_case" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "core-foundation" version = "0.9.4" @@ -471,53 +412,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "derive_more" -version = "1.0.0-beta.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7abbfc297053be59290e3152f8cbcd52c8642e0728b69ee187d991d4c1af08d" -dependencies = [ - "derive_more-impl", -] - -[[package]] -name = "derive_more-impl" -version = "1.0.0-beta.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bba3e9872d7c58ce7ef0fcf1844fcc3e23ef2a58377b50df35dd98e42a5726e" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "syn", - "unicode-xid", -] - -[[package]] -name = "derive_tools" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca02b7497f33afce052e0f74e5c16602d850996939dcdbde70f9544033eddf5" -dependencies = [ - "cfg_aliases", - "clone_dyn", - "derive_more", - "derive_tools_meta", - "variadic_from", -] - -[[package]] -name = "derive_tools_meta" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62df3ce52d0bc5e03122e0599f1acc3b0d04f4a5d86e088fbd719c9b2b62dba7" -dependencies = [ - "const_format", - "former_types", - "iter_tools", - "macro_tools", -] - [[package]] name = "directories" version = "5.0.1" @@ -745,15 +639,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "former_types" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60829d710f5f502433b919b1c6835b930b63f108e70e424ca28375dbfd0be632" -dependencies = [ - "collection_tools", -] - [[package]] name = "futures-channel" version = "0.3.30" @@ -1062,12 +947,6 @@ dependencies = [ "syn", ] -[[package]] -name = "interval_adapter" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f677a6e690ab1a2d101e86a1c0667160301de89f1c57fc9e5319e98ffab1607" - [[package]] name = "ipnet" version = "2.9.0" @@ -1085,24 +964,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "iter_tools" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55f9f40b3308a2367d5201430790786748b3e038982317dd880677c0f7b3f3f0" -dependencies = [ - "itertools 0.11.0", -] - -[[package]] -name = "itertools" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.12.1" @@ -1216,19 +1077,6 @@ dependencies = [ "imgref", ] -[[package]] -name = "macro_tools" -version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17c63898fb6bbcc299df7198f201be0acedf9d69220a771519bf34a2a6f2f19d" -dependencies = [ - "former_types", - "interval_adapter", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "material-colors" version = "0.4.0" @@ -1260,8 +1108,6 @@ dependencies = [ "paris-log", "pretty_env_logger", "prettytable-rs", - "proper_path_tools", - "regex", "reqwest", "resolve-path", "serde", @@ -1321,25 +1167,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "mod_interface" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "026eac6f9ed87963c4c453beea73feb31ed1958748235668f963e3363c2f2bc2" -dependencies = [ - "mod_interface_meta", -] - -[[package]] -name = "mod_interface_meta" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6834898a60fc29dfe779998c426c3f92f9a7d9a5a09e3b23c147c051c5cbf0b4" -dependencies = [ - "derive_tools", - "macro_tools", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" @@ -1575,16 +1402,6 @@ dependencies = [ "syn", ] -[[package]] -name = "proper_path_tools" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7750173988f68266f75ac986f03f055e465e0ba62018a060a8943160de70b85a" -dependencies = [ - "mod_interface", - "regex", -] - [[package]] name = "qoi" version = "0.4.1" @@ -1653,7 +1470,7 @@ dependencies = [ "built", "cfg-if", "interpolate_name", - "itertools 0.12.1", + "itertools", "libc", "libfuzzer-sys", "log", @@ -2270,24 +2087,12 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" - [[package]] name = "unicode-width" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - [[package]] name = "untrusted" version = "0.9.0" @@ -2365,15 +2170,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "variadic_from" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a6960d82a75f824807869e442064915a0df47fb891db5e51bf9da8fc54ca552" -dependencies = [ - "derive_tools_meta", -] - [[package]] name = "version-compare" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index de9d40a..a0c22d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,6 @@ colorsys = "0.6.7" resolve-path = "0.1.0" directories = "5.0" -proper_path_tools = "0.7.0" ahash = "0.8.7" indexmap = "2.2.2" diff --git a/src/util/template.rs b/src/util/template.rs index 32481e0..331ba94 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -8,13 +8,12 @@ use material_colors::color::Argb; use matugen::filters::grayscale::grayscale; use matugen::filters::hue::set_hue; use matugen::filters::invert::invert; -use proper_path_tools::path::rebase; use serde::{Deserialize, Serialize}; use upon::Value; -use matugen::filters::{alpha::set_alpha, lightness::set_lightness}; use matugen::exec::hook::format_hook; +use matugen::filters::{alpha::set_alpha, lightness::set_lightness}; use std::path::Path; use std::str; @@ -137,7 +136,8 @@ impl Template { }; for (i, (name, template)) in templates.iter().enumerate() { - let (input_path_absolute, output_path_absolute) = get_absolute_paths(&config_path, template)?; + let (input_path_absolute, output_path_absolute) = + get_absolute_paths(&config_path, template)?; if template.pre_hook.is_some() { format_hook( @@ -145,8 +145,9 @@ impl Template { &mut render_data, template.pre_hook.as_ref().unwrap(), &template.colors_to_compare, - &template.compare_to - ).unwrap(); + &template.compare_to, + ) + .unwrap(); } if !input_path_absolute.exists() { @@ -191,8 +192,9 @@ impl Template { &mut render_data, template.post_hook.as_ref().unwrap(), &template.colors_to_compare, - &template.compare_to - ).unwrap(); + &template.compare_to, + ) + .unwrap(); } } Ok(()) @@ -216,7 +218,10 @@ fn create_missing_folders(output_path_absolute: &PathBuf) -> Result<(), Report> }) } -fn get_absolute_paths(config_path: &Option, template: &Template) -> Result<(PathBuf, PathBuf), Report> { +fn get_absolute_paths( + config_path: &Option, + template: &Template, +) -> Result<(PathBuf, PathBuf), Report> { let (input_path_absolute, output_path_absolute) = if config_path.is_some() { let base = std::fs::canonicalize(config_path.as_ref().unwrap())?; ( @@ -266,8 +271,16 @@ fn export_template( })?; let out = if path_prefix.is_some() && !cfg!(windows) { - let prefix_path = PathBuf::from(path_prefix.as_ref().unwrap()); - rebase(&output_path_absolute, &prefix_path, None).expect("failed to rebase output path") + let mut prefix_path = PathBuf::from(path_prefix.as_ref().unwrap()); + + // remove the root from the output_path so that we can push it onto the prefix + let output_path = output_path_absolute + .strip_prefix("/") + .expect("output_path_absolute is not an absolute path."); + + prefix_path.push(&output_path); + + prefix_path } else { output_path_absolute.to_path_buf() }; @@ -296,7 +309,7 @@ fn export_template( name, output_path_absolute.display() ); - + Ok(()) } From 56b19d2de1384aeac24ae1f6c57312cc2d915213 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 17 Aug 2024 21:57:21 +0200 Subject: [PATCH 30/59] fix: removed deprecated default_features --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a0c22d2..51f2971 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ paris-log = { version = "1.0.2", features = ["icons"] } log = "0.4.17" prettytable-rs = "0.10.0" update-informer = "1.1.0" -reqwest = { version = "0.11.23", default_features = false, features = [ +reqwest = { version = "0.11.23", default-features = false, features = [ "blocking", "rustls-tls", ] } From 929db5ca8e7333106526600282aea9ad60a35051 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 17 Aug 2024 22:00:10 +0200 Subject: [PATCH 31/59] chore: cargo update --- Cargo.lock | 763 ++++++++++++++++++++++++++++------------------------- 1 file changed, 403 insertions(+), 360 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec41859..3a1e8f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,9 +32,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -47,47 +47,48 @@ checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" [[package]] name = "anstream" -version = "0.6.5" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.4" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", "windows-sys 0.52.0", @@ -95,9 +96,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.82" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "arbitrary" @@ -118,15 +119,15 @@ dependencies = [ [[package]] name = "arrayvec" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "av1-grain" @@ -153,9 +154,9 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.69" +version = "0.3.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" dependencies = [ "addr2line", "cc", @@ -168,9 +169,15 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bit_field" @@ -186,33 +193,33 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitstream-io" -version = "2.2.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06c9989a51171e2e81038ab168b6ae22886fe9ded214430dbb4f41c28cf176da" +checksum = "3dcde5f311c85b8ca30c2e4198d4326bc342c76541590106f5fa4a50946ea499" [[package]] name = "built" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41bfbdb21256b87a8b5e80fab81a8eed158178e812fd7ba451907518b2742f16" +checksum = "236e6289eda5a812bc6b53c3b024039382a2895fbbeef2d748b2931546d392c4" [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.14.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" +checksum = "6fd4c6dcc3b0aea2f5c0b4b82c2b15fe39ddbc76041a310848f4706edf76bb31" [[package]] name = "byteorder" @@ -228,18 +235,19 @@ checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495" [[package]] name = "bytes" -version = "1.5.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" [[package]] name = "cc" -version = "1.0.83" +version = "1.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "72db2f7947ecee9b03b510377e8bb9077afa27176fdbff55c51027e976fdcc48" dependencies = [ "jobserver", "libc", + "shlex", ] [[package]] @@ -260,9 +268,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.4.11" +version = "4.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2" +checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019" dependencies = [ "clap_builder", "clap_derive", @@ -270,9 +278,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.11" +version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb" +checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" dependencies = [ "anstream", "anstyle", @@ -282,11 +290,11 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.7" +version = "4.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "syn", @@ -294,15 +302,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.6.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "color-eyre" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +checksum = "55146f5e46f237f7423d74111267d4597b59b0dad0ffaf7303bce9945d843ad5" dependencies = [ "backtrace", "eyre", @@ -319,9 +327,9 @@ checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" [[package]] name = "colorsys" @@ -341,49 +349,43 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] [[package]] name = "crossbeam-deque" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.17" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.18" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" -dependencies = [ - "cfg-if", -] +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crunchy" @@ -476,9 +478,9 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "encode_unicode" @@ -488,9 +490,9 @@ checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" [[package]] name = "encoding_rs" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ "cfg-if", ] @@ -506,9 +508,9 @@ dependencies = [ [[package]] name = "env_logger" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" dependencies = [ "humantime", "is-terminal", @@ -523,16 +525,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "errno" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "execute" version = "0.2.13" @@ -572,9 +564,9 @@ checksum = "69dc321eb6be977f44674620ca3aa21703cb20ffbe560e1ae97da08401ffbcad" [[package]] name = "exr" -version = "1.71.0" +version = "1.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "832a761f35ab3e6664babfbdc6cef35a4860e816ec3916dcfd0882954e98a8a8" +checksum = "887d93f60543e9a9362ef8a21beedd0a833c5d9610e18c67abe15a5963dcb1a4" dependencies = [ "bit_field", "flume", @@ -588,9 +580,9 @@ dependencies = [ [[package]] name = "eyre" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6267a1fa6f59179ea4afc8e50fd8612a3cc60bc858f786ff877a4a8cb042799" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" dependencies = [ "indenter", "once_cell", @@ -598,18 +590,18 @@ dependencies = [ [[package]] name = "fdeflate" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64d6dafc854908ff5da46ff3f8f473c6984119a2876a383a860246dd7841a868" +checksum = "4f9bfee30e4dedf0ab8b422f03af778d9612b63f502710fc500a334ebe2de645" dependencies = [ "simd-adler32", ] [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "7f211bbe8e69bbd0cfdea405084f128ae8b4aaa6b0b522fc8f2b009084797920" dependencies = [ "crc32fast", "miniz_oxide", @@ -689,18 +681,18 @@ dependencies = [ [[package]] name = "generic-array" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe739944a5406424e080edccb6add95685130b9f160d5407c639c7df0c5836b0" +checksum = "96512db27971c2c3eece70a1e106fbe6c87760234e31e8f7e5634912fe52794a" dependencies = [ "typenum", ] [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -725,9 +717,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" -version = "0.3.22" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" dependencies = [ "bytes", "fnv", @@ -744,42 +736,43 @@ dependencies = [ [[package]] name = "half" -version = "2.2.1" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" dependencies = [ + "cfg-if", "crunchy", ] [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] -name = "heck" -version = "0.5.0" +name = "hermit-abi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" [[package]] name = "http" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes", "fnv", @@ -799,9 +792,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" [[package]] name = "httpdate" @@ -817,9 +810,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.28" +version = "0.14.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +checksum = "a152ddd61dfaec7273fe8419ab357f33aee0d914c5f4efbf0d96fa749eea5ec9" dependencies = [ "bytes", "futures-channel", @@ -848,7 +841,7 @@ dependencies = [ "futures-util", "http", "hyper", - "rustls", + "rustls 0.21.12", "tokio", "tokio-rustls", ] @@ -906,12 +899,12 @@ dependencies = [ [[package]] name = "image-webp" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d730b085583c4d789dfd07fdcf185be59501666a90c97c40162b37e4fdad272d" +checksum = "f79afb8cbee2ef20f59ccd477a218c12a93943d075b492015ecb1bb81f8ee904" dependencies = [ "byteorder-lite", - "thiserror", + "quick-error", ] [[package]] @@ -928,9 +921,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "2.2.6" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" dependencies = [ "equivalent", "hashbrown", @@ -955,15 +948,21 @@ checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "is-terminal" -version = "0.4.9" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" dependencies = [ - "hermit-abi", - "rustix", - "windows-sys 0.48.0", + "hermit-abi 0.4.0", + "libc", + "windows-sys 0.52.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.12.1" @@ -975,42 +974,42 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" +checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" dependencies = [ "libc", ] [[package]] name = "jpeg-decoder" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" +checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" dependencies = [ "rayon", ] [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" dependencies = [ "wasm-bindgen", ] [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lebe" @@ -1020,9 +1019,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.151" +version = "0.2.156" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a" [[package]] name = "libfuzzer-sys" @@ -1037,26 +1036,19 @@ dependencies = [ [[package]] name = "libredox" -version = "0.0.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.4.1", + "bitflags 2.6.0", "libc", - "redox_syscall", ] -[[package]] -name = "linux-raw-sys" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" - [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1064,9 +1056,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "loop9" @@ -1079,9 +1071,9 @@ dependencies = [ [[package]] name = "material-colors" -version = "0.4.0" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5353fb14a2b40a703a5e2dd855ca0ec7f488a79c9c965ee28d861bb7c05c06b7" +checksum = "e226ffda362d5bc26bb8f730d637a0851eedfb05e35d92108c9d8b48d2e47941" dependencies = [ "ahash", "image 0.25.2", @@ -1125,14 +1117,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea1f30cedd69f0a2954655f7188c6a834246d2bcf1e315e2ac40c4b24dc9519" dependencies = [ "cfg-if", - "rayon", ] [[package]] name = "memchr" -version = "2.6.4" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -1148,9 +1139,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.1" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" dependencies = [ "adler", "simd-adler32", @@ -1158,13 +1149,14 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.10" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi 0.3.9", "libc", "wasi", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1191,11 +1183,10 @@ checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8" [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", ] @@ -1213,21 +1204,19 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-rational" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", "num-bigint", "num-integer", "num-traits", @@ -1235,23 +1224,13 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" version = "0.32.2" @@ -1303,9 +1282,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "percent-encoding" @@ -1315,9 +1294,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -1333,9 +1312,9 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "png" -version = "0.17.10" +version = "0.17.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd75bf2d8dd3702b9707cdbc56a5b9ef42cec752eb8b3bafc01234558442aa64" +checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1" dependencies = [ "bitflags 1.3.2", "crc32fast", @@ -1346,9 +1325,12 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] [[package]] name = "pretty_env_logger" @@ -1376,9 +1358,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -1493,24 +1475,23 @@ dependencies = [ [[package]] name = "ravif" -version = "0.11.5" +version = "0.11.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc13288f5ab39e6d7c9d501759712e6969fcc9734220846fc9ed26cae2cc4234" +checksum = "a8f0bfd976333248de2078d350bfdf182ff96e168a24d23d2436cef320dd4bdd" dependencies = [ "avif-serialize", "imgref", "loop9", "quick-error", "rav1e", - "rayon", "rgb", ] [[package]] name = "rayon" -version = "1.8.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -1518,28 +1499,19 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ "crossbeam-deque", "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_users" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ "getrandom", "libredox", @@ -1548,9 +1520,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -1571,17 +1543,17 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" [[package]] name = "reqwest" -version = "0.11.23" +version = "0.11.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" dependencies = [ - "base64", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -1598,11 +1570,12 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls", + "rustls 0.21.12", "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", + "sync_wrapper", "system-configuration", "tokio", "tokio-rustls", @@ -1611,7 +1584,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "webpki-roots", + "webpki-roots 0.25.4", "winreg", ] @@ -1626,56 +1599,59 @@ dependencies = [ [[package]] name = "rgb" -version = "0.8.37" +version = "0.8.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05aaa8004b64fd573fc9d002f4e632d51ad4f026c2b5ba95fcb6c2f32c2c47d8" +checksum = "0f86ae463694029097b846d8f99fd5536740602ae00022c0c50c5600720b2f71" dependencies = [ "bytemuck", ] [[package]] name = "ring" -version = "0.17.7" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", + "cfg-if", "getrandom", "libc", "spin", "untrusted", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] -name = "rustix" -version = "0.38.28" +name = "rustls" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ - "bitflags 2.4.1", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.52.0", + "log", + "ring", + "rustls-webpki 0.101.7", + "sct", ] [[package]] name = "rustls" -version = "0.21.10" +version = "0.23.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" dependencies = [ "log", + "once_cell", "ring", - "rustls-webpki", - "sct", + "rustls-pki-types", + "rustls-webpki 0.102.6", + "subtle", + "zeroize", ] [[package]] @@ -1684,9 +1660,15 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64", + "base64 0.21.7", ] +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + [[package]] name = "rustls-webpki" version = "0.101.7" @@ -1697,17 +1679,28 @@ dependencies = [ "untrusted", ] +[[package]] +name = "rustls-webpki" +version = "0.102.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e6b52d4fda176fd835fdc55a835d4a89b8499cad995885a21149d5ad62f852e" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "ryu" -version = "1.0.16" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scopeguard" @@ -1727,24 +1720,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.20" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.204" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.208" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" dependencies = [ "proc-macro2", "quote", @@ -1753,20 +1746,21 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.108" +version = "1.0.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +checksum = "83c8e735a073ccf5be70aa8066aa984eaf2fa000db6c8d0100ae605b366d31ed" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" dependencies = [ "serde", ] @@ -1783,6 +1777,12 @@ dependencies = [ "serde", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "simd-adler32" version = "0.3.7" @@ -1809,18 +1809,18 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.2" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1834,21 +1834,33 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.66" +version = "2.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + [[package]] name = "system-configuration" version = "0.5.1" @@ -1877,7 +1889,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" dependencies = [ "cfg-expr", - "heck 0.5.0", + "heck", "pkg-config", "toml", "version-compare", @@ -1885,9 +1897,9 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.14" +version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "term" @@ -1902,27 +1914,27 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "thiserror" -version = "1.0.51" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.51" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", @@ -1931,9 +1943,9 @@ dependencies = [ [[package]] name = "tiff" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d172b0f4d3fba17ba89811858b9d3d97f928aece846475bbda076ca46736211" +checksum = "ba1310fcea54c6a9a4fd1aad794ecc02c31682f6bfbecdf460bf19533eed1e3e" dependencies = [ "flate2", "jpeg-decoder", @@ -1942,9 +1954,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -1957,18 +1969,17 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.35.1" +version = "1.39.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104" +checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" dependencies = [ "backtrace", "bytes", "libc", "mio", - "num_cpus", "pin-project-lite", "socket2", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -1977,29 +1988,28 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls", + "rustls 0.21.12", "tokio", ] [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] name = "toml" -version = "0.8.8" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ "serde", "serde_spanned", @@ -2009,18 +2019,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.21.0" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ "indexmap", "serde", @@ -2031,9 +2041,9 @@ dependencies = [ [[package]] name = "tower-service" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" @@ -2068,9 +2078,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "unicode-bidi" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" @@ -2080,18 +2090,18 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "untrusted" @@ -2115,9 +2125,9 @@ dependencies = [ [[package]] name = "upon" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6539a8975f097abc4500a33d542ac5f2e11b8912d48c980ce585161eed1ec59a" +checksum = "9fe29601d1624f104fa9a35ea71a5f523dd8bd1cfc8c31f8124ad2b829f013c0" dependencies = [ "serde", "unicode-ident", @@ -2126,27 +2136,27 @@ dependencies = [ [[package]] name = "ureq" -version = "2.9.1" +version = "2.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8cdd25c339e200129fe4de81451814e5228c9b771d57378817d6117cc2b3f97" +checksum = "b74fc6b57825be3373f7054754755f03ac3a8f5d70015ccad699ba2029956f4a" dependencies = [ - "base64", + "base64 0.22.1", "flate2", "log", "once_cell", - "rustls", - "rustls-webpki", + "rustls 0.23.12", + "rustls-pki-types", "serde", "serde_json", "url", - "webpki-roots", + "webpki-roots 0.26.3", ] [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -2155,9 +2165,9 @@ dependencies = [ [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "v_frame" @@ -2178,9 +2188,9 @@ checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "want" @@ -2199,19 +2209,20 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" dependencies = [ "bumpalo", "log", @@ -2224,9 +2235,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.39" +version = "0.4.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +checksum = "61e9300f63a621e96ed275155c108eb6f843b6a26d053f122ab69724559dc8ed" dependencies = [ "cfg-if", "js-sys", @@ -2236,9 +2247,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2246,9 +2257,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" dependencies = [ "proc-macro2", "quote", @@ -2259,15 +2270,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" [[package]] name = "web-sys" -version = "0.3.66" +version = "0.3.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" +checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" dependencies = [ "js-sys", "wasm-bindgen", @@ -2275,9 +2286,18 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.25.3" +version = "0.25.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" + +[[package]] +name = "webpki-roots" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" +checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd" +dependencies = [ + "rustls-pki-types", +] [[package]] name = "weezl" @@ -2303,11 +2323,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "winapi", + "windows-sys 0.59.0", ] [[package]] @@ -2331,7 +2351,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -2351,17 +2380,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -2372,9 +2402,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -2384,9 +2414,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -2396,9 +2426,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.0" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -2408,9 +2444,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -2420,9 +2456,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -2432,9 +2468,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -2444,15 +2480,15 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.5.30" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] @@ -2469,24 +2505,31 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ + "byteorder", "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" + [[package]] name = "zune-core" version = "0.4.12" @@ -2504,9 +2547,9 @@ dependencies = [ [[package]] name = "zune-jpeg" -version = "0.4.11" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec866b44a2a1fd6133d363f073ca1b179f438f99e7e5bfb1e33f7181facfe448" +checksum = "16099418600b4d8f028622f73ff6e3deaabdff330fb9a2a131dea781ee8b0768" dependencies = [ "zune-core", ] From 793568e235333b7605416f0156dd297be667ea58 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 17 Aug 2024 22:53:47 +0200 Subject: [PATCH 32/59] fix: apply more aggressive clippy lints --- src/color/math.rs | 4 ++-- src/exec/hook.rs | 4 ++-- src/helpers.rs | 2 +- src/scheme/scheme.rs | 6 +++--- src/util/template.rs | 9 +++++---- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/color/math.rs b/src/color/math.rs index 20832f7..36fa76e 100644 --- a/src/color/math.rs +++ b/src/color/math.rs @@ -25,9 +25,9 @@ pub fn get_color_distance(c1: &Rgb, c2: &Rgb) -> f64 { let weight_g: f64 = 4.0; let weight_b: f64 = 2.0 + (255.0 - rmean) / 256.0; - return f64::sqrt( + f64::sqrt( weight_r * i64::pow(r1 - r2, 2) as f64 + weight_g * i64::pow(g1 - g2, 2) as f64 + weight_b * i64::pow(b1 - b2, 2) as f64, - ); + ) } diff --git a/src/exec/hook.rs b/src/exec/hook.rs index 78e3292..a9f6ee9 100644 --- a/src/exec/hook.rs +++ b/src/exec/hook.rs @@ -14,7 +14,7 @@ pub fn format_hook( ) -> Result<(), Box> { let closest_color: Option = if colors_to_compare.is_some() && compare_to.is_some() { let s = engine.compile(compare_to.as_ref().unwrap())?; - let compare_to = s.render(engine, &render_data).to_string()?; + let compare_to = s.render(engine, &*render_data).to_string()?; Some(color_to_string( colors_to_compare.as_ref().unwrap(), &compare_to, @@ -64,7 +64,7 @@ pub fn format_hook_text( } } - let data = template.render(&engine, &render_data).to_string().unwrap(); + let data = template.render(&engine, render_data).to_string().unwrap(); data } diff --git a/src/helpers.rs b/src/helpers.rs index bdeaaa1..047c893 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -37,7 +37,7 @@ pub fn check_version() { } pub fn setup_logging(args: &Cli) -> Result<(), Report> { - let log_level = get_log_level(&args); + let log_level = get_log_level(args); let mut logger = pretty_env_logger::env_logger::builder(); diff --git a/src/scheme/scheme.rs b/src/scheme/scheme.rs index 9a9a4ff..190641b 100644 --- a/src/scheme/scheme.rs +++ b/src/scheme/scheme.rs @@ -79,7 +79,7 @@ pub fn get_custom_color_schemes( color.to_custom_color(name.to_string()).unwrap_or_else(|_| { panic!("Failed to parse custom color: {}, {:?}", name, color) }), - &scheme_type, + scheme_type, source_color, *contrast, ) @@ -101,13 +101,13 @@ pub fn get_schemes( contrast: &Option, ) -> (Scheme, Scheme) { let scheme_dark = Scheme::from(generate_dynamic_scheme( - &scheme_type, + scheme_type, source_color, true, *contrast, )); let scheme_light = Scheme::from(generate_dynamic_scheme( - &scheme_type, + scheme_type, source_color, false, *contrast, diff --git a/src/util/template.rs b/src/util/template.rs index 331ba94..837779d 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -201,11 +201,11 @@ impl Template { } } -fn create_missing_folders(output_path_absolute: &PathBuf) -> Result<(), Report> { +fn create_missing_folders(output_path_absolute: &Path) -> Result<(), Report> { let parent_folder = &output_path_absolute .parent() .wrap_err("Could not get the parent of the output path.")?; - Ok(if !parent_folder.exists() { + if !parent_folder.exists() { error!( "The {} folder doesnt exist, trying to create...", &parent_folder.display() @@ -215,7 +215,8 @@ fn create_missing_folders(output_path_absolute: &PathBuf) -> Result<(), Report> "Failed to create the {} folders.", &output_path_absolute.display() )); - }) + }; + Ok(()) } fn get_absolute_paths( @@ -278,7 +279,7 @@ fn export_template( .strip_prefix("/") .expect("output_path_absolute is not an absolute path."); - prefix_path.push(&output_path); + prefix_path.push(output_path); prefix_path } else { From 76ead5f2fdc86899eab10c1dc43f0ee9c557ed90 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 17 Aug 2024 22:55:41 +0200 Subject: [PATCH 33/59] chore: moved scheme out of module with only 1 file --- src/color/color.rs | 2 +- src/main.rs | 4 ++-- src/{scheme => }/scheme.rs | 0 src/scheme/mod.rs | 1 - src/util/arguments.rs | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) rename src/{scheme => }/scheme.rs (100%) delete mode 100644 src/scheme/mod.rs diff --git a/src/color/color.rs b/src/color/color.rs index 22cb4a6..c0cd6a3 100644 --- a/src/color/color.rs +++ b/src/color/color.rs @@ -14,7 +14,7 @@ use material_colors::{ use colorsys::{Hsl, Rgb}; use std::str::FromStr; -use crate::{color::math::get_color_distance_lab, scheme::scheme::SchemeTypes}; +use crate::{color::math::get_color_distance_lab, scheme::SchemeTypes}; #[derive(clap::Parser, Debug)] pub enum ColorFormat { diff --git a/src/main.rs b/src/main.rs index fa01c06..aa12189 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ mod wallpaper; use helpers::{check_version, set_wallpaper, setup_logging}; use matugen::{ color::color::get_source_color, - scheme::scheme::{get_custom_color_schemes, get_schemes}, + scheme::{get_custom_color_schemes, get_schemes}, }; use crate::util::{ @@ -25,7 +25,7 @@ use crate::util::{ use clap::Parser; use color_eyre::{eyre::Result, Report}; -use matugen::scheme::scheme::{Schemes, SchemesEnum}; +use matugen::scheme::{Schemes, SchemesEnum}; fn main() -> Result<(), Report> { color_eyre::install()?; diff --git a/src/scheme/scheme.rs b/src/scheme.rs similarity index 100% rename from src/scheme/scheme.rs rename to src/scheme.rs diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs deleted file mode 100644 index 5453ae6..0000000 --- a/src/scheme/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod scheme; diff --git a/src/util/arguments.rs b/src/util/arguments.rs index 3c227ab..27ab115 100644 --- a/src/util/arguments.rs +++ b/src/util/arguments.rs @@ -19,7 +19,7 @@ pub struct Cli { global = true, default_value = "scheme-tonal-spot" )] - pub r#type: Option, + pub r#type: Option, /// Sets a custom config file #[arg(short, long, value_name = "FILE", global = true)] From ef437e30e63315c9bccac0c0bcd25248e49cbe83 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sun, 18 Aug 2024 00:37:28 +0200 Subject: [PATCH 34/59] feat: feature-gated update-informer --- Cargo.toml | 5 ++++- src/helpers.rs | 6 +++--- src/main.rs | 4 +++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 51f2971..55b2e92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,9 @@ edition = "2021" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["winuser"] } +[features] +update-informer = ["dep:update-informer"] + [dependencies] # This is here because of #43 enquote = "1.1.0" @@ -23,7 +26,7 @@ pretty_env_logger = "0.5.0" paris-log = { version = "1.0.2", features = ["icons"] } log = "0.4.17" prettytable-rs = "0.10.0" -update-informer = "1.1.0" +update-informer = { version = "1.1.0", optional = true } reqwest = { version = "0.11.23", default-features = false, features = [ "blocking", "rustls-tls", diff --git a/src/helpers.rs b/src/helpers.rs index 047c893..84d9c54 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -3,7 +3,6 @@ use color_eyre::{eyre::Result, Report}; use log::LevelFilter; use matugen::color::color::Source; use std::io::Write; -use update_informer::{registry, Check}; use crate::util::arguments::Cli; @@ -20,11 +19,12 @@ pub fn get_log_level(args: &Cli) -> LevelFilter { log_level } +#[cfg(feature = "update-informer")] pub fn check_version() { + use update_informer::{registry, Check}; + let name = env!("CARGO_PKG_NAME"); let current_version = env!("CARGO_PKG_VERSION"); - // for testing - // let current_version = "2.2.0"; let informer = update_informer::new(registry::Crates, name, current_version); diff --git a/src/main.rs b/src/main.rs index aa12189..76d0dc6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ mod reload; mod util; mod wallpaper; -use helpers::{check_version, set_wallpaper, setup_logging}; +use helpers::{set_wallpaper, setup_logging}; use matugen::{ color::color::get_source_color, scheme::{get_custom_color_schemes, get_schemes}, @@ -35,7 +35,9 @@ fn main() -> Result<(), Report> { let (config, config_path) = ConfigFile::read(&args)?; + #[cfg(feature = "update-informer")] if config.config.version_check == Some(true) { + use crate::helpers::check_version; check_version(); } From c4aa1847b7a2f9e40e64d4e28b20ab74993c2911 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sun, 18 Aug 2024 17:15:10 +0200 Subject: [PATCH 35/59] feat: feature-gated dumping json --- Cargo.toml | 3 ++- src/main.rs | 9 +++------ src/util/arguments.rs | 10 ++-------- src/util/color.rs | 10 +++++++--- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 55b2e92..a8a7e49 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ winapi = { version = "0.3", features = ["winuser"] } [features] update-informer = ["dep:update-informer"] +dump-json = ["dep:serde_json"] [dependencies] # This is here because of #43 @@ -45,7 +46,7 @@ image = "0.24.7" upon = "0.8.0" clap = { version = "4.2.4", features = ["derive"] } serde = { version = "1.0.160", features = ["derive"] } -serde_json = "1.0.107" +serde_json = { version = "1.0.107", optional = true } toml = "0.8.8" material-colors = { version = "0.4.0", features = ["image"] } execute = "0.2.13" diff --git a/src/main.rs b/src/main.rs index 76d0dc6..6b72452 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,12 +15,7 @@ use matugen::{ scheme::{get_custom_color_schemes, get_schemes}, }; -use crate::util::{ - arguments::Cli, - color::{dump_json, show_color}, - config::ConfigFile, - template::Template, -}; +use crate::util::{arguments::Cli, color::show_color, config::ConfigFile, template::Template}; use clap::Parser; use color_eyre::{eyre::Result, Report}; @@ -62,7 +57,9 @@ fn main() -> Result<(), Report> { show_color(&schemes, &source_color); } + #[cfg(feature = "dump-json")] if let Some(ref format) = args.json { + use crate::util::color::dump_json; dump_json(&schemes, &source_color, format); } diff --git a/src/util/arguments.rs b/src/util/arguments.rs index 27ab115..5a78d5a 100644 --- a/src/util/arguments.rs +++ b/src/util/arguments.rs @@ -64,15 +64,9 @@ pub struct Cli { #[arg(long, global = true, action=ArgAction::SetTrue, default_value = "false")] pub show_colors: Option, + #[cfg(feature = "dump-json")] /// Whether to dump json of colors - #[arg( - value_enum, - short, - long, - global = true, - value_name = "JSON", - default_value = None, - )] + #[arg(value_enum, short, long, global = true, value_name = "JSON")] pub json: Option, } diff --git a/src/util/color.rs b/src/util/color.rs index bfc5b1f..5cccace 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -5,11 +5,10 @@ use prettytable::{format, Cell, Row, Table}; use crate::Schemes; +#[cfg(feature = "dump-json")] use super::arguments::Format; -use colorsys::{ColorAlpha, Hsl, Rgb}; -use serde_json::json; -use std::collections::HashMap; +use colorsys::Rgb; use matugen::color::format::rgb_from_argb; pub fn show_color(schemes: &Schemes, source_color: &Argb) { @@ -32,7 +31,12 @@ pub fn show_color(schemes: &Schemes, source_color: &Argb) { table.printstd(); } +#[cfg(feature = "dump-json")] pub fn dump_json(schemes: &Schemes, source_color: &Argb, format: &Format) { + use colorsys::{ColorAlpha, Hsl}; + use serde_json::json; + use std::collections::HashMap; + type F = Format; let fmt = match format { F::Rgb => |c: Rgb| format!("rgb({:?}, {:?}, {:?})", c.red(), c.green(), c.blue()), From 614557fd8c6a69af7f3d4fea78fdca77ba363c36 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sun, 18 Aug 2024 17:37:21 +0200 Subject: [PATCH 36/59] feat: feature-gated web-image --- Cargo.toml | 3 ++- src/color/color.rs | 16 +++++++++++----- src/helpers.rs | 1 + src/util/template.rs | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a8a7e49..250d0ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ winapi = { version = "0.3", features = ["winuser"] } [features] update-informer = ["dep:update-informer"] +web-image = ["dep:reqwest"] dump-json = ["dep:serde_json"] [dependencies] @@ -31,7 +32,7 @@ update-informer = { version = "1.1.0", optional = true } reqwest = { version = "0.11.23", default-features = false, features = [ "blocking", "rustls-tls", -] } +], optional = true } owo-colors = "4.0.0" colorsys = "0.6.7" diff --git a/src/color/color.rs b/src/color/color.rs index c0cd6a3..b87ccfa 100644 --- a/src/color/color.rs +++ b/src/color/color.rs @@ -27,8 +27,11 @@ pub enum ColorFormat { pub enum Source { /// The image to use for generating a color scheme Image { path: String }, + + #[cfg(feature = "web-image")] /// The image to fetch from web and use for generating a color scheme WebImage { url: String }, + /// The source color to use for generating a color scheme #[clap(subcommand)] Color(crate::color::color::ColorFormat), @@ -68,19 +71,21 @@ impl OwnCustomColor { } pub fn get_source_color(source: &Source) -> Result> { - let source_color: Argb = match &source { + use crate::color::color; + + let source_color: Argb = match source { Source::Image { path } => { // test info!("Opening image in {}", path); - crate::color::color::get_source_color_from_image(path) - .expect("Could not get source color from image") + color::get_source_color_from_image(path).expect("Could not get source color from image") } + #[cfg(feature = "web-image")] Source::WebImage { url } => { info!("Fetching image from {}", url); - crate::color::color::get_source_color_from_web_image(url) + color::get_source_color_from_web_image(url) .expect("Could not get source color from web image") } - Source::Color(color) => crate::color::color::get_source_color_from_color(color) + Source::Color(color) => color::get_source_color_from_color(color) .expect("Could not get source color from color"), }; Ok(source_color) @@ -94,6 +99,7 @@ pub fn get_source_color_from_image(path: &str) -> Result Result> { let bytes = reqwest::blocking::get(url)?.bytes()?; Ok(ImageReader::extract_color( diff --git a/src/helpers.rs b/src/helpers.rs index 84d9c54..4372abd 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -60,6 +60,7 @@ pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { let path = match &source { Source::Image { path } => path, Source::Color { .. } => return Ok(()), + #[cfg(feature = "web-image")] Source::WebImage { .. } => return Ok(()), }; #[cfg(any(target_os = "linux", target_os = "netbsd"))] diff --git a/src/util/template.rs b/src/util/template.rs index 837779d..94a5eb1 100644 --- a/src/util/template.rs +++ b/src/util/template.rs @@ -117,6 +117,7 @@ impl Template { let image = match &source { Source::Image { path } => Some(path), + #[cfg(feature = "web-image")] Source::WebImage { .. } => None, Source::Color { .. } => None, }; From 2f118fb93a388911c438c14613434fb6eea9b9ed Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sun, 18 Aug 2024 17:48:15 +0200 Subject: [PATCH 37/59] made enquote only required for builds targeting macOS --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 250d0ee..0d07dd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,15 +14,15 @@ edition = "2021" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["winuser"] } +[target.'cfg(target_os = "macos")'.dependencies] +enquote = "1.1.0" + [features] update-informer = ["dep:update-informer"] web-image = ["dep:reqwest"] dump-json = ["dep:serde_json"] [dependencies] -# This is here because of #43 -enquote = "1.1.0" - color-eyre = { version = "0.6.2", default-features = false } pretty_env_logger = "0.5.0" paris-log = { version = "1.0.2", features = ["icons"] } From df7e553f04c6e5a8e26536f0a4f209776392caaf Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sun, 18 Aug 2024 18:32:19 +0200 Subject: [PATCH 38/59] chore: removed unused dependency features --- Cargo.lock | 102 ----------------------------------------------------- Cargo.toml | 18 +++++----- 2 files changed, 9 insertions(+), 111 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3a1e8f4..817690c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,55 +45,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" -[[package]] -name = "anstream" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - [[package]] name = "anstyle" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" -[[package]] -name = "anstyle-parse" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - [[package]] name = "anyhow" version = "1.0.86" @@ -282,10 +239,8 @@ version = "4.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6" dependencies = [ - "anstream", "anstyle", "clap_lex", - "strsim", ] [[package]] @@ -325,12 +280,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" -[[package]] -name = "colorchoice" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" - [[package]] name = "colorsys" version = "0.6.7" @@ -393,27 +342,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "csv" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" -dependencies = [ - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" -dependencies = [ - "memchr", -] - [[package]] name = "directories" version = "5.0.1" @@ -865,13 +793,7 @@ dependencies = [ "bytemuck", "byteorder", "color_quant", - "exr", - "gif", - "jpeg-decoder", "num-traits", - "png", - "qoi", - "tiff", ] [[package]] @@ -957,12 +879,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - [[package]] name = "itertools" version = "0.12.1" @@ -992,9 +908,6 @@ name = "jpeg-decoder" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" -dependencies = [ - "rayon", -] [[package]] name = "js-sys" @@ -1348,7 +1261,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eea25e07510aa6ab6547308ebe3c036016d162b8da920dbb079e3ba8acf3d95a" dependencies = [ - "csv", "encode_unicode", "is-terminal", "lazy_static", @@ -1832,12 +1744,6 @@ dependencies = [ "lock_api", ] -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - [[package]] name = "subtle" version = "2.6.1" @@ -2130,8 +2036,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fe29601d1624f104fa9a35ea71a5f523dd8bd1cfc8c31f8124ad2b829f013c0" dependencies = [ "serde", - "unicode-ident", - "unicode-width", ] [[package]] @@ -2163,12 +2067,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "v_frame" version = "0.3.8" diff --git a/Cargo.toml b/Cargo.toml index 0d07dd9..2093f82 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ color-eyre = { version = "0.6.2", default-features = false } pretty_env_logger = "0.5.0" paris-log = { version = "1.0.2", features = ["icons"] } log = "0.4.17" -prettytable-rs = "0.10.0" +prettytable-rs = { default-features = false, version = "0.10.0" } update-informer = { version = "1.1.0", optional = true } reqwest = { version = "0.11.23", default-features = false, features = [ "blocking", @@ -35,19 +35,19 @@ reqwest = { version = "0.11.23", default-features = false, features = [ ], optional = true } owo-colors = "4.0.0" -colorsys = "0.6.7" +colorsys = { default-features = false, version = "0.6.7" } resolve-path = "0.1.0" directories = "5.0" -ahash = "0.8.7" -indexmap = "2.2.2" +ahash = { default-features = false, version = "0.8.7" } +indexmap = { default-features = false, version = "2.2.2" } -image = "0.24.7" -upon = "0.8.0" -clap = { version = "4.2.4", features = ["derive"] } -serde = { version = "1.0.160", features = ["derive"] } +image = { default-features = false, version = "0.24.7" } +upon = { features = ["filters", "serde"], default-features = false, version = "0.8.0" } +clap = { version = "4.2.4", features = ["derive", "std"], default-features = false } +serde = { version = "1.0.160", features = ["serde_derive", "std"], default-features = false } serde_json = { version = "1.0.107", optional = true } -toml = "0.8.8" +toml = { features = ["parse"], default-features = false, version = "0.8.8" } material-colors = { version = "0.4.0", features = ["image"] } execute = "0.2.13" From 4d2db69c8befa41fc29b6b352603d9ce6feb11c7 Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sun, 18 Aug 2024 18:41:59 +0200 Subject: [PATCH 39/59] chore: sorted dependencies --- Cargo.toml | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2093f82..cdfa99c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,31 +23,43 @@ web-image = ["dep:reqwest"] dump-json = ["dep:serde_json"] [dependencies] -color-eyre = { version = "0.6.2", default-features = false } -pretty_env_logger = "0.5.0" -paris-log = { version = "1.0.2", features = ["icons"] } +# logging log = "0.4.17" -prettytable-rs = { default-features = false, version = "0.10.0" } -update-informer = { version = "1.1.0", optional = true } -reqwest = { version = "0.11.23", default-features = false, features = [ - "blocking", - "rustls-tls", -], optional = true } +paris-log = { version = "1.0.2", features = ["icons"] } # TODO replace with using paris directly? +pretty_env_logger = "0.5.0" -owo-colors = "4.0.0" +# terminal output +prettytable-rs = { default-features = false, version = "0.10.0" } # TODO feature-gate? This should definitely be a default feature tho. +color-eyre = { version = "0.6.2", default-features = false } colorsys = { default-features = false, version = "0.6.7" } +owo-colors = "4.0.0" -resolve-path = "0.1.0" -directories = "5.0" - -ahash = { default-features = false, version = "0.8.7" } -indexmap = { default-features = false, version = "2.2.2" } - -image = { default-features = false, version = "0.24.7" } +# templating engine upon = { features = ["filters", "serde"], default-features = false, version = "0.8.0" } -clap = { version = "4.2.4", features = ["derive", "std"], default-features = false } + +# config serde = { version = "1.0.160", features = ["serde_derive", "std"], default-features = false } -serde_json = { version = "1.0.107", optional = true } toml = { features = ["parse"], default-features = false, version = "0.8.8" } + +clap = { version = "4.2.4", features = ["derive", "std"], default-features = false } material-colors = { version = "0.4.0", features = ["image"] } +image = { default-features = false, version = "0.24.7" } +directories = "5.0" + +# should probably be removed +indexmap = { default-features = false, version = "2.2.2" } # not sure yet +ahash = { default-features = false, version = "0.8.7" } +resolve-path = "0.1.0" execute = "0.2.13" + +# update-informer feature +update-informer = { version = "1.1.0", optional = true } + +# dump-json feature +serde_json = { version = "1.0.107", optional = true } + +# web-image feature +reqwest = { version = "0.11.23", default-features = false, features = [ + "blocking", + "rustls-tls", +], optional = true } From cd051ee0746f0eb49bf0441beceb92560364d10f Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sun, 18 Aug 2024 18:57:10 +0200 Subject: [PATCH 40/59] chore: update dependencies with breaking changes --- Cargo.lock | 326 +++++++++++++++++++++++++++++++++++++++++++++++------ Cargo.toml | 4 +- 2 files changed, 293 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 817690c..aeeaea7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -566,6 +566,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -600,6 +601,7 @@ checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", "futures-io", + "futures-sink", "futures-task", "memchr", "pin-project-lite", @@ -654,7 +656,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.12", "indexmap", "slab", "tokio", @@ -707,6 +709,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -714,7 +727,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", "pin-project-lite", ] @@ -747,8 +783,8 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", + "http 0.2.12", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -760,6 +796,25 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + [[package]] name = "hyper-rustls" version = "0.24.2" @@ -767,33 +822,59 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", - "hyper", + "http 0.2.12", + "hyper 0.14.30", "rustls 0.21.12", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", ] [[package]] -name = "idna" -version = "0.5.0" +name = "hyper-rustls" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "5ee4be2c948921a1a5320b629c4193916ed787a7f7f293fd3f7f5a6c9de74155" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "futures-util", + "http 1.1.0", + "hyper 1.4.1", + "hyper-util", + "rustls 0.23.12", + "rustls-pki-types", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", + "webpki-roots 0.26.3", ] [[package]] -name = "image" -version = "0.24.9" +name = "hyper-util" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" dependencies = [ - "bytemuck", - "byteorder", - "color_quant", - "num-traits", + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.4.1", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", ] [[package]] @@ -932,9 +1013,9 @@ checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8" [[package]] name = "libc" -version = "0.2.156" +version = "0.2.157" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5f43f184355eefb8d17fc948dbecf6c13be3c141f20d834ae842193a448c72a" +checksum = "374af5f94e54fa97cf75e945cce8a6b201e88a1a07e688b47dfd2a59c66dbd86" [[package]] name = "libfuzzer-sys" @@ -989,7 +1070,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e226ffda362d5bc26bb8f730d637a0851eedfb05e35d92108c9d8b48d2e47941" dependencies = [ "ahash", - "image 0.25.2", + "image", "indexmap", "serde", ] @@ -1005,7 +1086,7 @@ dependencies = [ "directories", "enquote", "execute", - "image 0.24.9", + "image", "indexmap", "log", "material-colors", @@ -1013,7 +1094,7 @@ dependencies = [ "paris-log", "pretty_env_logger", "prettytable-rs", - "reqwest", + "reqwest 0.12.5", "resolve-path", "serde", "serde_json", @@ -1205,6 +1286,26 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "pin-project-lite" version = "0.2.14" @@ -1311,6 +1412,54 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" +[[package]] +name = "quinn" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls 0.23.12", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls 0.23.12", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "1.0.36" @@ -1471,10 +1620,10 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", - "http-body", - "hyper", - "hyper-rustls", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", + "hyper-rustls 0.24.2", "ipnet", "js-sys", "log", @@ -1483,21 +1632,64 @@ dependencies = [ "percent-encoding", "pin-project-lite", "rustls 0.21.12", - "rustls-pemfile", + "rustls-pemfile 1.0.4", "serde", "serde_json", "serde_urlencoded", - "sync_wrapper", + "sync_wrapper 0.1.2", "system-configuration", "tokio", - "tokio-rustls", + "tokio-rustls 0.24.1", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", "webpki-roots 0.25.4", - "winreg", + "winreg 0.50.0", +] + +[[package]] +name = "reqwest" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.4.1", + "hyper-rustls 0.27.2", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls 0.23.12", + "rustls-pemfile 2.1.3", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "tokio", + "tokio-rustls 0.26.0", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots 0.26.3", + "winreg 0.52.0", ] [[package]] @@ -1539,6 +1731,12 @@ version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustls" version = "0.21.12" @@ -1575,6 +1773,16 @@ dependencies = [ "base64 0.21.7", ] +[[package]] +name = "rustls-pemfile" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" +dependencies = [ + "base64 0.22.1", + "rustls-pki-types", +] + [[package]] name = "rustls-pki-types" version = "1.8.0" @@ -1752,9 +1960,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.74" +version = "2.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fceb41e3d546d0bd83421d3409b1460cc7444cd389341a4c880fe7a042cb3d7" +checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9" dependencies = [ "proc-macro2", "quote", @@ -1767,6 +1975,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "system-configuration" version = "0.5.1" @@ -1898,6 +2112,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls 0.23.12", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.11" @@ -1945,6 +2170,27 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + [[package]] name = "tower-service" version = "0.3.3" @@ -2022,7 +2268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f8811797a24ff123db3c6e1087aa42551d03d772b3724be421ad063da1f5f3f" dependencies = [ "directories", - "reqwest", + "reqwest 0.11.27", "semver", "serde", "serde_json", @@ -2401,6 +2647,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "zerocopy" version = "0.7.35" diff --git a/Cargo.toml b/Cargo.toml index cdfa99c..63097b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ toml = { features = ["parse"], default-features = false, version = "0.8.8" } clap = { version = "4.2.4", features = ["derive", "std"], default-features = false } material-colors = { version = "0.4.0", features = ["image"] } -image = { default-features = false, version = "0.24.7" } +image = { default-features = false, version = "0.25.2" } directories = "5.0" # should probably be removed @@ -59,7 +59,7 @@ update-informer = { version = "1.1.0", optional = true } serde_json = { version = "1.0.107", optional = true } # web-image feature -reqwest = { version = "0.11.23", default-features = false, features = [ +reqwest = { version = "0.12.5", default-features = false, features = [ "blocking", "rustls-tls", ], optional = true } From bed5f76eb6ab6351f8f4194da9b9d2a2a47de06a Mon Sep 17 00:00:00 2001 From: ini <81521595+InioX@users.noreply.github.com> Date: Wed, 21 Aug 2024 10:03:20 +0200 Subject: [PATCH 41/59] Create rustfmt.yml --- .github/workflows/rustfmt.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/rustfmt.yml diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml new file mode 100644 index 0000000..76bedfd --- /dev/null +++ b/.github/workflows/rustfmt.yml @@ -0,0 +1,17 @@ +name: "rustfmt" +on: + push: + pull_request: + +jobs: + formatting: + name: cargo fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Ensure rustfmt is installed and setup problem matcher + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt + - name: Rustfmt Check + uses: actions-rust-lang/rustfmt@v1 From e656f2c1d522c5acdd9dc8320d106aab30e1298b Mon Sep 17 00:00:00 2001 From: InioX Date: Thu, 22 Aug 2024 09:43:19 +0200 Subject: [PATCH 42/59] refactor: move template into src/ --- src/main.rs | 4 +++- src/{util => }/template.rs | 0 src/util/mod.rs | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) rename src/{util => }/template.rs (100%) diff --git a/src/main.rs b/src/main.rs index 6b72452..cbc8fb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ extern crate paris_log; mod helpers; mod reload; +mod template; mod util; mod wallpaper; @@ -15,7 +16,8 @@ use matugen::{ scheme::{get_custom_color_schemes, get_schemes}, }; -use crate::util::{arguments::Cli, color::show_color, config::ConfigFile, template::Template}; +use crate::template::Template; +use crate::util::{arguments::Cli, color::show_color, config::ConfigFile}; use clap::Parser; use color_eyre::{eyre::Result, Report}; diff --git a/src/util/template.rs b/src/template.rs similarity index 100% rename from src/util/template.rs rename to src/template.rs diff --git a/src/util/mod.rs b/src/util/mod.rs index 5f42aca..2428765 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -1,4 +1,3 @@ pub mod arguments; pub mod color; pub mod config; -pub mod template; From 5d2beb0885a77855eb1a4b7d57df11b42a59161a Mon Sep 17 00:00:00 2001 From: InioX Date: Thu, 22 Aug 2024 12:06:23 +0200 Subject: [PATCH 43/59] refactor: use `BTreeSet`, remove `ahash` and `IndexMap` --- Cargo.lock | 2 -- Cargo.toml | 2 -- src/scheme.rs | 10 +++++----- src/template.rs | 21 +++++++++++---------- src/util/color.rs | 6 +++--- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aeeaea7..1c6d40f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1079,7 +1079,6 @@ dependencies = [ name = "matugen" version = "2.3.0" dependencies = [ - "ahash", "clap", "color-eyre", "colorsys", @@ -1087,7 +1086,6 @@ dependencies = [ "enquote", "execute", "image", - "indexmap", "log", "material-colors", "owo-colors 4.0.0", diff --git a/Cargo.toml b/Cargo.toml index 63097b0..d803736 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,8 +47,6 @@ image = { default-features = false, version = "0.25.2" } directories = "5.0" # should probably be removed -indexmap = { default-features = false, version = "2.2.2" } # not sure yet -ahash = { default-features = false, version = "0.8.7" } resolve-path = "0.1.0" execute = "0.2.13" diff --git a/src/scheme.rs b/src/scheme.rs index 190641b..82900b3 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use indexmap::IndexMap; +use std::collections::BTreeSet; use material_colors::scheme::Scheme; use crate::color::color::{generate_dynamic_scheme, make_custom_color, OwnCustomColor}; @@ -18,8 +18,8 @@ pub enum SchemeTypes { SchemeTonalSpot, } pub struct Schemes { - pub light: IndexMap, - pub dark: IndexMap, + pub light: BTreeSet<(std::string::String, material_colors::color::Argb)>, + pub dark: BTreeSet<(std::string::String, material_colors::color::Argb)>, } #[derive( @@ -89,8 +89,8 @@ pub fn get_custom_color_schemes( let custom_colors_light = custom_colors.flat_map(|c| from_color!(c, light)); let schemes: Schemes = Schemes { - dark: IndexMap::from_iter(scheme_dark.into_iter().chain(custom_colors_dark)), - light: IndexMap::from_iter(scheme_light.into_iter().chain(custom_colors_light)), + dark: BTreeSet::from_iter(scheme_dark.into_iter().chain(custom_colors_dark)), + light: BTreeSet::from_iter(scheme_light.into_iter().chain(custom_colors_light)), }; schemes } diff --git a/src/template.rs b/src/template.rs index 94a5eb1..7f4bd04 100644 --- a/src/template.rs +++ b/src/template.rs @@ -337,28 +337,29 @@ fn generate_colors( default_scheme: &SchemesEnum, ) -> Result, Report> { let mut hashmap: HashMap = Default::default(); - for (field, _color) in &schemes.dark { + for ((field, color_light), (_, color_dark)) in std::iter::zip(&schemes.light, &schemes.dark) { hashmap.insert( field.to_string(), - generate_single_color(field, schemes, source_color, default_scheme)?, + generate_single_color(field, source_color, default_scheme, *color_light, *color_dark)?, ); } hashmap.insert( String::from("source_color"), - generate_single_color("source_color", schemes, source_color, default_scheme)?, + generate_single_color("source_color", source_color, default_scheme, *source_color, *source_color)?, ); Ok(hashmap) } fn generate_single_color( field: &str, - schemes: &Schemes, source_color: &Argb, default_scheme: &SchemesEnum, + color_light: Argb, + color_dark: Argb, ) -> Result { - let scheme = match default_scheme { - SchemesEnum::Light => &schemes.light, - SchemesEnum::Dark => &schemes.dark, + let default_scheme_color = match default_scheme { + SchemesEnum::Light => color_light, + SchemesEnum::Dark => color_dark, }; if field == "source_color" { @@ -370,9 +371,9 @@ fn generate_single_color( } Ok(ColorVariants { - default: generate_color_strings(scheme[field]), - light: generate_color_strings(schemes.light[field]), - dark: generate_color_strings(schemes.dark[field]), + default: generate_color_strings(default_scheme_color), + light: generate_color_strings(color_light), + dark: generate_color_strings(color_dark), }) } diff --git a/src/util/color.rs b/src/util/color.rs index 5cccace..506078d 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -14,9 +14,9 @@ use matugen::color::format::rgb_from_argb; pub fn show_color(schemes: &Schemes, source_color: &Argb) { let mut table: Table = generate_table_format(); - for (field, _color) in &schemes.dark { - let color_light: Rgb = rgb_from_argb(schemes.light[field]); - let color_dark: Rgb = rgb_from_argb(schemes.dark[field]); + for ((field, color_light), (_, color_dark)) in std::iter::zip(&schemes.light, &schemes.dark) { + let color_light: Rgb = rgb_from_argb(*color_light); + let color_dark: Rgb = rgb_from_argb(*color_dark); generate_table_rows(&mut table, field, color_light, color_dark); } From f18a8d23ad29442474a95d98d569cd41225caa89 Mon Sep 17 00:00:00 2001 From: InioX Date: Thu, 22 Aug 2024 12:27:44 +0200 Subject: [PATCH 44/59] tests: add schemes_eq test --- src/color/color.rs | 2 +- src/scheme.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/color/color.rs b/src/color/color.rs index b87ccfa..95d5c93 100644 --- a/src/color/color.rs +++ b/src/color/color.rs @@ -137,7 +137,7 @@ pub fn generate_dynamic_scheme( is_dark: bool, contrast_level: Option, ) -> DynamicScheme { - match scheme_type.unwrap() { + match scheme_type.unwrap_or(SchemeTypes::SchemeContent) { SchemeTypes::SchemeContent => { SchemeContent::new(Hct::new(source_color), is_dark, contrast_level).scheme } diff --git a/src/scheme.rs b/src/scheme.rs index 82900b3..6d34f12 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -114,3 +114,29 @@ pub fn get_schemes( )); (scheme_dark, scheme_light) } + + +#[cfg(test)] +mod tests { + use super::*; + use material_colors::color::Argb; + + #[test] + fn schemes_eq() { + let source_color = material_colors::color::Argb::new(255, 255, 0, 0); + assert_eq!( + Scheme::from(generate_dynamic_scheme( + &None, + source_color, + true, + None, + )).primary, + Argb { + alpha: 255, + red: 255, + green: 180, + blue: 168, + } + ); + } +} \ No newline at end of file From abe81ee7231a329527536f4eb0d74db2c080c98d Mon Sep 17 00:00:00 2001 From: InioX Date: Thu, 22 Aug 2024 12:58:45 +0200 Subject: [PATCH 45/59] refactor: move some stuff into template_util (prepare for criterion) --- src/lib.rs | 1 + src/main.rs | 2 +- src/template.rs | 151 ++-------------------------------- src/template_util/mod.rs | 1 + src/template_util/template.rs | 151 ++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 146 deletions(-) create mode 100644 src/template_util/mod.rs create mode 100644 src/template_util/template.rs diff --git a/src/lib.rs b/src/lib.rs index 130e470..9ed7116 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ pub mod color; pub mod exec; pub mod filters; pub mod scheme; +pub mod template_util; extern crate pretty_env_logger; #[macro_use] diff --git a/src/main.rs b/src/main.rs index cbc8fb5..5772d11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ extern crate paris_log; mod helpers; mod reload; -mod template; +pub mod template; mod util; mod wallpaper; diff --git a/src/template.rs b/src/template.rs index 7f4bd04..1dd21ff 100644 --- a/src/template.rs +++ b/src/template.rs @@ -3,17 +3,15 @@ use color_eyre::eyre::WrapErr; use color_eyre::Help; use color_eyre::{eyre::Result, Report}; -use colorsys::{ColorAlpha, Hsl}; use material_colors::color::Argb; -use matugen::filters::grayscale::grayscale; -use matugen::filters::hue::set_hue; -use matugen::filters::invert::invert; +use matugen::template_util::template::add_engine_filters; +use matugen::template_util::template::get_render_data; +use matugen::template_util::template::render_template; use serde::{Deserialize, Serialize}; use upon::Value; use matugen::exec::hook::format_hook; -use matugen::filters::{alpha::set_alpha, lightness::set_lightness}; use std::path::Path; use std::str; @@ -25,10 +23,6 @@ use std::fs::OpenOptions; use std::io::Write; use std::path::PathBuf; -use matugen::color::format::{ - format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba, -}; - use matugen::color::color::Source; use resolve_path::PathResolveExt; @@ -47,32 +41,6 @@ pub struct Template { pub post_hook: Option, } -#[derive(Serialize, Deserialize, Debug)] -struct Colora { - hex: String, - hex_stripped: String, - rgb: String, - rgba: String, - hsl: String, - hsla: String, - red: String, - green: String, - blue: String, - alpha: String, - hue: String, - saturation: String, - lightness: String, -} - -#[derive(Serialize, Deserialize, Debug)] -struct ColorVariants { - pub light: Colora, - pub dark: Colora, - pub default: Colora, -} - -use matugen::color::format::rgb_from_argb; - #[allow(clippy::manual_strip)] pub trait StripCanonicalization where @@ -122,19 +90,7 @@ impl Template { Source::Color { .. } => None, }; - let colors = generate_colors(schemes, source_color, default_scheme)?; - - let mut custom: HashMap = Default::default(); - - for entry in custom_keywords.iter() { - for (name, value) in entry { - custom.insert(name.to_string(), value.to_string()); - } - } - - let mut render_data = upon::value! { - colors: &colors, image: image, custom: &custom, - }; + let mut render_data = get_render_data(schemes, source_color, default_scheme, custom_keywords, image)?; for (i, (name, template)) in templates.iter().enumerate() { let (input_path_absolute, output_path_absolute) = @@ -257,20 +213,7 @@ fn export_template( i: usize, templates: &HashMap, ) -> Result<(), Report> { - let data = engine - .template(name) - .render(render_data) - .to_string() - .map_err(|error| { - let message = format!( - "[{} - {}]\n{:#}", - name, - input_path_absolute.display(), - &error - ); - - Report::new(error).wrap_err(message) - })?; + let data = render_template(engine, name, render_data, input_path_absolute.to_str())?; let out = if path_prefix.is_some() && !cfg!(windows) { let mut prefix_path = PathBuf::from(path_prefix.as_ref().unwrap()); @@ -313,86 +256,4 @@ fn export_template( ); Ok(()) -} - -fn add_engine_filters(engine: &mut Engine) { - // Color manipulation - engine.add_filter("set_lightness", set_lightness); - engine.add_filter("set_alpha", set_alpha); - engine.add_filter("set_hue", set_hue); - engine.add_filter("grayscale", grayscale); - engine.add_filter("invert", invert); - - // String manipulation - engine.add_filter("to_upper", str::to_uppercase); - engine.add_filter("to_lower", str::to_lowercase); - engine.add_filter("replace", |s: String, from: String, to: String| { - s.replace(&from, &to) - }); -} - -fn generate_colors( - schemes: &Schemes, - source_color: &Argb, - default_scheme: &SchemesEnum, -) -> Result, Report> { - let mut hashmap: HashMap = Default::default(); - for ((field, color_light), (_, color_dark)) in std::iter::zip(&schemes.light, &schemes.dark) { - hashmap.insert( - field.to_string(), - generate_single_color(field, source_color, default_scheme, *color_light, *color_dark)?, - ); - } - hashmap.insert( - String::from("source_color"), - generate_single_color("source_color", source_color, default_scheme, *source_color, *source_color)?, - ); - Ok(hashmap) -} - -fn generate_single_color( - field: &str, - source_color: &Argb, - default_scheme: &SchemesEnum, - color_light: Argb, - color_dark: Argb, -) -> Result { - let default_scheme_color = match default_scheme { - SchemesEnum::Light => color_light, - SchemesEnum::Dark => color_dark, - }; - - if field == "source_color" { - return Ok(ColorVariants { - default: generate_color_strings(*source_color), - light: generate_color_strings(*source_color), - dark: generate_color_strings(*source_color), - }); - } - - Ok(ColorVariants { - default: generate_color_strings(default_scheme_color), - light: generate_color_strings(color_light), - dark: generate_color_strings(color_dark), - }) -} - -fn generate_color_strings(color: Argb) -> Colora { - let base_color = rgb_from_argb(color); - let hsl_color = Hsl::from(&base_color); - Colora { - hex: format_hex(&base_color), - hex_stripped: format_hex_stripped(&base_color), - rgb: format_rgb(&base_color), - rgba: format_rgba(&base_color, true), - hsl: format_hsl(&hsl_color), - hsla: format_hsla(&hsl_color, true), - red: format!("{:?}", base_color.red() as u8), - green: format!("{:?}", base_color.green() as u8), - blue: format!("{:?}", base_color.blue() as u8), - alpha: format!("{:?}", base_color.alpha() as u8), - hue: format!("{:?}", &hsl_color.hue()), - lightness: format!("{:?}", &hsl_color.lightness()), - saturation: format!("{:?}", &hsl_color.saturation()), - } -} +} \ No newline at end of file diff --git a/src/template_util/mod.rs b/src/template_util/mod.rs new file mode 100644 index 0000000..01806cb --- /dev/null +++ b/src/template_util/mod.rs @@ -0,0 +1 @@ +pub mod template; \ No newline at end of file diff --git a/src/template_util/template.rs b/src/template_util/template.rs new file mode 100644 index 0000000..49baded --- /dev/null +++ b/src/template_util/template.rs @@ -0,0 +1,151 @@ +use std::collections::HashMap; + +use color_eyre::{eyre::Result, Report}; +use colorsys::{ColorAlpha, Hsl}; +use material_colors::color::Argb; +use upon::{Engine, Value}; + +use crate::filters::alpha::set_alpha; +use crate::filters::grayscale::grayscale; +use crate::filters::hue::set_hue; +use crate::filters::invert::invert; +use crate::filters::lightness::set_lightness; +use crate::scheme::{Schemes, SchemesEnum}; +use crate::color::format::{format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba, rgb_from_argb}; + +#[derive(serde::Serialize, serde::Deserialize, Debug)] +pub struct Color { + hex: String, + hex_stripped: String, + rgb: String, + rgba: String, + hsl: String, + hsla: String, + red: String, + green: String, + blue: String, + alpha: String, + hue: String, + saturation: String, + lightness: String, +} + +#[derive(serde::Serialize, serde::Deserialize, Debug)] +pub struct ColorVariants { + pub light: Color, + pub dark: Color, + pub default: Color, +} + +pub fn add_engine_filters(engine: &mut Engine) { + // Color manipulation + engine.add_filter("set_lightness", set_lightness); + engine.add_filter("set_alpha", set_alpha); + engine.add_filter("set_hue", set_hue); + engine.add_filter("grayscale", grayscale); + engine.add_filter("invert", invert); + + // String manipulation + engine.add_filter("to_upper", str::to_uppercase); + engine.add_filter("to_lower", str::to_lowercase); + engine.add_filter("replace", |s: String, from: String, to: String| { + s.replace(&from, &to) + }); +} + +pub fn render_template(engine: &Engine, name: &String, render_data: &Value, path: Option<&str>) -> Result { + let data = engine + .template(name) + .render(render_data) + .to_string() + .map_err(|error| { + let message = format!( + "[{} - {}]\n{:#}", + name, + path.unwrap_or(&"".to_string()), + &error + ); + + Report::new(error).wrap_err(message) + })?; + Ok(data) +} + +pub fn get_render_data(schemes: &Schemes, source_color: &Argb, default_scheme: &SchemesEnum, custom_keywords: &Option>, image: Option<&String>) -> Result { + let colors = generate_colors(schemes, source_color, default_scheme)?; + let mut custom: HashMap = Default::default(); + for entry in custom_keywords.iter() { + for (name, value) in entry { + custom.insert(name.to_string(), value.to_string()); + } + } + Ok(upon::value! { + colors: &colors, image: image, custom: &custom, + }) +} + +pub fn generate_colors( + schemes: &Schemes, + source_color: &Argb, + default_scheme: &SchemesEnum, +) -> Result, Report> { + let mut hashmap: HashMap = Default::default(); + for ((field, color_light), (_, color_dark)) in std::iter::zip(&schemes.light, &schemes.dark) { + hashmap.insert( + field.to_string(), + generate_single_color(field, source_color, default_scheme, *color_light, *color_dark)?, + ); + } + hashmap.insert( + String::from("source_color"), + generate_single_color("source_color", source_color, default_scheme, *source_color, *source_color)?, + ); + Ok(hashmap) +} + +pub fn generate_single_color( + field: &str, + source_color: &Argb, + default_scheme: &SchemesEnum, + color_light: Argb, + color_dark: Argb, +) -> Result { + let default_scheme_color = match default_scheme { + SchemesEnum::Light => color_light, + SchemesEnum::Dark => color_dark, + }; + + if field == "source_color" { + return Ok(ColorVariants { + default: generate_color_strings(*source_color), + light: generate_color_strings(*source_color), + dark: generate_color_strings(*source_color), + }); + } + + Ok(ColorVariants { + default: generate_color_strings(default_scheme_color), + light: generate_color_strings(color_light), + dark: generate_color_strings(color_dark), + }) +} + +fn generate_color_strings(color: Argb) -> Color { + let base_color = rgb_from_argb(color); + let hsl_color = Hsl::from(&base_color); + Color { + hex: format_hex(&base_color), + hex_stripped: format_hex_stripped(&base_color), + rgb: format_rgb(&base_color), + rgba: format_rgba(&base_color, true), + hsl: format_hsl(&hsl_color), + hsla: format_hsla(&hsl_color, true), + red: format!("{:?}", base_color.red() as u8), + green: format!("{:?}", base_color.green() as u8), + blue: format!("{:?}", base_color.blue() as u8), + alpha: format!("{:?}", base_color.alpha() as u8), + hue: format!("{:?}", &hsl_color.hue()), + lightness: format!("{:?}", &hsl_color.lightness()), + saturation: format!("{:?}", &hsl_color.saturation()), + } +} \ No newline at end of file From 7da3b0af696c176d1b32585143525c948499e981 Mon Sep 17 00:00:00 2001 From: InioX Date: Mon, 26 Aug 2024 12:35:06 +0200 Subject: [PATCH 46/59] tests: add criterion bench --- Cargo.lock | 150 +++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 7 +++ benches/template.rs | 50 +++++++++++++++ 3 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 benches/template.rs diff --git a/Cargo.lock b/Cargo.lock index 1c6d40f..862f68b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,6 +45,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4aa90d7ce82d4be67b64039a3d588d38dbcc6736577de4a847025ce5b0c468d1" +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "anstyle" version = "1.0.8" @@ -196,6 +202,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cc" version = "1.1.13" @@ -223,6 +235,33 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "clap" version = "4.5.16" @@ -311,6 +350,42 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools 0.10.5", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools 0.10.5", +] + [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -960,6 +1035,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.12.1" @@ -1082,6 +1166,7 @@ dependencies = [ "clap", "color-eyre", "colorsys", + "criterion", "directories", "enquote", "execute", @@ -1238,6 +1323,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "oorandom" +version = "11.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" + [[package]] name = "option-ext" version = "0.2.0" @@ -1322,6 +1413,34 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "plotters" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" + +[[package]] +name = "plotters-svg" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" +dependencies = [ + "plotters-backend", +] + [[package]] name = "png" version = "0.17.13" @@ -1511,7 +1630,7 @@ dependencies = [ "built", "cfg-if", "interpolate_name", - "itertools", + "itertools 0.12.1", "libc", "libfuzzer-sys", "log", @@ -1820,6 +1939,15 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -2070,6 +2198,16 @@ dependencies = [ "weezl", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -2334,6 +2472,16 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "want" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index d803736..3137276 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,13 @@ update-informer = ["dep:update-informer"] web-image = ["dep:reqwest"] dump-json = ["dep:serde_json"] +[dev-dependencies] +criterion = { version = "0.5", features = ["html_reports"] } + +[[bench]] +name = "template" +harness = false + [dependencies] # logging log = "0.4.17" diff --git a/benches/template.rs b/benches/template.rs new file mode 100644 index 0000000..a9e349c --- /dev/null +++ b/benches/template.rs @@ -0,0 +1,50 @@ +use std::hint::black_box; +use criterion::{criterion_group, criterion_main, Criterion}; + +use matugen::{scheme::{get_custom_color_schemes, get_schemes, SchemesEnum}, template_util::template::{self, get_render_data, render_template}}; +use template::add_engine_filters; +use upon::{Engine, Syntax}; + +fn parse_template(data: &str) { + let source_color = material_colors::color::Argb::new(255, 255, 0, 0); + + let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build(); + let mut engine = Engine::with_syntax(syntax); + + add_engine_filters(&mut engine); + + let (scheme_dark, scheme_light) = get_schemes(source_color, &None, &None); + let schemes = get_custom_color_schemes( + source_color, + scheme_dark, + scheme_light, + &None, + &None, + &None + ); + let render_data = get_render_data(&schemes, &source_color,&SchemesEnum::Dark, &None, None).unwrap(); + + engine.add_template("a", data.repeat(50)).expect("failed to add template"); + render_template(&engine, &"a".to_string(), &render_data, None).expect("failed to render template"); +} + +fn criterion_benchmark(c: &mut Criterion) { + let data = + r#" + <* for name, value in colors *> + {{name}} {{value.default.rgba}}; + <* endfor *> + "#; + let data_filter = + r#" + <* for name, value in colors *> + {{name | replace: "_", "-" }} {{value.default.rgba | set_alpha: 0.7 | set_hue: -180.0 }}; + <* endfor *> + "#; + + c.bench_function("parse 20", |b| b.iter(|| parse_template(black_box(&data.repeat(20))))); + c.bench_function("parse 20 filters", |b| b.iter(|| parse_template(black_box(&data_filter.repeat(20))))); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches); \ No newline at end of file From 87f7bd934a19941ee9a6744bdfe1bdc8a5dd08ee Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 27 Aug 2024 14:12:41 +0200 Subject: [PATCH 47/59] fix: dump_json BTreeSet index --- src/util/color.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/color.rs b/src/util/color.rs index 506078d..68fb9a6 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -57,10 +57,10 @@ pub fn dump_json(schemes: &Schemes, source_color: &Argb, format: &Format) { let mut colors_normal_light: HashMap<&str, String> = HashMap::new(); let mut colors_normal_dark: HashMap<&str, String> = HashMap::new(); - - for (field, _color) in &schemes.dark { - let color_light: Rgb = rgb_from_argb(schemes.light[field]); - let color_dark: Rgb = rgb_from_argb(schemes.dark[field]); + + for ((field, color_light), (_, color_dark)) in std::iter::zip(&schemes.light, &schemes.dark) { + let color_light: Rgb = rgb_from_argb(*color_light); + let color_dark: Rgb = rgb_from_argb(*color_dark); colors_normal_light.insert(field, fmt(color_light)); colors_normal_dark.insert(field, fmt(color_dark)); From dbb2f58165fda617b73e4d9fd803873f5b0a3777 Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 27 Aug 2024 14:13:24 +0200 Subject: [PATCH 48/59] fix(nix): add dump-json feature build flag --- default.nix | 1 + flake.lock | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/default.nix b/default.nix index a6c99f0..bcd8b58 100644 --- a/default.nix +++ b/default.nix @@ -6,4 +6,5 @@ in version = manifest.version; cargoLock.lockFile = ./Cargo.lock; src = pkgs.lib.cleanSource ./.; + buildFeatures = [ "dump-json" ]; } diff --git a/flake.lock b/flake.lock index 746e55d..68bfad6 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1716330097, - "narHash": "sha256-8BO3B7e3BiyIDsaKA0tY8O88rClYRTjvAp66y+VBUeU=", + "lastModified": 1724479785, + "narHash": "sha256-pP3Azj5d6M5nmG68Fu4JqZmdGt4S4vqI5f8te+E/FTw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "5710852ba686cc1fd0d3b8e22b3117d43ba374c2", + "rev": "d0e1602ddde669d5beb01aec49d71a51937ed7be", "type": "github" }, "original": { From b73982a6fc824eed02c8d8345a887f070eaf807a Mon Sep 17 00:00:00 2001 From: InioX Date: Tue, 27 Aug 2024 22:39:03 +0200 Subject: [PATCH 49/59] chore: format code --- benches/template.rs | 45 +++++++++++++++++++---------------- src/scheme.rs | 12 +++------- src/template.rs | 10 ++++++-- src/template_util/mod.rs | 2 +- src/template_util/template.rs | 38 ++++++++++++++++++++++++----- src/util/color.rs | 2 +- 6 files changed, 69 insertions(+), 40 deletions(-) diff --git a/benches/template.rs b/benches/template.rs index a9e349c..f52abb0 100644 --- a/benches/template.rs +++ b/benches/template.rs @@ -1,7 +1,10 @@ -use std::hint::black_box; use criterion::{criterion_group, criterion_main, Criterion}; +use std::hint::black_box; -use matugen::{scheme::{get_custom_color_schemes, get_schemes, SchemesEnum}, template_util::template::{self, get_render_data, render_template}}; +use matugen::{ + scheme::{get_custom_color_schemes, get_schemes, SchemesEnum}, + template_util::template::{self, get_render_data, render_template}, +}; use template::add_engine_filters; use upon::{Engine, Syntax}; @@ -14,37 +17,37 @@ fn parse_template(data: &str) { add_engine_filters(&mut engine); let (scheme_dark, scheme_light) = get_schemes(source_color, &None, &None); - let schemes = get_custom_color_schemes( - source_color, - scheme_dark, - scheme_light, - &None, - &None, - &None - ); - let render_data = get_render_data(&schemes, &source_color,&SchemesEnum::Dark, &None, None).unwrap(); - - engine.add_template("a", data.repeat(50)).expect("failed to add template"); - render_template(&engine, &"a".to_string(), &render_data, None).expect("failed to render template"); + let schemes = + get_custom_color_schemes(source_color, scheme_dark, scheme_light, &None, &None, &None); + let render_data = + get_render_data(&schemes, &source_color, &SchemesEnum::Dark, &None, None).unwrap(); + + engine + .add_template("a", data.repeat(50)) + .expect("failed to add template"); + render_template(&engine, &"a".to_string(), &render_data, None) + .expect("failed to render template"); } fn criterion_benchmark(c: &mut Criterion) { - let data = - r#" + let data = r#" <* for name, value in colors *> {{name}} {{value.default.rgba}}; <* endfor *> "#; - let data_filter = - r#" + let data_filter = r#" <* for name, value in colors *> {{name | replace: "_", "-" }} {{value.default.rgba | set_alpha: 0.7 | set_hue: -180.0 }}; <* endfor *> "#; - c.bench_function("parse 20", |b| b.iter(|| parse_template(black_box(&data.repeat(20))))); - c.bench_function("parse 20 filters", |b| b.iter(|| parse_template(black_box(&data_filter.repeat(20))))); + c.bench_function("parse 20", |b| { + b.iter(|| parse_template(black_box(&data.repeat(20)))) + }); + c.bench_function("parse 20 filters", |b| { + b.iter(|| parse_template(black_box(&data_filter.repeat(20)))) + }); } criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); diff --git a/src/scheme.rs b/src/scheme.rs index 6d34f12..01a6633 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; -use std::collections::BTreeSet; use material_colors::scheme::Scheme; +use std::collections::BTreeSet; use crate::color::color::{generate_dynamic_scheme, make_custom_color, OwnCustomColor}; @@ -115,7 +115,6 @@ pub fn get_schemes( (scheme_dark, scheme_light) } - #[cfg(test)] mod tests { use super::*; @@ -125,12 +124,7 @@ mod tests { fn schemes_eq() { let source_color = material_colors::color::Argb::new(255, 255, 0, 0); assert_eq!( - Scheme::from(generate_dynamic_scheme( - &None, - source_color, - true, - None, - )).primary, + Scheme::from(generate_dynamic_scheme(&None, source_color, true, None,)).primary, Argb { alpha: 255, red: 255, @@ -139,4 +133,4 @@ mod tests { } ); } -} \ No newline at end of file +} diff --git a/src/template.rs b/src/template.rs index 1dd21ff..0bb64c4 100644 --- a/src/template.rs +++ b/src/template.rs @@ -90,7 +90,13 @@ impl Template { Source::Color { .. } => None, }; - let mut render_data = get_render_data(schemes, source_color, default_scheme, custom_keywords, image)?; + let mut render_data = get_render_data( + schemes, + source_color, + default_scheme, + custom_keywords, + image, + )?; for (i, (name, template)) in templates.iter().enumerate() { let (input_path_absolute, output_path_absolute) = @@ -256,4 +262,4 @@ fn export_template( ); Ok(()) -} \ No newline at end of file +} diff --git a/src/template_util/mod.rs b/src/template_util/mod.rs index 01806cb..612b5b9 100644 --- a/src/template_util/mod.rs +++ b/src/template_util/mod.rs @@ -1 +1 @@ -pub mod template; \ No newline at end of file +pub mod template; diff --git a/src/template_util/template.rs b/src/template_util/template.rs index 49baded..65cb39f 100644 --- a/src/template_util/template.rs +++ b/src/template_util/template.rs @@ -5,13 +5,16 @@ use colorsys::{ColorAlpha, Hsl}; use material_colors::color::Argb; use upon::{Engine, Value}; +use crate::color::format::{ + format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba, + rgb_from_argb, +}; use crate::filters::alpha::set_alpha; use crate::filters::grayscale::grayscale; use crate::filters::hue::set_hue; use crate::filters::invert::invert; use crate::filters::lightness::set_lightness; use crate::scheme::{Schemes, SchemesEnum}; -use crate::color::format::{format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba, rgb_from_argb}; #[derive(serde::Serialize, serde::Deserialize, Debug)] pub struct Color { @@ -53,7 +56,12 @@ pub fn add_engine_filters(engine: &mut Engine) { }); } -pub fn render_template(engine: &Engine, name: &String, render_data: &Value, path: Option<&str>) -> Result { +pub fn render_template( + engine: &Engine, + name: &String, + render_data: &Value, + path: Option<&str>, +) -> Result { let data = engine .template(name) .render(render_data) @@ -71,7 +79,13 @@ pub fn render_template(engine: &Engine, name: &String, render_data: &Value, path Ok(data) } -pub fn get_render_data(schemes: &Schemes, source_color: &Argb, default_scheme: &SchemesEnum, custom_keywords: &Option>, image: Option<&String>) -> Result { +pub fn get_render_data( + schemes: &Schemes, + source_color: &Argb, + default_scheme: &SchemesEnum, + custom_keywords: &Option>, + image: Option<&String>, +) -> Result { let colors = generate_colors(schemes, source_color, default_scheme)?; let mut custom: HashMap = Default::default(); for entry in custom_keywords.iter() { @@ -93,12 +107,24 @@ pub fn generate_colors( for ((field, color_light), (_, color_dark)) in std::iter::zip(&schemes.light, &schemes.dark) { hashmap.insert( field.to_string(), - generate_single_color(field, source_color, default_scheme, *color_light, *color_dark)?, + generate_single_color( + field, + source_color, + default_scheme, + *color_light, + *color_dark, + )?, ); } hashmap.insert( String::from("source_color"), - generate_single_color("source_color", source_color, default_scheme, *source_color, *source_color)?, + generate_single_color( + "source_color", + source_color, + default_scheme, + *source_color, + *source_color, + )?, ); Ok(hashmap) } @@ -148,4 +174,4 @@ fn generate_color_strings(color: Argb) -> Color { lightness: format!("{:?}", &hsl_color.lightness()), saturation: format!("{:?}", &hsl_color.saturation()), } -} \ No newline at end of file +} diff --git a/src/util/color.rs b/src/util/color.rs index 68fb9a6..0d57c38 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -57,7 +57,7 @@ pub fn dump_json(schemes: &Schemes, source_color: &Argb, format: &Format) { let mut colors_normal_light: HashMap<&str, String> = HashMap::new(); let mut colors_normal_dark: HashMap<&str, String> = HashMap::new(); - + for ((field, color_light), (_, color_dark)) in std::iter::zip(&schemes.light, &schemes.dark) { let color_light: Rgb = rgb_from_argb(*color_light); let color_dark: Rgb = rgb_from_argb(*color_dark); From 994e17e1c2b3f50a9919402d3e5e66df392889f0 Mon Sep 17 00:00:00 2001 From: InioX Date: Thu, 29 Aug 2024 12:03:57 +0200 Subject: [PATCH 50/59] fix: parse color bug for rgb (#107) --- src/color/color.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/color/color.rs b/src/color/color.rs index 95d5c93..9c4db84 100644 --- a/src/color/color.rs +++ b/src/color/color.rs @@ -115,7 +115,13 @@ pub fn get_source_color_from_color( Ok(Argb::from_str(string).expect("Invalid hex color string provided")) } ColorFormat::Rgb { string } => { - Ok(string.parse().expect("Invalid rgb color string provided")) + let rgb = Rgb::from_str(string).expect("Invalid rgb color string provided"); + Ok(Argb { + red: rgb.red() as u8, + green: rgb.green() as u8, + blue: rgb.blue() as u8, + alpha: 255, + }) } ColorFormat::Hsl { string } => { let rgb: Rgb = Hsl::from_str(string) From ac8e82769ec50f0c73eedca1f49b674a686c2acf Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Tue, 27 Aug 2024 11:14:28 +1000 Subject: [PATCH 51/59] add custom colors option to nix module. --- module.nix | 57 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/module.nix b/module.nix index d00d2df..1fba9b0 100644 --- a/module.nix +++ b/module.nix @@ -8,6 +8,17 @@ matugen: { cfg = config.programs.matugen; osCfg = args.osConfig.programs.matugen or {}; + hexColor = lib.types.strMatching "#([0-9a-fA-F]{3}){1,2}"; + hexStrippedColor = lib.types.strMatching "([0-9a-fA-F]{3}){1,2}"; + rgbColor = lib.types.strMatching "rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)"; + rgbaColor = lib.types.strMatching "rgba\(\d{1,3}, ?\d{1,3}, ?\d{1,3}, ?\d{1,3}\)"; + hslColor = lib.types.strMatching "hsl\(\d{1,3}, ?\d{1,3}%, ?\d{1,3}%\)"; + hslaColor = lib.types.strMatching "hsla\(\d{1,3}, ?\d{1,3}%, ?\d{1,3}%, ?[0,1](\.\d*)\)"; + + # Only hexColor is currently supported for custom_colors. + colorType = hexColor; + # colorType = lib.types.oneOf [hexColor hexStrippedColor rgbColor rgbaColor hslColor hslaColor]; + configFormat = pkgs.formats.toml {}; capitalize = str: let @@ -27,7 +38,9 @@ matugen: { cfg.templates; matugenConfig = configFormat.generate "matugen-config.toml" { - config = {}; + config = { + custom_colors = cfg.custom_colors; + }; templates = sanitizedTemplates; }; @@ -41,18 +54,14 @@ matugen: { ${cfg.package}/bin/matugen \ image ${cfg.wallpaper} \ - ${ - if cfg.templates != {} - then "--config ${matugenConfig}" - else "" - } \ + --config ${matugenConfig} \ --mode ${cfg.variant} \ --type ${cfg.type} \ --json ${cfg.jsonFormat} \ --quiet \ > $out/theme.json ''; - colors = builtins.fromJSON (builtins.readFile "${themePackage}/theme.json"); + colors = (builtins.fromJSON (builtins.readFile "${themePackage}/theme.json")).colors; in { options.programs.matugen = { enable = lib.mkEnableOption "Matugen declarative theming"; @@ -95,11 +104,43 @@ in { ''; }; + custom_colors = lib.mkOption { + description = "Other colors that should be included in the colorsheme."; + type = with lib.types; + attrsOf (submodule { + options = { + color = lib.mkOption { + description = "Color value for this custom color."; + type = colorType; + example = "#d03e3e"; + }; + blend = lib.mkOption { + description = "Whether to pick a color close to the given value, or to pass the value through to the final colorscheme unchanged."; + type = bool; + default = true; + }; + }; + }); + default = osCfg.custom_colors or {}; + example = '' + { + light-red.color = "#d03e3e"; + light-orange.color = "#d7691d"; + light-yellow.color = "#ad8200"; + + red = { + color = "#ff0000"; + blend = false; + }; + } + ''; + }; + type = lib.mkOption { description = "Palette used when generating the colorschemes."; type = lib.types.enum ["scheme-content" "scheme-expressive" "scheme-fidelity" "scheme-fruit-salad" "scheme-monochrome" "scheme-neutral" "scheme-rainbow" "scheme-tonal-spot"]; default = osCfg.palette or "scheme-tonal-spot"; - example = "triadic"; + example = "scheme-content"; }; jsonFormat = lib.mkOption { From 7df197c7b917c897fab4339c4804c95f296dd260 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Tue, 27 Aug 2024 15:12:18 +1000 Subject: [PATCH 52/59] add backup config option to add in anything that isn't explicitly supported --- module.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/module.nix b/module.nix index 1fba9b0..81a83a2 100644 --- a/module.nix +++ b/module.nix @@ -40,7 +40,7 @@ matugen: { matugenConfig = configFormat.generate "matugen-config.toml" { config = { custom_colors = cfg.custom_colors; - }; + } // cfg.config; templates = sanitizedTemplates; }; @@ -157,6 +157,17 @@ in { example = "light"; }; + config = lib.mkOption { + description = "Add things to the config not covered by other options."; + type = lib.types.attrs; + default = osCfg.config or {}; + example = '' + { + custom_keywords.font1 = "Google Sans"; + } + ''; + }; + theme.files = lib.mkOption { type = lib.types.package; readOnly = true; From ac4a36bf331012b655abe5125d801033dee976c2 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Wed, 28 Aug 2024 23:29:37 +1000 Subject: [PATCH 53/59] make nix module able to generate from color or wallpaper. --- module.nix | 53 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/module.nix b/module.nix index 81a83a2..f5f145e 100644 --- a/module.nix +++ b/module.nix @@ -8,16 +8,22 @@ matugen: { cfg = config.programs.matugen; osCfg = args.osConfig.programs.matugen or {}; - hexColor = lib.types.strMatching "#([0-9a-fA-F]{3}){1,2}"; - hexStrippedColor = lib.types.strMatching "([0-9a-fA-F]{3}){1,2}"; - rgbColor = lib.types.strMatching "rgb\(\d{1,3}, ?\d{1,3}, ?\d{1,3}\)"; - rgbaColor = lib.types.strMatching "rgba\(\d{1,3}, ?\d{1,3}, ?\d{1,3}, ?\d{1,3}\)"; - hslColor = lib.types.strMatching "hsl\(\d{1,3}, ?\d{1,3}%, ?\d{1,3}%\)"; - hslaColor = lib.types.strMatching "hsla\(\d{1,3}, ?\d{1,3}%, ?\d{1,3}%, ?[0,1](\.\d*)\)"; - - # Only hexColor is currently supported for custom_colors. - colorType = hexColor; - # colorType = lib.types.oneOf [hexColor hexStrippedColor rgbColor rgbaColor hslColor hslaColor]; + hexColorRegex = ''#([0-9a-fA-F]{3}){1,2}''; + hexStrippedColorRegex = ''([0-9a-fA-F]{3}){1,2}''; + rgbColorRegex = ''rgb\([0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}\)''; + rgbaColorRegex = ''rgba\([0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}\)''; + hslColorRegex = ''hsl\([0-9]{1,3}(\.[0-9]*)?, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0-9]{1,3}(\.[0-9]*)?%\)''; + hslaColorRegex = ''hsla\([0-9]{1,3}(\.[0-9]*)?, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0,1](\.[0-9]*)?\)''; + + hexColor = lib.types.strMatching hexColorRegex; + hexStrippedColor = lib.types.strMatching hexStrippedColorRegex; + rgbColor = lib.types.strMatching rgbColorRegex; + rgbaColor = lib.types.strMatching rgbaColorRegex; + hslColor = lib.types.strMatching hslColorRegex; + hslaColor = lib.types.strMatching hslaColorRegex; + + sourceColorType = lib.types.oneOf [hexColor rgbColor hslColor]; + customColorType = hexColor; # Only hexColor is currently supported for custom_colors. configFormat = pkgs.formats.toml {}; @@ -47,20 +53,32 @@ matugen: { # get matugen package pkg = matugen.packages.${pkgs.system}.default; - themePackage = pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} '' + # takes in a source color string and returns the subcommand needed to generate + # a color scheme using that color type. + sourceColorTypeMatcher = color: (lib.lists.findSingle (p: null != builtins.match p.regex color) {} {} [ + { regex = hexColorRegex; code = "hex"; } + { regex = rgbColorRegex; code = "rgb"; } + { regex = hslColorRegex; code = "hsl"; } + ]).code; + + command = if (builtins.isNull cfg.source_color) then + "image ${cfg.wallpaper}" else + "color ${sourceColorTypeMatcher cfg.source_color} \"${cfg.source_color}\""; + + themePackage = builtins.trace command (pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} '' mkdir -p $out cd $out export HOME=$(pwd) ${cfg.package}/bin/matugen \ - image ${cfg.wallpaper} \ + ${command} \ --config ${matugenConfig} \ --mode ${cfg.variant} \ --type ${cfg.type} \ --json ${cfg.jsonFormat} \ --quiet \ > $out/theme.json - ''; + ''); colors = (builtins.fromJSON (builtins.readFile "${themePackage}/theme.json")).colors; in { options.programs.matugen = { @@ -72,6 +90,13 @@ in { default = pkg; }; + source_color = lib.mkOption { + description = "Hex color to generate the colorschemes from. If this and wallpaper are defined, will use this."; + type = lib.types.nullOr sourceColorType; + default = osCfg.source_color or null; + example = "#ff1243"; + }; + wallpaper = lib.mkOption { description = "Path to `wallpaper` that matugen will generate the colorschemes from"; type = lib.types.path; @@ -111,7 +136,7 @@ in { options = { color = lib.mkOption { description = "Color value for this custom color."; - type = colorType; + type = customColorType; example = "#d03e3e"; }; blend = lib.mkOption { From 80a781659f626adf40febdca2c339c200a92b556 Mon Sep 17 00:00:00 2001 From: Talia-12 Date: Thu, 29 Aug 2024 01:34:30 +1000 Subject: [PATCH 54/59] made contrast configurable in nix module --- module.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/module.nix b/module.nix index f5f145e..4397c34 100644 --- a/module.nix +++ b/module.nix @@ -76,6 +76,7 @@ matugen: { --mode ${cfg.variant} \ --type ${cfg.type} \ --json ${cfg.jsonFormat} \ + --contrast ${lib.strings.floatToString cfg.contrast} \ --quiet \ > $out/theme.json ''); @@ -182,6 +183,13 @@ in { example = "light"; }; + contrast = lib.mkOption { + description = "Value from -1 to 1. -1 represents minimum contrast, 0 represents standard (i.e. the design as spec'd), and 1 represents maximum contrast."; + type = lib.types.numbers.between (-1) 1; + default = 0; + example = "0.2"; + }; + config = lib.mkOption { description = "Add things to the config not covered by other options."; type = lib.types.attrs; From 324eee37e77bcf6941f788d0853b3be597ddeb0d Mon Sep 17 00:00:00 2001 From: TanX-009 Date: Sun, 13 Oct 2024 08:38:10 +0530 Subject: [PATCH 55/59] feat: custom expr and block prefix, postfix fix: revert keywords to custom_keywords --- src/template.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/template.rs b/src/template.rs index 0bb64c4..f3ffaf4 100644 --- a/src/template.rs +++ b/src/template.rs @@ -39,6 +39,10 @@ pub struct Template { pub compare_to: Option, pub pre_hook: Option, pub post_hook: Option, + pub expr_prefix: Option, + pub expr_postfix: Option, + pub block_prefix: Option, + pub block_postfix: Option, } #[allow(clippy::manual_strip)] @@ -78,11 +82,6 @@ impl Template { ) -> Result<(), Report> { info!("Loaded {} templates.", &templates.len()); - let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build(); - let mut engine = Engine::with_syntax(syntax); - - add_engine_filters(&mut engine); - let image = match &source { Source::Image { path } => Some(path), #[cfg(feature = "web-image")] @@ -99,6 +98,19 @@ impl Template { )?; for (i, (name, template)) in templates.iter().enumerate() { + let expr_prefix = template.expr_prefix.as_deref().unwrap_or("{{"); + let expr_postfix = template.expr_postfix.as_deref().unwrap_or("}}"); + let block_prefix = template.block_prefix.as_deref().unwrap_or("<*"); + let block_postfix = template.block_postfix.as_deref().unwrap_or("*>"); + + let syntax = Syntax::builder() + .expr(expr_prefix, expr_postfix) + .block(block_prefix, block_postfix) + .build(); + let mut engine = Engine::with_syntax(syntax); + + add_engine_filters(&mut engine); + let (input_path_absolute, output_path_absolute) = get_absolute_paths(&config_path, template)?; From 2f9af444aa1256ae2d77c714dad804001627be82 Mon Sep 17 00:00:00 2001 From: YS5G Date: Thu, 10 Oct 2024 15:01:38 -0400 Subject: [PATCH 56/59] feat(config): Ditch `reload_apps`; add a prototype for better wallpaper configuration --- idea.throwAway | 10 ++ src/helpers.rs | 23 ++--- src/main.rs | 9 +- src/reload/mod.rs | 2 - src/reload/unix.rs | 73 --------------- src/util/config.rs | 24 ++--- src/wallpaper/mod.rs | 13 +++ src/wallpaper/unix.rs | 211 +++++++++++++++++++++++++----------------- 8 files changed, 173 insertions(+), 192 deletions(-) create mode 100644 idea.throwAway delete mode 100644 src/reload/mod.rs delete mode 100644 src/reload/unix.rs diff --git a/idea.throwAway b/idea.throwAway new file mode 100644 index 0000000..91c9257 --- /dev/null +++ b/idea.throwAway @@ -0,0 +1,10 @@ +`nix + config.wallpaper = { + set = true; + command = "swww"; + arguments = [ + "{{image}}" + "--transition-type" "center" + ]; + } +` diff --git a/src/helpers.rs b/src/helpers.rs index 4372abd..e0e438e 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -63,18 +63,11 @@ pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { #[cfg(feature = "web-image")] Source::WebImage { .. } => return Ok(()), }; - #[cfg(any(target_os = "linux", target_os = "netbsd"))] - let wallpaper_tool = match &config.wallpaper_tool { - Some(wallpaper_tool) => wallpaper_tool, - None => { - if cfg!(windows) { - return Ok(()); - } - return Ok(warn!( - "Wallpaper tool not set, not setting wallpaper..." - )); - } - }; + if config.wallpaper.is_none() { + return Ok(warn!( + "Wallpaper setting disabled, not setting wallpaper..." + )); + } #[cfg(target_os = "windows")] wallpaper::windows::set(path)?; #[cfg(target_os = "macos")] @@ -82,9 +75,9 @@ pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { #[cfg(any(target_os = "linux", target_os = "netbsd"))] wallpaper::unix::set( path, - wallpaper_tool, - &config.feh_options, - &config.swww_options, + &(config.wallpaper).clone().unwrap().command, + &(config.wallpaper).clone().unwrap().pre_hook, + &(config.wallpaper).clone().unwrap().arguments )?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 5772d11..87de4bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ extern crate pretty_env_logger; extern crate paris_log; mod helpers; -mod reload; +// mod reload; pub mod template; mod util; mod wallpaper; @@ -77,12 +77,7 @@ fn main() -> Result<(), Report> { config_path, )?; - if config.config.reload_apps == Some(true) { - #[cfg(any(target_os = "linux", target_os = "netbsd"))] - reload::unix::reload(&args, &config)?; - } - - if config.config.set_wallpaper == Some(true) { + if config.config.wallpaper.is_some() { set_wallpaper(&args.source, &config.config)?; } } diff --git a/src/reload/mod.rs b/src/reload/mod.rs deleted file mode 100644 index 824b010..0000000 --- a/src/reload/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -pub mod unix; diff --git a/src/reload/unix.rs b/src/reload/unix.rs deleted file mode 100644 index 85543c0..0000000 --- a/src/reload/unix.rs +++ /dev/null @@ -1,73 +0,0 @@ -use crate::util::{arguments::Cli, config::ConfigFile}; -use color_eyre::{eyre::Result, Report}; - -use std::process::Command; - -use crate::SchemesEnum; - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -pub fn reload(args: &Cli, config: &ConfigFile) -> Result<(), Report> { - if config.config.reload_apps_list.is_none() { - warn!("The option config.reload_apps is set to TRUE, but config.reload_apps_list is EMPTY. Not restarting any apps..."); - return Ok(()); - } - - let reload_apps_list = &config.config.reload_apps_list.as_ref().unwrap(); - - if reload_apps_list.waybar == Some(true) || reload_apps_list.waybar.is_none() { - reload_app("waybar", "SIGUSR2")?; - } - - if reload_apps_list.kitty == Some(true) || reload_apps_list.waybar.is_none() { - reload_app("kitty", "SIGUSR1")?; - } - - if reload_apps_list.dunst == Some(true) || reload_apps_list.waybar.is_none() { - reload_app("dunst", "SIGUSR2")?; - } - - if reload_apps_list.gtk_theme == Some(true) || reload_apps_list.waybar.is_none() { - reload_gtk_theme(args)?; - } - - if reload_apps_list.mako == Some(true) || reload_apps_list.waybar.is_none() { - reload_app("mako", "SIGUSR2")?; - } - - Ok(()) -} - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -pub fn reload_app(name: &str, signal: &str) -> Result<(), Report> { - info!("Restarting {}", name); - let mut kill = Command::new("pkill"); - kill.arg(format!("-{}", signal)); - kill.arg(name); - - kill.spawn()?; - Ok(()) -} - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn reload_gtk_theme(args: &Cli) -> Result<(), Report> { - let mode = match args.mode { - Some(SchemesEnum::Light) => "light", - Some(SchemesEnum::Dark) => "dark", - None => "dark", - }; - - info!("Setting gtk theme to adw-gtk3-{}", mode); - - set_theme("")?; - set_theme(format!("adw-gtk3-{}", mode).as_str())?; - Ok(()) -} - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_theme(theme: &str) -> Result<(), Report> { - Command::new("gsettings") - .args(["set", "org.gnome.desktop.interface", "gtk-theme", theme]) - .spawn()?; - - Ok(()) -} diff --git a/src/util/config.rs b/src/util/config.rs index 82d2602..7087274 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -9,25 +9,27 @@ use serde::{Deserialize, Serialize}; use super::arguments::Cli; use crate::Template; +use crate::wallpaper::Wallpaper; -#[derive(Serialize, Deserialize, Debug)] -pub enum WallpaperTool { - Swaybg, - Swww, - Nitrogen, - Feh, -} +// #[derive(Serialize, Deserialize, Debug)] +// pub enum WallpaperTool { +// Swaybg, +// Swww, +// Nitrogen, +// Feh, +// } #[derive(Serialize, Deserialize, Debug)] pub struct Config { pub reload_apps: Option, pub version_check: Option, pub reload_apps_list: Option, - pub set_wallpaper: Option, - pub wallpaper_tool: Option, - // TODO: Add a `Command` struct - pub swww_options: Option>, + pub wallpaper: Option, + // pub set_wallpaper: Option, + // pub wallpaper_tool: Option, + // pub swww_options: Option>, pub feh_options: Option>, + // TODO: Add a `Command` struct pub prefix: Option, pub custom_keywords: Option>, pub custom_colors: Option>, diff --git a/src/wallpaper/mod.rs b/src/wallpaper/mod.rs index 9bc53c6..6b46bf2 100644 --- a/src/wallpaper/mod.rs +++ b/src/wallpaper/mod.rs @@ -1,3 +1,16 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct Wallpaper { + pub set: bool, + /// Useful for, for example, killing the wallpaper daemon + pub pre_hook: Option, + pub command: String, + /// The last argument will be the image path + pub arguments: Option>, +} + + #[cfg(any(target_os = "linux", target_os = "netbsd"))] pub mod unix; diff --git a/src/wallpaper/unix.rs b/src/wallpaper/unix.rs index 793ac9f..291ace7 100644 --- a/src/wallpaper/unix.rs +++ b/src/wallpaper/unix.rs @@ -2,40 +2,41 @@ use color_eyre::Report; use std::process::Command; use std::process::Stdio; -use crate::reload::unix::reload_app; -use crate::util::config::WallpaperTool; +// use crate::reload::unix::reload_app; + +use execute::Execute; #[cfg(any(target_os = "linux", target_os = "netbsd"))] pub fn set( path: &String, - wallpaper_tool: &WallpaperTool, - feh_options: &Option>, - swww_options: &Option>, + wallpaper_cmd: &String, + pre_hook: &Option, + arguments: &Option>, ) -> Result<(), Report> { - info!("Setting wallpaper..."); - - match &wallpaper_tool { - WallpaperTool::Swaybg => set_wallaper_swaybg(path), - WallpaperTool::Swww => set_wallaper_swww(path, swww_options), - WallpaperTool::Nitrogen => set_wallaper_nitrogen(path), - WallpaperTool::Feh => set_wallaper_feh(path, feh_options), + if let Some(hook) = pre_hook { + spawn_hook(&hook)?//.unwrap(); } -} - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_wallaper_swaybg(path: &String) -> Result<(), Report> { - reload_app("swaybg", "SIGUSR1")?; + info!("Setting wallpaper..."); - let mut binding = Command::new("swaybg"); + // match &wallpaper_tool { + // WallpaperTool::Swaybg => set_wallaper_swaybg(path), + // WallpaperTool::Swww => set_wallaper_swww(path, swww_options), + // WallpaperTool::Nitrogen => set_wallaper_nitrogen(path), + // WallpaperTool::Feh => set_wallaper_feh(path, feh_options), + // } + let mut binding = Command::new(wallpaper_cmd); let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); - cmd.arg("-i"); + if let Some(args) = arguments { + cmd.args(args); + } cmd.arg(path); + match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with swaybg"), + Ok(_) => info!("Successfully set the wallpaper with {wallpaper_cmd}"), Err(e) => { if let std::io::ErrorKind::NotFound = e.kind() { - error!("Failed to set wallpaper, the program swaybg was not found in PATH!") + error!("Failed to set wallpaper, the program {wallpaper_cmd} was not found in PATH!") } else { error!("Some error(s) occured while setting wallpaper!"); } @@ -44,77 +45,119 @@ fn set_wallaper_swaybg(path: &String) -> Result<(), Report> { Ok(()) } -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_wallaper_swww(path: &String, swww_options: &Option>) -> Result<(), Report> { - let mut binding = Command::new("swww"); - let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); - cmd.arg("img"); - cmd.arg(path); - if let Some(options) = &swww_options { - if !options[0].is_empty() { - cmd.args(options); - } - } - - match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with swww"), - Err(e) => { - if let std::io::ErrorKind::NotFound = e.kind() { - error!("Failed to set wallpaper, the program swww was not found in PATH!") - } else { - error!("Some error(s) occured while setting wallpaper!"); - } - } - }; - Ok(()) -} #[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_wallaper_nitrogen(path: &String) -> Result<(), Report> { - let mut binding = Command::new("nitrogen"); - let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); - cmd.arg(path); +fn spawn_hook(hook: &String) -> Result<(), Report> { + let mut command = execute::shell(hook); - match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with nitrogen"), - Err(e) => { - if let std::io::ErrorKind::NotFound = e.kind() { - error!( - "Failed to set wallpaper, the program nitrogen was not found in PATH!" - ) - } else { - error!("Some error(s) occured while setting wallpaper!"); - } - } - }; - Ok(()) -} + command.stdout(Stdio::inherit()); -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_wallaper_feh(path: &String, feh_options: &Option>) -> Result<(), Report> { - let mut binding = Command::new("feh"); - let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); + let output = command.execute_output()?; - if let Some(options) = &feh_options { - if !options[0].is_empty() { - cmd.args(options); - } else { - cmd.arg("--bg-scale"); + if let Some(exit_code) = output.status.code() { + if exit_code != 0 { + error!("Failed executing command: {:?}", hook) } + } else { + eprintln!("Interrupted!"); } - cmd.arg(path); - - match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with feh"), - Err(e) => { - if let std::io::ErrorKind::NotFound = e.kind() { - error!("Failed to set wallpaper, the program feh was not found in PATH!") - } else { - error!("Some error(s) occured while setting wallpaper!"); - } - } - }; Ok(()) } +// #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// fn set_wallaper_swaybg(path: &String) -> Result<(), Report> { +// reload_app("swaybg", "SIGUSR1")?; +// +// let mut binding = Command::new("swaybg"); +// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); +// cmd.arg("-i"); +// cmd.arg(path); +// +// match cmd.spawn() { +// Ok(_) => info!("Successfully set the wallpaper with swaybg"), +// Err(e) => { +// if let std::io::ErrorKind::NotFound = e.kind() { +// error!("Failed to set wallpaper, the program swaybg was not found in PATH!") +// } else { +// error!("Some error(s) occured while setting wallpaper!"); +// } +// } +// }; +// Ok(()) +// } +// +// #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// fn set_wallaper_swww(path: &String, swww_options: &Option>) -> Result<(), Report> { +// let mut binding = Command::new("swww"); +// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); +// cmd.arg("img"); +// cmd.arg(path); +// +// if let Some(options) = &swww_options { +// if !options[0].is_empty() { +// cmd.args(options); +// } +// } +// +// match cmd.spawn() { +// Ok(_) => info!("Successfully set the wallpaper with swww"), +// Err(e) => { +// if let std::io::ErrorKind::NotFound = e.kind() { +// error!("Failed to set wallpaper, the program swww was not found in PATH!") +// } else { +// error!("Some error(s) occured while setting wallpaper!"); +// } +// } +// }; +// Ok(()) +// } +// +// #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// fn set_wallaper_nitrogen(path: &String) -> Result<(), Report> { +// let mut binding = Command::new("nitrogen"); +// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); +// cmd.arg(path); +// +// match cmd.spawn() { +// Ok(_) => info!("Successfully set the wallpaper with nitrogen"), +// Err(e) => { +// if let std::io::ErrorKind::NotFound = e.kind() { +// error!( +// "Failed to set wallpaper, the program nitrogen was not found in PATH!" +// ) +// } else { +// error!("Some error(s) occured while setting wallpaper!"); +// } +// } +// }; +// Ok(()) +// } +// +// #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// fn set_wallaper_feh(path: &String, feh_options: &Option>) -> Result<(), Report> { +// let mut binding = Command::new("feh"); +// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); +// +// if let Some(options) = &feh_options { +// if !options[0].is_empty() { +// cmd.args(options); +// } else { +// cmd.arg("--bg-scale"); +// } +// } +// +// cmd.arg(path); +// +// match cmd.spawn() { +// Ok(_) => info!("Successfully set the wallpaper with feh"), +// Err(e) => { +// if let std::io::ErrorKind::NotFound = e.kind() { +// error!("Failed to set wallpaper, the program feh was not found in PATH!") +// } else { +// error!("Some error(s) occured while setting wallpaper!"); +// } +// } +// }; +// Ok(()) +// } From 059c989c639942fe05af568bc8cac27e641fecd5 Mon Sep 17 00:00:00 2001 From: YS5G Date: Thu, 17 Oct 2024 15:27:44 -0400 Subject: [PATCH 57/59] feat(config): Completely remove `reload_apps`; get `config.wallpaper` to work --- idea.throwAway | 10 ---- src/helpers.rs | 12 ++-- src/main.rs | 5 +- src/util/config.rs | 23 -------- src/wallpaper/mod.rs | 3 +- src/wallpaper/unix.rs | 133 +++++------------------------------------- 6 files changed, 23 insertions(+), 163 deletions(-) delete mode 100644 idea.throwAway diff --git a/idea.throwAway b/idea.throwAway deleted file mode 100644 index 91c9257..0000000 --- a/idea.throwAway +++ /dev/null @@ -1,10 +0,0 @@ -`nix - config.wallpaper = { - set = true; - command = "swww"; - arguments = [ - "{{image}}" - "--transition-type" "center" - ]; - } -` diff --git a/src/helpers.rs b/src/helpers.rs index e0e438e..73b5ef8 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,4 +1,4 @@ -use crate::{util::config::Config, wallpaper}; +use crate::wallpaper; use color_eyre::{eyre::Result, Report}; use log::LevelFilter; use matugen::color::color::Source; @@ -56,18 +56,18 @@ pub fn setup_logging(args: &Cli) -> Result<(), Report> { Ok(()) } -pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { +pub fn set_wallpaper(source: &Source, wallpaper_cfg: wallpaper::Wallpaper) -> Result<(), Report> { let path = match &source { Source::Image { path } => path, Source::Color { .. } => return Ok(()), #[cfg(feature = "web-image")] Source::WebImage { .. } => return Ok(()), }; - if config.wallpaper.is_none() { + if !wallpaper_cfg.set { return Ok(warn!( "Wallpaper setting disabled, not setting wallpaper..." )); - } + }; #[cfg(target_os = "windows")] wallpaper::windows::set(path)?; #[cfg(target_os = "macos")] @@ -75,9 +75,7 @@ pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { #[cfg(any(target_os = "linux", target_os = "netbsd"))] wallpaper::unix::set( path, - &(config.wallpaper).clone().unwrap().command, - &(config.wallpaper).clone().unwrap().pre_hook, - &(config.wallpaper).clone().unwrap().arguments + wallpaper_cfg )?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 87de4bf..dbee85d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ extern crate pretty_env_logger; extern crate paris_log; mod helpers; -// mod reload; pub mod template; mod util; mod wallpaper; @@ -77,8 +76,8 @@ fn main() -> Result<(), Report> { config_path, )?; - if config.config.wallpaper.is_some() { - set_wallpaper(&args.source, &config.config)?; + if let Some(wallpaper_cfg) = config.config.wallpaper { + set_wallpaper(&args.source, wallpaper_cfg)?; } } diff --git a/src/util/config.rs b/src/util/config.rs index 7087274..4f1655c 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -11,39 +11,16 @@ use super::arguments::Cli; use crate::Template; use crate::wallpaper::Wallpaper; -// #[derive(Serialize, Deserialize, Debug)] -// pub enum WallpaperTool { -// Swaybg, -// Swww, -// Nitrogen, -// Feh, -// } - #[derive(Serialize, Deserialize, Debug)] pub struct Config { - pub reload_apps: Option, pub version_check: Option, - pub reload_apps_list: Option, pub wallpaper: Option, - // pub set_wallpaper: Option, - // pub wallpaper_tool: Option, - // pub swww_options: Option>, - pub feh_options: Option>, // TODO: Add a `Command` struct pub prefix: Option, pub custom_keywords: Option>, pub custom_colors: Option>, } -#[derive(Deserialize, Serialize, Debug)] -pub struct Apps { - pub kitty: Option, - pub waybar: Option, - pub gtk_theme: Option, - pub dunst: Option, - pub mako: Option, -} - #[derive(Serialize, Deserialize, Debug)] pub struct ConfigFile { pub config: Config, diff --git a/src/wallpaper/mod.rs b/src/wallpaper/mod.rs index 6b46bf2..a261724 100644 --- a/src/wallpaper/mod.rs +++ b/src/wallpaper/mod.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Wallpaper { pub set: bool, /// Useful for, for example, killing the wallpaper daemon @@ -10,7 +10,6 @@ pub struct Wallpaper { pub arguments: Option>, } - #[cfg(any(target_os = "linux", target_os = "netbsd"))] pub mod unix; diff --git a/src/wallpaper/unix.rs b/src/wallpaper/unix.rs index 291ace7..084dd7f 100644 --- a/src/wallpaper/unix.rs +++ b/src/wallpaper/unix.rs @@ -1,31 +1,24 @@ use color_eyre::Report; -use std::process::Command; -use std::process::Stdio; - -// use crate::reload::unix::reload_app; - +use std::process::{Command, Stdio}; +use crate::wallpaper::Wallpaper; use execute::Execute; #[cfg(any(target_os = "linux", target_os = "netbsd"))] pub fn set( path: &String, - wallpaper_cmd: &String, - pre_hook: &Option, - arguments: &Option>, + Wallpaper { pre_hook, command, arguments, .. }: Wallpaper, ) -> Result<(), Report> { + info!("Setting wallpaper..."); + if let Some(hook) = pre_hook { - spawn_hook(&hook)?//.unwrap(); + spawn_hook(hook)? } - info!("Setting wallpaper..."); - // match &wallpaper_tool { - // WallpaperTool::Swaybg => set_wallaper_swaybg(path), - // WallpaperTool::Swww => set_wallaper_swww(path, swww_options), - // WallpaperTool::Nitrogen => set_wallaper_nitrogen(path), - // WallpaperTool::Feh => set_wallaper_feh(path, feh_options), - // } - let mut binding = Command::new(wallpaper_cmd); - let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); + let mut binding = Command::new(&command); + let cmd = binding + .stdout(Stdio::null()) + .stderr(Stdio::null()); + if let Some(args) = arguments { cmd.args(args); } @@ -33,10 +26,10 @@ pub fn set( match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with {wallpaper_cmd}"), + Ok(_) => info!("Successfully set the wallpaper with {command}"), Err(e) => { if let std::io::ErrorKind::NotFound = e.kind() { - error!("Failed to set wallpaper, the program {wallpaper_cmd} was not found in PATH!") + error!("Failed to set wallpaper, the program {command} was not found in PATH!") } else { error!("Some error(s) occured while setting wallpaper!"); } @@ -48,8 +41,8 @@ pub fn set( #[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn spawn_hook(hook: &String) -> Result<(), Report> { - let mut command = execute::shell(hook); +fn spawn_hook(hook: String) -> Result<(), Report> { + let mut command = execute::shell(&hook); command.stdout(Stdio::inherit()); @@ -65,99 +58,3 @@ fn spawn_hook(hook: &String) -> Result<(), Report> { Ok(()) } -// #[cfg(any(target_os = "linux", target_os = "netbsd"))] -// fn set_wallaper_swaybg(path: &String) -> Result<(), Report> { -// reload_app("swaybg", "SIGUSR1")?; -// -// let mut binding = Command::new("swaybg"); -// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); -// cmd.arg("-i"); -// cmd.arg(path); -// -// match cmd.spawn() { -// Ok(_) => info!("Successfully set the wallpaper with swaybg"), -// Err(e) => { -// if let std::io::ErrorKind::NotFound = e.kind() { -// error!("Failed to set wallpaper, the program swaybg was not found in PATH!") -// } else { -// error!("Some error(s) occured while setting wallpaper!"); -// } -// } -// }; -// Ok(()) -// } -// -// #[cfg(any(target_os = "linux", target_os = "netbsd"))] -// fn set_wallaper_swww(path: &String, swww_options: &Option>) -> Result<(), Report> { -// let mut binding = Command::new("swww"); -// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); -// cmd.arg("img"); -// cmd.arg(path); -// -// if let Some(options) = &swww_options { -// if !options[0].is_empty() { -// cmd.args(options); -// } -// } -// -// match cmd.spawn() { -// Ok(_) => info!("Successfully set the wallpaper with swww"), -// Err(e) => { -// if let std::io::ErrorKind::NotFound = e.kind() { -// error!("Failed to set wallpaper, the program swww was not found in PATH!") -// } else { -// error!("Some error(s) occured while setting wallpaper!"); -// } -// } -// }; -// Ok(()) -// } -// -// #[cfg(any(target_os = "linux", target_os = "netbsd"))] -// fn set_wallaper_nitrogen(path: &String) -> Result<(), Report> { -// let mut binding = Command::new("nitrogen"); -// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); -// cmd.arg(path); -// -// match cmd.spawn() { -// Ok(_) => info!("Successfully set the wallpaper with nitrogen"), -// Err(e) => { -// if let std::io::ErrorKind::NotFound = e.kind() { -// error!( -// "Failed to set wallpaper, the program nitrogen was not found in PATH!" -// ) -// } else { -// error!("Some error(s) occured while setting wallpaper!"); -// } -// } -// }; -// Ok(()) -// } -// -// #[cfg(any(target_os = "linux", target_os = "netbsd"))] -// fn set_wallaper_feh(path: &String, feh_options: &Option>) -> Result<(), Report> { -// let mut binding = Command::new("feh"); -// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); -// -// if let Some(options) = &feh_options { -// if !options[0].is_empty() { -// cmd.args(options); -// } else { -// cmd.arg("--bg-scale"); -// } -// } -// -// cmd.arg(path); -// -// match cmd.spawn() { -// Ok(_) => info!("Successfully set the wallpaper with feh"), -// Err(e) => { -// if let std::io::ErrorKind::NotFound = e.kind() { -// error!("Failed to set wallpaper, the program feh was not found in PATH!") -// } else { -// error!("Some error(s) occured while setting wallpaper!"); -// } -// } -// }; -// Ok(()) -// } From 0e64f4f74cd212a9868cf8db71f7483adcced2ba Mon Sep 17 00:00:00 2001 From: YS5G Date: Fri, 18 Oct 2024 11:45:38 -0400 Subject: [PATCH 58/59] add DaniD3v's module updates --- module.nix | 236 +++++++++++------------------------------------------ 1 file changed, 49 insertions(+), 187 deletions(-) diff --git a/module.nix b/module.nix index 4397c34..e41931c 100644 --- a/module.nix +++ b/module.nix @@ -4,227 +4,89 @@ matugen: { lib, config, ... -} @ args: let +} @ inputs: let cfg = config.programs.matugen; - osCfg = args.osConfig.programs.matugen or {}; + osCfg = inputs.osConfig.programs.matugen or {}; - hexColorRegex = ''#([0-9a-fA-F]{3}){1,2}''; - hexStrippedColorRegex = ''([0-9a-fA-F]{3}){1,2}''; - rgbColorRegex = ''rgb\([0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}\)''; - rgbaColorRegex = ''rgba\([0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}, ?[0-9]{1,3}\)''; - hslColorRegex = ''hsl\([0-9]{1,3}(\.[0-9]*)?, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0-9]{1,3}(\.[0-9]*)?%\)''; - hslaColorRegex = ''hsla\([0-9]{1,3}(\.[0-9]*)?, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0-9]{1,3}(\.[0-9]*)?%, ?[0,1](\.[0-9]*)?\)''; - - hexColor = lib.types.strMatching hexColorRegex; - hexStrippedColor = lib.types.strMatching hexStrippedColorRegex; - rgbColor = lib.types.strMatching rgbColorRegex; - rgbaColor = lib.types.strMatching rgbaColorRegex; - hslColor = lib.types.strMatching hslColorRegex; - hslaColor = lib.types.strMatching hslaColorRegex; - - sourceColorType = lib.types.oneOf [hexColor rgbColor hslColor]; - customColorType = hexColor; # Only hexColor is currently supported for custom_colors. - - configFormat = pkgs.formats.toml {}; - - capitalize = str: let - inherit (builtins) substring stringLength; - firstChar = substring 0 1 str; - restOfString = substring 1 (stringLength str) str; - in - lib.concatStrings [(lib.toUpper firstChar) restOfString]; - - # don't use ~, use $HOME - sanitizedTemplates = - builtins.mapAttrs (_: v: { - mode = capitalize cfg.variant; - input_path = builtins.toString v.input_path; - output_path = builtins.replaceStrings ["$HOME"] ["~"] v.output_path; - }) - cfg.templates; - - matugenConfig = configFormat.generate "matugen-config.toml" { - config = { - custom_colors = cfg.custom_colors; - } // cfg.config; - templates = sanitizedTemplates; - }; - - # get matugen package - pkg = matugen.packages.${pkgs.system}.default; - - # takes in a source color string and returns the subcommand needed to generate - # a color scheme using that color type. - sourceColorTypeMatcher = color: (lib.lists.findSingle (p: null != builtins.match p.regex color) {} {} [ - { regex = hexColorRegex; code = "hex"; } - { regex = rgbColorRegex; code = "rgb"; } - { regex = hslColorRegex; code = "hsl"; } - ]).code; - - command = if (builtins.isNull cfg.source_color) then - "image ${cfg.wallpaper}" else - "color ${sourceColorTypeMatcher cfg.source_color} \"${cfg.source_color}\""; - - themePackage = builtins.trace command (pkgs.runCommandLocal "matugen-themes-${cfg.variant}" {} '' - mkdir -p $out - cd $out - export HOME=$(pwd) - - ${cfg.package}/bin/matugen \ - ${command} \ - --config ${matugenConfig} \ - --mode ${cfg.variant} \ - --type ${cfg.type} \ - --json ${cfg.jsonFormat} \ - --contrast ${lib.strings.floatToString cfg.contrast} \ - --quiet \ - > $out/theme.json - ''); - colors = (builtins.fromJSON (builtins.readFile "${themePackage}/theme.json")).colors; + tomlFormat = pkgs.formats.toml {}; in { options.programs.matugen = { enable = lib.mkEnableOption "Matugen declarative theming"; - package = - lib.mkPackageOption pkgs "matugen" {} - // { - default = pkg; - }; - - source_color = lib.mkOption { - description = "Hex color to generate the colorschemes from. If this and wallpaper are defined, will use this."; - type = lib.types.nullOr sourceColorType; - default = osCfg.source_color or null; - example = "#ff1243"; - }; - wallpaper = lib.mkOption { + type = with lib.types; nullOr path; + default = osCfg.wallpaper or null; + + example = "../wallpaper/astolfo.png"; description = "Path to `wallpaper` that matugen will generate the colorschemes from"; - type = lib.types.path; - default = osCfg.wallpaper or "${pkgs.nixos-artwork.wallpapers.simple-blue}/share/backgrounds/nixos/nix-wallpaper-simple-blue.png"; - defaultText = lib.literalExample '' - "${pkgs.nixos-artwork.wallpapers.simple-blue}/share/backgrounds/nixos/nix-wallpaper-simple-blue.png" - ''; }; templates = lib.mkOption { - type = with lib.types; - attrsOf (submodule { + type = with lib; + types.attrsOf (types.submodule { options = { - input_path = lib.mkOption { - type = path; - description = "Path to the template"; + input_path = mkOption { + type = types.path; + example = "./style.css"; + description = "Path to the template"; }; - output_path = lib.mkOption { - type = str; - description = "Path where the generated file will be written to"; - example = "~/.config/sytle.css"; + output_path = mkOption { + type = types.str; + + example = ".config/style.css"; + description = "Path relative to your homedirectory where the generated file will be written to"; }; }; }); default = osCfg.templates or {}; + description = '' Templates that have `@{placeholders}` which will be replaced by the respective colors. See for a list of colors. ''; }; - custom_colors = lib.mkOption { - description = "Other colors that should be included in the colorsheme."; - type = with lib.types; - attrsOf (submodule { - options = { - color = lib.mkOption { - description = "Color value for this custom color."; - type = customColorType; - example = "#d03e3e"; - }; - blend = lib.mkOption { - description = "Whether to pick a color close to the given value, or to pass the value through to the final colorscheme unchanged."; - type = bool; - default = true; - }; - }; - }); - default = osCfg.custom_colors or {}; - example = '' - { - light-red.color = "#d03e3e"; - light-orange.color = "#d7691d"; - light-yellow.color = "#ad8200"; + settings = lib.mkOption { + inherit (tomlFormat) type; + default = osCfg.settings or {}; - red = { - color = "#ff0000"; - blend = false; - }; + example = '' + config.reload_apps_list = { + gtk_theme = true; + kitty = true; } ''; - }; + description = '' + Matugen configuration file in nix syntax. - type = lib.mkOption { - description = "Palette used when generating the colorschemes."; - type = lib.types.enum ["scheme-content" "scheme-expressive" "scheme-fidelity" "scheme-fruit-salad" "scheme-monochrome" "scheme-neutral" "scheme-rainbow" "scheme-tonal-spot"]; - default = osCfg.palette or "scheme-tonal-spot"; - example = "scheme-content"; + Written to {file}`$XDG_CONFIG_HOME/matugen/config.toml` + A manual for configuring matugen can be found at . + ''; }; + }; - jsonFormat = lib.mkOption { - description = "Color format of the colorschemes."; - type = lib.types.enum ["rgb" "rgba" "hsl" "hsla" "hex" "strip"]; - default = osCfg.jsonFormat or "strip"; - example = "rgba"; - }; + config = let + package = matugen.packages.${pkgs.system}.default; - variant = lib.mkOption { - description = "Colorscheme variant."; - type = lib.types.enum ["light" "dark" "amoled"]; - default = osCfg.variant or "dark"; - example = "light"; - }; + mergedCfg = + cfg.settings + // ( + if cfg.templates != {} + then {inherit (cfg) templates;} + else {} + ); - contrast = lib.mkOption { - description = "Value from -1 to 1. -1 represents minimum contrast, 0 represents standard (i.e. the design as spec'd), and 1 represents maximum contrast."; - type = lib.types.numbers.between (-1) 1; - default = 0; - example = "0.2"; - }; + configFile = tomlFormat.generate "config.toml" mergedCfg; + in + lib.mkIf cfg.enable { + home.packages = [package]; - config = lib.mkOption { - description = "Add things to the config not covered by other options."; - type = lib.types.attrs; - default = osCfg.config or {}; - example = '' - { - custom_keywords.font1 = "Google Sans"; - } + home.activation.matugenCopyWallpapers = lib.hm.dag.entryAfter ["writeBoundary"] '' + ${package}/bin/matugen image ${cfg.wallpaper} --config ${configFile} ''; - }; - theme.files = lib.mkOption { - type = lib.types.package; - readOnly = true; - default = - if builtins.hasAttr "templates" osCfg - then - if cfg.templates != osCfg.templates - then themePackage - else osCfg.theme.files - else themePackage; - description = "Generated theme files. Including only the variant chosen."; + xdg.configFile."matugen/config.toml".source = + lib.mkIf (mergedCfg != {}) configFile; }; - - theme.colors = lib.mkOption { - inherit (pkgs.formats.json {}) type; - readOnly = true; - default = - if builtins.hasAttr "templates" osCfg - then - if cfg.templates != osCfg.templates - then colors - else osCfg.theme.colors - else colors; - description = "Generated theme colors. Includes all variants."; - }; - }; } From 4e9021c1548079809b27a55fcf4bea1d1770c562 Mon Sep 17 00:00:00 2001 From: ys5g <136090707+ys5g@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:14:17 -0400 Subject: [PATCH 59/59] feat(nix): allow the user to specify the package being used --- module.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/module.nix b/module.nix index e41931c..0eb0c33 100644 --- a/module.nix +++ b/module.nix @@ -13,6 +13,10 @@ in { options.programs.matugen = { enable = lib.mkEnableOption "Matugen declarative theming"; + package = lib.mkPackageOption pkgs "matugen" { + default = matugen.packages.${pkgs.system}.default; + }; + wallpaper = lib.mkOption { type = with lib.types; nullOr path; default = osCfg.wallpaper or null; @@ -67,8 +71,6 @@ in { }; config = let - package = matugen.packages.${pkgs.system}.default; - mergedCfg = cfg.settings // ( @@ -80,10 +82,10 @@ in { configFile = tomlFormat.generate "config.toml" mergedCfg; in lib.mkIf cfg.enable { - home.packages = [package]; + home.packages = [cfg.package]; home.activation.matugenCopyWallpapers = lib.hm.dag.entryAfter ["writeBoundary"] '' - ${package}/bin/matugen image ${cfg.wallpaper} --config ${configFile} + ${cfg.package}/bin/matugen image ${cfg.wallpaper} --config ${configFile} ''; xdg.configFile."matugen/config.toml".source =