feat: color previews via nvim-colorizer-lua

This commit is contained in:
NotAShelf 2023-06-04 10:24:06 +03:00
parent 1cc6bb8b8a
commit 471677d403
No known key found for this signature in database
GPG key ID: F0D14CCB5ED5AA22
8 changed files with 130 additions and 4 deletions

View file

@ -179,11 +179,11 @@ inputs: let
vim.ui = { vim.ui = {
noice.enable = true; noice.enable = true;
smartcolumn.enable = true; smartcolumn.enable = true;
colorizer.enable = true;
}; };
vim.assistant = { vim.assistant = {
copilot.enable = isMaximal; copilot.enable = isMaximal;
#tabnine.enable = false; # FIXME: this is not working because the plugin depends on an internal script to be ran by the package manager
}; };
vim.session = { vim.session = {

View file

@ -964,6 +964,22 @@
"type": "github" "type": "github"
} }
}, },
"nvim-colorizer-lua": {
"flake": false,
"locked": {
"lastModified": 1591879145,
"narHash": "sha256-6YrnItxExL2C8pNIdLd+hXCjsB2MbZANwWkah6dreD8=",
"owner": "norcalli",
"repo": "nvim-colorizer.lua",
"rev": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6",
"type": "github"
},
"original": {
"owner": "norcalli",
"repo": "nvim-colorizer.lua",
"type": "github"
}
},
"nvim-compe": { "nvim-compe": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -1325,6 +1341,7 @@
"nvim-bufferline-lua": "nvim-bufferline-lua", "nvim-bufferline-lua": "nvim-bufferline-lua",
"nvim-cmp": "nvim-cmp", "nvim-cmp": "nvim-cmp",
"nvim-code-action-menu": "nvim-code-action-menu", "nvim-code-action-menu": "nvim-code-action-menu",
"nvim-colorizer-lua": "nvim-colorizer-lua",
"nvim-compe": "nvim-compe", "nvim-compe": "nvim-compe",
"nvim-cursorline": "nvim-cursorline", "nvim-cursorline": "nvim-cursorline",
"nvim-lightbulb": "nvim-lightbulb", "nvim-lightbulb": "nvim-lightbulb",

View file

@ -451,6 +451,11 @@
flake = false; flake = false;
}; };
nvim-colorizer-lua = {
url = "github:norcalli/nvim-colorizer.lua";
flake = false;
};
# Assistant # Assistant
copilot-lua = { copilot-lua = {
url = "github:zbirenbaum/copilot.lua"; url = "github:zbirenbaum/copilot.lua";

View file

@ -81,9 +81,7 @@ with lib; let
"project-nvim" "project-nvim"
"elixir-ls" "elixir-ls"
"elixir-tools" "elixir-tools"
"vim-svelte" "nvim-colorizer-lua"
"vim-javascript"
"vim-html"
]; ];
# You can either use the name of the plugin or a package. # You can either use the name of the plugin or a package.
pluginsType = with types; pluginsType = with types;

View file

@ -0,0 +1,67 @@
{
config,
lib,
...
}:
with lib;
with builtins; {
options.vim.ui.colorizer = {
enable = mkEnableOption "Enable nvim-colorizer.lua for color highlighting";
options = {
rgb = mkOption {
type = types.bool;
default = true;
description = "#RGB hex codes";
};
rrggbb = mkOption {
type = types.bool;
default = true;
description = "#RRGGBB hex codes";
};
names = mkOption {
type = types.bool;
default = true;
description = ''"Name" codes such as "Blue"'';
};
rgb_fn = mkOption {
type = types.bool;
default = false;
description = "CSS rgb() and rgba() functions";
};
rrggbbaa = mkOption {
type = types.bool;
default = false;
description = "#RRGGBBAA hex codes";
};
hsl_fn = mkOption {
type = types.bool;
default = false;
description = "CSS hsl() and hsla() functions";
};
css = mkOption {
type = types.bool;
default = true;
description = "Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB";
};
css_fn = mkOption {
type = types.bool;
default = false;
description = "Enable all CSS *functions*: rgb_fn, hsl_fn";
};
mode = mkOption {
type = types.enum ["foreground" "background"];
default = "background";
description = "Set the display mode";
};
};
};
}

View file

@ -0,0 +1,32 @@
{
pkgs,
config,
lib,
...
}:
with lib;
with builtins; let
cfg = config.vim.ui.colorizer;
in {
config = mkIf cfg.enable {
vim.startPlugins = [
"nvim-colorizer-lua"
];
vim.luaConfigRC.colorizer = nvim.dag.entryAnywhere ''
require('colorizer').setup({
DEFAULT_OPTIONS = {
RGB = ${boolToString cfg.options.rgb};
RRGGBB = ${boolToString cfg.options.rrggbb};
names = ${boolToString cfg.options.names};
RRGGBBAA = ${boolToString cfg.options.rrggbbaa};
rgb_fn = ${boolToString cfg.options.rgb_fn};
hsl_fn = ${boolToString cfg.options.hsl_fn};
css = ${boolToString cfg.options.css};
css_fn = ${boolToString cfg.options.css_fn};
mode = '${toString cfg.options.mode}';
}
})
'';
};
}

View file

@ -0,0 +1,6 @@
_: {
imports = [
./colorizer.nix
./config.nix
];
}

View file

@ -4,5 +4,6 @@ _: {
./modes ./modes
./notifications ./notifications
./smartcolumn ./smartcolumn
./colorizer
]; ];
} }