IO ANSI Table v0.4.3 IO.ANSI.Table View Source

Prints data to STDOUT in a table with borders and colors.

Can choose a table style to change the look of the table.

Link to this section Summary

Functions

Prints data from maps to STDOUT in a table tailored by options

Link to this section Functions

Link to this function format(maps, options \\ []) View Source
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 of maps to format (integer)
  • :headers - to identify each column (list)
  • :header_fixes - to alter the headers (map)
  • :margins - to position the table (keyword)
  • :max_width - to cap column widths (non_neg_integer)
  • :sort_specs - to sort the maps (list)
  • :sort_symbols - to denote sort direction (keyword)
  • :style - table style (atom)

Table styles

  • :bare - no colors
  • :barish - like bare but colored
  • :cyan - 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 - game board
  • :green - 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

# Assuming the following config:

# config :io_ansi_table, headers: [:name, :dob, :likes]
# config :io_ansi_table, header_fixes: %{~r[dob]i => "Date of Birth"}
# config :io_ansi_table, sort_specs: [asc: :dob]
# config :io_ansi_table, align_specs: [center: :dob]
# config :io_ansi_table, margins: [top: 2, bottom: 2]

alias IO.ANSI.Table
people = [
  %{name: "Mike", likes: "ski, arts", dob: "1992-04-15", bmi: 23.9},
  %{name: "Mary", likes: "travels"  , dob: "1992-04-15", bmi: 26.8},
  %{name: "Ann" , likes: "reading"  , dob: "1992-04-15", bmi: 24.7},
  %{name: "Ray" , likes: "cycling"  , dob: "1977-08-28", bmi: 19.1},
  %{name: "Bill", likes: "karate"   , dob: "1977-08-28", bmi: 18.1},
  %{name: "Joe" , likes: "boxing"   , dob: "1977-08-28", bmi: 20.8},
  %{name: "Jill", likes: "cooking"  , dob: "1976-09-28", bmi: 25.8}
]
Table.format(people, style: :light)
Table.format(people, style: :light_alt)
Table.format(people, style: :light_mult)
Table.format(people, style: :cyan_alt)
Table.format(people, style: :cyan_mult)

light

light_alt

light_mult

cyan_alt

cyan_mult