summaryrefslogtreecommitdiffstats
path: root/lua/core/color.lua
blob: c4525f52c27c97e2008da747190d68a29105a7dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
local M = {}

--- copy highlight group
---@param hlgroup string highlight group to copy
---@param namespace? number highlight space
---@return table
function M.copyhl(hlgroup, namespace)
  namespace = namespace or 0

  local ok, hl = pcall(vim.api.nvim_get_hl, namespace, {
    name = hlgroup,
    create = false
  })
  if not ok then
    return {}
  end

  for _, key in pairs({ "foreground", "background", "special" }) do
    if hl[key] then
      hl[key] = string.format("#%06x", hl[key])
    end
  end
  return hl
end

return M