terminal-table 3.0.0 → 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
2
  SHA256:
3
- metadata.gz: b60d520a9834db6cc69515928da37ecbe590ca52b25a1b309ee33eb8c0b1bb78
4
- data.tar.gz: b7958982dfdffcd93bdb1df97cfcb9ad154f81b1ba8553787e4e388f2d78e0bb
3
+ metadata.gz: beedfc15a1d047a36f3086b433e525c3b02d49e34922c76853bd2d16c006be31
4
+ data.tar.gz: 844ec9d624be42cd0dfaa5f33a930e4d1353cd48c1f24a36bc47173c3809d38a
5
5
  SHA512:
6
- metadata.gz: d45e247eb8e5c3713fa273da5b7a2a6cf656a953bf2fd5f23932cbbb3bada619155a9dccacd87bd0eb84c50ce2f51989b59c0400650b62f3002ff5b4d51d38de
7
- data.tar.gz: e1d3dbd179da62d871e3dd577580d2350a5ab0554f0f4b8acb043bb855560f6dd2c0dd698c499a38650f17863be6a5a9b41024ce80c1b6deccd0cfe7c93534c3
6
+ metadata.gz: 0e649b65e3692f51cdefd96d1b472cce78df675e57ed02cb96bf5444211fb99778e911d6a2e80cab30b419941f7541a93f86376bb8eaaa6726d38bc1b93f6866
7
+ data.tar.gz: e2982cd89c3255ac8d95b0ad2009ed35cd102c38c8c49fc6e8a01022a8f3c4a747eaa3918dd7ca0acf389c0748ac6fd5590d0c5b5d7d84bc2e4d70d134dfdd43
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- terminal-table (3.0.0)
5
- unicode-display_width (~> 1.1, >= 1.1.1)
4
+ terminal-table (3.0.1)
5
+ unicode-display_width (>= 1.1.1, < 3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -30,7 +30,7 @@ GEM
30
30
  term-ansicolor (1.7.1)
31
31
  tins (~> 1.0)
32
32
  tins (1.0.1)
33
- unicode-display_width (1.7.0)
33
+ unicode-display_width (2.0.0)
34
34
 
35
35
  PLATFORMS
36
36
  ruby
@@ -46,4 +46,4 @@ DEPENDENCIES
46
46
  tins (~> 1.0.0)
47
47
 
48
48
  BUNDLED WITH
49
- 2.2.0
49
+ 2.2.3
data/History.rdoc CHANGED
@@ -1,4 +1,11 @@
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
+
1
7
  3.0.0 / 2020-01-27
8
+ ==================
2
9
 
3
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.
4
11
 
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [<img src="https://github.com/tj/terminal-table/workflows/CI/badge.svg"/>](https://github.com/tj/terminal-table/actions)
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)
2
3
 
3
4
  # Terminal Table
4
5
 
@@ -63,10 +64,10 @@ To add separators between rows:
63
64
 
64
65
  ```ruby
65
66
  table = Terminal::Table.new do |t|
66
- t << ['One', 1]
67
- t << :separator
67
+ t << ['One', 1] # Using << (push) as an alias for add_row
68
+ t << :separator # Using << with :separator as an alias for add_separator
68
69
  t.add_row ['Two', 2]
69
- t.add_separator
70
+ t.add_separator # Note - this version allows setting the separator's border_type
70
71
  t.add_row ['Three', 3]
71
72
  end
72
73
 
@@ -128,7 +129,7 @@ table = Terminal::Table.new :title => "Cheatsheet", :headings => ['Word', 'Numbe
128
129
 
129
130
  # > puts table
130
131
  #
131
- # +------------+--------+
132
+ # +---------------------+
132
133
  # | Cheatsheet |
133
134
  # +------------+--------+
134
135
  # | Word | Number |
@@ -196,7 +197,7 @@ table.style = {:width => 40, :padding_left => 3, :border_x => "=", :border_i =>
196
197
 
197
198
  # > puts table
198
199
  #
199
- # x====================x=================x
200
+ # x======================================x
200
201
  # | Cheatsheet |
201
202
  # x====================x=================x
202
203
  # | Word | Number |
@@ -286,9 +287,9 @@ table.style = {:width => 40}
286
287
  ## New Formatting
287
288
 
288
289
  ### 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
+ 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.
290
291
 
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
+ 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.
292
293
 
293
294
  The simplest way to use an alternate border is one of the following:
294
295
  ```
@@ -307,7 +308,7 @@ table.style = { :border => Terminal::Table::UnicodeThickEdgeBorder.new() }
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`.
308
309
 
309
310
  ### Markdown Compatiblity
310
- Per popular request, markdown formatted tables can be generated by using the following border style:
311
+ Per popular request, Markdown formatted tables can be generated by using the following border style:
311
312
 
312
313
  ```
313
314
  table.style = { :border => :markdown }
@@ -320,37 +321,40 @@ table.style = { :border => :ascii }
320
321
  ```
321
322
 
322
323
  ### Customizing Borders
323
- Inside the `UnicodeBorder` class, there are definitions for a variety of corner/intersection types.
324
+ Inside the `UnicodeBorder` class, there are definitions for a variety of corner/intersection and divider types.
324
325
 
325
- ```
326
+ ```ruby
326
327
  @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: "┘",
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: '╍',
334
338
  }
335
339
  ```
336
340
 
337
341
  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.
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.
340
344
 
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:
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:
343
347
 
344
348
  ```
345
349
  table.style = {border: :unicode}
346
- table.style.border[:nw] = '*' # override the north-west corner of the table
350
+ table.style.border[:nw] = '*' # Override the north-west corner of the table
347
351
  ```
348
352
 
349
353
  ### Customizing row separators
350
354
 
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).
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).
352
356
 
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.
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.
354
358
 
