spruce/table
Bordered, ANSI-aware data table rendering.
Types
Horizontal alignment for a table column.
pub type Align {
Left
Center
Right
}
Constructors
-
Left -
Center -
Right
Identifies the row kind passed to a style_fn.
pub type RowContext {
Header
Body(index: Int)
}
Constructors
-
HeaderThe header row.
-
Body(index: Int)A zero-based body row.
Values
pub fn border(table: Table, border: border.Border) -> Table
Set the table border style.
Junctions are exact for Normal, Rounded, Thick, and Double. Other border styles approximate junctions from their edge characters.
pub fn column_alignments(
table: Table,
alignments: List(Align),
) -> Table
Set horizontal alignment by column.
Columns without a corresponding alignment are left-aligned.
pub fn column_widths(table: Table, widths: List(Int)) -> Table
Constrain columns to maximum visual widths.
Widths less than one are ignored. Columns without a corresponding configured width use their natural content width.
pub fn render(context: spruce.Spruce, table: Table) -> String
Render a table as a bordered grid.
pub fn row_separators(table: Table, enabled: Bool) -> Table
Toggle separator lines between body rows.
pub fn rows(table: Table, rows: List(List(String))) -> Table
Set the body rows. Short rows are padded with empty cells at render time.
pub fn style_fn(
table: Table,
style_fn: fn(RowContext, Int) -> style.Style,
) -> Table
Set a per-cell style function.
The RowContext argument is Header for header cells and Body(index) for
zero-based body row cells.