synth-shell-theme 1.3.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. synth_shell_theme/__init__.py +7 -0
  2. synth_shell_theme/__main__.py +8 -0
  3. synth_shell_theme/assets/studio.html +1920 -0
  4. synth_shell_theme/cli.py +887 -0
  5. synth_shell_theme/core.py +1695 -0
  6. synth_shell_theme/ecosystem.py +537 -0
  7. synth_shell_theme/patches.py +1853 -0
  8. synth_shell_theme/paths.py +363 -0
  9. synth_shell_theme/separators.py +320 -0
  10. synth_shell_theme/server.py +506 -0
  11. synth_shell_theme/themes/01-screenshot-match.conf +30 -0
  12. synth_shell_theme/themes/02-current-live-theme.conf +30 -0
  13. synth_shell_theme/themes/03-dracula-punch.conf +30 -0
  14. synth_shell_theme/themes/04-nord-ice.conf +30 -0
  15. synth_shell_theme/themes/05-matrix-green.conf +30 -0
  16. synth_shell_theme/themes/06-amber-heat.conf +30 -0
  17. synth_shell_theme/themes/07-cloud-ops.conf +30 -0
  18. synth_shell_theme/themes/08-catppuccin-mauve.conf +30 -0
  19. synth_shell_theme/themes/09-solarized-night.conf +30 -0
  20. synth_shell_theme/themes/10-gruvbox-dark.conf +30 -0
  21. synth_shell_theme/themes/11-monokai-neon.conf +30 -0
  22. synth_shell_theme/themes/12-tokyo-night.conf +30 -0
  23. synth_shell_theme/themes/13-synthwave-pink.conf +30 -0
  24. synth_shell_theme/themes/14-forest-mint.conf +30 -0
  25. synth_shell_theme/themes/15-ruby-steel.conf +30 -0
  26. synth_shell_theme/themes/16-ice-gold.conf +30 -0
  27. synth_shell_theme/themes/17-aqua-slate.conf +30 -0
  28. synth_shell_theme/themes/18-cyber-lime.conf +30 -0
  29. synth_shell_theme/themes/19-lavender-sunset.conf +30 -0
  30. synth_shell_theme/themes/20-minimal-mono.conf +30 -0
  31. synth_shell_theme/themes/21-rose-pine.conf +30 -0
  32. synth_shell_theme/themes/22-kanagawa.conf +30 -0
  33. synth_shell_theme/themes/23-everforest.conf +30 -0
  34. synth_shell_theme/themes/24-one-dark.conf +30 -0
  35. synth_shell_theme/themes/25-ayu-dark.conf +30 -0
  36. synth_shell_theme/themes/26-nightfox.conf +30 -0
  37. synth_shell_theme/themes/27-palenight.conf +30 -0
  38. synth_shell_theme/themes/28-cyberdream.conf +30 -0
  39. synth_shell_theme/themes/29-moonlight.conf +30 -0
  40. synth_shell_theme/themes/30-poimandres.conf +30 -0
  41. synth_shell_theme/themes/31-tokyo-storm.conf +30 -0
  42. synth_shell_theme/themes/32-catppuccin-mocha.conf +30 -0
  43. synth_shell_theme/themes/33-nordic-aurora.conf +30 -0
  44. synth_shell_theme/themes/34-horizon-synth.conf +30 -0
  45. synth_shell_theme/themes/35-gruvbox-material.conf +30 -0
  46. synth_shell_theme/themes/36-oxocarbon.conf +30 -0
  47. synth_shell_theme/themes/37-catppuccin-latte.conf +30 -0
  48. synth_shell_theme/themes/38-tokyo-twilight.conf +30 -0
  49. synth_shell_theme/themes/39-solarized-ocean.conf +30 -0
  50. synth_shell_theme/themes/40-vaporwave-sunset.conf +30 -0
  51. synth_shell_theme/themes/41-deep-abyss.conf +30 -0
  52. synth_shell_theme/themes/42-sakura-blossom.conf +30 -0
  53. synth_shell_theme/themes/43-emerald-forest.conf +30 -0
  54. synth_shell_theme/themes/44-vesper.conf +30 -0
  55. synth_shell_theme/themes/45-cobalt-neon.conf +30 -0
  56. synth_shell_theme/themes/46-desert-dunes.conf +30 -0
  57. synth_shell_theme/themes/47-cyber-samurai.conf +30 -0
  58. synth_shell_theme/themes/48-glacier-mint.conf +30 -0
  59. synth_shell_theme/themes/49-carbon-titanium.conf +30 -0
  60. synth_shell_theme/themes/50-matcha-latte.conf +30 -0
  61. synth_shell_theme/themes/51-volcanic-magma.conf +30 -0
  62. synth_shell_theme/themes/52-catppuccin-frappe.conf +30 -0
  63. synth_shell_theme/themes/53-bioluminescence.conf +30 -0
  64. synth_shell_theme/themes/54-mocha-caramel.conf +30 -0
  65. synth_shell_theme/themes/55-neon-genesis.conf +30 -0
  66. synth_shell_theme/themes/56-midnight-amethyst.conf +30 -0
  67. synth_shell_theme/themes/57-andromeda.conf +30 -0
  68. synth_shell_theme/themes/58-golden-velvet.conf +30 -0
  69. synth_shell_theme/themes/59-miami-vice.conf +30 -0
  70. synth_shell_theme/themes/60-zen-garden.conf +30 -0
  71. synth_shell_theme/themes/61-google-cloud.conf +30 -0
  72. synth_shell_theme/themes/62-github-dark.conf +30 -0
  73. synth_shell_theme/themes/63-cyberpunk-edgerunners.conf +30 -0
  74. synth_shell_theme/themes/64-vscode-dark.conf +30 -0
  75. synth_shell_theme/themes.py +580 -0
  76. synth_shell_theme/tui.py +632 -0
  77. synth_shell_theme-1.3.9.dist-info/METADATA +261 -0
  78. synth_shell_theme-1.3.9.dist-info/RECORD +82 -0
  79. synth_shell_theme-1.3.9.dist-info/WHEEL +5 -0
  80. synth_shell_theme-1.3.9.dist-info/entry_points.txt +3 -0
  81. synth_shell_theme-1.3.9.dist-info/licenses/LICENSE +21 -0
  82. synth_shell_theme-1.3.9.dist-info/top_level.txt +1 -0
