From 83e8ecc8e31335f6c9f5133549e34e337ecc7956 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Mon, 14 Oct 2024 17:34:43 +0200 Subject: [PATCH] Color: Add different color representations RgbString: e.g. "24,155,213" Rgb: e.g. [24 155 213] --- home/modules/color/default.nix | 47 ++++++++++++++++++++++++++-------- home/modules/color/options.nix | 10 ++++++++ 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/home/modules/color/default.nix b/home/modules/color/default.nix index 64276b8d..41466d48 100644 --- a/home/modules/color/default.nix +++ b/home/modules/color/default.nix @@ -45,20 +45,47 @@ in { lightDefs = import ./schemes/${color.lightScheme}.nix; darkDefs = import ./schemes/${color.darkScheme}.nix; - mkLightColorAssignment = key: {${key} = lightDefs.${key};}; - mkDarkColorAssignment = key: {${key} = darkDefs.${key};}; + mkColorAssignment = defs: key: {${key} = defs.${key};}; + mkRgbColorAssignment = defs: key: {${key} = mylib.color.hexToRGB defs.${key};}; + mkRgbStringColorAssignment = defs: key: {${key} = mylib.color.hexToRGBString "," defs.${key};}; in lib.mkIf color.enable { # This module sets its own options # to the values specified in a colorscheme file. - modules.color.light = lib.pipe colorKeys [ - (builtins.map mkLightColorAssignment) - lib.mergeAttrsList - ]; + modules.color = { + light = lib.pipe colorKeys [ + (builtins.map (mkColorAssignment lightDefs)) + lib.mergeAttrsList + ]; - modules.color.dark = lib.pipe colorKeys [ - (builtins.map mkDarkColorAssignment) - lib.mergeAttrsList - ]; + dark = lib.pipe colorKeys [ + (builtins.map (mkColorAssignment darkDefs)) + lib.mergeAttrsList + ]; + + rgb = { + light = lib.pipe colorKeys [ + (builtins.map (mkRgbColorAssignment lightDefs)) + lib.mergeAttrsList + ]; + + dark = lib.pipe colorKeys [ + (builtins.map (mkRgbColorAssignment darkDefs)) + lib.mergeAttrsList + ]; + }; + + rgbString = { + light = lib.pipe colorKeys [ + (builtins.map (mkRgbStringColorAssignment lightDefs)) + lib.mergeAttrsList + ]; + + dark = lib.pipe colorKeys [ + (builtins.map (mkRgbStringColorAssignment darkDefs)) + lib.mergeAttrsList + ]; + }; + }; }; } diff --git a/home/modules/color/options.nix b/home/modules/color/options.nix index 22b65dec..297daee4 100644 --- a/home/modules/color/options.nix +++ b/home/modules/color/options.nix @@ -62,4 +62,14 @@ in type = types.attrs; description = "Colors belonging to the selected dark scheme"; }; + + rgbString = mkOption { + type = types.attrs; + description = "Colors belonging to the selected light scheme in 'RR,GG,BB' format"; + }; + + rgb = mkOption { + type = types.attrs; + description = "Colors belonging to the selected light scheme in '[RR GG BB]' format"; + }; }