Skip to content

feat(build): replace iocraft with opentui + yoga-layout renderer#1202

Closed
John-David Dalton (jdalton) wants to merge 4 commits intomainfrom
feat/opentui-migration
Closed

feat(build): replace iocraft with opentui + yoga-layout renderer#1202
John-David Dalton (jdalton) wants to merge 4 commits intomainfrom
feat/opentui-migration

Conversation

@jdalton
Copy link
Copy Markdown
Contributor

@jdalton John-David Dalton (jdalton) commented Apr 15, 2026

Summary

Replace iocraft's native terminal UI renderer with opentui + yoga-layout:

  • render-engine.mjs (~750 lines): Yoga-layout WASM for flexbox + opentui.node for buffer drawing + custom ANSI/plain serializer
  • yoga-sync.cjs: socket-btm's custom yoga-layout WASM build (153KB, synchronous require)
  • opentui.node: socket-btm's 266-function native binding for terminal buffer operations
  • iocraft.mts: Falls back to iocraft if opentui not available

Architecture

iocraft.mts (Element builders — unchanged, 29 call sites untouched)
  → @socketaddon/opentui/render-engine.mjs
    → yoga-sync.cjs (socket-btm WASM, flexbox layout)
    → opentui.node (socket-btm native, buffer drawing)
    → custom serializer (plain text for renderToString, ANSI for print/eprint)

Test results

  • 86/86 tests pass
    • 26/26 iocraft-new-features (MixedText, Fragment, borders, colors)
    • 54/54 iocraft-properties (full flexbox: row/column, gap, padding, margin, absolute, overflow)
    • 6/6 renderer snapshots (Analytics, AuditLog, ThreatFeed)
  • CLI --help renders correctly with full color support

Remaining

  • Dev setup script (setup-opentui-dev.mjs)
  • @opentui/react reconciler integration (patch FFI → Node-API)
  • Interactive components (scrollbox, input, select, code, diff)
  • SEA build .node inclusion
  • Full iocraft removal

Test plan

  • pnpm run build:cli succeeds
  • node packages/cli/dist/index.js --help renders correctly
  • All 86 terminal UI tests pass
  • Renderer snapshot tests updated and passing

WIP: OpenTUI-based terminal UI renderer with yoga-layout flexbox.
Replaces iocraft's native rendering with:
- yoga-layout WASM (153KB, from socket-btm) for flexbox computation
- opentui.node (266 functions, from socket-btm) for buffer drawing
- Custom render engine mapping Element trees to yoga nodes + opentui buffers

Current state:
- 25/26 iocraft feature tests passing
- CLI --help renders correctly with full color support
- Full flexbox: row/column, gap, padding, margin, borders, absolute positioning
- All border styles (single, double, rounded, bold, classic, etc.)
- Named colors, hex, ANSI 256 palette
- Text attributes (bold, dim, italic, underline, strikethrough)
- MixedText, Fragment support

Remaining:
- MixedText ANSI adjacency in renderToString (1 test)
- iocraft-properties.test.mts full flexbox property tests
- Renderer snapshot tests (may need snapshot updates)
- renderToString returns plain text (matching iocraft behavior)
- printComponent/eprintComponent use ANSI-colored output
- Custom buffer serializer reads cell data directly for clean output
- Fix Fragment root handling (wrap in implicit View for yoga)
- Fix border corner character order (bl/br swap)
- Update renderer snapshots for plain-text output format

All 86 terminal UI tests pass:
- 26/26 iocraft-new-features tests
- 54/54 iocraft-properties tests
- 6/6 renderer snapshot tests
Add opentui .node binary download configuration to download-assets.mjs
alongside existing iocraft config. Downloads from socket-btm releases.
Add @socketaddon/opentui/react module that provides a React renderer
mapping JSX components to the OpenTUI render engine's Element tree.

Components: <box>, <text>, <mixed-text>, <br>
Props: All flexbox (via yoga-layout), borders, colors, text styling
API: render(element, engine), renderToString(element, engine),
     renderToElementTree(element)

Uses react-reconciler@0.33.0 with synchronous rendering
(updateContainerSync + flushSyncWork) for deterministic output.

Example:
  import { render } from '@socketaddon/opentui/react'
  render(
    <box borderStyle="rounded" padding={1}>
      <text color="green" bold>Hello React!</text>
    </box>,
    engine
  )
@jdalton John-David Dalton (jdalton) deleted the feat/opentui-migration branch April 15, 2026 02:14
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