feat: use new style definitions for hl groups. Keep backward compatibility for string styles

This commit is contained in:
Folke Lemaitre
2022-09-12 07:51:08 +02:00
parent fe120cc71e
commit 25a1a77b00
4 changed files with 80 additions and 73 deletions

View File

@@ -49,16 +49,21 @@ function M.invert_color(color)
end
---@param group string
function M.highlight(group, color)
function M.highlight(group, hl)
group = ts.get(group)
if not group then
return
end
local hl = { fg = color.fg, bg = color.bg, sp = color.sp, link = color.link }
if color.style and color.style:lower() ~= "none" then
for s in string.gmatch(color.style, "([^,]+)") do
hl[s] = true
if hl.style then
if type(hl.style) == "table" then
hl = vim.tbl_extend("force", hl, hl.style)
elseif hl.style:lower() ~= "none" then
-- handle old string style definitions
for s in string.gmatch(hl.style, "([^,]+)") do
hl[s] = true
end
end
hl.style = nil
end
vim.api.nvim_set_hl(0, group, hl)
end