utility/ccc: add setupOpts option

Added `ccc.nvim` option `vim.utility.ccc.setupOpts` with the existing
hard-coded options as default values.
This commit is contained in:
Jens Feodor Nielsen 2025-12-17 16:44:44 +01:00
parent 3c73befdc5
commit 3e5c6eb73f
3 changed files with 150 additions and 86 deletions

View file

@ -632,6 +632,5 @@
[ccc.nvim]: https://github.com/uga-rosa/ccc.nvim [ccc.nvim]: https://github.com/uga-rosa/ccc.nvim
- Added [ccc.nvim] options {option}`vim.utility.ccc.inputs` and - Added [ccc.nvim] option {option}`vim.utility.ccc.setupOpts` with the existing
{option}`vim.utility.ccc.outputs` to make input color systems and output color hard-coded options as default values.
formats configurable.

View file

@ -2,10 +2,65 @@
inherit (lib.options) mkOption mkEnableOption; inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) listOf enum; inherit (lib.types) listOf enum;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption luaInline;
inherit (lib.generators) mkLuaInline;
in { in {
options.vim.utility.ccc = { options.vim.utility.ccc = {
enable = mkEnableOption "ccc color picker for neovim"; enable = mkEnableOption "ccc color picker for neovim";
setupOpts = mkPluginSetupOption "ccc.nvim" {
highlighter = mkOption {
type = luaInline;
default = mkLuaInline ''
{
auto_enable = true,
max_byte = 2 * 1024 * 1024, -- 2mb
lsp = true,
filetypes = colorPickerFts,
}
'';
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
},
}
'';
description = ''
List of formats that can be detected by |:CccPick| to be activated.
'';
};
alpha_show = mkOption {
type = enum [
"show"
"hide"
"auto"
];
default = "hide";
description = ''
This option determines whether the alpha slider is displayed when the
UI is opened. "show" and "hide" mean as they are. "auto" makes the
slider appear only when the alpha value can be picked up.
'';
};
recognize = mkOption {
type = luaInline;
default = mkLuaInline ''
{ output = true }
'';
description = "Settings for recognizing the color format.";
};
inputs = mkOption { inputs = mkOption {
type = listOf (enum [ type = listOf (enum [
"rgb" "rgb"
@ -62,6 +117,38 @@ 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 },
}
'';
description = ''
Specify the correspondence between picker and output.
'';
};
mappings = mkOption {
type = luaInline;
default = mkLuaInline ''
{
["q"] = ccc.mapping.quit,
["L"] = ccc.mapping.increase10,
["H"] = 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.
'';
};
};
mappings = { mappings = {
quit = mkMappingOption "Cancel and close the UI without replace or insert" "<Esc>"; quit = mkMappingOption "Cancel and close the UI without replace or insert" "<Esc>";
increase10 = mkMappingOption "Increase the value times delta of the slider" "<L>"; increase10 = mkMappingOption "Increase the value times delta of the slider" "<L>";

View file

@ -3,47 +3,25 @@
lib, lib,
... ...
}: let }: let
inherit (lib.strings) concatStringsSep;
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.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 { ccc.setup(${toLuaObject (mapSetupOptions cfg.setupOpts)})
highlighter = {
auto_enable = true,
max_byte = 2 * 1024 * 1024, -- 2mb
lsp = true,
filetypes = colorPickerFts,
},
pickers = {
ccc.picker.hex,
ccc.picker.css_rgb,
ccc.picker.css_hsl,
ccc.picker.ansi_escape {
meaning1 = "bright", -- whether the 1 means bright or yellow
},
},
alpha_show = "hide", -- needed when highlighter.lsp is set to true
recognize = { output = true }, -- automatically recognize color format under cursor
inputs = {${concatStringsSep "," (map (input: "ccc.input.${input}") cfg.inputs)}},
outputs = {${concatStringsSep "," (map (output: "ccc.output.${output}") cfg.outputs)}},
convert = {
{ ccc.picker.hex, ccc.output.css_hsl },
{ ccc.picker.css_rgb, ccc.output.css_hsl },
{ ccc.picker.css_hsl, ccc.output.hex },
},
mappings = {
["q"] = ccc.mapping.quit,
["L"] = ccc.mapping.increase10,
["H"] = ccc.mapping.decrease10,
},
}
''; '';
}; };
} }