package toffee
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
CSS layout engine for OCaml (Flexbox, Grid, Block)
Install
dune-project
Dependency
Authors
Maintainers
Sources
mosaic-0.1.0.tbz
sha256=9e4e90d17f9b2af1b07071fe425bc2c519c849c4f1d1ab73cde512be2d874849
sha512=06e9c4a741590942e81a27738d0b5c0413fafec8cf3b7dae047ad69f155e7b718aa4223818dc161b7d028efffcfd3365905e264d6fd31d453910ddfa91dcf9b9
doc/CHANGES.html
Changelog
[0.1.0] - Unreleased
Mosaic
Terminal UI framework for OCaml built on Matrix and Toffee. Implements The Elm Architecture (TEA) for declarative, composable terminal applications.
- The Elm Architecture – Pure functional Model-View-Update pattern with
init,update,view, andsubscriptions. Commands (Cmd) handle side effects; subscriptions (Sub) handle external events - Flexbox and Grid layout – Powered by Toffee, define complex layouts with familiar CSS properties like
flex_direction,align_items,justify_content, and CSS Grid support - Rich widget library –
box,text,input,textarea,select,tab_select,slider,table,spinner,scroll_box,canvas,code,markdown,tree,progress_bar, andline_number - Rich text – Styled fragments, word/character wrapping, text selection, and full Unicode support
- Syntax highlighting – Tree-sitter-based code highlighting with the
codewidget - Event system – Mouse, keyboard, paste, focus, and resize events with
Sub.on_key,Sub.on_mouse,Sub.on_paste,Sub.on_resize,Sub.on_focus, andSub.on_blur - Canvas drawing – Procedural drawing API with shapes, lines, and braille patterns for charts and visualizations
- Markdown rendering – CommonMark rendering with the
markdownwidget - Dirty tracking and viewport culling – Only re-layouts dirty subtrees; scroll containers cull off-screen children
Matrix
Terminal toolkit for OCaml providing rendering, input, and terminal management.
- Immediate-mode runtime –
Matrix.runwithon_frame,on_render,on_input,on_resizecallbacks, configurable FPS capping, and safe teardown that restores terminal state even on exceptions - Two display modes – Full-screen alternate buffer (
Alt) or inline on primary screen (Primary) with dynamic height and full scrollback - Declarative Image API – Notty-inspired compositional DSL with
hcat,vcat,overlay, padding, cropping, and hit regions for mouse interaction - Full Unicode support – Grapheme cluster handling, emoji, wide characters, and configurable width calculation (wcwidth, Unicode tables)
- Modern terminal protocols – Kitty keyboard (with auto-detection), SGR/X10/URXVT mouse tracking, bracketed paste, focus reporting—all negotiated automatically
- Native alpha blending – RGBA colors with proper alpha compositing for translucent overlays
- Double-buffered diffing – Screen module diffs cell changes between frames to emit minimal ANSI output
- PTY & VTE – Spawn processes in pseudo-terminals and embed terminal output in your UI; cross-platform with Windows ConPTY support
- Automatic capability detection – Two-stage probing (environment heuristics + active queries) detects RGB, Kitty keyboard, sixel, hyperlinks, and Unicode width support without manual configuration
- Hit testing – O(1) spatial indexing maps mouse coordinates to UI element IDs for clickable widgets
- Built-in devtools – Debug overlay for frame timing/FPS, frame dumps to disk for diagnostics
Toffee
CSS layout engine for OCaml, ported from Taffy (Rust).
- CSS Grid Level 1 – Full implementation including
grid-template-columns/rows,grid-auto-flow, named lines/areas,repeat(),minmax(),frunits, and auto-placement - Flexbox – Complete algorithm with
flex-direction,flex-wrap,flex-grow/shrink/basis,align-items/self/content,justify-content,gap, andorder - Block layout – Traditional CSS block formatting context with proper margin collapsing
- Pure OCaml, zero dependencies – No C stubs, no runtime dependencies; works wherever OCaml 5 runs
- Arena storage and layout caching – Nodes stored in a flat arena; layout results cached and invalidated via
mark_dirty - Composable architecture – Use the high-level
Toffeetree API or the lower-leveltoffee.treeandtoffee.computelibraries to plug layout into your own node representation - Custom measure functions – Integrate text shaping, images, or any content with intrinsic sizing via
compute_layout_with_measure
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page