IO ANSI Table v0.2.4 IO.ANSI.Table.Style View Source

Defines functions to retrieve properties of predefined table styles.

Link to this section Summary

Functions

Retrieves the border attribute of a given table style and line/row type

Retrieves the 3 multipart border widths (left, inner and right) of a given table style and line/row type. The widths are multipart to account for the “fillers” preceding/following the borders

Retrieves the borders of a given table style and line/row type

Retrieves the dash of a given table style and line/row type

Retrieves the filler attribute of a given table style and line/row type

Retrieves the key attribute of a given table style and line/row type

Retrieves the line types of a given table style

Retrieves the non key attribute of a given table style and line/row type

Retrieves the table style for a given table style tag

Retrieves the table style tag for a given table style

Retrieves a list of interpolated texts (one per table style) and optionally passes each interpolated text to a function

Link to this section Types

Link to this type attr() View Source
attr() :: [atom] | atom
Link to this type border_widths() View Source
border_widths() :: {[non_neg_integer], [non_neg_integer], [non_neg_integer]}
Link to this type line_type() View Source
line_type() :: :top | :header | :separator | :bottom
Link to this type row_type() View Source
row_type() :: :row | :even_row | :odd_row | :row_1 | :row_2 | :row_3

Link to this section Functions

Link to this function border_attr(style, type) View Source
border_attr(t, line_type | row_type) :: attr | nil

Retrieves the border attribute of a given table style and line/row type.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.border_attr(:green, :top)
[:light_yellow, :light_green_background]
Link to this function border_widths(style, type) View Source
border_widths(t, line_type | row_type) :: border_widths | nil

Retrieves the 3 multipart border widths (left, inner and right) of a given table style and line/row type. The widths are multipart to account for the “fillers” preceding/following the borders.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.border_widths(:plain, :bottom) # borders: "└─", "─┴─", "─┘"
{[2, 0], [0, 3, 0], [0, 2]}

iex> alias IO.ANSI.Table.Style
iex> Style.border_widths(:plain, :header) # borders: "│" ,  "│" ,  "│"
{[1, 1], [1, 1, 1], [1, 1]}
Link to this function borders(style, type) View Source
borders(t, line_type | row_type) :: borders | nil

Retrieves the borders of a given table style and line/row type.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.borders(:cyan, :bottom)
{"╚═", "═╩═", "═╝"}

iex> alias IO.ANSI.Table.Style
iex> Style.borders(:cyan, :row)
{"║", "║", "║"}

Retrieves the dash of a given table style and line/row type.

Examples

iex> IO.ANSI.Table.Style
iex> Style.dash(:dark, :top)
"═"

iex> IO.ANSI.Table.Style
iex> Style.dash(:dark, :row)
nil
Link to this function filler_attr(style, type) View Source
filler_attr(t, line_type | row_type) :: attr | nil

Retrieves the filler attribute of a given table style and line/row type.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.filler_attr(:mixed, :row)
:light_green_background
Link to this function key_attr(style, type) View Source
key_attr(t, line_type | row_type) :: attr | nil

Retrieves the key attribute of a given table style and line/row type.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.key_attr(:light, :row)
:light_cyan

iex> alias IO.ANSI.Table.Style
iex> Style.key_attr(:light, :header)
[:light_yellow, :underline]
Link to this function line_types(style) View Source
line_types(t) :: [line_type | [row_type]] | nil

Retrieves the line types of a given table style.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.line_types(:light)
[:top, :header, :separator, [:row], :bottom]

iex> alias IO.ANSI.Table.Style
iex> Style.line_types(:green_alt)
[:top, :header, :separator, [:even_row, :odd_row]]
Link to this function non_key_attr(style, type) View Source
non_key_attr(t, line_type | row_type) :: attr | nil

Retrieves the non key attribute of a given table style and line/row type.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.non_key_attr(:cyan, :row)
[:black, :light_cyan_background]
Link to this function style_for(tag) View Source
style_for(String.t) :: {:ok, t} | :error

Retrieves the table style for a given table style tag.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.style_for("light")
{:ok, :light}

iex> alias IO.ANSI.Table.Style
iex> Style.style_for("green-alt")
{:ok, :green_alt}
Link to this function tag_for(style) View Source
tag_for(t) :: String.t | nil

Retrieves the table style tag for a given table style.

Examples

iex> alias IO.ANSI.Table.Style
iex> Style.tag_for(:light)
"light"

iex> alias IO.ANSI.Table.Style
iex> Style.tag_for(:green_alt)
"green-alt"
Link to this function texts(template, fun \\ &(&1)) View Source
texts(String.t, (String.t -> any)) :: [any]

Retrieves a list of interpolated texts (one per table style) and optionally passes each interpolated text to a function.

Examples

alias IO.ANSI.Table.Style
Style.texts "  - `&style`&filler - &note\n"

alias IO.ANSI.Table.Style
Style.texts "  - `&style`&filler - &note", &IO.puts/1

Interpolation placeholders

  • &style - table style (e.g. “:light”)
  • &tag - table style tag (e.g. “light”)
  • &filler - padding after &style or &tag
  • &note - table style note
  • &rank - table style rank (3 digits)