row
Row molecule — horizontal sequence of Column atoms with flex-aware width resolution.
struct Component
pub struct ComponentA 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
pub fn new() -> SelfCreate 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
pub fn col(self, column: Column) -> SelfAppend 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
pub fn spacing(self, spacing: usize) -> SelfSet 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
pub fn max_width(self, width: usize) -> SelfSet 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
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
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
pub fn display_width(s: &str) -> usizeReturn 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
pub fn terminal_width() -> u16Query 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
pub fn strip_ansi(s: &str) -> StringRemove 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. |