pub struct Table { /* private fields */ }Expand description
A grid of cells rendered inside a box. Mirrors rich.table.Table.
Implementations§
Source§impl Table
impl Table
pub fn new() -> Self
Sourcepub fn grid() -> Self
pub fn grid() -> Self
A table with no borders, for laying out columns. Port of Table.grid:
box=None, no header or edge, padding=0, collapse_padding=True and
pad_edge=False.
Sourcepub fn without_box(self) -> Self
pub fn without_box(self) -> Self
Draw no borders and no column dividers (upstream box=None).
Sourcepub fn padding(
self,
top: usize,
right: usize,
bottom: usize,
left: usize,
) -> Self
pub fn padding( self, top: usize, right: usize, bottom: usize, left: usize, ) -> Self
Cell padding as (top, right, bottom, left) (upstream padding).
Sourcepub fn border_style(self, style: Style) -> Self
pub fn border_style(self, style: Style) -> Self
Style the box border (edges + dividers). Composed over the table-level
style: border = style + border_style. Port of Table(border_style=…).
Sourcepub fn show_header(self, show: bool) -> Self
pub fn show_header(self, show: bool) -> Self
Whether to render the header row.
Sourcepub fn show_lines(self, show: bool) -> Self
pub fn show_lines(self, show: bool) -> Self
Draw a separator line between each body row.
Sourcepub fn show_edge(self, show: bool) -> Self
pub fn show_edge(self, show: bool) -> Self
Draw the outer box edges (top/bottom borders + left/right glyphs). When
off, only the internal dividers and content remain. Port of show_edge.
Sourcepub fn pad_edge(self, pad: bool) -> Self
pub fn pad_edge(self, pad: bool) -> Self
Pad the outer cell edges. When off, the first column drops its left pad
and the last column its right pad. Port of pad_edge.
Sourcepub fn collapse_padding(self, collapse: bool) -> Self
pub fn collapse_padding(self, collapse: bool) -> Self
Merge adjacent cell padding: an interior column’s left pad is reduced by
the previous column’s right pad. Port of collapse_padding.
Sourcepub fn style(self, style: Style) -> Self
pub fn style(self, style: Style) -> Self
Default style for the whole table. Upstream applies it as the base of the
border style (border_style = style + border_style); cell content keeps
its own styles. Port of Table(style=…).
Sourcepub fn highlight(self, highlight: bool) -> Self
pub fn highlight(self, highlight: bool) -> Self
Highlight string cells with the console’s highlighter (upstream
Table(highlight=…), default off). Columns added without their own
setting use it.
Sourcepub fn title(self, title: impl Into<String>) -> Self
pub fn title(self, title: impl Into<String>) -> Self
A title rendered above the table (console markup, centered by default).
Sourcepub fn caption(self, caption: impl Into<String>) -> Self
pub fn caption(self, caption: impl Into<String>) -> Self
A caption rendered below the table (console markup).
Sourcepub fn title_text(self, title: Text) -> Self
pub fn title_text(self, title: Text) -> Self
A Text title (upstream title=Text(...)): rendered as it is, in
its own style and justify, with no title_style.
Sourcepub fn caption_text(self, caption: Text) -> Self
pub fn caption_text(self, caption: Text) -> Self
A Text caption (upstream caption=Text(...)).
Sourcepub fn title_style(self, style: impl Into<StyleType>) -> Self
pub fn title_style(self, style: impl Into<StyleType>) -> Self
The style of a markup title (upstream title_style; default
table.title).
Sourcepub fn caption_style(self, style: impl Into<StyleType>) -> Self
pub fn caption_style(self, style: impl Into<StyleType>) -> Self
The style of a markup caption (upstream caption_style; default
table.caption).
Sourcepub fn title_justify(self, justify: Justify) -> Self
pub fn title_justify(self, justify: Justify) -> Self
How the title is justified (upstream title_justify, default center).
Sourcepub fn caption_justify(self, justify: Justify) -> Self
pub fn caption_justify(self, justify: Justify) -> Self
How the caption is justified (upstream caption_justify).
Sourcepub fn header_style(self, style: impl Into<StyleType>) -> Self
pub fn header_style(self, style: impl Into<StyleType>) -> Self
The header row’s style (upstream header_style, default
table.header). A column’s own header style combines over it.
The footer row’s style (upstream footer_style, default
table.footer).
Sourcepub fn width(self, width: Option<usize>) -> Self
pub fn width(self, width: Option<usize>) -> Self
The table’s width, borders included (upstream width). Setting it
expands the table to exactly that width.
Sourcepub fn min_width(self, min_width: Option<usize>) -> Self
pub fn min_width(self, min_width: Option<usize>) -> Self
The table’s minimum width, borders included (upstream min_width).
Render a footer row from each column’s footer (upstream
show_footer).
Sourcepub fn leading(self, leading: usize) -> Self
pub fn leading(self, leading: usize) -> Self
Blank lines between rows (upstream leading); takes precedence over
show_lines.
Sourcepub fn row_styles(self, styles: Vec<StyleType>) -> Self
pub fn row_styles(self, styles: Vec<StyleType>) -> Self
Styles body rows cycle through (upstream row_styles).
Sourcepub fn safe_box(self, safe_box: Option<bool>) -> Self
pub fn safe_box(self, safe_box: Option<bool>) -> Self
Whether to substitute boxes a legacy Windows console cannot draw
(upstream safe_box; None takes the console’s).
Sourcepub fn is_expand(&self) -> bool
pub fn is_expand(&self) -> bool
Whether the table expands: expand, or any explicit width. Port
of the Table.expand property.
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
The number of columns.
Sourcepub fn get_row_style(&self, console: &Console, index: usize) -> Style
pub fn get_row_style(&self, console: &Console, index: usize) -> Style
The style of body row index: its place in row_styles, then its
own style. Port of Table.get_row_style.
Sourcepub fn add_section(&mut self) -> &mut Self
pub fn add_section(&mut self) -> &mut Self
End the current section: draw a line beneath the last row. Port of
Table.add_section.
Sourcepub fn add_column(&mut self, header: impl Into<String>) -> &mut Self
pub fn add_column(&mut self, header: impl Into<String>) -> &mut Self
Add a left-justified column with the given header, which is console
markup as upstream’s add_column("[b]Name") is.
Sourcepub fn add_column_justify(
&mut self,
header: impl Into<String>,
justify: Justify,
) -> &mut Self
pub fn add_column_justify( &mut self, header: impl Into<String>, justify: Justify, ) -> &mut Self
Add a column with an explicit justification. The header is console
markup; use add_column_text for a literal one.
Sourcepub fn add_column_text(&mut self, header: Text, justify: Justify) -> &mut Self
pub fn add_column_text(&mut self, header: Text, justify: Justify) -> &mut Self
Add a column whose header is a styled Text, as upstream’s
add_column(header=Text(...)) does. The text’s spans survive into the
header cell; its own justify, overflow and no_wrap override the
column’s, as Text.__rich_console__ prefers them over the options.
Sourcepub fn add_column_cell(&mut self, header: Cell, justify: Justify) -> &mut Self
pub fn add_column_cell(&mut self, header: Cell, justify: Justify) -> &mut Self
Add a column whose header is any Cell (upstream’s header is any
renderable).
Set the most-recently-added column’s footer (upstream
Column.footer), shown with show_footer.
Style the most-recently-added column’s whole footer cell, combined
over the table-level footer_style (upstream Column.footer_style).
Sourcepub fn add_column_with(
&mut self,
header: Text,
options: ColumnOptions,
) -> &mut Self
pub fn add_column_with( &mut self, header: Text, options: ColumnOptions, ) -> &mut Self
Add a column with every ColumnOptions set, as upstream’s
add_column(header, justify=…, width=…, ratio=…, …) does.
Sourcepub fn column_vertical(&mut self, vertical: VerticalAlign) -> &mut Self
pub fn column_vertical(&mut self, vertical: VerticalAlign) -> &mut Self
Set the vertical alignment of the most-recently-added column’s body
cells (upstream Column.vertical, default top). A cell whose
renderable has its own vertical
uses that instead. Chain after add_column.
Sourcepub fn column_width(&mut self, width: usize) -> &mut Self
pub fn column_width(&mut self, width: usize) -> &mut Self
Pin the most-recently-added column to an explicit content width. Content
wider than this wraps (with ellipsis overflow) instead of shrinking the
column. Chain after add_column.
Sourcepub fn column_ratio(&mut self, ratio: usize) -> &mut Self
pub fn column_ratio(&mut self, ratio: usize) -> &mut Self
Give the most-recently-added column a flex ratio: when the table is
expanded, ratio columns share the free width in proportion. Chain after
add_column. Port of Column.ratio.
Sourcepub fn column_min_width(&mut self, min_width: usize) -> &mut Self
pub fn column_min_width(&mut self, min_width: usize) -> &mut Self
Set a minimum content width on the most-recently-added column. Chain after
add_column. Port of Column.min_width.
Sourcepub fn column_max_width(&mut self, max_width: usize) -> &mut Self
pub fn column_max_width(&mut self, max_width: usize) -> &mut Self
Set a maximum content width on the most-recently-added column — wider
cells wrap. Chain after add_column. Port of Column.max_width.
Sourcepub fn column_style(&mut self, style: Style) -> &mut Self
pub fn column_style(&mut self, style: Style) -> &mut Self
Apply a style to the most-recently-added column’s body cells. Chain after
add_column.
Sourcepub fn column_header_style(&mut self, style: Style) -> &mut Self
pub fn column_header_style(&mut self, style: Style) -> &mut Self
Style the most-recently-added column’s header content (the visible
characters), leaving its padding as the base header_style. Chain after
add_column. Mirrors upstream stylizing the heading Text.
Sourcepub fn column_header_fill(&mut self, style: Style) -> &mut Self
pub fn column_header_fill(&mut self, style: Style) -> &mut Self
Style the most-recently-added column’s whole header cell (content +
padding), combined over the table-level header_style. Chain after
add_column. Port of Column.header_style.
Sourcepub fn column_overflow(&mut self, overflow: Overflow) -> &mut Self
pub fn column_overflow(&mut self, overflow: Overflow) -> &mut Self
Set how the most-recently-added column handles over-long text (upstream
Column.overflow, default ellipsis). Chain after add_column.
Sourcepub fn column_highlight(&mut self, highlight: bool) -> &mut Self
pub fn column_highlight(&mut self, highlight: bool) -> &mut Self
Set whether the most-recently-added column highlights its string cells
(upstream Column.highlight). Chain after add_column.
Sourcepub fn column_no_wrap(&mut self) -> &mut Self
pub fn column_no_wrap(&mut self) -> &mut Self
Mark the most-recently-added column no_wrap: its cells crop to a single
line (with ellipsis) instead of wrapping. Chain after add_column.
Sourcepub fn add_row(&mut self, cells: &[&str]) -> &mut Self
pub fn add_row(&mut self, cells: &[&str]) -> &mut Self
Add a row of string cells (extra cells are ignored; missing cells render
empty). Each string is console markup, as upstream’s add_row("[b]x")
is, so a [ in data can restyle or hide the rest of the cell: for
data you do not control use add_row_text with
Text::new(..) cells, which are never parsed.
Sourcepub fn add_row_with(
&mut self,
cells: Vec<Cell>,
style: Option<StyleType>,
end_section: bool,
) -> &mut Self
pub fn add_row_with( &mut self, cells: Vec<Cell>, style: Option<StyleType>, end_section: bool, ) -> &mut Self
Add a row with upstream’s keyword options: a style for the whole
row and end_section to draw a line beneath it. Port of
add_row(*renderables, style=…, end_section=…).
Sourcepub fn add_row_text(&mut self, cells: Vec<Text>) -> &mut Self
pub fn add_row_text(&mut self, cells: Vec<Text>) -> &mut Self
Add a row of styled Text cells, as upstream’s add_row(Text(...)).
Each cell keeps its spans, and its own justify, overflow and
no_wrap override the column’s.
Sourcepub fn add_row_cells(&mut self, cells: Vec<Cell>) -> &mut Self
pub fn add_row_cells(&mut self, cells: Vec<Cell>) -> &mut Self
Add a row of Cells, which may be any renderable.
Trait Implementations§
Source§impl LineRenderable for Table
impl LineRenderable for Table
Source§fn try_for_each_line<E>(
&self,
console: &Console,
options: &ConsoleOptions,
emit: impl FnMut(Vec<Segment>) -> Result<(), E>,
) -> Result<(), E>
fn try_for_each_line<E>( &self, console: &Console, options: &ConsoleOptions, emit: impl FnMut(Vec<Segment>) -> Result<(), E>, ) -> Result<(), E>
Render visual lines in order without retaining the full rendered table.
Like upstream’s Table.__rich_console__ / _render generators, this
measures all columns first, then renders only one row block at a time.
Lines contain styled segments without a trailing newline. The callback
may write each line immediately; its first error stops rendering.
The table still owns its source rows for column-width measurement.
Source§impl OwnedTableRows for Table
impl OwnedTableRows for Table
Source§impl Renderable for Table
impl Renderable for Table
Source§fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
Port of Table.__rich_measure__: the column widths the table would
render at, then each column measured within their total; an explicit
width is the maximum, and min_width a floor.
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
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.