pub trait Renderable {
// Required method
fn rich_render(
&self,
console: &Console,
options: &ConsoleOptions,
) -> Vec<Segment>;
// Provided methods
fn measure(
&self,
_console: &Console,
options: &ConsoleOptions,
) -> Measurement { ... }
fn fit_to_measurement(&self) -> bool { ... }
fn vertical(&self) -> Option<VerticalAlign> { ... }
}Expand description
Anything that can be rendered to a stream of Segments within a width.
The Rust equivalent of upstream’s __rich_console__(console, options)
protocol. Implement it to make a custom type printable by Console. The
options carry the available width (and, later, height/justify) the
renderable must fit into. Newlines between lines are emitted as ordinary
segments containing \n.
Required Methods§
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Provided Methods§
Sourcefn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
The (minimum, maximum) cell width this renderable wants. The default
assumes the renderable fills the available width (e.g. Panel, Table);
Text overrides it with its content width so the top-level print path can
shrink to fit. Port of __rich_measure__ / Measurement.get.
Sourcefn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Whether a top-level Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.
Sourcefn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
The vertical alignment a Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl Renderable for String
A string renders as upstream’s Console.render renders a str: through
Console::render_str with the options’ highlight and markup
(None taking the console’s defaults), then as that Text. Malformed
markup falls back to the literal text, as render_str does.
impl Renderable for String
A string renders as upstream’s Console.render renders a str: through
Console::render_str with the options’ highlight and markup
(None taking the console’s defaults), then as that Text. Malformed
markup falls back to the literal text, as render_str does.
Source§fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
Measurement.get of a str: render_str(markup=options.markup, highlight=False), then the text’s measurement.
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Implementors§
impl Renderable for Align
impl Renderable for Bar
impl Renderable for Columns
impl Renderable for Constrain
impl Renderable for Control
impl Renderable for Json
impl Renderable for Layout
impl Renderable for LiveRender
impl Renderable for LogRecord
impl Renderable for Markdown
impl Renderable for Padding
impl Renderable for Panel
impl Renderable for Pretty
impl Renderable for Progress
impl Renderable for ProgressBar
impl Renderable for Renderables
impl Renderable for Rule
impl Renderable for Screen
impl Renderable for ScreenUpdate
impl Renderable for Spinner
impl Renderable for Status
Upstream’s Status.__rich__ returns the spinner, so a status renders (and
measures) exactly as its spinner: the frame for the console’s clock.