xript-ratatui
Fragment renderer for xript: turns application/x-ratatui+json fragments into native Ratatui terminal widgets.
Install
[]
= "0.3"
Usage
use HashMap;
use render_json_fragment;
use json;
let fragment = json!;
let mut bindings = new;
bindings.insert;
bindings.insert;
bindings.insert;
// Inside your Ratatui draw closure:
terminal.draw?;
What it does
- Parses
application/x-ratatui+jsonfragments (JsonML format) into a widget tree - Renders the tree as native Ratatui widgets (Block, Paragraph, Gauge, Layout, List, Table, Sparkline)
- Resolves
data-bindattributes against a bindings map at render time - Supports
data-iffor conditional widget visibility - Handles nested layouts with directional constraints (
Length,Percentage,Fill,Min,Max,Ratio) - No runtime JavaScript; this is pure Rust parsing and rendering
API
render_json_fragment(frame, area, json, bindings)
One-call render. Parses a JSON fragment and renders it into the given frame area. Bindings are resolved during parsing.
parse_fragment(json, bindings) -> Option<WidgetNode>
Parses a serde_json::Value into a widget tree. Returns None for unrecognized or empty input.
render_fragment(frame, area, node, bindings)
Renders a previously parsed WidgetNode tree into the frame.
parse_style(value) -> Style
Parses a JSON style object ({"fg": "Green", "bg": "Black", "bold": true}) into a Ratatui Style.
parse_constraint(value) -> Option<Constraint>
Parses a constraint string ("Length:1", "Percentage:50", "Fill:1") into a Ratatui Constraint.
Supported widgets
| Widget | Attributes | Children |
|---|---|---|
Block |
title, borders, border_type, border_style |
Any widget |
Paragraph |
alignment, style, data-if |
Line elements |
Gauge |
data-bind, ratio_bind, gauge_style, label, data-if |
None |
Layout |
direction, constraints, data-if |
Any widget |
List |
style, data-if |
String items |
Table |
header, widths, style, data-if |
Row arrays |
Sparkline |
data, data-bind, style, data-if |
None |
Documentation
xript.dev: full docs, fragment specification, and format catalog.
License
MIT