public
Description: Ruby ASCII Table Generator, simple and feature rich.
Homepage:
Clone URL: git://github.com/visionmedia/terminal-table.git
name age message
file .gitignore Tue Jan 13 15:35:36 -0800 2009 - Adde doc [visionmedia]
file History.rdoc Thu Aug 06 08:25:30 -0700 2009 Release 1.2.0 [visionmedia]
file Manifest Mon Jul 13 08:53:28 -0700 2009 Update manifest Signed-off-by: TJ Holowaychuk ... [smtlaissezfaire]
file README.rdoc Sat Oct 10 10:39:46 -0700 2009 Docs [visionmedia]
file Rakefile Sat Oct 10 10:39:46 -0700 2009 Docs [visionmedia]
file Todo.rdoc Sat Mar 14 22:30:53 -0700 2009 Release 1.0.5 [visionmedia]
directory examples/ Thu Aug 06 08:22:17 -0700 2009 updated examples Signed-off-by: TJ Holowaychuk... [Flavio Castelli]
directory lib/ Thu Aug 06 08:25:30 -0700 2009 Release 1.2.0 [visionmedia]
directory spec/ Thu Aug 06 08:22:23 -0700 2009 updated unit tests Signed-off-by: TJ Holowaych... [Flavio Castelli]
directory tasks/ Tue Jan 13 15:35:11 -0800 2009 - Doc [visionmedia]
file terminal-table.gemspec Sat Oct 10 17:52:44 -0700 2009 Gem description [visionmedia]
README.rdoc

Terminal Table

Simple, feature rich ASCII table generator.

Installation:

  Install [Gemcutter](http://gemcutter.org) then execute:
  $ sudo gem install terminal-table

Features:

  • Fast
  • Simple
  • Optional headings
  • Alignment of columns, headings, or cells
  • Supports column span
  • Easy modification of table strings (+, -, |)

Examples:

  require 'rubygems'
  require 'terminal-table/import'

  puts table(['a', 'b'], [1, 2], [3, 4])

  t = table ['a', 'b']
  t << [1, 2]
  t << [3, 4]
  puts t

  user_table = table do |t|
    t.headings = 'First Name', 'Last Name', 'Email'
    t << ['TJ',  'Holowaychuk', 'tj@vision-media.ca']
    t << ['Bob', 'Someone',     'bob@vision-media.ca']
    t << ['Joe', 'Whatever',    'joe@vision-media.ca']
  end
  puts user_table

  user_table = table do
    self.headings = 'First Name', 'Last Name', 'Email'
    add_row ['TJ',  'Holowaychuk', { :value => 'tj@vision-media.ca', :align => :right }]
    add_row ['Bob', 'Someone',     'bob@vision-media.ca']
    add_row ['Joe', 'Whatever',    'joe@vision-media.ca']
    align_column 1, :center
  end
  puts user_table

  puts
  user_table = table do
    self.headings = ['First Name', 'Last Name', {:value => 'Phones', :colspan => 2, :alignment => :center}]
    add_row ['Bob', 'Someone',     '123', '456']
    add_row ['TJ',  'Holowaychuk', {:value => "No phones", :colspan => 2, :alignment => :center}]
    add_row ['Joe', 'Whatever',    '4324', '343242']
  end
  puts user_table

  rows = []
  rows << ['Lines',      100]
  rows << ['Comments',   20]
  rows << ['Ruby',       70]
  rows << ['JavaScript', 30]
  puts table([nil, 'Lines'], *rows)

  rows = []
  rows << ['Lines',      100]
  rows << ['Comments',   20]
  rows << ['Ruby',       70]
  rows << ['JavaScript', 30]
  puts table(nil, *rows)

Results:

  +---+---+
  | a | b |
  +---+---+
  | 1 | 2 |
  | 3 | 4 |
  +---+---+

  +---+---+
  | a | b |
  +---+---+
  | 1 | 2 |
  | 3 | 4 |
  +---+---+

  +------------+-------------+---------------------+
  | First Name | Last Name   | Email               |
  +------------+-------------+---------------------+
  | TJ         | Holowaychuk | tj@vision-media.ca  |
  | Bob        | Someone     | bob@vision-media.ca |
  | Joe        | Whatever    | joe@vision-media.ca |
  +------------+-------------+---------------------+

  +------------+-----------------------------+---------------------+
  | First Name | Last Name                   | Email               |
  +------------+-----------------------------+---------------------+
  | TJ         |         Holowaychuk         |  tj@vision-media.ca |
  | Bob        |           Someone           | bob@vision-media.ca |
  | Joe        |          Whatever           | joe@vision-media.ca |
  +------------+-----------------------------+---------------------+

  +------------+-------------+-----------+--------+
  | First Name | Last Name   |       Phones       |
  +------------+-------------+-----------+--------+
  | Bob        | Someone     | 123       | 456    |
  | TJ         | Holowaychuk |     No phones      |
  | Joe        | Whatever    | 4324      | 343242 |
  +------------+-------------+-----------+--------+

  +------------+-------+
  |            | Lines |
  +------------+-------+
  | Lines      | 100   |
  | Comments   | 20    |
  | Ruby       | 70    |
  | JavaScript | 30    |
  +------------+-------+

  +------------+-----+
  | Lines      | 100 |
  | Comments   | 20  |
  | Ruby       | 70  |
  | JavaScript | 30  |
  +------------+-----+

License:

(The MIT License)

Copyright © 2008-2009 TJ Holowaychuk <tj@vision-media.ca>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, an d/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.