nix-dots/pkgs/nvim/config/helpers.lua

27 lines
588 B
Lua

if MVim then return end -- avoid loading twice the same module
MVim = {}
---@return {fg?:string}?
function MVim.fg(name)
local color = MVim.color(name)
return color and { fg = color } or nil
end
---@param name string
---@param bg? boolean
---@return string?
function MVim.color(name, bg)
---@type {fg?:number, bg?:number}?
local hl = vim.api.nvim_get_hl(0, { name = name, link = false })
---@type number?
local color = nil
if hl then
if bg then
color = hl.bg
else
color = hl.fg
end
end
return color and string.format("#%06x", color) or nil
end