Pi66

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

← back to log

add new opetions and make it more faster

author: pixel2175
date: 2025-06-23 18:52
hash: 8779fb342a03896f74e276cb8435abd71382d9f1

Diffstat:

M

Cargo.lock
2 -

M

Cargo.toml
2 -

M

src/get_colors.rs
8 ++-

M

src/main.rs
51 ++++++++++++++++-----

M

src/reload.rs
74 +++++++++++++++---------------

M

src/theme.rs
4 +-
  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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
diff --git a/Cargo.lock b/Cargo.lock
index 784cc54..9829dd6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1226,7 +1226,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"

 [[package]]
 name = "walrs"
-version = "1.1.5"
+version = "1.1.6"
 dependencies = [
  "argh",
  "color-thief",
diff --git a/Cargo.toml b/Cargo.toml
index eb9912a..98b9eec 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "walrs"
-version = "1.1.6"
+version = "1.1.7"
 edition = "2024"
 description = "walrs - Generate colorscheme from image."
 license = "GPL-3.0" 
diff --git a/src/get_colors.rs b/src/get_colors.rs
index f6caef5..9a28a56 100644
--- a/src/get_colors.rs
+++ b/src/get_colors.rs
@@ -70,7 +70,7 @@ fn kmeans_colors(len: u8, native_rgba: &RgbaImage) -> Vec<(u8, u8, u8)> {

 fn color_thief_colors(len: u8, native_rgba: &RgbaImage) -> Vec<(u8, u8, u8)> {
     let palette_extract = palette_extract::get_palette_with_options(
-        &native_rgba,
+        native_rgba,
         palette_extract::PixelEncoding::Rgba,
         Quality::new(5),
         MaxColors::new(len),
@@ -84,7 +84,7 @@ fn color_thief_colors(len: u8, native_rgba: &RgbaImage) -> Vec<(u8, u8, u8)> {
 }

 fn palette_extract_colors(len: u8, native_rgba: &RgbaImage, send: bool) -> Vec<(u8, u8, u8)> {
-    let palette_thief = color_thief::get_palette(&native_rgba, ColorFormat::Rgba, 5, len)
+    let palette_thief = color_thief::get_palette(native_rgba, ColorFormat::Rgba, 5, len)
         .unwrap_or_else(|_| {
             warning("Backend", "palette thief can't extract the palette", send);
             exit(1)
@@ -166,8 +166,8 @@ pub fn get_colors(
     };

     let image = core_image.resize(
-        400,
-        (core_image.height() as f32 * (400_f32 / core_image.width() as f32)) as u32,
+        250,
+        (core_image.height() as f32 * (250_f32 / core_image.width() as f32)) as u32,
         image::imageops::FilterType::Lanczos3,
     );

diff --git a/src/main.rs b/src/main.rs
index 42c2454..7b88527 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,7 +13,6 @@ use std::fs::{copy, create_dir_all};
 use std::process::exit;
 use theme::{print_themes, set_theme, theme_exists};
 use utils::*;
-use wallpaper::change_wallpaper;

 #[derive(FromArgs)]
 #[argh(description = "walrs - Generate colorscheme from image")]
@@ -21,7 +20,7 @@ struct Arg {
     #[argh(
         option,
         short = 'i',
-        description = "path/to/your/wal.png | path/to/your/wallpapers/"
+        description = "path/to/your/wal.png | path/to/your/wallpapers/ | this will change the wallpaper"
     )]
     image: Option<String>,

@@ -39,12 +38,11 @@ struct Arg {
         description = "reload without changing the wallpaper"
     )]
     reload: bool,
-
     #[argh(
         switch,
         short = 'R',
         long = "reload-no",
-        description = "reload with changing the wallpaper"
+        description = "this will removed next update use -w instead"
     )]
     reload_no: bool,

@@ -80,6 +78,22 @@ struct Arg {
     )]
     brightness: Option<i8>,

+    #[argh(
+        switch,
+        short = 'S',
+        long = "scripts",
+        description = "this will skip runing the scripts in ~/.config/walrs/scripts/"
+    )]
+    run_scripts: Option<bool>,
+
+    #[argh(
+        switch,
+        short = 'W',
+        long = "wallpaperless",
+        description = "this will skip changing the wallpaper"
+    )]
+    wallpaperless: Option<bool>,
+
     #[argh(
         switch,
         short = 'q',
@@ -108,15 +122,24 @@ fn main() {
         exit(0);
     }

-    // reload colors without setting wallpaper
+    // this will be removed next update
     if arg.reload_no {
-        reload(send, true);
+        warning(
+            "Reload",
+            "this will be removed in the next update, use -W instead\n",
+            send,
+        );
+        reload(send, true, arg.run_scripts.unwrap_or(false));
         exit(0);
     }

     // reload colors with setting wallpaper
     if arg.reload {
-        reload(send, false);
+        reload(
+            send,
+            arg.wallpaperless.unwrap_or(false),
+            arg.run_scripts.unwrap_or(false),
+        );
         exit(0);
     }

