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 | mod create_templates;
mod get_colors;
mod reload;
mod theme;
mod utils;
mod wallpaper;
use argh::FromArgs;
use create_templates::create_template;
use get_colors::get_colors;
use reload::reload;
use std::fs::{copy, create_dir_all};
use std::process::exit;
use theme::{print_themes, set_theme, theme_exists};
use utils::*;
#[derive(FromArgs)]
#[argh(description = "walrs - Generate colorscheme from image")]
struct Arg {
#[argh(option, short = 'i', description = "path to image or directory")]
image: Option<String>,
#[argh(
switch,
short = 'r',
description = "reload without changing the wallpaper"
)]
reload: bool,
#[argh(
switch,
short = 'R',
long = "reload-no",
description = "will be removed in the next update; use -w instead"
)]
reload_no: bool,
#[argh(
option,
short = 't',
long = "theme",
description = "use external theme file from .config/walrs/colorschemes"
)]
theme: Option<String>,
#[argh(
option,
short = 'g',
long = "generate",
description = "generate & save theme to .config/walrs/colorschemes"
)]
generate: Option<String>,
#[argh(
option,
short = 's',
long = "saturation",
description = "set saturation value (-128 to 127)"
)]
saturation: Option<i16>,
#[argh(
option,
short = 'b',
long = "brightness",
description = "set brightness value (-128 to 127)"
)]
brightness: Option<i16>,
#[argh(
switch,
short = 'S',
long = "scripts",
description = "skip running scripts in ~/.config/walrs/scripts/"
)]
run_scripts: Option<bool>,
#[argh(
switch,
short = 'W',
long = "walless",
description = "skip changing the wallpaper"
)]
walless: Option<bool>,
#[argh(
switch,
short = 'q',
long = "quiet",
description = "set quit mode (no output)"
)]
quit: bool,
#[argh(switch, short = 'v', long = "version", description = "show version")]
version: bool,
}
fn main() {
// get and load args from user
let arg: Arg = argh::from_env();
// save the quit status
let send = !arg.quit;
// print the version
if arg.version {
info("Version", env!("CARGO_PKG_VERSION"), send);
exit(0);
}
// this will be removed next update
if arg.reload_no {
warning(
"Reload",
"this will be removed in the next update, use -W instead",
send,
);
reload(send, true, arg.run_scripts.unwrap_or(false));
exit(0);
}
// reload colors with setting wallpaper
if arg.reload {
reload(
send,
arg.walless.unwrap_or(false),
arg.run_scripts.unwrap_or(false),
);
exit(0);
}
// if user didn't type any thing
if arg.image.is_none() && arg.theme.is_none() && arg.generate.is_none() {
warning("Args", "run: walrs --help", send);
exit(1);
}
// show or set theme from user
if let Some(v) = arg.theme {
let config = get_config(send);
if v == "themes" {
print_themes(send);
} else if theme_exists(&config) {
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()) {
warning("theme", "Can't find configuration directory", send);
exit(1)
}
run(&format!(
"cp -r {}/* {}",
walrs_cache.join("colorschemes").display(),
colorschemes_dir.display()
));
set_theme(v, send, arg.run_scripts.unwrap_or(false));
}
exit(0);
}
// generate a new theme from current colors
if let Some(v) = arg.generate {
let dis = get_config(send).join("walrs").join("colorschemes");
create_dir_all(dis.join("dark")).unwrap();
copy(
get_cache(send).join("wal").join("colors"),
dis.join("dark").join(v),
)
.unwrap();
info("Generate", "generate colors", send);
exit(0);
};
// analyze the image and generate the palette
if arg.image.is_some() {
let image_path = image_path(arg.image, send);
let palette = get_colors(&image_path, send, arg.brightness, arg.saturation);
info("Generate", "generate colors", send);
create_template(palette, &image_path, send);
info("Template", "create templates", send);
reload(
send,
arg.walless.unwrap_or(false),
arg.run_scripts.unwrap_or(false),
);
print_colors(send);
};
}
|