From 32eb9c3de6e3a3c2b39fffc6eb960ae8a68a03ff Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:56:48 +0200 Subject: [PATCH] lib: extract shared borderType --- lib/types/default.nix | 2 +- lib/types/plugins.nix | 4 ++++ modules/plugins/ui/borders/borders.nix | 14 ++++++++------ modules/plugins/ui/breadcrumbs/breadcrumbs.nix | 14 +++++--------- modules/plugins/visuals/fidget/fidget.nix | 6 +++--- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/types/default.nix b/lib/types/default.nix index 928bbae..6751229 100644 --- a/lib/types/default.nix +++ b/lib/types/default.nix @@ -9,7 +9,7 @@ typesCustom = import ./custom.nix {inherit lib;}; in { inherit (typesDag) dagOf; - inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType; + inherit (typesPlugin) pluginsOpt extraPluginType mkPluginSetupOption luaInline pluginType borderType; inherit (typesLanguage) diagnostics mkGrammarOption; inherit (typesCustom) anythingConcatLists char; } diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index c0e89d6..65ba49b 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -51,9 +51,13 @@ }; }; }; + + borderPresets = ["none" "single" "double" "rounded" "solid" "shadow"]; in { inherit extraPluginType fromInputs pluginType; + borderType = either (enum borderPresets) (listOf str); + pluginsOpt = { description, example, diff --git a/modules/plugins/ui/borders/borders.nix b/modules/plugins/ui/borders/borders.nix index 4abb130..8a295fc 100644 --- a/modules/plugins/ui/borders/borders.nix +++ b/modules/plugins/ui/borders/borders.nix @@ -4,22 +4,24 @@ ... }: let inherit (lib.options) mkOption mkEnableOption; - inherit (lib.lists) optionals; - inherit (lib.types) enum either listOf str; + inherit (lib.nvim.types) borderType; cfg = config.vim.ui.borders; - - defaultStyles = ["none" "single" "double" "rounded"]; in { options.vim.ui.borders = { enable = mkEnableOption "visible borders for most windows"; globalStyle = mkOption { - type = either (enum defaultStyles) (listOf str); + type = borderType; default = "rounded"; description = '' The global border style to use. + + If a list is given, it should have a length of eight or any divisor of + eight. The array will specify the eight chars building up the border in + a clockwise fashion starting with the top-left corner. ''; + example = ["╔" "═" "╗" "║" "╝" "═" "╚" "║"]; }; # TODO: make per-plugin borders configurable @@ -28,7 +30,7 @@ in { enable = mkEnableOption "borders for the ${name} plugin" // {default = cfg.enable;}; style = mkOption { - type = either (enum (defaultStyles ++ optionals (name != "which-key") ["shadow"])) (listOf str); + type = borderType; default = cfg.globalStyle; description = "The border style to use for the ${name} plugin"; }; diff --git a/modules/plugins/ui/breadcrumbs/breadcrumbs.nix b/modules/plugins/ui/breadcrumbs/breadcrumbs.nix index 8f246b3..e173688 100644 --- a/modules/plugins/ui/breadcrumbs/breadcrumbs.nix +++ b/modules/plugins/ui/breadcrumbs/breadcrumbs.nix @@ -6,7 +6,7 @@ inherit (lib.options) mkOption mkEnableOption; inherit (lib.types) nullOr listOf enum bool str int either; inherit (lib.modules) mkRenamedOptionModule; - inherit (lib.nvim.types) mkPluginSetupOption; + inherit (lib.nvim.types) mkPluginSetupOption borderType; mkSimpleIconOption = default: mkOption { inherit default; @@ -212,8 +212,7 @@ in { # position = {} border = mkOption { - # TODO: let this type accept a custom string - type = either (enum ["single" "rounded" "double" "solid" "none"]) (listOf str); + type = borderType; default = config.vim.ui.borders.globalStyle; description = "border style to use"; }; @@ -236,8 +235,7 @@ in { */ border = mkOption { - # TODO: let this type accept a custom string - type = nullOr (either (enum ["single" "rounded" "double" "solid" "none"]) (listOf str)); + type = borderType; default = config.vim.ui.borders.globalStyle; description = "border style to use for the left section of Navbuddy UI"; }; @@ -254,8 +252,7 @@ in { */ border = mkOption { - # TODO: let this type accept a custom string - type = nullOr (either (enum ["single" "rounded" "double" "solid" "none"]) (listOf str)); + type = borderType; default = config.vim.ui.borders.globalStyle; description = "border style to use for the middle section of Navbuddy UI"; }; @@ -265,8 +262,7 @@ in { # there is no size option for the right section, it fills the remaining space right = { border = mkOption { - # TODO: let this type accept a custom string - type = nullOr (either (enum ["single" "rounded" "double" "solid" "none"]) (listOf str)); + type = borderType; default = config.vim.ui.borders.globalStyle; description = "border style to use for the right section of Navbuddy UI"; }; diff --git a/modules/plugins/visuals/fidget/fidget.nix b/modules/plugins/visuals/fidget/fidget.nix index b77f42c..79974bd 100644 --- a/modules/plugins/visuals/fidget/fidget.nix +++ b/modules/plugins/visuals/fidget/fidget.nix @@ -6,8 +6,8 @@ inherit (lib.modules) mkRemovedOptionModule mkRenamedOptionModule; inherit (lib.options) mkEnableOption mkOption literalExpression; inherit (lib.strings) toUpper; - inherit (lib.types) int float bool str enum listOf attrsOf oneOf nullOr submodule either; - inherit (lib.nvim.types) mkPluginSetupOption luaInline; + inherit (lib.types) int float bool str enum listOf attrsOf oneOf nullOr submodule; + inherit (lib.nvim.types) mkPluginSetupOption luaInline borderType; inherit (lib.generators) mkLuaInline; in { imports = [ @@ -453,7 +453,7 @@ in { }; border = mkOption { description = "Border style of the notification window"; - type = either (enum ["none" "single" "double" "rounded" "solid" "shadow"]) (listOf str); + type = borderType; default = if config.vim.ui.borders.enable then config.vim.ui.borders.globalStyle