terminal-table 1.7.2 → 3.0.1

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
- SHA1:
3
- metadata.gz: 6c0927620bf05c372458c73382bfd171be972288
4
- data.tar.gz: e7aad54b23b37641a9edf68867d8b741af52563e
2
+ SHA256:
3
+ metadata.gz: beedfc15a1d047a36f3086b433e525c3b02d49e34922c76853bd2d16c006be31
4
+ data.tar.gz: 844ec9d624be42cd0dfaa5f33a930e4d1353cd48c1f24a36bc47173c3809d38a
5
5
  SHA512:
6
- metadata.gz: 469f18cf16097c03b06e4e39696f04b8fa7547facc206cdfc52ac4fa918b78109d6ef6caeb14366c3bc2d4902ef3e6fd23587d453c90d80fabd7249a94b1c0ec
7
- data.tar.gz: d6c9253df10b4bed36b4a494ef20c39dc462e2c388ad3b1cdeb464676bbe31458b718f14283818c99713e813c5c9cd728ddd7ce8f4bd64cebdba8f300633b689
6
+ metadata.gz: 0e649b65e3692f51cdefd96d1b472cce78df675e57ed02cb96bf5444211fb99778e911d6a2e80cab30b419941f7541a93f86376bb8eaaa6726d38bc1b93f6866
7
+ data.tar.gz: e2982cd89c3255ac8d95b0ad2009ed35cd102c38c8c49fc6e8a01022a8f3c4a747eaa3918dd7ca0acf389c0748ac6fd5590d0c5b5d7d84bc2e4d70d134dfdd43
@@ -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
@@ -3,4 +3,8 @@ pkg
3
3
  tmp
4
4
  *.cache
5
5
  doc
6
- Gemfile.lock
6
+ vendor
7
+ /.bundle
8
+
9
+ # tempfiles
10
+ *~
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in test-gem.gemspec
4
4
  gemspec
