Skip to content

Upgrade Delphi TUI with vendored MVCFramework.Console (Apache 2.0) - #24

Merged
FMXExpress merged 1 commit into
mainfrom
claude/pr24-tui-mvc-console
May 27, 2026
Merged

FMXExpress merged 1 commit into
mainfrom
claude/pr24-tui-mvc-console

Conversation

@FMXExpress

Copy link
Copy Markdown
Owner

Summary

Adopts Daniele Teti's MVCFramework.Console (DMVCFramework) as the rich rendering layer for pasclaw tui on Delphi. FPC keeps the existing line-based ANSI renderer untouched — both implementations live in PasClaw.TUI behind {$IFNDEF FPC} / {$IFDEF FPC} guards and share the same TTUI class shape, slash-command surface, and tool-loop wiring. Nothing about command dispatch, config, providers, or tool registry changes.

Vendored (Apache 2.0)

src/pkg/vendor/dmvcframework/:

File Lines Purpose
MVCFramework.Console.pas 2299 Themed boxes, tables, menus, spinners, progress bars, color primitives, cursor and console-size helpers
LoggerPro.AnsiColors.pas 252 ANSI escape constants + EnableANSIColorConsole (the one external dep of MVCFramework.Console)
dmvcframework.inc 121 Compiler-version sentinels
NOTICE – Apache 2.0 attribution

The vendored files are wired into PasClaw.dproj and the unit search path. FPC's Makefile has an explicit UNIT_DIRS list that doesn't include the vendor directory, so it never tries to compile the Delphi-only WinApi.Windows / Posix.Termios uses.

The repo-root .gitignore vendor/ rule (for make get-indy's Indy mirror) is narrowed with !src/pkg/vendor/ so this intentional bundle is tracked.

Rich TUI uses

  • WriteHeader('PasClaw provider/model tools:N', 80, Cyan)
  • Box('TUI commands', [...]) — boxed /help panel
  • Table(['#','tool'], rows, 'tools (N)') — boxed /tools listing
  • Spinner('thinking', ssDots, Cyan) — runs in a background thread during RunToolLoop, hidden in a finally block so exceptions don't leave it spinning
  • WriteSuccess / WriteWarning / WriteError / WriteInfo for status messages
  • WriteColoredText('you', Cyan) + > prompts
  • EnableUTF8Console + EnableANSIColorConsole at startup — both idempotent and safe to call after CliUI_Init already did the Windows variant

On the EnableUTF8Console / EnableANSIColorConsole note from the article

"On Windows, EnableUTF8Console calls SetConsoleOutputCP(CP_UTF8). On Linux it is a no-op since UTF-8 is the default. If you also plan to use the ANSI color primitives (Fore, Back, Style) directly with WriteLn, also call EnableANSIColorConsole. However, all high-level functions in this library call it internally, so most of the time you do not need to worry about it."

PR #23 already added our own EnableUTF8Console (with the extra SetTextCodePage(Output, CP_UTF8) Delphi needs). The vendored library's version is idempotent, so we call it again at TUI startup as belt-and-suspenders — the high-level functions (Box, Table, WriteHeader, etc.) also call EnableANSIColorConsole internally as the article promises, so we don't sprinkle that one through every call site.

Test plan

  • Delphi Win64 build: pasclaw tui shows a boxed cyan header, /help opens a styled box, /tools renders a bordered table, a dotted spinner animates during the LLM call
  • Delphi Linux64 build: same rendering (Posix branch of MVCFramework.Console)
  • FPC build: line-based TUI still works identically to before
  • FPC build does not try to compile MVCFramework.Console.pas (no WinApi.Windows/Posix.Termios errors)
  • Ctrl-C during a spinner doesn't leave the cursor hidden

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon


Generated by Claude Code

Adopts Daniele Teti's MVCFramework.Console as the rich rendering layer
for `pasclaw tui` on Delphi. FPC keeps the existing line-based ANSI
renderer untouched — both implementations live in PasClaw.TUI behind
{\$IFNDEF FPC} / {\$IFDEF FPC} guards and share the same TTUI class shape,
slash-command surface, and tool-loop wiring. Nothing about command
dispatch, config, providers, or tool registry changes.

Vendored under src/pkg/vendor/dmvcframework/ (Apache 2.0, attribution
preserved in NOTICE):

  MVCFramework.Console.pas    2299 lines — themed boxes, tables,
                              menus, spinners, progress bars, color
                              primitives, cursor and console-size helpers
  LoggerPro.AnsiColors.pas    252 lines  — ANSI escape constants +
                              EnableANSIColorConsole (the one external
                              dep of MVCFramework.Console)
  dmvcframework.inc           121 lines  — compiler-version sentinels
                              (no IDE / FireDAC / DBX coupling at this
                              level — we use only the console unit)

The vendored files are added to PasClaw.dproj and the unit search path,
and the FPC Makefile's explicit UNIT_DIRS list does not include the
vendor directory, so FPC never tries to compile the Delphi-only sources
or resolve the WinApi.Windows / Posix.Termios uses they contain.

The .gitignore root rule `vendor/` (which exists to keep `make
get-indy`'s third-party Indy mirror out of the tree) is narrowed with
an `!src/pkg/vendor/` allow rule so this intentional bundle is tracked.

The Delphi TUI now uses:

  WriteHeader('PasClaw  provider/model  tools:N', 80, Cyan)
  Box('TUI commands', [...])  — boxed /help panel
  Table(['#','tool'], rows, 'tools (N)')  — boxed /tools listing
  Spinner('thinking', ssDots, Cyan) — runs in a background thread
    during RunToolLoop, hidden in a `finally` so exceptions don't
    leave the spinner spinning
  WriteSuccess / WriteWarning / WriteError / WriteInfo for status
  WriteColoredText('you', Cyan) + ' > '  prompts
  EnableUTF8Console + EnableANSIColorConsole at startup (the library
    is idempotent; safe even after CliUI_Init already called the
    Windows variant)

https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
@FMXExpress
FMXExpress merged commit 4f81cbe into main May 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edd9cac938

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

WriteWarning('no registry');
Exit;
end;
Names := FRegistry.Names;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Qualify the registry array before assigning names

In the Delphi branch, adding MVCFramework.Console introduces a second TStringArray, so this unqualified local now binds to MVC's array type while TToolRegistry.Names still returns PasClaw.Tools.Registry.TStringArray. Delphi does not treat separately declared dynamic array types as assignment-compatible, so the Delphi TUI build fails as soon as this method is compiled; qualify the registry result or copy it into MVC's TStringArray before building the table.

Useful? React with 👍 / 👎.

EnableUTF8Console;
EnableANSIColorConsole;
DrawHeader;
WriteColoredText('/help for commands, /quit to exit'#10, DarkGray);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Respect no-color mode in the Delphi TUI

For Delphi builds, this path bypasses PasClaw.CliUI.Ansi and unconditionally uses MVC color helpers, so pasclaw --no-color tui, NO_COLOR, or TERM=dumb still emits ANSI color sequences even though the root command advertises and initializes global no-color handling. Gate the MVC colored output/theme on CliUI_NoColor or use a non-color path for those environments.

Useful? React with 👍 / 👎.

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