@@ -0,0 +1,506 @@
1
+ """Local HTTP Web Studio server for synth-shell-theme (zero external dependencies, v1.1.0)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import socket
7
+ import webbrowser
8
+ from http import HTTPStatus
9
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
10
+ from pathlib import Path
11
+ from urllib.parse import urlparse
12
+
13
+ from synth_shell_theme import __version__
14
+ from synth_shell_theme.core import (
15
+ VALID_FONT_EFFECTS,
16
+ VALID_FORMAT_TOKENS,
17
+ apply_ascii_safe_mode,
18
+ apply_auto_system_theme,
19
+ apply_layout_options,
20
+ apply_separators,
21
+ apply_theme,
22
+ backup_config,
23
+ benchmark_prompt,
24
+ list_backups,
25
+ read_current_state,
26
+ read_greeter_state,
27
+ restore_backup,
28
+ sync_greeter_theme,
29
+ sync_root_config,
30
+ toggle_light_dark_theme,
31
+ )
32
+ from synth_shell_theme.ecosystem import export_starship_toml, sync_ecosystem
33
+ from synth_shell_theme.patches import apply_runtime_patches
34
+ from synth_shell_theme.paths import (
35
+ detect_nerd_fonts,
36
+ detect_terminal_capabilities,
37
+ detect_utf8_locale,
38
+ get_assets_dir,
39
+ get_config_dir,
40
+ )
41
+ from synth_shell_theme.separators import resolve_separator_input, serialize_separators_for_web
42
+ from synth_shell_theme.themes import (
43
+ BOLD,
44
+ DIM,
45
+ RESET,
46
+ find_theme,
47
+ load_themes,
48
+ save_custom_theme,
49
+ serialize_theme_for_web,
50
+ )
51
+
52
+
53
+ def build_bootstrap_payload(config_dir: Path | None = None) -> dict[str, object]:
54
+ """Assemble full initial JSON state for the Web Studio frontend."""
55
+ base = config_dir if config_dir is not None else get_config_dir()
56
+ themes = load_themes(config_dir=base)
57
+ serialized_themes = [serialize_theme_for_web(t, idx) for idx, t in enumerate(themes, 1)]
58
+ nf = detect_nerd_fonts()
59
+ return {
60
+ "version": __version__,
61
+ "themes": serialized_themes,
62
+ "separators": serialize_separators_for_web(),
63
+ "valid_segments": list(VALID_FORMAT_TOKENS),
64
+ "valid_font_effects": list(VALID_FONT_EFFECTS),
65
+ "state": read_current_state(themes, base),
66
+ "greeter": read_greeter_state(base),
67
+ "diagnostics": {
68
+ "locale": detect_utf8_locale(),
69
+ "nerd_fonts": nf,
70
+ "terminal": detect_terminal_capabilities(nf),
71
+ },
72
+ "backups": list_backups(base),
73
+ }
74
+
75
+
76
+ def handle_apply_payload(
77
+ payload: dict[str, object],
78
+ config_dir: Path | None = None,
79
+ ) -> dict[str, object]:
80
+ """Apply theme, dual separators, layout, truncation, speed, and sync options atomically."""
81
+ base = config_dir if config_dir is not None else get_config_dir()
82
+ themes = load_themes()
83
+ bak = backup_config(base)
84
+ applied: list[str] = []
85
+ chosen_theme: dict[str, object] | None = None
86
+
87
+ if "theme" in payload and payload["theme"] not in (None, ""):
88
+ query = payload["theme"]
89
+ theme, _ = find_theme(query, themes) # type: ignore[arg-type]
90
+ if not theme:
91
+ raise ValueError(f"Theme not found: {query}")
92
+ chosen_theme = theme
93
+ force_white = bool(payload.get("force_white", False))
94
+ keep_input = bool(payload.get("keep_input", False))
95
+ res_t = apply_theme(
96
+ theme,
97
+ force_white=force_white,
98
+ keep_input=keep_input,
99
+ create_backup=False,
100
+ config_dir=base,
101
+ )
102
+ applied.append(f"Theme: {res_t['theme']}")
103
+
104
+ if payload.get("ascii_safe"):
105
+ apply_ascii_safe_mode(create_backup=False, config_dir=base)
106
+ applied.append("ASCII-Safe Mode")
107
+ else:
108
+ int_raw = payload.get("internal_separator")
109
+ end_raw = payload.get("end_separator")
110
+ int_tuple: tuple[str, str] | None = None
111
+ end_tuple: tuple[str, str] | None = None
112
+ if isinstance(int_raw, str) and int_raw.strip():
113
+ g, c, _ = resolve_separator_input(int_raw.strip())
114
+ int_tuple = (g, c)
115
+ if isinstance(end_raw, str) and end_raw.strip():
116
+ g, c, _ = resolve_separator_input(end_raw.strip())
117
+ end_tuple = (g, c)
118
+ if int_tuple is not None or end_tuple is not None:
119
+ apply_separators(
120
+ internal=int_tuple,
121
+ end=end_tuple,
122
+ create_backup=False,
123
+ config_dir=base,
124
+ )
125
+ applied.append("Separators updated")
126
+
127
+ layout_keys = (
128
+ "format",
129
+ "right_format",
130
+ "right_fill_char",
131
+ "enable_osc133",
132
+ "enable_osc7",
133
+ "enable_terminal_sanitize",
134
+ "kube_show_namespace",
135
+ "kube_prod_warning",
136
+ "kube_prod_pattern",
137
+ "git_dynamic_color",
138
+ "ssh_host_color",
139
+ "pwd_style",
140
+ "notify_duration_sec",
141
+ "custom_segment_text",
142
+ "git_show_state",
143
+ "battery_threshold",
144
+ "enable_command_on_new_line",
145
+ "enable_vertical_padding",
146
+ "max_pwd_char",
147
+ "max_git_char",
148
+ "max_pyenv_char",
149
+ "max_kube_char",
150
+ "compact_width",
151
+ "git_show_counts",
152
+ "transient_prompt",
153
+ "light_theme",
154
+ "dark_theme",
155
+ "prompt_prefix",
156
+ "font_effect",
157
+ "enable_terminal_title",
158
+ "git_skip_untracked_on_slow_fs",
159
+ "git_timeout_ms",
160
+ "git_async_cache",
161
+ "min_duration_ms",
162
+ )
163
+ if any(k in payload for k in layout_keys):
164
+ fmt_raw = payload.get("format")
165
+ if isinstance(fmt_raw, list):
166
+ fmt_str: str | None = " ".join(str(x) for x in fmt_raw)
167
+ elif isinstance(fmt_raw, str):
168
+ fmt_str = fmt_raw
169
+ else:
170
+ fmt_str = None
171
+
172
+ rfmt_raw = payload.get("right_format")
173
+ if isinstance(rfmt_raw, list):
174
+ rfmt_str: str | None = " ".join(str(x) for x in rfmt_raw)
175
+ elif isinstance(rfmt_raw, str):
176
+ rfmt_str = rfmt_raw
177
+ else:
178
+ rfmt_str = None
179
+
180
+ apply_layout_options(
181
+ format_str=fmt_str,
182
+ right_format_str=rfmt_str,
183
+ right_fill_char=str(payload["right_fill_char"]) if "right_fill_char" in payload else None,
184
+ enable_osc133=bool(payload["enable_osc133"]) if "enable_osc133" in payload else None,
185
+ enable_osc7=bool(payload["enable_osc7"]) if "enable_osc7" in payload else None,
186
+ enable_terminal_sanitize=(
187
+ bool(payload["enable_terminal_sanitize"]) if "enable_terminal_sanitize" in payload else None
188
+ ),
189
+ kube_show_namespace=bool(payload["kube_show_namespace"]) if "kube_show_namespace" in payload else None,
190
+ kube_prod_warning=bool(payload["kube_prod_warning"]) if "kube_prod_warning" in payload else None,
191
+ kube_prod_pattern=str(payload["kube_prod_pattern"]) if "kube_prod_pattern" in payload else None,
192
+ git_dynamic_color=bool(payload["git_dynamic_color"]) if "git_dynamic_color" in payload else None,
193
+ ssh_host_color=bool(payload["ssh_host_color"]) if "ssh_host_color" in payload else None,
194
+ pwd_style=str(payload["pwd_style"]) if "pwd_style" in payload else None,
195
+ notify_duration_sec=int(payload["notify_duration_sec"]) if "notify_duration_sec" in payload else None, # type: ignore[arg-type]
196
+ custom_segment_text=str(payload["custom_segment_text"]) if "custom_segment_text" in payload else None,
197
+ git_show_state=bool(payload["git_show_state"]) if "git_show_state" in payload else None,
198
+ battery_threshold=int(payload["battery_threshold"]) if "battery_threshold" in payload else None, # type: ignore[arg-type]
199
+ new_line=bool(payload["enable_command_on_new_line"]) if "enable_command_on_new_line" in payload else None,
200
+ vertical_padding=bool(payload["enable_vertical_padding"]) if "enable_vertical_padding" in payload else None,
201
+ max_pwd_char=int(payload["max_pwd_char"]) if "max_pwd_char" in payload else None, # type: ignore[arg-type]
202
+ max_git_char=int(payload["max_git_char"]) if "max_git_char" in payload else None, # type: ignore[arg-type]
203
+ max_pyenv_char=int(payload["max_pyenv_char"]) if "max_pyenv_char" in payload else None, # type: ignore[arg-type]
204
+ max_kube_char=int(payload["max_kube_char"]) if "max_kube_char" in payload else None, # type: ignore[arg-type]
205
+ compact_width=int(payload["compact_width"]) if "compact_width" in payload else None, # type: ignore[arg-type]
206
+ git_show_counts=bool(payload["git_show_counts"]) if "git_show_counts" in payload else None,
207
+ transient_prompt=bool(payload["transient_prompt"]) if "transient_prompt" in payload else None,
208
+ light_theme=str(payload["light_theme"]) if "light_theme" in payload else None,
209
+ dark_theme=str(payload["dark_theme"]) if "dark_theme" in payload else None,
210
+ prompt_prefix=str(payload["prompt_prefix"]) if "prompt_prefix" in payload else None,
211
+ font_effect=str(payload["font_effect"]) if "font_effect" in payload else None,
212
+ enable_terminal_title=bool(payload["enable_terminal_title"]) if "enable_terminal_title" in payload else None,
213
+ git_skip_untracked_on_slow_fs=(
214
+ bool(payload["git_skip_untracked_on_slow_fs"]) if "git_skip_untracked_on_slow_fs" in payload else None
215
+ ),
216
+ git_timeout_ms=int(payload["git_timeout_ms"]) if "git_timeout_ms" in payload else None, # type: ignore[arg-type]
217
+ git_async_cache=bool(payload["git_async_cache"]) if "git_async_cache" in payload else None,
218
+ min_duration_ms=int(payload["min_duration_ms"]) if "min_duration_ms" in payload else None, # type: ignore[arg-type]
219
+ create_backup=False,
220
+ config_dir=base,
221
+ )
222
+ applied.append("Layout & performance options updated")
223
+
224
+ if payload.get("sync_root"):
225
+ sync_root_config(theme=chosen_theme, config_dir=base)
226
+ applied.append("Root config synced")
227
+
228
+ if payload.get("sync_greeter"):
229
+ sync_greeter_theme(theme=chosen_theme, config_dir=base)
230
+ applied.append("Greeter palette synced")
231
+
232
+ return {
233
+ "ok": True,
234
+ "applied": applied,
235
+ "backup": str(bak) if bak else None,
236
+ "state": read_current_state(themes, base),
237
+ "greeter": read_greeter_state(base),
238
+ "backups": list_backups(base),
239
+ }
240
+
241
+
242
+ def create_studio_server(
243
+ host: str = "127.0.0.1",
244
+ port: int = 7778,
245
+ config_dir: Path | None = None,
246
+ ) -> ThreadingHTTPServer:
247
+ """Create a configured `ThreadingHTTPServer` serving the Synth-Shell Web Studio."""
248
+ studio_html_path = get_assets_dir() / "studio.html"
249
+
250
+ class StudioHandler(BaseHTTPRequestHandler):
251
+ def log_message(self, fmt: str, *args: object) -> None:
252
+ return
253
+
254
+ def _send_json(self, data: dict[str, object], status: int = HTTPStatus.OK) -> None:
255
+ body = json.dumps(data, ensure_ascii=False).encode("utf-8")
256
+ self.send_response(status)
257
+ self.send_header("Content-Type", "application/json; charset=utf-8")
258
+ self.send_header("Content-Length", str(len(body)))
259
+ self.send_header("Cache-Control", "no-store")
260
+ self.end_headers()
261
+ self.wfile.write(body)
262
+
263
+ def _read_json_body(self) -> dict[str, object]:
264
+ length = int(self.headers.get("Content-Length", "0") or "0")
265
+ if length <= 0:
266
+ return {}
267
+ raw = self.rfile.read(length).decode("utf-8", errors="replace")
268
+ parsed = json.loads(raw) if raw.strip() else {}
269
+ if not isinstance(parsed, dict):
270
+ raise ValueError("Expected a JSON object body.")
271
+ return parsed
272
+
273
+ def do_GET(self) -> None: # noqa: N802
274
+ route = urlparse(self.path).path
275
+ if route in ("/", "/index.html"):
276
+ if not studio_html_path.is_file():
277
+ self._send_json({"ok": False, "error": "studio.html asset missing"}, HTTPStatus.NOT_FOUND)
278
+ return
279
+ html_bytes = studio_html_path.read_bytes()
280
+ self.send_response(HTTPStatus.OK)
281
+ self.send_header("Content-Type", "text/html; charset=utf-8")
282
+ self.send_header("Content-Length", str(len(html_bytes)))
283
+ self.send_header("Cache-Control", "no-store")
284
+ self.end_headers()
285
+ self.wfile.write(html_bytes)
286
+ return
287
+
288
+ if route == "/api/bootstrap":
289
+ self._send_json(build_bootstrap_payload(config_dir))
290
+ return
291
+
292
+ if route == "/api/health":
293
+ self._send_json({"ok": True, "version": __version__})
294
+ return
295
+
296
+ self._send_json({"ok": False, "error": f"Unknown endpoint: {route}"}, HTTPStatus.NOT_FOUND)
297
+
298
+ def do_POST(self) -> None: # noqa: N802
299
+ route = urlparse(self.path).path
300
+ try:
301
+ body = self._read_json_body()
302
+ if route == "/api/apply":
303
+ result = handle_apply_payload(body, config_dir)
304
+ self._send_json(result)
305
+ return
306
+ if route == "/api/patches":
307
+ tune = bool(body.get("tune_defaults", False))
308
+ patch_res = apply_runtime_patches(config_dir=config_dir, tune_defaults=tune)
309
+ themes = load_themes()
310
+ self._send_json(
311
+ {
312
+ "ok": True,
313
+ "changes": patch_res["changes"],
314
+ "state": read_current_state(themes, config_dir),
315
+ "greeter": read_greeter_state(config_dir),
316
+ "backups": list_backups(config_dir),
317
+ }
318
+ )
319
+ return
320
+ if route == "/api/ascii-safe":
321
+ sep = str(body.get("separator", ">"))
322
+ res_a = apply_ascii_safe_mode(separator=sep, config_dir=config_dir)
323
+ themes = load_themes()
324
+ self._send_json(
325
+ {
326
+ "ok": True,
327
+ "result": res_a,
328
+ "state": read_current_state(themes, config_dir),
329
+ "backups": list_backups(config_dir),
330
+ }
331
+ )
332
+ return
333
+ if route == "/api/sync-root":
334
+ accent = str(body.get("root_accent", "196"))
335
+ res_r = sync_root_config(root_accent=accent, config_dir=config_dir)
336
+ themes = load_themes()
337
+ self._send_json(
338
+ {
339
+ "ok": True,
340
+ "result": res_r,
341
+ "state": read_current_state(themes, config_dir),
342
+ "backups": list_backups(config_dir),
343
+ }
344
+ )
345
+ return
346
+ if route == "/api/greeter":
347
+ mons_raw = body.get("monitors")
348
+ mons = [str(x) for x in mons_raw] if isinstance(mons_raw, list) else None
349
+ hide_swap = bool(body.get("hide_swap_if_unavailable", False))
350
+ res_g = sync_greeter_theme(
351
+ monitors=mons,
352
+ hide_swap_if_unavailable=hide_swap,
353
+ config_dir=config_dir,
354
+ )
355
+ themes = load_themes(config_dir=config_dir)
356
+ self._send_json(
357
+ {
358
+ "ok": True,
359
+ "result": res_g,
360
+ "state": read_current_state(themes, config_dir),
361
+ "greeter": read_greeter_state(config_dir),
362
+ "backups": list_backups(config_dir),
363
+ }
364
+ )
365
+ return
366
+ if route == "/api/custom-theme":
367
+ name = str(body.get("name", "")).strip()
368
+ colors_raw = body.get("colors", {})
369
+ if not isinstance(colors_raw, dict):
370
+ raise ValueError("Expected 'colors' object.")
371
+ clean_colors = {str(k): str(v) for k, v in colors_raw.items()}
372
+ saved = save_custom_theme(
373
+ name=name,
374
+ colors=clean_colors,
375
+ description=str(body.get("description", "")),
376
+ badge=str(body.get("badge", "Custom")),
377
+ config_dir=config_dir,
378
+ )
379
+ if body.get("apply", True):
380
+ apply_theme(saved, config_dir=config_dir)
381
+ themes = load_themes(config_dir=config_dir)
382
+ serialized_themes = [serialize_theme_for_web(t, idx) for idx, t in enumerate(themes, 1)]
383
+ self._send_json(
384
+ {
385
+ "ok": True,
386
+ "saved_theme": saved["name"],
387
+ "themes": serialized_themes,
388
+ "state": read_current_state(themes, config_dir),
389
+ "backups": list_backups(config_dir),
390
+ }
391
+ )
392
+ return
393
+ if route == "/api/toggle-theme":
394
+ res_t = toggle_light_dark_theme(
395
+ light_slug=str(body["light_theme"]) if body.get("light_theme") else None,
396
+ dark_slug=str(body["dark_theme"]) if body.get("dark_theme") else None,
397
+ config_dir=config_dir,
398
+ )
399
+ themes = load_themes(config_dir=config_dir)
400
+ self._send_json(
401
+ {
402
+ "ok": True,
403
+ "result": res_t,
404
+ "state": read_current_state(themes, config_dir),
405
+ "backups": list_backups(config_dir),
406
+ }
407
+ )
408
+ return
409
+ if route == "/api/bench":
410
+ runs = int(body.get("iterations", 12)) # type: ignore[arg-type]
411
+ self._send_json(benchmark_prompt(iterations=runs, config_dir=config_dir))
412
+ return
413
+ if route == "/api/sync-ecosystem":
414
+ res_e = sync_ecosystem(config_dir=config_dir)
415
+ themes = load_themes(config_dir=config_dir)
416
+ self._send_json(
417
+ {
418
+ "ok": True,
419
+ "result": res_e,
420
+ "state": read_current_state(themes, config_dir),
421
+ }
422
+ )
423
+ return
424
+ if route == "/api/auto-theme":
425
+ res_at = apply_auto_system_theme(config_dir=config_dir)
426
+ themes = load_themes(config_dir=config_dir)
427
+ self._send_json(
428
+ {
429
+ "ok": True,
430
+ "result": res_at,
431
+ "state": read_current_state(themes, config_dir),
432
+ "backups": list_backups(config_dir),
433
+ }
434
+ )
435
+ return
436
+ if route == "/api/export-starship":
437
+ dest_str = str(body.get("output") or "").strip()
438
+ dest_p = Path(dest_str) if dest_str else (config_dir or Path.home() / ".config") / "starship.toml"
439
+ res_st = export_starship_toml(dest_p, config_dir=config_dir)
440
+ self._send_json({"ok": True, "result": res_st})
441
+ return
442
+ if route == "/api/restore":
443
+ target = body.get("target", 1)
444
+ restored = restore_backup(target, config_dir=config_dir) # type: ignore[arg-type]
445
+ if not restored:
446
+ self._send_json({"ok": False, "error": "Backup not found."}, HTTPStatus.NOT_FOUND)
447
+ return
448
+ themes = load_themes()
449
+ self._send_json(
450
+ {
451
+ "ok": True,
452
+ "restored": restored.name,
453
+ "state": read_current_state(themes, config_dir),
454
+ "backups": list_backups(config_dir),
455
+ }
456
+ )
457
+ return
458
+ self._send_json({"ok": False, "error": f"Unknown endpoint: {route}"}, HTTPStatus.NOT_FOUND)
459
+ except Exception as exc:
460
+ self._send_json({"ok": False, "error": str(exc)}, HTTPStatus.BAD_REQUEST)
461
+
462
+ return ThreadingHTTPServer((host, port), StudioHandler)
463
+
464
+
465
+ def _find_available_port(host: str, preferred_port: int, attempts: int = 15) -> int:
466
+ for candidate in range(preferred_port, preferred_port + attempts):
467
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
468
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
469
+ try:
470
+ sock.bind((host, candidate))
471
+ return candidate
472
+ except OSError:
473
+ continue
474
+ return 0
475
+
476
+
477
+ def run_studio_server(
478
+ host: str = "127.0.0.1",
479
+ port: int = 7778,
480
+ open_browser: bool = True,
481
+ config_dir: Path | None = None,
482
+ ) -> None:
483
+ """Start the local Web Studio server and open it in the user's browser."""
484
+ actual_port = _find_available_port(host, port)
485
+ server = create_studio_server(host=host, port=actual_port, config_dir=config_dir)
486
+ bound_port = server.server_address[1]
487
+ url = f"http://{host}:{bound_port}"
488
+
489
+ print()
490
+ print(f" {BOLD}Synth-Shell Theme Web Studio{RESET} v{__version__}")
491
+ print(f" Live URL: \033[36;1m{url}\033[0m")
492
+ print(f" {DIM}Press Ctrl+C to stop the server.{RESET}")
493
+ print()
494
+
495
+ if open_browser:
496
+ try:
497
+ webbrowser.open(url)
498
+ except Exception:
499
+ pass
500
+
501
+ try:
502
+ server.serve_forever()
503
+ except KeyboardInterrupt:
504
+ print("\n Stopping Web Studio server. Bye!")
505
+ finally:
506
+ server.server_close()
@@ -0,0 +1,30 @@
1
+ # Theme 1: Screenshot Match
2
+ # swatch256: 141 255 238
3
+ # badge: Signature
4
+ # description: Amethyst purple host, crisp white working directory, and warm amber input accent.
5
+ format="HOST PWD GIT PYENV TF KUBE"
6
+ separator_char="\uE0B4"
7
+ separator_char_end="\uE0B0"
8
+ enable_vertical_padding=true
9
+ enable_command_on_new_line=true
10
+
11
+ font_color_host="black"
12
+ background_host="141"
13
+
14
+ font_color_pwd="black"
15
+ background_pwd="255"
16
+
17
+ font_color_git="light-gray"
18
+ background_git="238"
19
+
20
+ font_color_pyenv="white"
21
+ background_pyenv="63"
22
+
23
+ font_color_tf="black"
24
+ background_tf="228"
25
+
26
+ font_color_kube="black"
27
+ background_kube="135"
28
+
29
+ font_color_input="214"
30
+ background_input="none"
@@ -0,0 +1,30 @@
1
+ # Theme 2: Current Live Theme
2
+ # swatch256: 69 15 240
3
+ # badge: Classic
4
+ # description: Classic sky-blue host with clean white working directory and charcoal Git segment.
5
+ format="HOST PWD GIT PYENV TF KUBE"
6
+ separator_char="\uE0B4"
7
+ separator_char_end="\uE0B0"
8
+ enable_vertical_padding=true
9
+ enable_command_on_new_line=true
10
+
11
+ font_color_host="white"
12
+ background_host="light-blue"
13
+
14
+ font_color_pwd="black"
15
+ background_pwd="white"
16
+
17
+ font_color_git="black"
18
+ background_git="dark-gray"
19
+
20
+ font_color_pyenv="white"
21
+ background_pyenv="blue"
22
+
23
+ font_color_tf="black"
24
+ background_tf="light-purple"
25
+
26
+ font_color_kube="white"
27
+ background_kube="purple"
28
+
29
+ font_color_input="45"
30
+ background_input="none"
@@ -0,0 +1,30 @@
1
+ # Theme 3: Dracula Punch
2
+ # swatch256: 141 60 84
3
+ # badge: Vampire
4
+ # description: Iconic Dracula purple and pink palette with high-contrast spring green git.
5
+ format="HOST PWD GIT PYENV TF KUBE"
6
+ separator_char="\uE0B4"
7
+ separator_char_end="\uE0B0"
8
+ enable_vertical_padding=true
9
+ enable_command_on_new_line=true
10
+
11
+ font_color_host="black"
12
+ background_host="141"
13
+
14
+ font_color_pwd="white"
15
+ background_pwd="60"
16
+
17
+ font_color_git="black"
18
+ background_git="84"
19
+
20
+ font_color_pyenv="black"
21
+ background_pyenv="117"
22
+
23
+ font_color_tf="black"
24
+ background_tf="228"
25
+
26
+ font_color_kube="black"
27
+ background_kube="205"
28
+
29
+ font_color_input="201"
30
+ background_input="none"
@@ -0,0 +1,30 @@
1
+ # Theme 4: Nord Ice
2
+ # swatch256: 117 153 60
3
+ # badge: Cool
4
+ # description: Steel blue and soft cyan tones with arctic serenity.
5
+ format="HOST PWD GIT PYENV TF KUBE"
6
+ separator_char="\uE0B4"
7
+ separator_char_end="\uE0B0"
8
+ enable_vertical_padding=true
9
+ enable_command_on_new_line=true
10
+
11
+ font_color_host="black"
12
+ background_host="117"
13
+
14
+ font_color_pwd="black"
15
+ background_pwd="153"
16
+
17
+ font_color_git="white"
18
+ background_git="60"
19
+
20
+ font_color_pyenv="black"
21
+ background_pyenv="151"
22
+
23
+ font_color_tf="black"
24
+ background_tf="187"
25
+
26
+ font_color_kube="black"
27
+ background_kube="110"
28
+
29
+ font_color_input="111"
30
+ background_input="none"
@@ -0,0 +1,30 @@
1
+ # Theme 5: Matrix Green
2
+ # swatch256: 119 71 148
3
+ # badge: Retro
4
+ # description: Green-forward prompt with classic hacker terminal energy.
5
+ format="HOST PWD GIT PYENV TF KUBE"
6
+ separator_char="\uE0B4"
7
+ separator_char_end="\uE0B0"
8
+ enable_vertical_padding=true
9
+ enable_command_on_new_line=true
10
+
11
+ font_color_host="black"
12
+ background_host="119"
13
+
14
+ font_color_pwd="black"
15
+ background_pwd="71"
16
+
17
+ font_color_git="black"
18
+ background_git="148"
19
+
20
+ font_color_pyenv="black"
21
+ background_pyenv="120"
22
+
23
+ font_color_tf="black"
24
+ background_tf="190"
25
+
26
+ font_color_kube="black"
27
+ background_kube="80"
28
+
29
+ font_color_input="82"
30
+ background_input="none"