IO.ANSI.Table.Column (IO ANSI Table v1.0.14) View Source

Functions related to the columns of a table.

Link to this section Summary

Types

A list of 3 contiguous widths: [left_width, inner_width, right_width]

t()

Functions

Spreads a width given an element and its align attribute.

Returns a list of column widths capped by maximum width.

Link to this section Types

Specs

spread() :: [width()]

A list of 3 contiguous widths: [left_width, inner_width, right_width]

Specs

t() :: [String.t()]

Specs

width() :: non_neg_integer()

Link to this section Functions

Link to this function

spread(width, elem, align_attr)

View Source

Specs

Spreads a width given an element and its align attribute.

Examples

iex> alias IO.ANSI.Table.Column
iex> {
...>   Column.spread(7, "name", :left  ),
...>   Column.spread(7, "name", :center),
...>   Column.spread(7, "name", :right )
...> }
{[0, 4, 3], [1, 4, 2], [3, 4, 0]}

iex> alias IO.ANSI.Table.Column
iex> {
...>   Column.spread(3, "name", :left  ),
...>   Column.spread(3, "name", :center),
...>   Column.spread(3, "name", :right )
...> }
{[0, 3, 0], [0, 3, 0], [0, 3, 0]}

iex> alias IO.ANSI.Table.Column
iex> {
...>   Column.spread(10, "\e[32m\e[42mCHEETAH\e[0m", :left  ),
...>   Column.spread(10, "\e[32m\e[42mCHEETAH\e[0m", :center),
...>   Column.spread(10, "\e[32m\e[42mCHEETAH\e[0m", :right )
...> }
{[0, 21, 3], [1, 21, 2], [3, 21, 0]}

iex> alias IO.ANSI.Table.Column
iex> {
...>   Column.spread(7, "\e[32m\e[42mCHEETAH\e[0m", :left  ),
...>   Column.spread(7, "\e[32m\e[42mCHEETAH\e[0m", :center),
...>   Column.spread(7, "\e[32m\e[42mCHEETAH\e[0m", :right )
...> }
{[0, 21, 0], [0, 21, 0], [0, 21, 0]}
Link to this function

widths(columns, max_width)

View Source

Specs

widths([t()], width()) :: [width()]

Returns a list of column widths capped by maximum width.

Examples

iex> alias IO.ANSI.Table.Column
iex> data = [["cat", "wombat", "elk"], ["mongoose", "ant", "gnu"]]
iex> Column.widths(data, 99)
[6, 8]

iex> alias IO.ANSI.Table.Column
iex> data = [["cat", "wombat", "elk"], ["mongoose", "ant", "gnu"]]
iex> Column.widths(data, 7)
[6, 7]

iex> alias IO.ANSI.Table.Column
iex> data = [["\e[32m\e[42mCHEETAH\e[0m", "elk"], ["mongoose", "ant"]]
iex> Column.widths(data, 99)
[7, 8]

iex> alias IO.ANSI.Table.Column
iex> data = [["\e[32m\e[42mCHEETAH\e[0m", "elk"], ["mongoose", "ant"]]
iex> Column.widths(data, 6)
[6, 6]