From 1fe11e25294101cd00ec50b334792ee28c7dec79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=A9tan=20Lepage?= <33058747+GaetanLepage@users.noreply.github.com> Date: Mon, 23 Jan 2023 15:31:53 +0100 Subject: [PATCH] plugins: Add nvim-colorizer (#140) --- plugins/default.nix | 1 + plugins/utils/nvim-colorizer.nix | 161 +++++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 plugins/utils/nvim-colorizer.nix diff --git a/plugins/default.nix b/plugins/default.nix index 9cb055b1e8..a76b39fb09 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -58,6 +58,7 @@ ./utils/mark-radar.nix ./utils/notify.nix ./utils/nvim-autopairs.nix + ./utils/nvim-colorizer.nix ./utils/nvim-tree.nix ./utils/project-nvim.nix ./utils/specs.nix diff --git a/plugins/utils/nvim-colorizer.nix b/plugins/utils/nvim-colorizer.nix new file mode 100644 index 0000000000..8c4eaf3023 --- /dev/null +++ b/plugins/utils/nvim-colorizer.nix @@ -0,0 +1,161 @@ +{ pkgs, config, lib, ... }: +with lib; +let + + cfg = config.plugins.nvim-colorizer; + helpers = import ../helpers.nix { inherit lib; }; + + colorizer-options = { + RGB = mkOption { + description = "#RGB hex codes"; + type = types.nullOr types.bool; + default = null; + }; + RRGGBB = mkOption { + description = "#RRGGBB hex codes"; + type = types.nullOr types.bool; + default = null; + }; + names = mkOption { + description = "\"Name\" codes like Blue or blue"; + type = types.nullOr types.bool; + default = null; + }; + RRGGBBAA = mkOption { + description = "#RRGGBBAA hex codes"; + type = types.nullOr types.bool; + default = null; + }; + AARRGGBB = mkOption { + description = "0xAARRGGBB hex codes"; + type = types.nullOr types.bool; + default = null; + }; + rgb_fn = mkOption { + description = "CSS rgb() and rgba() functions"; + type = types.nullOr types.bool; + default = null; + }; + hsl_fn = mkOption { + description = "CSS hsl() and hsla() functions"; + type = types.nullOr types.bool; + default = null; + }; + css = mkOption { + description = "Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB"; + type = types.nullOr types.bool; + default = null; + }; + css_fn = mkOption { + description = "Enable all CSS *functions*: rgb_fn, hsl_fn"; + type = types.nullOr types.bool; + default = null; + }; + mode = mkOption { + description = "Set the display mode"; + type = types.nullOr (types.enum [ "foreground" "background" "virtualtext" ]); + default = null; + }; + tailwind = mkOption { + description = "Enable tailwind colors"; + type = types.nullOr ( + types.oneOf [ + types.bool + (types.enum [ "normal" "lsp" "both" ]) + ] + ); + default = null; + }; + sass = { + enable = mkOption { + description = "Enable sass colors"; + type = types.nullOr types.bool; + default = null; + }; + parsers = mkOption { + description = "sass parsers settings"; + type = types.nullOr types.attrs; + default = null; + }; + }; + virtualtext = mkOption { + description = "Set the virtualtext character (only used when mode is set to 'virtualtext')"; + type = types.nullOr types.str; + default = null; + }; + }; + +in +{ + options = { + plugins.nvim-colorizer = { + + enable = mkEnableOption "nvim-colorizer"; + + package = mkOption { + type = types.package; + default = pkgs.vimPlugins.nvim-colorizer-lua; + description = "Plugin to use for vim-commentary"; + }; + + fileTypes = mkOption { + description = "Enable and/or configure highlighting for certain filetypes"; + type = types.nullOr ( + types.listOf (types.oneOf [ + types.str + (types.submodule { + options = { + language = mkOption { + type = types.str; + }; + } // colorizer-options; + }) + ]) + ); + default = null; + }; + + userDefaultOptions = mkOption { + description = "Default options"; + type = types.nullOr (types.submodule { + options = colorizer-options; + }); + default = null; + }; + + bufTypes = mkOption { + description = "Buftype value is fetched by vim.bo.buftype"; + type = types.nullOr (types.listOf types.str); + default = null; + }; + }; + }; + + config = mkIf cfg.enable { + extraPlugins = [ cfg.package ]; + + extraConfigLua = let + + filetypes = if (cfg.fileTypes != null) + then ( + let + list = map ( + v: if builtins.isAttrs v + then v.language + " = " + helpers.toLuaObject (builtins.removeAttrs v [ "language" ]) + else "'${v}'" + ) cfg.fileTypes; + in "{" + (concatStringsSep "," list) + "}" + ) + else + "nil" + ; + + in '' + require("colorizer").setup({ + filetypes = ${filetypes}, + user_default_options = ${helpers.toLuaObject cfg.userDefaultOptions}, + buftypes = ${helpers.toLuaObject cfg.bufTypes}, + }) + ''; + }; +}