IO ANSI Table v0.4.29 IO.ANSI.Table.Column View Source
Functions related to the columns of a table.
Link to this section Summary
Functions
Returns the specs
attribute of a header
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
Link to this type
align_attr()
View Source
align_attr()
View Source
align_attr() :: :left | :center | :right
align_attr() :: :left | :center | :right
Link to this type
align_spec()
View Source
align_spec()
View Source
align_spec() :: any() | {align_attr(), any()}
align_spec() :: any() | {align_attr(), any()}
Link to this type
attr()
View Source
attr()
View Source
attr() :: align_attr() | sort_attr()
attr() :: align_attr() | sort_attr()
Link to this type
sort_attr()
View Source
sort_attr()
View Source
sort_attr() :: MapSorter.SortSpec.sort_dir()
sort_attr() :: MapSorter.SortSpec.sort_dir()
Link to this type
sort_spec()
View Source
sort_spec()
View Source
sort_spec() :: MapSorter.SortSpec.t()
sort_spec() :: MapSorter.SortSpec.t()
Link to this type
sort_symbol() View Source
Link to this type
spec()
View Source
spec()
View Source
spec() :: align_spec() | sort_spec()
spec() :: align_spec() | sort_spec()
Link to this type
spread()
View Source
spread()
View Source
spread() :: [width()]
spread() :: [width()]
Link to this type
t()
View Source
t()
View Source
t() :: [String.t()]
t() :: [String.t()]
Link to this type
width()
View Source
width()
View Source
width() :: non_neg_integer()
width() :: non_neg_integer()
Link to this section Functions
Link to this function
align_attrs(spec)
View Source
align_attrs(spec)
View Source
align_attrs(IO.ANSI.Table.Spec.t()) :: IO.ANSI.Table.Spec.t()
align_attrs(IO.ANSI.Table.Spec.t()) :: IO.ANSI.Table.Spec.t()
Link to this function
column_widths(spec)
View Source
column_widths(spec)
View Source
column_widths(IO.ANSI.Table.Spec.t()) :: IO.ANSI.Table.Spec.t()
column_widths(IO.ANSI.Table.Spec.t()) :: IO.ANSI.Table.Spec.t()
Link to this function
find_attr(header, specs, default_attr) View Source
Returns the specs
attribute of a header
.
Examples
iex> alias IO.ANSI.Table.Column
iex> sort_specs = ["dept", desc: "hired"]
iex> {
...> Column.find_attr("dept" , sort_specs, :asc),
...> Column.find_attr("hired", sort_specs, :asc),
...> Column.find_attr("job" , sort_specs, :asc)
...> }
{:asc, :desc, nil}
Link to this function
left_margin(spec)
View Source
left_margin(spec)
View Source
left_margin(IO.ANSI.Table.Spec.t()) :: IO.ANSI.Table.Spec.t()
left_margin(IO.ANSI.Table.Spec.t()) :: IO.ANSI.Table.Spec.t()
Link to this function
sort_attrs(spec)
View Source
sort_attrs(spec)
View Source
sort_attrs(IO.ANSI.Table.Spec.t()) :: IO.ANSI.Table.Spec.t()
sort_attrs(IO.ANSI.Table.Spec.t()) :: IO.ANSI.Table.Spec.t()
Link to this function
spread(width, elem, align_attr)
View Source
spread(width, elem, align_attr)
View Source
spread(width(), IO.ANSI.Table.Line.elem(), align_attr()) :: spread()
spread(width(), IO.ANSI.Table.Line.elem(), align_attr()) :: spread()
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, "[32m[42mCHEETAH[0m", :left ),
...> Column.spread(10, "[32m[42mCHEETAH[0m", :center),
...> Column.spread(10, "[32m[42mCHEETAH[0m", :right )
...> }
{[0, 21, 3], [1, 21, 2], [3, 21, 0]}
iex> alias IO.ANSI.Table.Column
iex> {
...> Column.spread(7, "[32m[42mCHEETAH[0m", :left ),
...> Column.spread(7, "[32m[42mCHEETAH[0m", :center),
...> Column.spread(7, "[32m[42mCHEETAH[0m", :right )
...> }
{[0, 21, 0], [0, 21, 0], [0, 21, 0]}
Link to this function
widths(columns, max_width \\ 99) View Source
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)
[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 = [["[32m[42mCHEETAH[0m", "elk"], ["mongoose", "ant"]]
iex> Column.widths(data)
[7, 8]