From 2d8047ccf453b1248f9e9ba25d53f5f49d7a9c97 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 13 Jun 2026 15:05:27 -0500 Subject: Extract theme studio default face adapter --- scripts/theme-studio/generate.py | 96 +++++++--------------------------------- 1 file changed, 15 insertions(+), 81 deletions(-) (limited to 'scripts/theme-studio/generate.py') diff --git a/scripts/theme-studio/generate.py b/scripts/theme-studio/generate.py index e98d0bf3..be526242 100644 --- a/scripts/theme-studio/generate.py +++ b/scripts/theme-studio/generate.py @@ -1,4 +1,5 @@ import json, os, re +from default_faces import DefaultFaces HERE=os.path.dirname(os.path.abspath(__file__)) def strip_exports(src): @@ -39,15 +40,7 @@ exec(src[:src.index('cols=')], ns) SAMPLES={"Elisp":ns['ELS'],"Go":ns['GOS'],"Python":ns['PYS'],"TypeScript":ns['TSS'],"Java":ns['JAS'],"C":ns['CS'],"C++":ns['CPS'],"Shell":ns['SHS']} COLS=ns['COLS'] DEFAULT_FACES_PATH=os.path.join(HERE,'emacs-default-faces.json') -DEFAULT_FACES=json.load(open(DEFAULT_FACES_PATH)) if os.path.exists(DEFAULT_FACES_PATH) else None -DEFAULT_COLOR_HEX={} -if DEFAULT_FACES: - for _data in DEFAULT_FACES.get('faces',{}).values(): - for _block in ('chosenGuiLight','effectiveGuiLight'): - _d=_data.get(_block,{}) or {} - for _attr in ('foreground','background','distantForeground'): - if _d.get(_attr) and _d.get(_attr+'Hex'): - DEFAULT_COLOR_HEX[str(_d[_attr]).lower().replace(' ','')]=_d[_attr+'Hex'] +DEFAULTS=DefaultFaces.from_path(DEFAULT_FACES_PATH) MAP={k:'' for k in COLS}; MAP['bg']='#000000'; MAP['p']='#ffffff' BOLD={k:False for k in COLS} ITALIC_MAP={k:False for k in COLS} @@ -58,75 +51,16 @@ def normalize_palette(palette): return [[p[0], p[1] if len(p) > 1 else 'color', p[2] if len(p) > 2 else column_id(p[1] if len(p) > 1 else 'color')] for p in palette] -def default_face(face, effective=True): - if not DEFAULT_FACES: return {} - data=DEFAULT_FACES.get('faces',{}).get(face,{}) - return data.get('effectiveGuiLight' if effective else 'chosenGuiLight',{}) or {} - -def default_color(face, attr='foreground', effective=True): - d=default_face(face,effective) - return d.get(attr+'Hex') or d.get(attr) - -def emacs_box_to_theme(box): - if not box: return None - if isinstance(box,dict): return box - if not isinstance(box,list): return None - vals={} - i=0 - while i+1 seeds the tool's starting # palette / assignments / bold / italic / UI from a theme.json (path relative to @@ -177,7 +111,7 @@ if _seed: for _k,_v in _d['ui'].items(): UIMAP[_k]=_v if 'locks' in _d: LOCKS=_d['locks'] PALETTE=normalize_palette(PALETTE) -if not DEFAULT_FACES: +if not DEFAULTS.available: # These faces carry a fixed style in Emacs's built-in definitions. Fallback # only; normal generation uses emacs-default-faces.json above. UIMAP["link"]["underline"]=True @@ -516,10 +450,10 @@ if os.path.exists(_inv_path): APPS[_pkg]={"label":_pkg,"preview":"generic","faces":[ [f,(f[len(_pkg)+1:] if f.startswith(_pkg+"-") else f).replace("-face","").replace("-"," "),{}] for f in _INV[_pkg]]} -if DEFAULT_FACES: +if DEFAULTS.available: for _app in APPS.values(): for _row in _app["faces"]: - _row[2]=face_seed(_row[0],False) + _row[2]=DEFAULTS.seed(_row[0],False) # Apply seed theme package overrides when THEME_STUDIO_SEED is set: each full # per-face spec (color + structure) replaces the hardcoded face seed before render. if _seed and _d.get('packages'): @@ -531,7 +465,7 @@ if _seed and _d.get('packages'): def add_palette_color(value, label=None): if not value: return if any((p[0] or '').lower()==str(value).lower() for p in PALETTE): return - name=label or color_label(value,'color-'+str(len(PALETTE))) + name=label or DEFAULTS.label(value,'color-'+str(len(PALETTE))) base=name n=2 used={p[1].lower() for p in PALETTE} @@ -539,7 +473,7 @@ def add_palette_color(value, label=None): name=base+'-'+str(n); n+=1 PALETTE.append([value,name,column_id(name)]) -if DEFAULT_FACES: +if DEFAULTS.available: for _k,_v in MAP.items(): add_palette_color(_v, 'bg' if _k=='bg' else 'fg' if _k=='p' else None) for _face,_spec in UIMAP.items(): -- cgit v1.2.3