repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
neovim/tests/manual/capture_highlights.lua
Raw--- Capture current highlights as a baseline for comparison.
--- Stores both gui (hex) and cterm values where available.
--- Usage: :luafile tests/manual/capture_highlights.lua
--- Output: /tmp/nugu_highlights_baseline.txt
local function rgb_to_hex(n)
if type(n) ~= 'number' then return nil end
return string.format('#%06x', n)
end
local function sorted_keys(t)
local keys = {}
for k in pairs(t) do
keys[#keys + 1] = k
end
table.sort(keys)
return keys
end
local all_hl = vim.api.nvim_get_hl(0, {})
local names = sorted_keys(all_hl)
local lines = {
'-- Nugu highlight baseline',
'-- Date: ' .. os.date '!%Y-%m-%dT%H:%M:%SZ',
'-- Groups: ' .. #names,
'-- termguicolors: ' .. tostring(vim.o.termguicolors),
'',
}
for _, name in ipairs(names) do
local hl = all_hl[name]
local parts = {}
if hl.fg then parts[#parts + 1] = 'fg=' .. rgb_to_hex(hl.fg) end
if hl.bg then parts[#parts + 1] = 'bg=' .. rgb_to_hex(hl.bg) end
if hl.sp then parts[#parts + 1] = 'sp=' .. rgb_to_hex(hl.sp) end
if hl.ctermfg then parts[#parts + 1] = 'ctermfg=' .. hl.ctermfg end
if hl.ctermbg then parts[#parts + 1] = 'ctermbg=' .. hl.ctermbg end
if hl.blend then parts[#parts + 1] = 'blend=' .. hl.blend end
-- check both top-level (gui) and cterm table for attributes
local cterm = hl.cterm or {}
if hl.bold or cterm.bold then parts[#parts + 1] = 'bold' end
if hl.italic or cterm.italic then parts[#parts + 1] = 'italic' end
if hl.underline or cterm.underline then parts[#parts + 1] = 'underline' end
if hl.undercurl or cterm.undercurl then parts[#parts + 1] = 'undercurl' end
if hl.underdouble or cterm.underdouble then parts[#parts + 1] = 'underdouble' end
if hl.underdotted or cterm.underdotted then parts[#parts + 1] = 'underdotted' end
if hl.underdashed or cterm.underdashed then parts[#parts + 1] = 'underdashed' end
if hl.strikethrough or cterm.strikethrough then parts[#parts + 1] = 'strikethrough' end
if hl.reverse or cterm.reverse then parts[#parts + 1] = 'reverse' end
if hl.standout or cterm.standout then parts[#parts + 1] = 'standout' end
if hl.nocombine or cterm.nocombine then parts[#parts + 1] = 'nocombine' end
if hl.link then parts[#parts + 1] = 'link=' .. hl.link end
if hl.default then parts[#parts + 1] = 'default' end
if #parts > 0 then
lines[#lines + 1] = name .. ' ' .. table.concat(parts, ' ')
end
end
local outpath = vim.fn.argv()[1] or '/tmp/nugu_highlights_baseline.txt'
local f = assert(io.open(outpath, 'w'))
f:write(table.concat(lines, '\n') .. '\n')
f:close()
print('Captured ' .. #names .. ' highlight groups to ' .. outpath)