spruce/table

Bordered, ANSI-aware data table rendering.

Types

A table of string cells with an optional header row. Build one with new and the configuration functions in this module, then render it with render.

pub opaque type Table

Values

pub fn border(table: Table, border: box.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_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 headers(table: Table, headers: List(String)) -> Table

Set the optional header row.

pub fn new() -> Table

Create an empty table.

pub fn render(sp: 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(Int, Int) -> style.Style,
) -> Table

Set a per-cell style function.

Body rows are passed zero-based row indexes. Header cells are passed row -1.

pub fn width(table: Table, width: Int) -> Table

Constrain the overall table to a maximum visual width.

The available cell content width is distributed evenly across columns. Cells that exceed their column width are wrapped with spruce/align.wrap.

Search Document