repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

wip: add highlight capture scripts before cterm refactor

9bc8a4a7599d2cfc3bd569dd5205c3cf94b7aa06

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (2)

neovim/tests/manual/analyze_color_usage.lua

Added
new file mode 100644
1 +-- Analyze which nugu palette colors are used in highlight groups
2 +-- and map them to wezterm ANSI/indexed slots.
3 +-- Usage: :luafile tests/manual/analyze_color_usage.lua
5 +local palette = require 'bugabinga.nugu.palette'
7 +-- Build reverse map: hex -> semantic name
8 +local hex_to_name = {}
9 +for k, v in pairs(palette) do
10 + hex_to_name[v] = k
11 +end
13 +-- Current wezterm mapping (from wezterm/nugu/init.lua)
14 +local ansi_map = {
15 + [0] = 'content_backdrop',
16 + [1] = 'error',
17 + [2] = 'content_focus',
18 + [3] = 'warning',
19 + [4] = 'content_important_local',
20 + [5] = 'content_accent',
21 + [6] = 'content_unfocus',
22 + [7] = 'content_normal',
23 + [8] = 'content_minor',
24 + [9] = 'error', -- duplicate
25 + [10] = 'ui_unfocus',
26 + [11] = 'ui_backdrop',
27 + [12] = 'content_important_global',
28 + [13] = 'ui_accent',
29 + [14] = 'ui_important_local',
30 + [15] = 'ui_important_global',
33 +-- Build name -> slot
34 +local name_to_slot = {}
35 +for slot, name in pairs(ansi_map) do
36 + name_to_slot[name] = slot
37 +end
39 +-- Collect all unique fg/bg/sp colors used
40 +local all_hl = vim.api.nvim_get_hl(0, {})
41 +local color_usage = {} -- hex -> { groups={}, as={fg=0, bg=0, sp=0} }
43 +for name, hl in pairs(all_hl) do
44 + for _, prop in ipairs { 'fg', 'bg', 'sp' } do
45 + if hl[prop] then
46 + local hex = string.format('#%06x', hl[prop])
47 + if not color_usage[hex] then
48 + color_usage[hex] = { groups = {}, as = { fg = 0, bg = 0, sp = 0 } }
49 + end
50 + color_usage[hex].as[prop] = color_usage[hex].as[prop] + 1
51 + color_usage[hex].groups[#color_usage[hex].groups + 1] = name .. '.' .. prop
52 + end
53 + end
54 +end
56 +print('=== Color Usage Analysis ===')
57 +print('')
59 +-- Sort by total usage
60 +local sorted = {}
61 +for hex, info in pairs(color_usage) do
62 + local total = info.as.fg + info.as.bg + info.as.sp
63 + sorted[#sorted + 1] = { hex = hex, info = info, total = total }
64 +end
65 +table.sort(sorted, function(a, b) return a.total > b.total end)
67 +local covered = 0
68 +local uncovered = 0
69 +local uncovered_colors = {}
71 +for _, entry in ipairs(sorted) do
72 + local hex = entry.hex
73 + local name = hex_to_name[hex] or 'UNKNOWN'
74 + local slot = name_to_slot[name]
75 + local status = slot and ('slot ' .. slot) or 'UNMAPPED'
76 + print(string.format('%-30s %-25s fg=%-3d bg=%-3d sp=%-3d total=%-3d %s',
77 + hex, name, entry.info.as.fg, entry.info.as.bg, entry.info.as.sp, entry.total, status))
78 + if slot then
79 + covered = covered + entry.total
80 + else
81 + uncovered = uncovered + entry.total
82 + uncovered_colors[#uncovered_colors + 1] = { hex = hex, name = name, total = entry.total }
83 + end
84 +end
86 +print('')
87 +print(string.format('Covered by ANSI: %d references', covered))
88 +print(string.format('Not in ANSI palette: %d references', uncovered))
89 +print('')
91 +print('=== Unmapped colors ===')
92 +for _, c in ipairs(uncovered_colors) do
93 + print(string.format(' %-30s (%s) used %d times', c.hex, c.name, c.total))
94 +end
96 +print('')
97 +print('=== Proposed indexed slot assignment ===')
98 +local next_slot = 16
99 +for _, c in ipairs(uncovered_colors) do
100 + print(string.format(' indexed[%d] = %s (%s)', next_slot, c.hex, c.name))
101 + next_slot = next_slot + 1
102 +end
104 +-- Also check: can we reclaim slot 9?
105 +print('')
106 +print('=== Slot 9 reclaim ===')
107 +print('Slot 9 currently duplicates error (slot 1).')
108 +print('Can be reassigned to: ' .. uncovered_colors[1].name .. ' (' .. uncovered_colors[1].hex .. ')')

neovim/tests/manual/capture_highlights.lua

Added
new file mode 100644
1 +--- Capture current highlights as a baseline for comparison.
2 +--- Stores both gui (hex) and cterm values where available.
3 +--- Usage: :luafile tests/manual/capture_highlights.lua
4 +--- Output: /tmp/nugu_highlights_baseline.txt
6 +local function rgb_to_hex(n)
7 + if type(n) ~= 'number' then return nil end
8 + return string.format('#%06x', n)
9 +end
11 +local function sorted_keys(t)
12 + local keys = {}
13 + for k in pairs(t) do
14 + keys[#keys + 1] = k
15 + end
16 + table.sort(keys)
17 + return keys
18 +end
20 +local all_hl = vim.api.nvim_get_hl(0, {})
21 +local names = sorted_keys(all_hl)
23 +local lines = {
24 + '-- Nugu highlight baseline',
25 + '-- Date: ' .. os.date '!%Y-%m-%dT%H:%M:%SZ',
26 + '-- Groups: ' .. #names,
27 + '-- termguicolors: ' .. tostring(vim.opt.termguicolors:get()),
28 + '',
31 +for _, name in ipairs(names) do
32 + local hl = all_hl[name]
33 + local parts = {}
35 + if hl.fg then parts[#parts + 1] = 'fg=' .. rgb_to_hex(hl.fg) end
36 + if hl.bg then parts[#parts + 1] = 'bg=' .. rgb_to_hex(hl.bg) end
37 + if hl.sp then parts[#parts + 1] = 'sp=' .. rgb_to_hex(hl.sp) end
38 + if hl.ctermfg then parts[#parts + 1] = 'ctermfg=' .. hl.ctermfg end
39 + if hl.ctermbg then parts[#parts + 1] = 'ctermbg=' .. hl.ctermbg end
40 + if hl.blend then parts[#parts + 1] = 'blend=' .. hl.blend end
41 + if hl.bold then parts[#parts + 1] = 'bold' end
42 + if hl.italic then parts[#parts + 1] = 'italic' end
43 + if hl.underline then parts[#parts + 1] = 'underline' end
44 + if hl.undercurl then parts[#parts + 1] = 'undercurl' end
45 + if hl.underdouble then parts[#parts + 1] = 'underdouble' end
46 + if hl.underdotted then parts[#parts + 1] = 'underdotted' end
47 + if hl.underdashed then parts[#parts + 1] = 'underdashed' end
48 + if hl.strikethrough then parts[#parts + 1] = 'strikethrough' end
49 + if hl.reverse then parts[#parts + 1] = 'reverse' end
50 + if hl.standout then parts[#parts + 1] = 'standout' end
51 + if hl.nocombine then parts[#parts + 1] = 'nocombine' end
52 + if hl.link then parts[#parts + 1] = 'link=' .. hl.link end
53 + if hl.default then parts[#parts + 1] = 'default' end
55 + if #parts > 0 then
56 + lines[#lines + 1] = name .. ' ' .. table.concat(parts, ' ')
57 + end
58 +end
60 +local outpath = vim.fn.argv()[1] or '/tmp/nugu_highlights_baseline.txt'
61 +local f = io.open(outpath, 'w')
62 +f:write(table.concat(lines, '\n') .. '\n')
63 +f:close()
64 +print('Captured ' .. #names .. ' highlight groups to ' .. outpath)