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§
- Native
Style Converter - Default one-to-one Termosaic-to-Ratatui style conversion.
- Ratatui
Renderer - Retained Termosaic-to-Ratatui renderer for frame-driven hosts.
Traits§
- Style
Converter - 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.