types/theme.nix: add check regex matching

types/theme.nix: fixed regex matching
This commit is contained in:
Charlie Root 2024-10-04 23:01:41 +02:00
parent 7ba06fd77c
commit b2f694c78e
No known key found for this signature in database

View file

@ -1,13 +1,14 @@
{lib}: let
inherit (lib.strings) isString hasPrefix;
inherit (lib.strings) isString;
inherit (lib.types) mkOptionType;
inherit (builtins) stringLength;
inherit (builtins) match;
# This was almost entirely taken from raf himself.
in {
hexColorType = mkOptionType {
name = "hex-color";
descriptionClass = "noun";
description = "RGB color in hex format";
check = x: isString x && hasPrefix "#" x && stringLength x == 7;
# Check to determine wether the provided color is base16-valid
check = x: isString x && (match "#[0-9a-fA-F]{6}" x) != null;
};
}