mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2025-12-20 03:30:20 +01:00
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:
parent
3e5c6eb73f
commit
c0fe9f1839
2 changed files with 83 additions and 91 deletions
|
|
@ -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`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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})
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue