pub struct Table<Row = TextTableRow> { /* private fields */ }Expand description
Owned table data independent of presentation policy.
Table owns semantic content, structural visibility, and offsets only. Every
presentation concern — borders, padding, width, and cell styles — belongs to
TablePresentation.
Rows may be ragged: a row shorter than the widest row is padded with empty
cells when its TableRow formatting is composed. Use Table::text for
rows that are already plain text.
use urushi::{BlockStyle, Table, TablePresentation, TextStyle, measure};
let table = Table::text()
.headers(["Name", "Location"])
.row(["Kini", "New York"])
.row(["Iris", "Paris"]);
let presentation =
TablePresentation::new(BlockStyle::new(), BlockStyle::new(), TextStyle::new());
assert_eq!(measure(&presentation.compose(&table)).height(), 6);Implementations§
Source§impl<Row> Table<Row>
impl<Row> Table<Row>
Sourcepub fn headers<I, S>(self, headers: I) -> Self
pub fn headers<I, S>(self, headers: I) -> Self
Replaces the header cells, each of which is plain text.
A table without headers composes its body rows only. Escape sequences and cursor movement in a header break the plain-text contract: debug builds panic, and release builds measure them as ordinary characters and may split them when wrapping or truncating. Raw ANSI is not accepted as component text.
Sourcepub fn rows<I>(self, rows: I) -> Selfwhere
I: IntoIterator<Item = Row>,
pub fn rows<I>(self, rows: I) -> Selfwhere
I: IntoIterator<Item = Row>,
Appends typed body rows in iteration order.
Includes or excludes the complete table.
Sourcepub const fn offset(self, start: usize, end: usize) -> Self
pub const fn offset(self, start: usize, end: usize) -> Self
Omits start body rows from the front and end from the back.
Headers are never omitted; the offset selects among body rows only.
Returns whether the table is excluded.
Source§impl<Row> Table<Row>where
Row: TableRow,
impl<Row> Table<Row>where
Row: TableRow,
Sourcepub fn column_count(&self) -> usize
pub fn column_count(&self) -> usize
Returns the column count from the widest canonical header or body row.
This formats every owned row, including rows omitted by the offset. Composition formats only visible rows, so an omitted wide row does not add columns to the composed view.