row

Row molecule — horizontal sequence of Column atoms with flex-aware width resolution.

struct Component

source

pub struct Component

A horizontal sequence of columns with configurable spacing and terminal-width-aware layout. Row owns all measurement and width resolution.

Field Type Description
columns Vec<Column> Cells in display order.
max_width Option<usize> Total width budget; None uses terminal_width.
spacing usize Spaces written between adjacent columns.

Implements Display.

Component::new

source

pub fn new() -> Self

Create an empty row with default spacing of 2 columns.

Parameter Type Description
returns Self A row with no columns, sized to the terminal.

Component::col

source

pub fn col(self, column: Column) -> Self

Append a Column to this row.

Parameter Type Description
column Column the cell to add at the right end
returns Self The row with the column appended.

Component::spacing

source

pub fn spacing(self, spacing: usize) -> Self

Set the number of space characters between columns (default 2).

Parameter Type Description
spacing usize the number of spaces between columns
returns Self The row with the new spacing.

Component::max_width

source

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

Set an explicit maximum width (defaults to terminal width).

Parameter Type Description
width usize the total width budget in columns, spacing included
returns Self The row with the width set.

Component::columns

source

pub fn columns(&self) -> &[Column]

Returns the columns for external inspection (used by Grid).

Parameter Type Description
returns &[Column] The columns, for external inspection (used by Grid).

Component::resolve_widths

source

fn resolve_widths(&self) -> Vec<(usize, &str)>

Resolve column widths and render.

Parameter Type Description
returns Vec<(usize, &str)> Each column’s resolved width with its content, in order. Fixed and natural columns get their own width; flex columns share what is left by weight. Content wider than its width is not cut.

fn display_width

source

pub fn display_width(s: &str) -> usize

Return the visible column width of s after stripping ANSI escape sequences.

Parameter Type Description
s &str the text, which may hold ANSI CSI or OSC escapes
returns usize The visible column width of s after stripping ANSI escape sequences.

fn terminal_width

source

pub fn terminal_width() -> u16

Query the terminal width, falling back to 80 columns if unavailable.

Parameter Type Description
returns u16 The width of the terminal in columns, or 80 when it cannot be read.

fn strip_ansi

source

pub fn strip_ansi(s: &str) -> String

Remove ANSI CSI and OSC escape sequences from a string.

Parameter Type Description
s &str the text to clean
returns String A copy of the text with the escapes removed.