TableRenderer class

Centralized table rendering utility.

Provides consistent table layout across views/prompts:

  • Column width computation (ANSI-aware)
  • Styled header row
  • Connector lines
  • Zebra-striped data rows
  • Flexible alignment per column

Usage:

final renderer = TableRenderer(
  columns: [
    ColumnConfig.left('Name'),
    ColumnConfig.center('Status'),
    ColumnConfig.right('Count'),
  ],
  theme: PromptTheme.dark,
);

// Compute widths from data
renderer.computeWidths(rows);

// Build individual lines
final header = renderer.headerLine();
final connector = renderer.connectorLine();
for (var i = 0; i < rows.length; i++) {
  final row = renderer.rowLine(rows[i], index: i);
}

Constructors

TableRenderer({required List<ColumnConfig> columns, PromptTheme theme = PromptTheme.dark, bool zebraStripes = true, int cellPadding = 0})
TableRenderer.fromHeaders(List<String> headers, {PromptTheme theme = PromptTheme.dark, bool zebraStripes = true, int cellPadding = 0})
Creates a renderer from simple string headers.
factory
TableRenderer.withAlignments(List<String> headers, List<ColumnAlign> alignments, {PromptTheme theme = PromptTheme.dark, bool zebraStripes = true, int cellPadding = 0})
Creates a renderer with custom alignments.
factory

Properties

cellPadding int
Padding added to each side of cell content.
final
columnCount int
Number of columns.
no setter
columns List<ColumnConfig>
Column configurations.
final
contentWidth int
Total width of the table content (excluding outer frame).
no setter
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
theme PromptTheme
Theme for styling.
final
widths List<int>
Current computed widths.
no setter
zebraStripes bool
Whether to apply zebra stripes to rows.
final

Methods

buildLines(List<List<String>> rows) List<String>
Builds a complete table as a list of lines.
computeWidths(List<List<String>> rows) → void
Computes column widths based on header and row data.
connectorLine({String? leadingGutter}) String
Builds the connector line below the header.
headerLine({String? leadingGutter}) String
Builds the header row line.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rowLine(List<String> cells, {int index = 0, String? leadingGutter, bool forceStripe = false}) String
Builds a data row line.
selectableRowLine(List<String> cells, {required int index, int? selectedColumn, bool isEditing = false, String editBuffer = '', String? leadingGutter}) String
Builds a row with selection highlighting.
setWidths(List<int> widths) → void
Sets column widths explicitly.
toString() String
A string representation of this object.
inherited
writeHeader(void out(String)) → void
Writes the table header and connector to out.
writeRows(List<List<String>> rows, void out(String)) → void
Writes all data rows to out.

Operators

operator ==(Object other) bool
The equality operator.
inherited