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 | diff --git a/src/create_templates.rs b/src/create_templates.rs
index 879d019..ba1a8e1 100644
--- a/src/create_templates.rs
+++ b/src/create_templates.rs
@@ -1,5 +1,5 @@
use crate::utils::{get_cache_folder, get_config_folder};
-use std::fs::{self, create_dir_all, read_to_string, write};
+use std::{fs::{self, create_dir_all, read_to_string, write}, path::Path};
fn change(template: &str, colors: (u8, u8, u8), alpha: u8) -> String {
let (r, g, b) = colors;
@@ -26,12 +26,17 @@ fn fill_template(
template: &str,
colors: &(Vec<(u8, u8, u8)>, u8),
wallpaper: &str,
+ output_dir:String
) {
- let output_path = format!(
- "{}/wal/{}",
- get_cache_folder().expect("Can't find cache folder"),
- template_name
- );
+ let output_path = if output_dir == "None" {
+format!(
+ "{}/wal/{}",
+ get_cache_folder().expect("Can't find cache folder"),
+ template_name
+)
+ }else {
+Path::new(&output_dir).join(template_name).to_string_lossy().to_string()
+ };
let alpha = colors.1;
let mut result = template
@@ -116,7 +121,7 @@ fn fill_template(
write(output_path, result).expect("Failed to write filled template");
}
-pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str) {
+pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str,output_dir:String) {
let system_template_path = "/etc/walrs/templates/";
let user_template_path = format!("{}/walrs/templates/", get_config_folder().unwrap());
let cache_path = format!("{}/wal/", get_cache_folder().unwrap());
@@ -134,7 +139,7 @@ pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str) {
let Some(name) = entry.file_name().into_string().ok() else {
continue;
};
- fill_template(&name, &content, &colors, wallpaper);
+ fill_template(&name, &content, &colors, wallpaper,output_dir.clone());
}
}
}
@@ -157,7 +162,7 @@ pub fn create_template(colors: (Vec<(u8, u8, u8)>, u8), wallpaper: &str) {
let user_file_path = format!("{}{}", user_template_path, name);
let _ = write(&user_file_path, &content);
- fill_template(&name, &content, &colors, wallpaper);
+ fill_template(&name, &content, &colors, wallpaper,output_dir.clone());
}
}
}
diff --git a/src/main.rs b/src/main.rs
index 758c2b8..532ec33 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,6 +27,10 @@ struct Arg {
#[arg(short = 'g')]
generate: Option<String>,
+ /// output generated diractory | default: .cache/wal/
+ #[arg(short = 'o')]
+ output: Option<String>,
+
/// reload Templates from cache file and set the wallpaper
#[arg(short = 'r', action = ArgAction::SetTrue)]
reload_nowal: bool,
@@ -61,11 +65,11 @@ fn image_path(image: Option<String>, send: bool) -> String {
.arg(format!("find \"{}\" -type f | sort -R | head -n1", p))
.output()
.unwrap()
- .stdout,
+ .stdout,
)
- .unwrap()
- .trim()
- .to_string()
+ .unwrap()
+ .trim()
+ .to_string()
}
}
None => {
@@ -87,6 +91,16 @@ fn image_path(image: Option<String>, send: bool) -> String {
fn main() {
let arg = Arg::parse();
+ let output_dir = match arg.output {
+ Some(v) => {
+ if !Path::new(&v).is_dir() {
+ warning("Error", "Can't find a directory", !arg.quit);
+ exit(1)
+ }
+ v
+ },
+ None => "None".to_string()
+ };
if arg.reload_nowal {
reload(!arg.quit, true);
exit(0);
@@ -108,7 +122,7 @@ fn main() {
let palette = get_colors(&image_path, !arg.quit, arg.brightness, arg.saturation);
info("Generate", "generate colors", !arg.quit);
- create_template(palette, &image_path);
+ create_template(palette, &image_path,output_dir);
info("Template", "create templates", !arg.quit);
exit(0)
};
@@ -119,10 +133,13 @@ fn main() {
let palette = get_colors(&image_path, !arg.quit, arg.brightness, arg.saturation);
info("Generate", "generate colors", !arg.quit);
- create_template(palette, &image_path);
+ create_template(palette, &image_path,output_dir);
info("Template", "create templates", !arg.quit);
reload(!arg.quit, true);
print_colors(!arg.quit);
};
}
+
+
+
|