5
+
6
+ gem 'tins', '~> 1.0.0' # Ruby 1.9 compat
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ terminal-table (3.0.1)
5
+ unicode-display_width (>= 1.1.1, < 3)
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 (2.0.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.3
data/History.rdoc CHANGED
@@ -1,3 +1,69 @@
1
+ 3.0.1 / 2021-05-10
2
+ ==================
3
+
4
+ - Support for unicode-display_width 2.0
5
+ - Fix issue where last row of an empty table changed format
6
+
7
+ 3.0.0 / 2020-01-27
8
+ ==================
9
+
10
+ - 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.
11
+
12
+ For example, previously the output of a table may be:
13
+ +------+-----+
14
+ | Title |
15
+ +------+-----+
16
+ | Char | Num |
17
+ +------+-----+
18
+ | a | 1 |
19
+ | b | 2 |
20
+ | c | 3 |
21
+ +------+-----+
22
+
23
+ And now the `+` character above the word Title is removed, as it is no longer considered an intersection:
24
+
25
+ +------------+
26
+ | Title |
27
+ +------+-----+
28
+ | Char | Num |
29
+ +------+-----+
30
+ | a | 1 |
31
+ | b | 2 |
32
+ +------+-----+
33
+
34
+ - 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.
35
+
36
+ In support of this update, the following issues were addressed:
37
+ - colspan creates conflict with colorize (#95)
38
+ - Use nice UTF box-drawing characters by default (#99)
39
+ - Note that `AsciiBorder` is stll the default
40
+ - Border-left and border-right style (#100)
41
+ - Helper function to style as Markdown (#111)
42
+ - Achieved using `MarkdownBorder`
43
+
44
+ 2.0.0 / 2020-10-28
45
+ ==================
46
+
47
+ - Drops official support for Ruby 1.9.x with and of life on 2015-02-23
48
+ - Drops official support for Ruby 2.0.x with and of life on 2016-02-24
49
+ - Drops official support for Ruby 2.1.x with and of life on 2017-03-31
50
+ - Drops official support for Ruby 2.2.x with and of life on 2018-03-31
51
+ - Drops official support for Ruby 2.3.x with and of life on 2019-03-31
52
+
53
+ 1.8.0 / 2017-05-16
54
+ ==================
55
+
56
+ * Top and bottom borders can be disabled (@kubakrzempek, #83)
57
+ * `unicode-display-width` dependency relaxes (@mvz, #88)
58
+
59
+ * Readme and docs fixes (@loualrid, #82 and @leoarnold, #86)
60
+ * Fixed some test-related warnings (@juanitofatas, #81 and @mvz, #89)
61
+
62
+ 1.7.3 / 2016-09-21
63
+ ==================
64
+
65
+ * Fixed compatibility issues for Ruby 1.9, 2.0, 2.1. (@vivekbisen, #80)
66
+
1
67
  1.7.2 / 2016-09-09
2
68
  ==================
3
69
 
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,417 @@
1
+ [![CI status](https://github.com/tj/terminal-table/workflows/CI/badge.svg)](https://github.com/tj/terminal-table/actions)
2
+ [![Gem Version](https://badge.fury.io/rb/terminal-table.svg)](https://badge.fury.io/rb/terminal-table)
3
+
4
+ # Terminal Table
5
+
6
+ ## Description
7
+
8
+ Terminal Table is a fast and simple, yet feature rich table generator
9
+ written in Ruby. It supports ASCII and Unicode formatted tables.
10
+
11
+ ## Installation
12
+
13
+ ```
14
+ $ gem install terminal-table
15
+ ```
16
+ ## Usage
17
+
18
+ ### Basics
19
+
20
+ To use Terminal Table:
21
+
22
+ ```ruby
23
+ require 'terminal-table'
24
+ ```
25
+ To generate a table, provide an array of arrays (which are interpreted as
26
+ rows):
27
+
28
+ ```ruby
29
+ rows = []
30
+ rows << ['One', 1]
31
+ rows << ['Two', 2]
32
+ rows << ['Three', 3]
33
+ table = Terminal::Table.new :rows => rows
34
+
35
+ # > puts table
36
+ #
37
+ # +-------+---+
38
+ # | One | 1 |
39
+ # | Two | 2 |
40
+ # | Three | 3 |
41
+ # +-------+---+
42
+ ```
43
+ The constructor can also be given a block which is either yielded the Table
44
+ object or instance evaluated:
45
+
46
+ ```ruby
47
+ table = Terminal::Table.new do |t|
48
+ t.rows = rows
49
+ end
50
+
51
+ table = Terminal::Table.new do
52
+ self.rows = rows
53
+ end
54
+ ```
55
+ Adding rows one by one:
56
+
57
+ ```ruby
58
+ table = Terminal::Table.new do |t|
59
+ t << ['One', 1]
60
+ t.add_row ['Two', 2]
61
+ end
62
+ ```
63
+ To add separators between rows:
64
+
65
+ ```ruby
66
+ table = Terminal::Table.new do |t|
67
+ t << ['One', 1] # Using << (push) as an alias for add_row
68
+ t << :separator # Using << with :separator as an alias for add_separator
69
+ t.add_row ['Two', 2]
70
+ t.add_separator # Note - this version allows setting the separator's border_type
71
+ t.add_row ['Three', 3]
72
+ end
73
+
74
+ # > puts table
75
+ #
76
+ # +-------+---+
77
+ # | One | 1 |
78
+ # +-------+---+
79
+ # | Two | 2 |
80
+ # +-------+---+
81
+ # | Three | 3 |
82
+ # +-------+---+
83
+ ```
84
+ Cells can handle multiline content:
85
+
86
+ ```ruby
87
+ table = Terminal::Table.new do |t|
88
+ t << ['One', 1]
89
+ t << :separator
90
+ t.add_row ["Two\nDouble", 2]
91
+ t.add_separator
92
+ t.add_row ['Three', 3]
93
+ end
94
+
95
+ # > puts table
96
+ #
97
+ # +--------+---+
98
+ # | One | 1 |
99
+ # +--------+---+
100
+ # | Two | 2 |
101
+ # | Double | |
102
+ # +--------+---+
103
+ # | Three | 3 |
104
+ # +--------+---+
105
+ ```
106
+ ### Head
107
+
108
+ To add a head to the table:
109
+
110
+ ```ruby
111
+ table = Terminal::Table.new :headings => ['Word', 'Number'], :rows => rows
112
+
113
+ # > puts table
114
+ #
115
+ # +-------+--------+
116
+ # | Word | Number |
117
+ # +-------+--------+
118
+ # | One | 1 |
119
+ # | Two | 2 |
120
+ # | Three | 3 |
121
+ # +-------+--------+
122
+ ```
123
+ ### Title
124
+
125
+ To add a title to the table:
126
+
127
+ ```ruby
128
+ table = Terminal::Table.new :title => "Cheatsheet", :headings => ['Word', 'Number'], :rows => rows
129
+
130
+ # > puts table
131
+ #
132
+ # +---------------------+
133
+ # | Cheatsheet |
134
+ # +------------+--------+
135
+ # | Word | Number |
136
+ # +------------+--------+
137
+ # | One | 1 |
138
+ # | Two | 2 |
139
+ # | Three | 3 |
140
+ # +------------+--------+
141
+ ```
142
+ ### Alignment
143
+
144
+ To align the second column to the right:
145
+
146
+ ```ruby
147
+ table.align_column(1, :right)
148
+
149
+ # > puts table
150
+ #
151
+ # +-------+--------+
152
+ # | Word | Number |
153
+ # +-------+--------+
154
+ # | One | 1 |
155
+ # | Two | 2 |
156
+ # | Three | 3 |
157
+ # +-------+--------+
158
+ ```
159
+ To align an individual cell, you specify the cell value in a hash along the
160
+ alignment:
161
+
162
+ ```ruby
163
+ table << ["Four", {:value => 4.0, :alignment => :center}]
164
+
165
+ # > puts table
166
+ #
167
+ # +-------+--------+
168
+ # | Word | Number |
169
+ # +-------+--------+
170
+ # | One | 1 |
171
+ # | Two | 2 |
172
+ # | Three | 3 |
173
+ # | Four | 4.0 |
174
+ # +-------+--------+
175
+ ```
176
+ ### Style
177
+
178
+ To specify style options:
179
+
180
+ ```ruby
181
+ table = Terminal::Table.new :headings => ['Word', 'Number'], :rows => rows, :style => {:width => 80}
182
+
183
+ # > puts table
184
+ #
185
+ # +--------------------------------------+---------------------------------------+
186
+ # | Word | Number |
187
+ # +--------------------------------------+---------------------------------------+
188
+ # | One | 1 |
189
+ # | Two | 2 |
190
+ # | Three | 3 |
191
+ # +--------------------------------------+---------------------------------------+
192
+ ```
193
+ And change styles on the fly:
194
+
195
+ ```ruby
196
+ table.style = {:width => 40, :padding_left => 3, :border_x => "=", :border_i => "x"}
197
+
198
+ # > puts table
199
+ #
200
+ # x======================================x
201
+ # | Cheatsheet |
202
+ # x====================x=================x
203
+ # | Word | Number |
204
+ # x====================x=================x
205
+ # | One | 1 |
206
+ # | Two | 2 |
207
+ # | Three | 3 |
208
+ # x====================x=================x
209
+ ```
210
+ You can also use styles to add a separator after every row:
211
+
212
+ ```ruby
213
+ table = Terminal::Table.new do |t|
214
+ t.add_row [1, 'One']
215
+ t.add_row [2, 'Two']
216
+ t.add_row [3, 'Three']
217
+ t.style = {:all_separators => true}
218
+ end
219
+
220
+ # > puts table
221
+ #
222
+ # +---+-------+
223
+ # | 1 | One |
224
+ # +---+-------+
225
+ # | 2 | Two |
226
+ # +---+-------+
227
+ # | 3 | Three |
228
+ # +---+-------+
229
+ ```
230
+ You can also use styles to disable top and bottom borders of the table.
231
+
232
+ ```ruby
233
+ table = Terminal::Table.new do |t|
234
+ t.headings = ['id', 'name']
235
+ t.rows = [[1, 'One'], [2, 'Two'], [3, 'Three']]
236
+ t.style = { :border_top => false, :border_bottom => false }
237
+ end
238
+
239
+ # > puts table
240
+ # | id | name |
241
+ # +----+-------+
242
+ # | 1 | One |
243
+ # | 2 | Two |
244
+ # | 3 | Three |
245
+ ```
246
+
247
+ And also to disable left and right borders of the table.
248
+
249
+ ```ruby
250
+ table = Terminal::Table.new do |t|
251
+ t.headings = ['id', 'name']
252
+ t.rows = [[1, 'One'], [2, 'Two'], [3, 'Three']]
253
+ t.style = { :border_left => false, :border_right => false }
254
+ end
255
+
256
+ # > puts table
257
+ # ----+-------
258
+ # id | name
259
+ # ----+-------
260
+ # 1 | One
261
+ # 2 | Two
262
+ # 3 | Three
263
+ # ----+-------
264
+ ```
265
+
266
+ To change the default style options:
267
+
268
+ ```ruby
269
+ Terminal::Table::Style.defaults = {:width => 80}
270
+ ```
271
+ All Table objects created afterwards will inherit these defaults.
272
+
273
+ ### Constructor options and setter methods
274
+
275
+ Valid options for the constructor are `:rows`, `:headings`, `:style` and `:title` -
276
+ and all options can also be set on the created table object by their setter
277
+ method:
278
+
279
+ ```ruby
280
+ table = Terminal::Table.new
281
+ table.title = "Cheatsheet"
282
+ table.headings = ['Word', 'Number']
283
+ table.rows = rows
284
+ table.style = {:width => 40}
285
+ ```
286
+
287
+ ## New Formatting
288
+
289
+ ### Unicode Table Borders
290
+ Support for Unicode 'box art' borders presented a challenge, as the original 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.
291
+
292
+ For the sake of backward compatiblity, the previous interface is still supported, as this gem has been around a long time and making breaking changes would have been 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.
293
+
294
+ The simplest way to use an alternate border is one of the following:
295
+ ```
296
+ table.style = { :border => :unicode }
297
+ table.style = { :border => :unicode_round }
298
+ table.style = { :border => :unicode_thick_edge }
299
+ ```
300
+
301
+ These are a convenience wrapper around setting border using an instance of a class that inherits from Table::Terminal::Border
302
+ ```
303
+ table.style = { :border => Terminal::Table::UnicodeBorder.new() }
304
+ table.style = { :border => Terminal::Table::UnicodeRoundBorder.new() }
305
+ table.style = { :border => Terminal::Table::UnicodeThickEdgeBorder.new() }
306
+ ```
307
+
308
+ 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`.
309
+
310
+ ### Markdown Compatiblity
311
+ Per popular request, Markdown formatted tables can be generated by using the following border style:
312
+
313
+ ```
314
+ table.style = { :border => :markdown }
315
+ ```
316
+
317
+ ### Ascii Borders
318
+ Ascii borders are default, but can be explicitly set with:
319
+ ```
320
+ table.style = { :border => :ascii }
321
+ ```
322
+
323
+ ### Customizing Borders
324
+ Inside the `UnicodeBorder` class, there are definitions for a variety of corner/intersection and divider types.
325
+
326
+ ```ruby
327
+ @data = {
328
+ nil => nil,
329
+ nw: "┌", nx: "─", n: "┬", ne: "┐",
330
+ yw: "│", y: "│", ye: "│",
331
+ aw: "╞", ax: "═", ai: "╪", ae: "╡", ad: '╤', au: "╧", # double
332
+ bw: "┝", bx: "━", bi: "┿", be: "┥", bd: '┯', bu: "┷", # heavy/bold/thick
333
+ w: "├", x: "─", i: "┼", e: "┤", dn: "┬", up: "┴", # normal div
334
+ sw: "└", sx: "─", s: "┴", se: "┘",
335
+ # alternative dots/dashes
336
+ x_dot4: '┈', x_dot3: '┄', x_dash: '╌',
337
+ bx_dot4: '┉', bx_dot3: '┅', bx_dash: '╍',
338
+ }
339
+ ```
340
+
341
+ Note that many are defined as directional (:nw == north-west), others defined in terms of 'x' or 'y'.
342
+ The border that separates headings (below each heading) is of type `:double` and is defined with `a*` entries.
343
+ Alternate `:heavy` types that can be applied to separators can be defined with `b*` entries.
344
+
345
+ 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.
346
+ However, these elements can be these can be overridden by poking setting the Hash, should the need arise:
347
+
348
+ ```
349
+ table.style = {border: :unicode}
350
+ table.style.border[:nw] = '*' # Override the north-west corner of the table
351
+ ```
352
+
353
+ ### Customizing row separators
354
+
355
+ Row-separators can now be customized in a variety of ways. The default separator's border_type is referred to as `:div`. Additional separator border types (e.g. `:double`, `:heavy`, `:dash` - see full list below) can be applied to separate the sections (e.g. header/footer/title).
356
+
357
+ The separator's `border_type` may be specified when a user-defined separator is added. Alternatively, borders may be adjusted after the table's rows are elaborated, but before the table is rendered.
358
+
359
+ 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:
360
+
361
+ div dash dot3 dot4
362
+ thick thick_dash thick_dot3 thick_dot4
363
+ heavy heavy_dash heavy_dot3 heavy_dot4
364
+ bold bold_dash bold_dot3 bold_dot4
365
+ double
366
+
367
+ To manually set the separator border_type, the `add_separator` method may be called.
368
+ ```ruby
369
+ add_separator(border_type: :heavy_dash)
370
+ ```
371
+
372
+ Alternatively, if `style: :all_separators` is used at the table level, it may be necessary to elaborate the implicit Separator rows prior to rendering.
373
+ ```ruby
374
+ table = Terminal::Table.new do |t|
375
+ t.add_row [1, 'One']
376
+ t.add_row [2, 'Two']
377
+ t.add_row [3, 'Three']
378
+ t.style = {:all_separators => true}
379
+ end
380
+ rows = table.elaborate_rows
381
+ rows[2].border_type = :heavy # modify separator row: emphasize below title
382
+ puts table.render
383
+ ```
384
+
385
+ ## Example: Displaying a small CSV spreadsheet
386
+
387
+ This example code demonstrates using Terminal-table and CSV to display a small spreadsheet.
388
+
389
+ ```ruby
390
+ #!/usr/bin/env ruby
391
+ require "csv"
392
+ require "terminal-table"
393
+ use_stdin = ARGV[0].nil? || (ARGV[0] == '-')
394
+ io_object = use_stdin ? $stdin : File.open(ARGV[0], 'r')
395
+ csv = CSV.new(io_object)
396
+ csv_array = csv.to_a
397
+ user_table = Terminal::Table.new do |v|
398
+ v.style = { :border => :unicode_round } # >= v3.0.0
399
+ v.title = "Some Title"
400
+ v.headings = csv_array[0]
401
+ v.rows = csv_array[1..-1]
402
+ end
403
+ puts user_table
404
+ ```
405
+
406
+ See also `examples/show_csv_table.rb` in the source distribution.
407
+
408
+ ## More examples
409
+
410
+ For more examples, please see the `examples` directory included in the
411
+ source distribution.
412
+
413
+ ## Author
414
+
415
+ TJ Holowaychuk <tj@vision-media.ca>
416
+
417
+ Unicode table support by Ben Bowers https://github.com/nanobowers