tty-table 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -3
- data/CHANGELOG.md +16 -0
- data/Gemfile +4 -4
- data/README.md +3 -3
- data/appveyor.yml +2 -0
- data/benchmarks/speed.rb +3 -5
- data/examples/alignment.rb +3 -3
- data/examples/basic.rb +2 -2
- data/examples/orientation.rb +13 -0
- data/examples/padding.rb +15 -0
- data/examples/resize.rb +15 -0
- data/lib/tty/table.rb +2 -1
- data/lib/tty/table/border.rb +4 -12
- data/lib/tty/table/column_constraint.rb +15 -7
- data/lib/tty/table/columns.rb +42 -68
- data/lib/tty/table/field.rb +3 -13
- data/lib/tty/table/indentation.rb +9 -20
- data/lib/tty/table/operation/alignment.rb +2 -2
- data/lib/tty/table/operation/padding.rb +3 -3
- data/lib/tty/table/operation/truncation.rb +3 -3
- data/lib/tty/table/operation/wrapped.rb +3 -3
- data/lib/tty/table/operations.rb +3 -14
- data/lib/tty/table/renderer.rb +28 -24
- data/lib/tty/table/renderer/ascii.rb +1 -1
- data/lib/tty/table/renderer/basic.rb +42 -41
- data/lib/tty/table/renderer/unicode.rb +1 -1
- data/lib/tty/table/version.rb +1 -3
- data/spec/unit/border/ascii/rendering_spec.rb +1 -1
- data/spec/unit/border/null/rendering_spec.rb +1 -1
- data/spec/unit/border/unicode/rendering_spec.rb +1 -1
- data/spec/unit/column_constraint/enforce_spec.rb +2 -2
- data/spec/unit/columns/extract_widths_spec.rb +7 -12
- data/spec/unit/columns/total_width_spec.rb +3 -4
- data/spec/unit/indentation/indent_spec.rb +2 -6
- data/spec/unit/operations/new_spec.rb +3 -5
- data/spec/unit/renderer/ascii/padding_spec.rb +29 -0
- data/tty-table.gemspec +3 -4
- metadata +12 -24
data/lib/tty/table/version.rb
CHANGED
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe TTY::Table::Border::ASCII, '#rendering' do
|
6
6
|
|
7
|
-
subject(:border) { described_class.new(column_widths
|
7
|
+
subject(:border) { described_class.new(column_widths) }
|
8
8
|
|
9
9
|
context 'with empty row' do
|
10
10
|
let(:row) { TTY::Table::Row.new([]) }
|
@@ -5,7 +5,7 @@ require 'spec_helper'
|
|
5
5
|
RSpec.describe TTY::Table::Border::Null, '#rendering' do
|
6
6
|
let(:border) { nil }
|
7
7
|
|
8
|
-
subject { described_class.new column_widths,
|
8
|
+
subject { described_class.new column_widths, border }
|
9
9
|
|
10
10
|
context 'with empty row' do
|
11
11
|
let(:row) { TTY::Table::Row.new([]) }
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
RSpec.describe TTY::Table::Border::Unicode, '#rendering' do
|
6
6
|
|
7
|
-
subject(:border) { described_class.new(column_widths
|
7
|
+
subject(:border) { described_class.new(column_widths) }
|
8
8
|
|
9
9
|
context 'with empty row' do
|
10
10
|
let(:row) { TTY::Table::Row.new([]) }
|
@@ -25,9 +25,9 @@ RSpec.describe TTY::Table::ColumnConstraint, '#enforce' do
|
|
25
25
|
let(:options) { { width: 11, resize: true }}
|
26
26
|
|
27
27
|
it 'raises error when table width is too small' do
|
28
|
-
allow(columns).to receive(:
|
28
|
+
allow(columns).to receive(:expand_column_widths)
|
29
29
|
columns.enforce
|
30
|
-
expect(columns).to have_received(:
|
30
|
+
expect(columns).to have_received(:expand_column_widths)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -6,33 +6,29 @@ RSpec.describe TTY::Table::Columns, '#extract_widths' do
|
|
6
6
|
it 'extract widths' do
|
7
7
|
header = ['h1', 'h2', 'h3']
|
8
8
|
rows = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']]
|
9
|
-
table = TTY::Table.new
|
10
|
-
|
11
|
-
expect(column_set.extract_widths).to eql([2,2,2])
|
9
|
+
table = TTY::Table.new(header, rows)
|
10
|
+
expect(described_class.extract_widths(table.data)).to eql([2,2,2])
|
12
11
|
end
|
13
12
|
|
14
13
|
it "extracts widths from utf" do
|
15
14
|
header = ['h1', 'うなじ']
|
16
15
|
rows = [['こんにちは', 'a2'], ['b1','選択']]
|
17
|
-
table = TTY::Table.new
|
18
|
-
|
19
|
-
expect(column_set.extract_widths).to eql([10,6])
|
16
|
+
table = TTY::Table.new(header, rows)
|
17
|
+
expect(described_class.extract_widths(table.data)).to eql([10,6])
|
20
18
|
end
|
21
19
|
|
22
20
|
it "extracts widths from multiline text" do
|
23
21
|
table = TTY::Table.new
|
24
22
|
table << ["Multi\nLine\nContent", "Text\nthat\nwraps"]
|
25
23
|
table << ["Some\nother\ntext", 'Simple']
|
26
|
-
|
27
|
-
expect(column_set.extract_widths).to eq([7,6])
|
24
|
+
expect(described_class.extract_widths(table.data)).to eq([7,6])
|
28
25
|
end
|
29
26
|
|
30
27
|
it "extracts widths from multiline text" do
|
31
28
|
table = TTY::Table.new
|
32
29
|
table << ["Multi\\nLine\\nContent", "Text\\nthat\\nwraps"]
|
33
30
|
table << ["Some\\nother\\ntext", 'Simple']
|
34
|
-
|
35
|
-
expect(column_set.extract_widths).to eq([20, 17])
|
31
|
+
expect(described_class.extract_widths(table.data)).to eq([20, 17])
|
36
32
|
end
|
37
33
|
|
38
34
|
it "extracts widths from ANSI text" do
|
@@ -40,7 +36,6 @@ RSpec.describe TTY::Table::Columns, '#extract_widths' do
|
|
40
36
|
table = TTY::Table.new header: header
|
41
37
|
table << [color.green.on_blue('a1'), 'a2']
|
42
38
|
table << ['b1', color.red.on_yellow('b2')]
|
43
|
-
|
44
|
-
expect(column_set.extract_widths).to eq([2,2])
|
39
|
+
expect(described_class.extract_widths(table.data)).to eq([2,2])
|
45
40
|
end
|
46
41
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
RSpec.describe TTY::Table::Columns, '#extract_widths!' do
|
4
5
|
let(:header) { ['h1', 'h2', 'h3'] }
|
5
6
|
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { TTY::Table.new header, rows }
|
7
|
-
|
8
|
-
subject { described_class.new table }
|
9
7
|
|
10
8
|
it 'extract widths' do
|
11
|
-
|
9
|
+
table = TTY::Table.new(header, rows)
|
10
|
+
expect(described_class.total_width(table.data)).to eql(6)
|
12
11
|
end
|
13
12
|
end
|
@@ -3,19 +3,15 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe TTY::Table::Indentation, '.indent' do
|
6
|
-
let(:indent) { 2 }
|
7
|
-
|
8
|
-
subject(:indentation) { described_class.new(indent) }
|
9
|
-
|
10
6
|
context 'when enumerable' do
|
11
7
|
it 'inserts indentation for each element' do
|
12
|
-
expect(
|
8
|
+
expect(described_class.indent(['line1'], 2)).to eql([' line1'])
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
16
12
|
context 'when string' do
|
17
13
|
it 'inserts indentation' do
|
18
|
-
expect(
|
14
|
+
expect(described_class.indent('line1', 2)).to eql(' line1')
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
RSpec.describe TTY::Table::Operations, '#new' do
|
6
4
|
let(:object) { described_class }
|
7
5
|
let(:row) { [1,2,3] }
|
@@ -15,7 +13,7 @@ RSpec.describe TTY::Table::Operations, '#new' do
|
|
15
13
|
}
|
16
14
|
let(:instance) { callable.new }
|
17
15
|
|
18
|
-
subject { object.new
|
16
|
+
subject { object.new }
|
19
17
|
|
20
18
|
before { subject.add(:alignment, instance) }
|
21
19
|
|
@@ -23,8 +21,8 @@ RSpec.describe TTY::Table::Operations, '#new' do
|
|
23
21
|
expect(subject[:alignment]).to include(instance)
|
24
22
|
end
|
25
23
|
|
26
|
-
it '
|
27
|
-
subject.
|
24
|
+
it 'applies selected operations' do
|
25
|
+
subject.apply_to(table, :alignment)
|
28
26
|
expect(table.data[0]).to eql([2,3,4])
|
29
27
|
end
|
30
28
|
end
|
@@ -85,4 +85,33 @@ RSpec.describe TTY::Table::Renderer::ASCII, 'padding' do
|
|
85
85
|
EOS
|
86
86
|
end
|
87
87
|
end
|
88
|
+
|
89
|
+
context "with resize option" do
|
90
|
+
it "pads fields correctly" do
|
91
|
+
table = TTY::Table.new(header: [ "Column 1", "Column 2", "Column 3"]) do |t|
|
92
|
+
t << [ "11", "12", "13" ]
|
93
|
+
t << [ "21", "22", "23" ]
|
94
|
+
t << [ "31", "32", "33" ]
|
95
|
+
end
|
96
|
+
|
97
|
+
renderer = TTY::Table::Renderer::ASCII.new(table, padding: [1,1,1,1], resize: true, width: 50)
|
98
|
+
expect(renderer.render).to eql unindent(<<-EOS)
|
99
|
+
+----------------+---------------+---------------+
|
100
|
+
| | | |
|
101
|
+
| Column 1 | Column 2 | Column 3 |
|
102
|
+
| | | |
|
103
|
+
+----------------+---------------+---------------+
|
104
|
+
| | | |
|
105
|
+
| 11 | 12 | 13 |
|
106
|
+
| | | |
|
107
|
+
| | | |
|
108
|
+
| 21 | 22 | 23 |
|
109
|
+
| | | |
|
110
|
+
| | | |
|
111
|
+
| 31 | 32 | 33 |
|
112
|
+
| | | |
|
113
|
+
+----------------+---------------+---------------+
|
114
|
+
EOS
|
115
|
+
end
|
116
|
+
end
|
88
117
|
end
|
data/tty-table.gemspec
CHANGED
@@ -22,10 +22,9 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_dependency 'equatable', '~> 0.5.0'
|
24
24
|
spec.add_dependency 'necromancer', '~> 0.4.0'
|
25
|
-
spec.add_dependency 'pastel', '~> 0.7.
|
26
|
-
spec.add_dependency 'tty-screen', '~> 0.6.
|
27
|
-
spec.add_dependency '
|
28
|
-
spec.add_dependency 'unicode-display_width','~> 1.1.0'
|
25
|
+
spec.add_dependency 'pastel', '~> 0.7.2'
|
26
|
+
spec.add_dependency 'tty-screen', '~> 0.6.4'
|
27
|
+
spec.add_dependency 'strings', '~> 0.1.0'
|
29
28
|
|
30
29
|
spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
|
31
30
|
spec.add_development_dependency 'rake'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty-table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Murach
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: equatable
|
@@ -44,56 +44,42 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.7.
|
47
|
+
version: 0.7.2
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.7.
|
54
|
+
version: 0.7.2
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: tty-screen
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.6.
|
61
|
+
version: 0.6.4
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.6.
|
68
|
+
version: 0.6.4
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: strings
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.5.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: unicode-display_width
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.1.0
|
75
|
+
version: 0.1.0
|
90
76
|
type: :runtime
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
82
|
+
version: 0.1.0
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: bundler
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -162,6 +148,9 @@ files:
|
|
162
148
|
- benchmarks/speed.rb
|
163
149
|
- examples/alignment.rb
|
164
150
|
- examples/basic.rb
|
151
|
+
- examples/orientation.rb
|
152
|
+
- examples/padding.rb
|
153
|
+
- examples/resize.rb
|
165
154
|
- lib/tty-table.rb
|
166
155
|
- lib/tty/table.rb
|
167
156
|
- lib/tty/table/alignment_set.rb
|
@@ -425,4 +414,3 @@ test_files:
|
|
425
414
|
- spec/unit/utf_spec.rb
|
426
415
|
- spec/unit/validatable/validate_options_spec.rb
|
427
416
|
- spec/unit/validatable_spec.rb
|
428
|
-
has_rdoc:
|