feat(hl): highlight icons

This commit is contained in:
Barrett Ruth 2026-03-02 19:40:26 -05:00
parent 4335fb8596
commit 7a655c9919
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
5 changed files with 130 additions and 3 deletions

View file

@ -0,0 +1,37 @@
local colors = require('nonicons.colors')
local M = {}
---@param icon_name string
---@return string
local function to_hl_group(icon_name)
local parts = {}
for part in icon_name:gmatch('[^-]+') do
parts[#parts + 1] = part:sub(1, 1):upper() .. part:sub(2)
end
return 'Nonicons' .. table.concat(parts)
end
local function apply()
for name, data in pairs(colors) do
vim.api.nvim_set_hl(0, to_hl_group(name), { fg = data[1], ctermfg = data[2] })
end
end
function M.setup()
apply()
local group = vim.api.nvim_create_augroup('NoniconsHighlights', { clear = true })
vim.api.nvim_create_autocmd('ColorScheme', {
group = group,
callback = apply,
})
end
---@param icon_name string
---@return string hl_group
function M.get(icon_name)
return to_hl_group(icon_name)
end
return M