IO ANSI Table v0.3.14 IO.ANSI.Table View Source
Prints data to STDOUT in a table with borders and colors.
Can choose a table style among the 40 already predefined.
Link to this section Summary
Functions
Prints data from maps to STDOUT in a table tailored by options
Link to this section Functions
format([Access.container()], Keyword.t()) :: :ok
Prints data from maps to STDOUT in a table tailored by options.
All options can be configured and/or passed as a keyword argument.
Each option of the keyword will override its configured counterpart.
You should however configure all options except possibly
bell, count and style.
The columns are identified by the :headers option (map keys).
We calculate the width of each column to fit the longest element
in that column, also considering the column heading.
However, the :max_width option prevails.
If the :count option is positive, we format the first n
maps in the list, once sorted. If negative, the last n ones.
See IO.ANSI.Table.Options for examples of all options.
Parameters
maps- list of maps/keywords/structs (list)options- up to 10 options all configurable (keyword)
Options
:align_specs- to align column elements (list):bell- ring the bell? (boolean):count- number ofmapsto format (integer):headers- to identify each column (list):header_fixes- to alter theheaders(map):margins- to position the table (keyword):max_width- to cap column widths (non_neg_integer):sort_specs- to sort themaps(list):sort_symbols- to denote sort direction (keyword):style- table style (atom)
Table styles
:bare- no colors:barish- like bare but colored:cyan- light cyan background:cyan_alt- cyan header, alternating row colors:cyan_border- light cyan border:cyan_mult- cyan header, 3 repeating row colors:dark- dark colors:dark_alt- dark colors, alternating row colors:dark_mult- dark colors, 3 repeating row colors:dashed- no colors:dotted- slightly colored:dotted_alt- slightly colored, alternating row colors:dotted_mult- slightly colored, 3 repeating row colors:game_cyan- cyan headers, 3 repeating row colors:game_green- green headers, 3 repeating row colors:game_magenta- magenta headers, 3 repeating row colors:game_red- red headers, 3 repeating row colors:game_yellow- yellow headers, 3 repeating row colors:green- light green background:green_alt- green header, alternating row colors:green_border- light green border:green_border_padded- light green border with extra padding:green_border_unpadded- light green border without padding:green_mult- green header, 3 repeating row colors:green_padded- like green but with extra padding:green_unpadded- like green but without padding:light- light colors:light_alt- light colors, alternating row colors:light_mult- light colors, 3 repeating row colors:medium- medium colors:medium_alt- medium colors, alternating row colors:medium_mult- medium colors, 3 repeating row colors:mixed- fillers revealed:plain- slightly colored:pretty- multicolored:pretty_alt- multicolored, alternating row colors:pretty_mult- multicolored, 3 repeating row colors:test- no colors:yellow- light yellow background:yellow_border- light yellow border
Examples
alias IO.ANSI.Table
people = [
%{name: "Mike", likes: "ski, arts", dob: "1992-04-15"},
%{name: "Mary", likes: "reading" , dob: "1985-07-11"},
%{name: "Ray" , likes: "cycling" , dob: "1977-08-28"}
]
Table.format(
people, bell: true, count: 3, style: :dark,
headers: [:name, :dob, :likes],
header_fixes: %{~r[^dob$]i => "Date of Birth"},
sort_specs: [:dob],
align_specs: [center: :dob],
margins: [top: 2, bottom: 2]
)
