diff --git a/README.md b/README.md
index ba579a5..6204861 100644
--- a/README.md
+++ b/README.md
@@ -10,6 +10,7 @@ There is the old bash version in: https://github.com/warpwm/lule_bash
```
lule --image=/some/path/of/an/image.jpg create -- set
+LULE_W=/some/dir/of/wallpapers; lule create -- set
```
diff --git a/src/cli.rs b/src/cli.rs
index 05232a9..b1a1bb3 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -5,7 +5,7 @@ pub mod daemon;
pub mod test;
use colored::*;
-use clap::{crate_description, crate_name, crate_version, App, Arg, SubCommand, AppSettings};
+use clap::{crate_description, crate_name, crate_version, App, Arg, SubCommand, AppSettings, ArgSettings};
/////UNSAFE
fn string_to_unsafe_static_str(s: String) -> &'static str {
@@ -65,6 +65,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.value_name("PATH")
.help("specify a dir to load color configs from")
.takes_value(true)
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("cache")
@@ -72,6 +73,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.value_name("PATH")
.help("specify a dir where to dump color caches")
.takes_value(true)
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("pattern")
@@ -80,14 +82,16 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.help("specify a path to substitute pattern colors")
.takes_value(true)
.multiple(true)
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("script")
.long("script")
- .value_name("PATH")
+ .value_name("PATH:PATH")
.help("specify a script to run afte colors are generated")
.takes_value(true)
.multiple(true)
+ .set(ArgSettings::RequireEquals)
)
.subcommand(
SubCommand::with_name("create")
@@ -100,6 +104,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.takes_value(true)
.value_name("DIRPATH")
.conflicts_with("image")
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("palette")
@@ -109,6 +114,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.possible_values(&["schemer2", "pigment"])
.default_value("pigment")
.value_name("NAME")
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("scheme")
@@ -116,6 +122,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.value_name("NAME")
.help("specify a color scheme from configs to use")
.takes_value(true)
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("image")
@@ -125,6 +132,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.takes_value(true)
.value_name("FLEPATH")
.conflicts_with("wallpath")
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("theme")
@@ -134,6 +142,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.value_name("THEME")
.possible_values(&["dark", "light"])
.default_value("dark")
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("action")
@@ -153,6 +162,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.takes_value(true)
.default_value("300")
.value_name("SECONDS")
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("action")
@@ -193,6 +203,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.possible_values(&["dark", "light"])
.default_value("dark")
.required(true)
+ .set(ArgSettings::RequireEquals)
)
)
.subcommand(
@@ -205,6 +216,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.visible_aliases(&["source"])
.takes_value(true)
.value_name("FLEPATH")
+ .set(ArgSettings::RequireEquals)
)
.arg(
Arg::with_name("pattern")
@@ -213,6 +225,7 @@ pub fn build_cli(show_logo: bool) -> App<'static, 'static> {
.help("specify a path to substitute pattern colors")
.takes_value(true)
.multiple(true)
+ .set(ArgSettings::RequireEquals)
)
)
}
diff --git a/src/cli/colors.rs b/src/cli/colors.rs
index accc37b..5cfab1a 100644
--- a/src/cli/colors.rs
+++ b/src/cli/colors.rs
@@ -16,7 +16,7 @@ pub fn run(app: &clap::ArgMatches, output: &mut WRITE, scheme: &mut SCHEME) -> R
var::pipe::concatinate(scheme);
- scheme.set_script(None);
+ scheme.set_scripts(None);
if sub.is_present("gen") {
create::new_palette(output, scheme)?;
}
diff --git a/src/cli/create.rs b/src/cli/create.rs
index aac80a9..4e50c9b 100644
--- a/src/cli/create.rs
+++ b/src/cli/create.rs
@@ -40,14 +40,12 @@ pub fn new_palette(output: &mut WRITE, scheme: &mut SCHEME) -> Result<()> {
if scheme.image().is_none() {
scheme.set_image(Some(helper::random_image(&wallpaper)));
}
- println!("{}", &scheme.image().clone().unwrap());
let palette: Vec;
if let Some(content) = scheme.palette() {
match content.as_str() {
"pigment" => {
palette = palette::palette_from_image(scheme.image().clone().unwrap());
- println!("{}", &scheme.image().clone().unwrap());
helper::write_temp_file("lule_palette", palette.join("\n").as_bytes());
scheme.set_colors(Some(palette));
},
@@ -63,8 +61,8 @@ pub fn new_palette(output: &mut WRITE, scheme: &mut SCHEME) -> Result<()> {
write::write_temp(&output);
write::write_cache(&scheme);
write::write_cache_json(scheme, values);
- if let Some(_) = scheme.script() {
- execute::external_command();
+ if let Some(_) = scheme.scripts() {
+ execute::external_command(scheme);
}
scheme.set_image(None);
Ok(())
@@ -91,6 +89,6 @@ pub fn old_palette(output: &mut WRITE, scheme: &mut SCHEME) -> Result<()> {
write::write_temp(&output);
write::write_cache(&scheme);
write::write_cache_json(scheme, write::output_to_json(output, false));
- execute::external_command();
+ execute::external_command(scheme);
Ok(())
}
diff --git a/src/gen/execute.rs b/src/gen/execute.rs
index d7b21fc..53751f7 100644
--- a/src/gen/execute.rs
+++ b/src/gen/execute.rs
@@ -1,7 +1,12 @@
use std::process::Command;
-// use crate::scheme::scheme::*;
+use crate::scheme::*;
-pub fn external_command(){
+pub fn external_command(scheme: &mut SCHEME){
+ if let Some(scripts) = scheme.scripts() {
+ for script in scripts.iter() {
+ println!("{}", script)
+ }
+ }
Command::new("bash")
.arg("-c")
.arg("/home/bresilla/code/proj/warp/lule/scripts/lule_colors")
diff --git a/src/gen/templ.rs b/src/gen/templ.rs
index 9e4d1fc..f358a95 100644
--- a/src/gen/templ.rs
+++ b/src/gen/templ.rs
@@ -5,34 +5,35 @@ use crate::scheme::*;
use templar;
use templar::*;
-pub fn generate_template(original: PathBuf, _replaced: PathBuf, output: &WRITE) -> Result<()> {
+pub fn generate_template(original: PathBuf, replaced: PathBuf, output: &WRITE) -> Result<()> {
let mut content = String::new();
if let Ok(cont) = helper::file_to_string(original) {
content = cont;
}
- if let Err(e) = templar::Templar::global().parse(&content) {
- println!("{}", e);
- };
+ // if let Err(e) = templar::Templar::global().parse(&content) {
+ // println!("{}", e);
+ // };
let template = templar::Templar::global().parse(&content)?;
- println!("{}", content);
let mut data: templar::Document = templar::Document::default();
for (i, color) in output.colors().iter().enumerate() {
let name = "color".to_string() + &i.to_string();
- data[name] = color.to_rgb_hex_string(true).into();
+ data[name] = color.to_rgb_hex_string(false).into();
}
- data["background"] = output.colors()[0].to_rgb_hex_string(true).into();
- data["foreground"] = output.colors()[15].to_rgb_hex_string(true).into();
- data["cursor"] = output.colors()[1].to_rgb_hex_string(true).into();
- data["accent"] = output.colors()[1].to_rgb_hex_string(true).into();
+ data["background"] = output.colors()[0].to_rgb_hex_string(false).into();
+ data["foreground"] = output.colors()[15].to_rgb_hex_string(false).into();
+ data["cursor"] = output.colors()[1].to_rgb_hex_string(false).into();
+ data["accent"] = output.colors()[1].to_rgb_hex_string(false).into();
+
+ data["wallpaper"] = output.wallpaper().into();
+ data["theme"] = output.theme().into();
let context = templar::StandardContext::new();
context.set(data)?;
- println!("{}", template.render(&context)?);
-
-
+ let new_content = format!("{}", template.render(&context)?);
+ helper::write_to_file(replaced, new_content.as_bytes());
Ok(())
}
diff --git a/src/scheme.rs b/src/scheme.rs
index afef30e..f55f9a5 100644
--- a/src/scheme.rs
+++ b/src/scheme.rs
@@ -38,7 +38,8 @@ pub struct SCHEME {
walldir: Option,
config: Option,
cache: Option,
- script: Option,
+ scripts: Option>,
+ patterns: Option>,
looop: Option,
theme: Option,
palette: Option,
@@ -60,7 +61,8 @@ impl SCHEME {
walldir: None,
config: None,
cache: None,
- script: None,
+ scripts: None,
+ patterns: None,
looop: None,
theme: None,
palette: None,
@@ -80,7 +82,8 @@ impl SCHEME {
if let Some(value) = new.walldir() { self.walldir = Some(value.clone()); }
if let Some(value) = new.config() { self.config = Some(value.clone()); }
if let Some(value) = new.cache() { self.cache = Some(value.clone()); }
- if let Some(value) = new.script() { self.script = Some(value.clone()); }
+ if let Some(value) = new.scripts() { self.scripts = Some(value.clone()); }
+ if let Some(value) = new.patterns() { self.patterns = Some(value.clone()); }
if let Some(value) = new.theme() { self.theme = Some(value.clone()); }
if let Some(value) = new.palette() { self.palette = Some(value.clone()); }
if let Some(value) = new.sort() { self.sort = Some(value.clone()); }
diff --git a/src/var/args.rs b/src/var/args.rs
index c5648a6..6526513 100644
--- a/src/var/args.rs
+++ b/src/var/args.rs
@@ -1,8 +1,40 @@
use clap;
use crate::scheme::*;
use crate::helper;
+use std::fs;
pub fn concatinate(app: &clap::ArgMatches, scheme: &mut SCHEME) {
+
+ if let Some(_) = app.values_of("script") {
+ let vals: Vec<&str> = app.values_of("script").unwrap().collect();
+ let mut scripts = Vec::new();
+ if let Some(s) = scheme.scripts() {
+ scripts = s.to_vec();
+ }
+ for val in vals {
+ scripts.push(val.to_string())
+ }
+ scripts.retain(|x| fs::metadata(x).is_ok());
+ scheme.set_scripts(Some(scripts));
+ }
+
+ if let Some(_) = app.values_of("pattern") {
+ let vals: Vec<&str> = app.values_of("pattern").unwrap().collect();
+ let mut patterns = Vec::new();
+ for val in vals {
+ let s: Vec<&str> = val.split_terminator(':').collect();
+ // TODO: better error
+ if s.len() == 2 {
+ if fs::metadata(s[0]).is_ok() && fs::metadata(s[1]).is_ok() {
+ patterns.push((s[0].to_string(), s[1].to_string()));
+ };
+ }
+ }
+ scheme.set_patterns(Some(patterns));
+ }
+
+
+
if let Some(sub) = app.subcommand_matches("create"){
if let Some(arg) = sub.value_of("image") {
scheme.set_image(Some(helper::vaid_image(arg)));
diff --git a/src/var/envi.rs b/src/var/envi.rs
index 5bb3311..ae3686a 100644
--- a/src/var/envi.rs
+++ b/src/var/envi.rs
@@ -13,7 +13,17 @@ pub fn concatinate(scheme: &mut SCHEME) {
let env_lule_s = std::env::var("LULE_S");
if env_lule_s.is_ok(){
- scheme.set_script(Some(env_lule_s.unwrap()));
+ let mut newvec = vec![env_lule_s.unwrap()];
+ match scheme.scripts() {
+ None => {
+ scheme.set_scripts(Some(newvec));
+ }
+ Some(vec) => {
+ newvec.append(&mut vec.clone());
+ newvec.retain(|x| std::fs::metadata(x).is_ok());
+ scheme.set_scripts(Some(newvec));
+ }
+ }
}
let env_lule_a = std::env::var("LULE_A");
diff --git a/templates/colors.sh b/templates/colors.sh
new file mode 100644
index 0000000..1560196
--- /dev/null
+++ b/templates/colors.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+# Shell variables
+# Generated by 'wal'
+wallpaper="#{{ wallpaper }}"
+
+# Special
+background='#{{ background }}'
+foreground='#{{ foreground }}'
+cursor='#{{ cursor }}'
+
+# Colors
+color0='#{{ color0 }}'
+color1='#{{ color1 }}'
+color2='#{{ color2 }}'
+color3='#{{ color3 }}'
+color4='#{{ color4 }}'
+color5='#{{ color5 }}'
+color6='#{{ color6 }}'
+color7='#{{ color7 }}'
+color8='#{{ color8 }}'
+color9='#{{ color9 }}'
+color10='#{{ color10 }}'
+color11='#{{ color11 }}'
+color12='#{{ color12 }}'
+color13='#{{ color13 }}'
+color14='#{{ color14 }}'
+color15='#{{ color15 }}'
+
+# FZF colors
+export FZF_DEFAULT_OPTS="
+ $FZF_DEFAULT_OPTS
+ --color fg:7,bg:0,hl:1,fg+:232,bg+:1,hl+:255
+ --color info:7,prompt:2,spinner:1,pointer:232,marker:1
+"