1

Modules/Color: Prepare applyColors helper script

This commit is contained in:
2025-07-19 17:50:47 +02:00
parent 4dabf6d05d
commit 3daefbad68
2 changed files with 40 additions and 2 deletions

View File

@ -0,0 +1,16 @@
import fileinput
colors: dict[str, str]
# colors: dict[str, str] = {
# "rosewater": "f5e0dc",
# "flamingo": "f2cdcd",
# }
def applyColorToLine(line: str) -> None:
print(f"{line} # piped")
# Apply transformation to every line from stdin
for line in fileinput.input():
applyColorToLine(line)

View File

@ -2,6 +2,7 @@
config,
lib,
mylib,
pkgs,
...
}: let
inherit (config.modules) color;
@ -20,8 +21,29 @@ in {
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.
# Helper script that processes a visual mode selection and replaces
# referenced colors in-place with their counterparts in this module.
# Usage: '<,'>!applyColors<cr>
home.packages = let
applyColors = let
mkPythonColorDef = name: value: " '${name}': '${value}',";
in
pkgs.writers.writePython3Bin
"applyColors"
(
builtins.concatStringsSep "\n" [
"colors: dict[str, str] = {"
(config.modules.color.hex.dark
|> builtins.mapAttrs mkPythonColorDef
|> builtins.attrValues
|> builtins.concatStringsSep "\n")
"}"
(builtins.readFile ./applyColors.py)
]
);
in [applyColors];
# 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 = {