utility/ccc: no hidden mapping, better types

- Remove hidden mapping input/output options into luaInline with
   prefixes.
 - Update types of setupOpts sub-options to avoid large blocks of
   inline Lua in the configuration.
This commit is contained in:
Jens Feodor Nielsen 2025-12-18 15:28:56 +01:00
parent 3e5c6eb73f
commit c0fe9f1839
2 changed files with 83 additions and 91 deletions

View file

@ -1,6 +1,12 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkOption mkEnableOption; 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.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption luaInline; inherit (lib.nvim.types) mkPluginSetupOption luaInline;
inherit (lib.generators) mkLuaInline; inherit (lib.generators) mkLuaInline;
@ -10,32 +16,32 @@ in {
setupOpts = mkPluginSetupOption "ccc.nvim" { setupOpts = mkPluginSetupOption "ccc.nvim" {
highlighter = mkOption { highlighter = mkOption {
type = luaInline; type = attrsOf anything;
default = mkLuaInline '' default = {
{ auto_enable = true;
auto_enable = true, max_byte = 2 * 1024 * 1024; # 2mb
max_byte = 2 * 1024 * 1024, -- 2mb lsp = true;
lsp = true, filetypes = mkLuaInline "colorPickerFts";
filetypes = colorPickerFts, };
} description = ''
Settings for the highlighter. See {command}`:help ccc` for options.
''; '';
description = "Settings for the highlighter";
}; };
pickers = mkOption { pickers = mkOption {
type = luaInline; type = listOf luaInline;
default = mkLuaInline '' default = map mkLuaInline [
{ "ccc.picker.hex"
ccc.picker.hex, "ccc.picker.css_rgb"
ccc.picker.css_rgb, "ccc.picker.css_hsl"
ccc.picker.css_hsl, "ccc.picker.ansi_escape { meaning1 = \"bold\", }"
ccc.picker.ansi_escape { ];
meaning1 = "bright", -- whether the 1 means bright or yellow
},
}
'';
description = '' 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 { recognize = mkOption {
type = luaInline; type = attrsOf anything;
default = mkLuaInline '' default = {
{ output = true } output = true;
};
description = ''
Settings for recognizing the color format. See {command}`:help ccc` for options.
''; '';
description = "Settings for recognizing the color format.";
}; };
inputs = mkOption { inputs = mkOption {
type = listOf (enum [ type = listOf luaInline;
"rgb" default = map mkLuaInline ["ccc.input.hsl"];
"hsl"
"hwb"
"lab"
"lch"
"oklab"
"oklch"
"cmyk"
"hsluv"
"okhsl"
"hsv"
"okhsv"
"xyz"
]);
default = [
"hsl"
];
description = '' 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 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 the default used at the first startup. Once activated, it will keep the
@ -90,26 +84,16 @@ in {
}; };
outputs = mkOption { outputs = mkOption {
type = listOf (enum [ type = listOf luaInline;
"hex" default = map mkLuaInline [
"hex_short" "ccc.output.css_hsl"
"css_hsl" "ccc.output.css_rgb"
"css_rgb" "ccc.output.hex"
"css_rgba"
"css_hwb"
"css_lab"
"css_lch"
"css_oklab"
"css_oklch"
"float"
]);
default = [
"css_hsl"
"css_rgb"
"hex"
]; ];
description = '' 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 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 the default used at the first startup. Once activated, it will keep the
@ -118,33 +102,49 @@ in {
}; };
convert = mkOption { convert = mkOption {
type = luaInline; type = listOf (listOf luaInline);
default = mkLuaInline '' default = map (map mkLuaInline) [
{ [
{ ccc.picker.hex, ccc.output.css_hsl }, "ccc.picker.hex"
{ ccc.picker.css_rgb, ccc.output.css_hsl }, "ccc.output.css_hsl"
{ ccc.picker.css_hsl, ccc.output.hex }, ]
} [
''; "ccc.picker.css_rgb"
"ccc.output.css_hsl"
]
[
"ccc.picker.css_hsl"
"ccc.output.hex"
]
];
description = '' 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 { mappings = mkOption {
type = luaInline; type = attrsOf luaInline;
default = mkLuaInline '' default = {
{ "q" = mkLuaInline "ccc.mapping.quit";
["q"] = ccc.mapping.quit, "L" = mkLuaInline "ccc.mapping.increase10";
["L"] = ccc.mapping.increase10, "H" = mkLuaInline "ccc.mapping.decrease10";
["H"] = ccc.mapping.decrease10, };
}
'';
description = '' description = ''
The mappings are set in the UI of ccc. The table where lhs is key and 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 rhs is value. To disable all default mappings, use
disable_default_mappings. To disable only some of the default {option}`vim.utility.ccc.setupOpts.disable_default_mappings`. To
mappings, set ccc.mapping.none. disable only some of the default mappings, set `ccc.mapping.none`.
''; '';
}; };
}; };

View file

@ -6,22 +6,14 @@
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere; inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject; inherit (lib.nvim.lua) toLuaObject;
inherit (lib.generators) mkLuaInline;
cfg = config.vim.utility.ccc; 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 { in {
config = mkIf cfg.enable { config = mkIf cfg.enable {
vim.startPlugins = ["ccc-nvim"]; vim.startPlugins = ["ccc-nvim"];
vim.pluginRC.ccc = entryAnywhere '' vim.pluginRC.ccc = entryAnywhere ''
local ccc = require("ccc") local ccc = require("ccc")
ccc.setup(${toLuaObject (mapSetupOptions cfg.setupOpts)}) ccc.setup(${toLuaObject cfg.setupOpts})
''; '';
}; };
} }