From e16d2448650f6ae3841198996bb795b0f4e28b79 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sun, 15 Dec 2024 12:33:05 -0600 Subject: [PATCH] plugins/tiny-devicons-auto-colors: init --- .../tiny-devicons-auto-colors/default.nix | 109 ++++++++++++++++++ .../tiny-devicons-auto-colors/default.nix | 63 ++++++++++ 2 files changed, 172 insertions(+) create mode 100644 plugins/by-name/tiny-devicons-auto-colors/default.nix create mode 100644 tests/test-sources/plugins/by-name/tiny-devicons-auto-colors/default.nix diff --git a/plugins/by-name/tiny-devicons-auto-colors/default.nix b/plugins/by-name/tiny-devicons-auto-colors/default.nix new file mode 100644 index 00000000..0e0acc05 --- /dev/null +++ b/plugins/by-name/tiny-devicons-auto-colors/default.nix @@ -0,0 +1,109 @@ +{ config, lib, ... }: +let + inherit (lib.nixvim) defaultNullOpts; +in +lib.nixvim.neovim-plugin.mkNeovimPlugin { + name = "tiny-devicons-auto-colors"; + packPathName = "tiny-devicons-auto-colors.nvim"; + package = "tiny-devicons-auto-colors-nvim"; + + maintainers = [ lib.maintainers.khaneliman ]; + + settingsOptions = { + colors = + defaultNullOpts.mkNullableWithRaw (with lib.types; either (attrsOf anything) (listOf str)) [ ] + '' + A table of color codes that the plugin will use to assign colors to devicons. + If not provided, the plugin will fetch highlights from the current theme to generate a color palette. + ''; + + factors = { + lightness = defaultNullOpts.mkNum 1.75 '' + Adjust the lightness factor. + ''; + chroma = defaultNullOpts.mkNum 1 '' + Adjust the chroma factor. + ''; + hue = defaultNullOpts.mkNum 1.25 '' + Adjust the hue factor. + ''; + }; + + cache = { + enabled = defaultNullOpts.mkBool true '' + Enable or disable caching to improve performance. + ''; + path = defaultNullOpts.mkStr (lib.nixvim.literalLua ''vim.fn.stdpath("cache") .. "/tiny-devicons-auto-colors-cache.json"'') '' + Path to the cache file. + ''; + }; + + precise_search = { + enabled = defaultNullOpts.mkBool true '' + Enable or disable precise search for better color matching. + ''; + iteration = defaultNullOpts.mkNum 10 '' + Number of iterations for precise search. + ''; + precision = defaultNullOpts.mkNum 20 '' + Precision level for the search. + ''; + threshold = defaultNullOpts.mkNum 23 '' + Threshold to consider a color as a match. + ''; + }; + + ignore = defaultNullOpts.mkListOf lib.types.str [ ] '' + A list of icon names to ignore. + ''; + + autoreload = defaultNullOpts.mkBool false '' + Automatically reload colors when the colorscheme changes. + ''; + }; + + settingsExample = { + colors = { + red = "#ff0000"; + green = "#00ff00"; + }; + factors = { + lightness = 1.5; + chroma = 1.2; + hue = 1.1; + }; + cache = { + enabled = true; + path = "/path/to/cache.json"; + }; + precise_search = { + enabled = true; + iteration = 15; + precision = 25; + threshold = 20; + }; + ignore = [ + "lua" + "vim" + ]; + autoreload = true; + }; + + extraConfig = { + assertions = [ + { + assertion = + config.plugins.web-devicons.enable + || ( + config.plugins.mini.enable + && config.plugins.mini.modules ? icons + && config.plugins.mini.mockDevIcons + ); + message = '' + Nixvim: Either `plugins.web-devicons` or `plugins.mini`* must be enabled to use `tiny-devicons-auto-colors`. + *If using `plugins.mini`, you must enable the `icons` module and the `mockDevIcons` option. + ''; + } + ]; + }; +} diff --git a/tests/test-sources/plugins/by-name/tiny-devicons-auto-colors/default.nix b/tests/test-sources/plugins/by-name/tiny-devicons-auto-colors/default.nix new file mode 100644 index 00000000..c45ef32d --- /dev/null +++ b/tests/test-sources/plugins/by-name/tiny-devicons-auto-colors/default.nix @@ -0,0 +1,63 @@ +{ + empty = { + plugins = { + web-devicons.enable = true; + tiny-devicons-auto-colors.enable = true; + }; + }; + + defaults = { + plugins = { + web-devicons.enable = true; + tiny-devicons-auto-colors = { + enable = true; + + settings = { + colors = null; + factors = { + lightness = 1.75; + chroma = 1; + hue = 1.25; + }; + cache = { + enabled = true; + path.__raw = ''vim.fn.stdpath("cache") .. "/tiny-devicons-auto-colors-cache.json"''; + }; + precise_search = { + enabled = true; + iteration = 10; + precision = 20; + threshold = 23; + }; + ignore = [ ]; + autoreload = false; + }; + }; + }; + }; + + catppuccin = { + colorschemes.catppuccin.enable = true; + plugins = { + web-devicons.enable = true; + tiny-devicons-auto-colors = { + enable = true; + + settings = { + colors.__raw = ''require("catppuccin.palettes").get_palette("macchiato")''; + }; + }; + }; + }; + + mini = { + plugins = { + mini = { + enable = true; + mockDevIcons = true; + modules.icons = { }; + }; + tiny-devicons-auto-colors.enable = true; + }; + }; +}