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
Addednew file mode 100644 5 +local palette
= require 'bugabinga.nugu.palette' 8 +local hex_to_name
= {}
9 +for k, v
in pairs(palette)
do 15 + [
0] =
'content_backdrop',
17 + [
2] =
'content_focus',
19 + [
4] =
'content_important_local',
20 + [
5] =
'content_accent',
21 + [
6] =
'content_unfocus',
22 + [
7] =
'content_normal',
23 + [
8] =
'content_minor',
25 + [
10] =
'ui_unfocus',
26 + [
11] =
'ui_backdrop',
27 + [
12] =
'content_important_global',
29 + [
14] =
'ui_important_local',
30 + [
15] =
'ui_important_global',
34 +local name_to_slot
= {}
35 +for slot, name
in pairs(ansi_map)
do 36 + name_to_slot[name]
= slot
40 +local all_hl
= vim.api.nvim_get_hl(
0, {})
41 +local color_usage
= {}
43 +for name, hl
in pairs(all_hl)
do 44 + for _, prop
in ipairs {
'fg',
'bg',
'sp' }
do 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 } }
50 + color_usage[hex].as[prop]
= color_usage[hex].as[prop]
+ 1 51 + color_usage[hex].groups[
#color_usage[hex].groups
+ 1]
= name
.. '.' .. prop
56 +print(
'=== Color Usage Analysis ===')
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 }
65 +table.
sort(sorted,
function(a, b)
return a.total
> b.total
end)
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))
79 + covered
= covered
+ entry.total
81 + uncovered
= uncovered
+ entry.total
82 + uncovered_colors[
#uncovered_colors
+ 1]
= {
hex = hex,
name = name,
total = entry.total }
87 +print(
string.
format(
'Covered by ANSI: %d references', covered))
88 +print(
string.
format(
'Not in ANSI palette: %d references', uncovered))
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))
97 +print(
'=== Proposed indexed slot assignment ===')
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 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
Addednew file mode 100644 6 +local function rgb_to_hex(n)
7 + if type(n)
~= 'number' then return nil end 8 + return string.
format(
'#%06x', n)
11 +local function sorted_keys(t)
13 + for k
in pairs(t)
do 20 +local all_hl
= vim.api.nvim_get_hl(
0, {})
21 +local names
= sorted_keys(all_hl)
24 + '-- Nugu highlight baseline',
25 + '-- Date: ' .. os.
date '!%Y-%m-%dT%H:%M:%SZ',
26 + '-- Groups: ' .. #names,
27 + '-- termguicolors: ' .. tostring(vim.opt.termguicolors:get()),
31 +for _, name
in ipairs(names)
do 32 + local hl
= all_hl[name]
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 56 + lines[
#lines
+ 1]
= name
.. ' ' .. table.
concat(parts,
' ')
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')
64 +print(
'Captured ' .. #names
.. ' highlight groups to ' .. outpath)