mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-24 17:58:51 +02:00
feat(util): added util function to get a fg/bg color from the active colorscheme
This commit is contained in:
parent
1d2cb7d8d1
commit
c00e3aa6b1
1 changed files with 19 additions and 2 deletions
|
@ -139,14 +139,31 @@ function M.statuscolumn()
|
|||
return table.concat(components, "")
|
||||
end
|
||||
|
||||
---@return {fg?:string}?
|
||||
function M.fg(name)
|
||||
local color = M.color(name)
|
||||
return color and { fg = color } or nil
|
||||
end
|
||||
|
||||
---@param name string
|
||||
---@param bg? boolean
|
||||
---@return string?
|
||||
function M.color(name, bg)
|
||||
---@type {foreground?:number}?
|
||||
---@diagnostic disable-next-line: deprecated
|
||||
local hl = vim.api.nvim_get_hl and vim.api.nvim_get_hl(0, { name = name, link = false })
|
||||
or vim.api.nvim_get_hl_by_name(name, true)
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
local fg = hl and (hl.fg or hl.foreground)
|
||||
return fg and { fg = string.format("#%06x", fg) } or nil
|
||||
---@type string?
|
||||
local color = nil
|
||||
if hl then
|
||||
if bg then
|
||||
color = hl.bg or hl.background
|
||||
else
|
||||
color = hl.fg or hl.foreground
|
||||
end
|
||||
end
|
||||
return color and string.format("#%06x", color) or nil
|
||||
end
|
||||
|
||||
M.skip_foldexpr = {} ---@type table<number,boolean>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue