IO ANSI Table v0.4.19 IO.ANSI.Table.Line View Source

Formats the line of a table.

Link to this section Summary

Functions

Returns an Erlang io format reflecting item widths and item attributes. It consists of a string with embedded ANSI codes (escape sequences), if emitting ANSI codes is enabled

Deploys the style attributes of a given line type and table spec

Deploys widths of elements for a given line type and table spec

Deploys elements by mixing “fillers” and borders (left, inner and right)

Link to this section Types

Link to this section Functions

Link to this function format(item_widths, item_attrs, ansi_enabled? \\ true) View Source

Returns an Erlang io format reflecting item widths and item attributes. It consists of a string with embedded ANSI codes (escape sequences), if emitting ANSI codes is enabled.

Here are a few ANSI codes:

  • light yellow - \e[93m
  • light cyan - \e[96m
  • reset - \e[0m

Examples

iex> alias IO.ANSI.Table.Line
iex> item_widths = [2, 0, 6]
iex> item_attrs = [:light_yellow, :normal, :light_cyan]
iex> Line.format(item_widths, item_attrs, true)
"\e[93m~-2ts\e[0m~-0ts\e[96m~-6ts\e[0m~n"

Deploys the style attributes of a given line type and table spec.

Examples

iex> alias IO.ANSI.Table.Line
iex> spec = %{style: :medium, sort_attrs: [nil, :asc, nil]}
iex> type = :header
iex> Line.item_attrs(type, spec)
[
  :normal, :gold                 , :normal, # left border
  :normal, :canary               , :normal, # non key column
  :normal, :gold                 , :normal, # inner border
  :normal, [:canary, :underline] , :normal, # key column
  :normal, :gold                 , :normal, # inner border
  :normal, :canary               , :normal, # non key column
  :normal, :gold                 , :normal  # right border
]

Deploys widths of elements for a given line type and table spec.

Examples

iex> alias IO.ANSI.Table.Line
iex> spec = %{
...>   style: :medium,
...>   align_attrs: [:right, :center, nil],
...>   column_widths: [7, 13, 11]
...> }
iex> type = :header
iex> elems = ["Number", "Created at", "Title"]
iex> Line.item_widths(elems, type, spec)
[0, 1, 1, 1, 6, 0, 1, 1, 1, 1, 10, 2, 1, 1, 1, 0, 5, 6, 1, 1, 0]
Link to this function items(elems, borders) View Source
items([elem()], [IO.ANSI.Table.Style.border()]) :: [item()]

Deploys elements by mixing “fillers” and borders (left, inner and right).

Examples

iex> alias IO.ANSI.Table.Line
iex> elements = ["Number", "Created at", "Title"]
iex> Line.items(elements, ["<", "=", ">"])
[
  "", "<"         , "", # filler, left border, filler
  "", "Number"    , "", # filler, element, filler
  "", "="         , "", # filler, inner border, filler
  "", "Created at", "", # filler, element, filler
  "", "="         , "", # filler, inner border, filler
  "", "Title"     , "", # filler, element, filler
  "", ">"         , ""  # filler, right border, filler
]