From d32553aa1a8cd49a514a347558524c98eb566627 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 19 Jun 2026 11:23:25 -0400 Subject: refactor(theme-studio): dedup the palette harvest and color-pair walks generate.py's add_default_palette_colors repeated the same fg/bg/box-color harvest three times (syntax, ui, package faces); it now calls one _harvest_spec_colors helper, preserving the add order so the palette and generated page are byte-identical. default_faces' _build_color_hex and _build_color_names each walked the same faces -> chosen/effective -> foreground/background/distantForeground nesting; both now consume one _iter_color_pairs generator and only differ in their key choice and filter. The rebuilt color maps match the originals exactly. I left the lower-value generate.py items (a build() wrapper, dict-driven fill_data) and the capture/face-coverage script dedups for later: they touch import-time behavior or scripts the suite doesn't run, so they want their own verification rather than riding this change. --- scripts/theme-studio/generate.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'scripts/theme-studio/generate.py') diff --git a/scripts/theme-studio/generate.py b/scripts/theme-studio/generate.py index d774a6061..43ebf02c6 100644 --- a/scripts/theme-studio/generate.py +++ b/scripts/theme-studio/generate.py @@ -177,25 +177,23 @@ def add_palette_color(palette,defaults,value,label=None): name=base+'-'+str(n); n+=1 palette.append([value,name,column_id(name)]) +def _harvest_spec_colors(palette,defaults,spec): + """Add a face spec's fg, bg, and box color (if any) to the palette, in order.""" + add_palette_color(palette,defaults,spec.get('fg')) + add_palette_color(palette,defaults,spec.get('bg')) + if spec.get('box'): + add_palette_color(palette,defaults,spec['box'].get('color')) + def add_default_palette_colors(palette,map_,syntax,uimap,apps,defaults): for key,value in map_.items(): add_palette_color(palette,defaults,value,'bg' if key=='bg' else 'fg' if key=='p' else None) for spec in syntax.values(): - add_palette_color(palette,defaults,spec.get('fg')) - add_palette_color(palette,defaults,spec.get('bg')) - if spec.get('box'): - add_palette_color(palette,defaults,spec['box'].get('color')) + _harvest_spec_colors(palette,defaults,spec) for _face,spec in uimap.items(): - add_palette_color(palette,defaults,spec.get('fg')) - add_palette_color(palette,defaults,spec.get('bg')) - if spec.get('box'): - add_palette_color(palette,defaults,spec['box'].get('color')) + _harvest_spec_colors(palette,defaults,spec) for app in apps.values(): for _face,_label,spec in app['faces']: - add_palette_color(palette,defaults,spec.get('fg')) - add_palette_color(palette,defaults,spec.get('bg')) - if spec.get('box'): - add_palette_color(palette,defaults,spec['box'].get('color')) + _harvest_spec_colors(palette,defaults,spec) def apply_seed_packages(apps,data,seed): if seed: -- cgit v1.2.3