lib/binds: improve code, adjust functions to new api

This commit is contained in:
diniamo 2024-08-10 15:06:06 +02:00
parent 75cb9bced7
commit 6cb57e1d26

View file

@ -4,30 +4,29 @@
inherit (lib.types) nullOr str;
inherit (lib.attrsets) isAttrs mapAttrs;
binds = rec {
mkLuaBinding = key: action: desc:
mkLuaBinding = mode: key: action: desc:
mkIf (key != null) {
"${key}" = {
inherit action desc;
${key} = {
inherit mode action desc;
lua = true;
silent = true;
};
};
mkExprBinding = key: action: desc:
mkExprBinding = mode: key: action: desc:
mkIf (key != null) {
"${key}" = {
inherit action desc;
${key} = {
inherit mode action desc;
lua = true;
silent = true;
expr = true;
};
};
mkBinding = key: action: desc:
mkBinding = mode: key: action: desc:
mkIf (key != null) {
"${key}" = {
inherit action desc;
${key} = {
inherit mode action desc;
silent = true;
};
};
@ -48,25 +47,25 @@
isNested = isAttrs value;
returnedValue =
if isNested
then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}"
then addDescriptionsToMappings actualMappings.${name} mappingDefinitions.${name}
else {
inherit value;
inherit (mappingDefinitions."${name}") description;
inherit (mappingDefinitions.${name}) description;
};
in
returnedValue)
actualMappings;
mkSetBinding = binding: action:
mkBinding binding.value action binding.description;
mkSetBinding = mode: binding: action:
mkBinding mode binding.value action binding.description;
mkSetExprBinding = binding: action:
mkExprBinding binding.value action binding.description;
mkSetExprBinding = mode: binding: action:
mkExprBinding mode binding.value action binding.description;
mkSetLuaBinding = binding: action:
mkLuaBinding binding.value action binding.description;
mkSetLuaBinding = mode: binding: action:
mkLuaBinding mode binding.value action binding.description;
pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
};
in
binds
in {
inherit mkLuaBinding mkExprBinding mkBinding mkMappingOption addDescriptionsToMappings mkSetBinding mkSetExprBinding mkSetLuaBinding pushDownDefault;
}