|
| 1 | +{ |
| 2 | + config, |
| 3 | + lib, |
| 4 | + ... |
| 5 | +}: let |
| 6 | + inherit (lib.options) mkOption; |
| 7 | + inherit (lib.types) nullOr attrsOf listOf submodule bool ints str enum; |
| 8 | + inherit (lib.strings) hasPrefix concatLines; |
| 9 | + inherit (lib.attrsets) mapAttrsToList; |
| 10 | + inherit (lib.nvim.dag) entryBetween; |
| 11 | + inherit (lib.nvim.lua) toLuaObject; |
| 12 | + inherit (lib.nvim.types) hexColor; |
| 13 | + |
| 14 | + mkColorOption = target: |
| 15 | + mkOption { |
| 16 | + type = nullOr hexColor; |
| 17 | + default = null; |
| 18 | + example = "#ebdbb2"; |
| 19 | + description = '' |
| 20 | + The ${target} color to use. Written as color name or hex "#RRGGBB". |
| 21 | + ''; |
| 22 | + }; |
| 23 | + |
| 24 | + mkBoolOption = name: |
| 25 | + mkOption { |
| 26 | + type = nullOr bool; |
| 27 | + default = null; |
| 28 | + example = false; |
| 29 | + description = "Whether to enable ${name}"; |
| 30 | + }; |
| 31 | + |
| 32 | + cfg = config.vim.highlight; |
| 33 | +in { |
| 34 | + options.vim.highlight = mkOption { |
| 35 | + type = attrsOf (submodule { |
| 36 | + # See :h nvim_set_hl |
| 37 | + options = { |
| 38 | + bg = mkColorOption "background"; |
| 39 | + fg = mkColorOption "foreground"; |
| 40 | + sp = mkColorOption "special"; |
| 41 | + blend = mkOption { |
| 42 | + type = nullOr (ints.between 0 100); |
| 43 | + default = null; |
| 44 | + description = "Blend as an integer between 0 and 100"; |
| 45 | + }; |
| 46 | + bold = mkBoolOption "bold"; |
| 47 | + standout = mkBoolOption "standout"; |
| 48 | + underline = mkBoolOption "underline"; |
| 49 | + undercurl = mkBoolOption "undercurl"; |
| 50 | + underdouble = mkBoolOption "underdouble"; |
| 51 | + underdotted = mkBoolOption "underdotted"; |
| 52 | + underdashed = mkBoolOption "underdashed"; |
| 53 | + strikethrough = mkBoolOption "strikethrough"; |
| 54 | + italic = mkBoolOption "italic"; |
| 55 | + reverse = mkBoolOption "reverse"; |
| 56 | + nocombine = mkBoolOption "nocombine"; |
| 57 | + link = mkOption { |
| 58 | + type = nullOr str; |
| 59 | + default = null; |
| 60 | + description = "The name of another highlight group to link to"; |
| 61 | + }; |
| 62 | + default = mkOption { |
| 63 | + type = nullOr bool; |
| 64 | + default = null; |
| 65 | + description = "Don't override existing definition"; |
| 66 | + }; |
| 67 | + ctermfg = mkOption { |
| 68 | + type = nullOr str; |
| 69 | + default = null; |
| 70 | + description = "The cterm foreground color to use"; |
| 71 | + }; |
| 72 | + ctermbg = mkOption { |
| 73 | + type = nullOr str; |
| 74 | + default = null; |
| 75 | + description = "The cterm background color to use"; |
| 76 | + }; |
| 77 | + cterm = mkOption { |
| 78 | + type = nullOr (listOf (enum [ |
| 79 | + "bold" |
| 80 | + "underline" |
| 81 | + "undercurl" |
| 82 | + "underdouble" |
| 83 | + "underdotted" |
| 84 | + "underdashed" |
| 85 | + "strikethrough" |
| 86 | + "reverse" |
| 87 | + "inverse" |
| 88 | + "italic" |
| 89 | + "standout" |
| 90 | + "altfont" |
| 91 | + "nocombine" |
| 92 | + "NONE" |
| 93 | + ])); |
| 94 | + default = null; |
| 95 | + description = "The cterm arguments to use. See ':h highlight-args'"; |
| 96 | + }; |
| 97 | + force = mkBoolOption "force update"; |
| 98 | + }; |
| 99 | + }); |
| 100 | + default = {}; |
| 101 | + example = { |
| 102 | + SignColumn = { |
| 103 | + bg = "#282828"; |
| 104 | + }; |
| 105 | + }; |
| 106 | + description = "Custom highlights to apply"; |
| 107 | + }; |
| 108 | + |
| 109 | + config = { |
| 110 | + vim.luaConfigRC.highlight = let |
| 111 | + highlights = |
| 112 | + mapAttrsToList ( |
| 113 | + name: value: ''vim.api.nvim_set_hl(0, ${toLuaObject name}, ${toLuaObject value})'' |
| 114 | + ) |
| 115 | + cfg; |
| 116 | + in |
| 117 | + entryBetween ["lazyConfigs" "pluginConfigs" "extraPluginConfigs"] ["theme"] (concatLines highlights); |
| 118 | + }; |
| 119 | +} |
0 commit comments