diff --git a/modules/plugins/utility/ccc/ccc.nix b/modules/plugins/utility/ccc/ccc.nix index a8f19587..420801da 100644 --- a/modules/plugins/utility/ccc/ccc.nix +++ b/modules/plugins/utility/ccc/ccc.nix @@ -1,6 +1,12 @@ {lib, ...}: let inherit (lib.options) mkOption mkEnableOption; - inherit (lib.types) listOf enum; + inherit + (lib.types) + anything + attrsOf + listOf + enum + ; inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.generators) mkLuaInline; @@ -10,32 +16,32 @@ in { setupOpts = mkPluginSetupOption "ccc.nvim" { highlighter = mkOption { - type = luaInline; - default = mkLuaInline '' - { - auto_enable = true, - max_byte = 2 * 1024 * 1024, -- 2mb - lsp = true, - filetypes = colorPickerFts, - } + type = attrsOf anything; + default = { + auto_enable = true; + max_byte = 2 * 1024 * 1024; # 2mb + lsp = true; + filetypes = mkLuaInline "colorPickerFts"; + }; + description = '' + Settings for the highlighter. See {command}`:help ccc` for options. ''; - description = "Settings for the highlighter"; }; pickers = mkOption { - type = luaInline; - default = mkLuaInline '' - { - ccc.picker.hex, - ccc.picker.css_rgb, - ccc.picker.css_hsl, - ccc.picker.ansi_escape { - meaning1 = "bright", -- whether the 1 means bright or yellow - }, - } - ''; + type = listOf luaInline; + default = map mkLuaInline [ + "ccc.picker.hex" + "ccc.picker.css_rgb" + "ccc.picker.css_hsl" + "ccc.picker.ansi_escape { meaning1 = \"bold\", }" + ]; description = '' - List of formats that can be detected by |:CccPick| to be activated. + List of formats that can be detected by {command}`:CccPick` to be + activated. + + Must be inline lua references to `ccc.picker`, for example + `mkLuaInline "ccc.picker.hex"`. See {command}`:help ccc` for options. ''; }; @@ -54,34 +60,22 @@ in { }; recognize = mkOption { - type = luaInline; - default = mkLuaInline '' - { output = true } + type = attrsOf anything; + default = { + output = true; + }; + description = '' + Settings for recognizing the color format. See {command}`:help ccc` for options. ''; - description = "Settings for recognizing the color format."; }; inputs = mkOption { - type = listOf (enum [ - "rgb" - "hsl" - "hwb" - "lab" - "lch" - "oklab" - "oklch" - "cmyk" - "hsluv" - "okhsl" - "hsv" - "okhsv" - "xyz" - ]); - default = [ - "hsl" - ]; + type = listOf luaInline; + default = map mkLuaInline ["ccc.input.hsl"]; description = '' - List of color systems to be activated. + List of color systems to be activated. Must be inline lua references to + `ccc.input`, for example `mkLuaInline "ccc.input.rgb"`. See + {command}`:help ccc` for options. The toggle input mode action toggles in this order. The first one is the default used at the first startup. Once activated, it will keep the @@ -90,26 +84,16 @@ in { }; outputs = mkOption { - type = listOf (enum [ - "hex" - "hex_short" - "css_hsl" - "css_rgb" - "css_rgba" - "css_hwb" - "css_lab" - "css_lch" - "css_oklab" - "css_oklch" - "float" - ]); - default = [ - "css_hsl" - "css_rgb" - "hex" + type = listOf luaInline; + default = map mkLuaInline [ + "ccc.output.css_hsl" + "ccc.output.css_rgb" + "ccc.output.hex" ]; description = '' - List of output formats to be activated. + List of output formats to be activated. Must be inline Lua references to + `ccc.output`, for example `mkLuaInline "ccc.output.rgb"`. See + {command}`:help ccc` for options. The toggle output mode action toggles in this order. The first one is the default used at the first startup. Once activated, it will keep the @@ -118,33 +102,49 @@ in { }; convert = mkOption { - type = luaInline; - default = mkLuaInline '' - { - { ccc.picker.hex, ccc.output.css_hsl }, - { ccc.picker.css_rgb, ccc.output.css_hsl }, - { ccc.picker.css_hsl, ccc.output.hex }, - } - ''; + type = listOf (listOf luaInline); + default = map (map mkLuaInline) [ + [ + "ccc.picker.hex" + "ccc.output.css_hsl" + ] + [ + "ccc.picker.css_rgb" + "ccc.output.css_hsl" + ] + [ + "ccc.picker.css_hsl" + "ccc.output.hex" + ] + ]; description = '' - Specify the correspondence between picker and output. + Specify the correspondence between picker and output. Must be a list of + two-element lists defining picker/output pairs as inline Lua references, + for example: + + ```nix + map (map mkLuaInline) [ + ["ccc.picker.hex", "ccc.output.css_rgb"] + ["ccc.picker.css_rgb", "ccc.output.hex"] + ]; + ``` + + See {command}`:help ccc` for options. ''; }; mappings = mkOption { - type = luaInline; - default = mkLuaInline '' - { - ["q"] = ccc.mapping.quit, - ["L"] = ccc.mapping.increase10, - ["H"] = ccc.mapping.decrease10, - } - ''; + type = attrsOf luaInline; + default = { + "q" = mkLuaInline "ccc.mapping.quit"; + "L" = mkLuaInline "ccc.mapping.increase10"; + "H" = mkLuaInline "ccc.mapping.decrease10"; + }; description = '' The mappings are set in the UI of ccc. The table where lhs is key and rhs is value. To disable all default mappings, use - disable_default_mappings. To disable only some of the default - mappings, set ccc.mapping.none. + {option}`vim.utility.ccc.setupOpts.disable_default_mappings`. To + disable only some of the default mappings, set `ccc.mapping.none`. ''; }; }; diff --git a/modules/plugins/utility/ccc/config.nix b/modules/plugins/utility/ccc/config.nix index f8472649..e0654ceb 100644 --- a/modules/plugins/utility/ccc/config.nix +++ b/modules/plugins/utility/ccc/config.nix @@ -6,22 +6,14 @@ inherit (lib.modules) mkIf; inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.lua) toLuaObject; - inherit (lib.generators) mkLuaInline; cfg = config.vim.utility.ccc; - mkLuaIdentifier = prefix: identifier: mkLuaInline "${prefix}${identifier}"; - mapSetupOptions = setupOpts: - setupOpts - // { - inputs = map (mkLuaIdentifier "ccc.input.") setupOpts.inputs; - outputs = map (mkLuaIdentifier "ccc.output.") setupOpts.outputs; - }; in { config = mkIf cfg.enable { vim.startPlugins = ["ccc-nvim"]; vim.pluginRC.ccc = entryAnywhere '' local ccc = require("ccc") - ccc.setup(${toLuaObject (mapSetupOptions cfg.setupOpts)}) + ccc.setup(${toLuaObject cfg.setupOpts}) ''; }; }