# Shared palette and adapters for the hand-tuned application themes.
let
name = import ../theme.nix;
rosePine = {
base = "#191724"; surface = "#1f1d2e"; overlay = "#26233a";
muted = "#6e6a86"; subtle = "#908caa"; text = "#e0def4";
love = "#eb6f92"; gold = "#f6c177"; rose = "#ebbcba";
pine = "#31748f"; foam = "#9ccfd8"; iris = "#c4a7e7";
hlLow = "#21202e"; hlMed = "#403d52"; hlHigh = "#524f67";
};
# Gruvbox's warm charcoal, cream, yellow and sage; Rosé Pine's soft accents.
gruvpine = rosePine // {
base = "#282828"; surface = "#32302f"; overlay = "#3c3836";
muted = "#928374"; subtle = "#a89984"; text = "#ebdbb2";
gold = "#fabd2f"; pine = "#b8bb26";
hlLow = "#32302f"; hlMed = "#504945"; hlHigh = "#665c54";
};
gruvbox = gruvpine // {
love = "#fb4934"; rose = "#fe8019"; foam = "#8ec07c";
iris = "#d3869b";
};
palettes = { "rose-pine" = rosePine; inherit gruvpine gruvbox; };
palette = palettes.${name} or (throw "Unknown theme ${name}; choose rose-pine, gruvpine or gruvbox in theme.nix");
keys = builtins.attrNames rosePine;
hexDigits = [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" ];
digit = c: let find = n: if builtins.elemAt hexDigits n == c then n else find (n + 1); in find 0;
channel = s: offset: 16 * digit (builtins.substring offset 1 s) + digit (builtins.substring (offset + 1) 1 s);
bare = s: builtins.substring 1 6 s;
in {
inherit name palette rosePine gruvpine gruvbox;
sgr = builtins.mapAttrs (_: color: "38;2;${toString (channel color 1)};${toString (channel color 3)};${toString (channel color 5)}") palette;
base16 = {
base00 = palette.base; base01 = palette.surface; base02 = palette.hlMed;
base03 = palette.muted; base04 = palette.subtle; base05 = palette.text;
base06 = "#f2e5bc"; base07 = "#fbf1c7"; base08 = palette.love;
base09 = palette.rose; base0A = palette.gold; base0B = palette.pine;
base0C = palette.foam; base0D = palette.foam; base0E = palette.iris;
base0F = "#d3869b";
};
# Recolour existing Lua, JSON, RON and syntax themes without duplicating them.
render = text: builtins.replaceStrings
((map (k: bare rosePine.${k}) keys) ++ [ "16141f" "2a273f" ])
((map (k: bare palette.${k}) keys) ++ (if name != "rose-pine" then [ "1d2021" "3c3836" ] else [ "16141f" "2a273f" ]))
text;
}