Skip to main content

Crate ratatui_style

Crate ratatui_style 

Source
Expand description

§ratatui-style

A CSS cascade engine for ratatui — selectors, specificity, inheritance, pseudo-states, and data-driven styling. Produces native ratatui Style / Block / Constraint values; it is never a parallel rendering stack.

See design.md for the full RFC.

§Quick start (L1 — stylesheet + class)

use ratatui_style::{CssStyle, Origin, OwnedNode, Stylesheet};

let mut sheet = Stylesheet::new();
sheet.add(
    "Button.primary",
    CssStyle::new().color("#fff").background("blue").bold(),
    Origin::User,
)
.unwrap();

let node = OwnedNode::new("Button").with_classes(["primary"]);
let computed = sheet.compute(&node, None);
let _ratatui_style = computed.to_style();

Re-exports§

pub use box_model::BorderSpec;
pub use box_model::BorderStyle;
pub use box_model::BorderStyleValue;
pub use box_model::BoxEdges;
pub use box_model::BoxEdgesValue;
pub use box_model::IntoBorderSpec;
pub use box_model::IntoBoxEdges;
pub use box_model::Length;
pub use cache::ComputeCache;
pub use cascade::render_computed;
pub use cascade::CascadeContext;
pub use cascade::ComputedStyle;
pub use cascade::ComputeScratch;
pub use color::Color;
pub use error::CssError;
pub use error::CssErrorKind;
pub use error::Loc;
pub use error::Result;
pub use media::MediaAlternative;
pub use media::MediaCondition;
pub use media::MediaContext;
pub use media::MediaQuery;
pub use media::MediaTerm;
pub use node::Classes;
pub use node::NodeRef;
pub use node::OwnedNode;
pub use node::Position;
pub use node::State;
pub use node::StyledNode;
pub use runtime::RuntimeStyle;
pub use selector::Combinator;
pub use selector::NthExpr;
pub use selector::Pseudo;
pub use selector::PseudoClass;
pub use selector::Selector;
pub use style::Align;
pub use style::CssStyle;
pub use style::FontStyle;
pub use style::TextDecoration;
pub use style::Weight;
pub use stylesheet::apply_decl;
pub use stylesheet::Origin;
pub use stylesheet::RuleEntry;
pub use stylesheet::Stylesheet;
pub use supports::SupportsAlternative;
pub use supports::SupportsCondition;
pub use supports::SupportsQuery;
pub use supports::SupportsTerm;
pub use token::ThemeTokens;

Modules§

box_model
Box-model value types: padding, margin, border, and sizing lengths.
cache
An opt-in LRU cache for ComputedStyle results.
cascade
The cascade engine — turns a Stylesheet + a StyledNode into a fully resolved ComputedStyle.
color
CSS color syntax → ratatui Color.
css_macro
Compile-time CSS embedding via the css! macro.
error
Error type for the CSS engine.
media
@media query support — conditional rules based on terminal size and color capability.
node
Framework-agnostic element view: the StyledNode trait and supporting types. The cascade engine knows nothing about a2ui, ratatui widgets, or any particular framework — it only knows a StyledNode.
prelude
Convenience re-exports — use ratatui_style::prelude::*; to pull in the common public surface in one line.
runtime
Runtime-overridable stylesheets.
selector
CSS selectors — the pragmatic subset: compound selectors of the form Type.class#id:pseudo… (plus comma lists and the * universal).
style
CssStyle — a CSS declaration block projected onto ratatui primitives.
stylesheet
Stylesheet — a collection of Rules plus a token table, with a small CSS text parser and a builder API.
supports
@supports query support — conditional rules based on terminal/engine capability.
token
CSS custom properties — the var() resolution target.

Macros§

css
Embed CSS at compile time and lazily parse it into a std::sync::LazyLock<Stylesheet>.