terminal-table 1.7.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +28 -0
- data/.gitignore +5 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +49 -0
- data/History.rdoc +64 -0
- data/LICENSE.txt +21 -0
- data/README.md +391 -0
- data/Rakefile +10 -4
- data/examples/examples.rb +0 -0
- data/examples/examples_unicode.rb +89 -0
- data/examples/issue100.rb +34 -0
- data/examples/issue111.rb +4 -0
- data/examples/issue95.rb +42 -0
- data/examples/strong_separator.rb +23 -0
- data/lib/terminal-table.rb +2 -2
- data/lib/terminal-table/cell.rb +3 -11
- data/lib/terminal-table/row.rb +21 -3
- data/lib/terminal-table/separator.rb +56 -4
- data/lib/terminal-table/style.rb +227 -10
- data/lib/terminal-table/table.rb +183 -48
- data/lib/terminal-table/util.rb +13 -0
- data/lib/terminal-table/version.rb +1 -1
- data/terminal-table.gemspec +3 -3
- metadata +27 -13
- data/README.rdoc +0 -238
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b60d520a9834db6cc69515928da37ecbe590ca52b25a1b309ee33eb8c0b1bb78
|
4
|
+
data.tar.gz: b7958982dfdffcd93bdb1df97cfcb9ad154f81b1ba8553787e4e388f2d78e0bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d45e247eb8e5c3713fa273da5b7a2a6cf656a953bf2fd5f23932cbbb3bada619155a9dccacd87bd0eb84c50ce2f51989b59c0400650b62f3002ff5b4d51d38de
|
7
|
+
data.tar.gz: e1d3dbd179da62d871e3dd577580d2350a5ab0554f0f4b8acb043bb855560f6dd2c0dd698c499a38650f17863be6a5a9b41024ce80c1b6deccd0cfe7c93534c3
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push]
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
7
|
+
|
8
|
+
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
|
13
|
+
matrix:
|
14
|
+
os: [ubuntu]
|
15
|
+
ruby: [2.4, 2.5, 2.6, 2.7]
|
16
|
+
|
17
|
+
runs-on: ${{ matrix.os }}-latest
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v2
|
21
|
+
|
22
|
+
- uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
bundler-cache: true
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
26
|
+
|
27
|
+
- run: bundle install
|
28
|
+
- run: bundle exec rspec
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
terminal-table (3.0.0)
|
5
|
+
unicode-display_width (~> 1.1, >= 1.1.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
method_source (1.0.0)
|
13
|
+
pry (0.13.1)
|
14
|
+
coderay (~> 1.1)
|
15
|
+
method_source (~> 1.0)
|
16
|
+
rake (13.0.1)
|
17
|
+
rspec (3.10.0)
|
18
|
+
rspec-core (~> 3.10.0)
|
19
|
+
rspec-expectations (~> 3.10.0)
|
20
|
+
rspec-mocks (~> 3.10.0)
|
21
|
+
rspec-core (3.10.0)
|
22
|
+
rspec-support (~> 3.10.0)
|
23
|
+
rspec-expectations (3.10.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.10.0)
|
26
|
+
rspec-mocks (3.10.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.10.0)
|
29
|
+
rspec-support (3.10.0)
|
30
|
+
term-ansicolor (1.7.1)
|
31
|
+
tins (~> 1.0)
|
32
|
+
tins (1.0.1)
|
33
|
+
unicode-display_width (1.7.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
x86_64-linux
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 2)
|
41
|
+
pry
|
42
|
+
rake (~> 13.0)
|
43
|
+
rspec (>= 3.0)
|
44
|
+
term-ansicolor
|
45
|
+
terminal-table!
|
46
|
+
tins (~> 1.0.0)
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
2.2.0
|
data/History.rdoc
CHANGED
@@ -1,3 +1,67 @@
|
|
1
|
+
3.0.0 / 2020-01-27
|
2
|
+
|
3
|
+
- Support for (optional) Unicode border styles on tables. In order to support decent looking Unicode borders, different types of intersections get different types of intersection characters. This has the side effect of subtle formatting differences even for the ASCII table border case due to removal of certain intersections near colspans.
|
4
|
+
|
5
|
+
For example, previously the output of a table may be:
|
6
|
+
+------+-----+
|
7
|
+
| Title |
|
8
|
+
+------+-----+
|
9
|
+
| Char | Num |
|
10
|
+
+------+-----+
|
11
|
+
| a | 1 |
|
12
|
+
| b | 2 |
|
13
|
+
| c | 3 |
|
14
|
+
+------+-----+
|
15
|
+
|
16
|
+
And now the `+` character above the word Title is removed, as it is no longer considered an intersection:
|
17
|
+
|
18
|
+
+------------+
|
19
|
+
| Title |
|
20
|
+
+------+-----+
|
21
|
+
| Char | Num |
|
22
|
+
+------+-----+
|
23
|
+
| a | 1 |
|
24
|
+
| b | 2 |
|
25
|
+
+------+-----+
|
26
|
+
|
27
|
+
- The default border remains an ASCII border for backwards compatibility, however multiple border classes are included / documented, and user defined border types can be applied as needed.
|
28
|
+
|
29
|
+
In support of this update, the following issues were addressed:
|
30
|
+
- colspan creates conflict with colorize (#95)
|
31
|
+
- Use nice UTF box-drawing characters by default (#99)
|
32
|
+
- Note that `AsciiBorder` is stll the default
|
33
|
+
- Border-left and border-right style (#100)
|
34
|
+
- Helper function to style as Markdown (#111)
|
35
|
+
- Achieved using `MarkdownBorder`
|
36
|
+
|
37
|
+
2.0.0 / 2020-10-28
|
38
|
+
==================
|
39
|
+
|
40
|
+
- Drops official support for Ruby 1.9.x with and of life on 2015-02-23
|
41
|
+
- Drops official support for Ruby 2.0.x with and of life on 2016-02-24
|
42
|
+
- Drops official support for Ruby 2.1.x with and of life on 2017-03-31
|
43
|
+
- Drops official support for Ruby 2.2.x with and of life on 2018-03-31
|
44
|
+
- Drops official support for Ruby 2.3.x with and of life on 2019-03-31
|
45
|
+
|
46
|
+
1.8.0 / 2017-05-16
|
47
|
+
==================
|
48
|
+
|
49
|
+
* Top and bottom borders can be disabled (@kubakrzempek, #83)
|
50
|
+
* `unicode-display-width` dependency relaxes (@mvz, #88)
|
51
|
+
|
52
|
+
* Readme and docs fixes (@loualrid, #82 and @leoarnold, #86)
|
53
|
+
* Fixed some test-related warnings (@juanitofatas, #81 and @mvz, #89)
|
54
|
+
|
55
|
+
1.7.3 / 2016-09-21
|
56
|
+
==================
|
57
|
+
|
58
|
+
* Fixed compatibility issues for Ruby 1.9, 2.0, 2.1. (@vivekbisen, #80)
|
59
|
+
|
60
|
+
1.7.2 / 2016-09-09
|
61
|
+
==================
|
62
|
+
|
63
|
+
* Fix packing table to a minimal width (@vizv, #76)
|
64
|
+
|
1
65
|
1.7.1 / 2016-08-29
|
2
66
|
==================
|
3
67
|
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2008-2017 TJ Holowaychuk <tj@vision-media.ca>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,391 @@
|
|
1
|
+
[<img src="https://github.com/tj/terminal-table/workflows/CI/badge.svg"/>](https://github.com/tj/terminal-table/actions)
|
2
|
+
|
3
|
+
# Terminal Table
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
Terminal Table is a fast and simple, yet feature rich table generator
|
8
|
+
written in Ruby. It supports ASCII and Unicode formatted tables.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
```
|
13
|
+
$ gem install terminal-table
|
14
|
+
```
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
### Basics
|
18
|
+
|
19
|
+
To use Terminal Table:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'terminal-table'
|
23
|
+
```
|
24
|
+
To generate a table, provide an array of arrays (which are interpreted as
|
25
|
+
rows):
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
rows = []
|
29
|
+
rows << ['One', 1]
|
30
|
+
rows << ['Two', 2]
|
31
|
+
rows << ['Three', 3]
|
32
|
+
table = Terminal::Table.new :rows => rows
|
33
|
+
|
34
|
+
# > puts table
|
35
|
+
#
|
36
|
+
# +-------+---+
|
37
|
+
# | One | 1 |
|
38
|
+
# | Two | 2 |
|
39
|
+
# | Three | 3 |
|
40
|
+
# +-------+---+
|
41
|
+
```
|
42
|
+
The constructor can also be given a block which is either yielded the Table
|
43
|
+
object or instance evaluated:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
table = Terminal::Table.new do |t|
|
47
|
+
t.rows = rows
|
48
|
+
end
|
49
|
+
|
50
|
+
table = Terminal::Table.new do
|
51
|
+
self.rows = rows
|
52
|
+
end
|
53
|
+
```
|
54
|
+
Adding rows one by one:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
table = Terminal::Table.new do |t|
|
58
|
+
t << ['One', 1]
|
59
|
+
t.add_row ['Two', 2]
|
60
|
+
end
|
61
|
+
```
|
62
|
+
To add separators between rows:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
table = Terminal::Table.new do |t|
|
66
|
+
t << ['One', 1]
|
67
|
+
t << :separator
|
68
|
+
t.add_row ['Two', 2]
|
69
|
+
t.add_separator
|
70
|
+
t.add_row ['Three', 3]
|
71
|
+
end
|
72
|
+
|
73
|
+
# > puts table
|
74
|
+
#
|
75
|
+
# +-------+---+
|
76
|
+
# | One | 1 |
|
77
|
+
# +-------+---+
|
78
|
+
# | Two | 2 |
|
79
|
+
# +-------+---+
|
80
|
+
# | Three | 3 |
|
81
|
+
# +-------+---+
|
82
|
+
```
|
83
|
+
Cells can handle multiline content:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
table = Terminal::Table.new do |t|
|
87
|
+
t << ['One', 1]
|
88
|
+
t << :separator
|
89
|
+
t.add_row ["Two\nDouble", 2]
|
90
|
+
t.add_separator
|
91
|
+
t.add_row ['Three', 3]
|
92
|
+
end
|
93
|
+
|
94
|
+
# > puts table
|
95
|
+
#
|
96
|
+
# +--------+---+
|
97
|
+
# | One | 1 |
|
98
|
+
# +--------+---+
|
99
|
+
# | Two | 2 |
|
100
|
+
# | Double | |
|
101
|
+
# +--------+---+
|
102
|
+
# | Three | 3 |
|
103
|
+
# +--------+---+
|
104
|
+
```
|
105
|
+
### Head
|
106
|
+
|
107
|
+
To add a head to the table:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
table = Terminal::Table.new :headings => ['Word', 'Number'], :rows => rows
|
111
|
+
|
112
|
+
# > puts table
|
113
|
+
#
|
114
|
+
# +-------+--------+
|
115
|
+
# | Word | Number |
|
116
|
+
# +-------+--------+
|
117
|
+
# | One | 1 |
|
118
|
+
# | Two | 2 |
|
119
|
+
# | Three | 3 |
|
120
|
+
# +-------+--------+
|
121
|
+
```
|
122
|
+
### Title
|
123
|
+
|
124
|
+
To add a title to the table:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
table = Terminal::Table.new :title => "Cheatsheet", :headings => ['Word', 'Number'], :rows => rows
|
128
|
+
|
129
|
+
# > puts table
|
130
|
+
#
|
131
|
+
# +------------+--------+
|
132
|
+
# | Cheatsheet |
|
133
|
+
# +------------+--------+
|
134
|
+
# | Word | Number |
|
135
|
+
# +------------+--------+
|
136
|
+
# | One | 1 |
|
137
|
+
# | Two | 2 |
|
138
|
+
# | Three | 3 |
|
139
|
+
# +------------+--------+
|
140
|
+
```
|
141
|
+
### Alignment
|
142
|
+
|
143
|
+
To align the second column to the right:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
table.align_column(1, :right)
|
147
|
+
|
148
|
+
# > puts table
|
149
|
+
#
|
150
|
+
# +-------+--------+
|
151
|
+
# | Word | Number |
|
152
|
+
# +-------+--------+
|
153
|
+
# | One | 1 |
|
154
|
+
# | Two | 2 |
|
155
|
+
# | Three | 3 |
|
156
|
+
# +-------+--------+
|
157
|
+
```
|
158
|
+
To align an individual cell, you specify the cell value in a hash along the
|
159
|
+
alignment:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
table << ["Four", {:value => 4.0, :alignment => :center}]
|
163
|
+
|
164
|
+
# > puts table
|
165
|
+
#
|
166
|
+
# +-------+--------+
|
167
|
+
# | Word | Number |
|
168
|
+
# +-------+--------+
|
169
|
+
# | One | 1 |
|
170
|
+
# | Two | 2 |
|
171
|
+
# | Three | 3 |
|
172
|
+
# | Four | 4.0 |
|
173
|
+
# +-------+--------+
|
174
|
+
```
|
175
|
+
### Style
|
176
|
+
|
177
|
+
To specify style options:
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
table = Terminal::Table.new :headings => ['Word', 'Number'], :rows => rows, :style => {:width => 80}
|
181
|
+
|
182
|
+
# > puts table
|
183
|
+
#
|
184
|
+
# +--------------------------------------+---------------------------------------+
|
185
|
+
# | Word | Number |
|
186
|
+
# +--------------------------------------+---------------------------------------+
|
187
|
+
# | One | 1 |
|
188
|
+
# | Two | 2 |
|
189
|
+
# | Three | 3 |
|
190
|
+
# +--------------------------------------+---------------------------------------+
|
191
|
+
```
|
192
|
+
And change styles on the fly:
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
table.style = {:width => 40, :padding_left => 3, :border_x => "=", :border_i => "x"}
|
196
|
+
|
197
|
+
# > puts table
|
198
|
+
#
|
199
|
+
# x====================x=================x
|
200
|
+
# | Cheatsheet |
|
201
|
+
# x====================x=================x
|
202
|
+
# | Word | Number |
|
203
|
+
# x====================x=================x
|
204
|
+
# | One | 1 |
|
205
|
+
# | Two | 2 |
|
206
|
+
# | Three | 3 |
|
207
|
+
# x====================x=================x
|
208
|
+
```
|
209
|
+
You can also use styles to add a separator after every row:
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
table = Terminal::Table.new do |t|
|
213
|
+
t.add_row [1, 'One']
|
214
|
+
t.add_row [2, 'Two']
|
215
|
+
t.add_row [3, 'Three']
|
216
|
+
t.style = {:all_separators => true}
|
217
|
+
end
|
218
|
+
|
219
|
+
# > puts table
|
220
|
+
#
|
221
|
+
# +---+-------+
|
222
|
+
# | 1 | One |
|
223
|
+
# +---+-------+
|
224
|
+
# | 2 | Two |
|
225
|
+
# +---+-------+
|
226
|
+
# | 3 | Three |
|
227
|
+
# +---+-------+
|
228
|
+
```
|
229
|
+
You can also use styles to disable top and bottom borders of the table.
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
table = Terminal::Table.new do |t|
|
233
|
+
t.headings = ['id', 'name']
|
234
|
+
t.rows = [[1, 'One'], [2, 'Two'], [3, 'Three']]
|
235
|
+
t.style = { :border_top => false, :border_bottom => false }
|
236
|
+
end
|
237
|
+
|
238
|
+
# > puts table
|
239
|
+
# | id | name |
|
240
|
+
# +----+-------+
|
241
|
+
# | 1 | One |
|
242
|
+
# | 2 | Two |
|
243
|
+
# | 3 | Three |
|
244
|
+
```
|
245
|
+
|
246
|
+
And also to disable left and right borders of the table.
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
table = Terminal::Table.new do |t|
|
250
|
+
t.headings = ['id', 'name']
|
251
|
+
t.rows = [[1, 'One'], [2, 'Two'], [3, 'Three']]
|
252
|
+
t.style = { :border_left => false, :border_right => false }
|
253
|
+
end
|
254
|
+
|
255
|
+
# > puts table
|
256
|
+
# ----+-------
|
257
|
+
# id | name
|
258
|
+
# ----+-------
|
259
|
+
# 1 | One
|
260
|
+
# 2 | Two
|
261
|
+
# 3 | Three
|
262
|
+
# ----+-------
|
263
|
+
```
|
264
|
+
|
265
|
+
To change the default style options:
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
Terminal::Table::Style.defaults = {:width => 80}
|
269
|
+
```
|
270
|
+
All Table objects created afterwards will inherit these defaults.
|
271
|
+
|
272
|
+
### Constructor options and setter methods
|
273
|
+
|
274
|
+
Valid options for the constructor are `:rows`, `:headings`, `:style` and `:title` -
|
275
|
+
and all options can also be set on the created table object by their setter
|
276
|
+
method:
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
table = Terminal::Table.new
|
280
|
+
table.title = "Cheatsheet"
|
281
|
+
table.headings = ['Word', 'Number']
|
282
|
+
table.rows = rows
|
283
|
+
table.style = {:width => 40}
|
284
|
+
```
|
285
|
+
|
286
|
+
## New Formatting
|
287
|
+
|
288
|
+
### Unicode Table Borders
|
289
|
+
A support for Unicode 'box art' borders presented a challenge, as the basics of terminal-table only handled three border types: horizontal (x), vertical (y), and intersection (i). For proper box-art, it became necessary to enable different types of corners/edges for multiple intersection types.
|
290
|
+
|
291
|
+
For the sake of backward compatiblity, the previous interface is still supported, this gem has been around a long time and making breaking changes would be inconvenient. The new interface is required for any complex and/or unicode style bordering. A few variations on border style are supported via some new classes and creation of additional classes (or modification of characters used in existing ones) will allow for customized border types.
|
292
|
+
|
293
|
+
The simplest way to use an alternate border is one of the following:
|
294
|
+
```
|
295
|
+
table.style = { :border => :unicode }
|
296
|
+
table.style = { :border => :unicode_round }
|
297
|
+
table.style = { :border => :unicode_thick_edge }
|
298
|
+
```
|
299
|
+
|
300
|
+
These are a convenience wrapper around setting border using an instance of a class that inherits from Table::Terminal::Border
|
301
|
+
```
|
302
|
+
table.style = { :border => Terminal::Table::UnicodeBorder.new() }
|
303
|
+
table.style = { :border => Terminal::Table::UnicodeRoundBorder.new() }
|
304
|
+
table.style = { :border => Terminal::Table::UnicodeThickEdgeBorder.new() }
|
305
|
+
```
|
306
|
+
|
307
|
+
If you define a custom class and wish to use the symbol shortcut, you must namespace within `Terminal::Table` and end your class name with `Border`.
|
308
|
+
|
309
|
+
### Markdown Compatiblity
|
310
|
+
Per popular request, markdown formatted tables can be generated by using the following border style:
|
311
|
+
|
312
|
+
```
|
313
|
+
table.style = { :border => :markdown }
|
314
|
+
```
|
315
|
+
|
316
|
+
### Ascii Borders
|
317
|
+
Ascii borders are default, but can be explicitly set with:
|
318
|
+
```
|
319
|
+
table.style = { :border => :ascii }
|
320
|
+
```
|
321
|
+
|
322
|
+
### Customizing Borders
|
323
|
+
Inside the `UnicodeBorder` class, there are definitions for a variety of corner/intersection types.
|
324
|
+
|
325
|
+
```
|
326
|
+
@data = {
|
327
|
+
nil => nil,
|
328
|
+
nw: "┌", nx: "─", n: "┬", ne: "┐",
|
329
|
+
yw: "│", y: "│", ye: "│",
|
330
|
+
aw: "╞", ax: "═", ai: "╪", ae: "╡", ad: '╤', au: "╧",
|
331
|
+
bw: "┝", bx: "━", bi: "┿", be: "┥", bd: '┯', bu: "┷",
|
332
|
+
w: "├", x: "─", i: "┼", e: "┤", dn: "┬", up: "┴",
|
333
|
+
sw: "└", sx: "─", s: "┴", se: "┘",
|
334
|
+
}
|
335
|
+
```
|
336
|
+
|
337
|
+
Note that many are defined as directional (:nw == north-west), others defined in terms of 'x' or 'y'.
|
338
|
+
The border that separates headings (below each heading) is of type `:double` and is defined with 'a*' entries.
|
339
|
+
Alternate `:heavy` types that can be applied to separators can be defined with 'b*' entries.
|
340
|
+
|
341
|
+
When defining a new set of borders, it's probably easiest to define a new class that inherits from UnicodeBorder and replaces the @data Hash.
|
342
|
+
However, these corners can be these can be overridden with:
|
343
|
+
|
344
|
+
```
|
345
|
+
table.style = {border: :unicode}
|
346
|
+
table.style.border[:nw] = '*' # override the north-west corner of the table
|
347
|
+
```
|
348
|
+
|
349
|
+
### Customizing row separators
|
350
|
+
|
351
|
+
Row-separators can now be customized in a variety of ways. The default separator's border_type is referred to as `:mid`. Additional `:strong` / `:strong_a` and `:strong_b` separator styles can be applied to separate sections (e.g. header/footer/title).
|
352
|
+
|
353
|
+
The separator border_type may be specified when a user-defined separator added. Alternatively, borders may be adjusted after the table's rows are elaborated, but before the table is rendered.
|
354
|
+
|
355
|
+
Separator `border_type`s can be adjusted to be heavy, use double-lines, and different dash/dot styles. The border type should be one of:
|
356
|
+
|
357
|
+
div dash dot3 dot4
|
358
|
+
thick thick_dash thick_dot3 thick_dot4
|
359
|
+
heavy heavy_dash heavy_dot3 heavy_dot4
|
360
|
+
bold bold_dash bold_dot3 bold_dot4
|
361
|
+
double
|
362
|
+
|
363
|
+
|
364
|
+
To manually set the separator border_type, the `add_separator` method may be called.
|
365
|
+
```ruby
|
366
|
+
add_separator(border_type: :heavy_dash)
|
367
|
+
```
|
368
|
+
|
369
|
+
Alternatively, if `style: :all_separators` is used, it may be necessary to elaborate the Rows prior to rendering.
|
370
|
+
```ruby
|
371
|
+
table = Terminal::Table.new do |t|
|
372
|
+
t.add_row [1, 'One']
|
373
|
+
t.add_row [2, 'Two']
|
374
|
+
t.add_row [3, 'Three']
|
375
|
+
t.style = {:all_separators => true}
|
376
|
+
end
|
377
|
+
rows = table.elaborate_rows
|
378
|
+
rows[2].border_type = :heavy # modify separator row: emphasize below title
|
379
|
+
puts table.render
|
380
|
+
```
|
381
|
+
|
382
|
+
## More examples
|
383
|
+
|
384
|
+
For more examples, please see the `examples` directory included in the
|
385
|
+
source distribution.
|
386
|
+
|
387
|
+
## Author
|
388
|
+
|
389
|
+
TJ Holowaychuk <tj@vision-media.ca>
|
390
|
+
|
391
|
+
Unicode table support by Ben Bowers https://github.com/nanobowers
|