refactor(performance): Improve nvim_set_hl

dev
nullchilly 2 years ago
parent 3914f0d38e
commit c1fb001213

@ -14,7 +14,7 @@ function M.get(cp)
BufferLineFill = { bg = bg_highlight }, BufferLineFill = { bg = bg_highlight },
BufferLineBackcrust = { fg = cp.text, bg = inactive_bg }, -- others BufferLineBackcrust = { fg = cp.text, bg = inactive_bg }, -- others
BufferLineBufferVisible = { fg = cp.surface1, bg = inactive_bg }, BufferLineBufferVisible = { fg = cp.surface1, bg = inactive_bg },
BufferLineBufferSelected = { fg = cp.text, bg = cp.base, style = "bold,italic" }, -- current BufferLineBufferSelected = { fg = cp.text, bg = cp.base, style = { "bold", "italic" } }, -- current
BufferLineTab = { fg = cp.surface1, bg = cp.base }, BufferLineTab = { fg = cp.surface1, bg = cp.base },
BufferLineTabSelected = { fg = cp.red, bg = cp.blue }, BufferLineTabSelected = { fg = cp.red, bg = cp.blue },
BufferLineTabClose = { fg = cp.red, bg = inactive_bg }, BufferLineTabClose = { fg = cp.red, bg = inactive_bg },

@ -2,9 +2,9 @@ local M = {}
function M.get(cp) function M.get(cp)
return { return {
HopNextKey = { bg = cp.base, fg = cp.peach, style = "bold,underline" }, HopNextKey = { bg = cp.base, fg = cp.peach, style = { "bold", "underline" } },
HopNextKey1 = { bg = cp.base, fg = cp.blue, style = "bold" }, HopNextKey1 = { bg = cp.base, fg = cp.blue, style = "bold" },
HopNextKey2 = { bg = cp.base, fg = cp.teal, style = "bold,italic" }, HopNextKey2 = { bg = cp.base, fg = cp.teal, style = { "bold", "italic" } },
HopUnmatched = { bg = cp.base, fg = cp.overlay0 }, HopUnmatched = { bg = cp.base, fg = cp.overlay0 },
} }
end end

@ -17,7 +17,7 @@ function M.get(cp)
MiniJump = { fg = cp.overlay2, bg = cp.pink }, MiniJump = { fg = cp.overlay2, bg = cp.pink },
MiniJump2dSpot = { bg = cp.base, fg = cp.peach, style = "bold,underline" }, MiniJump2dSpot = { bg = cp.base, fg = cp.peach, style = { "bold", "underline" } },
MiniStarterCurrent = {}, MiniStarterCurrent = {},
MiniStarterFooter = { fg = cp.yellow, style = "italic" }, MiniStarterFooter = { fg = cp.yellow, style = "italic" },
@ -42,10 +42,10 @@ function M.get(cp)
MiniSurround = { bg = cp.pink, fg = cp.surface1 }, MiniSurround = { bg = cp.pink, fg = cp.surface1 },
MiniTablineCurrent = { fg = cp.text, bg = cp.base, style = "bold,italic" }, MiniTablineCurrent = { fg = cp.text, bg = cp.base, style = { "bold", "italic" } },
MiniTablineFill = { bg = bg_highlight }, MiniTablineFill = { bg = bg_highlight },
MiniTablineHidden = { fg = cp.text, bg = inactive_bg }, MiniTablineHidden = { fg = cp.text, bg = inactive_bg },
MiniTablineModifiedCurrent = { fg = cp.base, bg = cp.text, style = "bold,italic" }, MiniTablineModifiedCurrent = { fg = cp.base, bg = cp.text, style = { "bold", "italic" } },
MiniTablineModifiedHidden = { fg = inactive_bg, bg = cp.text }, MiniTablineModifiedHidden = { fg = inactive_bg, bg = cp.text },
MiniTablineModifiedVisible = { fg = cp.surface1, bg = cp.subtext1 }, MiniTablineModifiedVisible = { fg = cp.surface1, bg = cp.subtext1 },
MiniTablineTabpagesection = { fg = cp.surface1, bg = cp.base }, MiniTablineTabpagesection = { fg = cp.surface1, bg = cp.base },

