Skip to content

Commit

Permalink
Merge pull request #57 from InioX/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
InioX authored Mar 3, 2024
2 parents 1b1ca86 + 4523c65 commit e278b4f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 84 deletions.
56 changes: 20 additions & 36 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn main() -> Result<(), Report> {
}

if let Some(ref format) = args.json {
dump_json(&schemes, &source_color, format);
dump_json(&schemes, &source_color, format, &harmonized_colors);
}

if args.dry_run == Some(false) {
Expand All @@ -99,7 +99,7 @@ fn main() -> Result<(), Report> {
&source_color,
&default_scheme,
&config.config.custom_keywords,
harmonized_colors,
&harmonized_colors,
)?;

if config.config.reload_apps == Some(true) {
Expand Down Expand Up @@ -177,44 +177,28 @@ fn generate_scheme(
) -> Scheme {
match scheme_type.unwrap() {
SchemeTypes::SchemeContent => {
Scheme::from(
SchemeContent::new(Hct::new(source_color), is_dark, contrast_level).scheme,
)
}
SchemeTypes::SchemeExpressive => {
Scheme::from(
SchemeExpressive::new(Hct::new(source_color), is_dark, contrast_level).scheme,
)
}
SchemeTypes::SchemeFidelity => {
Scheme::from(
SchemeFidelity::new(Hct::new(source_color), is_dark, contrast_level).scheme,
)
}
SchemeTypes::SchemeFruitSalad => {
Scheme::from(
SchemeFruitSalad::new(Hct::new(source_color), is_dark, contrast_level).scheme,
)
}
SchemeTypes::SchemeMonochrome => {
Scheme::from(
SchemeMonochrome::new(Hct::new(source_color), is_dark, contrast_level).scheme,
)
Scheme::from(SchemeContent::new(Hct::new(source_color), is_dark, contrast_level).scheme)
}
SchemeTypes::SchemeExpressive => Scheme::from(
SchemeExpressive::new(Hct::new(source_color), is_dark, contrast_level).scheme,
),
SchemeTypes::SchemeFidelity => Scheme::from(
SchemeFidelity::new(Hct::new(source_color), is_dark, contrast_level).scheme,
),
SchemeTypes::SchemeFruitSalad => Scheme::from(
SchemeFruitSalad::new(Hct::new(source_color), is_dark, contrast_level).scheme,
),
SchemeTypes::SchemeMonochrome => Scheme::from(
SchemeMonochrome::new(Hct::new(source_color), is_dark, contrast_level).scheme,
),
SchemeTypes::SchemeNeutral => {
Scheme::from(
SchemeNeutral::new(Hct::new(source_color), is_dark, contrast_level).scheme,
)
Scheme::from(SchemeNeutral::new(Hct::new(source_color), is_dark, contrast_level).scheme)
}
SchemeTypes::SchemeRainbow => {
Scheme::from(
SchemeRainbow::new(Hct::new(source_color), is_dark, contrast_level).scheme,
)
}
SchemeTypes::SchemeTonalSpot => {
Scheme::from(
SchemeTonalSpot::new(Hct::new(source_color), is_dark, contrast_level).scheme,
)
Scheme::from(SchemeRainbow::new(Hct::new(source_color), is_dark, contrast_level).scheme)
}
SchemeTypes::SchemeTonalSpot => Scheme::from(
SchemeTonalSpot::new(Hct::new(source_color), is_dark, contrast_level).scheme,
),
}
}
22 changes: 9 additions & 13 deletions src/util/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ pub fn show_color(schemes: &Schemes, source_color: &[u8; 4]) {
table.printstd();
}

pub fn dump_json(schemes: &Schemes, source_color: &[u8; 4], format: &Format) {
pub fn dump_json(
schemes: &Schemes,
source_color: &[u8; 4],
format: &Format,
harmonized_colors: &Option<HashMap<String, [u8; 4]>>,
) {
type F = Format;
let fmt = match format {
F::Rgb => |c: Rgb| format!("rgb({:?}, {:?}, {:?})", c.red(), c.green(), c.blue()),
Expand All @@ -131,18 +136,8 @@ pub fn dump_json(schemes: &Schemes, source_color: &[u8; 4], format: &Format) {
c.alpha()
)
},
F::Hsl => {
|c: Rgb| Hsl::from((c.red(), c.green(), c.blue())).to_css_string()
}
F::Hsla => |c: Rgb| {
Hsl::from((
c.red(),
c.green(),
c.blue(),
c.alpha(),
))
.to_css_string()
},
F::Hsl => |c: Rgb| Hsl::from((c.red(), c.green(), c.blue())).to_css_string(),
F::Hsla => |c: Rgb| Hsl::from((c.red(), c.green(), c.blue(), c.alpha())).to_css_string(),
F::Hex => |c: Rgb| c.to_hex_string(),
F::Strip => |c: Rgb| c.to_hex_string().replace('#', ""),
};
Expand All @@ -167,6 +162,7 @@ pub fn dump_json(schemes: &Schemes, source_color: &[u8; 4], format: &Format) {
"light": colors_normal_light,
"dark": colors_normal_dark,
},
"harmonized_colors": harmonized_colors,
})
);
}
Expand Down
42 changes: 7 additions & 35 deletions src/util/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Template {
source_color: &[u8; 4],
default_scheme: &SchemesEnum,
custom_keywords: &Option<HashMap<String, String>>,
harmonized_colors: Option<HashMap<String, [u8; 4]>>,
harmonized_colors: &Option<HashMap<String, [u8; 4]>>,
) -> Result<(), Report> {
let default_prefix = "@".to_string();

Expand Down Expand Up @@ -160,9 +160,7 @@ impl Template {
input_path_absolute.display(),
error
);
Report::new(error)
.wrap_err(message)
.suggestion("Make sure you closed the {{ opening properly.")
Report::new(error).wrap_err(message)
})?;

debug!(
Expand Down Expand Up @@ -196,36 +194,10 @@ impl Template {
"[{} - {}]\n{:#}",
name,
input_path_absolute.display(),
error
&error
);
Report::new(error).wrap_err(message).note(
r#"The following colors have been removed:
- color_accent_primary
- color_accent_primary_variant
- color_accent_secondary
- color_accent_secondary_variant
- color_accent_tertiary
- color_accent_tertiary_variant
- text_color_primary
- text_color_secondary:
- text_color_tertiary
- text_color_primary_inverse
- text_color_secondary_inverse
- text_color_tertiary_inverse
- color_background
- color_background_floating
- color_surface
- color_surface_variant
- color_surface_highlight
- surface_header
- under_surface
- off_state
- accent_surface
- text_primary_on_accent
- text_secondary_on_accent
- volume_background
"#,
)

Report::new(error).wrap_err(message)
})?;

let mut output_file = OpenOptions::new()
Expand Down Expand Up @@ -275,12 +247,12 @@ fn generate_colors(

fn generate_harmonized_colors(
_source_color: &[u8; 4],
harmonized_colors: Option<HashMap<String, [u8; 4]>>,
harmonized_colors: &Option<HashMap<String, [u8; 4]>>,
) -> Result<Option<HashMap<String, Colora>>, Report> {
if let Some(colors) = harmonized_colors {
let mut map: HashMap<String, Colora> = Default::default();
for (name, color) in colors {
map.insert(name, generate_color_strings(color));
map.insert(name.to_string(), generate_color_strings(*color));
}
Ok(Some(map))
} else {
Expand Down

0 comments on commit e278b4f

Please sign in to comment.