Giter Site home page Giter Site logo

milkwine / io_ansi_table Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raymondloranger/io_ansi_table

0.0 2.0 0.0 380 KB

Prints data to STDOUT in a table with borders and colors. Can choose a table style to change the look of the table.

Elixir 100.00%

io_ansi_table's Introduction

IO ANSI Table

Build Status

Prints data to STDOUT in a table with borders and colors. Can choose a table style to change the look of the table.

Inspired by the book Programming Elixir by Dave Thomas.

Installation

Add the :io_ansi_table dependency to your mix.exs file:

def deps do
  [
    {:io_ansi_table, "~> 0.4"}
  ]
end

Usage

In your config/config.exs, you should then configure the table formatting options.

Examples

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

Notes

For side-by-side tables, you can specify negative top margins.

In addition to the 16 regular ANSI colors and their background counterparts, this package also supports the 256 Xterm colors (foreground and background).

Most of these 256 colors were given names like:

  • #00ffff:aqua
  • #87ff00:chartreuse
  • #d700ff:psychedelic_purple

For details, see file config/persist_colors.exs.

The following 2 packages use :io_ansi_table as a dependency to tabulate data fetched from the web:

Customization

You can create new table styles or modify any predefined one by changing the dependency's config/persist_styles.exs file. You would then need to run mix deps.compile io_ansi_table [--force] to make the changes effective.

Latest version

The latest version supports:

  • sorting on multiple headers
  • alternating row attributes
  • alignment of column elements
  • sort direction indicators
  • negative top margins
  • ANSI and Xterm-256 colors

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.