tty-table 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/README.md +104 -98
- data/lib/tty-table.rb +1 -1
- data/lib/tty/table.rb +70 -34
- data/lib/tty/table/alignment_set.rb +1 -3
- data/lib/tty/table/border.rb +50 -57
- data/lib/tty/table/border/ascii.rb +16 -16
- data/lib/tty/table/border/null.rb +19 -22
- data/lib/tty/table/border/row_line.rb +3 -2
- data/lib/tty/table/border/unicode.rb +16 -16
- data/lib/tty/table/border_dsl.rb +24 -22
- data/lib/tty/table/border_options.rb +32 -27
- data/lib/tty/table/column_constraint.rb +12 -9
- data/lib/tty/table/columns.rb +6 -6
- data/lib/tty/table/field.rb +46 -28
- data/lib/tty/table/header.rb +5 -5
- data/lib/tty/table/indentation.rb +7 -4
- data/lib/tty/table/operation/alignment.rb +1 -1
- data/lib/tty/table/operation/escape.rb +1 -2
- data/lib/tty/table/operation/padding.rb +1 -1
- data/lib/tty/table/operation/truncation.rb +1 -1
- data/lib/tty/table/operation/wrapped.rb +1 -1
- data/lib/tty/table/options.rb +1 -1
- data/lib/tty/table/orientation.rb +4 -4
- data/lib/tty/table/renderer.rb +8 -8
- data/lib/tty/table/renderer/ascii.rb +2 -2
- data/lib/tty/table/renderer/basic.rb +37 -40
- data/lib/tty/table/renderer/unicode.rb +1 -1
- data/lib/tty/table/row.rb +7 -7
- data/lib/tty/table/validatable.rb +23 -7
- data/lib/tty/table/version.rb +1 -1
- metadata +23 -272
- data/Rakefile +0 -10
- data/examples/alignment.rb +0 -10
- data/examples/basic.rb +0 -6
- data/examples/orientation.rb +0 -13
- data/examples/padding.rb +0 -15
- data/examples/resize.rb +0 -15
- data/spec/spec_helper.rb +0 -50
- data/spec/unit/access_spec.rb +0 -84
- data/spec/unit/add_row_spec.rb +0 -26
- data/spec/unit/alignment_set/each_spec.rb +0 -15
- data/spec/unit/alignment_set/new_spec.rb +0 -25
- data/spec/unit/alignment_set/to_ary_spec.rb +0 -12
- data/spec/unit/alignment_spec.rb +0 -69
- data/spec/unit/border/ascii/rendering_spec.rb +0 -88
- data/spec/unit/border/new_spec.rb +0 -25
- data/spec/unit/border/null/rendering_spec.rb +0 -128
- data/spec/unit/border/options/from_spec.rb +0 -36
- data/spec/unit/border/options/new_spec.rb +0 -12
- data/spec/unit/border/unicode/rendering_spec.rb +0 -61
- data/spec/unit/border_options/new_spec.rb +0 -18
- data/spec/unit/border_options/update_spec.rb +0 -16
- data/spec/unit/column_constraint/enforce_spec.rb +0 -68
- data/spec/unit/column_constraint/widths_spec.rb +0 -33
- data/spec/unit/columns/extract_widths_spec.rb +0 -41
- data/spec/unit/columns/total_width_spec.rb +0 -11
- data/spec/unit/columns/widths_from_spec.rb +0 -49
- data/spec/unit/data_spec.rb +0 -10
- data/spec/unit/each_spec.rb +0 -24
- data/spec/unit/each_with_index_spec.rb +0 -49
- data/spec/unit/empty_spec.rb +0 -21
- data/spec/unit/eql_spec.rb +0 -32
- data/spec/unit/field/equality_spec.rb +0 -49
- data/spec/unit/field/length_spec.rb +0 -33
- data/spec/unit/field/lines_spec.rb +0 -19
- data/spec/unit/field/new_spec.rb +0 -27
- data/spec/unit/field/width_spec.rb +0 -21
- data/spec/unit/filter_spec.rb +0 -20
- data/spec/unit/header/call_spec.rb +0 -28
- data/spec/unit/header/color_spec.rb +0 -17
- data/spec/unit/header/equality_spec.rb +0 -49
- data/spec/unit/header/height_spec.rb +0 -25
- data/spec/unit/header/new_spec.rb +0 -13
- data/spec/unit/header/set_spec.rb +0 -18
- data/spec/unit/header/to_ary_spec.rb +0 -12
- data/spec/unit/header_spec.rb +0 -11
- data/spec/unit/indentation/indent_spec.rb +0 -15
- data/spec/unit/new_spec.rb +0 -71
- data/spec/unit/operation/alignment/call_spec.rb +0 -37
- data/spec/unit/operation/escape/call_spec.rb +0 -13
- data/spec/unit/operation/filter/call_spec.rb +0 -14
- data/spec/unit/operation/truncation/call_spec.rb +0 -28
- data/spec/unit/operation/wrapped/call_spec.rb +0 -38
- data/spec/unit/operations/new_spec.rb +0 -28
- data/spec/unit/options/access_spec.rb +0 -12
- data/spec/unit/options_spec.rb +0 -23
- data/spec/unit/orientation_spec.rb +0 -143
- data/spec/unit/padding_spec.rb +0 -115
- data/spec/unit/properties_spec.rb +0 -23
- data/spec/unit/render_repeat_spec.rb +0 -39
- data/spec/unit/render_spec.rb +0 -61
- data/spec/unit/render_with_spec.rb +0 -104
- data/spec/unit/renderer/ascii/coloring_spec.rb +0 -83
- data/spec/unit/renderer/ascii/indentation_spec.rb +0 -39
- data/spec/unit/renderer/ascii/multiline_spec.rb +0 -99
- data/spec/unit/renderer/ascii/padding_spec.rb +0 -115
- data/spec/unit/renderer/ascii/render_spec.rb +0 -66
- data/spec/unit/renderer/ascii/resizing_spec.rb +0 -112
- data/spec/unit/renderer/ascii/separator_spec.rb +0 -38
- data/spec/unit/renderer/basic/alignment_spec.rb +0 -86
- data/spec/unit/renderer/basic/coloring_spec.rb +0 -59
- data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -26
- data/spec/unit/renderer/basic/filter_spec.rb +0 -51
- data/spec/unit/renderer/basic/indentation_spec.rb +0 -46
- data/spec/unit/renderer/basic/multiline_spec.rb +0 -72
- data/spec/unit/renderer/basic/new_spec.rb +0 -24
- data/spec/unit/renderer/basic/options_spec.rb +0 -50
- data/spec/unit/renderer/basic/padding_spec.rb +0 -74
- data/spec/unit/renderer/basic/render_spec.rb +0 -55
- data/spec/unit/renderer/basic/resizing_spec.rb +0 -94
- data/spec/unit/renderer/basic/separator_spec.rb +0 -41
- data/spec/unit/renderer/basic/single_row_separator_spec.rb +0 -80
- data/spec/unit/renderer/basic/truncation_spec.rb +0 -33
- data/spec/unit/renderer/basic/wrapping_spec.rb +0 -38
- data/spec/unit/renderer/border_spec.rb +0 -102
- data/spec/unit/renderer/render_spec.rb +0 -34
- data/spec/unit/renderer/select_spec.rb +0 -20
- data/spec/unit/renderer/unicode/coloring_spec.rb +0 -68
- data/spec/unit/renderer/unicode/indentation_spec.rb +0 -39
- data/spec/unit/renderer/unicode/padding_spec.rb +0 -59
- data/spec/unit/renderer/unicode/render_spec.rb +0 -66
- data/spec/unit/renderer/unicode/separator_spec.rb +0 -36
- data/spec/unit/renderer_spec.rb +0 -17
- data/spec/unit/rotate_spec.rb +0 -84
- data/spec/unit/row/access_spec.rb +0 -23
- data/spec/unit/row/call_spec.rb +0 -43
- data/spec/unit/row/data_spec.rb +0 -24
- data/spec/unit/row/each_spec.rb +0 -29
- data/spec/unit/row/equality_spec.rb +0 -71
- data/spec/unit/row/height_spec.rb +0 -25
- data/spec/unit/row/new_spec.rb +0 -39
- data/spec/unit/row/to_ary_spec.rb +0 -12
- data/spec/unit/to_s_spec.rb +0 -56
- data/spec/unit/transformation/extract_tuples_spec.rb +0 -33
- data/spec/unit/utf_spec.rb +0 -31
- data/spec/unit/validatable/validate_options_spec.rb +0 -31
- data/spec/unit/validatable_spec.rb +0 -30
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-table.gemspec +0 -41
data/spec/unit/padding_spec.rb
DELETED
@@ -1,115 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, 'padding' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { described_class.new(header, rows) }
|
7
|
-
|
8
|
-
it 'sets specific padding' do
|
9
|
-
expect(table.render(:ascii) { |renderer|
|
10
|
-
renderer.padding.right = 2
|
11
|
-
renderer.padding.top = 1
|
12
|
-
}).to eq unindent(<<-EOS)
|
13
|
-
+----+----+----+
|
14
|
-
| | | |
|
15
|
-
|h1 |h2 |h3 |
|
16
|
-
+----+----+----+
|
17
|
-
| | | |
|
18
|
-
|a1 |a2 |a3 |
|
19
|
-
| | | |
|
20
|
-
|b1 |b2 |b3 |
|
21
|
-
+----+----+----+
|
22
|
-
EOS
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'sets padding for all' do
|
26
|
-
expect(table.render(:ascii) { |renderer|
|
27
|
-
renderer.padding= [1,2,1,2]
|
28
|
-
}).to eq unindent(<<-EOS)
|
29
|
-
+------+------+------+
|
30
|
-
| | | |
|
31
|
-
| h1 | h2 | h3 |
|
32
|
-
| | | |
|
33
|
-
+------+------+------+
|
34
|
-
| | | |
|
35
|
-
| a1 | a2 | a3 |
|
36
|
-
| | | |
|
37
|
-
| | | |
|
38
|
-
| b1 | b2 | b3 |
|
39
|
-
| | | |
|
40
|
-
+------+------+------+
|
41
|
-
EOS
|
42
|
-
end
|
43
|
-
|
44
|
-
context 'with column width' do
|
45
|
-
let(:column_widths) { [4,4,4] }
|
46
|
-
|
47
|
-
it 'sets padding for all' do
|
48
|
-
expect(table.render(:ascii) { |renderer|
|
49
|
-
renderer.column_widths = column_widths
|
50
|
-
renderer.padding= [1,2,1,2]
|
51
|
-
}).to eq unindent(<<-EOS)
|
52
|
-
+--------+--------+--------+
|
53
|
-
| | | |
|
54
|
-
| h1 | h2 | h3 |
|
55
|
-
| | | |
|
56
|
-
+--------+--------+--------+
|
57
|
-
| | | |
|
58
|
-
| a1 | a2 | a3 |
|
59
|
-
| | | |
|
60
|
-
| | | |
|
61
|
-
| b1 | b2 | b3 |
|
62
|
-
| | | |
|
63
|
-
+--------+--------+--------+
|
64
|
-
EOS
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'with multi line text' do
|
69
|
-
let(:header) { ['h1', 'head2'] }
|
70
|
-
let(:rows) { [["Multi\nLine", "Text\nthat\nwraps"],
|
71
|
-
["Some\nother\ntext", 'Simple']] }
|
72
|
-
|
73
|
-
context 'when wrapped' do
|
74
|
-
it 'sets padding for all' do
|
75
|
-
expect(table.render(:ascii) { |renderer|
|
76
|
-
renderer.multiline = true
|
77
|
-
renderer.padding= [1,2,1,2]
|
78
|
-
}).to eq unindent(<<-EOS)
|
79
|
-
+---------+----------+
|
80
|
-
| | |
|
81
|
-
| h1 | head2 |
|
82
|
-
| | |
|
83
|
-
+---------+----------+
|
84
|
-
| | |
|
85
|
-
| Multi | Text |
|
86
|
-
| Line | that |
|
87
|
-
| | wraps |
|
88
|
-
| | |
|
89
|
-
| | |
|
90
|
-
| Some | Simple |
|
91
|
-
| other | |
|
92
|
-
| text | |
|
93
|
-
| | |
|
94
|
-
+---------+----------+
|
95
|
-
EOS
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'when escaped' do
|
100
|
-
it 'sets padding for all' do
|
101
|
-
expect(table.render(:ascii) { |renderer|
|
102
|
-
renderer.multiline = false
|
103
|
-
renderer.padding= [0,2,0,2]
|
104
|
-
}).to eq unindent(<<-EOS)
|
105
|
-
+---------------------+---------------------+
|
106
|
-
| h1 | head2 |
|
107
|
-
+---------------------+---------------------+
|
108
|
-
| Multi\\nLine | Text\\nthat\\nwraps |
|
109
|
-
| Some\\nother\\ntext | Simple |
|
110
|
-
+---------------------+---------------------+
|
111
|
-
EOS
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, 'properties' do
|
4
|
-
let(:rows) {[['a1', 'a2', 'a3'], ['b1', 'b2', 'c3']] }
|
5
|
-
|
6
|
-
subject(:table) { described_class.new rows }
|
7
|
-
|
8
|
-
it { expect(table.width).to eq(6) }
|
9
|
-
|
10
|
-
it { expect(table.rows_size).to eq(2) }
|
11
|
-
|
12
|
-
it { expect(table.columns_size).to eq(3) }
|
13
|
-
|
14
|
-
it { expect(table.size).to eq([2,3]) }
|
15
|
-
|
16
|
-
context 'no size' do
|
17
|
-
let(:rows) { [] }
|
18
|
-
|
19
|
-
it { expect(table.rows_size).to eq(0) }
|
20
|
-
|
21
|
-
it { expect(table.columns_size).to eq(0) }
|
22
|
-
end
|
23
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, 'render repeat' do
|
4
|
-
it "renders consistently" do
|
5
|
-
table = TTY::Table.new header: ['header1', 'header2']
|
6
|
-
table << ['a1', 'a2']
|
7
|
-
table << ['b1', 'b2']
|
8
|
-
options = {padding: [1,1,1,1], alignments: [:right, :center]}
|
9
|
-
expect(table.render(:ascii, options)).to eq unindent(<<-EOS)
|
10
|
-
+---------+---------+
|
11
|
-
| | |
|
12
|
-
| header1 | header2 |
|
13
|
-
| | |
|
14
|
-
+---------+---------+
|
15
|
-
| | |
|
16
|
-
| a1 | a2 |
|
17
|
-
| | |
|
18
|
-
| | |
|
19
|
-
| b1 | b2 |
|
20
|
-
| | |
|
21
|
-
+---------+---------+
|
22
|
-
EOS
|
23
|
-
|
24
|
-
expect(table.render(:ascii, options)).to eq unindent(<<-EOS)
|
25
|
-
+---------+---------+
|
26
|
-
| | |
|
27
|
-
| header1 | header2 |
|
28
|
-
| | |
|
29
|
-
+---------+---------+
|
30
|
-
| | |
|
31
|
-
| a1 | a2 |
|
32
|
-
| | |
|
33
|
-
| | |
|
34
|
-
| b1 | b2 |
|
35
|
-
| | |
|
36
|
-
+---------+---------+
|
37
|
-
EOS
|
38
|
-
end
|
39
|
-
end
|
data/spec/unit/render_spec.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, '#render' do
|
4
|
-
let(:object) { described_class }
|
5
|
-
let(:header) { ['h1', 'h2'] }
|
6
|
-
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
7
|
-
let(:color) { Pastel.new(enabled: true) }
|
8
|
-
let(:basic_renderer) { TTY::Table::Renderer::Basic }
|
9
|
-
let(:ascii_renderer) { TTY::Table::Renderer::ASCII }
|
10
|
-
|
11
|
-
subject(:table) { object.new header, rows }
|
12
|
-
|
13
|
-
before { allow(Pastel).to receive(:new).and_return(color) }
|
14
|
-
|
15
|
-
it { is_expected.to respond_to(:render) }
|
16
|
-
|
17
|
-
context 'with block' do
|
18
|
-
it 'allows to modify renderer in a block' do
|
19
|
-
expected = nil
|
20
|
-
block = lambda { |renderer| expected = renderer }
|
21
|
-
table.render(&block)
|
22
|
-
expect(expected).to be_kind_of(basic_renderer)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'sets renderer as block parameter' do
|
26
|
-
expected = nil
|
27
|
-
block = lambda { |renderer| expected = renderer }
|
28
|
-
table.render(:ascii, &block)
|
29
|
-
expect(expected).to be_kind_of(ascii_renderer)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'sets parameter on renderer' do
|
33
|
-
result = table.render :ascii do |renderer|
|
34
|
-
renderer.border.style = :red
|
35
|
-
end
|
36
|
-
expect(result).to eq unindent(<<-EOS)
|
37
|
-
\e[31m+--+--+\e[0m
|
38
|
-
\e[31m|\e[0mh1\e[31m|\e[0mh2\e[31m|\e[0m
|
39
|
-
\e[31m+--+--+\e[0m
|
40
|
-
\e[31m|\e[0ma1\e[31m|\e[0ma2\e[31m|\e[0m
|
41
|
-
\e[31m|\e[0mb1\e[31m|\e[0mb2\e[31m|\e[0m
|
42
|
-
\e[31m+--+--+\e[0m
|
43
|
-
EOS
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'with params' do
|
48
|
-
it 'sets params without renderer' do
|
49
|
-
allow(TTY::Table::Renderer).to receive(:render)
|
50
|
-
table.render(:basic)
|
51
|
-
expect(TTY::Table::Renderer).to have_received(:render).
|
52
|
-
with(table, {renderer: :basic})
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'sets params with renderer' do
|
56
|
-
allow(TTY::Table::Renderer).to receive(:render)
|
57
|
-
table.render
|
58
|
-
expect(TTY::Table::Renderer).to have_received(:render).with(table, {})
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table, '#render_with' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { described_class.new header, rows }
|
7
|
-
let(:color) { Pastel.new(enabled: true) }
|
8
|
-
|
9
|
-
before { allow(Pastel).to receive(:new).and_return(color) }
|
10
|
-
|
11
|
-
context 'with invalid border class' do
|
12
|
-
it "doesn't inherit from TTY::Table::Border" do
|
13
|
-
expect { table.render_with String }.to raise_error(TTY::Table::TypeError)
|
14
|
-
end
|
15
|
-
|
16
|
-
it "doesn't implement def_border" do
|
17
|
-
klass = Class.new(TTY::Table::Border)
|
18
|
-
expect { table.render_with klass }.
|
19
|
-
to raise_error(TTY::Table::NoImplementationError)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'with complete border' do
|
24
|
-
before {
|
25
|
-
class MyBorder < TTY::Table::Border
|
26
|
-
def_border do
|
27
|
-
top '='
|
28
|
-
top_mid '*'
|
29
|
-
top_left '*'
|
30
|
-
top_right '*'
|
31
|
-
bottom '='
|
32
|
-
bottom_mid '*'
|
33
|
-
bottom_left '*'
|
34
|
-
bottom_right '*'
|
35
|
-
mid '='
|
36
|
-
mid_mid '*'
|
37
|
-
mid_left '*'
|
38
|
-
mid_right '*'
|
39
|
-
left '$'
|
40
|
-
center '$'
|
41
|
-
right '$'
|
42
|
-
end
|
43
|
-
end
|
44
|
-
}
|
45
|
-
|
46
|
-
it 'displays custom border' do
|
47
|
-
expect(table.render_with(MyBorder)).to eq unindent(<<-EOS)
|
48
|
-
*==*==*==*
|
49
|
-
$h1$h2$h3$
|
50
|
-
*==*==*==*
|
51
|
-
$a1$a2$a3$
|
52
|
-
$b1$b2$b3$
|
53
|
-
*==*==*==*
|
54
|
-
EOS
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context 'with incomplete border' do
|
59
|
-
before {
|
60
|
-
class MyBorder < TTY::Table::Border
|
61
|
-
def_border do
|
62
|
-
bottom ' '
|
63
|
-
bottom_mid '*'
|
64
|
-
bottom_left '*'
|
65
|
-
bottom_right '*'
|
66
|
-
left '$'
|
67
|
-
center '$'
|
68
|
-
right '$'
|
69
|
-
end
|
70
|
-
end
|
71
|
-
}
|
72
|
-
|
73
|
-
it 'displays border' do
|
74
|
-
expect(table.render_with(MyBorder)).to eq unindent(<<-EOS)
|
75
|
-
$h1$h2$h3$
|
76
|
-
$a1$a2$a3$
|
77
|
-
$b1$b2$b3$
|
78
|
-
* * * *
|
79
|
-
EOS
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context 'with renderer' do
|
84
|
-
before {
|
85
|
-
class MyBorder < TTY::Table::Border
|
86
|
-
def_border do
|
87
|
-
left '|'
|
88
|
-
right '|'
|
89
|
-
end
|
90
|
-
end
|
91
|
-
}
|
92
|
-
|
93
|
-
it 'displays border' do
|
94
|
-
result = table.render_with MyBorder do |renderer|
|
95
|
-
renderer.border.style = :red
|
96
|
-
end
|
97
|
-
expect(result).to eq unindent(<<-EOS)
|
98
|
-
\e[31m|\e[0mh1h2h3\e[31m|\e[0m
|
99
|
-
\e[31m|\e[0ma1a2a3\e[31m|\e[0m
|
100
|
-
\e[31m|\e[0mb1b2b3\e[31m|\e[0m
|
101
|
-
EOS
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end # render_with
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::ASCII, 'coloring' do
|
4
|
-
|
5
|
-
let(:color) { Pastel.new(enabled: true) }
|
6
|
-
|
7
|
-
before { allow(Pastel).to receive(:new).and_return(color) }
|
8
|
-
|
9
|
-
context 'when border' do
|
10
|
-
it "colors border" do
|
11
|
-
table = TTY::Table.new header: ['header1', 'header2']
|
12
|
-
table << ['a1', 'a2']
|
13
|
-
table << ['b1', 'b2']
|
14
|
-
renderer = described_class.new(table)
|
15
|
-
renderer.border.style = :green
|
16
|
-
|
17
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
18
|
-
#{color.green('+-------+-------+')}
|
19
|
-
#{color.green('|')}header1#{color.green('|')}header2#{color.green('|')}
|
20
|
-
#{color.green('+-------+-------+')}
|
21
|
-
#{color.green('|')}a1 #{color.green('|')}a2 #{color.green('|')}
|
22
|
-
#{color.green('|')}b1 #{color.green('|')}b2 #{color.green('|')}
|
23
|
-
#{color.green('+-------+-------+')}
|
24
|
-
EOS
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when content' do
|
29
|
-
it "colors individual field" do
|
30
|
-
header = [color.yellow('header1'), 'header2']
|
31
|
-
table = TTY::Table.new header: header
|
32
|
-
table << [color.green.on_blue('a1'), 'a2']
|
33
|
-
table << ['b1', color.red.on_yellow('b2')]
|
34
|
-
renderer = described_class.new(table)
|
35
|
-
|
36
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
37
|
-
+-------+-------+
|
38
|
-
|#{color.yellow('header1')}|header2|
|
39
|
-
+-------+-------+
|
40
|
-
|#{color.green.on_blue('a1')} |a2 |
|
41
|
-
|b1 |#{color.red.on_yellow('b2')} |
|
42
|
-
+-------+-------+
|
43
|
-
EOS
|
44
|
-
end
|
45
|
-
|
46
|
-
it "colors multiline content" do
|
47
|
-
header = [color.yellow("Multi\nHeader"), 'header2']
|
48
|
-
table = TTY::Table.new header: header
|
49
|
-
table << [color.green.on_blue("Multi\nLine\nContent"), 'a2']
|
50
|
-
table << ['b1', color.red.on_yellow("Multi\nLine\nContent")]
|
51
|
-
renderer = described_class.new(table, multiline: true)
|
52
|
-
|
53
|
-
expect(renderer.render).to eq unindent(<<-EOS)
|
54
|
-
+-------+-------+
|
55
|
-
|#{color.yellow('Multi ')}|header2|
|
56
|
-
|#{color.yellow('Header')} | |
|
57
|
-
+-------+-------+
|
58
|
-
|#{color.green.on_blue('Multi ')}|a2 |
|
59
|
-
|#{color.green.on_blue('Line ')}| |
|
60
|
-
|#{color.green.on_blue('Content')}| |
|
61
|
-
|b1 |#{color.red.on_yellow("Multi ")}|
|
62
|
-
| |#{color.red.on_yellow("Line ")}|
|
63
|
-
| |#{color.red.on_yellow("Content")}|
|
64
|
-
+-------+-------+
|
65
|
-
EOS
|
66
|
-
end
|
67
|
-
|
68
|
-
xit "colors adjecent content" do
|
69
|
-
hello = color.decorate("hello", :black, :on_green)
|
70
|
-
world = color.decorate("world", :black, :on_red)
|
71
|
-
|
72
|
-
table = TTY::Table.new [:header], [
|
73
|
-
[hello],
|
74
|
-
[world],
|
75
|
-
[hello + world],
|
76
|
-
[hello + ' ' + world],
|
77
|
-
]
|
78
|
-
renderer = described_class.new(table, column_widths: 6, multiline: true)
|
79
|
-
|
80
|
-
rendered = renderer.render
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::Table::Renderer::ASCII, 'indentation' do
|
4
|
-
let(:header) { ['h1', 'h2', 'h3'] }
|
5
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
6
|
-
let(:table) { TTY::Table.new(header, rows) }
|
7
|
-
let(:indent) { 2 }
|
8
|
-
let(:options) { {indent: indent } }
|
9
|
-
|
10
|
-
subject(:renderer) { described_class.new(table, options)}
|
11
|
-
|
12
|
-
context 'when default' do
|
13
|
-
it 'indents by value' do
|
14
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
15
|
-
+--+--+--+
|
16
|
-
|h1|h2|h3|
|
17
|
-
+--+--+--+
|
18
|
-
|a1|a2|a3|
|
19
|
-
|b1|b2|b3|
|
20
|
-
+--+--+--+
|
21
|
-
EOS
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when each row' do
|
26
|
-
it 'indents by value' do
|
27
|
-
renderer.border.separator = :each_row
|
28
|
-
expect(renderer.render).to eql <<-EOS.chomp
|
29
|
-
+--+--+--+
|
30
|
-
|h1|h2|h3|
|
31
|
-
+--+--+--+
|
32
|
-
|a1|a2|a3|
|
33
|
-
+--+--+--+
|
34
|
-
|b1|b2|b3|
|
35
|
-
+--+--+--+
|
36
|
-
EOS
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|