Skip to main content

Crate taria_ratatui

Crate taria_ratatui 

Source
Expand description

Ratatui adapter for taria, the agent accessibility layer for terminal UIs.

Embed a TariaLayer in your ratatui app and each rendered frame can also publish a semantic taria::Snapshot over the taria transport (one JSON message per line over a Unix domain socket on Linux and macOS, or a named pipe on Windows). Agent inputs come back as taria::AgentInput values your event loop handles like any other input source.

taria::AgentInput::Text is the one that needs aiming rather than handling: typed text belongs wherever your app puts typing, not in your key handler, or an agent’s two characters meet your bindings instead of your text field. Route it to that surface yourself, and use text_to_keys to lower it if the surface is made of key events.

§Usage

use ratatui::widgets::Paragraph;
use taria::{Node, Role};
use taria_ratatui::{InputStatus, TariaLayer, sem};

fn main() -> std::io::Result<()> {
    // Never fails: if the socket (a named pipe on Windows) cannot be
    // bound, the layer is inert and the app runs exactly as it would
    // without taria.
    let mut layer = TariaLayer::bind_or_disabled("my-app");
    let mut terminal = ratatui::init();

    // Each render pass: record semantics alongside drawing, then publish.
    let rec = layer.frame();
    terminal.draw(|frame| {
        let widget = Paragraph::new("hello");
        let node = Node::new("greeting", Role::Text).label("hello");
        frame.render_widget(sem(&rec, widget, node), frame.area());
    })?;
    rec.publish();

    // Drain agent input alongside terminal events. Each input is acked
    // `Delivered` as it is handed over; return `Ignored` for one you
    // looked at and deliberately did nothing with, and the layer sends it.
    layer.drain(|_input| {
        // Apply to app state exactly like a keyboard event.
        InputStatus::Delivered
    });

    ratatui::restore();
    // Only now the alternate screen is gone is printing safe.
    if let Some(err) = layer.bind_error() {
        eprintln!("taria disabled: {err}");
    }
    Ok(())
}

Re-exports§

pub use taria;

Structs§

FrameRecorder
Records the semantic nodes of one rendered frame.
InputId
Identifier the bridge assigns to one input so the app’s acknowledgement can be matched back to it.
LayerStats
What a TariaLayer has lost or cut so far, from TariaLayer::stats.
Semantic
A widget paired with its semantic node; created by sem.
SnapshotTooLarge
A snapshot too large for one taria line, and what was cut to make it fit.
TariaLayer
The embeddable taria endpoint for a ratatui app.

Enums§

InputStatus
Fate of one input, reported back by the app.

Functions§

sem
Wrap a widget with its semantic Node so rendering it also records the node into the current frame.
text_to_keys
Lower literal text into one key event per character, for an app whose typing surface consumes key events, such as a text field.
to_crossterm
Lower an already-parsed KeyPress into a crossterm KeyEvent, or None for a key this build cannot express.
to_crossterm_key
Parse a key description from a taria::AgentInput::Key message into a crossterm KeyEvent (via ratatui’s crossterm re-export).