2024-10-01 15:53:23 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: let
|
2024-10-06 10:14:35 +00:00
|
|
|
# convert rrggbb hex to rgba(r, g, b, a) CSS format
|
|
|
|
rgba = c: let
|
|
|
|
r = toString (hexToDec (builtins.substring 0 2 c));
|
|
|
|
g = toString (hexToDec (builtins.substring 2 2 c));
|
|
|
|
b = toString (hexToDec (builtins.substring 4 2 c));
|
|
|
|
in "rgba(${r}, ${g}, ${b}, .5)";
|
|
|
|
|
2024-10-01 15:53:23 +00:00
|
|
|
# Helper function to convert hex color to decimal RGB values
|
|
|
|
hexToDec = v: let
|
|
|
|
hexToInt = {
|
|
|
|
"0" = 0;
|
|
|
|
"1" = 1;
|
|
|
|
"2" = 2;
|
|
|
|
"3" = 3;
|
|
|
|
"4" = 4;
|
|
|
|
"5" = 5;
|
|
|
|
"6" = 6;
|
|
|
|
"7" = 7;
|
|
|
|
"8" = 8;
|
|
|
|
"9" = 9;
|
|
|
|
"a" = 10;
|
|
|
|
"b" = 11;
|
|
|
|
"c" = 12;
|
|
|
|
"d" = 13;
|
|
|
|
"e" = 14;
|
|
|
|
"f" = 15;
|
|
|
|
"A" = 10;
|
|
|
|
"B" = 11;
|
|
|
|
"C" = 12;
|
|
|
|
"D" = 13;
|
|
|
|
"E" = 14;
|
|
|
|
"F" = 15;
|
|
|
|
};
|
|
|
|
chars = lib.strings.stringToCharacters v;
|
|
|
|
in
|
2024-10-06 10:14:35 +00:00
|
|
|
lib.foldl' (a: v: a + v) 0
|
|
|
|
(lib.imap (k: v: hexToInt."${v}" * (pow 16 (builtins.length chars - k - 1))) chars);
|
2024-10-01 15:53:23 +00:00
|
|
|
|
|
|
|
# Power function for exponentiation
|
2024-10-06 10:14:35 +00:00
|
|
|
pow = base: exponent: lib.foldl' (acc: _: acc * base) 1 (lib.range 1 exponent);
|
2024-10-01 15:53:23 +00:00
|
|
|
|
|
|
|
# Converts hex color to KDE color format
|
|
|
|
colorToKde = name: hexColor: let
|
|
|
|
r = hexToDec (builtins.substring 0 2 hexColor);
|
|
|
|
g = hexToDec (builtins.substring 2 2 hexColor);
|
|
|
|
b = hexToDec (builtins.substring 4 2 hexColor);
|
|
|
|
in "[${name}]\nColor=${toString r},${toString g},${toString b}\n";
|
|
|
|
|
|
|
|
# Mapping base16 colors to KDE color scheme sections
|
|
|
|
schemeToKonsole = scheme: let
|
|
|
|
inherit (scheme) palette;
|
|
|
|
|
|
|
|
colorMap = {
|
|
|
|
base00 = ["Background" "BackgroundFaint" "BackgroundIntense"];
|
|
|
|
base01 = ["Color0"];
|
|
|
|
base02 = ["Color0Intense"];
|
|
|
|
base04 = ["Color4"];
|
|
|
|
base05 = ["Foreground" "ForegroundFaint" "ForegroundIntense"];
|
|
|
|
base06 = ["Color7"];
|
|
|
|
base07 = ["Color7Intense"];
|
|
|
|
base08 = ["Color1" "Color1Intense"];
|
|
|
|
base09 = ["Color1Intense"];
|
|
|
|
base0A = ["Color3" "Color3Intense"];
|
|
|
|
base0B = ["Color2" "Color2Intense"];
|
|
|
|
base0C = ["Color6" "Color6Intense"];
|
|
|
|
base0D = ["Color4" "Color4Intense"];
|
|
|
|
base0E = ["Color5" "Color5Intense"];
|
|
|
|
};
|
|
|
|
|
|
|
|
colorSections = lib.concatStringsSep "\n" (lib.attrsets.mapAttrsToList
|
2024-10-06 10:14:35 +00:00
|
|
|
(name: value:
|
|
|
|
lib.concatMapStrings (slot: colorToKde slot value) (colorMap.${name} or []))
|
2024-10-01 15:53:23 +00:00
|
|
|
palette);
|
|
|
|
in
|
2024-10-06 10:14:35 +00:00
|
|
|
lib.concatStringsSep "\n" [
|
|
|
|
"[General]"
|
|
|
|
"Description=${scheme.name}"
|
|
|
|
"Opacity=1"
|
|
|
|
"Wallpaper="
|
|
|
|
colorSections
|
|
|
|
];
|
2024-10-01 15:53:23 +00:00
|
|
|
|
2024-10-06 10:14:35 +00:00
|
|
|
# Create a KDE konsole color scheme from base16 colors
|
2024-10-01 15:53:23 +00:00
|
|
|
mkKonsoleColorScheme = scheme:
|
|
|
|
pkgs.writeText "${scheme.name}.colorscheme" (schemeToKonsole scheme);
|
2024-10-06 10:14:35 +00:00
|
|
|
in {
|
|
|
|
inherit mkKonsoleColorScheme rgba;
|
|
|
|
}
|