Skip to content

Commit

Permalink
refactor: rename compared_color to closest_color (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
InioX committed Jun 29, 2024
1 parent 12101b0 commit 7ea9a75
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion example/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ colors_to_compare = [
{ name = "purple", color = "#800080" },
]
compare_to = "{{colors.primary.default.hex}}"
hook = 'echo "source color {{colors.source_color.default.hex}}, source image {{image}}, compared color {{compared_color}}"'
hook = 'echo "source color {{colors.source_color.default.hex}}, source image {{image}}, closest color {{closest_color}}"'

[config.custom_colors]
green = "#00FF00"
Expand Down
4 changes: 2 additions & 2 deletions src/util/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ fn format_hook(
engine: &Engine,
render_data: &mut Value,
) -> Result<(), Report> {
let compared_color: Option<String> =
let closest_color: Option<String> =
if template.colors_to_compare.is_some() && template.compare_to.is_some() {
let s = engine.compile(template.compare_to.as_ref().unwrap())?;
let compare_to = s.render(&engine, &render_data).to_string()?;
Expand All @@ -328,7 +328,7 @@ fn format_hook(
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, compared_color.as_ref(), t);
let res = format_hook_text(render_data, closest_color.as_ref(), t);
let mut command = shell(&res);

command.stdout(Stdio::inherit());
Expand Down
12 changes: 6 additions & 6 deletions src/util/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use upon::{Engine, Syntax, Template, Value};
// }

// match input {
// "compared_color" => Variables::ComparedColor,
// "closest_color" => Variables::ComparedColor,
// "source_image" => Variables::SourceImage,
// "source_color" => Variables::SourceColor,
// _ => {
Expand Down Expand Up @@ -53,7 +53,7 @@ use upon::{Engine, Syntax, Template, Value};
// input: &str,
// default_value: &String,
// src_img: Option<&String>,
// compared_color: Option<&String>,
// closest_color: Option<&String>,
// source_color: &Argb,
// ) -> String {
// let re = Regex::new(r"\{.*?\}").unwrap();
Expand All @@ -63,7 +63,7 @@ use upon::{Engine, Syntax, Template, Value};
// let result = re.replace_all(input, |cap: &Captures| {
// match Variables::from(&cap[0]) {
// Variables::Invalid => &cap[0],
// Variables::ComparedColor => compared_color.unwrap_or(default_value),
// Variables::ComparedColor => closest_color.unwrap_or(default_value),
// Variables::SourceImage => src_img.unwrap_or(default_value),
// Variables::SourceColor => &source_formatted,
// }
Expand All @@ -73,13 +73,13 @@ use upon::{Engine, Syntax, Template, Value};
// return result.to_string();
// }

pub fn format_hook_text(render_data: &mut Value, compared_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 compared_color.is_some() {
map.insert("compared_color".to_string(), Value::from(compared_color.unwrap().as_str()));
if closest_color.is_some() {
map.insert("closest_color".to_string(), Value::from(closest_color.unwrap().as_str()));
}
},
_ => {
Expand Down

0 comments on commit 7ea9a75

Please sign in to comment.