Skip to main content

Crate termosaic_ratatui

Crate termosaic_ratatui 

Source
Expand description

Ratatui rendering for Termosaic styled documents.

Termosaic lays out semantic documents; this crate converts the resulting StyledLine values into ratatui-core text. A raw Buffer, a Paragraph, or another compatible host paints them without ANSI escapes.

use ratatui_core::buffer::Buffer;
use ratatui_core::layout::Rect;
use termosaic::{AnsiColor, Color, Doc, HumanLayoutOptions, Theme, TokenStyle, tokens};

let theme = Theme::builder("demo")
    .rule(
        tokens::STATUS_SUCCESS,
        TokenStyle::bold(Color::Ansi(AnsiColor::Green)),
    )?
    .build()?;
let doc = Doc::token_text(tokens::STATUS_SUCCESS, "ready");

let area = Rect::new(0, 0, 20, 1);
let mut buffer = Buffer::empty(area);
termosaic_ratatui::render_doc(
    &doc,
    &theme,
    HumanLayoutOptions::fast(),
    area,
    &mut buffer,
)?;
assert_eq!(buffer.cell((0, 0)).expect("cell in area").symbol(), "r");

Layout runs at a chosen column width in Termosaic; conversion here is width-independent. Re-render the document when the target area’s width changes. render_doc handles that common path directly; prepare the document once and retain a RatatuiRenderer when painting it repeatedly.

Re-exports§

pub use ratatui_core;

Structs§

NativeStyleConverter
Default one-to-one Termosaic-to-Ratatui style conversion.
RatatuiRenderer
Retained Termosaic-to-Ratatui renderer for frame-driven hosts.

Traits§

StyleConverter
Converts Termosaic color and style policy for a Ratatui host.

Functions§

render_doc
Lays out and paints a document using the target area’s current width.
render_prepared_doc
Paints a prepared document using the target area’s current width.
to_color
Converts a Termosaic terminal color into a ratatui color.
to_color_at_depth
Converts a Termosaic color for a specific terminal color depth.
to_line
Converts one styled line into a ratatui line, borrowing its text.
to_line_with
Converts one styled line through a host-supplied style policy.
to_style
Converts a resolved Termosaic token style into a ratatui style.
to_style_with
Converts a resolved token style through a host-supplied policy.
to_text
Converts styled lines into ratatui text, borrowing their text.
to_text_with
Converts styled lines through a host-supplied style policy.