From 471677d403452de37386c289d18134b00c47ee60 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 4 Jun 2023 10:24:06 +0300 Subject: [PATCH] feat: color previews via nvim-colorizer-lua --- extra.nix | 2 +- flake.lock | 17 ++++++++ flake.nix | 5 +++ lib/types/plugins.nix | 4 +- modules/ui/colorizer/colorizer.nix | 67 ++++++++++++++++++++++++++++++ modules/ui/colorizer/config.nix | 32 ++++++++++++++ modules/ui/colorizer/default.nix | 6 +++ modules/ui/default.nix | 1 + 8 files changed, 130 insertions(+), 4 deletions(-) create mode 100644 modules/ui/colorizer/colorizer.nix create mode 100644 modules/ui/colorizer/config.nix create mode 100644 modules/ui/colorizer/default.nix diff --git a/extra.nix b/extra.nix index ed9bd80..a91ff9b 100644 --- a/extra.nix +++ b/extra.nix @@ -179,11 +179,11 @@ inputs: let vim.ui = { noice.enable = true; smartcolumn.enable = true; + colorizer.enable = true; }; vim.assistant = { 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 = { diff --git a/flake.lock b/flake.lock index 6ab3a98..08d8c5b 100644 --- a/flake.lock +++ b/flake.lock @@ -964,6 +964,22 @@ "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": { "flake": false, "locked": { @@ -1325,6 +1341,7 @@ "nvim-bufferline-lua": "nvim-bufferline-lua", "nvim-cmp": "nvim-cmp", "nvim-code-action-menu": "nvim-code-action-menu", + "nvim-colorizer-lua": "nvim-colorizer-lua", "nvim-compe": "nvim-compe", "nvim-cursorline": "nvim-cursorline", "nvim-lightbulb": "nvim-lightbulb", diff --git a/flake.nix b/flake.nix index a61adba..5498d61 100644 --- a/flake.nix +++ b/flake.nix @@ -451,6 +451,11 @@ flake = false; }; + nvim-colorizer-lua = { + url = "github:norcalli/nvim-colorizer.lua"; + flake = false; + }; + # Assistant copilot-lua = { url = "github:zbirenbaum/copilot.lua"; diff --git a/lib/types/plugins.nix b/lib/types/plugins.nix index d5a0524..c8fc593 100644 --- a/lib/types/plugins.nix +++ b/lib/types/plugins.nix @@ -81,9 +81,7 @@ with lib; let "project-nvim" "elixir-ls" "elixir-tools" - "vim-svelte" - "vim-javascript" - "vim-html" + "nvim-colorizer-lua" ]; # You can either use the name of the plugin or a package. pluginsType = with types; diff --git a/modules/ui/colorizer/colorizer.nix b/modules/ui/colorizer/colorizer.nix new file mode 100644 index 0000000..48ec2bd --- /dev/null +++ b/modules/ui/colorizer/colorizer.nix @@ -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"; + }; + }; + }; +} diff --git a/modules/ui/colorizer/config.nix b/modules/ui/colorizer/config.nix new file mode 100644 index 0000000..2b2d743 --- /dev/null +++ b/modules/ui/colorizer/config.nix @@ -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}'; + } + }) + ''; + }; +} diff --git a/modules/ui/colorizer/default.nix b/modules/ui/colorizer/default.nix new file mode 100644 index 0000000..3b5b491 --- /dev/null +++ b/modules/ui/colorizer/default.nix @@ -0,0 +1,6 @@ +_: { + imports = [ + ./colorizer.nix + ./config.nix + ]; +} diff --git a/modules/ui/default.nix b/modules/ui/default.nix index 58ab015..286b3ce 100644 --- a/modules/ui/default.nix +++ b/modules/ui/default.nix @@ -4,5 +4,6 @@ _: { ./modes ./notifications ./smartcolumn + ./colorizer ]; }