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,632 @@
1
+ """Interactive Terminal UI (TUI) for browsing 64 themes and editing dual Powerline separators."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import random
6
+ import shutil
7
+ import sys
8
+
9
+ from synth_shell_theme.core import (
10
+ apply_separators,
11
+ apply_theme,
12
+ backup_config,
13
+ detect_current_separators,
14
+ detect_current_theme,
15
+ list_backups,
16
+ read_current_state,
17
+ restore_backup,
18
+ )
19
+ from synth_shell_theme.paths import get_config_path
20
+ from synth_shell_theme.separators import (
21
+ ALL_PRESETS,
22
+ CATEGORIES,
23
+ CHARACTER_PALETTE,
24
+ find_preset,
25
+ get_separator_key,
26
+ resolve_separator_input,
27
+ )
28
+ from synth_shell_theme.themes import (
29
+ BOLD,
30
+ DIM,
31
+ RESET,
32
+ ansi_bg,
33
+ build_card_lines,
34
+ color_index,
35
+ filter_themes,
36
+ find_theme,
37
+ load_themes,
38
+ pad_to,
39
+ render_prompt_line,
40
+ )
41
+
42
+ GUTTER = " "
43
+
44
+
45
+ def _clear_screen(enabled: bool = True) -> None:
46
+ if enabled and sys.stdout.isatty():
47
+ sys.stdout.write("\033[H\033[2J")
48
+ sys.stdout.flush()
49
+ else:
50
+ print()
51
+
52
+
53
+ def print_side_by_side(cards: list[list[str]], cols: int, col_width: int) -> None:
54
+ """Print rendered theme cards arranged in a multi-column grid."""
55
+ for row_start in range(0, len(cards), cols):
56
+ row_cards = [list(c) for c in cards[row_start : row_start + cols]]
57
+ max_lines = max(len(c) for c in row_cards)
58
+ for c in row_cards:
59
+ while len(c) < max_lines:
60
+ c.append("")
61
+ for line_idx in range(max_lines):
62
+ parts = [pad_to(card[line_idx], col_width) for card in row_cards]
63
+ print(GUTTER.join(parts))
64
+ print()
65
+
66
+
67
+ def print_theme_list(themes: list[dict[str, object]], current_name: str | None) -> None:
68
+ """Print compact numbered list of all 64 themes with 256-color swatches."""
69
+ print()
70
+ print(f"{BOLD} Synth-Shell Prompt Theme Gallery ({len(themes)} themes){RESET}")
71
+ print(f" {DIM}Host · PWD · Git swatches (256-color){RESET}")
72
+ print()
73
+ for i, t in enumerate(themes, 1):
74
+ name = str(t.get("name", "Unknown"))
75
+ badge = str(t.get("badge", ""))
76
+ h_bg = color_index(str(t.get("background_host", "0")))
77
+ p_bg = color_index(str(t.get("background_pwd", "0")))
78
+ g_bg = color_index(str(t.get("background_git", "0")))
79
+ swatch = f"{ansi_bg(h_bg)} {ansi_bg(p_bg)} {ansi_bg(g_bg)} {RESET}"
80
+ badge_str = f" {DIM}[{badge}]{RESET}" if badge else ""
81
+ active = f" \033[33;1m← active{RESET}" if current_name and name == current_name else ""
82
+ print(f" {BOLD}#{i:02d}{RESET} {swatch} {name}{badge_str}{active}")
83
+ print()
84
+
85
+
86
+ def print_character_palette_table() -> None:
87
+ """Print visual cheat-sheet table of 60+ Nerd Font & Unicode separator glyphs."""
88
+ print()
89
+ print(f" {BOLD}╔═════════════════════════════════════════════════════════════════════════════════════════╗{RESET}")
90
+ print(f" {BOLD}║ Nerd Font & Unicode Character Palette (60+ Glyphs) ║{RESET}")
91
+ print(f" {BOLD}╚═════════════════════════════════════════════════════════════════════════════════════════╝{RESET}")
92
+ print()
93
+
94
+ for title, items in CHARACTER_PALETTE.items():
95
+ bar = "─" * max(4, 75 - len(title))
96
+ print(f" {BOLD}\033[36m── {title} ({len(items)} glyphs) {bar}{RESET}")
97
+ for i in range(0, len(items), 4):
98
+ row = items[i : i + 4]
99
+ cells = [
100
+ f" {BOLD}{ch}{RESET} \033[33m\\u{hex_code:<5}\033[0m {DIM}{desc:<11}{RESET}"
101
+ for ch, hex_code, desc in row
102
+ ]
103
+ print(" " + " ".join(cells))
104
+ print()
105
+
106
+ print(
107
+ f" {DIM}Pick any character by its {BOLD}Hex Code{RESET}{DIM} (e.g. E0B4, F0E7), "
108
+ f"{BOLD}Name{RESET}{DIM} (e.g. bubble, lightning), or paste a symbol.{RESET}"
109
+ )
110
+ print()
111
+
112
+
113
+ def _active_preview_theme(themes: list[dict[str, object]] | None = None) -> dict[str, object]:
114
+ """Return active colors from `synth-shell-prompt.config`, falling back to Tokyo Night."""
115
+ catalog = themes if themes is not None else load_themes()
116
+ state = read_current_state(catalog)
117
+ colors = state.get("colors")
118
+ if isinstance(colors, dict) and colors.get("background_host"):
119
+ merged: dict[str, object] = {"name": state.get("active_theme") or "Active Prompt"}
120
+ merged.update(colors)
121
+ return merged
122
+ tokyo, _ = find_theme("tokyo-night", catalog)
123
+ return tokyo if tokyo else catalog[0]
124
+
125
+
126
+ def render_separator_sample(
127
+ internal_sep: str,
128
+ theme: dict[str, object],
129
+ end_sep: str | None = None,
130
+ ) -> str:
131
+ """Render a 3-segment live sample prompt with `internal_sep` and `end_sep`."""
132
+ return render_prompt_line(
133
+ theme,
134
+ [("host", "dev"), ("pwd", "~/workspace/app"), ("git", "main")],
135
+ "git status",
136
+ sep=internal_sep,
137
+ sep_end=end_sep if end_sep else internal_sep,
138
+ )
139
+
140
+
141
+ def print_separator_showcase(
142
+ theme: dict[str, object] | None = None,
143
+ current_glyph: str | None = None,
144
+ ) -> None:
145
+ """Print categorized showcase of all 46 Powerline & Nerd Font separator presets."""
146
+ preview_theme = theme if theme is not None else _active_preview_theme()
147
+ if current_glyph is None:
148
+ (current_glyph, _), _ = detect_current_separators()
149
+
150
+ print()
151
+ print(f"{BOLD} Synth-Shell Powerline Separator Gallery ({len(ALL_PRESETS)} presets){RESET}")
152
+ print(f" {DIM}Live sample previews rendered with your prompt colors:{RESET}")
153
+ print()
154
+
155
+ counter = 1
156
+ for cat_name, items in CATEGORIES.items():
157
+ print(f" {BOLD}\033[36m── {cat_name} ──────────────────────────────────────{RESET}")
158
+ print()
159
+ for key, glyph, code, desc in items:
160
+ active = f" \033[33;1m← active{RESET}" if glyph == current_glyph else ""
161
+ sample = render_separator_sample(glyph, preview_theme)
162
+ print(f" {BOLD}#{counter:02d}{RESET} {glyph} {BOLD}{key:<16}{RESET} ({code}) {desc}{active}")
163
+ print(f" {sample}")
164
+ print()
165
+ counter += 1
166
+
167
+
168
+ def report_theme_applied(
169
+ res: dict[str, object],
170
+ force_white: bool = False,
171
+ keep_input: bool = False,
172
+ ) -> None:
173
+ """Print user-friendly summary and reload instructions after applying a theme."""
174
+ idx = res.get("theme_id")
175
+ idx_str = f" (#{idx})" if idx else ""
176
+ print()
177
+ print(f" Selected: {BOLD}{res.get('theme')}{RESET}{idx_str}")
178
+ if force_white:
179
+ print(f" Mode: {BOLD}High-Contrast White Text{RESET} (segment foregrounds forced to white)")
180
+ if keep_input:
181
+ print(f" Input: {BOLD}Preserved existing font_color_input{RESET}")
182
+ if res.get("backup"):
183
+ print(f" Backup: {res['backup']}")
184
+ print(f" Applied: {res['config_path']}")
185
+ print()
186
+ print(f" {BOLD}Theme applied!{RESET} Reload your current Bash session with:")
187
+ print(f" {BOLD}source ~/.config/synth-shell/synth-shell-prompt.sh{RESET}")
188
+ print()
189
+
190
+
191
+ def report_separators_applied(res: dict[str, object], label: str = "") -> None:
192
+ """Print user-friendly summary after applying internal/ending separators."""
193
+ print()
194
+ print(f" {BOLD}Separators applied!{RESET}")
195
+ if label:
196
+ print(f" Preset: {BOLD}{label}{RESET}")
197
+ internal = res.get("internal")
198
+ if isinstance(internal, dict):
199
+ print(f" Internal: {BOLD}{internal['glyph']}{RESET} ({internal['code']})")
200
+ end = res.get("end")
201
+ if isinstance(end, dict):
202
+ print(f" Ending: {BOLD}{end['glyph']}{RESET} ({end['code']})")
203
+ if res.get("backup"):
204
+ print(f" Backup: {res['backup']}")
205
+ print(f" Config: {res['config_path']}")
206
+ print()
207
+ print(f" Reload your current Bash session with:")
208
+ print(f" {BOLD}source ~/.config/synth-shell/synth-shell-prompt.sh{RESET}")
209
+ print()
210
+
211
+
212
+ def run_separator_tui(
213
+ clear_screen: bool = True,
214
+ return_on_apply: bool = True,
215
+ ) -> str | None:
216
+ """Interactive Dual Separator & 60+ Glyph Palette Editor."""
217
+ status_msg = ""
218
+ while True:
219
+ theme = _active_preview_theme()
220
+ (cur_int_glyph, cur_int_code), end_tuple = detect_current_separators()
221
+ cur_end_glyph = end_tuple[0] if end_tuple else cur_int_glyph
222
+ cur_end_code = end_tuple[1] if end_tuple else cur_int_code
223
+ end_note = f" ({cur_end_code})" if end_tuple else " (same as internal)"
224
+
225
+ _clear_screen(clear_screen)
226
+ print(f"{BOLD} Synth-Shell Powerline Separator Editor{RESET} — {len(ALL_PRESETS)} presets + dual separators")
227
+ print(f" Internal separator: \033[36;1m{cur_int_glyph}\033[0m ({cur_int_code}) [between segments]")
228
+ print(f" Ending separator: \033[33;1m{cur_end_glyph}\033[0m{end_note} [final cap before command]")
229
+ print(f" Live prompt: {render_separator_sample(cur_int_glyph, theme, cur_end_glyph)}")
230
+ print(f" Config: {get_config_path()}")
231
+ print()
232
+
233
+ counter = 1
234
+ for cat_name, items in CATEGORIES.items():
235
+ print(f" \033[36m── {cat_name} ──{RESET}")
236
+ for key, glyph, code, desc in items:
237
+ active = f" \033[33;1m← active{RESET}" if glyph == cur_int_glyph else ""
238
+ sample = render_separator_sample(glyph, theme, cur_end_glyph if end_tuple else glyph)
239
+ print(f" {BOLD}#{counter:02d}{RESET} {glyph} {BOLD}{key:<16}{RESET} {desc}{active}")
240
+ print(f" {sample}")
241
+ counter += 1
242
+ print()
243
+
244
+ if status_msg:
245
+ print(f" {status_msg}")
246
+ print()
247
+ status_msg = ""
248
+
249
+ nav = [
250
+ f"[1-{len(ALL_PRESETS)}|name] apply both",
251
+ "[m]ix dual",
252
+ "[i]nternal only",
253
+ "[e]nding only",
254
+ "[c]ustom 60+ palette",
255
+ "[p <sep>] preview",
256
+ "[r]andom",
257
+ "[q]uit",
258
+ ]
259
+ try:
260
+ choice = input(f" {' | '.join(nav)}: ").strip()
261
+ except (EOFError, KeyboardInterrupt):
262
+ print("\n Cancelled.")
263
+ return None
264
+
265
+ if not choice:
266
+ continue
267
+ cmd = choice.lower()
268
+
269
+ if cmd in ("q", "quit", "exit"):
270
+ return None
271
+ if cmd in ("r", "random"):
272
+ key, glyph, code, desc = random.choice(ALL_PRESETS)
273
+ res = apply_separators(internal=(glyph, code), end=(glyph, code))
274
+ msg = f"Separator set to {key} ({glyph})"
275
+ if return_on_apply:
276
+ report_separators_applied(res, label=f"{key} ({desc})")
277
+ return msg
278
+ status_msg = f"\033[32m{msg}\033[0m"
279
+ continue
280
+
281
+ if cmd in ("m", "mix", "dual"):
282
+ print()
283
+ print(f" {BOLD}Step 1: Internal Separator{RESET} (between Host, PWD, Git, etc.)")
284
+ try:
285
+ raw_int = input(
286
+ f" Pick INTERNAL [name, #id, hex, glyph] (Enter to keep '{cur_int_glyph}'): "
287
+ ).strip()
288
+ except (EOFError, KeyboardInterrupt):
289
+ continue
290
+ int_glyph, int_code, int_label = (
291
+ resolve_separator_input(raw_int) if raw_int else (cur_int_glyph, cur_int_code, "Current")
292
+ )
293
+
294
+ print()
295
+ print(f" {BOLD}Step 2: Ending Separator{RESET} (final transition before typed command)")
296
+ try:
297
+ raw_end = input(
298
+ f" Pick ENDING [e.g. arrow, zap, rocket, flame] (Enter to keep '{cur_end_glyph}'): "
299
+ ).strip()
300
+ except (EOFError, KeyboardInterrupt):
301
+ continue
302
+ end_glyph, end_code, end_label = (
303
+ resolve_separator_input(raw_end) if raw_end else (cur_end_glyph, cur_end_code, "Current")
304
+ )
305
+
306
+ sample = render_separator_sample(int_glyph, theme, end_glyph)
307
+ print()
308
+ print(" Selected Dual Combination:")
309
+ print(f" Internal: {BOLD}{int_glyph}{RESET} ({int_code}) — {int_label}")
310
+ print(f" Ending: {BOLD}{end_glyph}{RESET} ({end_code}) — {end_label}")
311
+ print(f" Preview: {sample}")
312
+ try:
313
+ confirm = input(" Apply this dual separator combination? [Y/n]: ").strip().lower()
314
+ except (EOFError, KeyboardInterrupt):
315
+ continue
316
+ if confirm in ("", "y", "yes"):
317
+ res = apply_separators(internal=(int_glyph, int_code), end=(end_glyph, end_code))
318
+ msg = f"Dual separators set: {int_glyph} + {end_glyph}"
319
+ if return_on_apply:
320
+ report_separators_applied(res, label=f"{int_label} + {end_label}")
321
+ return msg
322
+ status_msg = f"\033[32m{msg}\033[0m"
323
+ else:
324
+ status_msg = "\033[33mDual separator selection cancelled.\033[0m"
325
+ continue
326
+
327
+ if cmd in ("i", "internal") or cmd.startswith("i ") or cmd.startswith("internal "):
328
+ parts = choice.split(None, 1)
329
+ raw = parts[1].strip() if len(parts) > 1 else ""
330
+ if not raw:
331
+ try:
332
+ raw = input(" Pick INTERNAL separator [name, #id, hex, glyph]: ").strip()
333
+ except (EOFError, KeyboardInterrupt):
334
+ continue
335
+ if raw:
336
+ g, c, label = resolve_separator_input(raw)
337
+ res = apply_separators(internal=(g, c))
338
+ msg = f"Internal separator set to {g} ({label})"
339
+ if return_on_apply:
340
+ report_separators_applied(res, label=f"Internal: {label}")
341
+ return msg
342
+ status_msg = f"\033[32m{msg}\033[0m"
343
+ continue
344
+
345
+ if cmd in ("e", "end", "last") or cmd.startswith("e ") or cmd.startswith("end "):
346
+ parts = choice.split(None, 1)
347
+ raw = parts[1].strip() if len(parts) > 1 else ""
348
+ if not raw:
349
+ try:
350
+ raw = input(" Pick ENDING separator [name, #id, hex, glyph]: ").strip()
351
+ except (EOFError, KeyboardInterrupt):
352
+ continue
353
+ if raw:
354
+ g, c, label = resolve_separator_input(raw)
355
+ res = apply_separators(end=(g, c))
356
+ msg = f"Ending separator set to {g} ({label})"
357
+ if return_on_apply:
358
+ report_separators_applied(res, label=f"Ending: {label}")
359
+ return msg
360
+ status_msg = f"\033[32m{msg}\033[0m"
361
+ continue
362
+
363
+ if cmd in ("c", "custom", "palette", "table"):
364
+ _clear_screen(clear_screen)
365
+ print_character_palette_table()
366
+ try:
367
+ raw_char = input(" Pick character [name, hex, or glyph] (Enter to cancel): ").strip()
368
+ except (EOFError, KeyboardInterrupt):
369
+ continue
370
+ if not raw_char:
371
+ continue
372
+ glyph, code, label = resolve_separator_input(raw_char)
373
+ sample = render_separator_sample(glyph, theme, glyph)
374
+ print()
375
+ print(f" Selected: {BOLD}{glyph}{RESET} (Code: {code}, Label: {label})")
376
+ print(f" Preview: {sample}")
377
+ try:
378
+ target = input(" Apply to [b]oth, [i]nternal only, [e]nding only, or [n]o? [B/i/e/n]: ").strip().lower()
379
+ except (EOFError, KeyboardInterrupt):
380
+ continue
381
+ if target in ("", "b", "both", "y", "yes"):
382
+ res = apply_separators(internal=(glyph, code), end=(glyph, code))
383
+ elif target in ("i", "internal"):
384
+ res = apply_separators(internal=(glyph, code))
385
+ elif target in ("e", "end", "ending"):
386
+ res = apply_separators(end=(glyph, code))
387
+ else:
388
+ status_msg = "\033[33mCancelled.\033[0m"
389
+ continue
390
+ msg = f"Applied custom glyph {glyph} ({code})"
391
+ if return_on_apply:
392
+ report_separators_applied(res, label=label)
393
+ return msg
394
+ status_msg = f"\033[32m{msg}\033[0m"
395
+ continue
396
+
397
+ if cmd.startswith("p ") or cmd.startswith("preview "):
398
+ raw_parts = choice.split()[1:]
399
+ if len(raw_parts) >= 2:
400
+ g1, _, _ = resolve_separator_input(raw_parts[0])
401
+ g2, _, _ = resolve_separator_input(raw_parts[1])
402
+ status_msg = f"Dual Preview ({g1} + {g2}): {render_separator_sample(g1, theme, g2)}"
403
+ elif raw_parts:
404
+ g, c, _ = resolve_separator_input(raw_parts[0])
405
+ status_msg = f"Preview for \033[1m{g}\033[0m ({c}): {render_separator_sample(g, theme, g)}"
406
+ continue
407
+
408
+ preset = find_preset(choice)
409
+ if preset:
410
+ key, glyph, code, desc = preset
411
+ res = apply_separators(internal=(glyph, code), end=(glyph, code))
412
+ msg = f"Separator set to {key} ({glyph})"
413
+ if return_on_apply:
414
+ report_separators_applied(res, label=f"{key} ({desc})")
415
+ return msg
416
+ status_msg = f"\033[32m{msg}\033[0m"
417
+ continue
418
+
419
+ g, c, label = resolve_separator_input(choice)
420
+ if label != "Custom" or len(choice) == 1:
421
+ res = apply_separators(internal=(g, c), end=(g, c))
422
+ msg = f"Separator set to {g} ({label})"
423
+ if return_on_apply:
424
+ report_separators_applied(res, label=label)
425
+ return msg
426
+ status_msg = f"\033[32m{msg}\033[0m"
427
+ continue
428
+
429
+ status_msg = (
430
+ f"\033[31mUnknown choice: '{choice}'. Type 1-{len(ALL_PRESETS)}, "
431
+ f"preset name, [m]ix dual, [c]ustom palette, or [q]uit.\033[0m"
432
+ )
433
+
434
+
435
+ def run_theme_tui(
436
+ themes: list[dict[str, object]] | None = None,
437
+ clear_screen_enabled: bool = True,
438
+ initial_filter: str = "",
439
+ force_white: bool = False,
440
+ keep_input: bool = False,
441
+ ) -> None:
442
+ """Unified interactive 2-column TUI for browsing 64 themes, editing dual separators, and launching Web Studio."""
443
+ catalog = themes if themes is not None else load_themes()
444
+ filter_query = initial_filter
445
+ total_all = len(catalog)
446
+ page = 0
447
+ status_msg = ""
448
+
449
+ while True:
450
+ current_name, _ = detect_current_theme(catalog)
451
+ (sep_int, _), end_tuple = detect_current_separators()
452
+ sep_end = end_tuple[0] if end_tuple else sep_int
453
+
454
+ filtered_items = (
455
+ filter_themes(filter_query, catalog)
456
+ if filter_query
457
+ else [(i, t) for i, t in enumerate(catalog, 1)]
458
+ )
459
+ total = len(filtered_items)
460
+
461
+ term_cols = shutil.get_terminal_size((120, 24)).columns
462
+ col_width = 74
463
+ num_cols = 2 if term_cols >= col_width * 2 + len(GUTTER) else 1
464
+ if num_cols == 1:
465
+ col_width = max(56, term_cols - 2)
466
+
467
+ per_page = num_cols * 5
468
+ total_pages = max(1, (total + per_page - 1) // per_page)
469
+ if page >= total_pages:
470
+ page = total_pages - 1
471
+
472
+ _clear_screen(clear_screen_enabled)
473
+
474
+ filter_badge = (
475
+ f" | Filter: \033[36;1m'{filter_query}'\033[0m ({total} matches)"
476
+ if filter_query
477
+ else ""
478
+ )
479
+ sep_badge = f" | Sep: \033[36;1m{sep_int}\033[0m→\033[33;1m{sep_end}\033[0m ({get_separator_key(sep_int)})"
480
+ fw_badge = " | \033[35;1m[White Text ON]\033[0m" if force_white else ""
481
+ ki_badge = " | \033[32;1m[Keep Input ON]\033[0m" if keep_input else ""
482
+
483
+ print(
484
+ f"{BOLD} Synth-Shell Theme Studio{RESET} — {total_all} themes"
485
+ f"{filter_badge}{sep_badge}{fw_badge}{ki_badge}"
486
+ )
487
+ if current_name:
488
+ print(f" Active theme: \033[33;1m{current_name}\033[0m | Config: {get_config_path()}")
489
+ else:
490
+ print(f" Config: {get_config_path()}")
491
+ print()
492
+
493
+ if total == 0:
494
+ print(f" No themes matching '{filter_query}'. Press [c] to clear filter.")
495
+ print()
496
+ else:
497
+ start = page * per_page
498
+ end = min(start + per_page, total)
499
+ cards = [
500
+ build_card_lines(
501
+ t,
502
+ orig_idx,
503
+ current_name,
504
+ sep=sep_int,
505
+ sep_end=sep_end,
506
+ force_white=force_white,
507
+ )
508
+ for orig_idx, t in filtered_items[start:end]
509
+ ]
510
+ print_side_by_side(cards, num_cols, col_width)
511
+
512
+ if status_msg:
513
+ print(f" {status_msg}")
514
+ print()
515
+ status_msg = ""
516
+
517
+ nav = []
518
+ if filter_query:
519
+ nav.append("[c]lear")
520
+ if page > 0:
521
+ nav.append("[p]rev")
522
+ if (page + 1) < total_pages:
523
+ nav.append("[n]ext")
524
+ nav.extend(
525
+ [
526
+ f"[1-{total_all}|name] apply",
527
+ "[s]eparators",
528
+ "[/]search",
529
+ "[f]white-text",
530
+ "[w]eb studio",
531
+ "[u]ndo",
532
+ "[r]andom",
533
+ "[q]uit",
534
+ ]
535
+ )
536
+
537
+ page_info = f" Page {page + 1}/{total_pages}" if total_pages > 1 else " "
538
+ try:
539
+ choice = input(f"{page_info} {' | '.join(nav)}: ").strip()
540
+ except (EOFError, KeyboardInterrupt):
541
+ print("\n Cancelled.")
542
+ return
543
+
544
+ cmd = choice.lower()
545
+ if not cmd:
546
+ continue
547
+ if cmd in ("q", "quit", "exit"):
548
+ print(" Bye.")
549
+ return
550
+ if cmd in ("n", "next"):
551
+ if (page + 1) < total_pages:
552
+ page += 1
553
+ else:
554
+ status_msg = "\033[33mAlready on last page.\033[0m"
555
+ elif cmd in ("p", "prev", "back"):
556
+ if page > 0:
557
+ page -= 1
558
+ else:
559
+ status_msg = "\033[33mAlready on first page.\033[0m"
560
+ elif cmd.startswith("g ") or cmd.startswith("page "):
561
+ part = cmd.split()[-1]
562
+ if part.isdigit() and 1 <= int(part) <= total_pages:
563
+ page = int(part) - 1
564
+ else:
565
+ status_msg = f"\033[31mPage must be between 1 and {total_pages}.\033[0m"
566
+ elif cmd in ("c", "clear", "all", "/clear"):
567
+ filter_query = ""
568
+ page = 0
569
+ elif cmd == "f" or cmd == "white":
570
+ force_white = not force_white
571
+ state_lbl = "enabled" if force_white else "disabled"
572
+ status_msg = f"\033[36mHigh-contrast white segment text {state_lbl}.\033[0m"
573
+ elif cmd == "k" or cmd == "keep-input":
574
+ keep_input = not keep_input
575
+ state_lbl = "enabled" if keep_input else "disabled"
576
+ status_msg = f"\033[36mKeep existing input color {state_lbl}.\033[0m"
577
+ elif cmd in ("b", "backup"):
578
+ bak = backup_config()
579
+ status_msg = (
580
+ f"\033[32mBackup saved: {bak}\033[0m"
581
+ if bak
582
+ else "\033[33mNo config file found to back up yet.\033[0m"
583
+ )
584
+ elif cmd in ("u", "undo", "restore"):
585
+ baks = list_backups()
586
+ if not baks:
587
+ status_msg = "\033[33mNo backups found.\033[0m"
588
+ else:
589
+ restored = restore_backup(1)
590
+ status_msg = (
591
+ f"\033[32mRestored backup: {restored.name}\033[0m"
592
+ if restored
593
+ else "\033[31mRestore failed.\033[0m"
594
+ )
595
+ elif cmd in ("/", "search") or cmd.startswith("/"):
596
+ if cmd in ("/", "search"):
597
+ try:
598
+ term = input(" Search themes (name, slug, or badge): ").strip()
599
+ except (EOFError, KeyboardInterrupt):
600
+ continue
601
+ else:
602
+ term = choice[1:].strip()
603
+ filter_query = term
604
+ page = 0
605
+ elif cmd in ("s", "t", "sep", "separator", "separators"):
606
+ sep_res = run_separator_tui(clear_screen=clear_screen_enabled, return_on_apply=False)
607
+ if sep_res:
608
+ status_msg = f"\033[32m{sep_res}\033[0m"
609
+ elif cmd in ("r", "random"):
610
+ pick_t = random.choice(catalog)
611
+ res = apply_theme(pick_t, force_white=force_white, keep_input=keep_input)
612
+ report_theme_applied(res, force_white=force_white, keep_input=keep_input)
613
+ return
614
+ elif cmd in ("w", "web", "studio"):
615
+ from synth_shell_theme.server import run_studio_server
616
+
617
+ run_studio_server(open_browser=True)
618
+ return
619
+ elif cmd in ("?", "help"):
620
+ status_msg = (
621
+ f"{BOLD}Keys:{RESET} [n]ext, [p]rev, [g N] page, [s]eparator editor, "
622
+ f"[/term] search, [f] white-text, [k] keep-input, [b]ackup, [u]ndo, [w]eb studio, [q]uit"
623
+ )
624
+ else:
625
+ target_theme, _ = find_theme(choice, catalog)
626
+ if target_theme:
627
+ res = apply_theme(target_theme, force_white=force_white, keep_input=keep_input)
628
+ report_theme_applied(res, force_white=force_white, keep_input=keep_input)
629
+ return
630
+ status_msg = (
631
+ f"\033[31mTheme not found: '{choice}'. Enter 1-{total_all}, a theme name, or /search.\033[0m"
632
+ )