diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/default.nix | 2 | ||||
-rw-r--r-- | lib/genid.nix | 3 | ||||
-rw-r--r-- | lib/svg-colors.json | 149 | ||||
-rw-r--r-- | lib/types.nix | 38 |
4 files changed, 185 insertions, 7 deletions
diff --git a/lib/default.nix b/lib/default.nix index 280f04299..187514a30 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -45,6 +45,8 @@ let genid_uint31 = x: ((lib.genid_uint32 x) + 16777216) / 2; genid_uint32 = import ./genid.nix { inherit lib; }; + hexchars = stringToCharacters "0123456789abcdef"; + lpad = n: c: s: if lib.stringLength s < n then lib.lpad n c (c + s) diff --git a/lib/genid.nix b/lib/genid.nix index 0aed1d351..bfa4a9a03 100644 --- a/lib/genid.nix +++ b/lib/genid.nix @@ -32,6 +32,5 @@ let out = genid; hexint = x: hexvals.${toLower x}; # :: attrset char uint4 - hexvals = listToAttrs (imap (i: c: { name = c; value = i - 1; }) - (stringToCharacters "0123456789abcdef")); + hexvals = listToAttrs (imap (i: c: { name = c; value = i - 1; }) hexchars); in out diff --git a/lib/svg-colors.json b/lib/svg-colors.json new file mode 100644 index 000000000..834bf14f4 --- /dev/null +++ b/lib/svg-colors.json @@ -0,0 +1,149 @@ +[ + "aliceblue", + "antiquewhite", + "aqua", + "aquamarine", + "azure", + "beige", + "bisque", + "black", + "blanchedalmond", + "blue", + "blueviolet", + "brown", + "burlywood", + "cadetblue", + "chartreuse", + "chocolate", + "coral", + "cornflowerblue", + "cornsilk", + "crimson", + "cyan", + "darkblue", + "darkcyan", + "darkgoldenrod", + "darkgray", + "darkgreen", + "darkgrey", + "darkkhaki", + "darkmagenta", + "darkolivegreen", + "darkorange", + "darkorchid", + "darkred", + "darksalmon", + "darkseagreen", + "darkslateblue", + "darkslategray", + "darkslategrey", + "darkturquoise", + "darkviolet", + "deeppink", + "deepskyblue", + "dimgray", + "dimgrey", + "dodgerblue", + "firebrick", + "floralwhite", + "forestgreen", + "fuchsia", + "gainsboro", + "ghostwhite", + "gold", + "goldenrod", + "gray", + "green", + "greenyellow", + "grey", + "honeydew", + "hotpink", + "indianred", + "indigo", + "ivory", + "khaki", + "lavender", + "lavenderblush", + "lawngreen", + "lemonchiffon", + "lightblue", + "lightcoral", + "lightcyan", + "lightgoldenrodyellow", + "lightgray", + "lightgreen", + "lightgrey", + "lightpink", + "lightsalmon", + "lightseagreen", + "lightskyblue", + "lightslategray", + "lightslategrey", + "lightsteelblue", + "lightyellow", + "lime", + "limegreen", + "linen", + "magenta", + "maroon", + "mediumaquamarine", + "mediumblue", + "mediumorchid", + "mediumpurple", + "mediumseagreen", + "mediumslateblue", + "mediumspringgreen", + "mediumturquoise", + "mediumvioletred", + "midnightblue", + "mintcream", + "mistyrose", + "moccasin", + "navajowhite", + "navy", + "oldlace", + "olive", + "olivedrab", + "orange", + "orangered", + "orchid", + "palegoldenrod", + "palegreen", + "paleturquoise", + "palevioletred", + "papayawhip", + "peachpuff", + "peru", + "pink", + "plum", + "powderblue", + "purple", + "red", + "rosybrown", + "royalblue", + "saddlebrown", + "salmon", + "sandybrown", + "seagreen", + "seashell", + "sienna", + "silver", + "skyblue", + "slateblue", + "slategray", + "slategrey", + "snow", + "springgreen", + "steelblue", + "tan", + "teal", + "thistle", + "tomato", + "turquoise", + "violet", + "wheat", + "white", + "whitesmoke", + "yellow", + "yellowgreen" +] diff --git a/lib/types.nix b/lib/types.nix index 32b4541ae..5f01ccb52 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -3,11 +3,11 @@ let inherit (lib) all any attrNames concatMapStringsSep concatStringsSep const filter flip - genid_uint31 hasSuffix head isInt isString length mergeOneOption mkOption - mkOptionType optional optionalAttrs optionals range splitString + genid_uint31 hasSuffix head importJSON isInt isString length mergeOneOption + mkOption mkOptionType optional optionalAttrs optionals range splitString stringLength substring test testString typeOf; inherit (lib.types) - attrsOf bool either enum int lines listOf nullOr path str submodule; + addCheck attrsOf bool either enum int lines listOf nullOr path str submodule; in rec { @@ -287,15 +287,27 @@ rec { }; }); + boundedInt = min: max: mkOptionType { + name = "bounded integer"; + check = x: isInt x && min <= x && x <= max; + merge = mergeOneOption; + }; + + lowerBoundedInt = min: mkOptionType { + name = "lower bounded integer"; + check = x: isInt x && min <= x; + merge = mergeOneOption; + }; + positive = mkOptionType { + inherit (lowerBoundedInt 1) check; name = "positive integer"; - check = x: isInt x && x > 0; merge = mergeOneOption; }; uint = mkOptionType { + inherit (lowerBoundedInt 0) check; name = "unsigned integer"; - check = x: isInt x && x >= 0; merge = mergeOneOption; }; @@ -583,6 +595,9 @@ rec { }; }; + flameshot.color = + either (addCheck str (test "#[0-9A-Fa-f]{6}")) svg.color-keyword; + file-mode = mkOptionType { name = "file mode"; check = test "[0-7]{4}"; @@ -601,6 +616,19 @@ rec { merge = mergeOneOption; }; + # SVG 1.1, 4.4 Recognized color keyword names + # + # svg-colors.json has been generated with: + # curl -sS https://www.w3.org/TR/SVG11/types.html#ColorKeywords | + # fq -d html '[ + # grep_by(.["@class"]=="color-keywords") | + # grep_by(.["@class"]=="prop-value"and.["#text"]!="").["#text"] + # ] | sort' + # + svg.color-keyword = enum (importJSON ./svg-colors.json) // { + name = "SVG 1.1 recognized color keyword"; + }; + systemd.unit-name = mkOptionType { name = "systemd unit name"; check = x: |