@ -80,7 +80,7 @@ function M.get(cp)
-- TSURI = { }; -- Any URI like a link or email. -- TSURI = { }; -- Any URI like a link or email.
-- --
-- Markdown tresitter parser support -- Markdown tresitter parser support
TSURI = { fg = cp.rosewater, style = "italic,underline" }, -- urls, links and emails TSURI = { fg = cp.rosewater, style = { "italic", "underline" } }, -- urls, links and emails
TSLiteral = { fg = cp.teal, style = "italic" }, -- used for inline code in markdown and for doc in python (""") TSLiteral = { fg = cp.teal, style = "italic" }, -- used for inline code in markdown and for doc in python (""")
TSTextReference = { fg = cp.lavender, style = "bold" }, -- references TSTextReference = { fg = cp.lavender, style = "bold" }, -- references
TSTitle = { fg = cp.blue, style = "bold" }, -- titles like: # Example TSTitle = { fg = cp.blue, style = "bold" }, -- titles like: # Example

@ -34,7 +34,7 @@ local function get_base()
}, -- Screen-line at the cursor, when 'cursorline' is secp. Low-priority if forecrust (ctermfg OR guifg) is not secp. }, -- Screen-line at the cursor, when 'cursorline' is secp. Low-priority if forecrust (ctermfg OR guifg) is not secp.
Directory = { fg = cp.blue }, -- directory names (and other special names in listings) Directory = { fg = cp.blue }, -- directory names (and other special names in listings)
EndOfBuffer = { fg = cp.base }, -- filler lines (~) after the end of the buffer. By default, this is highlighted like |hl-NonText|. EndOfBuffer = { fg = cp.base }, -- filler lines (~) after the end of the buffer. By default, this is highlighted like |hl-NonText|.
ErrorMsg = { fg = cp.red, style = "bold,italic" }, -- error messages on the command line ErrorMsg = { fg = cp.red, style = { "bold", "italic" } }, -- error messages on the command line
VertSplit = { fg = cp.crust }, -- the column separating vertically split windows VertSplit = { fg = cp.crust }, -- the column separating vertically split windows
Folded = { fg = cp.blue, bg = cp.surface1 }, -- line used for closed folds Folded = { fg = cp.blue, bg = cp.surface1 }, -- line used for closed folds
FoldColumn = { bg = cp.base, fg = cp.overlay0 }, -- 'foldcolumn' FoldColumn = { bg = cp.base, fg = cp.overlay0 }, -- 'foldcolumn'

@ -8,13 +8,4 @@ function M.set_of(list)
return set return set
end end
-- https://www.codegrepper.com/code-examples/lua/lua+split+string+on+comma
function M.split(s, delimiter)
local result = {}
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
return M return M

@ -1,9 +1,6 @@
local udata = require("catppuccin.utils.data")
local g = vim.g local g = vim.g
local util = {} local util = {}
local has_nvim07 = vim.fn.has("nvim-0.7") local has_nvim07 = vim.fn.has("nvim-0.7")
function util.highlight(group, color) function util.highlight(group, color)
@ -15,9 +12,13 @@ function util.highlight(group, color)
else else
if color.style then if color.style then
if color.style ~= "NONE" then if color.style ~= "NONE" then
for _, style in pairs(udata.split(color.style, ",")) do if type(color.style) == "table" then
for _, style in ipairs(color.style) do
color[style] = true color[style] = true
end end
else
color[color.style] = true
end
end end
end end
@ -26,6 +27,9 @@ function util.highlight(group, color)
end end
else else
-- Doc: :h highlight-gui -- Doc: :h highlight-gui
if color.style and type(color.style) == "table" then
color.style = table.concat(color.style, ",")
end
local style = color.style and "gui=" .. color.style or "gui=NONE" local style = color.style and "gui=" .. color.style or "gui=NONE"
local fg = color.fg and "guifg=" .. color.fg or "guifg=NONE" local fg = color.fg and "guifg=" .. color.fg or "guifg=NONE"
local bg = color.bg and "guibg=" .. color.bg or "guibg=NONE" local bg = color.bg and "guibg=" .. color.bg or "guibg=NONE"

Loading…
Cancel
Save