WardrikDaemon.Console.Table (wardrik_daemon v0.1.0-rc.1)

Copy Markdown

A markdown table: its header, its body rows, and each column's alignment.

WardrikDaemon.Console.Markdown builds one from the rows it held back, and returns it in place of a line. Whoever draws it lays it out at the width it has then. lines/2 does that for a terminal written a line at a time.

Summary

Types

How a column's cells are aligned, from the rule row's colons.

t()

A header row, body rows, one alignment per column, and how many columns to indent.

Functions

Returns the alignment a rule cell asks for: :---: is :center, ---: is :right, anything else :left.

Returns the table as lines no wider than width, for a terminal that's never redrawn.

Returns a table from its header, body rows and alignments.

Types

alignment()

@type alignment() :: :left | :right | :center

How a column's cells are aligned, from the rule row's colons.

t()

@type t() :: %WardrikDaemon.Console.Table{
  alignments: [alignment()],
  header: [Owl.Data.t()],
  indent: non_neg_integer(),
  rows: [[Owl.Data.t()]]
}

A header row, body rows, one alignment per column, and how many columns to indent.

Functions

alignment(rule)

@spec alignment(String.t()) :: alignment()

Returns the alignment a rule cell asks for: :---: is :center, ---: is :right, anything else :left.

lines(table, width)

@spec lines(t(), pos_integer()) :: [Owl.Data.t()]

Returns the table as lines no wider than width, for a terminal that's never redrawn.

The table is boxed, with a bright header. Columns take their natural width if they fit. If not, each cell wraps inside its column, at the left. A table with no body rows is its header alone.

new(header, rows, alignments \\ [])

@spec new([Owl.Data.t()], [[Owl.Data.t()]], [alignment()]) :: t()

Returns a table from its header, body rows and alignments.

Short rows are padded with empty cells. Missing alignments are :left.