Skip to main content

Table

Struct Table 

Source
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

Source

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.

Source

pub fn grid() -> Self

Create a grid (table with no borders or header).

A grid is useful for simple layouts without table decoration.

Source

pub fn with_box(self, box_type: Option<RichBox>) -> Self

Set the border style.

Source

pub fn with_safe_box(self, safe: bool) -> Self

Set whether to use ASCII-safe box characters.

Source

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.

Source

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
Source

pub fn with_title_style(self, style: Style) -> Self

Set the title style.

Source

pub fn with_caption_style(self, style: Style) -> Self

Set the caption style.

Source

pub fn with_collapse_padding(self, collapse: bool) -> Self

Set whether to collapse padding between cells.

Source

pub fn with_pad_edge(self, pad: bool) -> Self

Set whether to pad edge cells.

Source

pub fn with_expand(self, expand: bool) -> Self

Set whether to expand to fill available width.

Source

pub fn with_show_header(self, show: bool) -> Self

Set whether to show the header row.

Set whether to show the footer row.

Source

pub fn with_show_edge(self, show: bool) -> Self

Set whether to show the outer edge.

Source

pub fn with_show_lines(self, show: bool) -> Self

Set whether to show lines between all rows.

Source

pub fn with_leading(self, leading: usize) -> Self

Set number of blank lines between rows.

Source

pub fn with_style(self, style: Style) -> Self

Set the base table style.

Source

pub fn with_row_styles(self, styles: Vec<Style>) -> Self

Set alternating row styles.

Source

pub fn with_header_style(self, style: Style) -> Self

Set the header style.

Set the footer style.

Source

pub fn with_border_style(self, style: Style) -> Self

Set the border style.

Source

pub fn with_title(self, title: &str) -> Self

Set the title above the table.

Source

pub fn with_title_text(self, title: Text) -> Self

Set the title with a Text object.

Source

pub fn with_caption(self, caption: &str) -> Self

Set the caption below the table.

Source

pub fn with_caption_text(self, caption: Text) -> Self

Set the caption with a Text object.

Source

pub fn with_title_align(self, align: AlignMethod) -> Self

Set title alignment.

Source

pub fn with_caption_align(self, align: AlignMethod) -> Self

Set caption alignment.

Source

pub fn with_width(self, width: usize) -> Self

Set a fixed width for the table.

Source

pub fn with_min_width(self, width: usize) -> Self

Set the minimum width.

Source

pub fn with_highlight(self, highlight: bool) -> Self

Set whether to highlight cell contents.

Source

pub fn add_column(&mut self, column: Column)

Add a column to the table.

Source

pub fn add_column_str(&mut self, header: &str)

Add a column with a string header.

Source

pub fn add_column_renderable( &mut self, header: Box<dyn Renderable + Send + Sync>, )

Add a column with a renderable header.

Source

pub fn add_row(&mut self, row: Row)

Add a row of cells to the table.

Source

pub fn add_row_strs(&mut self, cells: &[&str])

Add a row of string cells.

Source

pub fn add_row_renderables( &mut self, cells: Vec<Box<dyn Renderable + Send + Sync>>, )

Add a row of renderable cells.

Source

pub fn add_section(&mut self)

Mark the last row as an end-of-section (draws separator after).

Source

pub fn row_count(&self) -> usize

Get the number of rows (excluding header/footer).

Source

pub fn column_count(&self) -> usize

Get the number of columns.

Source

pub fn set_title(&mut self, title: Option<Text>)

Set the table title.

Source

pub fn set_caption(&mut self, caption: Option<Text>)

Set the table caption.

Set whether to show the footer row.

Source

pub fn set_border_style(&mut self, style: Style)

Set the border style.

Source

pub fn set_box(&mut self, box_type: Option<RichBox>)

Set the box drawing style.

Source

pub fn set_row_styles(&mut self, styles: Vec<Style>)

Set alternating row styles.

Source

pub fn set_pad_edge(&mut self, pad: bool)

Set whether to pad the edge cells.

Source

pub fn set_width(&mut self, width: Option<usize>)

Set the fixed width (None for auto).

Source

pub fn column_mut(&mut self, idx: usize) -> Option<&mut Column>

Get a mutable reference to a column by index.

Trait Implementations§

Source§

impl Debug for Table

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Table

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Renderable for Table

Source§

fn render( &self, console: &Console<Stdout>, options: &ConsoleOptions, ) -> Segments

Render this object to a sequence of segments.
Source§

fn measure( &self, console: &Console<Stdout>, options: &ConsoleOptions, ) -> Measurement

Measure the minimum and maximum width requirements. Read more

Auto Trait Implementations§

§

impl Freeze for Table

§

impl !RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl !UnwindSafe for Table

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.