local function parse_color(col)
local hex = string.format('%06x', col)
local red = tonumber(hex:sub(1, 2), 16)
local green = tonumber(hex:sub(3, 4), 16)
local blue = tonumber(hex:sub(5, 6), 16)
return red, green, blue
end
local function sorted_pairs(tbl)
local keys = {}
for k in pairs(tbl) do keys[#keys+1] = k end
table.sort(keys)
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], tbl[keys[i]]
end
end
end
local all_highlights = vim.api.nvim_get_hl(0, {})
print(' ResolvedTheme::new(BTreeMap::from([')
local normal = vim.api.nvim_get_hl(0, { name = 'Normal' })
if normal.bg ~= nil then
local line = ' ("bg0".to_owned(), Style::color_only('
local r, g, b = parse_color(normal.bg)
line = line .. r .. ', ' .. g .. ', ' .. b .. ')),'
print(line)
end
for key, _ in sorted_pairs(all_highlights) do
if key:sub(1, 1) ~= '@' or key:find('@lsp', 1, true) == 1 then
goto continue
end
local style = vim.api.nvim_get_hl(0, { name = key })
while style.link ~= nil do
style = vim.api.nvim_get_hl(0, { name = style.link })
end
if style.fg == nil then
goto continue
end
local value = 'Style::new('
local r, g, b = parse_color(style.fg)
value = value .. 'Color::new(' .. r .. ', ' .. g .. ', ' .. b .. '), '
value = value .. tostring(style.underline or false) .. ', '
value = value .. tostring(style.strikethrough or false) .. ', '
value = value .. tostring(style.italic or false) .. ', '
value = value .. tostring(style.bold or false) .. ')'
print(' ("' .. key:sub(2) .. '".to_owned(), ' .. value .. '),')
::continue::
end
print(' ]))')