|
| 1 | +{ |
| 2 | + lib, |
| 3 | + helpers, |
| 4 | + config, |
| 5 | + pkgs, |
| 6 | + ... |
| 7 | +}: |
| 8 | +with lib; let |
| 9 | + cfg = config.colorschemes.palette; |
| 10 | +in { |
| 11 | + meta.maintainers = [maintainers.GaetanLepage]; |
| 12 | + |
| 13 | + options.colorschemes.palette = |
| 14 | + helpers.extraOptionsOptions |
| 15 | + // { |
| 16 | + enable = mkEnableOption "palette.nvim"; |
| 17 | + |
| 18 | + # package = helpers.mkPackageOption "palette.nvim" pkgs.vimPlugins.palette-nvim; |
| 19 | + package = helpers.mkPackageOption "palette.nvim" pkgs.vimPlugins.harpoon; # TODO |
| 20 | + |
| 21 | + palettes = { |
| 22 | + main = helpers.defaultNullOpts.mkStr "dark" '' |
| 23 | + Palette for the main colors. |
| 24 | + ''; |
| 25 | + |
| 26 | + accent = helpers.defaultNullOpts.mkStr "pastel" '' |
| 27 | + Palette for the accent colors. |
| 28 | + ''; |
| 29 | + |
| 30 | + state = helpers.defaultNullOpts.mkStr "pastel" '' |
| 31 | + Palette for the state colors. |
| 32 | + ''; |
| 33 | + }; |
| 34 | + |
| 35 | + customPalettes = |
| 36 | + mapAttrs |
| 37 | + ( |
| 38 | + name: colorNames: |
| 39 | + helpers.defaultNullOpts.mkAttrsOf ( |
| 40 | + types.submodule { |
| 41 | + options = |
| 42 | + genAttrs |
| 43 | + colorNames |
| 44 | + ( |
| 45 | + colorName: |
| 46 | + mkOption { |
| 47 | + type = types.str; |
| 48 | + description = "Definition of color '${colorName}'"; |
| 49 | + } |
| 50 | + ); |
| 51 | + } |
| 52 | + ) |
| 53 | + "{}" |
| 54 | + '' |
| 55 | + Custom palettes for ${name} colors. |
| 56 | + '' |
| 57 | + ) { |
| 58 | + main = [ |
| 59 | + "color0" |
| 60 | + "color1" |
| 61 | + "color2" |
| 62 | + "color3" |
| 63 | + "color4" |
| 64 | + "color5" |
| 65 | + "color6" |
| 66 | + "color7" |
| 67 | + "color8" |
| 68 | + ]; |
| 69 | + |
| 70 | + accent = [ |
| 71 | + "accent0" |
| 72 | + "accent1" |
| 73 | + "accent2" |
| 74 | + "accent3" |
| 75 | + "accent4" |
| 76 | + "accent5" |
| 77 | + "accent6" |
| 78 | + ]; |
| 79 | + |
| 80 | + state = [ |
| 81 | + "error" |
| 82 | + "warning" |
| 83 | + "hint" |
| 84 | + "ok" |
| 85 | + "info" |
| 86 | + ]; |
| 87 | + }; |
| 88 | + |
| 89 | + italics = helpers.defaultNullOpts.mkBool true '' |
| 90 | + Whether to use italics. |
| 91 | + ''; |
| 92 | + |
| 93 | + transparentBackground = helpers.defaultNullOpts.mkBool false '' |
| 94 | + Whether to use transparent background. |
| 95 | + ''; |
| 96 | + |
| 97 | + caching = helpers.defaultNullOpts.mkBool true '' |
| 98 | + Whether to enable caching. |
| 99 | + ''; |
| 100 | + |
| 101 | + cacheDir = |
| 102 | + helpers.defaultNullOpts.mkNullable |
| 103 | + (with types; either str helpers.rawType) |
| 104 | + ''{__raw = "vim.fn.stdpath('cache') .. '/palette'";}'' |
| 105 | + "Cache directory."; |
| 106 | + }; |
| 107 | + |
| 108 | + config = mkIf cfg.enable { |
| 109 | + assertions = |
| 110 | + mapAttrsToList ( |
| 111 | + name: defaultPaletteNames: let |
| 112 | + palette = cfg.palettes.${name}; |
| 113 | + allowedPaletteNames = (attrNames cfg.customPalettes.${name}) ++ defaultPaletteNames; |
| 114 | + in { |
| 115 | + assertion = isString palette -> elem palette allowedPaletteNames; |
| 116 | + message = '' |
| 117 | + Nixvim: `colorschemes.palette.palettes.${name}` (${palette}") is not part of the allowed ${name} palette names (${concatStringsSep " " allowedPaletteNames}). |
| 118 | + ''; |
| 119 | + } |
| 120 | + ) |
| 121 | + { |
| 122 | + main = ["dark" "light"]; |
| 123 | + accent = ["pastel" "dark" "bright"]; |
| 124 | + state = ["pastel" "dark" "bright"]; |
| 125 | + }; |
| 126 | + |
| 127 | + colorscheme = "palette"; |
| 128 | + |
| 129 | + extraPlugins = [cfg.package]; |
| 130 | + |
| 131 | + extraConfigLuaPre = let |
| 132 | + setupOptions = with cfg; |
| 133 | + { |
| 134 | + inherit palettes; |
| 135 | + custom_palettes = customPalettes; |
| 136 | + inherit italics; |
| 137 | + transparent_background = transparentBackground; |
| 138 | + inherit caching; |
| 139 | + cache_dir = cacheDir; |
| 140 | + } |
| 141 | + // cfg.extraOptions; |
| 142 | + in '' |
| 143 | + require('palette').setup(${helpers.toLuaObject setupOptions}) |
| 144 | + ''; |
| 145 | + }; |
| 146 | +} |
0 commit comments