README.rdoc in terminal-table-1.7.3 vs README.rdoc in terminal-table-1.8.0
- old
+ new
@@ -21,11 +21,11 @@
rows = []
rows << ['One', 1]
rows << ['Two', 2]
rows << ['Three', 3]
table = Terminal::Table.new :rows => rows
-
+
# > puts table
#
# +-------+---+
# | One | 1 |
# | Two | 2 |
@@ -49,19 +49,19 @@
t << ['One', 1]
t.add_row ['Two', 2]
end
To add separators between rows:
-
+
table = Terminal::Table.new do |t|
t << ['One', 1]
t << :separator
t.add_row ['Two', 2]
t.add_separator
t.add_row ['Three', 3]
end
-
+
# > puts table
#
# +-------+---+
# | One | 1 |
# +-------+---+
@@ -69,19 +69,19 @@
# +-------+---+
# | Three | 3 |
# +-------+---+
Cells can handle multiline content:
-
+
table = Terminal::Table.new do |t|
t << ['One', 1]
t << :separator
t.add_row ["Two\nDouble", 2]
t.add_separator
t.add_row ['Three', 3]
end
-
+
# > puts table
#
# +--------+---+
# | One | 1 |
# +--------+---+
@@ -94,11 +94,11 @@
=== Head
To add a head to the table:
table = Terminal::Table.new :headings => ['Word', 'Number'], :rows => rows
-
+
# > puts table
#
# +-------+--------+
# | Word | Number |
# +-------+--------+
@@ -110,11 +110,11 @@
=== Title
To add a title to the table:
table = Terminal::Table.new :title => "Cheatsheet", :headings => ['Word', 'Number'], :rows => rows
-
+
# > puts table
#
# +------------+--------+
# | Cheatsheet |
# +------------+--------+
@@ -128,11 +128,11 @@
=== Alignment
To align the second column to the right:
table.align_column(1, :right)
-
+
# > puts table
#
# +-------+--------+
# | Word | Number |
# +-------+--------+
@@ -142,28 +142,28 @@
# +-------+--------+
To align an individual cell, you specify the cell value in a hash along the alignment:
table << ["Four", {:value => 4.0, :alignment => :center}]
-
+
# > puts table
#
# +-------+--------+
# | Word | Number |
# +-------+--------+
# | One | 1 |
# | Two | 2 |
# | Three | 3 |
# | Four | 4.0 |
# +-------+--------+
-
+
=== Style
To specify style options:
-
+
table = Terminal::Table.new :headings => ['Word', 'Number'], :rows => rows, :style => {:width => 80}
-
+
# > puts table
#
# +--------------------------------------+---------------------------------------+
# | Word | Number |
# +--------------------------------------+---------------------------------------+
@@ -171,13 +171,13 @@
# | Two | 2 |
# | Three | 3 |
# +--------------------------------------+---------------------------------------+
And change styles on the fly:
-
+
table.style = {:width => 40, :padding_left => 3, :border_x => "=", :border_i => "x"}
-
+
# > puts table
#
# x====================x=================x
# | Cheatsheet |
# x====================x=================x
@@ -185,11 +185,45 @@
# x====================x=================x
# | One | 1 |
# | Two | 2 |
# | Three | 3 |
# x====================x=================x
-
+
+You can also use styles to add a separator after every row:
+
+ table = Terminal::Table.new do |t|
+ t.add_row [1, 'One']
+ t.add_row [2, 'Two']
+ t.add_row [3, 'Three']
+ t.style = {:all_separators => true}
+ end
+
+ # > puts table
+ #
+ # +---+-------+
+ # | 1 | One |
+ # +---+-------+
+ # | 2 | Two |
+ # +---+-------+
+ # | 3 | Three |
+ # +---+-------+
+
+You can also use styles to disable top and bottom borders of the table
+
+ table = Terminal::Table.new do |t|
+ t.headings = ['id', 'name']
+ t.rows = [[1, 'One'], [2, 'Two'], [3, 'Three']]
+ t.style = { :border_top => false, :border_bottom => false }
+ end
+
+ # > puts table
+ # | id | name |
+ # +----+-------+
+ # | 1 | One |
+ # | 2 | Two |
+ # | 3 | Three |
+
To change the default style options:
Terminal::Table::Style.defaults = {:width => 80}
All Table objects created afterwards will inherit these defaults.
@@ -209,30 +243,5 @@
For more examples, please see the examples/examples.rb file included in the source distribution.
== Author
TJ Holowaychuk <tj@vision-media.ca>
-
-== License
-
-(The MIT License)
-
-Copyright (c) 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.