2024-02-26 04:28:07 +00:00
|
|
|
{lib}: let
|
|
|
|
inherit (lib.options) mkOption;
|
2024-03-12 00:48:53 +00:00
|
|
|
inherit (lib.modules) mkIf mkDefault;
|
2024-02-26 04:28:07 +00:00
|
|
|
inherit (lib.types) nullOr str;
|
|
|
|
inherit (lib.attrsets) isAttrs mapAttrs;
|
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
binds = rec {
|
|
|
|
mkLuaBinding = key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
"${key}" = {
|
|
|
|
inherit action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkExprBinding = key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
"${key}" = {
|
|
|
|
inherit action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
|
|
|
expr = true;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkBinding = key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
"${key}" = {
|
|
|
|
inherit action desc;
|
|
|
|
silent = true;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkMappingOption = description: default:
|
|
|
|
mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
inherit default description;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
# Utility function that takes two attrsets:
|
|
|
|
# { someKey = "some_value" } and
|
|
|
|
# { someKey = { description = "Some Description"; }; }
|
|
|
|
# and merges them into
|
|
|
|
# { someKey = { value = "some_value"; description = "Some Description"; }; }
|
|
|
|
addDescriptionsToMappings = actualMappings: mappingDefinitions:
|
|
|
|
mapAttrs (name: value: let
|
|
|
|
isNested = isAttrs value;
|
|
|
|
returnedValue =
|
|
|
|
if isNested
|
|
|
|
then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}"
|
|
|
|
else {
|
|
|
|
inherit value;
|
|
|
|
inherit (mappingDefinitions."${name}") description;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
returnedValue)
|
|
|
|
actualMappings;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkSetBinding = binding: action:
|
|
|
|
mkBinding binding.value action binding.description;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkSetExprBinding = binding: action:
|
|
|
|
mkExprBinding binding.value action binding.description;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
mkSetLuaBinding = binding: action:
|
|
|
|
mkLuaBinding binding.value action binding.description;
|
2024-03-12 00:48:53 +00:00
|
|
|
|
2024-08-12 22:27:05 +00:00
|
|
|
pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
|
2024-11-04 15:50:50 +00:00
|
|
|
|
2024-11-17 18:31:28 +00:00
|
|
|
mkKeymap = mode: key: action: opt: opt // {inherit mode key action;};
|
2024-08-12 22:27:05 +00:00
|
|
|
};
|
|
|
|
in
|
|
|
|
binds
|