tty 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -1
- data/.travis.yml +3 -6
- data/README.md +232 -134
- data/lib/tty/plugins/plugin.rb +56 -0
- data/lib/tty/plugins.rb +75 -0
- data/lib/tty/shell/suggestion.rb +102 -0
- data/lib/tty/shell.rb +41 -14
- data/lib/tty/system/editor.rb +111 -0
- data/lib/tty/system/which.rb +13 -1
- data/lib/tty/system.rb +44 -28
- data/lib/tty/table/border/null.rb +0 -9
- data/lib/tty/table/border/row_line.rb +21 -0
- data/lib/tty/table/border.rb +63 -32
- data/lib/tty/table/border_dsl.rb +1 -1
- data/lib/tty/table/column_set.rb +16 -17
- data/lib/tty/table/field.rb +27 -7
- data/lib/tty/table/header.rb +18 -9
- data/lib/tty/table/operation/alignment_set.rb +20 -25
- data/lib/tty/table/operation/escape.rb +30 -0
- data/lib/tty/table/operation/filter.rb +36 -0
- data/lib/tty/table/operation/truncation.rb +22 -11
- data/lib/tty/table/operation/wrapped.rb +21 -10
- data/lib/tty/table/operations.rb +10 -8
- data/lib/tty/table/orientation/horizontal.rb +1 -1
- data/lib/tty/table/renderer/ascii.rb +3 -3
- data/lib/tty/table/renderer/basic.rb +135 -65
- data/lib/tty/table/renderer/color.rb +1 -4
- data/lib/tty/table/renderer/unicode.rb +3 -3
- data/lib/tty/table/renderer.rb +48 -61
- data/lib/tty/table/row.rb +30 -3
- data/lib/tty/table/transformation.rb +38 -0
- data/lib/tty/table/validatable.rb +7 -5
- data/lib/tty/table.rb +78 -99
- data/lib/tty/terminal/color.rb +2 -2
- data/lib/tty/terminal/echo.rb +1 -1
- data/lib/tty/terminal/pager/basic.rb +52 -0
- data/lib/tty/terminal/pager/system.rb +39 -0
- data/lib/tty/terminal/pager.rb +95 -0
- data/lib/tty/terminal.rb +30 -1
- data/lib/tty/version.rb +1 -1
- data/lib/tty.rb +41 -1
- data/spec/spec_helper.rb +20 -0
- data/spec/tty/plugins/find_spec.rb +28 -0
- data/spec/tty/plugins/load_spec.rb +20 -0
- data/spec/tty/plugins/plugin/load_spec.rb +30 -0
- data/spec/tty/plugins/plugin/new_spec.rb +18 -0
- data/spec/tty/shell/suggest_spec.rb +50 -0
- data/spec/tty/support/conversion_spec.rb +3 -3
- data/spec/tty/support/delegatable_spec.rb +1 -1
- data/spec/tty/support/equatable_spec.rb +6 -9
- data/spec/tty/system/editor/available_spec.rb +40 -0
- data/spec/tty/system/editor/build_spec.rb +40 -0
- data/spec/tty/system/editor/command_spec.rb +16 -0
- data/spec/tty/system/editor/executables_spec.rb +13 -0
- data/spec/tty/system/editor/invoke_spec.rb +38 -0
- data/spec/tty/system/editor/open_spec.rb +27 -0
- data/spec/tty/system/platform_spec.rb +4 -6
- data/spec/tty/system/which/which_spec.rb +48 -0
- data/spec/tty/system/which_spec.rb +8 -34
- data/spec/tty/table/border/ascii/rendering_spec.rb +19 -5
- data/spec/tty/table/border/new_spec.rb +1 -1
- data/spec/tty/table/border/null/rendering_spec.rb +24 -8
- data/spec/tty/table/border/unicode/rendering_spec.rb +19 -5
- data/spec/tty/table/column_set/extract_widths_spec.rb +4 -15
- data/spec/tty/table/column_set/total_width_spec.rb +15 -0
- data/spec/tty/table/data_spec.rb +14 -0
- data/spec/tty/table/each_spec.rb +17 -4
- data/spec/tty/table/each_with_index_spec.rb +34 -6
- data/spec/tty/table/field/length_spec.rb +21 -0
- data/spec/tty/table/field/lines_spec.rb +21 -0
- data/spec/tty/table/filter_spec.rb +23 -0
- data/spec/tty/table/header/call_spec.rb +1 -1
- data/spec/tty/table/header/height_spec.rb +27 -0
- data/spec/tty/table/initialize_spec.rb +6 -6
- data/spec/tty/table/operation/alignment_set/call_spec.rb +39 -0
- data/spec/tty/table/operation/escape/call_spec.rb +16 -0
- data/spec/tty/table/operation/filter/call_spec.rb +17 -0
- data/spec/tty/table/operation/truncation/call_spec.rb +15 -10
- data/spec/tty/table/operation/truncation/truncate_spec.rb +1 -1
- data/spec/tty/table/operation/wrapped/call_spec.rb +15 -10
- data/spec/tty/table/operation/wrapped/wrap_spec.rb +1 -1
- data/spec/tty/table/operations/new_spec.rb +4 -4
- data/spec/tty/table/options_spec.rb +0 -28
- data/spec/tty/table/orientation_spec.rb +5 -6
- data/spec/tty/table/properties_spec.rb +1 -4
- data/spec/tty/table/render_spec.rb +57 -0
- data/spec/tty/table/{renders_with_spec.rb → render_with_spec.rb} +29 -10
- data/spec/tty/table/renderer/ascii/render_spec.rb +68 -0
- data/spec/tty/table/renderer/ascii/separator_spec.rb +28 -0
- data/spec/tty/table/renderer/basic/alignment_spec.rb +18 -16
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +17 -12
- data/spec/tty/table/renderer/basic/filter_spec.rb +53 -0
- data/spec/tty/table/renderer/basic/multiline_content_spec.rb +135 -0
- data/spec/tty/table/renderer/basic/new_spec.rb +13 -2
- data/spec/tty/table/renderer/basic/options_spec.rb +48 -0
- data/spec/tty/table/renderer/basic/render_spec.rb +19 -121
- data/spec/tty/table/renderer/basic/separator_spec.rb +14 -48
- data/spec/tty/table/renderer/basic/truncation_spec.rb +35 -0
- data/spec/tty/table/renderer/basic/wrapping_spec.rb +40 -0
- data/spec/tty/table/{border_spec.rb → renderer/border_spec.rb} +17 -20
- data/spec/tty/table/renderer/select_spec.rb +22 -0
- data/spec/tty/table/{border → renderer}/style_spec.rb +13 -14
- data/spec/tty/table/renderer/unicode/render_spec.rb +68 -0
- data/spec/tty/table/renderer/unicode/separator_spec.rb +26 -0
- data/spec/tty/table/rotate_spec.rb +2 -3
- data/spec/tty/table/row/call_spec.rb +1 -1
- data/spec/tty/table/row/each_spec.rb +31 -0
- data/spec/tty/table/row/height_spec.rb +27 -0
- data/spec/tty/table/to_s_spec.rb +3 -3
- data/spec/tty/table/transformation/extract_tuples_spec.rb +35 -0
- data/spec/tty/table/validatable/validate_options_spec.rb +1 -2
- data/spec/tty/terminal/home_spec.rb +3 -3
- data/spec/tty/terminal/page_spec.rb +13 -0
- data/spec/tty/terminal/pager/available_spec.rb +40 -0
- data/spec/tty/terminal/pager/basic/page_spec.rb +54 -0
- data/spec/tty/terminal/pager/command_spec.rb +16 -0
- data/spec/tty/terminal/pager/executables_spec.rb +13 -0
- data/spec/tty/terminal/pager/page_spec.rb +47 -0
- data/spec/tty/terminal/pager/system/page_spec.rb +29 -0
- data/spec/tty/text/distance/distance_spec.rb +12 -0
- data/tty.gemspec +7 -3
- metadata +160 -27
- data/spec/tty/table/operation/alignment_set/align_rows_spec.rb +0 -53
- data/spec/tty/table/renderer/pick_renderer_spec.rb +0 -25
- data/spec/tty/table/renderer_spec.rb +0 -49
@@ -5,10 +5,9 @@ require 'spec_helper'
|
|
5
5
|
describe TTY::Table, 'orientation' do
|
6
6
|
let(:header) { ['h1', 'h2', 'h3'] }
|
7
7
|
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
-
let(:
|
9
|
-
let(:options) { { :orientation => orientation, :renderer => renderer } }
|
8
|
+
let(:options) { { :orientation => orientation } }
|
10
9
|
|
11
|
-
subject { described_class.new
|
10
|
+
subject { described_class.new(header, rows, options) }
|
12
11
|
|
13
12
|
context 'when illegal option' do
|
14
13
|
let(:orientation) { :accross }
|
@@ -26,7 +25,7 @@ describe TTY::Table, 'orientation' do
|
|
26
25
|
it { expect(subject.header).to eql header }
|
27
26
|
|
28
27
|
it 'preserves original rows' do
|
29
|
-
expect(subject.to_a).to eql
|
28
|
+
expect(subject.to_a).to eql(subject.data)
|
30
29
|
end
|
31
30
|
|
32
31
|
context 'without border' do
|
@@ -43,7 +42,7 @@ describe TTY::Table, 'orientation' do
|
|
43
42
|
let(:renderer) { :ascii }
|
44
43
|
|
45
44
|
it 'diplays table' do
|
46
|
-
subject.
|
45
|
+
subject.render(renderer).should == <<-EOS.normalize
|
47
46
|
+--+--+--+
|
48
47
|
|h1|h2|h3|
|
49
48
|
+--+--+--+
|
@@ -84,7 +83,7 @@ describe TTY::Table, 'orientation' do
|
|
84
83
|
let(:renderer) { :ascii }
|
85
84
|
|
86
85
|
it 'diplays table' do
|
87
|
-
subject.
|
86
|
+
subject.render(renderer).should == <<-EOS.normalize
|
88
87
|
+--+--+--+
|
89
88
|
|h1|a1|b1|
|
90
89
|
|h2|a2|b2|
|
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe TTY::Table, 'properties' do
|
6
6
|
let(:rows) {[['a1', 'a2', 'a3'], ['b1', 'b2', 'c3']] }
|
7
|
-
subject { described_class.new
|
7
|
+
subject { described_class.new rows }
|
8
8
|
|
9
9
|
its(:width) { should == 6 }
|
10
10
|
|
@@ -14,8 +14,6 @@ describe TTY::Table, 'properties' do
|
|
14
14
|
|
15
15
|
its(:size) { should == [2,3] }
|
16
16
|
|
17
|
-
its(:width) { should == 6 }
|
18
|
-
|
19
17
|
context 'no size' do
|
20
18
|
let(:rows) { [] }
|
21
19
|
|
@@ -23,5 +21,4 @@ describe TTY::Table, 'properties' do
|
|
23
21
|
|
24
22
|
its(:column_size) { should == 0 }
|
25
23
|
end
|
26
|
-
|
27
24
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Table, '#render' do
|
6
|
+
let(:object) { described_class }
|
7
|
+
let(:header) { ['h1', 'h2'] }
|
8
|
+
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
9
|
+
let(:basic_renderer) { TTY::Table::Renderer::Basic }
|
10
|
+
let(:ascii_renderer) { TTY::Table::Renderer::ASCII }
|
11
|
+
|
12
|
+
subject(:table) { object.new header, rows }
|
13
|
+
|
14
|
+
it { should respond_to(:render) }
|
15
|
+
|
16
|
+
context 'with block' do
|
17
|
+
it 'allows to modify renderer in a block' do
|
18
|
+
expected = nil
|
19
|
+
block = lambda { |renderer| expected = renderer }
|
20
|
+
table.render(&block)
|
21
|
+
expect(expected).to be_kind_of(basic_renderer)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'sets renderer as block parameter' do
|
25
|
+
expected = nil
|
26
|
+
block = lambda { |renderer| expected = renderer }
|
27
|
+
table.render(:ascii, &block)
|
28
|
+
expect(expected).to be_kind_of(ascii_renderer)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'sets parameter on renderer' do
|
32
|
+
result = table.render :ascii do |renderer|
|
33
|
+
renderer.border.style = :red
|
34
|
+
end
|
35
|
+
result.should == <<-EOS.normalize
|
36
|
+
\e[31m+--+--+\e[0m
|
37
|
+
\e[31m|\e[0mh1\e[31m|\e[0mh2\e[31m|\e[0m
|
38
|
+
\e[31m+--+--+\e[0m
|
39
|
+
\e[31m|\e[0ma1\e[31m|\e[0ma2\e[31m|\e[0m
|
40
|
+
\e[31m|\e[0mb1\e[31m|\e[0mb2\e[31m|\e[0m
|
41
|
+
\e[31m+--+--+\e[0m
|
42
|
+
EOS
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with params' do
|
47
|
+
it 'sets params without renderer' do
|
48
|
+
TTY::Table::Renderer.should_receive(:render).with(table, {renderer: :basic})
|
49
|
+
table.render(:basic)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'sets params with renderer' do
|
53
|
+
TTY::Table::Renderer.should_receive(:render).with(table, {})
|
54
|
+
table.render
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe TTY::Table, '#
|
5
|
+
describe TTY::Table, '#render_with' do
|
6
6
|
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
-
let(:rows)
|
8
|
-
let(:table)
|
7
|
+
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
+
let(:table) { described_class.new header, rows }
|
9
9
|
|
10
10
|
context 'with invalid border class' do
|
11
11
|
it "doesn't inherit from TTY::Table::Border" do
|
12
|
-
expect { table.
|
12
|
+
expect { table.render_with String }.to raise_error(TTY::TypeError)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "doesn't implement def_border" do
|
16
16
|
klass = Class.new(TTY::Table::Border)
|
17
|
-
expect { table.
|
17
|
+
expect { table.render_with klass }.to raise_error(TTY::NoImplementationError)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -42,8 +42,7 @@ describe TTY::Table, '#renders_with' do
|
|
42
42
|
}
|
43
43
|
|
44
44
|
it 'displays custom border' do
|
45
|
-
table.
|
46
|
-
table.to_s.should == <<-EOS.normalize
|
45
|
+
table.render_with(MyBorder).should == <<-EOS.normalize
|
47
46
|
*==*==*==*
|
48
47
|
$h1$h2$h3$
|
49
48
|
*==*==*==*
|
@@ -70,8 +69,7 @@ describe TTY::Table, '#renders_with' do
|
|
70
69
|
}
|
71
70
|
|
72
71
|
it 'displays border' do
|
73
|
-
table.
|
74
|
-
table.to_s.should == <<-EOS.normalize
|
72
|
+
table.render_with(MyBorder).should == <<-EOS.normalize
|
75
73
|
$h1$h2$h3$
|
76
74
|
$a1$a2$a3$
|
77
75
|
$b1$b2$b3$
|
@@ -80,4 +78,25 @@ describe TTY::Table, '#renders_with' do
|
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
83
|
-
|
81
|
+
context 'with renderer' do
|
82
|
+
before {
|
83
|
+
class MyBorder < TTY::Table::Border
|
84
|
+
def_border do
|
85
|
+
left '|'
|
86
|
+
right '|'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
}
|
90
|
+
|
91
|
+
it 'displays border' do
|
92
|
+
result = table.render_with MyBorder do |renderer|
|
93
|
+
renderer.border.style = :red
|
94
|
+
end
|
95
|
+
result.should == <<-EOS.normalize
|
96
|
+
\e[31m|\e[0mh1\e[31m\e[0mh2\e[31m\e[0mh3\e[31m|\e[0m
|
97
|
+
\e[31m|\e[0ma1\e[31m\e[0ma2\e[31m\e[0ma3\e[31m|\e[0m
|
98
|
+
\e[31m|\e[0mb1\e[31m\e[0mb2\e[31m\e[0mb3\e[31m|\e[0m
|
99
|
+
EOS
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end # render_with
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Table::Renderer::ASCII, '#render' do
|
6
|
+
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
+
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
+
let(:table) { TTY::Table.new header, rows }
|
9
|
+
|
10
|
+
subject { described_class.new(table) }
|
11
|
+
|
12
|
+
context 'only rows' do
|
13
|
+
let(:table) { TTY::Table.new rows }
|
14
|
+
|
15
|
+
it 'display table rows' do
|
16
|
+
subject.render.should == <<-EOS.normalize
|
17
|
+
+--+--+--+
|
18
|
+
|a1|a2|a3|
|
19
|
+
|b1|b2|b3|
|
20
|
+
+--+--+--+
|
21
|
+
EOS
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with header' do
|
26
|
+
it 'displays table with header' do
|
27
|
+
subject.render.should == <<-EOS.normalize
|
28
|
+
+--+--+--+
|
29
|
+
|h1|h2|h3|
|
30
|
+
+--+--+--+
|
31
|
+
|a1|a2|a3|
|
32
|
+
|b1|b2|b3|
|
33
|
+
+--+--+--+
|
34
|
+
EOS
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with short header' do
|
39
|
+
let(:header) { ['h1', 'h2'] }
|
40
|
+
let(:rows) { [['aaa1', 'a2'], ['b1', 'bb1']] }
|
41
|
+
|
42
|
+
it 'displays table according to widths' do
|
43
|
+
subject.render.should == <<-EOS.normalize
|
44
|
+
+----+---+
|
45
|
+
|h1 |h2 |
|
46
|
+
+----+---+
|
47
|
+
|aaa1|a2 |
|
48
|
+
|b1 |bb1|
|
49
|
+
+----+---+
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'with long header' do
|
55
|
+
let(:header) { ['header1', 'header2', 'header3'] }
|
56
|
+
|
57
|
+
it 'header greater than row sizes' do
|
58
|
+
subject.render.should == <<-EOS.normalize
|
59
|
+
+-------+-------+-------+
|
60
|
+
|header1|header2|header3|
|
61
|
+
+-------+-------+-------+
|
62
|
+
|a1 |a2 |a3 |
|
63
|
+
|b1 |b2 |b3 |
|
64
|
+
+-------+-------+-------+
|
65
|
+
EOS
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Table::Renderer::ASCII, 'with separator' do
|
6
|
+
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
+
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
+
let(:table) { TTY::Table.new(header, rows) }
|
9
|
+
|
10
|
+
let(:object) { described_class.new table }
|
11
|
+
|
12
|
+
subject(:renderer) { object }
|
13
|
+
|
14
|
+
context 'when ascii' do
|
15
|
+
it "renders each row" do
|
16
|
+
renderer.border.separator= :each_row
|
17
|
+
renderer.render.should == <<-EOS.normalize
|
18
|
+
+--+--+--+
|
19
|
+
|h1|h2|h3|
|
20
|
+
+--+--+--+
|
21
|
+
|a1|a2|a3|
|
22
|
+
+--+--+--+
|
23
|
+
|b1|b2|b3|
|
24
|
+
+--+--+--+
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -2,20 +2,22 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe TTY::Table, 'alignment' do
|
5
|
+
describe TTY::Table::Renderer::Basic, 'alignment' do
|
6
6
|
let(:header) { ['h1', 'h2', 'h3'] }
|
7
7
|
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
8
|
let(:options) { { :renderer => :basic, :column_aligns => column_aligns }}
|
9
9
|
|
10
|
-
|
10
|
+
let(:table) { TTY::Table.new(header, rows) }
|
11
|
+
|
12
|
+
subject(:renderer) { described_class.new table, options }
|
11
13
|
|
12
14
|
context 'with default' do
|
13
15
|
let(:header) { ['h1', 'h2'] }
|
14
|
-
let(:rows)
|
16
|
+
let(:rows) { [['aaaaa', 'a'], ['b', 'bbbbb']] }
|
15
17
|
let(:column_aligns) { nil }
|
16
18
|
|
17
19
|
it 'aligns left by default' do
|
18
|
-
|
20
|
+
renderer.render.should == <<-EOS.normalize
|
19
21
|
h1 h2
|
20
22
|
aaaaa a
|
21
23
|
b bbbbb
|
@@ -28,7 +30,7 @@ describe TTY::Table, 'alignment' do
|
|
28
30
|
let(:column_aligns) { [:left, :center, :right] }
|
29
31
|
|
30
32
|
it 'aligns headers' do
|
31
|
-
|
33
|
+
renderer.render.should == <<-EOS.normalize
|
32
34
|
header1 head2 h3
|
33
35
|
a1 a2 a3
|
34
36
|
b1 b2 b3
|
@@ -42,7 +44,7 @@ describe TTY::Table, 'alignment' do
|
|
42
44
|
let(:column_aligns) { [:left, :right] }
|
43
45
|
|
44
46
|
it 'aligns table rows' do
|
45
|
-
|
47
|
+
renderer.render.to_s.should == <<-EOS.normalize
|
46
48
|
aaaaa a
|
47
49
|
b bbbbb
|
48
50
|
EOS
|
@@ -52,15 +54,17 @@ describe TTY::Table, 'alignment' do
|
|
52
54
|
context 'with individual field aligns' do
|
53
55
|
let(:header) { ['header1', 'header2', 'header3'] }
|
54
56
|
let(:column_aligns) { [:left, :center, :right] }
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
table = described_class.new options do |t|
|
57
|
+
let(:options) { { :column_aligns => column_aligns, :renderer => :basic } }
|
58
|
+
let(:table) {
|
59
|
+
TTY::Table.new :header => header do |t|
|
59
60
|
t << ['a1', 'a2', 'a3']
|
60
61
|
t << ['b1', {:value => 'b2', :align => :right}, 'b3']
|
61
62
|
t << ['c1', 'c2', {:value => 'c3', :align => :center}]
|
62
63
|
end
|
63
|
-
|
64
|
+
}
|
65
|
+
|
66
|
+
it "takes individual fields over global aligns" do
|
67
|
+
renderer.render.should == <<-EOS.normalize
|
64
68
|
header1 header2 header3
|
65
69
|
a1 a2 a3
|
66
70
|
b1 b2 b3
|
@@ -71,17 +75,15 @@ describe TTY::Table, 'alignment' do
|
|
71
75
|
|
72
76
|
context 'with aligned header' do
|
73
77
|
let(:rows) { [['aaaaa1', 'a2', 'aaa3'], ['b1', 'bbbb2', 'bb3']] }
|
78
|
+
let(:header) {['h1', {:value => 'h2', :align => :right}, {:value => 'h3', :align => :center}] }
|
79
|
+
let(:options) { { :renderer => :basic } }
|
74
80
|
|
75
81
|
it "aligns headres" do
|
76
|
-
|
77
|
-
options = {:header => header, :renderer => :basic, :rows => rows }
|
78
|
-
table = described_class.new options
|
79
|
-
table.to_s.should == <<-EOS.normalize
|
82
|
+
renderer.render.should == <<-EOS.normalize
|
80
83
|
h1 h2 h3
|
81
84
|
aaaaa1 a2 aaa3
|
82
85
|
b1 bbbb2 bb3
|
83
86
|
EOS
|
84
87
|
end
|
85
|
-
|
86
88
|
end
|
87
89
|
end
|
@@ -3,21 +3,26 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Table::Renderer::Basic, '#extract_column_widths' do
|
6
|
-
let(:rows)
|
6
|
+
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
7
|
+
let(:object) { described_class.new(table) }
|
7
8
|
|
8
|
-
subject {
|
9
|
+
subject { object.render }
|
9
10
|
|
10
|
-
|
11
|
-
rows
|
12
|
-
table
|
13
|
-
|
14
|
-
|
11
|
+
context 'with rows only' do
|
12
|
+
let(:rows) { [['a1a', 'a2a2a2'], ['b1b1b', 'b2b2']] }
|
13
|
+
let(:table) { TTY::Table.new rows }
|
14
|
+
|
15
|
+
it 'calculates column widths' do
|
16
|
+
object.column_widths.should == [5,6]
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
|
-
|
18
|
-
header
|
19
|
-
table
|
20
|
-
|
21
|
-
|
20
|
+
context 'with header' do
|
21
|
+
let(:header) { ['header1', 'head2', 'h3'] }
|
22
|
+
let(:table) { TTY::Table.new header, rows }
|
23
|
+
|
24
|
+
it 'calcualtes column widths with header' do
|
25
|
+
object.column_widths.should == [7,5,2]
|
26
|
+
end
|
22
27
|
end
|
23
28
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Table::Renderer::Basic, 'filter' do
|
6
|
+
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
+
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
+
let(:table) { TTY::Table.new(header, rows) }
|
9
|
+
|
10
|
+
subject(:renderer) { described_class.new(table, {filter: filter}) }
|
11
|
+
|
12
|
+
context 'with header' do
|
13
|
+
context 'filtering only rows' do
|
14
|
+
let(:filter) { Proc.new { |val, row, col|
|
15
|
+
(col == 1 and row > 0) ? val.capitalize : val
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
it 'filters only rows' do
|
20
|
+
subject.render.should == <<-EOS.normalize
|
21
|
+
h1 h2 h3
|
22
|
+
a1 A2 a3
|
23
|
+
b1 B2 b3
|
24
|
+
EOS
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'filtering header and rows' do
|
29
|
+
let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val }}
|
30
|
+
|
31
|
+
it 'filters only rows' do
|
32
|
+
subject.render.should == <<-EOS.normalize
|
33
|
+
h1 H2 h3
|
34
|
+
a1 A2 a3
|
35
|
+
b1 B2 b3
|
36
|
+
EOS
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'without header' do
|
42
|
+
let(:header) { nil }
|
43
|
+
|
44
|
+
let(:filter) { Proc.new { |val, row, col| col == 1 ? val.capitalize : val } }
|
45
|
+
|
46
|
+
it 'filters only rows' do
|
47
|
+
subject.render.should == <<-EOS.normalize
|
48
|
+
a1 A2 a3
|
49
|
+
b1 B2 b3
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Table::Renderer::Basic, 'with multiline content' do
|
6
|
+
let(:header) { nil }
|
7
|
+
let(:object) { described_class }
|
8
|
+
let(:table) { TTY::Table.new header, rows }
|
9
|
+
|
10
|
+
subject(:renderer) { object.new table }
|
11
|
+
|
12
|
+
context 'with escaping' do
|
13
|
+
let(:rows) { [ ["First", '1'], ["Multiline\nContent", '2'], ["Third", '3']] }
|
14
|
+
|
15
|
+
context 'without border' do
|
16
|
+
it "renders single line" do
|
17
|
+
table.render(multiline: false).should == <<-EOS.normalize
|
18
|
+
First 1
|
19
|
+
Multiline\\nContent 2
|
20
|
+
Third 3
|
21
|
+
EOS
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with column widths' do
|
26
|
+
it "renders single line" do
|
27
|
+
table.render(multiline: false, column_widths: [8,1]).should == <<-EOS.normalize
|
28
|
+
First 1
|
29
|
+
Multili… 2
|
30
|
+
Third 3
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'with border' do
|
36
|
+
it "renders single line" do
|
37
|
+
table.render(:ascii, multiline: false).should == <<-EOS.normalize
|
38
|
+
+------------------+-+
|
39
|
+
|First |1|
|
40
|
+
|Multiline\\nContent|2|
|
41
|
+
|Third |3|
|
42
|
+
+------------------+-+
|
43
|
+
EOS
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with header' do
|
48
|
+
let(:header) { ["Multi\nHeader", "header2"] }
|
49
|
+
|
50
|
+
it "renders header" do
|
51
|
+
table.render(:ascii, multiline: false).should == <<-EOS.normalize
|
52
|
+
+------------------+-------+
|
53
|
+
|Multi\\nHeader |header2|
|
54
|
+
+------------------+-------+
|
55
|
+
|First |1 |
|
56
|
+
|Multiline\\nContent|2 |
|
57
|
+
|Third |3 |
|
58
|
+
+------------------+-------+
|
59
|
+
EOS
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'without escaping' do
|
65
|
+
let(:rows) { [ ["First", '1'], ["Multi\nLine\nContent", '2'], ["Third", '3']] }
|
66
|
+
|
67
|
+
context 'without border' do
|
68
|
+
it "renders every line" do
|
69
|
+
table.render(multiline: true).should == <<-EOS.normalize
|
70
|
+
First 1
|
71
|
+
Multi 2
|
72
|
+
Line
|
73
|
+
Content
|
74
|
+
Third 3
|
75
|
+
EOS
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'with column widths' do
|
80
|
+
it "renders multiline" do
|
81
|
+
table.render(multiline: true, column_widths: [8,1]).should == <<-EOS.normalize
|
82
|
+
First 1
|
83
|
+
Multi 2
|
84
|
+
Line
|
85
|
+
Content
|
86
|
+
Third 3
|
87
|
+
EOS
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'wraps multi line' do
|
91
|
+
table.render(multiline: true, column_widths: [5,1]).should == <<-EOS.normalize
|
92
|
+
First 1
|
93
|
+
Multi 2
|
94
|
+
Line
|
95
|
+
Conte
|
96
|
+
nt
|
97
|
+
Third 3
|
98
|
+
EOS
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'with border' do
|
103
|
+
it "renders every line" do
|
104
|
+
table.render(:ascii, multiline: true).should == <<-EOS.normalize
|
105
|
+
+-------+-+
|
106
|
+
|First |1|
|
107
|
+
|Multi |2|
|
108
|
+
|Line | |
|
109
|
+
|Content| |
|
110
|
+
|Third |3|
|
111
|
+
+-------+-+
|
112
|
+
EOS
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'with header' do
|
117
|
+
let(:header) { ["Multi\nHeader", "header2"] }
|
118
|
+
|
119
|
+
it "renders header" do
|
120
|
+
table.render(:ascii, multiline: true).should == <<-EOS.normalize
|
121
|
+
+-------+-------+
|
122
|
+
|Multi |header2|
|
123
|
+
|Header | |
|
124
|
+
+-------+-------+
|
125
|
+
|First |1 |
|
126
|
+
|Multi |2 |
|
127
|
+
|Line | |
|
128
|
+
|Content| |
|
129
|
+
|Third |3 |
|
130
|
+
+-------+-------+
|
131
|
+
EOS
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -3,9 +3,20 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe TTY::Table::Renderer::Basic do
|
6
|
+
let(:header) { ['h1'] }
|
7
|
+
let(:rows) { [['a1']] }
|
6
8
|
|
7
|
-
subject { described_class
|
9
|
+
subject(:renderer) { described_class }
|
8
10
|
|
9
|
-
|
11
|
+
context 'without table' do
|
12
|
+
let(:table) { nil }
|
10
13
|
|
14
|
+
it { expect { renderer.new(table) }.to raise_error(TTY::ArgumentRequired) }
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with table' do
|
18
|
+
let(:table) { TTY::Table.new(header, rows) }
|
19
|
+
|
20
|
+
it { expect { renderer.new(table) }.not_to raise_error }
|
21
|
+
end
|
11
22
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Table::Renderer::Basic, 'options' do
|
6
|
+
let(:rows) { [['a1', 'a2'], ['b1', 'b2']] }
|
7
|
+
let(:object) { described_class }
|
8
|
+
let(:table) { TTY::Table.new(rows) }
|
9
|
+
let(:widths) { nil }
|
10
|
+
let(:aligns) { [] }
|
11
|
+
let(:options) {
|
12
|
+
{
|
13
|
+
:column_widths => widths,
|
14
|
+
:column_aligns => aligns,
|
15
|
+
:renderer => :basic
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
subject { object.new table, options }
|
20
|
+
|
21
|
+
its(:border) { should be_kind_of TTY::Table::BorderOptions }
|
22
|
+
|
23
|
+
its(:column_widths) { should be_empty }
|
24
|
+
|
25
|
+
its(:column_aligns) { should eql(aligns) }
|
26
|
+
|
27
|
+
it { subject.column_aligns.to_a.should be_empty }
|
28
|
+
|
29
|
+
context '#column_widths' do
|
30
|
+
let(:widths) { [10, 10] }
|
31
|
+
|
32
|
+
its(:column_widths) { should == widths }
|
33
|
+
end
|
34
|
+
|
35
|
+
context '#column_widths empty' do
|
36
|
+
let(:widths) { [] }
|
37
|
+
|
38
|
+
it { expect { subject }.to raise_error(TTY::InvalidArgument) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context '#column_aligns' do
|
42
|
+
let(:aligns) { [:center, :center] }
|
43
|
+
|
44
|
+
it 'unwraps original array' do
|
45
|
+
subject.column_aligns.to_a.should == aligns
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|