Pi66

Home | Repos | About | Blog | Gaza

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

About | Files | Commits | Refs | License


add new opetions and make it more faster

Author: pixel2175
Date: 2025-06-23 18:52
commit: 8779fb34

Stat

M Cargo.lock 2 +1 -1
M Cargo.toml 2 +1 -1
M src/get_colors.rs 8 +4 -4
M src/main.rs 51 +39 -12
M src/reload.rs 74 +38 -36
M src/theme.rs 4 +2 -2

Diff

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" ...

Show all

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&#95;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&#95;template((rgb&#95;colors, 100), &#34;None&#34;, send);

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

// Created by Pi66

// Copyright ©Pi66 2026