plugins/hardtime: migrate to mkNeovimPlugin

Co-authored-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
refaelsh 2024-09-08 00:01:06 +03:00 committed by Matt Sturgeon
parent 810eacf516
commit 2de406d972
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
2 changed files with 658 additions and 662 deletions

View file

@ -1,55 +1,65 @@
{
lib,
helpers,
config,
pkgs,
...
}:
with lib;
let
cfg = config.plugins.hardtime;
inherit (lib.nixvim) defaultNullOpts;
inherit (lib) types;
in
{
options = {
plugins.hardtime = helpers.neovim-plugin.extraOptionsOptions // {
enable = mkEnableOption "hardtime";
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "hardtime";
originalName = "hardtime.nvim";
package = "hardtime-nvim";
package = lib.mkPackageOption pkgs "hardtime" {
default = [
"vimPlugins"
"hardtime-nvim"
maintainers = [ lib.maintainers.refaelsh ];
# TODO: Added 2024-09-07; remove after 24.11
deprecateExtraOptions = true;
optionsRenamedToSettings = [
"hint"
"notification"
"hints"
"maxTime"
"maxCount"
"disableMouse"
"allowDifferentKey"
"resettingKeys"
"restrictedKeys"
"restrictionMode"
"disabledKeys"
"disabledFiletypes"
];
};
maxTime = helpers.defaultNullOpts.mkUnsignedInt 1000 ''
settingsOptions = {
max_time = defaultNullOpts.mkUnsignedInt 1000 ''
Maximum time (in milliseconds) to consider key presses as repeated.
'';
maxCount = helpers.defaultNullOpts.mkUnsignedInt 2 ''
max_count = defaultNullOpts.mkUnsignedInt 2 ''
Maximum count of repeated key presses allowed within the `max_time` period.
'';
disableMouse = helpers.defaultNullOpts.mkBool true ''
disable_mouse = defaultNullOpts.mkBool true ''
Disable mouse support.
'';
hint = helpers.defaultNullOpts.mkBool true ''
hint = defaultNullOpts.mkBool true ''
Enable hint messages for better commands.
'';
notification = helpers.defaultNullOpts.mkBool true ''
notification = defaultNullOpts.mkBool true ''
Enable notification messages for restricted and disabled keys.
'';
allowDifferentKey = helpers.defaultNullOpts.mkBool false ''
allow_different_key = defaultNullOpts.mkBool false ''
Allow different keys to reset the count.
'';
enabled = helpers.defaultNullOpts.mkBool true ''
enabled = defaultNullOpts.mkBool true ''
Whether the plugin in enabled by default or not.
'';
resettingKeys = helpers.defaultNullOpts.mkAttrsOf (with types; listOf str) {
resetting_keys = defaultNullOpts.mkAttrsOf (with types; listOf str) {
"1" = [
"n"
"x"
@ -97,7 +107,7 @@ in
"P" = [ "n" ];
} "Keys in what modes that reset the count.";
restrictedKeys = helpers.defaultNullOpts.mkAttrsOf (with types; listOf str) {
restricted_keys = defaultNullOpts.mkAttrsOf (with types; listOf str) {
"h" = [
"n"
"x"
@ -148,8 +158,8 @@ in
];
} "Keys in what modes triggering the count mechanism.";
restrictionMode =
helpers.defaultNullOpts.mkEnumFirstDefault
restriction_mode =
defaultNullOpts.mkEnumFirstDefault
[
"block"
"hint"
@ -158,7 +168,7 @@ in
The behavior when `restricted_keys` trigger count mechanism.
'';
disabledKeys = helpers.defaultNullOpts.mkAttrsOf (with types; listOf str) {
disabled_keys = defaultNullOpts.mkAttrsOf (with types; listOf str) {
"<Up>" = [
""
"i"
@ -177,7 +187,7 @@ in
];
} "Keys in what modes are disabled.";
disabledFiletypes = helpers.defaultNullOpts.mkListOf types.str [
disabled_filetypes = defaultNullOpts.mkListOf types.str [
"qf"
"netrw"
"NvimTree"
@ -186,14 +196,14 @@ in
] "`hardtime.nvim` is disabled under these filetypes.";
hints =
helpers.mkNullOrOption
lib.nixvim.mkNullOrOption
(
with types;
attrsOf (submodule {
options = {
message = lib.mkOption {
description = "Hint message to be displayed.";
type = helpers.nixvimTypes.rawLua;
type = types.rawLua;
};
length = lib.mkOption {
@ -208,37 +218,11 @@ in
of hint massage and pattern length.
'';
};
settingsExample = {
max_time = 1500;
settings = {
showmode = false;
};
config =
let
setupOptions =
with cfg;
{
inherit
hint
notification
enabled
hints
;
max_time = maxTime;
max_count = maxCount;
disable_mouse = disableMouse;
allow_different_key = allowDifferentKey;
resetting_keys = resettingKeys;
restricted_keys = restrictedKeys;
restriction_mode = restrictionMode;
disabled_keys = disabledKeys;
disabled_filetypes = disabledFiletypes;
}
// extraOptions;
in
mkIf cfg.enable {
extraPlugins = [ cfg.package ];
extraConfigLua = ''
require("hardtime").setup(${helpers.toLuaObject setupOptions})
'';
};
}

View file

@ -7,16 +7,17 @@
plugins.hardtime = {
enable = true;
maxTime = 1000;
maxCount = 2;
disableMouse = true;
settings = {
max_time = 1000;
max_count = 2;
disable_mouse = true;
hint = true;
notification = true;
allowDifferentKey = false;
allow_different_key = false;
enabled = true;
restrictionMode = "block";
restriction_mode = "block";
resettingKeys = {
resetting_keys = {
"1" = [
"n"
"x"
@ -64,7 +65,7 @@
"P" = [ "n" ];
};
restrictedKeys = {
restricted_keys = {
"h" = [
"n"
"x"
@ -115,7 +116,7 @@
];
};
disabledKeys = {
disabled_keys = {
"<Up>" = [
""
"i"
@ -134,7 +135,7 @@
];
};
disabledFiletypes = [
disabled_file_types = [
"qf"
"netrw"
"NvimTree"
@ -474,4 +475,15 @@
};
};
};
};
example = {
plugins.hardtime = {
enable = true;
settings = {
showmode = false;
};
};
};
}