Skip to content

Commit

Permalink
Merge branch 'main' into custom_renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
InioX committed Nov 30, 2024
2 parents d674505 + 3a5e27b commit 78fd5b1
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aur.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ jobs:
commit_email: ${{ secrets.AUR_EMAIL }}
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
commit_message: 'chore(aur): update package'
ssh_keyscan_types: rsa,dsa,ecdsa,ed25519
ssh_keyscan_types: rsa,ecdsa,ed25519
93 changes: 93 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,99 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.4.1](https://github.com/InioX/matugen/compare/v2.4.0...v2.4.1) - 2024-11-13

### Fixed

- remove `wallpaper.set` option
- add `dump-json` to default featues

### Other

- run cargo fmt
- *(readme)* add discord server link

## [2.4.0](https://github.com/InioX/matugen/compare/v2.3.0...v2.4.0) - 2024-11-03

### Added

- add `mode` keyword
- *(filter)* add auto_lightness filter
- *(filter)* add camel_case filter
- custom expr and block prefix, postfix
- feature-gated web-image
- feature-gated dumping json
- feature-gated update-informer
- *(filters)* add `invert`, `grayscale and `set_hue`
- add timestamp to debug logs
- add more info to debug mode
- add `pre_hook` and `post_hook` ([#100](https://github.com/InioX/matugen/pull/100))
- improve error message for color parsing
- change resize filter to Lanczos3 ([#89](https://github.com/InioX/matugen/pull/89))
- increase windows stack size to 8mb (fixes [#87](https://github.com/InioX/matugen/pull/87))
- fix relative paths for templates, format `compare_to` ([#83](https://github.com/InioX/matugen/pull/83))
- add template formatting for hook ([#83](https://github.com/InioX/matugen/pull/83))
- add `hook` and variables inside it ([#83](https://github.com/InioX/matugen/pull/83))
- add color comparsion ([#83](https://github.com/InioX/matugen/pull/83))
- add `--prefix` argument
- add `version_check` setting ([#78](https://github.com/InioX/matugen/pull/78))

### Fixed

- `--help` flag not recognized ([#112](https://github.com/InioX/matugen/pull/112))
- parse color bug for rgb ([#107](https://github.com/InioX/matugen/pull/107))
- *(nix)* add dump-json feature build flag
- dump_json BTreeSet index
- apply more aggressive clippy lints
- removed deprecated default_features
- removed unused dependency
- cargo fmt & alejandra (nix formatter)
- made unix version compile
- wrong display of alpha channel for `set_alpha` ([#95](https://github.com/InioX/matugen/pull/95))
- divide all alpha values by 255 for output ([#95](https://github.com/InioX/matugen/pull/95))
- make hooks not depend on `colors_to_compare` ([#93](https://github.com/InioX/matugen/pull/93))
- remove useless debugging
- update arguments to remove borrow error ([#85](https://github.com/InioX/matugen/pull/85))

### Other

- run `cargo fmt`
- made contrast configurable in nix module
- make nix module able to generate from color or wallpaper.
- add backup config option to add in anything that isn't explicitly supported
- add custom colors option to nix module.
- format code
- add criterion bench
- move some stuff into template_util (prepare for criterion)
- add schemes_eq test
- use `BTreeSet`, remove `ahash` and `IndexMap`
- move template into src/
- Create rustfmt.yml
- update dependencies with breaking changes
- sorted dependencies
- removed unused dependency features
- made enquote only required for builds targeting macOS
- moved scheme out of module with only 1 file
- cargo update
- removed dependency proper-path-tools
- move some stuff into lib instead
- remove useless stuff, add clippy rules
- run cargo fmt + clippy fix
- oops bad merge ([#95](https://github.com/InioX/matugen/pull/95))
- Merge branch 'main' of https://github.com/InioX/matugen
- add float parameter for `format_hsla` and `format_rgba` ([#95](https://github.com/InioX/matugen/pull/95))
- update CHANGELOG.md
- add the set_alpha filter to the engine
- add format_rgba_float and format_hsla_float functions to format the alpha value as a float instead of u8
- add set_alpha filter
- Nix module: add package option
- bump `material-colors` to 0.4.0
- rename `compared_color` to `closest_color` ([#83](https://github.com/InioX/matugen/pull/83))
- separate some stuff into functions
- format code
- run `cargo fmt`
- *(readme)* update version badges

### Added
- add `set_alpha` filter

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "matugen"
version = "2.3.0"
version = "2.4.1"
authors = ["InioX"]
description = "A material you color generation tool with templates"
repository = "https://github.com/InioX/matugen"
Expand All @@ -18,6 +18,7 @@ winapi = { version = "0.3", features = ["winuser"] }
enquote = "1.1.0"

[features]
default = ["dump-json"]
update-informer = ["dep:update-informer"]
web-image = ["dep:reqwest"]
dump-json = ["dep:serde_json"]
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@
·
<a href="https://github.com/InioX/matugen/wiki">Wiki</a>
·
<a href="#-------------------------themes">Themes</a>
<a href="#--------------------themes">Themes</a>
</div>

<div align="center">
<sub>A cross-platform material you color generation tool
</div>

<div align="center">
<a href="https://discord.gg/JA3C2U9EcC">
<br>
<img src="https://github.com/user-attachments/assets/84f4e3a2-73ac-4112-8633-c02164c2c02c">
</a>
</div>

<div align="center">
<img src="https://github.com/InioX/matugen/assets/81521595/9008d8d9-0157-4b38-9500-597986a2cb9f">
</div>
Expand Down
12 changes: 5 additions & 7 deletions example/config.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[config]
# version_check = true
set_wallpaper = true
wallpaper_tool = 'Swww'
prefix = '@'
swww_options = [
"--transition-type",
"center",
]

[config.wallpaper]
command = "swww"
arguments = ["img", "--transition-type", "center"]
# pre_hook = ""

[config.custom_keywords]
test = "aaaa"
Expand Down
8 changes: 8 additions & 0 deletions src/color/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ pub fn rgb_from_argb(color: Argb) -> Rgb {
])
}

pub fn hsl_from_argb(color: Argb) -> Hsl {
rgb_from_argb(color).as_ref().into()
}

pub fn hsl_from_rgb(color: Rgb) -> Hsl {
color.as_ref().into()
}

pub fn format_hex(color: &Rgb) -> String {
color.to_hex_string()
}
Expand Down
6 changes: 1 addition & 5 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ pub fn set_wallpaper(source: &Source, wallpaper_cfg: wallpaper::Wallpaper) -> Re
#[cfg(feature = "web-image")]
Source::WebImage { .. } => return Ok(()),
};
if !wallpaper_cfg.set {
return Ok(warn!(
"<d>Wallpaper setting disabled, not setting wallpaper...</>"
));
};

#[cfg(target_os = "windows")]
wallpaper::windows::set(path)?;
#[cfg(target_os = "macos")]
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
extern crate pretty_env_logger;
#[macro_use]
extern crate paris_log;
use material_colors::theme::ThemeBuilder;

mod helpers;
pub mod template;
Expand Down Expand Up @@ -37,7 +38,10 @@ fn main() -> Result<(), Report> {
check_version();

Check warning on line 38 in src/main.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/matugen/matugen/src/main.rs
}


let source_color = get_source_color(&args.source).unwrap();

let theme = ThemeBuilder::with_source(source_color).build();

let (scheme_dark, scheme_light) = get_schemes(source_color, &args.r#type, &args.contrast);

Expand All @@ -61,7 +65,7 @@ fn main() -> Result<(), Report> {
#[cfg(feature = "dump-json")]
if let Some(ref format) = args.json {
use crate::util::color::dump_json;
dump_json(&schemes, &source_color, format);
dump_json(&schemes, &source_color, format, theme.palettes);
}

if args.dry_run == Some(false) {
Expand Down
96 changes: 70 additions & 26 deletions src/util/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ use material_colors::color::Argb;
use owo_colors::{OwoColorize, Style};

use prettytable::{format, Cell, Row, Table};
use material_colors::theme::Palettes;
use material_colors::palette::TonalPalette;

use colorsys::Rgb;

use crate::Schemes;

#[cfg(feature = "dump-json")]
use super::arguments::Format;

use colorsys::Rgb;
use matugen::color::format::rgb_from_argb;

pub fn show_color(schemes: &Schemes, source_color: &Argb) {
Expand All @@ -32,53 +35,94 @@ pub fn show_color(schemes: &Schemes, source_color: &Argb) {
}

#[cfg(feature = "dump-json")]
pub fn dump_json(schemes: &Schemes, source_color: &Argb, format: &Format) {
use colorsys::{ColorAlpha, Hsl};
use serde_json::json;
pub fn dump_json(schemes: &Schemes, source_color: &Argb, format: &Format, palettes: Palettes) {
use std::collections::HashMap;

type F = Format;
let fmt = match format {
F::Rgb => |c: Rgb| format!("rgb({:?}, {:?}, {:?})", c.red(), c.green(), c.blue()),
F::Rgba => |c: Rgb| {
format!(
"rgba({:?}, {:?}, {:?}, {:?})",
c.red(),
c.green(),
c.blue(),
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::Hex => |c: Rgb| c.to_hex_string(),
F::Strip => |c: Rgb| c.to_hex_string().replace('#', ""),
};

let mut colors_normal_light: HashMap<&str, String> = HashMap::new();
let mut colors_normal_dark: HashMap<&str, String> = HashMap::new();

for ((field, color_light), (_, color_dark)) in std::iter::zip(&schemes.light, &schemes.dark) {
let color_light: Rgb = rgb_from_argb(*color_light);
let color_dark: Rgb = rgb_from_argb(*color_dark);

colors_normal_light.insert(field, fmt(color_light));
colors_normal_dark.insert(field, fmt(color_dark));
colors_normal_light.insert(field, format_single_color(color_light, format));
colors_normal_dark.insert(field, format_single_color(color_dark, format));

Check warning on line 49 in src/util/color.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/matugen/matugen/src/util/color.rs
}

colors_normal_light.insert("source_color", fmt(rgb_from_argb(*source_color)));
colors_normal_light.insert("source_color", format_single_color(rgb_from_argb(*source_color), format));

println!(
"{}",
json!({
serde_json::json!({
"colors": {
"light": colors_normal_light,
"dark": colors_normal_dark,
},
"palettes": format_palettes(palettes, format),
})
);
}

#[cfg(feature = "dump-json")]
fn format_palettes(palettes: Palettes, format: &Format) -> serde_json::Value {

Check warning on line 67 in src/util/color.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/matugen/matugen/src/util/color.rs
let primary = format_single_palette(palettes.primary, format);
let secondary = format_single_palette(palettes.secondary, format);
let tertiary = format_single_palette(palettes.tertiary, format);
let neutral = format_single_palette(palettes.neutral, format);
let neutral_variant = format_single_palette(palettes.neutral_variant, format);
let error = format_single_palette(palettes.error, format);
serde_json::json!({
"primary": primary,
"secondary": secondary,
"tertiary": tertiary,
"neutral": neutral,
"neutral_variant": neutral_variant,
"error": error,
})
}

#[cfg(feature = "dump-json")]
fn format_single_palette(palette: TonalPalette, format: &Format) -> serde_json::Value {
serde_json::json!({
"0": format_single_color(rgb_from_argb(palette.tone(0)), format),
"5": format_single_color(rgb_from_argb(palette.tone(5)), format),
"10": format_single_color(rgb_from_argb(palette.tone(10)), format),
"15": format_single_color(rgb_from_argb(palette.tone(15)), format),
"20": format_single_color(rgb_from_argb(palette.tone(20)), format),
"25": format_single_color(rgb_from_argb(palette.tone(25)), format),
"30": format_single_color(rgb_from_argb(palette.tone(30)), format),
"35": format_single_color(rgb_from_argb(palette.tone(35)), format),
"40": format_single_color(rgb_from_argb(palette.tone(40)), format),
"45": format_single_color(rgb_from_argb(palette.tone(45)), format),
"50": format_single_color(rgb_from_argb(palette.tone(50)), format),
"55": format_single_color(rgb_from_argb(palette.tone(55)), format),
"60": format_single_color(rgb_from_argb(palette.tone(60)), format),
"65": format_single_color(rgb_from_argb(palette.tone(65)), format),
"70": format_single_color(rgb_from_argb(palette.tone(70)), format),
"75": format_single_color(rgb_from_argb(palette.tone(75)), format),
"80": format_single_color(rgb_from_argb(palette.tone(80)), format),
"85": format_single_color(rgb_from_argb(palette.tone(85)), format),
"90": format_single_color(rgb_from_argb(palette.tone(90)), format),
"95": format_single_color(rgb_from_argb(palette.tone(95)), format),
"100": format_single_color(rgb_from_argb(palette.tone(100)), format),
})
}

Check warning on line 110 in src/util/color.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/matugen/matugen/src/util/color.rs
#[cfg(feature = "dump-json")]
fn format_single_color(color: Rgb, format: &Format) -> String {
use matugen::color::format::{format_hex, format_hex_stripped, format_hsl, format_hsla, format_rgb, format_rgba, hsl_from_rgb};

let fmt = match format {
Format::Rgb => |c: Rgb| format_rgb(&c),
Format::Rgba => |c: Rgb| format_rgba(&c, true),
Format::Hsl => |c: Rgb| format_hsl(&hsl_from_rgb(c)),
Format::Hsla => |c: Rgb| format_hsla(&hsl_from_rgb(c), true),
Format::Hex => |c: Rgb| format_hex(&c),
Format::Strip => |c: Rgb| format_hex_stripped(&c),
};
fmt(color)
}

fn generate_table_format() -> Table {
let mut table = Table::new();
let format = format::FormatBuilder::new()
Expand Down
1 change: 0 additions & 1 deletion src/wallpaper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Wallpaper {
pub set: bool,
/// Useful for, for example, killing the wallpaper daemon
pub pre_hook: Option<String>,
pub command: String,
Expand Down

0 comments on commit 78fd5b1

Please sign in to comment.