Skip to main content

Playground

Runnable examples live in playground/ - one file per example, grouped by a numbered prefix that follows this documentation's order, from the quick start to the capstone form:

GroupDemonstrates
01-quickstartThe fluent builder and run() - the form from the quick start
02-fields-*One script per field, plus the whole gallery on one form
02-markup-*Markup: prose, a bordered card and a grid - one block drawn three ways, collecting nothing
02-progress-rowThe progress row: a block that runs work when activated, filling a bar in place
03-panels-*Nested panels, modal dialogs, the border frame, the grid of windows and the plain row list beside it, the fullscreen stretch
04-inline-editingInline editing and ->standalone()
05-form-logic-*Derived values, conditional fields and whole conditional sections, fix-ups
06-field-behaviour-*Declared behavior: required fields, closures, handler classes
07-discoveryDiscovery against a bundled sample project
08-headless-*Unattended collection, the JSON schema, validation, agent help
09-themes-*The built-in themes, a custom theme class, one built on the floor, element overrides, theme options, field styles
10-key-bindings-*Key bindings: the vim preset and per-binding overrides
11-display-modes-*Display modes: dark/light, ASCII, no color, markdown
12-translationsTranslations through a consumer catalog
12-specification-screenThe specification made runnable: the levels, keys traveling inward, the same tree collected headlessly
13-testingThe test harness driving the TUI from scripted keystrokes
14-produce-boxThe capstone: panels, fields, logic and behavior in one real form
15-progress-*The progress primitive, for work around a form: a spinner when the length is unknown, a bar when it is
16-loading-dataLoading a panel's data on demand, with a themed indicator while it runs
17-query-optionsOptions that follow the query, cached and held back by ->minQuery()
18-output-*The output primitives: boxes and cards, tables, status lines, definition lists, text, rules, a banner
19-dynamic-optionsOptions that follow the answers, narrowing one field by another
20-layouts-*Layouts: a layout class of your own registered by name, blocks of your own placed in the regions around the form and flowed across them, a grid moving every line of itself together, and four arrangements nested in one form with every region's edges drawn

The reusable helper classes the scripts load sit beside them - themes/, layouts/ and handlers/ - with the fixtures the examples read from in sample-project/ and translations/.

Every script is self-contained: it requires the Composer autoloader directly and declares its whole form inline, so you can copy any single file out as a starting point. Most take no CLI options - each demonstrates exactly one thing, variants are separate scripts, and unattended runs are driven by piping stdin and setting PHPTUI_<ID> environment variables. The exception is 03-panels-fullscreen.php, which takes --halign/--valign and --max-width to pick one alignment from its grid.

composer install
php playground/01-quickstart.php

The SVG demos throughout this documentation are generated from the playground scripts and forms: php docs/util/update-assets.php records the panel walkthroughs through a scripted terminal session (it needs asciinema, expect, node and npm), while php docs/util/render-field-svgs.php, php docs/util/render-anatomy-svgs.php, php docs/util/render-progress-svgs.php, php docs/util/render-output-svgs.php and php docs/util/render-theme-svgs.php render the field cards, the anatomy diagrams, the primitives and the theme previews deterministically through the library's own test harness - no terminal involved.