cava: refactor + fix rainbow.enable description (#1276)

Link: https://github.com/danth/stylix/pull/1276
This commit is contained in:
awwpotato 2025-05-16 10:13:53 -07:00 committed by GitHub
parent 0e5b1613bd
commit 49b1eb9371
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,43 +1,40 @@
{ config, lib, ... }:
let
mkGradient =
colors:
lib.listToAttrs (
lib.imap0 (
i: c: lib.nameValuePair "gradient_color_${toString (i + 1)}" "'#${c}'"
) colors
)
// {
gradient = 1;
gradient_count = builtins.length colors;
};
rainbowColors = with config.lib.stylix.colors; [
base0E
base0D
base0C
base0B
base0A
base09
base08
];
in
{
options.stylix.targets.cava = {
enable = config.lib.stylix.mkEnableTarget "CAVA" true;
rainbow.enable = config.lib.stylix.mkEnableTarget "rainbow gradient theming" false;
rainbow.enable = lib.mkEnableOption "rainbow gradient theming";
};
config =
let
cfg = config.stylix.targets.cava;
mkGradient =
colors:
lib.listToAttrs (
lib.imap0 (
i: c: lib.nameValuePair "gradient_color_${toString (i + 1)}" "'#${c}'"
) colors
)
// {
gradient = 1;
gradient_count = builtins.length colors;
};
in
lib.mkIf (config.stylix.enable && cfg.enable) {
programs.cava.settings.color = lib.mkIf cfg.rainbow.enable (
mkGradient rainbowColors
mkGradient (
with config.lib.stylix.colors;
[
base0E
base0D
base0C
base0B
base0A
base09
base08
]
)
);
};
}