Expand description
§ratatui_unity
A C ABI wrapper around [ratatui] that renders terminal UIs to RGB24
pixel buffers, suitable for embedding in game engines (e.g. Unity).
The crate is compiled as both cdylib and staticlib so that it can be
consumed from any host capable of calling C functions. All public entry
points are extern "C" and #[no_mangle]; there is no idiomatic Rust API.
§High-level flow
- Create a terminal handle with
ratatui_create. - For each frame:
- Call
ratatui_begin_frameto reset per-frame state. - Build a layout tree with
ratatui_split/ratatui_inner. - Optionally set a style with
ratatui_set_stylebefore any widget call. - Queue widget commands (e.g.
ratatui_block,ratatui_paragraph,ratatui_chart_begin/ratatui_chart_end, …). - Call
ratatui_end_frame(orratatui_end_frame_hashed) to draw the queue and rasterize the cell grid into an RGB24 pixel buffer.
- Call
- When done, call
ratatui_destroyto release the handle.
§Memory & lifetime
The handle returned by ratatui_create is an opaque pointer to a
heap-allocated TerminalState. The pixel
buffer pointer returned by ratatui_end_frame* is owned by the handle and
is only valid until the next FFI call that mutates the handle. The caller
must copy the bytes before issuing further calls if it wants to retain them.
§Safety
All FFI entry points perform null-pointer checks on the handle and on any
pointer argument they dereference. Strings are read as null-terminated
*const c_char. Slices passed as (ptr, len) pairs must reference valid
memory for the duration of the call.
Functions§
- ratatui_
barchart - Queues a
BarChart. - ratatui_
begin_ frame - Begins a new frame.
- ratatui_
block - Queues a
Blockwidget with an optional title and per-edge borders. - ratatui_
calendar - Queues a monthly calendar
(
Monthly). - ratatui_
canvas_ begin - Starts a
Canvasbuilder. - ratatui_
canvas_ circle - Draws a colored circle centered at
(x, y)with the givenradius. - ratatui_
canvas_ end - Finalizes the pending canvas and queues it for rendering.
- ratatui_
canvas_ layer - Flushes the current canvas layer.
- ratatui_
canvas_ line - Draws a colored line from
(x1, y1)to(x2, y2)on the pending canvas. - ratatui_
canvas_ map - Draws the world map on the pending canvas.
- ratatui_
canvas_ points - Draws a colored point cloud on the pending canvas.
- ratatui_
canvas_ rectangle - Draws a colored rectangle outline anchored at
(x, y)with size(w, h). - ratatui_
canvas_ text - Draws colored text anchored at
(x, y)on the pending canvas. - ratatui_
chart_ begin - Starts a
Chartbuilder. - ratatui_
chart_ dataset - Adds a
Datasetto the pending chart. - ratatui_
chart_ end - Finalizes the pending chart and queues it for rendering.
- ratatui_
chart_ x_ axis - Sets the X axis title and
[min, max]data bounds of the pending chart. - ratatui_
chart_ y_ axis - Sets the Y axis title and
[min, max]data bounds of the pending chart. - ratatui_
create - Creates a terminal instance and returns an opaque handle.
- ratatui_
destroy - Destroys a terminal handle created by
ratatui_create. - ratatui_
end_ frame - Renders all queued widget commands and rasterizes the cell buffer.
- ratatui_
end_ frame_ hashed - Like
ratatui_end_frame, but skips rasterization when the cell buffer is unchanged from the previous frame (hash-based dirty check). Returns a valid pixel pointer when content changed, or null when unchanged. The previous frame’s pixel buffer remains valid when null is returned. - ratatui_
gauge - Queues a block-style
Gauge. - ratatui_
get_ area_ rect - Returns the cell-space rectangle of the given area as a packed
u64. - ratatui_
hit_ test - Returns the most specific area id covering the given terminal cell.
- ratatui_
inner - Returns a new area id covering the inner rectangle of
area_idshrunk by the given margins on each side. - ratatui_
line_ gauge - Queues a horizontal single-line
LineGauge. - ratatui_
list - Queues a
Listwidget. - ratatui_
paragraph - Queues a uniformly styled
Paragraph. - ratatui_
pixel_ height - Returns the height of the pixel buffer in pixels (
rows * cell_height). - ratatui_
pixel_ width - Returns the width of the pixel buffer in pixels (
cols * cell_width). - ratatui_
root_ area - Returns the id of the root area, which always covers the whole terminal.
- ratatui_
scrollbar - Queues a
Scrollbar. - ratatui_
set_ background_ color - Sets the RGB background color used by the rasterizer for cells whose
background is [
Color::Reset]. - ratatui_
set_ custom_ font - Replaces the embedded JetBrains Mono font with custom TTF bytes.
- ratatui_
set_ style - Sets the pending style consumed by the next widget-producing FFI call.
- ratatui_
sparkline - Queues a
Sparklinefrom rawu64samples. - ratatui_
split - Splits an existing area into
countchild areas and writes their ids intoout_ids. - ratatui_
styled_ para_ begin - Starts a multi-style paragraph builder.
- ratatui_
styled_ para_ end - Finalizes the pending styled paragraph and queues it for rendering.
- ratatui_
styled_ para_ newline - Starts a new line in the pending styled paragraph.
- ratatui_
styled_ para_ span - Appends a styled
Spanto the current line of the pending styled paragraph. - ratatui_
table - Queues a
Tablewith equal-width columns. - ratatui_
table_ ex - Queues an extended
Tablewith typed column widths and optional row highlighting. - ratatui_
tabs - Queues a
Tabsbar. - ratatui_
version - Returns the library version as a static null-terminated C string.