Skip to content

TUI theme switcher — Delphi-side, modal picker with live preview - #123

Merged
FMXExpress merged 1 commit into
mainfrom
claude/tui-themes
Jun 1, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/tui-themes

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Adds a theme switcher to the Delphi build of pasclaw tui. --theme <name> picks the initial theme; typing /theme in the TUI opens a modal menu with Up/Down live-preview, Enter to apply, Escape to revert. Seven themes from the vendored DMVCFramework: navy (default), matrix, sunset, ocean, midnight, classic, default. Unknown names fall back to navy. Session-only (no persistence — pass --theme next time, or wire a config field in a follow-up).

FPC branch deliberately untouched.

What's new

  • CLI flag — pasclaw tui --theme matrix sets the initial theme.
  • Slash command — /theme opens the modal picker.
  • Live preview — arrowing through themes calls SetConsoleTheme immediately, so you see chrome change as you navigate. Escape reverts to the original (the one in effect when the menu opened); Enter commits the highlighted one.

Implementation

  • New unit-scope helpers in PasClaw.TUI's Delphi branch: THEME_NAMES constant array (display order), ResolveTheme(name) → TConsoleColorStyle, CanonicalThemeName(name) → string (case-insensitive lookup + silent fallback).
  • TTUI gains a public ThemeName: string (forwarded from Cmd_TUI_Run), FMenuOpen / FMenuSelIdx / FMenuOrigTheme / FCurrentTheme state, and methods ApplyTheme / OpenThemeMenu / HandleMenuKey / DrawThemeMenu.
  • HandleKey intercepts when FMenuOpen and routes to HandleMenuKey. Escape in menu = revert + close (instead of quitting); Enter = commit; Up/Dn = preview-by-applying.
  • SubmitInput's slash branch grew /theme → OpenThemeMenu. /help flash updated to mention it.
  • DrawFrame draws the menu last so the modal sits on top of both panes. Centred 32-col box with title + separator + per-theme rows; highlighted selection rendered in ConsoleTheme.Highlight (which itself updates as the user arrows through).
  • ApplyTheme calls SetConsoleTheme (mutates the global ConsoleTheme record DMVCFramework's WriteAnsiText reads), then ClrScr + sets FLastResizeW := -1 to force a full repaint on the next tick — drops stale ink the previous theme's background fill leaves behind.
  • Startup replaces the hardcoded SetConsoleTheme(ConsoleThemeNavy) with SetConsoleTheme(ResolveTheme(CanonicalThemeName(ThemeName))) so the flag actually takes effect.

Out of scope (deliberate v1 cuts)

  • Config persistence — theme changes don't survive next start. Needs Cmd.TUI to thread a write-back to TConfig (~30 LOC plumbing); follow-up.
  • FPC palette — line-based renderer has no theme abstraction; separate PR.
  • Per-role colour theming — chat headers stay semantic (user=cyan, assistant=magenta, tool=yellow); theme only governs chrome.
  • Custom theme files under workspace/themes/ — picoclaw doesn't have it; seven vendored themes is the v1 surface.

Test plan

  • FPC build clean (443730 lines)
  • make smoke 11/11 OK
  • FPC TUI live spot check (theme branch is {$IFNDEF FPC}-gated, so FPC build path is unchanged)
  • Manual Delphi 12 build + run — verify pasclaw tui --theme matrix starts in matrix theme, /theme opens the modal, arrows live-preview, Enter commits, Escape reverts. The env this PR was authored in has no dcc64; the changes use only known-stable DMVCFramework APIs (SetConsoleTheme, WriteAnsiText, GotoXY) and no inline-var / anonymous-record patterns.

Generated by Claude Code

`pasclaw tui --theme <name>` picks the initial theme; typing `/theme`
in the TUI opens a modal menu with Up/Down live-preview, Enter to
apply, Escape to revert. Seven themes from DMVCFramework: `navy`
(default), `matrix`, `sunset`, `ocean`, `midnight`, `classic`,
`default`. Unknown names fall back to navy silently. Changes are
session-only (no persistence) — pass `--theme` on the next run, or
wire a config field in a follow-up.

Approach:
  - New unit-scope helpers in PasClaw.TUI's Delphi branch:
    THEME_NAMES (constant array — display order),
    ResolveTheme(name) -> TConsoleColorStyle,
    CanonicalThemeName(name) -> string (case-insensitive lookup + fallback).
  - TTUI gains a public ThemeName field (Cmd_TUI_Run forwards from
    --theme), an FMenuOpen / FMenuSelIdx / FMenuOrigTheme /
    FCurrentTheme state set, plus three methods: ApplyTheme,
    OpenThemeMenu, HandleMenuKey, DrawThemeMenu.
  - HandleKey intercepts when FMenuOpen, routes to HandleMenuKey;
    Escape in menu = revert + close (instead of quitting the TUI),
    Enter = commit, Up/Dn = preview-by-applying.
  - SubmitInput's slash-command branch grew `/theme` -> OpenThemeMenu.
    `/help` flash updated to mention `/theme`.
  - DrawFrame draws the menu LAST so the modal sits on top of both
    panes. The picker is a 32-col centred box with a title row, a
    separator, one row per theme, and the highlighted selection
    drawn in ConsoleTheme.Highlight (which itself updates as the
    user arrows through).
  - ApplyTheme calls SetConsoleTheme (mutates the global ConsoleTheme
    record DMVCFramework's WriteAnsiText reads from), ClrScr (drop
    stale ink the previous theme's background fill left behind), and
    FLastResizeW := -1 to force a full repaint on the next tick.
  - Startup replaces the hardcoded `SetConsoleTheme(ConsoleThemeNavy)`
    with `SetConsoleTheme(ResolveTheme(CanonicalThemeName(ThemeName)))`
    so the --theme flag actually takes effect.

FPC branch deliberately untouched. The FPC line-based renderer uses
Ansi.* constants directly with no theme abstraction — a port would
need its own palette system and isn't in scope. Slash command lookup
on Delphi still flashes "unknown" for the FPC-only legacy
HandleSlashCommand stub (which is dead code on Delphi anyway).

FPC build clean (443730 lines), smoke 11/11 OK. The Delphi branch is
gated by {$IFNDEF FPC} so dcc64 compile + runtime needs a human side
check — I was conservative with the syntax (no inline-var, no
anonymous records, only known-stable DMVCFramework APIs).

Out of scope (deliberate v1 cuts):
  - Config persistence (theme survives next start) — needs Cmd.TUI
    to thread a write-back to TConfig, ~30 LOC plumbing punted to
    follow-up.
  - FPC palette — separate PR.
  - Per-role colour theming — chat headers stay semantic
    (user=cyan, assistant=magenta, tool=yellow); theme only governs
    chrome.
  - Custom theme files under workspace/themes/ — picoclaw doesn't
    have it; seven vendored themes is the v1 surface.

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants