moonetui

    moonetui — a terminal UI toolkit for MoonBit (after Textual): cell buffer, differential ANSI renderer, incremental key parser, layout, widgets, and pluggable terminal drivers.

    tui
    terminal
    textual
    widget
    ansi
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    23 hours ago
    Downloads
    1

    #moonetui

    A terminal UI toolkit for MoonBit

    Cell buffer, differential ANSI renderer, incremental key parser, layout, widgets, and pluggable terminal drivers — after Python's Textual.

    Check and Test license

    0.1.0 is under construction. This README states what is in the repository today, not what is planned.

    #What is here

    PackageWhat it doesStatus
    @geomInteger rectangle algebra: Offset, Size, Region, Spacing, with intersection, union, splitting and clampingdone
    @styleColours (named, indexed, true colour), text attributes, palette quantisation, and differential SGR renderingdone
    @stripOne rendered line: styled segments measured in terminal columns, with cropping, division, padding and merging, over a generated Unicode width tabledone
    @eventKeys, mouse reports, paste, resize and focus as plain valuesdone
    @inputThe terminal byte stream turned into events: CSI and SS3 sequences, modifiers, SGR mouse, bracketed paste, in-band resize, UTF-8 split across readsdone
    @compThe compositor: placements to composed rows, consecutive screens to the spans that changed, spans to escape sequencesdone
    @driverThe seam to a terminal — write, poll, size, raw mode, clock — plus the capability sequences and a headless terminal for testsdone
    @layoutPlacing boxes along an axis: fixed cells, percentages, automatic sizes and fractional shares, with integer division that loses no columndone
    @widgetThe widget contract and eight widgets: static text, label, button, input, list, progress bar, header, footerdone
    @appThe widget tree, the focus ring, and the frame loop: poll, parse, dispatch, lay out, compose, diff, writedone
    @driver/nodeNode's terminal: raw mode, a queue the data handler fills, and a frame pumpdone
    @driver/webA terminal drawn on a canvas: the grid, the escape sequences it understands, key encoding, and in-band resizedone
    @driver/nativeA real terminal through the C library: termios on Unix, virtual terminal mode on Windowsdone

    All of 0.1.0 is here. What is deliberately not: the CSS-like style system, scrolling containers, and the thirty-odd widgets beyond the eight below — see AGENTS.md for where the line is.

    #Design

    The library core is synchronous. wasm-gc has no async, and the core has to run there because that is where the tests run, so the main loop is a step() the host drives: a blocking poll on native, setInterval under Node, requestAnimationFrame in a browser.

    Only four operations ever touch a platform: write, read what is available, set raw mode, and ask for the terminal size. Everything else — parsing, layout, composition, widgets — is pure and runs on all four backends.

    #Use it

    moon add moonbitstack/moonetui

    Three runnable examples of the same application: moon run --target native examples/tui on a terminal, moon run --target js examples/hello under Node, and examples/browser/index.html on a canvas in a browser.

    let screen = @geom.Size::new(80, 24)
    let panel = @geom.Region::new(2, 1, 40, 10)
    let visible = panel.clip(screen.width, screen.height)

    #Tests

    moon check --target all --deny-warn moon test --target all

    135 tests; the browser grid's own tests run on the js backend, the rest on all four.

    #License

    Apache-2.0. See LICENSE.