Skip to main content

Renderable

Trait Renderable 

Source
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> { ... }
    fn print_end_line(&self, _options: &ConsoleOptions) -> bool { ... }
}
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§

Source

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Provided Methods§

Source

fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement

The (minimum, maximum) cell width this renderable wants. Port of __rich_measure__. The default is what upstream’s Measurement.get returns for a renderable without one: anything from nothing to the whole width, (0, max_width).

Source

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.

Source

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.

Source

fn print_end_line(&self, _options: &ConsoleOptions) -> bool

Whether a top-level print ends this renderable’s last line. This port’s renderables separate lines, where upstream’s end each line with "\n", so a print adds the final line break. A renderable whose upstream output stops without one (Screen, LiveRender, a Rule whose end has no newline) returns false, and the next output continues its last line. options are the print’s options.

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.

Source§

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.

Source§

fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>

Implementors§

Source§

impl Renderable for Align

Source§

impl Renderable for Bar

Source§

impl Renderable for Color

A color prints as its description and a dot in the color. Port of Color.__rich__.

Source§

impl Renderable for Columns

Source§

impl Renderable for Constrain

Source§

impl Renderable for Control

Source§

impl Renderable for Emoji

Source§

impl Renderable for Json

Source§

impl Renderable for Layout

Source§

impl Renderable for Lines

Source§

impl Renderable for LiveRender

Source§

impl Renderable for LogRecord

Source§

impl Renderable for Markdown

Source§

impl Renderable for Padding

Source§

impl Renderable for Palette

A palette prints as a table of its colors. Port of Palette.__rich__.

Source§

impl Renderable for Panel

Source§

impl Renderable for Pretty

Source§

impl Renderable for Progress

Source§

impl Renderable for ProgressBar

Source§

impl Renderable for Renderables

Source§

impl Renderable for Rule

Source§

impl Renderable for Screen

Source§

impl Renderable for ScreenUpdate

Source§

impl Renderable for SegmentLines

Source§

impl Renderable for Segments

Source§

impl Renderable for Spinner

Source§

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.

Source§

impl Renderable for Styled

Source§

impl Renderable for Syntax

Source§

impl Renderable for Table

Source§

impl Renderable for Text

Source§

impl Renderable for Traceback

Source§

impl Renderable for Tree

Source§

impl Renderable for VerticalCenter