Palette library integrated + polybar and alacritty
This commit is contained in:
parent
a61bfe3c50
commit
ef5b48d142
17 changed files with 1090 additions and 214 deletions
46
extra/hex/default.nix
Normal file
46
extra/hex/default.nix
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{ pkgs, lib ? pkgs.lib, ... }:
|
||||
let
|
||||
inherit (lib.trivial) toHexString;
|
||||
inherit (lib.strings) match toUpper stringToCharacters;
|
||||
inherit (lib.lists) foldl;
|
||||
|
||||
# Parse a single hexadecimal digit to an integer
|
||||
_parseDigit = c:
|
||||
let
|
||||
v = toUpper c;
|
||||
in
|
||||
assert(match "[0-9A-F]" v != null);
|
||||
{
|
||||
"0" = 0;
|
||||
"1" = 1;
|
||||
"2" = 2;
|
||||
"3" = 3;
|
||||
"4" = 4;
|
||||
"5" = 5;
|
||||
"6" = 6;
|
||||
"7" = 7;
|
||||
"8" = 8;
|
||||
"9" = 9;
|
||||
"A" = 10;
|
||||
"B" = 11;
|
||||
"C" = 12;
|
||||
"D" = 13;
|
||||
"E" = 14;
|
||||
"F" = 15;
|
||||
}."${v}";
|
||||
|
||||
in
|
||||
rec {
|
||||
|
||||
# Convert an hexadecimal string to an integer
|
||||
toDec = s:
|
||||
let
|
||||
characters = stringToCharacters s;
|
||||
values = map _parseDigit characters;
|
||||
in
|
||||
foldl (acc: n: acc * 16 + n) 0 values;
|
||||
|
||||
# Convert an integer to a decimal string
|
||||
fromDec = toHexString;
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue