Skip to content

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

Merged
transfix merged 4 commits into
masterfrom
feat/ariadne-ftxui-wasm
Oct 19, 2026
Merged

transfix merged 4 commits into
masterfrom
feat/ariadne-ftxui-wasm

Conversation

@transfix

@transfix transfix commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Based on master. #708 merged as 4fa5620, and this branch was rebased onto master with #708's original commit dropped.

The FTXUI terminal backend now builds for Emscripten, and ari has a web target: bin/ari.js + ari.wasm + ari.html. The page puts an xterm.js terminal on the module's stdin/stdout. That is all FTXUI's Emscripten screen uses, plus ftxui_on_resize for the size. The build is single-threaded, so it serves over plain http with no COOP/COEP, the same as the gh-pages gallery. This is the reason roadmap §16.4 picked FTXUI.

Changes

  • FtxuiBackend::run_loop. In the browser the loop runs on the page's main thread. Its wait is emscripten_sleep (Asyncify), which hands control back so xterm.js can deliver input and paint; sleep_for would spin and freeze the page. Ctrl-Z is swallowed, since a page has no job control. Ctrl-C still goes to on_signal: as SIGINT.
  • ari. With no argv (a page has none) it runs the baked document CVC_ARIADNE_WASM_DOC, with the component library at /components. This is the ariadne_hello convention.
  • CMake (EMSCRIPTEN only).
    • Embeds CVC_ARI_WASM_DOC (default terminal_tour.ari) and the components.
    • Links -sASYNCIFY -sFETCH -sEXIT_RUNTIME and exports ftxui_on_resize.
    • Generates ari.html next to ari.js with a plain string replace, because configure_file(@ONLY) eats the @xterm/xterm@ in the CDN URLs.
    • CVC_ARIADNE_FTXUI turns on as before, whenever ftxui is in the wasm deps prefix.
  • src/cvc/tools/web/ari.html. Loads xterm.js 5.5 with the fit and WebGL addons, pinned with SRI. The program starts only after the stylesheet and font have loaded (see the clamp issue below). When the document quits, the page shows the exit status and a "run again" button.
  • CI ari-wasm. Path-gated like physics-wasm. It installs the wasm/wasm32 deps from the catalog and requires that the configure found yaml-cpp and ftxui (not stubs). It then runs node ari.js snapshot /terminal_tour.ari and checks that the tour rendered, and uploads the page as the ari-web artifact.
  • docs/ARIADNE.md. How to build and serve it, and what differs from a terminal.

Prerequisite for CI (in progress)

ari-wasm needs ftxui and yaml-cpp published for wasm/wasm32, and neither is yet:

cy-pca/cvcpkg#378 merged (e857aaa0), and populate-server run 39195263737 is publishing both for wasm and wasm-mt. Until it finishes, ari-wasm fails at the install step; it will be re-run after the publish.

Verified locally

Setup: emsdk 5.0.7 and boost/zstd/zlib/bzip2/xz/pegtl from the catalog; ftxui and yaml-cpp packed for wasm from cy-pca/cvcpkg recipes. Served from python3 -m http.server (no isolation headers) and driven in a browser:

  • keyboard: Tab focus, Right steps the slider (agents 64 → 65), F10 opens the menu bar, Enter activates a menu item
  • text: typing joe + Enter runs the field's on: program (log: hello, joe), and the tooltip shows
  • mouse (xterm.js SGR reports): checkbox click (wire: 1), slider drag (agents → 512, visible_when row appears), a window dragged by its title, the combo popup (picked private), File menu by click, the menu toggling the Status window off and on
  • resize: the viewport grew to 149×47 cells and FTXUI redrew at that size
  • Ctrl-C: the first press runs on_signal: (log: Ctrl-C again to quit), the second calls (quit), and the page shows [ari exited with status 0]

Under node, ari snapshot of the wasm build matches the native snapshot. clang-format 18 reports nothing on the changed lines. Both edited .cpp files compile natively with and without CVC_ARIADNE_WASM_DOC.

What can't work, or works differently, in the browser

  • The fixed-fps loop works but is timer-driven: it is emscripten_sleep(1000/fps), so a hidden tab's timer throttling slows redraws and on_tick. That is expected for a background page.
  • Ctrl-C: works through on_signal: as above. A browser keeps Ctrl-W/T/N and some F-keys for itself. OS signals don't exist in a page.
  • Startup pause (~0.5 s): FTXUI busy-waits up to 500 ms for the terminal's capability replies (DECRQSS/DA1/DA2). xterm.js can only answer once the loop yields, so the wait always times out. The replies then arrive as ordinary input and are ignored. This is from reading FTXUI's code; I did not time it.
  • Ctrl-Z is ignored (no job control).

Overlap with #709 (also stacked on #708)

#709 moves ari to src/ari/ (main.cpp, its own CMakeLists.txt) and removes the ari block from src/cvc/CMakeLists.txt. Rebasing this PR onto #709 conflicts only in that block. ftxui_backend.cpp and the renamed main.cpp merge cleanly. The resolution:

  • the if(EMSCRIPTEN) block moves into src/ari/CMakeLists.txt, with paths ../cvc/ariadne/...
  • the page moves to src/ari/web/ari.html
  • src/ari goes into the ari-wasm path filter

That rebase exists as the local branch feat/ariadne-ftxui-wasm-on-709 (not pushed). I built it for wasm and checked it in the browser: keys, and Ctrl-C asks and then quits through #709's signal hooks.

Found in #708's backend (not changed here)

begin_window clamps a window's stored x/y to the current terminal size on every frame, so one small frame moves windows permanently. I reproduced it: _ftxui_on_resize(3, 2) then back to full size leaves every window piled at (0,1). A native terminal that is shrunk and re-grown does the same. This PR only avoids the startup case in the page. The fix belongs in the backend: clamp the drawn position, not the stored one.

GitHub Pages (added after review)

The ari page now ships with the wasm demo gallery at https://transfix.github.io/libcvc/ (deploy-pages.yml, catx-03; runs on push to master, nightly, and on dispatch):

  • build-wasm-demo.sh builds ari when FTXUI is in the deps prefix, non-pthread gallery only.
  • build-pages.py keeps a target's own bin/<demo>.html as <demo>/index.html; everything else still gets the canvas template.
  • deploy-pages.yml installs ftxui (wasm/wasm32) as a required dep and adds ari to the post-deploy live check.
  • demos.json has an ari card; its thumbnail is rendered from ari snapshot --ansi.
  • ari.html shows an "all examples" link when it is the gallery entry. It fetches ari.wasm/ari.js with cache: 'no-cache', so a redeploy can't pair a cached script with a new binary.

I checked it locally: build-pages.py over the wasm bin/, served. The card and the ari/ page work, and the standalone ari.html still works.

Merge order: the ftxui wasm bundle must be published before this lands on master. Otherwise the deploy fails at the ftxui install, by design.

Follow-ups

  • ftxui + yaml-cpp in the published wasm libcvc (publish-cvcgl-wasm.yml, wasm-mt), with a libcvc recipe revision bump. Today that bundle's .ari loader is a stub.

transfix added a commit that referenced this pull request Oct 19, 2026
…ny 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).
… 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.
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.
…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
transfix changed the base branch from feat/ariadne-ftxui-backend to master October 19, 2026 03:46
@transfix
transfix force-pushed the feat/ariadne-ftxui-wasm branch from a14985a to e9ca161 Compare October 19, 2026 03:46
transfix added a commit that referenced this pull request Oct 19, 2026
…ny 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).
@transfix
transfix merged commit 32d08a9 into master Oct 19, 2026
30 of 31 checks passed
transfix added a commit that referenced this pull request Oct 19, 2026
…ny 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).
transfix added a commit that referenced this pull request Oct 19, 2026
…ny 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).
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
transfix deleted the feat/ariadne-ftxui-wasm 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