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§
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. 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).
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.
Sourcefn print_end_line(&self, _options: &ConsoleOptions) -> bool
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.
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 Color
A color prints as its description and a dot in the color. Port of
Color.__rich__.
impl Renderable for Columns
impl Renderable for Constrain
impl Renderable for Control
impl Renderable for Emoji
impl Renderable for Json
impl Renderable for Layout
impl Renderable for Lines
impl Renderable for LiveRender
impl Renderable for LogRecord
impl Renderable for Markdown
impl Renderable for Padding
impl Renderable for Palette
A palette prints as a table of its colors. Port of Palette.__rich__.
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 SegmentLines
impl Renderable for Segments
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.