bahaghari/lib: init generateGlyphSet

This commit is contained in:
Gabriel Arazas 2024-02-24 18:59:25 +08:00
parent 8f7e13734a
commit e8bdb850bc
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
3 changed files with 30 additions and 1 deletions

View File

@ -20,6 +20,6 @@ pkgs.lib.makeExtensible
# a top-level attribute. # a top-level attribute.
tinted-theming = callLibs ./tinted-theming.nix; tinted-theming = callLibs ./tinted-theming.nix;
inherit (self.trivial) importYAML toYAML toBaseDigitsWithGlyphs; inherit (self.trivial) importYAML toYAML toBaseDigitsWithGlyphs generateGlyphSet;
inherit (self.hex) toHexString; inherit (self.hex) toHexString;
}) })

View File

@ -46,4 +46,19 @@
toBaseDigits = d: glyphs.${builtins.toString d}; toBaseDigits = d: glyphs.${builtins.toString d};
in in
pkgs.lib.concatMapStrings toBaseDigits baseDigits; pkgs.lib.concatMapStrings toBaseDigits baseDigits;
/* Generates a glyph set usable for `toBaseDigitsWithGlyphs`. Take note the
given list is assumed to be sorted and the generated glyph set starts at
`0` up to (`listLength - 1`).
Type: generateGlyphSet :: [ String ] -> Attrs
Example:
generateGlyphSet [ "0" "1" "2" "3" "4" "5" "6" "7" "8 "9" "A" "B" "C" "D" "E" "F" ]
*/
generateGlyphSet = glyphsList:
let
glyphsList' = pkgs.lib.lists.imap0 (i: glyph: { "${builtins.toString i}" = glyph; }) glyphsList;
in
pkgs.lib.foldl (acc: glyph: acc // glyph) { } glyphsList';
} }

View File

@ -40,6 +40,20 @@ let
}; };
in in
pkgs.lib.runTests { pkgs.lib.runTests {
testGenerateCustomGlyphSet = {
expr = lib.trivial.generateGlyphSet [ "A" "B" "C" "D" "E" "F" "G" "H" ];
expected = customOctalGlyphs;
};
testGenerateBase24GlyphSet = {
expr =
lib.trivial.generateGlyphSet
[ "0" "1" "2" "3" "4" "5" "6" "7"
"8" "9" "A" "B" "C" "D" "E" "F"
"G" "H" "I" "J" "M" "N" "O" "P" ];
expected = customBase24Glyphs;
};
testBaseDigitWithCustomOctalGlyph = { testBaseDigitWithCustomOctalGlyph = {
expr = lib.trivial.toBaseDigitsWithGlyphs 8 9 customOctalGlyphs; expr = lib.trivial.toBaseDigitsWithGlyphs 8 9 customOctalGlyphs;
expected = "BB"; expected = "BB";