lib: unwrap special keys in shift, ctrl, meta and super mods

This commit is contained in:
Dmitriy Pleshevskiy 2024-05-08 15:22:30 +03:00
parent 721b9cbbec
commit 2d4d2f58de
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2

View file

@ -2,15 +2,16 @@
let
inherit (builtins) listToAttrs;
inherit (lib) nameValuePair;
inherit (lib) nameValuePair removePrefix removeSuffix;
wrap = val: "<${val}>";
unwrap = val: removePrefix "<" (removeSuffix ">" 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-*
shift = key: wrap "S-${unwrap key}"; # shift-key *shift* *<S-*
ctrl = key: wrap "C-${unwrap key}"; # control-key *control* *ctrl* *<C-*
meta = key: wrap "M-${unwrap key}"; # alt-key or meta-key *META* *ALT* *<M-*
super = key: wrap "D-${unwrap key}"; # command-key or "super" key *<D-*
keys = listToAttrs (map (v: nameValuePair v (wrap v)) (
[