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/default_faces.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'scripts/theme-studio/default_faces.py') diff --git a/scripts/theme-studio/default_faces.py b/scripts/theme-studio/default_faces.py index 70ceb39e6..b9633cfa7 100644 --- a/scripts/theme-studio/default_faces.py +++ b/scripts/theme-studio/default_faces.py @@ -141,32 +141,30 @@ class DefaultFaces: "packageInherits": package_inherits, } - def _build_color_hex(self) -> dict[str, str]: - out: dict[str, str] = {} + def _iter_color_pairs(self): + """Yield (name, hexValue) over every face's chosen/effective color attrs. + Both color maps walk this same nested structure; they differ only in which + of the pair is the key and how each filters.""" if not self.data: - return out + return for data in self.data.get("faces", {}).values(): for block in ("chosenGuiLight", "effectiveGuiLight"): face_data = data.get(block, {}) or {} for attr in ("foreground", "background", "distantForeground"): - name = face_data.get(attr) - hex_value = face_data.get(attr + "Hex") - if name and hex_value: - out[str(name).lower().replace(" ", "")] = hex_value + yield face_data.get(attr), face_data.get(attr + "Hex") + + def _build_color_hex(self) -> dict[str, str]: + out: dict[str, str] = {} + for name, hex_value in self._iter_color_pairs(): + if name and hex_value: + out[str(name).lower().replace(" ", "")] = hex_value return out def _build_color_names(self) -> dict[str, str]: out: dict[str, str] = {} - if not self.data: - return out - for data in self.data.get("faces", {}).values(): - for block in ("chosenGuiLight", "effectiveGuiLight"): - face_data = data.get(block, {}) or {} - for attr in ("foreground", "background", "distantForeground"): - hex_value = face_data.get(attr + "Hex") - name = face_data.get(attr) - if hex_value and name and not str(name).startswith("#"): - out.setdefault(hex_value.lower(), str(name).lower().replace(" ", "-")) + for name, hex_value in self._iter_color_pairs(): + if hex_value and name and not str(name).startswith("#"): + out.setdefault(hex_value.lower(), str(name).lower().replace(" ", "-")) return out -- cgit v1.2.3