Module: Aspera::Cli::TableFitter

Defined in:
lib/aspera/cli/table_fitter.rb

Overview

Build a terminal table that fits in a given width, by wrapping cells. Columns with text (containing spaces, e.g. description) are wrapped first, the widest first. If not enough, other columns (names, identifiers) are wrapped too. If the table cannot fit, columns are narrowed to their minimum width.

Class Method Summary collapse

Class Method Details

.table(headings:, rows:, style:, width:) ⇒ Terminal::Table

Parameters:

  • headings (Array) —

    Column names

  • rows (Array<Array<String>>) —

    Rows of cells

  • style (Hash) —

    Terminal::Table style

  • width (Integer, nil) —

    Maximum width of the table, or nil for natural width (not a style parameter)

Returns:

  • (Terminal::Table)


36
37
38
39
# File 'lib/aspera/cli/table_fitter.rb', line 36

def table(headings:, rows:, style:, width:)
  headings, rows = fit(headings, rows, width - overhead(headings.length, style)) unless width.nil?
  Terminal::Table.new(headings: headings, rows: rows, style: style)
end