Skip to content

Commit

Permalink
fix: make hooks not depend on colors_to_compare (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
InioX committed Jul 22, 2024
1 parent afefcf5 commit 1d09b15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
36 changes: 20 additions & 16 deletions src/util/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,25 +325,29 @@ fn format_hook(
} else {
None
};
Ok(
if template.colors_to_compare.is_some() && template.compare_to.is_some() {
let t = engine.compile(template.hook.as_ref().unwrap())?;
let res = format_hook_text(render_data, closest_color.as_ref(), t);
let mut command = shell(&res);

command.stdout(Stdio::inherit());
let t = engine.compile(template.hook.as_ref().unwrap())?;
let res = if template.colors_to_compare.is_some() && template.compare_to.is_some() {
format_hook_text(render_data, closest_color, t)
} else {
format_hook_text(render_data, None, t)
};

let mut command = shell(&res);

let output = command.execute_output()?;
command.stdout(Stdio::inherit());

if let Some(exit_code) = output.status.code() {
if exit_code != 0 {
error!("Failed executing command: {:?}", &res)
}
} else {
eprintln!("Interrupted!");
}
},
)
let output = command.execute_output()?;

if let Some(exit_code) = output.status.code() {
if exit_code != 0 {
error!("Failed executing command: {:?}", &res)
}
} else {
eprintln!("Interrupted!");
}

Ok(())
}

fn generate_colors(
Expand Down
9 changes: 4 additions & 5 deletions src/util/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,16 @@ use upon::{Engine, Syntax, Template, Value};
// return result.to_string();
// }

pub fn format_hook_text(render_data: &mut Value, closest_color: Option<&String>, template: Template<'_>) -> String {
pub fn format_hook_text(render_data: &mut Value, closest_color: Option<String>, template: Template<'_>) -> String {
let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build();
let mut engine = Engine::with_syntax(syntax);

match render_data {
Value::Map(ref mut map) => {
if closest_color.is_some() {
map.insert("closest_color".to_string(), Value::from(closest_color.unwrap().as_str()));
}
map.insert("closest_color".to_string(), Value::from(closest_color));
},
_ => {
println!("not")
debug!("not map")
}
}

Expand Down

0 comments on commit 1d09b15

Please sign in to comment.