355
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:
356
360
 
@@ -360,13 +364,12 @@ Separator `border_type`s can be adjusted to be heavy, use double-lines, and diff
360
364
  bold bold_dash bold_dot3 bold_dot4
361
365
  double
362
366
 
363
-
364
367
  To manually set the separator border_type, the `add_separator` method may be called.
365
368
  ```ruby
366
369
  add_separator(border_type: :heavy_dash)
367
370
  ```
368
371
 
369
- Alternatively, if `style: :all_separators` is used, it may be necessary to elaborate the Rows prior to rendering.
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.
370
373
  ```ruby
371
374
  table = Terminal::Table.new do |t|
372
375
  t.add_row [1, 'One']
@@ -379,6 +382,29 @@ rows[2].border_type = :heavy # modify separator row: emphasize below title
379
382
  puts table.render
380
383
  ```
381
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
+
382
408
  ## More examples
383
409
 
384
410
  For more examples, please see the `examples` directory included in the
data/examples/data.csv ADDED
@@ -0,0 +1,4 @@
1
+ First Name,Last Name,Email
2
+ TJ,Holowaychuk,tj@vision-media.ca
3
+ Bob,Someone,bob@vision-media.ca
4
+ Joe,Whatever,joe@vision-media.ca
@@ -1,4 +1,4 @@
1
- #!/bin/env ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  $:.unshift File.dirname(__FILE__) + '/../lib'
4
4
  require 'terminal-table/import'
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/terminal-table'
4
+
5
+ puts Terminal::Table.new(headings: ['a', 'b', 'c', 'd'], style: { border: :unicode })
6
+
7
+ puts
8
+
9
+ tbl = Terminal::Table.new do |t|
10
+ t.style = { border: :unicode }
11
+ t.add_separator
12
+ t.add_separator
13
+ t.add_row ['x','y','z']
14
+ t.add_separator
15
+ t.add_separator
16
+ end
17
+ puts tbl
18
+
19
+ puts
20
+
21
+ puts Terminal::Table.new(headings: [['a', 'b', 'c', 'd'], ['cat','dog','frog','mouse']], style: { border: :unicode })
22
+
23
+ puts
24
+
25
+ puts Terminal::Table.new(headings: ['a', 'b', 'c', 'd'])
26
+
27
+ puts
28
+
29
+ tbl = Terminal::Table.new do |t|
30
+ t.add_separator
31
+ t.add_separator
32
+ t.add_row ['x','y','z']
33
+ t.add_separator
34
+ t.add_separator
35
+ end
36
+ puts tbl
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "csv"
4
+ $LOAD_PATH << "#{__dir__}/../lib"
5
+ require "terminal-table"
6
+
7
+ #
8
+ # Usage:
9
+ # ./show_csv_table.rb data.csv
10
+ # cat data.csv | ./show_csv_table.rb
11
+ # cat data.csv | ./show_csv_table.rb -
12
+ #
13
+ #
14
+ # Reads a CSV from $stdin if no argument given, or argument is '-'
15
+ # otherwise interprets first cmdline argument as the CSV filename
16
+ #
17
+ use_stdin = ARGV[0].nil? || (ARGV[0] == '-')
18
+ io_object = use_stdin ? $stdin : File.open(ARGV[0], 'r')
19
+ csv = CSV.new(io_object)
20
+
21
+ #
22
+ # Convert to an array for use w/ terminal-table
23
+ # The assumption is that this is a pretty small spreadsheet.
24
+ #
25
+ csv_array = csv.to_a
26
+
27
+ user_table = Terminal::Table.new do |v|
28
+ v.style = { :border => :unicode_round } # >= v3.0.0
29
+ v.title = "Some Title"
30
+ v.headings = csv_array[0]
31
+ v.rows = csv_array[1..-1]
32
+ end
33
+
34
+ puts user_table
@@ -1,4 +1,4 @@
1
- require 'unicode/display_width/no_string_ext'
1
+ require 'unicode/display_width'
2
2
 
