terminal-table 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e955f9096ab89f2568bd233c53dcb58d38172fceff26123d1ff60a8af951e71
4
- data.tar.gz: 5c46d6e5cdeb4d233901374a5a5671768731e01ba246ee87ebc04788ea48de11
3
+ metadata.gz: b60d520a9834db6cc69515928da37ecbe590ca52b25a1b309ee33eb8c0b1bb78
4
+ data.tar.gz: b7958982dfdffcd93bdb1df97cfcb9ad154f81b1ba8553787e4e388f2d78e0bb
5
5
  SHA512:
6
- metadata.gz: d11bc2fbcfec5b822035e97b0c6e2e5393c06b54770b53dd0067f7120fd55a2382f9027186bd0ac2633c926788347df794a0672cdfd476c14754e310f2d1608b
7
- data.tar.gz: 7f69a5f7c6282defa0e2d9aebec91ab549a6d577520d8cc2d1d32116831234e36d9def50ee9d5995c900e0c8a82057f2a13e943164f259e85d09e7797008c599
6
+ metadata.gz: d45e247eb8e5c3713fa273da5b7a2a6cf656a953bf2fd5f23932cbbb3bada619155a9dccacd87bd0eb84c50ce2f51989b59c0400650b62f3002ff5b4d51d38de
7
+ data.tar.gz: e1d3dbd179da62d871e3dd577580d2350a5ab0554f0f4b8acb043bb855560f6dd2c0dd698c499a38650f17863be6a5a9b41024ce80c1b6deccd0cfe7c93534c3
data/.gitignore CHANGED
@@ -5,3 +5,6 @@ tmp
5
5
  doc
6
6
  vendor
7
7
  /.bundle
8
+
9
+ # tempfiles
10
+ *~
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- terminal-table (2.0.0)
4
+ terminal-table (3.0.0)
5
5
  unicode-display_width (~> 1.1, >= 1.1.1)
6
6
 
7
7
  GEM
@@ -14,19 +14,19 @@ GEM
14
14
  coderay (~> 1.1)
15
15
  method_source (~> 1.0)
16
16
  rake (13.0.1)
17
- rspec (3.9.0)
18
- rspec-core (~> 3.9.0)
19
- rspec-expectations (~> 3.9.0)
20
- rspec-mocks (~> 3.9.0)
21
- rspec-core (3.9.3)
22
- rspec-support (~> 3.9.3)
23
- rspec-expectations (3.9.3)
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
24
  diff-lcs (>= 1.2.0, < 2.0)
25
- rspec-support (~> 3.9.0)
26
- rspec-mocks (3.9.1)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-mocks (3.10.0)
27
27
  diff-lcs (>= 1.2.0, < 2.0)
28
- rspec-support (~> 3.9.0)
29
- rspec-support (3.9.4)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-support (3.10.0)
30
30
  term-ansicolor (1.7.1)
31
31
  tins (~> 1.0)
32
32
  tins (1.0.1)
@@ -34,6 +34,7 @@ GEM
34
34
 
35
35
  PLATFORMS
36
36
  ruby
37
+ x86_64-linux
37
38
 
38
39
  DEPENDENCIES
39
40
  bundler (~> 2)
@@ -45,4 +46,4 @@ DEPENDENCIES
45
46
  tins (~> 1.0.0)
46
47
 
47
48
  BUNDLED WITH
48
- 2.1.4
49
+ 2.2.0
@@ -1,3 +1,39 @@
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
+
1
37
  2.0.0 / 2020-10-28
2
38
  ==================
3
39
 
@@ -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