# `IO.ANSI.Table.Line`
[🔗](https://github.com/RaymondLoranger/io_ansi_table/blob/main/lib/io/ansi/table/line.ex#L1)

Formats the lines of a table.

# `elem`

```elixir
@type elem() :: String.t()
```

Line element

# `item`

```elixir
@type item() :: String.t()
```

Line item

# `format`

```elixir
@spec format([IO.ANSI.Table.Column.width()], [IO.ANSI.Table.Style.attr()], boolean()) ::
  String.t()
```

Returns an Erlang I/O format (see `:io.format/2`) reflecting `item widths` and
`item attributes`.

It consists of a string with control sequences and embedded
[ANSI codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
(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"

# `item_attrs`

```elixir
@spec item_attrs(IO.ANSI.Table.LineType.t(), IO.ANSI.Table.Spec.t()) :: [
  IO.ANSI.Table.Style.attr()
]
```

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

## Examples

    iex> alias IO.ANSI.Table.Line
    iex> # We use a map instead of a %Spec{} for conciseness.
    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
    ]

# `item_widths`

```elixir
@spec item_widths([elem()], IO.ANSI.Table.LineType.t(), IO.ANSI.Table.Spec.t()) :: [
  IO.ANSI.Table.Column.width()
]
```

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

## Examples

    iex> alias IO.ANSI.Table.Line
    iex> # We use a map instead of a %Spec{} for conciseness.
    iex> spec = %{
    ...>   style: :medium,
    ...>   align_attrs: [:right, :center, nil],
    ...>   column_widths: [7, 13, 9]
    ...> }
    iex> dashes = ["═══════", "═════════════", "═════════"]
    iex> elems = ["Number", "Created at", "Title"]
    iex> {Line.item_widths(dashes, :top, spec),
    ...>  Line.item_widths(elems, :header, spec)}
    {[0, 2, 0,  0, 7, 0,  0, 3, 0,  0, 13, 0,  0, 3, 0,  0, 9, 0,  0, 2, 0],
     [0, 1, 1,  1, 6, 0,  1, 1, 1,  1, 10, 2,  1, 1, 1,  0, 5, 4,  1, 1, 0]}

# `items`

```elixir
@spec items([elem()], [IO.ANSI.Table.Style.border()], String.t()) :: [item()]
```

Deploys `elements` by interlacing them with `filler` and `borders`
(left, inner and right).

## Examples

    iex> alias IO.ANSI.Table.Line
    iex> elements = ["Number", "Created at", "Title"]
    iex> borders = ["+-", "-+-", "-+"]
    iex> Line.items(elements, borders)
    [
      "", "+-"        , "", # 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
    ]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
