Pi66

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

← back to log

1.0.6

author: pixel
date: 2025-04-29 16:23
hash: 38e39ea5f5ce4cf0cdb9ea90b3af1919f17d15c9

Diffstat:

M

src/create_templates.rs
73 ++++++++++------

M

src/get_colors.rs
100 +++++++++++-----------

M

src/main.rs
62 +++++++-------

M

src/reload.rs
110 ++++++++++++++----------

M

src/utils.rs
18 ++--

M

src/wallpaper.rs
136 +++++++++++++++++-------------
   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
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
diff --git a/src/create_templates.rs b/src/create_templates.rs
index 9664275..879d019 100644
--- a/src/create_templates.rs
+++ b/src/create_templates.rs
@@ -1,9 +1,9 @@
-use std::fs::{self, create_dir_all, read_to_string, write};
 use crate::utils::{get_cache_folder, get_config_folder};
+use std::fs::{self, create_dir_all, read_to_string, write};

 fn change(template: &str, colors: (u8, u8, u8), alpha: u8) -> String {
     let (r, g, b) = colors;
-    
+
     if template.contains(".strip") {
         format!("{:02x}{:02x}{:02x}", r, g, b)
     } else if template.contains(".xrgba") {
@@ -21,15 +21,24 @@ fn change(template: &str, colors: (u8, u8, u8), alpha: u8) -> String {
     }
 }

-fn fill_template(template_name: &str, template: &str, colors: &(Vec<(u8, u8, u8)>, u8), wallpaper: &str) {
-    let output_path = format!("{}/wal/{}", get_cache_folder().expect("Can't find cache folder"), template_name);
+fn fill_template(
+    template_name: &str,
+    template: &str,
+    colors: &(Vec<(u8, u8, u8)>, u8),
+    wallpaper: &str,
+) {
+    let output_path = format!(
+        "{}/wal/{}",
+        get_cache_folder().expect("Can't find cache folder"),
+        template_name
+    );
     let alpha = colors.1;
-    
+
     let mut result = template
         .replace("{wallpaper}", wallpaper)
         .replace("{alpha}", &format!("{}", (alpha / 255) * 100));
-    
-    if !colors.0.is_empty()  {
+
+    if !colors.0.is_empty() {
         let background_patterns = [
             "{background.strip}",
             "{background.xrgba}",
@@ -38,13 +47,13 @@ fn fill_template(template_name: &str, template: &str, colors: &(Vec<(u8, u8, u8)
             "{background.alpha}",
             "{background}",
         ];
-        
+
         for pattern in background_patterns {
             let replacement = change(pattern, colors.0[0], alpha);
             result = result.replace(pattern, &replacement);
         }
     }
-    
+
     if colors.0.len() > 7 {
         let foreground_patterns = [
             "{foreground.strip}",
@@ -54,12 +63,12 @@ fn fill_template(template_name: &str, template: &str, colors: &(Vec<(u8, u8, u8)
             "{foreground.alpha}",
             "{foreground}",
         ];
-        
+
         for pattern in foreground_patterns {
             let replacement = change(pattern, colors.0[7], alpha);
             result = result.replace(pattern, &replacement);
         }
-        
+
         let cursor_patterns = [
             "{cursor.strip}",
             "{cursor.xrgba}",
@@ -68,16 +77,16 @@ fn fill_template(template_name: &str, template: &str, colors: &(Vec<(u8, u8, u8)
             "{cursor.alpha}",
             "{cursor}",
         ];
-        
+
         for pattern in cursor_patterns {
             let replacement = change(pattern, colors.0[7], alpha);
             result = result.replace(pattern, &replacement);
         }
     }
-    
+
     for i in 0..colors.0.len().min(16) {
         let color = colors.0[i];
-        
+
         let patterns = [
             format!("{{color{}.strip}}", i),
             format!("{{color{}.xrgba}}", i),
@@ -87,21 +96,23 @@ fn fill_template(template_name: &str, template: &str, colors: &(Vec<(u8, u8, u8)
             format!("{{color{}.alpha}}", i),
             format!("{{color{}}}", i),
         ];
-        
+
         for pattern in patterns {
             let replacement = change(&pattern, color, alpha);
             result = result.replace(&pattern, &replacement);
         }
     }
-    
+
     if result.contains("{checksum}") {
-        let checksum = colors.0.iter()
+        let checksum = colors
+            .0
+            .iter()
             .map(|(r, g, b)| format!("{:02X}{:02X}{:02X}", r, g, b))
             .collect::<Vec<String>>()
             .join("");
         result = result.replace("{checksum}", &checksum);
     }
-    
+
     write(output_path, result).expect("Failed to write filled template");
 }

@@ -110,34 +121,42 @@ pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str) {
     let user_template_path = format!("{}/walrs/templates/", get_config_folder().unwrap());
     let cache_path = format!("{}/wal/", get_cache_folder().unwrap());
     let _ = create_dir_all(&cache_path);
-    
+
     // Check if user templates directory exists and has templates
     let mut has_user_templates = false;
     if let Ok(entries) = fs::read_dir(&user_template_path) {
         for entry in entries.flatten() {
             if entry.path().is_file() {
                 has_user_templates = true;
-                let Ok(content) = read_to_string(entry.path()) else { continue };
-                let Some(name) = entry.file_name().into_string().ok() else { continue };
+                let Ok(content) = read_to_string(entry.path()) else {
+                    continue;
+                };
+                let Some(name) = entry.file_name().into_string().ok() else {
+                    continue;
+                };
                 fill_template(&name, &content, &colors, wallpaper);
             }
         }
     }
-    
+
     // If no user templates, copy from system templates
     if !has_user_templates {
         let _ = create_dir_all(&user_template_path);
-        
+
         if let Ok(entries) = fs::read_dir(system_template_path) {
             for entry in entries.flatten() {
                 if entry.path().is_file() {
-                    let Ok(content) = read_to_string(entry.path()) else { continue };
-                    let Some(name) = entry.file_name().into_string().ok() else { continue };
-                    
+                    let Ok(content) = read_to_string(entry.path()) else {
+                        continue;
+                    };
+                    let Some(name) = entry.file_name().into_string().ok() else {
+                        continue;
+                    };
+
                     // Copy template to user directory
                     let user_file_path = format!("{}{}", user_template_path, name);
                     let _ = write(&user_file_path, &content);
-                    
+
                     fill_template(&name, &content, &colors, wallpaper);
                 }
             }
diff --git a/src/get_colors.rs b/src/get_colors.rs
index dd1826e..3d755f6 100644
--- a/src/get_colors.rs
+++ b/src/get_colors.rs
@@ -1,18 +1,21 @@
+use crate::utils::warning;
 use color_thief::ColorFormat;
+use kmeans_colors::get_kmeans;
 use palette::{FromColor, IntoColor, Lab, Srgb};
-use palette_extract::{MaxColors, Quality,};
+use palette_extract::{MaxColors, Quality};
 use std::collections::HashSet;
-use std::process::exit;
 use std::fs::read;
-use crate::utils::warning;
-use kmeans_colors::get_kmeans;
+use std::process::exit;

 fn adjust_rgb(r: u8, g: u8, b: u8, brightness: i8, saturation: i8) -> (u8, u8, u8) {
     let avg = ((r as u16 + g as u16 + b as u16) / 3) as f32;

-    let r = ((r as f32 - avg) * (saturation as f32 / 100.0) + avg + brightness as f32).clamp(0.0, 255.0);
-    let g = ((g as f32 - avg) * (saturation as f32 / 100.0) + avg + brightness as f32).clamp(0.0, 255.0);
-    let b = ((b as f32 - avg) * (saturation as f32 / 100.0) + avg + brightness as f32).clamp(0.0, 255.0);
+    let r = ((r as f32 - avg) * (saturation as f32 / 100.0) + avg + brightness as f32)
+        .clamp(0.0, 255.0);
+    let g = ((g as f32 - avg) * (saturation as f32 / 100.0) + avg + brightness as f32)
+        .clamp(0.0, 255.0);
+    let b = ((b as f32 - avg) * (saturation as f32 / 100.0) + avg + brightness as f32)
+        .clamp(0.0, 255.0);

     (r as u8, g as u8, b as u8)
 }
@@ -23,7 +26,6 @@ fn remove_duplicates(colors: Vec<(u8, u8, u8)>) -> Vec<(u8, u8, u8)> {
 }

 fn to_gray(r: u8, g: u8, b: u8, v: u8) -> (u8, u8, u8) {
-
     let mut gray = (0.3 * r as f32 + 0.59 * g as f32 + 0.11 * b as f32).round() as u8;
     gray = gray.saturating_add(v);
     (gray, gray, gray)
@@ -33,8 +35,12 @@ fn generate_variation(color: (u8, u8, u8), offset: i8) -> (u8, u8, u8) {
     adjust_rgb(color.0, color.1, color.2, offset, 50)
 }

-pub fn get_colors(image_path: &str,send:bool,brightness: Option<i8>,saturation: Option<i8> ) -> (Vec<(u8,u8,u8)>,u8){
-
+pub fn get_colors(
+    image_path: &str,
+    send: bool,
+    brightness: Option<i8>,
+    saturation: Option<i8>,
+) -> (Vec<(u8, u8, u8)>, u8) {
     let core_image = match image::open(image_path) {
         Ok(img) => img,
         Err(_) => {
@@ -49,46 +55,40 @@ pub fn get_colors(image_path: &str,send:bool,brightness: Option<i8>,saturation:
         }
     };

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

-
     let native_rgba = image.to_rgba8();
     let alpha = &native_rgba.get_pixel(0, 0)[3];
-    let mut collect_rgb:Vec<(u8,u8,u8)> = Vec::new();
-    
-    let pixels_kmeans: Vec<Lab> = native_rgba.pixels()
-        .filter(|p| p.0[3] > 0)  // Filter out transparent pixels
+    let mut collect_rgb: Vec<(u8, u8, u8)> = Vec::new();
+
+    let pixels_kmeans: Vec<Lab> = native_rgba
+        .pixels()
+        .filter(|p| p.0[3] > 0) // Filter out transparent pixels
         .map(|p| {
             // Convert RGBA to Srgb (ignore alpha for clustering)
             let srgb = Srgb::new(
                 p.0[0] as f32 / 255.0,
                 p.0[1] as f32 / 255.0,
                 p.0[2] as f32 / 255.0,
-            ).into_linear();
+            )
+            .into_linear();
             // Convert to LAB for perceptual accuracy
             srgb.into_color()
         })
         .collect();

-    let palette_kmeans: Vec<Srgb>  = get_kmeans(
-        10,
-        20,
-        1.0,
-        false,
-        &pixels_kmeans,
-        0,).centroids
+    let palette_kmeans: Vec<Srgb> = get_kmeans(10, 20, 1.0, false, &pixels_kmeans, 0)
+        .centroids
         .iter()
         .map(|&lab| Srgb::from_color(lab))
         .collect();

-
-for color in &palette_kmeans {
+    for color in &palette_kmeans {
         let (r, g, b) = (
             (color.red * 255.0).round() as u8,
             (color.green * 255.0).round() as u8,
@@ -97,22 +97,20 @@ for color in &palette_kmeans {
         collect_rgb.push((r, g, b))
     }

-
-
     let palette_extract = palette_extract::get_palette_with_options(
         &native_rgba,
         palette_extract::PixelEncoding::Rgba,
         Quality::new(5),
         MaxColors::new(10),
-        palette_extract::PixelFilter::White
+        palette_extract::PixelFilter::White,
     );
-    let palette_thief = color_thief::get_palette(&native_rgba,ColorFormat::Rgba, 5,10);
+    let palette_thief = color_thief::get_palette(&native_rgba, ColorFormat::Rgba, 5, 10);

-   for color in &palette_extract{
+    for color in &palette_extract {
         collect_rgb.push((color.r, color.g, color.b));
     }

-    if let Ok(ref colors) = palette_thief{
+    if let Ok(ref colors) = palette_thief {
         for color in colors {
             collect_rgb.push((color.r, color.g, color.b));
         }
@@ -134,25 +132,27 @@ for color in &palette_kmeans {
         lum_a.partial_cmp(&lum_b).unwrap()
     });

-    let colors = [0, 13, 15, 16, 17, 21, 20, 19, 9,13,15,16,17,21,20,19];
-        
-    let mut done:Vec<(u8,u8,u8)> = Vec::new();
+    let colors = [0, 13, 15, 16, 17, 21, 20, 19, 9, 13, 15, 16, 17, 21, 20, 19];

-    for color in colors{
-        let  (mut r, mut g, mut b) = collect_rgb[color];
-        (r,g,b) = adjust_rgb(r, g, b,brightness.unwrap_or(0)-15,saturation.unwrap_or(0) + 80);
-        done.push((r,g,b));
-    }
-
-    let (mut r,mut g,mut b) =  collect_rgb[20];
-    (r,g,b) = adjust_rgb(r,g,b,40,60);
-    (r,g,b) = to_gray(r, g, b, 15);
-    done[7] =  (r,g,b);
-    done[15] = (r,g,b);
+    let mut done: Vec<(u8, u8, u8)> = Vec::new();

+    for color in colors {
+        let (mut r, mut g, mut b) = collect_rgb[color];
+        (r, g, b) = adjust_rgb(
+            r,
+            g,
+            b,
+            brightness.unwrap_or(0) - 15,
+            saturation.unwrap_or(0) + 80,
+        );
+        done.push((r, g, b));
+    }

+    let (mut r, mut g, mut b) = collect_rgb[20];
+    (r, g, b) = adjust_rgb(r, g, b, 40, 60);
+    (r, g, b) = to_gray(r, g, b, 15);
+    done[7] = (r, g, b);
+    done[15] = (r, g, b);

-    (done,*alpha)
-    
+    (done, *alpha)
 }
-
diff --git a/src/main.rs b/src/main.rs
index bf89f60..4ac8f21 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,26 +1,29 @@
-mod get_colors;
 mod create_templates;
+mod get_colors;
 mod reload;
 mod utils;
 mod wallpaper;

-use reload::reload;
+use clap::{ArgAction, CommandFactory, Parser};
 use create_templates::create_template;
 use get_colors::get_colors;
-use clap::{ArgAction, CommandFactory, Parser};
+use reload::reload;
 use std::path::Path;
 use std::process::exit;
 use utils::*;

 #[derive(Parser, Debug)]
-#[command(name = "walrs",version="v1.0.6",about= "walrs - Generate colorscheme from image")]
+#[command(
+    name = "walrs",
+    version = "v1.0.6",
+    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 
+    /// generate colors and save it into .cache/wal
     #[arg(short = 'g')]
     generate: Option<String>,

@@ -36,31 +39,35 @@ struct Arg {
     #[arg(short = 'q', action = ArgAction::SetTrue)]
     quit: bool,

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

-
     /// 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{
+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()
+                } 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);
@@ -77,25 +84,19 @@ fn image_path(image:Option<String>,send:bool) -> String{
     }
 }

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

     if arg.reload_nowal {
-        reload(!arg.quit,true);
+        reload(!arg.quit, true);
         exit(0);
     }

     if arg.reload {
-        reload(!arg.quit,false);
+        reload(!arg.quit, false);
         exit(0);
     }

-
     if arg.image.is_none() && arg.generate.is_none() {
         let mut cmd = Arg::command();
         let _ = cmd.print_help();
@@ -103,8 +104,8 @@ fn main() {
     }

     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);
+        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);

         create_template(palette, &image_path);
@@ -112,19 +113,16 @@ fn main() {
         exit(0)
     };

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

-        let palette = get_colors(&image_path, !arg.quit,arg.brightness,arg.saturation);
+        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);
+        reload(!arg.quit, true);
         print_colors(!arg.quit);
-
     };
 }
diff --git a/src/reload.rs b/src/reload.rs
index b1e5c0a..cdf3aad 100644
--- a/src/reload.rs
+++ b/src/reload.rs
@@ -1,13 +1,12 @@
-use std::fs::{read_dir, read_to_string};
-use std::process::{Command, Stdio};
 use std::fs::OpenOptions;
+use std::fs::{read_dir, read_to_string};
 use std::io::Write;
 use std::process::exit;
+use std::process::{Command, Stdio};

 use crate::wallpaper;

-
-use crate::utils::{get_cache_folder,info,warning};
+use crate::utils::{get_cache_folder, info, warning};

 fn run(command: &str) -> bool {
     Command::new("sh")
@@ -20,78 +19,92 @@ fn run(command: &str) -> bool {
         .unwrap_or(false)
 }

-fn tty(cache:&str) {
+fn tty(cache: &str) {
     let path = format!("{}/wal/colors-tty.sh", cache);
-    if Command::new("tty").arg("-s").status().map(|s| s.success()).unwrap_or(false) {
+    if Command::new("tty")
+        .arg("-s")
+        .status()
+        .map(|s| s.success())
+        .unwrap_or(false)
+    {
         run(&format!("chmod +x {}", path));
         run(&path);
     }
 }

-fn xrdb(cache:&str,send:bool) {
+fn xrdb(cache: &str, send: bool) {
     if run("which xrdb") {
-        run(&format!("xrdb -merge -quiet {}/wal/colors.Xresources", cache));
-        info("Xrdb", "xrdb colorscheme set",send);
+        run(&format!(
+            "xrdb -merge -quiet {}/wal/colors.Xresources",
+            cache
+        ));
+        info("Xrdb", "xrdb colorscheme set", send);
     }
 }

-fn i3(send:bool) {
+fn i3(send: bool) {
     if run("pgrep -x i3") {
         run("i3-msg reload");
-        info("i3", "i3 colorscheme set",send);
+        info("i3", "i3 colorscheme set", send);
     }
 }

-fn bspwm(send:bool) {
+fn bspwm(send: bool) {
     if run("pgrep -x bspwm") {
         run("bspc wm -r");
-        info("Bspwm", "bspwm colorscheme set",send);
+        info("Bspwm", "bspwm colorscheme set", send);
     }
 }

-fn kitty(cache:&str,send:bool) {
+fn kitty(cache: &str, send: bool) {
     if run("which kitty") && run("pgrep kitty") {
-        run(&format!("kitty @ set-colors --all {}/wal/colors-kitty.conf", cache));
-        info("Kitty", "kitty colorscheme set",send);
+        run(&format!(
+            "kitty @ set-colors --all {}/wal/colors-kitty.conf",
+            cache
+        ));
+        info("Kitty", "kitty colorscheme set", send);
     }
 }

-fn polybar(send:bool) {
+fn polybar(send: bool) {
     if run("which polybar") && run("pgrep polybar") {
         run("pkill -USR1 polybar");
-        info("Polybar", "polybar colorscheme set",send);
+        info("Polybar", "polybar colorscheme set", send);
     }
 }

-
-fn colors(colors:Vec<String>,send:bool){
-
-    for i in read_dir("/dev/pts/").expect("Can't load terminals"){
+fn colors(colors: Vec<String>, send: bool) {
+    for i in read_dir("/dev/pts/").expect("Can't load terminals") {
         let file = i.unwrap().file_name().into_string().unwrap();
-        if  file != "ptmx" && file.parse::<i32>().is_ok(){
-            let special_index = [(10,7),(11,0),(12,15),(708,5)];
+        if file != "ptmx" && file.parse::<i32>().is_ok() {
+            let special_index = [(10, 7), (11, 0), (12, 15), (708, 5)];
             let term = file.parse::<i32>().unwrap();
-            for (i,value) in colors.iter().enumerate(){
+            for (i, value) in colors.iter().enumerate() {
                 let sequence = format!("\x1b]4;{};{}\x1b\\", i, value);

-                if let Ok(mut file) = OpenOptions::new().write(true).open(format!("/dev/pts/{}",term)) {
+                if let Ok(mut file) = OpenOptions::new()
+                    .write(true)
+                    .open(format!("/dev/pts/{}", term))
+                {
                     let _ = file.write_all(sequence.as_bytes());
                 };
-            };
-            for (i,v) in special_index{
-                let sequence = format!("\x1b]{};{}\x1b\\", i,colors[v] );
+            }
+            if let Ok(mut file) = OpenOptions::new()
+                .write(true)
+                .open(format!("/dev/pts/{}", term))
+            {
+                for (i, v) in special_index {
+                    let sequence = format!("\x1b]{};{}\x1b\\", i, colors[v]);

-                if let Ok(mut file) = OpenOptions::new().write(true).open(format!("/dev/pts/{}",term)) {
                     let _ = file.write_all(sequence.as_bytes());
-                };
-
+                }
             }
         }
-    } 
-    info("Terminal", "terminal colorscheme set",send);
+    }
+    info("Terminal", "terminal colorscheme set", send);
 }

-pub fn reload(send:bool,set_wal:bool) {
+pub fn reload(send: bool, set_wal: bool) {
     let cache = get_cache_folder().expect("Can't get cache path");
     let file_path = format!("{}/wal/colors", cache);

@@ -104,21 +117,28 @@ pub fn reload(send:bool,set_wal:bool) {
     // Spawn threads
     let cache = match get_cache_folder() {
         Some(v) => v,
-        None =>  {warning("Path", "can't found cache folder",send);exit(1)}
+        None => {
+            warning("Path", "can't found cache folder", send);
+            exit(1)
+        }
     };

-    if set_wal{
-        let wallpaper = read_to_string(format!("{}/wal/wal",cache)).expect("run 'cp /etc/walrs/templates/wal ~/.config/walrs/templates/' and restart app").lines().next().unwrap().trim().to_string();
-        wallpaper::change_wallpaper(wallpaper.as_str(),send);
+    if set_wal {
+        let wallpaper = read_to_string(format!("{}/wal/wal", cache))
+            .expect("run 'cp /etc/walrs/templates/wal ~/.config/walrs/templates/' and restart app")
+            .lines()
+            .next()
+            .unwrap()
+            .trim()
+            .to_string();
+        wallpaper::change_wallpaper(wallpaper.as_str(), send);
     }
-    colors(lines,send);
-    xrdb(&cache,send);
-    kitty(&cache,send);
+    colors(lines, send);
+    xrdb(&cache, send);
+    kitty(&cache, send);
     i3(send);
     bspwm(send);
     polybar(send);
     tty(&cache);
-    info("Colors", "colorscheme applied successfully",send);
-
+    info("Colors", "colorscheme applied successfully", send);
 }
-
diff --git a/src/utils.rs b/src/utils.rs
index 67d2684..a46d281 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,10 +1,9 @@
-use std::{fs, process::Command};
 use dirs_next::{cache_dir, config_dir};
 use std::path::Path;
+use std::{fs, process::Command};

-pub fn print_colors(send:bool) {
-    if send{
-
+pub fn print_colors(send: bool) {
+    if send {
         if let Ok(output) = Command::new("bash")
             .arg("-c")
             .arg(r#"for i in {30..37} 90; do echo -en "\033[0;${i}m●\033[0m "; done; echo"#)
@@ -17,20 +16,18 @@ pub fn print_colors(send:bool) {
     }
 }

-
-pub fn warning(title:&str,message:&str,send:bool){
-    if send{
+pub fn warning(title: &str, message: &str, send: bool) {
+    if send {
         println!("[\x1b[33mW\x1b[0m] \x1b[31m{title}:\x1b[0m {message}.");
     }
 }

-pub fn info(title:&str,message:&str, send:bool){
-    if send{
+pub fn info(title: &str, message: &str, send: bool) {
+    if send {
         println!("[\x1b[32mI\x1b[0m] \x1b[31m{title}:\x1b[0m {message}.");
     }
 }

-
 pub fn get_config_folder() -> Option<String> {
     config_dir()?.to_str().map(|s| s.to_string())
 }
@@ -43,4 +40,3 @@ pub fn get_absolute_path(path_str: &str) -> Option<String> {
     let path = Path::new(path_str);
     fs::canonicalize(path).ok()?.to_str().map(|s| s.to_string())
 }
-
diff --git a/src/wallpaper.rs b/src/wallpaper.rs
index 25bf0b8..ccb558a 100644
--- a/src/wallpaper.rs
+++ b/src/wallpaper.rs
@@ -1,7 +1,7 @@
+use crate::utils::{info, warning};
 use std::env;
 use std::path::Path;
 use std::process::{Command, Stdio};
-use crate::utils::{info, warning};

 fn run(command: &str) -> bool {
     Command::new("sh")
@@ -22,7 +22,7 @@ fn run_with_output(command: &str) -> Option<String> {
         .stdout(Stdio::null())
         .output()
         .ok()?;
-    
+
     if output.status.success() {
         String::from_utf8(output.stdout).ok()
     } else {
@@ -51,17 +51,17 @@ fn get_desktop_env() -> Option<String> {
         "I3SOCK",
         "WAYLAND_DISPLAY",
     ];
-    
+
     // Check specifically for Sway
     if env::var("SWAYSOCK").is_ok() || run("pgrep -x sway") {
         return Some("SWAY".to_string());
     }
-    
+
     // Check if Hyprland is running
     if run("pgrep -x Hyprland") || env::var("HYPRLAND_INSTANCE_SIGNATURE").is_ok() {
         return Some("HYPRLAND".to_string());
     }
-    
+
     // Check if i3 is running
     if run("pgrep -x i3") || env::var("I3SOCK").is_ok() {
         return Some("I3".to_string());
@@ -112,7 +112,11 @@ fn set_wm_wallpaper(img: &str, send: bool) {
         spawn(&format!("nitrogen --set-zoom-fill --save '{}'", img));
         info("Wallpaper", "wallpaper set with nitrogen", send);
     } else if run("which xsetroot") {
-        warning("Wallpaper", "using xsetroot, but it does not support images properly", send);
+        warning(
+            "Wallpaper",
+            "using xsetroot, but it does not support images properly",
+            send,
+        );
         spawn("xsetroot -solid '#000000'");
         info("Wallpaper", "set solid background with xsetroot", send);
     } else {
@@ -122,7 +126,7 @@ fn set_wm_wallpaper(img: &str, send: bool) {

 fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
     let d = desktop.to_lowercase();
-    
+
     // Convert img to absolute path
     let abs_path = if Path::new(img).is_absolute() {
         img.to_string()
@@ -135,15 +139,17 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
             }
         }
     };
-    
+
     if d.contains("xfce") || d.contains("xubuntu") {
         // Try to find the active monitor
-        let monitors = run_with_output("xfconf-query -c xfce4-desktop -l | grep last-image").unwrap_or_default();
+        let monitors = run_with_output("xfconf-query -c xfce4-desktop -l | grep last-image")
+            .unwrap_or_default();
         if !monitors.is_empty() {
             for line in monitors.lines() {
                 spawn(&format!(
                     "xfconf-query --channel xfce4-desktop --property {} --set '{}'",
-                    line.trim(), abs_path
+                    line.trim(),
+                    abs_path
                 ));
             }
         } else {
@@ -187,44 +193,45 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
         ));
         info("Wallpaper", "wallpaper set with Cinnamon settings", send);
     } else if d.contains("hyprland") {
-    // Get monitors using a more reliable approach
-    let monitors: Vec<String> = run_with_output("hyprctl monitors | grep Monitor | cut -d' ' -f2")
-        .unwrap_or_default()
-        .lines()
-        .map(|s| s.trim().to_string())
-        .filter(|s| !s.is_empty())
-        .collect();
-
-    if !monitors.is_empty() {
-        println!("Found monitors: {:?}", monitors);
-        
-        // Create a new hyprpaper.conf file
-        let home = env::var("HOME").unwrap_or_else(|_| ".".to_string());
-        let config_path = format!("{}/.config/hypr/hyprpaper.conf", home);
-        
-        // Write configuration as a single operation instead of multiple echo commands
-        let mut config = format!("preload = {}\n", abs_path);
-        for monitor in &monitors {
-            config.push_str(&format!("wallpaper = {},{}\n", monitor, abs_path));
-        }
-        
-        // Use filesystem operations instead of echo
-        if let Err(e) = std::fs::write(&config_path, config) {
-            warning("Wallpaper", &format!("failed to write hyprpaper config: {}", e), send);
-        } else {
-            // Restart hyprpaper
-            spawn("killall hyprpaper 2>/dev/null; hyprpaper &");
-            info("Wallpaper", "wallpaper set with hyprpaper", send);
-        }
-    } else {
-        // Fallback to swaybg if no monitors detected
-        spawn(&format!("pkill swaybg; swaybg -i '{}' -m fill &", abs_path));
-        info("Wallpaper", "wallpaper set with swaybg for Hyprland", send);
-    }
+        // Get monitors using a more reliable approach
+        let monitors: Vec<String> =
+            run_with_output("hyprctl monitors | grep Monitor | cut -d' ' -f2")
+                .unwrap_or_default()
+                .lines()
+                .map(|s| s.trim().to_string())
+                .filter(|s| !s.is_empty())
+                .collect();

+        if !monitors.is_empty() {
+            println!("Found monitors: {:?}", monitors);

+            // Create a new hyprpaper.conf file
+            let home = env::var("HOME").unwrap_or_else(|_| ".".to_string());
+            let config_path = format!("{}/.config/hypr/hyprpaper.conf", home);

+            // Write configuration as a single operation instead of multiple echo commands
+            let mut config = format!("preload = {}\n", abs_path);
+            for monitor in &monitors {
+                config.push_str(&format!("wallpaper = {},{}\n", monitor, abs_path));
+            }

+            // Use filesystem operations instead of echo
+            if let Err(e) = std::fs::write(&config_path, config) {
+                warning(
+                    "Wallpaper",
+                    &format!("failed to write hyprpaper config: {}", e),
+                    send,
+                );
+            } else {
+                // Restart hyprpaper
+                spawn("killall hyprpaper 2>/dev/null; hyprpaper &");
+                info("Wallpaper", "wallpaper set with hyprpaper", send);
+            }
+        } else {
+            // Fallback to swaybg if no monitors detected
+            spawn(&format!("pkill swaybg; swaybg -i '{}' -m fill &", abs_path));
+            info("Wallpaper", "wallpaper set with swaybg for Hyprland", send);
+        }
     } else if d == "sway" {
         // Using swww or swaybg for Sway
         if run("which swww") {
@@ -232,13 +239,20 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
             if !run("pgrep -x swww-daemon") {
                 spawn("swww init");
             }
-            spawn(&format!("swww img '{}' --transition-type fade --transition-fps 60", abs_path));
+            spawn(&format!(
+                "swww img '{}' --transition-type fade --transition-fps 60",
+                abs_path
+            ));
             info("Wallpaper", "wallpaper set with swww for Sway", send);
         } else if run("which swaybg") {
             spawn(&format!("pkill swaybg; swaybg -i '{}' -m fill &", abs_path));
             info("Wallpaper", "wallpaper set with swaybg for Sway", send);
         } else {
-            warning("Wallpaper", "no suitable wallpaper tool found for Sway", send);
+            warning(
+                "Wallpaper",
+                "no suitable wallpaper tool found for Sway",
+                send,
+            );
         }
     } else if d.contains("awesome") {
         spawn(&format!(
@@ -287,7 +301,11 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
             spawn(&format!("swww img '{}'", abs_path));
             info("Wallpaper", "wallpaper set with swww", send);
         } else {
-            warning("Wallpaper", "no suitable Wayland wallpaper tool found", send);
+            warning(
+                "Wallpaper",
+                "no suitable Wayland wallpaper tool found",
+                send,
+            );
         }
     } else if d.contains("wayfire") {
         // Wayfire compositor
@@ -306,17 +324,11 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
         info("Wallpaper", "wallpaper set with Deepin settings", send);
     } else if d.contains("lxqt") {
         // LXQt uses pcmanfm-qt for desktop management
-        spawn(&format!(
-            "pcmanfm-qt --set-wallpaper='{}'",
-            abs_path
-        ));
+        spawn(&format!("pcmanfm-qt --set-wallpaper='{}'", abs_path));
         info("Wallpaper", "wallpaper set with LXQt settings", send);
     } else if d.contains("lxde") {
         // LXDE uses pcmanfm for desktop management
-        spawn(&format!(
-            "pcmanfm --set-wallpaper='{}'",
-            abs_path
-        ));
+        spawn(&format!("pcmanfm --set-wallpaper='{}'", abs_path));
         info("Wallpaper", "wallpaper set with LXDE settings", send);
     } else if d.contains("budgie") {
         // Budgie uses GNOME settings
@@ -324,7 +336,11 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {
             "gsettings set org.gnome.desktop.background picture-uri 'file://{}'",
             abs_path
         ));
-        info("Wallpaper", "wallpaper set with Budgie (GNOME) settings", send);
+        info(
+            "Wallpaper",
+            "wallpaper set with Budgie (GNOME) settings",
+            send,
+        );
     } else if d.contains("enlightenment") || d.contains("e17") || d.contains("e16") {
         // Enlightenment WM - try using enlightenment_remote
         if run("which enlightenment_remote") {
@@ -344,17 +360,17 @@ fn set_desktop_wallpaper(desktop: &str, img: &str, send: bool) {

 pub fn change_wallpaper(img: &str, send: bool) {
     if !Path::new(img).is_file() {
-        println!("asdf: {}",img);
+        println!("asdf: {}", img);
         warning("Wallpaper", "invalid image path", send);
         return;
     }
-    
+
     match get_desktop_env() {
         Some(d) => {
             set_desktop_wallpaper(&d, img, send);
-        },
+        }
         None => {
             set_wm_wallpaper(img, send);
-        },
+        }
     }
 }