A terminal UI toolkit for MoonBit: cell buffer, differential ANSI renderer, incremental key parser, layout, a CSS-like design system, fifty-four widgets, and drivers for terminals, Node, browsers and serial lines.
| Synchronous core | No async and no hidden event loop. The host calls one step(): poll, parse, dispatch, lay out, compose, diff, write. |
| Differential renderer | Two frames become the runs of cells that changed, and only the escape sequences needed to draw them. A widget that moved its cursor redraws its own rows and leaves the rest of the screen standing. |
| A CSS-like design system | Selectors over name, id, class and :focus, :hover, :disabled, stacked by specificity and cascade, with inheritance, borders, padding, margins, docks, grid spans and transitions. |
| Unicode-aware | Every line is measured in terminal columns over a generated width table: wide CJK, double-width emoji, combining marks. |
| Four backends | The same code and the same test suite on wasm, wasm-gc, js and native. |
| Any wire | A modern terminal with true colour, a serial-era terminal with eight colours, a browser canvas, or a bare UART with no cursor addressing at all. |
moon add moonbitstack/moonetuimoon run --target native src/examples/gallery # every widget and every style, live
moon run --target native src/examples/monitor/main # a complete app: tabs, timers, a command line
moon run --target native src/examples/tui/main # the starter: a list, a log, a bar and a field
moon run --target native src/examples/snake/main # a game: arrows turn, space pauses
moon run --target native src/examples/life/main # Conway's life, a generation a frame
moon run --target native src/examples/game2048/main # 2048: arrows slide, r restarts
moon run --target native src/examples/pulse/main # a dashboard: a window of load
moon run --target native src/examples/donut/main # a torus, turning in two axes
moon run --target native src/examples/files/main # a browser in Miller columns
moon run --target native src/examples/top/main # cores, memory, network, processes
moon run --target native src/examples/git/main # branches, commits, files
moon run --target native src/examples/read/main # a Markdown page, set with type
moon run --target native src/examples/invaders/main # a block that marches, a gun that shoots
moon run --target native src/examples/blocks/main # seven pieces, a ten by eighteen board
moon run --target native src/examples/sweep/main # mines, flags, and a region that opens
moon run --target native src/examples/sudoku/main # nine by nine, a clash marked
moon run --target native src/examples/cards/main # Klondike: seven columns, four foundations
moon run --target native src/examples/board/main # a dashboard of small panels
moon run --target native src/examples/boxes/main # containers, their stats, and a live tail
moon run --target native src/examples/prs/main # pull requests, checks, a merge
moon run --target native src/examples/tunes/main # a player: spectrum, needle, album
moon run --target native src/examples/drift/main # a trader on six ports, with a chart
moon run --target native src/examples/mon/main # a route, a party, a wild thing in the grass
moon run --target native src/examples/logs/main # a tail, a level filter, a typed query
moon run --target native src/examples/json/main # a document as a tree: a path, folds, a query
moon run --target js src/examples/hello # under Node
moon run --target native src/examples/uart # whole frames of plain text, as a serial line gets them
moon run --target native examples/dbmux/src/main -- --demo # a database client, with a SQLite demo database
moon run --target native examples/mbtjj/src/main # a Jujutsu client, read from the repository you run it infn main raise {
let sheet = @design.Stylesheet::new()
sheet.add(
@design.Sel::new(name="Header"),
@design.Styles::new(text=@style.Style::new(bold=true, fg=@style.cyan)),
)
sheet.add(@design.Sel::new(classes=["framed"]), @design.Styles::new(border=Round))
sheet.add(
@design.Sel::new(classes=["framed"], focus=true),
@design.Styles::new(border=Heavy),
)
let list = @widget.ListView::new(["alpha", "beta", "gamma"])
let field = @widget.Input::new(placeholder="pick one")
let line = @layout.Box::new(extent=Cells(1))
let tree = @app.column(0, [
@app.leaf(1, @widget.Header::new("moonetui"), box=line, name="Header"),
@app.leaf(2, list, classes=["framed"]),
@app.leaf(3, field, box=line),
@app.leaf(4, @widget.Footer::new([("tab", "next"), ("enter", "choose")]), box=line),
])
let ui = @app.App::new(@native.NativeTty::new(), tree, sheet~)
ui.start()
@native.run(() => {
let alive = ui.step()
for report in ui.drain() {
if report is Selected(index~, ..) {
field.set(list.items()[index])
ui.refresh()
}
}
alive
})
ui.stop()
}| Group | Widgets |
|---|---|
| Text and display | Static and label(), Header (with a Clock), Footer, Rule, Digits, Sparkline, Progress, LoadingIndicator, Placeholder, Pretty, Link, KeyPanel |
| Entry and logs | Input, TextArea, Log, RichLog, MaskedInput |
| Choices | Switch, Checkbox, RadioButton, RadioSet, OptionList, SelectionList, Select, Slider, Calendar |
| Navigation and structure | Button, ListView, Paginator, Tabs, TabbedContent, Collapsible, Tree, DirectoryTree, ContentSwitcher, StatefulList, StatefulTable |
| Data and notices | DataTable, HexView, Diff, Markdown, Tooltip, Toast |
| Dialogs | MessageBox, InputBox, FileDialog |
| Menus and commands | Menu, MenuBar, CommandPalette |
| Charts and meters | Chart (lines and scatter), BarChart, Gauge, Scrollbar, Canvas (Braille dots) |
| Decoration | Block — a frame, title and padding that wraps any widget |
| Package | What it does |
|---|---|
| @geom | Integer rectangle algebra: Offset, Size, Region, Spacing |
| @style | Colours (named, indexed, true colour), attributes, palette quantisation, differential SGR |
| @strip | One rendered line: styled segments measured in terminal columns |
| @event | Keys, mouse reports, paste, resize and focus as plain values |
| @input | The terminal byte stream turned into events |
| @comp | The compositor: placements to rows, rows to changed spans, spans to escape sequences |
| @driver | The seam to a terminal, and a headless terminal for tests |
| @vt | A virtual terminal: the screen an escape stream draws, for the browser driver, tests and screenshots |
| @layout | Sizes along an axis, the grid with spans and gutters, and anchored, pivoted placement |
| @design | Rules over name, id, class and state; borders, padding, margins, alignment, docks, offsets, transitions, and the semantic Theme |
| @widget | The widget contract and the inventory |
| @app | The widget tree, focus ring, scroll containers, docks, grids, screens, timers and the frame loop |
| @driver/native · @driver/node · @driver/web | A real terminal through the C library; Node; a canvas in the browser |
| examples/theme | The look the examples share: one palette, one sheet, the header and key bar every screen wears |
| examples/snake · examples/life · examples/game2048 | Three games, each with the frame test that plays it |
| examples/pulse | A dashboard: a rolling window drawn as a spectrum, a rate, and a hold |
| examples/donut | A torus sampled, turned and shaded into characters, with a z-buffer |
| examples/files | Miller columns: where from, what is here, what the selection holds |
| examples/top | Four regions: cores, memory, two network charts, the busiest processes |
| examples/git | Three panes with a tab between them, and a file that stages |
| examples/read | Markdown set with type: headings, bullets, code, quote, table, scrollbar |
| examples/invaders | Twenty-four invaders marching, one bullet in the air, three lives |
| examples/blocks | Seven pieces turning in a four by four box, rows that clear, a level that rises |
| examples/sweep | Ten by ten of mines: reveal, flag, and a zero that opens its region |
| examples/sudoku | Nine by nine: givens that hold, digits that go in, a clash marked |
| examples/cards | Klondike on green felt: a run lifted from a column, a card sent home |
| examples/board | Six framed panels: a big clock, the month, tasks, commits, load, the day |
| examples/boxes | A container client: a list of boxes, one opened, its log running below |
| examples/prs | Pull requests with their checks, a card for the chosen one, a merge |
| examples/tunes | A record playing: a spectrum, a needle, the album behind it |
| examples/drift | Six ports on a chart: prices, a hold, fuel, and a logbook |
| examples/mon | A route to walk, a party of three, and fights in the tall grass |
| examples/logs | A log tail: levels to switch off, a typed filter, a map of the file |
| examples/json | A document as a tree beside the node it holds, its path, a typed query |
moon check --target all --deny-warn
moon build --target all
moon test --target all
moon fmt && moon info --target all # the diff must stay clean| What | Held to | Vectors |
|---|---|---|
| Columns per code point | wcwidth 0.9.4 against CPython's unicodedata read through UAX #11 | every code point these two speak for: 291,782 |
| Grapheme clusters | two independent implementations of UAX #29, uniseg and regex, for where a cluster starts, and wcwidth for its columns | 48 strings: marks, conjuncts, joiner sequences, flags, keycaps, wide forms |
| Keys | the terminfo entries of xterm, screen, tmux, the Linux console, rxvt, vt100 and ansi | 168 sequences across eight terminals |
| Frames | the bytes a frame is drawn with, read back by pyte and by tmux | 5 frames: attributes, wide characters, joined emoji, widgets, a redraw |
| A demo's keys | the screen after each key, read back by pyte and by tmux | 8 frames: open, tab, two downs, enter, tab, a typed key, ctrl-c |
| A game's frames | the screen after each move, read back by pyte and by tmux | 6 frames: open, moving, ate, paused, over, again |
MOONETUI_INTEROP=1 moon test --target native -p moonbitstack/moonetui/app \
| grep '^interop' | python3 scripts/verify_terminals.py --in /dev/stdinMOONETUI_INTEROP=1 moon test --target native -p moonbitstack/moonetui/examples/board \
| grep '^interop' | python3 scripts/render_frame.py --pick board/00 --out board.pngInstall
Download zipA terminal UI toolkit for MoonBit: cell buffer, differential ANSI renderer, incremental key parser, layout, a CSS-like design system, fifty-four widgets, and drivers for terminals, Node, browsers and serial lines.