mirror of
https://github.com/rose-pine/neovim.git
synced 2025-10-15 12:38:53 +02:00
perf: parse necessary values upfront
This commit no longer parses each highlight group, but rather user config values only.
This commit is contained in:
parent
557b4faaf6
commit
03eccf56f1
4 changed files with 80 additions and 76 deletions
|
|
@ -15,9 +15,9 @@ local function color_to_rgb(color)
|
|||
end
|
||||
|
||||
---@param color string Palette key or hex value
|
||||
local function parse_color(color)
|
||||
function utilities.parse_color(color)
|
||||
if color == nil then
|
||||
return print("Invalid color")
|
||||
return print("Invalid color: " .. color)
|
||||
end
|
||||
|
||||
color = color:lower()
|
||||
|
|
@ -32,7 +32,7 @@ end
|
|||
---@param fg string Foreground color
|
||||
---@param bg string Background color
|
||||
---@param alpha number Between 0 (background) and 1 (foreground)
|
||||
local function blend(fg, bg, alpha)
|
||||
function utilities.blend(fg, bg, alpha)
|
||||
local fg_rgb = color_to_rgb(fg)
|
||||
local bg_rgb = color_to_rgb(bg)
|
||||
|
||||
|
|
@ -44,22 +44,4 @@ local function blend(fg, bg, alpha)
|
|||
return string.format("#%02X%02X%02X", blend_channel(1), blend_channel(2), blend_channel(3))
|
||||
end
|
||||
|
||||
---@param group string
|
||||
---@param highlight table<string, any>
|
||||
function utilities.highlight(group, highlight, blend_on)
|
||||
local fg = highlight.fg and parse_color(highlight.fg) or "NONE"
|
||||
local bg = highlight.bg and parse_color(highlight.bg) or "NONE"
|
||||
local sp = highlight.sp and parse_color(highlight.sp) or "NONE"
|
||||
|
||||
if highlight.blend ~= nil and (highlight.blend >= 0 and highlight.blend <= 100) and bg ~= nil then
|
||||
bg = blend(bg, blend_on or require("rose-pine.palette").base, highlight.blend / 100)
|
||||
end
|
||||
|
||||
highlight.fg = fg
|
||||
highlight.bg = bg
|
||||
highlight.sp = sp
|
||||
|
||||
vim.api.nvim_set_hl(0, group, highlight)
|
||||
end
|
||||
|
||||
return utilities
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue