htui 0.1.0

A terminal HTML/CSS renderer with an embedded JavaScript engine — build interactive TUIs from HTML, CSS and JS
Documentation

htui

An HTML/CSS/JS engine for the terminal — build interactive TUIs the way you build web pages.

crates.io docs.rs license Rust

中文说明

htui is a Rust library that renders HTML documents with CSS styling inside the terminal and runs each document's <script> blocks in an embedded JavaScript engine (Boa) with browser-style DOM bindings. Rust application code talks to the page through typed host functions that become callable JS globals. Everything the document sees is served from an in-memory mem:// registry — no filesystem, no network.

Features

  • HTML + CSS rendering — flow, flexbox, tables, multi-column, positioning, box model, text styling, :hover / :focus
  • JavaScript scripting — browser-aligned DOM bindings, timers, fetch (Promise-based), console
  • Rust ↔ JS interop — #[htui::command] turns plain Rust functions into typed JS globals
  • DOM-style events — click / hover / focus / input / key / form events with bubbling and preventDefault()
  • Form controls — input, textarea, select + datalist, checkbox / radio, form submit / reset, details, dialog
  • Images — PNG / JPEG / WebP and SVG as truecolor half-block cells
  • Smooth rendering — incremental diff output, region repaints, 60 fps cap
  • No unsafe — page JS runs under runtime limits; decoding and resources are sandboxed away from the filesystem and network

Quick start

[dependencies]
htui = "0.1"
use htui::Session;

fn main() {
    let mut session = Session::new();
    session.render(
        r#"
        <h1 style="color: steelblue">Hello, htui</h1>
        <p>Press <b>Esc</b> to quit.</p>
        "#,
        "",
    );
}

Interactivity is one attribute away — <button onclick="greet()"> with a #[htui::command] Rust function behind it. See the tutorials below.

Visual test gallery

The repository also contains visual_test, an interactive gallery covering every supported HTML/CSS/JS feature. It is a workspace member, not part of this crate — clone the repository and run from its root:

cargo run -p visual_test                          # interactive (Esc to quit)
cargo run -p visual_test -- flex                  # a specific demo
cargo run -p visual_test -- --dump showcase --cols 68   # headless preview

Documentation

Document Content
docs.rs/htui API reference
中文文档 Chinese introduction
Tutorial: HelloWorld First rendering
Tutorial: Dynamic terminal Events, timers, built-in keys
Tutorial: JS/Rust bindings Host functions, interop
Tutorial: Resources The mem:// registry
Architecture Pipeline & threading model
Capability matrix Full HTML/CSS/JS matrix vs. browsers

Platform

Rust 1.89+ (edition 2024). Windows console and POSIX terminals via crossterm; truecolor recommended.

License

Licensed under either of Apache-2.0 or MIT at your option.