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 | diff --git a/src/main.rs b/src/main.rs
index ff6465a..450c1a9 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,3 @@
-mod completions;
mod create_templates;
mod get_colors;
mod reload;
@@ -6,9 +5,8 @@ mod theme;
mod utils;
mod wallpaper;
-use clap::{ArgAction, CommandFactory, Parser};
+use argh::FromArgs;
use create_templates::create_template;
-use dirs_next::{cache_dir, config_dir};
use get_colors::get_colors;
use reload::reload;
use std::fs::{copy, create_dir_all};
@@ -17,48 +15,78 @@ use std::process::exit;
use theme::{collect_themes, set_theme};
use utils::*;
-#[derive(Parser, Debug)]
-#[command(
- name = "walrs",
- version = env!("CARGO_PKG_VERSION"),
- about = "walrs - Generate colorscheme from image",
-)]
+#[derive(FromArgs)]
+#[argh(description = "walrs - Generate colorscheme from image")]
struct Arg {
- /// path/to/your/wal.png | for random image: path/to/your/wallpapers/
- #[arg(short = 'i')]
+ #[argh(
+ option,
+ short = 'i',
+ description = "path/to/your/wal.png | path/to/your/wallpapers/"
+ )]
image: Option<String>,
- /// reload Templates without setting the wallpaper
- #[arg(short = 'r',long="reload", action = ArgAction::SetTrue)]
+ #[argh(
+ option,
+ short = 'k',
+ long = "backend",
+ description = "change the colors backend (walrs -k backends)"
+ )]
+ backend: Option<String>,
+
+ #[argh(
+ switch,
+ short = 'r',
+ description = "reload without changing the wallpaper"
+ )]
reload: bool,
- /// reload Templates with setting the wallpaper
- #[arg(short = 'R',long="Reload" ,action = ArgAction::SetTrue)]
+ #[argh(
+ switch,
+ short = 'R',
+ long = "reload-nowal",
+ description = "reload with changing the wallpaper"
+ )]
reload_nowal: bool,
- /// use external theme file
- #[arg(short = 't', long = "theme")]
+ #[argh(
+ option,
+ short = 't',
+ long = "theme",
+ description = "use external theme file"
+ )]
theme: Option<String>,
- /// generate theme and save it in themes folder (.cache/wal/colorschemes)
- #[arg(short = 'g', long = "generate")]
+ #[argh(
+ option,
+ short = 'g',
+ long = "generate",
+ description = "generate theme in themes folder (.cache/wal/colorschemes)"
+ )]
generate: Option<String>,
- /// specify the saturation value -128 => 127
- #[arg(short = 's', long = "saturation", allow_hyphen_values = true)]
+ #[argh(
+ option,
+ short = 's',
+ long = "saturation",
+ description = "specify the saturation value -128 => 127"
+ )]
saturation: Option<i8>,
- /// specify the brightness value -128 => 127
- #[arg(short = 'b', long = "brightness", allow_hyphen_values = true)]
+ #[argh(
+ option,
+ short = 'b',
+ long = "brightness",
+ description = "specify the brightness value -128 => 127"
+ )]
brightness: Option<i8>,
- /// set quit mode (no output)
- #[arg(long="quit",short = 'q', action = ArgAction::SetTrue)]
+ #[argh(
+ switch,
+ short = 'q',
+ long = "quit",
+ description = "set quit mode (no output)"
+ )]
quit: bool,
-
- /// Install completions for the current shell
- #[arg(long = "install-completions")]
- install_completions: bool,
}
fn image_path(image: Option<String>, send: bool) -> String {
@@ -97,8 +125,8 @@ fn image_path(image: Option<String>, send: bool) -> String {
}
}
-fn print_themes() {
- let (dark, light) = (collect_themes("dark"), collect_themes("light"));
+fn print_themes(send: bool) {
+ let (dark, light) = (collect_themes("dark", send), collect_themes("light", send));
println!("[\x1b[33mDark\x1b[0m]");
for theme in dark {
@@ -112,20 +140,28 @@ fn print_themes() {
}
fn main() {
- let arg = Arg::parse();
-
- if arg.install_completions {
- if completions::install_completions().is_err() {
- warning("Completions", "Failed to install completions", !arg.quit);
- exit(1);
+ let arg: Arg = argh::from_env();
+ let backend = match arg.backend {
+ Some(v) => {
+ if v == "backends" {
+ println!(
+ "┌──────────────────────┬───────────────────────┐
+│ Method │ Description │
+├──────────────────────┼───────────────────────┤
+│ kmeans │ best colors, slow │
+│ color_thief │ balanced │
+│ palette_extract │ fast, weak colors │
+│ all │ use all methods │
+└──────────────────────┴───────────────────────┘"
+ );
+ exit(0)
+ } else {
+ v
+ }
}
- info(
- "Completions",
- "Completions installed successfully!",
- !arg.quit,
- );
- exit(0)
- }
+ None => "kmeans".to_string(),
+ };
+
if arg.reload_nowal {
reload(!arg.quit, true);
exit(0);
@@ -136,23 +172,15 @@ fn main() {
exit(0);
}
- if arg.image.is_none() && arg.theme.is_none() && arg.generate.is_none() {
- let mut cmd = Arg::command();
- cmd.print_help().unwrap();
- exit(1);
- }
-
if let Some(v) = arg.theme {
if v == "themes" {
- print_themes();
+ print_themes(!arg.quit);
} else {
- if config_dir()
- .unwrap()
+ if get_config(!arg.quit)
.join("wal")
.join("colorscheme")
.exists()
- || config_dir()
- .unwrap()
+ || get_config(!arg.quit)
.join("walrs")
.join("colorscheme")
.exists()
@@ -161,12 +189,12 @@ fn main() {
} else {
create_dir_all(&format!(
"{}/walrs/colorschemes",
- get_config_folder().unwrap()
+ get_config(!arg.quit).to_string_lossy().to_string()
))
.unwrap();
run(&format!(
"cp -r /etc/walrs/colorschemes/* {}/walrs/colorschemes",
- get_config_folder().unwrap()
+ get_config(!arg.quit).to_string_lossy().to_string()
));
set_theme(v, !arg.quit);
};
@@ -175,10 +203,10 @@ fn main() {
}
if let Some(v) = arg.generate {
- let dis = config_dir().unwrap().join("walrs").join("colorschemes");
+ let dis = get_config(!arg.quit).join("walrs").join("colorschemes");
create_dir_all(&dis.join("dark")).unwrap();
copy(
- cache_dir().unwrap().join("wal").join("colors"),
+ get_config(!arg.quit).join("wal").join("colors"),
dis.join("dark").join(v),
)
.unwrap();
@@ -189,10 +217,16 @@ fn main() {
if arg.image.is_some() {
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,
+ &backend,
+ !arg.quit,
+ arg.brightness,
+ arg.saturation,
+ );
info("Generate", "generate colors", !arg.quit);
- create_template(palette, &image_path);
+ create_template(palette, &image_path, !arg.quit);
info("Template", "create templates", !arg.quit);
reload(!arg.quit, true);
|