Folder support, Custom theme support, Boiler Plate Code support
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
"""Convert themes from convert-themes/registry.json into src/tui/themes/*.json"""
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
REGISTRY_PATH = Path("convert-themes/registry.json")
|
||||
OUTPUT_DIR = Path("src/tui/themes")
|
||||
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if not REGISTRY_PATH.exists():
|
||||
print(f"Error: {REGISTRY_PATH} not found.")
|
||||
exit(1)
|
||||
|
||||
with open(REGISTRY_PATH, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
themes_list = data.get("themes", [])
|
||||
converted_count = 0
|
||||
|
||||
for item in themes_list:
|
||||
name = item.get("name")
|
||||
if not name:
|
||||
continue
|
||||
|
||||
dark = item.get("dark") or item.get("light") or {}
|
||||
if not dark:
|
||||
continue
|
||||
|
||||
theme_id = re.sub(r'[^a-z0-9\-]', '', name.lower().replace(' ', '-'))
|
||||
if not theme_id:
|
||||
continue
|
||||
|
||||
background = dark.get("mSurfaceVariant") or dark.get("mSurface") or "#1e1e1e"
|
||||
surface = dark.get("mSurface") or "#252526"
|
||||
primary = dark.get("mPrimary") or "#3b82f6"
|
||||
primary_text = dark.get("mOnPrimary") or "#ffffff"
|
||||
secondary = dark.get("mSecondary") or "#64748b"
|
||||
accent = dark.get("mTertiary") or dark.get("mHover") or primary
|
||||
folder_header = accent
|
||||
folder_text = dark.get("mOnTertiary") or dark.get("mOnHover") or "#ffffff"
|
||||
|
||||
theme_dict = {
|
||||
"id": theme_id,
|
||||
"name": name,
|
||||
"background": background,
|
||||
"surface": surface,
|
||||
"primary": primary,
|
||||
"primary_text": primary_text,
|
||||
"secondary": secondary,
|
||||
"accent": accent,
|
||||
"folder_header": folder_header,
|
||||
"folder_text": folder_text
|
||||
}
|
||||
|
||||
out_file = OUTPUT_DIR / f"{theme_id}.json"
|
||||
with open(out_file, "w", encoding="utf-8") as f_out:
|
||||
json.dump(theme_dict, f_out, indent=2)
|
||||
converted_count += 1
|
||||
|
||||
print(f"Successfully converted {converted_count} themes to {OUTPUT_DIR}/!")
|
||||
Reference in New Issue
Block a user