From 25b4f61512a76d75aa94b44bb666fd899cf8bf5e Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Mon, 16 Mar 2026 23:46:49 -0400 Subject: update caelestia and its theming --- lib/colors.nix | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/default.nix | 2 ++ 2 files changed, 68 insertions(+) create mode 100644 lib/colors.nix (limited to 'lib') diff --git a/lib/colors.nix b/lib/colors.nix new file mode 100644 index 0000000..a653f11 --- /dev/null +++ b/lib/colors.nix @@ -0,0 +1,66 @@ +{lib, ...}: let + colorToInt = hex: let + table = { + "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; + }; + in + builtins.foldl' + (acc: c: acc * 16 + table.${c}) + 0 + (lib.strings.stringToCharacters (lib.strings.toLower hex)); + + colorToHex = n: let + hexChars = "0123456789abcdef"; + hi = builtins.div n 16; + lo = lib.trivial.mod n 16; + in + builtins.substring hi 1 hexChars + + builtins.substring lo 1 hexChars; + + mapColor = f: hex: let + r = colorToInt (builtins.substring 0 2 hex); + g = colorToInt (builtins.substring 2 2 hex); + b = colorToInt (builtins.substring 4 2 hex); + in + colorToHex (f r) + + colorToHex (f g) + + colorToHex (f b); + + darkenColor = factor: hex: + mapColor (c: builtins.floor (c * (1 - factor))) hex; + + lightenColor = factor: hex: + mapColor (c: builtins.floor (c + (255 - c) * factor)) hex; + + mixColor = factor: hex1: hex2: let + r1 = colorToInt (builtins.substring 0 2 hex1); + g1 = colorToInt (builtins.substring 2 2 hex1); + b1 = colorToInt (builtins.substring 4 2 hex1); + r2 = colorToInt (builtins.substring 0 2 hex2); + g2 = colorToInt (builtins.substring 2 2 hex2); + b2 = colorToInt (builtins.substring 4 2 hex2); + r = builtins.floor (r1 * factor) + builtins.floor (r2 * (1 - factor)); + g = builtins.floor (g1 * factor) + builtins.floor (g2 * (1 - factor)); + b = builtins.floor (b1 * factor) + builtins.floor (b2 * (1 - factor)); + in + colorToHex r + + colorToHex g + + colorToHex b; +in { + inherit colorToInt colorToHex darkenColor lightenColor mixColor; +} diff --git a/lib/default.nix b/lib/default.nix index b501184..21031c8 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,8 +1,10 @@ {lib, ...} @ inputs: let callLibs = file: import file inputs; files = callLibs ./files.nix; + colors = callLibs ./colors.nix; in { inherit (files) getFiles certs sshKeys gpgKeys; + inherit (colors) colorToInt colorToHex darkenColor lightenColor mixColor; # set of options we want to copy from a system # config to home manager -- cgit v1.2.3-freya