|  | 
| 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) | 
| @@ -134,6 +134,24 @@ function M.blend(foreground, background, alpha) | 
| 134 | 134 | 	return string.format("#%02x%02x%02x", blend_channel(1), blend_channel(2), blend_channel(3)) | 
| 135 | 135 | end | 
| 136 | 136 | 
 | 
|  | 137 | +---Darken a color by blending it with the background color. | 
|  | 138 | +---@param hex string @The color in hex to darken | 
|  | 139 | +---@param amount number @The amount to darken the color | 
|  | 140 | +---@param bg string @The background color to blend with | 
|  | 141 | +---@return string @The darkened color as a hex string | 
|  | 142 | +function M.darken(hex, amount, bg) | 
|  | 143 | +	return M.blend(hex, bg or "#000000", math.abs(amount)) | 
|  | 144 | +end | 
|  | 145 | + | 
|  | 146 | +---Lighten a color by blending it with the foreground color. | 
|  | 147 | +---@param hex string @The color in hex to lighten | 
|  | 148 | +---@param amount number @The amount to lighten the color | 
|  | 149 | +---@param fg string @The foreground color to blend with | 
|  | 150 | +---@return string @The lightened color as a hex string | 
|  | 151 | +function M.lighten(hex, amount, fg) | 
|  | 152 | +	return M.blend(hex, fg or "#FFFFFF", math.abs(amount)) | 
|  | 153 | +end | 
|  | 154 | + | 
| 137 | 155 | ---Get RGB highlight by highlight group | 
| 138 | 156 | ---@param hl_group string @Highlight group name | 
| 139 | 157 | ---@param use_bg boolean @Returns background or not | 
| @@ -170,6 +188,7 @@ function M.extend_hl(name, def) | 
| 170 | 188 | 	local current_def = vim.api.nvim_get_hl(0, { name = name, link = false }) | 
| 171 | 189 | 	local combined_def = vim.tbl_deep_extend("force", current_def, def) | 
| 172 | 190 | 
 | 
|  | 191 | +	---@diagnostic disable-next-line: param-type-mismatch | 
| 173 | 192 | 	vim.api.nvim_set_hl(0, name, combined_def) | 
| 174 | 193 | end | 
| 175 | 194 | 
 | 
| @@ -239,6 +258,15 @@ function M.gen_alpha_hl() | 
| 239 | 258 | 	set_global_hl("AlphaFooter", colors.yellow) | 
| 240 | 259 | end | 
| 241 | 260 | 
 | 
|  | 261 | +-- Generate highlight groups for cursorword. Existing attributes will NOT be overwritten | 
|  | 262 | +function M.gen_cursorword_hl() | 
|  | 263 | +	local colors = M.get_palette() | 
|  | 264 | + | 
|  | 265 | +	-- Do not highlight `MiniCursorwordCurrent` | 
|  | 266 | +	set_global_hl("MiniCursorword", nil, M.darken(colors.surface1, 0.7, colors.base)) | 
|  | 267 | +	set_global_hl("MiniCursorwordCurrent", nil) | 
|  | 268 | +end | 
|  | 269 | + | 
| 242 | 270 | ---Convert number (0/1) to boolean | 
| 243 | 271 | ---@param value number @The value to check | 
| 244 | 272 | ---@return boolean|nil @Returns nil if failed | 
|  | 
0 commit comments