package toffee
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/README.html
Mosaic
Terminal user interfaces for OCaml.
This repository contains three packages that work together or independently:
Package | Description |
|---|---|
High-level UI framework with The Elm Architecture | |
Terminal toolkit: rendering, input, PTY, VTE | |
CSS layout engine (Flexbox, Grid, Block) ported from Taffy |
Mosaic provides a TEA runtime (model / update / view), 16 built-in widgets, and CSS layout via Toffee. Write your UI as a pure function of state.
Matrix is the terminal layer: double-buffered rendering that diffs cell changes to emit minimal ANSI output, Kitty keyboard, SGR mouse, bracketed paste, focus reporting, and a virtual terminal emulator. Usable on its own for immediate-mode terminal apps.
Toffee is a pure OCaml port of Taffy. It computes Flexbox, Grid, and Block layout with no C stubs and no runtime dependencies.
Two additional packages are included:
Package | Description |
|---|---|
Eio-based runtime for Matrix | |
OCaml bindings for Tree-sitter |
Quick start
Install via opam:
opam install mosaicOr build from source:
dune build @installRun a demo:
dune exec ./mosaic/examples/01-counter/main.exeA minimal Mosaic app:
open Mosaic
type msg = Increment | Decrement | Quit
let init () = (0, Cmd.none)
let update msg model =
match msg with
| Increment -> (model + 1, Cmd.none)
| Decrement -> (model - 1, Cmd.none)
| Quit -> (model, Cmd.quit)
let view model =
box ~flex_direction:Column
~size:{ width = pct 100; height = pct 100 }
[
box ~flex_grow:1. ~align_items:Center ~justify_content:Center
[ text (Printf.sprintf "Count: %d" model) ];
text "Press + / - to change, q to quit";
]
let subscriptions _model =
Sub.on_key (fun ev ->
match (Event.Key.data ev).key with
| Char c when Uchar.equal c (Uchar.of_char '+') -> Some Increment
| Char c when Uchar.equal c (Uchar.of_char '-') -> Some Decrement
| Char c when Uchar.equal c (Uchar.of_char 'q') -> Some Quit
| Escape -> Some Quit
| _ -> None)
let () = run { init; update; view; subscriptions }Examples
Mosaic ships with 24 examples and 3 showcase apps covering forms, tables, markdown, syntax highlighting, charts, async commands, tree widgets, CSS Grid layouts, and more. See mosaic/examples/.
Matrix has 15 examples and 1 showcase demonstrating rain animation, game of life, mandelbrot rendering, snake, a synthesizer, and a terminal emulator. See matrix/examples/.
Run any example from the repo root:
# Mosaic: form with focus management
dune exec ./mosaic/examples/12-form/main.exe
# Mosaic: ML dashboard showcase
dune exec ./mosaic/examples/x-dashboard/main.exe
# Matrix: rain animation
dune exec ./matrix/examples/01-rain/main.exeLicense
ISC. See LICENSE.