@std/cli/table.ms#
Import each required symbol with import Name from "@std/cli/table.ms".
Align Enum#
Horizontal placement of a cell within its column’s measured display width.
Example: Table(columns: [Align.Left, Align.Right]).
enum Align {
Left
Right
Center
}Align.Center#
Splits unused space, putting an odd extra space after the cell.
CenterAlign.Left#
Places unused column space after the cell.
LeftAlign.Right#
Places unused column space before the cell.
RightTable Type#
Aligned text columns for terminal output. columns gives one alignment per column; padding is the
number of spaces between columns (default 2, negative counts as 0) and indent the spaces before each
non-blank line. Rows are added one at a time and rendered as LF-separated lines with no final LF.
import Align, Table from "@std/cli/table.ms"
fn render() String! {
var table = Table(columns: [Align.Left, Align.Right])
table.add(["tea", "2"])?
table.add(["coffee", "30"])?
return ok(table.render())
}Unicode widths use String.display_width: cell bytes stay intact and widths are estimates, not a promise
for every font or terminal. Cells containing controls (tabs, CR/LF, ESC, C1, U+2028, U+2029) are rejected by
add, never expanded or interpreted. Trailing columns whose cells are empty are omitted, so no line ends in
added padding; a table without rows renders as “”.
type Table {
columns List[Align]
padding Int = 2
indent Int = 0
rows List[List[String]] = []
cell_widths List[List[Int]] = []
widths List[Int] = []
}Table.cell_widths#
Internal state: the display width of every cell in rows.
cell_widths List[List[Int]] = []Table.columns#
One alignment per column; also fixes the number of cells every row must have.
columns List[Align]Table.indent#
Spaces before each non-blank line.
indent Int = 0Table.padding#
Spaces between columns; negative counts as 0.
padding Int = 2Table.rows#
Internal state: the added rows.
rows List[List[String]] = []Table.widths#
Internal state: the widest cell of each column.
widths List[Int] = []Table.add#
Appends a row of exactly one cell per column. A wrong cell count or a cell with controls returns EBADMSG.
var fn add(row List[String]) Result[Void, Error]Table.before#
Spaces placed before a cell: all spare for Right, half for Center, null for Left.
fn before(col Int, spare Int) IntTable.render#
Lays out the rows added so far; the table is unchanged and can keep growing.
fn render() String