Skip to content

ariadne: interactive FTXUI terminal backend, ari runner, on_signal hook - #708

Merged
transfix merged 1 commit into
masterfrom
feat/ariadne-ftxui-backend
Oct 19, 2026
Merged

transfix merged 1 commit into
masterfrom
feat/ariadne-ftxui-backend

Conversation

@transfix

Copy link
Copy Markdown
Owner

Baseline terminal UI support for Ariadne (roadmap §16.4): the FTXUI backend goes from a display-only P0 to a fully interactive backend, plus an ari runner and a document-level on_signal: hook for Ctrl-C.

What changed

cvc::ariadne::FtxuiBackend is interactive. It is immediate-mode over FTXUI's DOM, the way ImGui works. Each walk rebuilds the Element tree, every leaf reflects its on-screen box, and the backend keeps only interaction state (focus, pressed item, open popup, in-progress edits, window placement). An input event is routed first (focus moves, popups, window drag, a mouse hit-test against the last frame drawn). A walk then runs in which the target widget reports {changed, committed, value} to the core. The Backend contract is unchanged, and the backend still never touches cvc::state.

  • Keyboard: Tab / Shift-Tab and Up / Down move focus, Enter / Space activate, Left / Right step sliders and cycle combos, F10 opens the menu bar, Esc closes a popup or reverts an edit.
  • Mouse: click, slider drag, window drag / raise / close ([x]), menu and combo popups.
  • Free floating windows (caps.windows = true), placed from pos: / size: or the persisted tree.<id>.geometry. A drag is persisted back in px, using a nominal 8×16 cell, so a layout saved under one backend holds under the other.
  • Grids and tables with seams, row-split panes, the colour widget, tooltips, and disabled scopes.
  • Graphics: set_image() + Kind::Image draw half-block cells (two pixels per cell, 24-bit colour). A colourless terminal gets a luminance ramp.
  • Each floating layer is line-merged on its own, so overlapping windows and dropdowns don't fuse their borders.
  • Commit edges match the ImGui backend: discrete widgets commit on the edit, a dragged slider commits on release, text commits on Enter or blur (Enter commits even when unchanged, as ImGui's EnterReturnsTrue does).
  • run(Runtime&) / run(AppRuntime&) drive FTXUI's Loop::RunOnce with a drain() between iterations. That proves §16.5 decision Modernization 2 #7 (intents never run mid-walk under a framework-owned loop). Keys and pointer events the UI didn't use are forwarded to on_key / on_pointer.

ari (new tool, src/cvc/tools/ari_main.cpp): ari run | snapshot | check doc.ari. It is GL-free: AppRuntime + FtxuiBackend with no SceneAdapter, so a scene: is dropped with a warning. It is installed to bin/, and -DCVC_BUILD_ARI=OFF turns it off.

on_signal: (new top-level .ari key): a resident program, like on_key, woken with event = {kind: "signal", signal: "SIGINT", source: "terminal"}.

  • Declaring it takes the signal over, like a POSIX handler. Runtime::post_signal returns true and the host skips the default.
  • The terminal loop routes Ctrl-C as SIGINT and Ctrl-\ as SIGQUIT.
  • With no handler, Ctrl-C quits. Three Ctrl-Cs within two seconds always quit, so a handler can't trap the user.
  • Ctrl-C now returns from run() instead of FTXUI re-raising SIGINT, which would have killed an embedding host.
  • ari registers a (quit) verb for handlers to call.

Verification

  • ariadne_ftxui_test: 28 new headless cases over render_to_string + feed(TermEvent). They cover focus, activation, slider keys and drag-commit-on-release, combo popup by key and by mouse, text commit on Enter / blur / Esc, menus by key and by mouse, window cascade / authored pos / persisted seed / drag-persist / close / raise-on-focus, disabled skip, tooltip, grid columns, colour, images, and the tour document end to end.
  • ariadne_runtime_test (134) and ariadne_loader_test (182) pass, including the new on_signal cases.
  • In a real terminal (tmux, xterm-256color) with real keystrokes and SGR mouse sequences:
    • typing into a field and pressing Enter ran its on: program, and the Status window updated;
    • a click toggled a checkbox;
    • dragging a title bar moved its window;
    • F10, Down, Enter quit;
    • resizing the terminal re-clamped the windows;
    • Ctrl-C exited with status 0;
    • the tour's on_signal asked first, then quit;
    • a handler that never quits was overridden by the third Ctrl-C.
  • git clang-format --diff is clean.

Not in this PR

  • Draggable row-split seams (panes keep their authored or persisted sizes).
  • Signals the OS delivers (kill -TERM, SIGHUP) still take FTXUI's default. A process-wide handler belongs to the host application (it would call post_signal), not a static in the library.
  • The wasm / xterm.js build of the terminal backend, and the tvision backend (§16.5 row 5).
  • Showing a 3D scene in the terminal (the §16.6 pixel mirror).

…hook

The FTXUI backend was a display-only P0 (every state-bound primitive returned an
empty edit). It is now a full interactive backend, immediate-mode over FTXUI's
DOM the way ImGui works: each walk rebuilds the Element tree, every leaf reflects
its on-screen Box, and an input event is routed (focus, popups, window drag,
mouse hit-test against the last frame drawn) and then handled by a walk in which
the target widget reports {changed, committed, value} to the core.

- Keyboard focus (Tab / arrows), activation, slider steps, combo popups, in-place
  text editing (commit on Enter or blur, Esc reverts), F10 menus.
- Mouse: click, slider drag (commit on release), window drag / raise / close.
- Free floating windows (caps.windows = true), placed from pos/size or the
  persisted tree.<id>.geometry, reported back in px (nominal 8x16 cell).
- Grids / tables with seams, row-split panes, colour picker, tooltips,
  disabled scopes, half-block image rendering via set_image().
- Each floating layer is line-merged in isolation, so overlapping windows and
  dropdowns don't fuse their borders.
- run(Runtime&) / run(AppRuntime&): FTXUI Loop + drain per iteration; unused
  keys and pointer events go to the document's on_key / on_pointer.

`ari run|snapshot|check doc.ari` runs a document in the terminal (GL-free).

New document-level `on_signal:` hook (loader -> Runtime::set_signal_program /
post_signal -> AppRuntime). Declaring it takes the signal over like a POSIX
handler; the terminal loop routes Ctrl-C as SIGINT and Ctrl-\ as SIGQUIT, quits
when no handler is set, and always quits on three Ctrl-Cs within two seconds.
Ctrl-C no longer re-raises SIGINT (which would kill an embedding host).

Tests: ariadne_ftxui_test (28 headless cases over render_to_string + feed),
plus loader and runtime cases for on_signal. Example: terminal_tour.ari.
transfix added a commit that referenced this pull request Oct 19, 2026
The frame wait (emscripten_sleep vs sleep_for) and whether Ctrl-Z suspends now
live in two helpers above run_loop, so run_loop itself changes by one line each.
Less to collide with the run_loop work stacked on #708.
@transfix
transfix merged commit 4fa5620 into master Oct 19, 2026
17 checks passed
transfix added a commit that referenced this pull request Oct 19, 2026
The frame wait (emscripten_sleep vs sleep_for) and whether Ctrl-Z suspends now
live in two helpers above run_loop, so run_loop itself changes by one line each.
Less to collide with the run_loop work stacked on #708.
transfix added a commit that referenced this pull request Oct 19, 2026
…cpkg package

Follow-ups to the interactive FTXUI backend (#708):

- Grid seams drag. A row split is now one framed stack with a separator
  between panes; dragging a separator resizes the two panes around it and
  the pane sizes persist to tree.<id>.tracks (seeded apply-once from the
  persisted / authored sizes). A `resizable` table gets a draggable seam
  between columns (a blank one-cell seam when it shows no inner borders).
- OS signals reach on_signal. RunOptions gains host hooks: on_start (after
  FTXUI installs its own handlers), on_stop, and a take_signal poll; each
  pending signal goes to the document's on_signal (source "os") and ends
  the loop when the document has no handler. run() now returns why it
  ended (RunExit). The handlers stay in the host: `ari` wires SIGTERM,
  SIGHUP, SIGINT, SIGQUIT and SIGUSR1/2 through sigaction and exits with
  128 + signo on an unhandled one.
- `ari` is its own package. It moves to a dual-mode src/ari (in-tree or
  standalone against an installed libcvc, like src/cvc-cli), gains
  CVC_BUILD_ARI (OFF in the libcvc / libcvc-cuda recipes), a linux
  cvcpkg/recipes/ari recipe, and a pack + publish step in
  publish-cvcpkg.yml modelled on cvcgl-examples.
transfix added a commit that referenced this pull request Oct 19, 2026
…rm.js (#710)

* ariadne: run a .ari in the browser — the FTXUI backend on wasm behind xterm.js

The terminal backend now builds for Emscripten, and `ari` gets a web target:
ari.js + ari.wasm + ari.html. The page wires xterm.js to the module's
stdin/stdout, which is all FTXUI's Emscripten screen talks to, and reports its
size through ftxui_on_resize. It is single-threaded, so the gh-pages gallery can
serve it without COOP/COEP. This is what roadmap §16.4 picked FTXUI for.

- FtxuiBackend::run_loop: in the browser the loop runs on the page's main
  thread, so the wait between iterations is emscripten_sleep (Asyncify), not
  sleep_for, which would spin and freeze the page. Ctrl-Z is swallowed (no job
  control to suspend to); Ctrl-C still goes to on_signal: as SIGINT.
- ari: with no argv (a page has none) it runs the document the build baked in,
  CVC_ARIADNE_WASM_DOC, with the component library at /components. That is the
  same convention as cvcGL's ariadne_hello.
- CMake (EMSCRIPTEN only): embed CVC_ARI_WASM_DOC (default terminal_tour.ari)
  and the components, link -sASYNCIFY -sFETCH -sEXIT_RUNTIME, export
  ftxui_on_resize, and generate ari.html next to ari.js. The page uses a plain
  string replace, because configure_file(@only) would eat "@xterm/xterm@".
- ari.html: xterm.js 5.5 + fit + webgl addons, pinned with SRI. The program
  starts only after the stylesheet and font load. Otherwise the first frames
  are drawn at a bogus size, and the backend's in-place window clamp piles every
  window at the origin.
- CI: a new ari-wasm job builds the web target against catalog wasm deps. It
  requires that the configure found yaml-cpp and ftxui, renders the baked tour
  under node with `ari snapshot`, and uploads the page.
- docs/ARIADNE.md: how to build and serve it, and what differs from a terminal.

Verified locally (emsdk 5.0.7, deps from cvcpkg; ftxui/yaml-cpp wasm packed
from cy-pca/cvcpkg recipes) in a browser on plain http.server: keyboard focus
and slider steps, a typed Name with Enter running the on: program, a click on
the checkbox, a slider drag, a window dragged by its title, the combo popup,
File menu by click and F10, the menu toggling a window, and resize. Ctrl-C
asks via on_signal:, and a second Ctrl-C quits with status 0. Under node the
snapshot matches the native one.

* ci: keep ci.yml's CRLF line endings (the ari-wasm edit had rewritten them as LF)

* ariadne(ftxui): keep the wasm differences out of run_loop's body

The frame wait (emscripten_sleep vs sleep_for) and whether Ctrl-Z suspends now
live in two helpers above run_loop, so run_loop itself changes by one line each.
Less to collide with the run_loop work stacked on #708.

* gallery: put ari (the .ari terminal in xterm.js) on the GitHub Pages site

The wasm demo gallery (deploy-pages.yml -> https://transfix.github.io/libcvc/)
now builds and serves the ari page next to the cvcGL demos.

- build-wasm-demo.sh builds the `ari` target when the deps prefix has FTXUI for
  wasm. Without it the target is the stub that only says FTXUI is missing, so
  it is skipped with a message. The --pthread gallery skips it too, because the
  page is single-threaded.
- build-pages.py: a target that builds its own host page next to its binaries
  (bin/<demo>.html) keeps it as <demo>/index.html; the rest still get the
  canvas template. ari's page is an xterm.js terminal, not a canvas.
- deploy-pages.yml installs ftxui for wasm/wasm32 as a required dep (like
  pegtl), adds ari to DEMOS so the post-deploy live check covers it, and the
  fallback assembly copies a <demo>.html.
- demos.json: an ari card with a thumbnail rendered from `ari snapshot --ansi`.
- ari.html: shows an "all examples" link when served as a gallery entry
  (.../ari/). It fetches ari.wasm and ari.js with cache: 'no-cache' (wasm via
  Module.wasmBinary, glue inline), so a redeploy can't pair a cached ari.js with
  a new ari.wasm. This is the same concern the canvas template's ASSET_V handles.

Checked locally: build-pages over the wasm bin/ gives the card and ari/index.html.
From the gallery path, keys work, Ctrl-C asks then quits, and the link shows.
The standalone ari.html still runs, without the link.
transfix added a commit that referenced this pull request Oct 19, 2026
…cpkg package

Follow-ups to the interactive FTXUI backend (#708):

- Grid seams drag. A row split is now one framed stack with a separator
  between panes; dragging a separator resizes the two panes around it and
  the pane sizes persist to tree.<id>.tracks (seeded apply-once from the
  persisted / authored sizes). A `resizable` table gets a draggable seam
  between columns (a blank one-cell seam when it shows no inner borders).
- OS signals reach on_signal. RunOptions gains host hooks: on_start (after
  FTXUI installs its own handlers), on_stop, and a take_signal poll; each
  pending signal goes to the document's on_signal (source "os") and ends
  the loop when the document has no handler. run() now returns why it
  ended (RunExit). The handlers stay in the host: `ari` wires SIGTERM,
  SIGHUP, SIGINT, SIGQUIT and SIGUSR1/2 through sigaction and exits with
  128 + signo on an unhandled one.
- `ari` is its own package. It moves to a dual-mode src/ari (in-tree or
  standalone against an installed libcvc, like src/cvc-cli), gains
  CVC_BUILD_ARI (OFF in the libcvc / libcvc-cuda recipes), a linux
  cvcpkg/recipes/ari recipe, and a pack + publish step in
  publish-cvcpkg.yml modelled on cvcgl-examples.
transfix added a commit that referenced this pull request Oct 19, 2026
…cpkg package

Follow-ups to the interactive FTXUI backend (#708):

- Grid seams drag. A row split is now one framed stack with a separator
  between panes; dragging a separator resizes the two panes around it and
  the pane sizes persist to tree.<id>.tracks (seeded apply-once from the
  persisted / authored sizes). A `resizable` table gets a draggable seam
  between columns (a blank one-cell seam when it shows no inner borders).
- OS signals reach on_signal. RunOptions gains host hooks: on_start (after
  FTXUI installs its own handlers), on_stop, and a take_signal poll; each
  pending signal goes to the document's on_signal (source "os") and ends
  the loop when the document has no handler. run() now returns why it
  ended (RunExit). The handlers stay in the host: `ari` wires SIGTERM,
  SIGHUP, SIGINT, SIGQUIT and SIGUSR1/2 through sigaction and exits with
  128 + signo on an unhandled one.
- `ari` is its own package. It moves to a dual-mode src/ari (in-tree or
  standalone against an installed libcvc, like src/cvc-cli), gains
  CVC_BUILD_ARI (OFF in the libcvc / libcvc-cuda recipes), a linux
  cvcpkg/recipes/ari recipe, and a pack + publish step in
  publish-cvcpkg.yml modelled on cvcgl-examples.
transfix added a commit that referenced this pull request Oct 19, 2026
…kg package (#709)

* cmake: also rewrite assimp's stale windows z.lib to ZLIB::ZLIB

The defensive rewrite of assimp's exported zlib link matched libz.* and
zlib.*, but an assimp republished on the windows builder exports
$<LINK_ONLY:.../cvcpkg-prefix-assimp-*/lib/z.lib> (zlib's CMake names its
windows import library z.lib). Neither pattern matched, so the builder-absolute
path survived into cvc.dll's link: `ninja: error: ...lib/z.lib, needed by
bin/cvc.dll, missing` in the windows recipe lane and `nvlink fatal: Could not
open input file ...lib/z.lib` in package-windows (red on master since the
republish). Match a path ending in /z.lib or \z.lib too, through to the end of
its list entry so a $<LINK_ONLY:...> wrapper does not leave a stray '>'.

* cmake: the same z.lib rewrite for libcvc's consumers (cvcConfig.cmake)

With the build-side rewrite fixed, the windows recipe lane got as far as its
consumer smoke test and failed there: `LNK1181: cannot open input file
...cvcpkg-prefix-assimp-*\lib\z.lib` in smoke.vcxproj. cvcConfig.cmake re-finds
assimp for every consumer and carries its own copy of the stale-zlib rewrite,
with the old libz/zlib-only pattern. Give it the same pattern as
src/cvc/CMakeLists.txt.

* ariadne(tui): draggable grid seams, OS signals to on_signal, `ari` cvcpkg package

Follow-ups to the interactive FTXUI backend (#708):

- Grid seams drag. A row split is now one framed stack with a separator
  between panes; dragging a separator resizes the two panes around it and
  the pane sizes persist to tree.<id>.tracks (seeded apply-once from the
  persisted / authored sizes). A `resizable` table gets a draggable seam
  between columns (a blank one-cell seam when it shows no inner borders).
- OS signals reach on_signal. RunOptions gains host hooks: on_start (after
  FTXUI installs its own handlers), on_stop, and a take_signal poll; each
  pending signal goes to the document's on_signal (source "os") and ends
  the loop when the document has no handler. run() now returns why it
  ended (RunExit). The handlers stay in the host: `ari` wires SIGTERM,
  SIGHUP, SIGINT, SIGQUIT and SIGUSR1/2 through sigaction and exits with
  128 + signo on an unhandled one.
- `ari` is its own package. It moves to a dual-mode src/ari (in-tree or
  standalone against an installed libcvc, like src/cvc-cli), gains
  CVC_BUILD_ARI (OFF in the libcvc / libcvc-cuda recipes), a linux
  cvcpkg/recipes/ari recipe, and a pack + publish step in
  publish-cvcpkg.yml modelled on cvcgl-examples.

* ariadne(tui): keep a window's placement when a frame is drawn on a tiny screen

begin_window clamped the STORED window position to the screen every frame, so
one frame drawn on a momentarily tiny screen (a terminal, or a browser page
before its first resize) moved every window into the corner for good. Clamp
only where the window is drawn (Win::sx/sy); the placement stays what the
document, the persisted geometry or a drag set. Found by the wasm/xterm.js
session (#710).

* ariadne(tui): clang-format
transfix added a commit that referenced this pull request Oct 19, 2026
#716)

* wasm-mt SDK: the real Ariadne .ari loader and FTXUI backend, not stubs

The published wasm-mt libcvc (publish-cvcgl-wasm.yml) never installed yaml-cpp
or ftxui into its deps, so its .ari loader and terminal backend compiled to
stubs. A downstream wasm app could not load a .ari document at all. Both are
now published for wasm-mt (cy-pca/cvcpkg#378 ftxui, #387 yaml-cpp).

- publish-cvcgl-wasm.yml installs yaml-cpp and ftxui for wasm-mt with the
  rest of the closure, and fails the build if the installed cvcConfig.cmake
  does not name them. That is the same check it already makes for Jolt, and
  a configure that misses them silently compiles the stubs.
- It also configures with CVC_BUILD_ARI=OFF. The job builds only cvc and
  cvcGL, then runs `cmake --install`. With `ari` on (the default since #708),
  that install fails on the missing bin/ari.js, so the next tag's wasm publish
  would have broken. The browser ari page ships with the gh-pages gallery.
- recipes/libcvc: yaml-cpp and ftxui are declared for wasm-mt too. A static
  libcvc's cvcConfig.cmake runs find_dependency on them, so a consumer's
  install must bring them.

No cvc_revision bump: no 3.6.0 wasm-mt bundle exists (the v3.6.0 wasm publish
was refused over the xmlrpc globs, since fixed on master), so the next wasm-mt
publish is a fresh bundle. Native bundles are unchanged.

Verified locally (emsdk 5.0.7, wasm-mt deps from the catalog, threaded build of
the cvc target):
- The configure prints "Ariadne: .ari YAML loader ENABLED" and "FTXUI
  terminal backend ENABLED".
- cmake --install succeeds with CVC_BUILD_ARI=OFF (it fails with it on).
- The installed cvcConfig.cmake lists yaml-cpp;ftxui;Jolt and names no
  build-machine path.
- A consumer project finds all three through find_package(cvc), links a
  -pthread module, and under node reports have_yaml=1 and ftxui=1.
- The recipe validates against cy-pca/cvcpkg master's recipe set.

* publish-cvcgl-wasm: install the gallery's data packages by their real tuple (platform any, x86_64, shared)

The cvcgl-examples step installed scene-austin-south-small, grl-snam-weights
and vehicle-humvee with --platform wasm-mt. They are published as platform
any, link shared, and the scene and vehicle bundles as arch x86_64 (not
noarch), so that matched no bundle. The dry run of this branch (run
39214815368) failed there with 'Austin scene not staged for preload', after
the libcvc + cvcgl pack had passed. Locally, --platform any --arch x86_64
--config release --link shared installs all three, including the noarch
weights.

* cvcgl-examples: scope the native bin/ entries to linux/windows (the wasm-mt pack refused them)

With the data-package install fixed, the dry run (run 39217076353) built the
wasm-mt gallery (terrain_lab, nav_city_swarm, nav_city_drive, nav_fog_ghost)
and then failed cvcpkg's strict-glob check. package.files declared
bin/lsystem_forest, bin/nav_city_*, bin/nav_fog_ghost, bin/nav_finale and
bin/cvcgl-examples-web on every platform, and the wasm-mt column ships only
share/cvcgl-examples/web. They are now platforms-scoped to linux and windows,
like the nav CLIs already were. Native bundles are unchanged, and no 3.6.0
wasm-mt bundle exists, so there is no revision bump.
@transfix
transfix deleted the feat/ariadne-ftxui-backend branch October 29, 2026 20:52
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.

1 participant