lib: add modificators to the lib

This commit is contained in:
Dmitriy Pleshevskiy 2024-05-08 01:06:31 +03:00
parent f823ebd2ba
commit 9e3e4b8345
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
2 changed files with 79 additions and 1 deletions

View file

@ -2,9 +2,10 @@
let let
types = import ./types.nix { inherit lib nix2lua; }; types = import ./types.nix { inherit lib nix2lua; };
mod = import ./mod.nix { inherit lib; };
in in
lib // { lib // {
inherit nix2lua; inherit nix2lua mod;
types = lib.types // types; types = lib.types // types;
} }

77
lib/mod.nix Normal file
View file

@ -0,0 +1,77 @@
{ lib }:
let
inherit (builtins) listToAttrs;
inherit (lib) nameValuePair toLower;
wrap = val: "<${val}>";
char = num: wrap "Char-${num}"; # map a character by its decimal, octal or hexadecimal number
shift = key: wrap "S-${key}"; # shift-key *shift* *<S-*
ctrl = key: wrap "C-${key}"; # control-key *control* *ctrl* *<C-*
meta = key: wrap "M-${key}"; # alt-key or meta-key *META* *ALT* *<M-*
super = key: wrap "D-${key}"; # command-key or "super" key *<D-*
keys = listToAttrs (map (v: nameValuePair v (wrap (toLower v))) (
[
"leader"
"localLeader"
"cmd"
"plug"
"mouseMove"
"nul"
"bs"
"tab"
"nl"
"cr"
"esc"
"space"
"lt"
"bslash"
"bar"
"del"
"csi"
"eol"
"ignore"
"nop"
"up"
"down"
"left"
"right"
"help"
"undo"
"insert"
"home"
"end"
"pageUp"
"pageDown"
"kUp"
"kDown"
"kLeft"
"kRight"
"kHome"
"kEnd"
"kOrigin"
"kPageUp"
"kPageDown"
"kDel"
"kPlus"
"kMinus"
"kMultiply"
"kDivide"
"kPoint"
"kComma"
"kEqual"
"kEnter"
]
++ map (n: "F${toString n}") (lib.range 1 12)
++ map (n: "k${toString n}") (lib.range 0 9)
)
);
in
{ inherit char shift ctrl meta super; } // keys // {
return = keys.cr;
enter = keys.cr;
backslash = keys.bslash;
}