terminal-table 1.6.0 → 1.7.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
  SHA1:
3
- metadata.gz: 906edc10ddbc49ce496a4bb49d2b0318ce67ce87
4
- data.tar.gz: e28e319ee32ef1be3a81ccd3e324970d7778a20d
3
+ metadata.gz: cfb17272e7d15b11623d2e7db0b5ee5cece62345
4
+ data.tar.gz: 01f29016e517f64038ef5da9428cbcdb59a9e192
5
5
  SHA512:
6
- metadata.gz: 37a853ebbf1ccad933892ed34372ca2126d3f302f4c81e9da4dd3e53937613af6e0f820e62c2675a3da50e3542b185d7bd523d15312f37535ca29c95dba14c13
7
- data.tar.gz: 8ef39f7169f4682ed4c94739ef2cda11eb1be487b4991e1c4fa3b70ebb7a30bc728d29eaa991d4849c873f58df04b86e3f4ce7bd5c76647893f439550d71b548
6
+ metadata.gz: a924d05a9e389acf1e7b5a7eeb6bbc706ae7ca5742d0fb94380dfbadc6de281eb5a8fe81e831379be7201bdde49cbb3d598cc446ce26a830ae3f71b54998cf07
7
+ data.tar.gz: 9e1d3a3cb750e9074679cfe06bdbd08271a11c64c0783a9847853edbacc622322cc7df499a1afd8849f79173e04ff7955e258aa19079795f6afaffb22d81d291
@@ -1,3 +1,11 @@
1
+ 1.7.0 / 2016-08-29
2
+ ==================
3
+
4
+ All props to @vizv for this release!
5
+
6
+ * Fixed some spec failures
7
+ * Added support for full-width characters (East Asian alphabets, etc)
8
+
1
9
  1.6.0 / 2016-06-06
2
10
  ==================
3
11
 
@@ -190,7 +190,7 @@ And change styles on the fly:
190
190
 
191
191
  To change the default style options:
192
192
 
193
- Terminal::Style.defaults = {:width => 80}
193
+ Terminal::Table::Style.defaults = {:width => 80}
194
194
 
195
195
  All Table objects created afterwards will inherit these defaults.
196
196
 
@@ -1,3 +1,5 @@
1
+ require 'unicode/display_width'
2
+
1
3
  module Terminal
2
4
  class Table
3
5
  class Cell
@@ -55,7 +57,8 @@ module Terminal
55
57
  def render(line = 0)
56
58
  left = " " * @table.style.padding_left
57
59
  right = " " * @table.style.padding_right
58
- render_width = lines[line].to_s.size - escape(lines[line]).size + width
60
+ display_width = Unicode::DisplayWidth.of(escape(lines[line]))
61
+ render_width = lines[line].to_s.size - display_width + width
59
62
  align("#{left}#{lines[line]}#{right}", alignment, render_width + @table.cell_padding)
60
63
  end
61
64
  alias :to_s :render
@@ -65,7 +68,7 @@ module Terminal
65
68
  # removes all ANSI escape sequences (e.g. color)
66
69
 
67
70
  def value_for_column_width_recalc
68
- lines.map{ |s| escape(s) }.max_by{ |s| s.size }
71
+ lines.map{ |s| escape(s) }.max_by{ |s| Unicode::DisplayWidth.of(s) }
69
72
  end
70
73
 
71
74
  ##
@@ -1,3 +1,5 @@
1
+ require 'unicode/display_width'
2
+
1
3
  module Terminal
2
4
  class Table
3
5
 
@@ -57,7 +59,15 @@ module Terminal
57
59
 
58
60
  def column n, method = :value, array = rows
59
61
  array.map { |row|
60
- cell = row[n]
62
+ # for each cells in a row, find the column with index
63
+ # just greater than the required one, and go back one.
64
+ index = col = 0
65
+ row.cells.each do |cell|
66
+ break if index > n
67
+ index += cell.colspan
68
+ col += 1
69
+ end
70
+ cell = row[col - 1]
61
71
  cell && method ? cell.__send__(method) : cell
62
72
  }.compact
63
73
  end
@@ -126,7 +136,7 @@ module Terminal
126
136
  buffer += @rows
127
137
  buffer << separator
128
138
  end
129
- buffer.map { |r| style.margin_left + r.render }.join("\n")
139
+ buffer.map { |r| style.margin_left + r.render.rstrip }.join("\n")
130
140
  end
131
141
  alias :to_s :render
132
142
 
@@ -192,7 +202,7 @@ module Terminal
192
202
  colspan = cell.colspan
193
203
  cell_value = cell.value_for_column_width_recalc
194
204
  colspan.downto(1) do |j|
195
- cell_length = cell_value.to_s.length
205
+ cell_length = Unicode::DisplayWidth.of(cell_value.to_s)
196
206
  if colspan > 1
197
207
  spacing_length = cell_spacing * (colspan - 1)
198
208
  length_in_columns = (cell_length - spacing_length)
@@ -1,5 +1,5 @@
1
1
  module Terminal
2
2
  class Table
3
- VERSION = '1.6.0'
3
+ VERSION = '1.7.0'
4
4
  end
5
5
  end
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "rspec", ">= 3.0"
22
22
  spec.add_development_dependency "term-ansicolor"
23
23
  spec.add_development_dependency "pry"
24
+
25
+ spec.add_runtime_dependency "unicode-display_width", "~> 1.1"
24
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: 1.6.0
4
+ version: 1.7.0
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: 2016-06-06 00:00:00.000000000 Z
12
+ date: 2016-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: unicode-display_width
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.1'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.1'
84
98
  description:
85
99
  email:
86
100
  - tj@vision-media.ca
@@ -131,4 +145,3 @@ signing_key:
131
145
  specification_version: 4
132
146
  summary: Simple, feature rich ascii table generation library
133
147
  test_files: []
134
- has_rdoc: