pub struct Table { /* private fields */ }Expand description
A console-renderable table with rows and columns.
Table supports headers, footers, various border styles, and flexible column width calculation.
§Example
use rich_rs::Table;
let mut table = Table::new();
table.add_column_str("Name");
table.add_column_str("Score");
table.add_row_strs(&["Alice", "100"]);
table.add_row_strs(&["Bob", "95"]);Implementations§
Source§impl Table
impl Table
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new empty table with default settings.
The default table uses HEAVY_HEAD border style, shows headers, and has standard padding.
Sourcepub fn grid() -> Self
pub fn grid() -> Self
Create a grid (table with no borders or header).
A grid is useful for simple layouts without table decoration.
Sourcepub fn with_safe_box(self, safe: bool) -> Self
pub fn with_safe_box(self, safe: bool) -> Self
Set whether to use ASCII-safe box characters.
Sourcepub fn with_padding(self, left: usize, right: usize) -> Self
pub fn with_padding(self, left: usize, right: usize) -> Self
Set cell padding (left and right), keeping top/bottom at 0.
For full 4-way padding, use with_padding_dims.
Sourcepub fn with_padding_dims(self, pad: impl Into<PaddingDimensions>) -> Self
pub fn with_padding_dims(self, pad: impl Into<PaddingDimensions>) -> Self
Set cell padding using CSS-order dimensions.
Accepts PaddingDimensions (or anything that converts to it):
usize— all four sides(vert, horiz)— top/bottom and left/right(top, right, bottom, left)— CSS order
Sourcepub fn with_title_style(self, style: Style) -> Self
pub fn with_title_style(self, style: Style) -> Self
Set the title style.
Sourcepub fn with_caption_style(self, style: Style) -> Self
pub fn with_caption_style(self, style: Style) -> Self
Set the caption style.
Sourcepub fn with_collapse_padding(self, collapse: bool) -> Self
pub fn with_collapse_padding(self, collapse: bool) -> Self
Set whether to collapse padding between cells.
Sourcepub fn with_pad_edge(self, pad: bool) -> Self
pub fn with_pad_edge(self, pad: bool) -> Self
Set whether to pad edge cells.
Sourcepub fn with_expand(self, expand: bool) -> Self
pub fn with_expand(self, expand: bool) -> Self
Set whether to expand to fill available width.
Sourcepub fn with_show_header(self, show: bool) -> Self
pub fn with_show_header(self, show: bool) -> Self
Set whether to show the header row.
Set whether to show the footer row.
Sourcepub fn with_show_edge(self, show: bool) -> Self
pub fn with_show_edge(self, show: bool) -> Self
Set whether to show the outer edge.
Sourcepub fn with_show_lines(self, show: bool) -> Self
pub fn with_show_lines(self, show: bool) -> Self
Set whether to show lines between all rows.
Sourcepub fn with_leading(self, leading: usize) -> Self
pub fn with_leading(self, leading: usize) -> Self
Set number of blank lines between rows.
Sourcepub fn with_style(self, style: Style) -> Self
pub fn with_style(self, style: Style) -> Self
Set the base table style.
Sourcepub fn with_row_styles(self, styles: Vec<Style>) -> Self
pub fn with_row_styles(self, styles: Vec<Style>) -> Self
Set alternating row styles.
Sourcepub fn with_header_style(self, style: Style) -> Self
pub fn with_header_style(self, style: Style) -> Self
Set the header style.
Set the footer style.
Sourcepub fn with_border_style(self, style: Style) -> Self
pub fn with_border_style(self, style: Style) -> Self
Set the border style.
Sourcepub fn with_title(self, title: &str) -> Self
pub fn with_title(self, title: &str) -> Self
Set the title above the table.
Sourcepub fn with_title_text(self, title: Text) -> Self
pub fn with_title_text(self, title: Text) -> Self
Set the title with a Text object.
Sourcepub fn with_caption(self, caption: &str) -> Self
pub fn with_caption(self, caption: &str) -> Self
Set the caption below the table.
Sourcepub fn with_caption_text(self, caption: Text) -> Self
pub fn with_caption_text(self, caption: Text) -> Self
Set the caption with a Text object.
Sourcepub fn with_title_align(self, align: AlignMethod) -> Self
pub fn with_title_align(self, align: AlignMethod) -> Self
Set title alignment.
Sourcepub fn with_caption_align(self, align: AlignMethod) -> Self
pub fn with_caption_align(self, align: AlignMethod) -> Self
Set caption alignment.
Sourcepub fn with_width(self, width: usize) -> Self
pub fn with_width(self, width: usize) -> Self
Set a fixed width for the table.
Sourcepub fn with_min_width(self, width: usize) -> Self
pub fn with_min_width(self, width: usize) -> Self
Set the minimum width.
Sourcepub fn with_highlight(self, highlight: bool) -> Self
pub fn with_highlight(self, highlight: bool) -> Self
Set whether to highlight cell contents.
Sourcepub fn add_column(&mut self, column: Column)
pub fn add_column(&mut self, column: Column)
Add a column to the table.
Sourcepub fn add_column_str(&mut self, header: &str)
pub fn add_column_str(&mut self, header: &str)
Add a column with a string header.
Sourcepub fn add_column_renderable(
&mut self,
header: Box<dyn Renderable + Send + Sync>,
)
pub fn add_column_renderable( &mut self, header: Box<dyn Renderable + Send + Sync>, )
Add a column with a renderable header.
Sourcepub fn add_row_strs(&mut self, cells: &[&str])
pub fn add_row_strs(&mut self, cells: &[&str])
Add a row of string cells.
Sourcepub fn add_row_renderables(
&mut self,
cells: Vec<Box<dyn Renderable + Send + Sync>>,
)
pub fn add_row_renderables( &mut self, cells: Vec<Box<dyn Renderable + Send + Sync>>, )
Add a row of renderable cells.
Sourcepub fn add_section(&mut self)
pub fn add_section(&mut self)
Mark the last row as an end-of-section (draws separator after).
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Get the number of columns.
Sourcepub fn set_caption(&mut self, caption: Option<Text>)
pub fn set_caption(&mut self, caption: Option<Text>)
Set the table caption.
Set whether to show the footer row.
Sourcepub fn set_border_style(&mut self, style: Style)
pub fn set_border_style(&mut self, style: Style)
Set the border style.
Sourcepub fn set_row_styles(&mut self, styles: Vec<Style>)
pub fn set_row_styles(&mut self, styles: Vec<Style>)
Set alternating row styles.
Sourcepub fn set_pad_edge(&mut self, pad: bool)
pub fn set_pad_edge(&mut self, pad: bool)
Set whether to pad the edge cells.
Sourcepub fn column_mut(&mut self, idx: usize) -> Option<&mut Column>
pub fn column_mut(&mut self, idx: usize) -> Option<&mut Column>
Get a mutable reference to a column by index.