Skip to content

Commit 25c0cf1

Browse files
committed
feat: add get_hlgroup function
1 parent 4e4eb1d commit 25c0cf1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lua/astroui/init.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ function M.setup(opts)
3939
end
4040
end
4141

42+
--- Get highlight properties for a given highlight name
43+
---@param name string The highlight group name
44+
---@param fallback? table The fallback highlight properties
45+
---@return table properties # the highlight group properties
46+
function M.get_hlgroup(name, fallback)
47+
if vim.fn.hlexists(name) == 1 then
48+
local hl = vim.api.nvim_get_hl(0, { name = name, link = false })
49+
if not hl.fg then hl.fg = "NONE" end
50+
if not hl.bg then hl.bg = "NONE" end
51+
return hl
52+
end
53+
return fallback or {}
54+
end
55+
4256
--- Get an icon from the AstroNvim internal icons if it is available and return it
4357
---@param kind string The kind of icon in astroui.icons to retrieve
4458
---@param padding? integer Padding to add to the end of the icon

0 commit comments

Comments
 (0)