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 +4 -4
- data/History.rdoc +8 -0
- data/README.rdoc +1 -1
- data/lib/terminal-table/cell.rb +5 -2
- data/lib/terminal-table/table.rb +13 -3
- data/lib/terminal-table/version.rb +1 -1
- data/terminal-table.gemspec +2 -0
- metadata +16 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfb17272e7d15b11623d2e7db0b5ee5cece62345
|
4
|
+
data.tar.gz: 01f29016e517f64038ef5da9428cbcdb59a9e192
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a924d05a9e389acf1e7b5a7eeb6bbc706ae7ca5742d0fb94380dfbadc6de281eb5a8fe81e831379be7201bdde49cbb3d598cc446ce26a830ae3f71b54998cf07
|
7
|
+
data.tar.gz: 9e1d3a3cb750e9074679cfe06bdbd08271a11c64c0783a9847853edbacc622322cc7df499a1afd8849f79173e04ff7955e258aa19079795f6afaffb22d81d291
|
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -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
|
|
data/lib/terminal-table/cell.rb
CHANGED
@@ -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
|
-
|
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
|
71
|
+
lines.map{ |s| escape(s) }.max_by{ |s| Unicode::DisplayWidth.of(s) }
|
69
72
|
end
|
70
73
|
|
71
74
|
##
|
data/lib/terminal-table/table.rb
CHANGED
@@ -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
|
-
|
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
|
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)
|
data/terminal-table.gemspec
CHANGED
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.
|
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-
|
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:
|