from __future__ import annotations """Export BeeOS themes into firmware-friendly C and JSON assets.""" import argparse import json from pathlib import Path def hex_to_int(value: str) -> int: value = value.strip().lstrip("#") return int(value, 16) def load_themes(project_root: Path) -> list[dict]: path = project_root / "beeos" / "data" / "themes.json" data = json.loads(path.read_text(encoding="utf-8")) return list(data.get("themes", [])) def export_themes(project_root: Path) -> dict: themes = load_themes(project_root) out_dir = project_root / "beeos" / "generated" / "themes" out_dir.mkdir(parents=True, exist_ok=True) json_out = out_dir / "beeos_themes.json" json_out.write_text(json.dumps({"themes": themes}, indent=2), encoding="utf-8") header = out_dir / "beeos_themes.h" source = out_dir / "beeos_themes.c" header_lines = [ "/* Auto-generated BeeOS theme declarations. */", "#pragma once", "", "#include ", "", "typedef struct BeeOSTheme {", " const char *id;", " const char *name;", " uint32_t accent;", " uint32_t background;", " uint32_t card;", " uint32_t text;", " uint32_t muted;", "} BeeOSTheme;", "", "extern const BeeOSTheme beeos_themes[];", "extern const uint32_t beeos_themes_count;", "", ] source_lines = [ "/* Auto-generated BeeOS theme table. */", "", '#include "beeos_themes.h"', "", "const BeeOSTheme beeos_themes[] = {", ] for theme in themes: source_lines.append( ' {"%s", "%s", 0x%06x, 0x%06x, 0x%06x, 0x%06x, 0x%06x},' % ( theme["id"], theme["name"], hex_to_int(theme["accent"]), hex_to_int(theme["background"]), hex_to_int(theme["card"]), hex_to_int(theme["text"]), hex_to_int(theme["muted"]), ) ) source_lines.append("};") source_lines.append("") source_lines.append(f"const uint32_t beeos_themes_count = {len(themes)};") source_lines.append("") header.write_text("\\n".join(header_lines), encoding="utf-8") source.write_text("\\n".join(source_lines), encoding="utf-8") index = { "theme_count": len(themes), "outputs": { "json": str(json_out.relative_to(project_root)), "header": str(header.relative_to(project_root)), "source": str(source.relative_to(project_root)), }, } index_out = out_dir / "theme_build_index.json" index_out.write_text(json.dumps(index, indent=2), encoding="utf-8") return index def main() -> None: parser = argparse.ArgumentParser(description="Export BeeOS themes into firmware-friendly assets.") parser.add_argument("--project-root", default=".", help="BeeOS project root") args = parser.parse_args() result = export_themes(Path(args.project_root).resolve()) print("BeeOS theme export complete.") print(f"Themes: {result['theme_count']}") for key, value in result["outputs"].items(): print(f" {key}: {value}") if __name__ == "__main__": main()