|
104 | 104 | -- NOTE: If the active colorscheme isn't `catppuccin`, this function won't overwrite existing definitions
|
105 | 105 | ---Sets a global highlight group.
|
106 | 106 | ---@param name string @Highlight group name, e.g. "ErrorMsg"
|
107 |
| ----@param foreground string @The foreground color |
| 107 | +---@param foreground? string @The foreground color |
108 | 108 | ---@param background? string @The background color
|
109 | 109 | ---@param italic? boolean
|
110 | 110 | local function set_global_hl(name, foreground, background, italic)
|
@@ -133,6 +133,24 @@ function M.blend(foreground, background, alpha)
|
133 | 133 | return string.format("#%02x%02x%02x", blend_channel(1), blend_channel(2), blend_channel(3))
|
134 | 134 | end
|
135 | 135 |
|
| 136 | +---Darken a color by blending it with the background color. |
| 137 | +---@param hex string @The color in hex to darken |
| 138 | +---@param amount number @The amount to darken the color |
| 139 | +---@param bg string @The background color to blend with |
| 140 | +---@return string @The darkened color as a hex string |
| 141 | +function M.darken(hex, amount, bg) |
| 142 | + return M.blend(hex, bg or "#000000", math.abs(amount)) |
| 143 | +end |
| 144 | + |
| 145 | +---Lighten a color by blending it with the foreground color. |
| 146 | +---@param hex string @The color in hex to lighten |
| 147 | +---@param amount number @The amount to lighten the color |
| 148 | +---@param fg string @The foreground color to blend with |
| 149 | +---@return string @The lightened color as a hex string |
| 150 | +function M.lighten(hex, amount, fg) |
| 151 | + return M.blend(hex, fg or "#FFFFFF", math.abs(amount)) |
| 152 | +end |
| 153 | + |
136 | 154 | ---Get RGB highlight by highlight group
|
137 | 155 | ---@param hl_group string @Highlight group name
|
138 | 156 | ---@param use_bg boolean @Returns background or not
|
@@ -169,6 +187,7 @@ function M.extend_hl(name, def)
|
169 | 187 | local current_def = vim.api.nvim_get_hl(0, { name = name, link = false })
|
170 | 188 | local combined_def = vim.tbl_deep_extend("force", current_def, def)
|
171 | 189 |
|
| 190 | + ---@diagnostic disable-next-line: param-type-mismatch |
172 | 191 | vim.api.nvim_set_hl(0, name, combined_def)
|
173 | 192 | end
|
174 | 193 |
|
|
0 commit comments