Pi66

walrs
pywal but if its Fast-Minimal-Simple
git clone https://git.pi66.xyz/walrs

← back to log

1.0.5

author: pixel
date: 2025-04-14 18:39
hash: aefe17a13bc6ef895f3d35582a5b0d7be8978edd

Diffstat:

M

Cargo.lock
2 -

M

Cargo.toml
2 -

M

src/main.rs
111 ++++++++++++++++--------------
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
diff --git a/Cargo.lock b/Cargo.lock
index daef4d4..1b12b94 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1061,7 +1061,7 @@ checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b"

 [[package]]
 name = "walrs"
-version = "1.0.4"
+version = "1.0.5"
 dependencies = [
  "clap",
  "color-thief",
diff --git a/Cargo.toml b/Cargo.toml
index d1459d2..409fc1c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "walrs"
-version = "1.0.4"
+version = "1.0.5"
 edition = "2024"
 description = "walrs is a fast color scheme generator."
 license = "GPL" 
diff --git a/src/main.rs b/src/main.rs
index 6811192..c8a0b55 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,8 @@
 mod get_colors;
 mod create_templates;
 mod reload;
-mod wallpaper;
 mod utils;
-
+mod wallpaper;

 use reload::reload;
 use create_templates::create_template;
@@ -14,13 +13,13 @@ use std::process::exit;
 use utils::*;

 #[derive(Parser, Debug)]
-#[command(name = "walrs",version="v1.0.4-2",about= "walrs - Generate colorscheme from image")]
+#[command(name = "walrs",version="v1.0.5",about= "walrs - Generate colorscheme from image")]
 struct Arg {
     /// path/to/your/wal.png
     #[arg(short = 'i')]
     image: Option<String>,

-    
+
     /// generate colors and save it into .cache/wal 
     #[arg(short = 'g')]
     generate: Option<String>,
@@ -38,20 +37,51 @@ struct Arg {
     quit: bool,


-    /// specify the saturation value 
-    #[arg(short = 's')]
+    /// specify the saturation value -128 => 127
+    #[arg(short = 's', allow_hyphen_values = true)]
     saturation: Option<i8>,


-    /// specify the brightness value
-    #[arg(short = 'b')]
+    /// specify the brightness value -128 => 127
+    #[arg(short = 'b', allow_hyphen_values = true)]
     brightness: Option<i8>,

+}


-
+fn image_path(image:Option<String>,send:bool) -> String{
+    match image {
+        Some(ref v) if Path::new(v).exists() => match get_absolute_path(v) {
+            Some(p) => {
+                if Path::new(&p).is_file() {
+                    p
+                }else {
+                    std::str::from_utf8(&std::process::Command::new("sh").arg("-c").arg(format!("find \"{}\" -type f | sort -R | head -n1", p)).output().unwrap().stdout).unwrap().trim().to_string()
+                }
+                
+
+            } ,
+            None => {
+                warning("Wallpaper", "Can't find wallpaper absolute path!", send);
+                exit(1);
+            }
+        },
+        Some(_) => {
+            warning("Image", "Image does not exist", send);
+            exit(1);
+        }
+        None => {
+            warning("Image", "Can't find Image", send);
+            exit(1);
+        }
+    }
 }

+
+
+
+
+
 fn main() {
     let arg = Arg::parse();

@@ -73,54 +103,29 @@ fn main() {
         exit(1);
     }

-    match arg.generate {
-        Some(ref v) if Path::new(v).exists() => match get_absolute_path(v) {
-            Some(p) => {
-                let palette = get_colors(&p, !arg.quit,arg.brightness,arg.saturation);
-                info("Generate", "generate colors", !arg.quit);
-
-                create_template(palette, &p);
-                info("Template", "create templates", !arg.quit);
-                exit(0)
-            },
-            None => {
-                warning("Wallpaper", "Can't find wallpaper absolute path!", !arg.quit);
-                exit(1);
-            }
-        },
-        Some(_) => {
-            warning("Image", "Image does not exist", !arg.quit);
-            exit(1);
-        }
-        None => {}
-    }
+    if arg.generate.is_some() {
+        let image_path = image_path(arg.generate,!arg.quit);
+        let palette = get_colors(&image_path, !arg.quit,arg.brightness,arg.saturation);
+        info("Generate", "generate colors", !arg.quit);

-    let image_path = match arg.image {
-        Some(ref v) if Path::new(v).exists() => match get_absolute_path(v) {
-            Some(p) => p,
-            None => {
-                warning("Wallpaper", "Can't find wallpaper absolute path!", !arg.quit);
-                exit(1);
-            }
-        },
-        Some(_) => {
-            warning("Image", "Image does not exist", !arg.quit);
-            exit(1);
-        }
-        None => {
-            warning("Image", "Can't find Image", !arg.quit);
-            exit(1);
-        }
+        create_template(palette, &image_path);
+        info("Template", "create templates", !arg.quit);
+        exit(0)
     };

-    let palette = get_colors(&image_path, !arg.quit,arg.brightness,arg.saturation);
-    info("Generate", "generate colors", !arg.quit);

-    create_template(palette, &image_path);
-    info("Template", "create templates", !arg.quit);

-    reload(!arg.quit,true);
+    if arg.image.is_some() {
+        let image_path = image_path(arg.image,!arg.quit);

-    print_colors(!arg.quit);
-}
+        let palette = get_colors(&image_path, !arg.quit,arg.brightness,arg.saturation);
+        info("Generate", "generate colors", !arg.quit);
+
+        create_template(palette, &image_path);
+        info("Template", "create templates", !arg.quit);
+
+        reload(!arg.quit,true);
+        print_colors(!arg.quit);

+    };
+}