3
3
  module Terminal
4
4
  class Table
@@ -81,6 +81,14 @@ module Terminal
81
81
  end
82
82
  inner_width + padding
83
83
  end
84
+
85
+ def inspect
86
+ fields = %i[alignment colspan index value width].map do |name|
87
+ val = self.instance_variable_get('@'+name.to_s)
88
+ "@#{name}=#{val.inspect}"
89
+ end.join(', ')
90
+ return "#<#{self.class} #{fields}>"
91
+ end
84
92
  end
85
93
  end
86
94
  end
@@ -12,7 +12,7 @@ module Terminal
12
12
  ##
13
13
  # Initialize with _width_ and _options_.
14
14
 
15
- def initialize table, array = []
15
+ def initialize table, array = [], **_kwargs
16
16
  @cell_index = 0
17
17
  @table = table
18
18
  @cells = []
@@ -1,4 +1,4 @@
1
- require 'unicode/display_width/no_string_ext'
1
+ require 'unicode/display_width'
2
2
 
3
3
  module Terminal
4
4
  class Table
@@ -1,5 +1,5 @@
1
1
  module Terminal
2
2
  class Table
3
- VERSION = '3.0.0'
3
+ VERSION = '3.0.1'
4
4
  end
5
5
  end
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "term-ansicolor"
23
23
  spec.add_development_dependency "pry"
24
24
 
25
- spec.add_runtime_dependency "unicode-display_width", ["~> 1.1", ">= 1.1.1"]
25
+ spec.add_runtime_dependency "unicode-display_width", [">= 1.1.1", "< 3"]
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminal-table
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-01-27 00:00:00.000000000 Z
12
+ date: 2021-05-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -85,22 +85,22 @@ dependencies:
85
85
  name: unicode-display_width
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
89
- - !ruby/object:Gem::Version
90
- version: '1.1'
91
88
  - - ">="
92
89
  - !ruby/object:Gem::Version
93
90
  version: 1.1.1
91
+ - - "<"
92
+ - !ruby/object:Gem::Version
93
+ version: '3'
94
94
  type: :runtime
95
95
  prerelease: false
96
96
  version_requirements: !ruby/object:Gem::Requirement
97
97
  requirements:
98
- - - "~>"
99
- - !ruby/object:Gem::Version
100
- version: '1.1'
101
98
  - - ">="
102
99
  - !ruby/object:Gem::Version
103
100
  version: 1.1.1
101
+ - - "<"
102
+ - !ruby/object:Gem::Version
103
+ version: '3'
104
104
  description:
105
105
  email:
106
106
  - tj@vision-media.ca
@@ -118,11 +118,14 @@ files:
118
118
  - README.md
119
119
  - Rakefile
120
120
  - Todo.rdoc
121
+ - examples/data.csv
121
122
  - examples/examples.rb
122
123
  - examples/examples_unicode.rb
123
124
  - examples/issue100.rb
124
125
  - examples/issue111.rb
126
+ - examples/issue118.rb
125
127
  - examples/issue95.rb
128
+ - examples/show_csv_table.rb
126
129
  - examples/strong_separator.rb
127
130
  - lib/terminal-table.rb
128
131
  - lib/terminal-table/cell.rb
@@ -154,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
157
  - !ruby/object:Gem::Version
155
158
  version: '0'
156
159
  requirements: []
157
- rubygems_version: 3.1.4
160
+ rubygems_version: 3.2.3
158
161
  signing_key:
159
162
  specification_version: 4
160
163
  summary: Simple, feature rich ascii table generation library