1

Modules/Color: Add hex string representation (e.g. "#123456" instead of "123456")

This commit is contained in:
2025-07-19 15:47:20 +02:00
parent 8258d96723
commit 4eed506642
2 changed files with 44 additions and 24 deletions

View File

@ -16,46 +16,61 @@ in {
colorKeys = builtins.attrNames lightDefs;
mkColorAssignment = defs: key: {${key} = defs.${key};};
mkStringColorAssignment = defs: key: {${key} = "#${defs.${key}}";};
mkRgbColorAssignment = defs: key: {${key} = mylib.color.hexToRGB defs.${key};};
mkRgbStringColorAssignment = defs: key: {${key} = mylib.color.hexToRGBString "," defs.${key};};
in {
# This module sets its own options
# to the values specified in a colorscheme file.
# TODO: This is fucking stupid. Add an option to set a colorscheme,
# then provide a single hex/rgb/rgbString set, not this light/dark shit.
modules.color = {
hex = {
light = lib.pipe colorKeys [
(builtins.map (mkColorAssignment lightDefs))
lib.mergeAttrsList
];
light =
colorKeys
|> builtins.map (mkColorAssignment lightDefs)
|> lib.mergeAttrsList;
dark = lib.pipe colorKeys [
(builtins.map (mkColorAssignment darkDefs))
lib.mergeAttrsList
];
dark =
colorKeys
|> builtins.map (mkColorAssignment darkDefs)
|> lib.mergeAttrsList;
};
hexString = {
light =
colorKeys
|> builtins.map (mkStringColorAssignment lightDefs)
|> lib.mergeAttrsList;
dark =
colorKeys
|> builtins.map (mkStringColorAssignment darkDefs)
|> lib.mergeAttrsList;
};
rgb = {
light = lib.pipe colorKeys [
(builtins.map (mkRgbColorAssignment lightDefs))
lib.mergeAttrsList
];
light =
colorKeys
|> builtins.map (mkRgbColorAssignment lightDefs)
|> lib.mergeAttrsList;
dark = lib.pipe colorKeys [
(builtins.map (mkRgbColorAssignment darkDefs))
lib.mergeAttrsList
];
dark =
colorKeys
|> builtins.map (mkRgbColorAssignment darkDefs)
|> lib.mergeAttrsList;
};
rgbString = {
light = lib.pipe colorKeys [
(builtins.map (mkRgbStringColorAssignment lightDefs))
lib.mergeAttrsList
];
light =
colorKeys
|> builtins.map (mkRgbStringColorAssignment lightDefs)
|> lib.mergeAttrsList;
dark = lib.pipe colorKeys [
(builtins.map (mkRgbStringColorAssignment darkDefs))
lib.mergeAttrsList
];
dark =
colorKeys
|> builtins.map (mkRgbStringColorAssignment darkDefs)
|> lib.mergeAttrsList;
};
};
};

View File

@ -33,6 +33,11 @@ with mylib.modules; {
description = "Colors in \"RRGGBB\" hexadecimal format";
};
hexString = mkOption {
type = types.attrs;
description = "Colors in \"#RRGGBB\" hexadecimal format";
};
rgbString = mkOption {
type = types.attrs;
description = "Colors in \"RR,GG,BB\" decimal format";