@@ -132,12 +155,12 @@ fn main() {
         if v == "themes" {
             print_themes(send);
         } else if theme_exists(&config) {
-            set_theme(v, send);
+            set_theme(v, send, arg.run_scripts.unwrap_or(false));
         } else {
             let colorschemes_dir = config.join("walrs").join("colorschemes");
             create_dir_all(&colorschemes_dir).unwrap();
             let walrs_cache = share_files();
-            if !theme_exists(&walrs_cache.parent().unwrap()) {
+            if !theme_exists(walrs_cache.parent().unwrap()) {
                 warning("theme", "Can't find configuration directory", send);
                 exit(1)
             }
@@ -146,7 +169,7 @@ fn main() {
                 walrs_cache.join("colorschemes").display(),
                 colorschemes_dir.display()
             ));
-            set_theme(v, send);
+            set_theme(v, send, arg.run_scripts.unwrap_or(false));
         }
         exit(0);
     }
@@ -173,8 +196,12 @@ fn main() {
         create_template(palette, &image_path, send);
         info("Template", "create templates", send);

-        change_wallpaper(&image_path, send);
-        reload(send, false);
+        // change_wallpaper(&image_path, send);
+        reload(
+            send,
+            arg.wallpaperless.unwrap_or(false),
+            arg.run_scripts.unwrap_or(false),
+        );
         print_colors(send);
     };
 }
diff --git a/src/reload.rs b/src/reload.rs
index ce29afe..77fbdb4 100644
--- a/src/reload.rs
+++ b/src/reload.rs
@@ -55,7 +55,7 @@ pub fn get_wallpaper(cache: &Path, send: bool) -> String {
         .to_string()
 }

-pub fn reload(send: bool, set_wal: bool) {
+pub fn reload(send: bool, set_wal: bool, run_scripts: bool) {
     let cache = get_cache(send).join("wal");
     let walrs_cache = share_files();
     let file_path = cache.join("colors");
@@ -71,53 +71,55 @@ pub fn reload(send: bool, set_wal: bool) {
         .collect();

     // applie the wallpaper
-    if set_wal {
+    if !set_wal {
         change_wallpaper(&get_wallpaper(&cache, send), send);
     }

     // change terminal colors
     colors(lines, send);

-    // initial scripts files
-    let scripts_dir = get_config(send).join("walrs").join("scripts");
-    if !scripts_dir.exists() {
-        match create_dir_all(&scripts_dir) {
-            Ok(_) => {
-                run(&format!(
-                    "cp -r {}/* {}",
-                    walrs_cache.join("scripts").display(),
-                    scripts_dir.display()
-                ));
+    if !run_scripts {
+        // initial scripts files
+        let scripts_dir = get_config(send).join("walrs").join("scripts");
+        if !scripts_dir.exists() {
+            match create_dir_all(&scripts_dir) {
+                Ok(_) => {
+                    run(&format!(
+                        "cp -r {}/* {}",
+                        walrs_cache.join("scripts").display(),
+                        scripts_dir.display()
+                    ));
+                }
+                Err(_) => return,
             }
-            Err(_) => return,
         }
-    }

-    // read the scripts directory and run them
-    match read_dir(scripts_dir) {
-        Ok(v) => {
-            for scr in v {
-                let script = scr.unwrap().path();
-                if !script.is_file() {
-                    continue;
-                };
-                if !run(&format!(
-                    "bash {}",
-                    &script.canonicalize().unwrap().to_string_lossy()
-                )) {
-                    warning(
-                        "Script",
-                        &format!(
-                            "can't run {}",
-                            script.file_name().unwrap().to_string_lossy()
-                        ),
-                        send,
-                    );
+        // read the scripts directory and run them
+        match read_dir(scripts_dir) {
+            Ok(v) => {
+                for scr in v {
+                    let script = scr.unwrap().path();
+                    if !script.is_file() {
+                        continue;
+                    };
+                    if !run(&format!(
+                        "bash {}",
+                        &script.canonicalize().unwrap().to_string_lossy()
+                    )) {
+                        warning(
+                            "Script",
+                            &format!(
+                                "can't run {}",
+                                script.file_name().unwrap().to_string_lossy()
+                            ),
+                            send,
+                        );
+                    }
                 }
+                info("Scripts", "scripts runs successfully", send);
             }
-            info("Scripts", "scripts runs successfully", send);
+            _ => return,
         }
-        _ => return,
     }
     info("Colors", "colorscheme applied successfully", send);
 }
diff --git a/src/theme.rs b/src/theme.rs
index 5d5aa55..f4356bd 100644
--- a/src/theme.rs
+++ b/src/theme.rs
@@ -52,7 +52,7 @@ fn hex_to_rgb(file: Vec<String>) -> Vec<(u8, u8, u8)> {
         .unwrap()
 }

-pub fn set_theme(theme_name: String, send: bool) {
+pub fn set_theme(theme_name: String, send: bool, scripts: bool) {
     let base = get_config(send);
     let mut theme: Vec<String> = ["dark", "light"]
         .iter()
@@ -87,7 +87,7 @@ pub fn set_theme(theme_name: String, send: bool) {
         let rgb_colors = hex_to_rgb(file);

         create_template((rgb_colors, 100), "None", send);
-        reload(send, false);
+        reload(send, false, !scripts);
     } else {
         warning("Theme", "Can't find theme", send);
         exit(1)