mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-06-25 10:18:47 +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, "")
|
return table.concat(components, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@return {fg?:string}?
|
||||||
function M.fg(name)
|
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}?
|
---@type {foreground?:number}?
|
||||||
---@diagnostic disable-next-line: deprecated
|
---@diagnostic disable-next-line: deprecated
|
||||||
local hl = vim.api.nvim_get_hl and vim.api.nvim_get_hl(0, { name = name, link = false })
|
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)
|
or vim.api.nvim_get_hl_by_name(name, true)
|
||||||
---@diagnostic disable-next-line: undefined-field
|
---@diagnostic disable-next-line: undefined-field
|
||||||
local fg = hl and (hl.fg or hl.foreground)
|
---@type string?
|
||||||
return fg and { fg = string.format("#%06x", fg) } or nil
|
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
|
end
|
||||||
|
|
||||||
M.skip_foldexpr = {} ---@type table<number,boolean>
|
M.skip_foldexpr = {} ---@type table<number,boolean>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue