vedeu 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +40 -0
- data/README.md +1 -0
- data/docs/dsl.md +24 -24
- data/lib/vedeu/all.rb +21 -44
- data/lib/vedeu/api.rb +13 -13
- data/lib/vedeu/application/application_controller.rb +2 -0
- data/lib/vedeu/bindings/movement.rb +53 -18
- data/lib/vedeu/bindings/refresh.rb +1 -1
- data/lib/vedeu/bindings/system.rb +2 -2
- data/lib/vedeu/bindings/visibility.rb +3 -3
- data/lib/vedeu/borders/all.rb +13 -0
- data/lib/vedeu/borders/border.rb +209 -202
- data/lib/vedeu/{dsl/border.rb → borders/dsl.rb} +15 -15
- data/lib/vedeu/{null/border.rb → borders/null.rb} +9 -9
- data/lib/vedeu/borders/render.rb +347 -0
- data/lib/vedeu/borders/repository.rb +19 -0
- data/lib/vedeu/buffers/all.rb +13 -0
- data/lib/vedeu/buffers/buffer.rb +182 -176
- data/lib/vedeu/{null/buffer.rb → buffers/null.rb} +8 -8
- data/lib/vedeu/buffers/repository.rb +24 -0
- data/lib/vedeu/buffers/virtual_buffer.rb +2 -2
- data/lib/vedeu/cursors/all.rb +11 -0
- data/lib/vedeu/cursors/cursor.rb +276 -0
- data/lib/vedeu/cursors/refresh.rb +84 -0
- data/lib/vedeu/cursors/repository.rb +34 -0
- data/lib/vedeu/dsl/interface.rb +9 -9
- data/lib/vedeu/dsl/shared.rb +11 -11
- data/lib/vedeu/{exceptions.rb → error.rb} +2 -2
- data/lib/vedeu/esc/esc.rb +1 -1
- data/lib/vedeu/geometry/all.rb +18 -0
- data/lib/vedeu/geometry/area.rb +170 -160
- data/lib/vedeu/geometry/coordinate.rb +61 -39
- data/lib/vedeu/geometry/dimension.rb +139 -132
- data/lib/vedeu/{dsl/geometry.rb → geometry/dsl.rb} +11 -11
- data/lib/vedeu/geometry/generic_coordinate.rb +159 -153
- data/lib/vedeu/geometry/geometry.rb +310 -212
- data/lib/vedeu/geometry/grid.rb +73 -69
- data/lib/vedeu/{null/geometry.rb → geometry/null.rb} +10 -10
- data/lib/vedeu/geometry/position.rb +124 -120
- data/lib/vedeu/geometry/repository.rb +19 -0
- data/lib/vedeu/input/editor/document.rb +2 -2
- data/lib/vedeu/internal_api.rb +8 -8
- data/lib/vedeu/models/escape.rb +2 -2
- data/lib/vedeu/models/interface.rb +1 -1
- data/lib/vedeu/models/page.rb +89 -0
- data/lib/vedeu/models/row.rb +66 -0
- data/lib/vedeu/models/toggleable.rb +1 -1
- data/lib/vedeu/models/views/char.rb +7 -6
- data/lib/vedeu/models/views/line.rb +1 -1
- data/lib/vedeu/models/views/view.rb +2 -2
- data/lib/vedeu/options.rb +19 -0
- data/lib/vedeu/output/clear/named_interface.rb +1 -1
- data/lib/vedeu/output/direct.rb +1 -1
- data/lib/vedeu/output/presentation.rb +2 -1
- data/lib/vedeu/output/viewport.rb +3 -3
- data/lib/vedeu/repositories/model.rb +9 -1
- data/lib/vedeu/repositories/repository.rb +5 -0
- data/lib/vedeu/terminal/terminal.rb +3 -3
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/borders/border_test.rb +299 -291
- data/test/lib/vedeu/{dsl/border_test.rb → borders/dsl_test.rb} +6 -6
- data/test/lib/vedeu/{null/border_test.rb → borders/null_test.rb} +6 -6
- data/test/lib/vedeu/borders/render_test.rb +125 -0
- data/test/lib/vedeu/borders/repository_test.rb +17 -0
- data/test/lib/vedeu/buffers/buffer_test.rb +116 -112
- data/test/lib/vedeu/{null/buffer_test.rb → buffers/null_test.rb} +5 -5
- data/test/lib/vedeu/buffers/repository_test.rb +18 -0
- data/test/lib/vedeu/cursors/cursor_test.rb +370 -0
- data/test/lib/vedeu/cursors/refresh_test.rb +69 -0
- data/test/lib/vedeu/cursors/repository_test.rb +41 -0
- data/test/lib/vedeu/dsl/interface_test.rb +5 -5
- data/test/lib/vedeu/{exceptions_test.rb → error_test.rb} +0 -0
- data/test/lib/vedeu/geometry/area_test.rb +141 -137
- data/test/lib/vedeu/geometry/coordinate_test.rb +93 -89
- data/test/lib/vedeu/geometry/dimension_test.rb +137 -133
- data/test/lib/vedeu/{dsl/geometry_test.rb → geometry/dsl_test.rb} +17 -17
- data/test/lib/vedeu/geometry/generic_coordinate_test.rb +32 -28
- data/test/lib/vedeu/geometry/geometry_test.rb +282 -157
- data/test/lib/vedeu/geometry/grid_test.rb +35 -31
- data/test/lib/vedeu/{null/geometry_test.rb → geometry/null_test.rb} +5 -5
- data/test/lib/vedeu/geometry/position_test.rb +146 -142
- data/test/lib/vedeu/geometry/repository_test.rb +19 -0
- data/test/lib/vedeu/input/editor/document_test.rb +1 -1
- data/test/lib/vedeu/models/escape_test.rb +1 -1
- data/test/lib/vedeu/models/interface_test.rb +2 -2
- data/test/lib/vedeu/models/page_test.rb +235 -0
- data/test/lib/vedeu/models/row_test.rb +111 -0
- data/test/lib/vedeu/models/views/char_test.rb +3 -3
- data/test/lib/vedeu/options_test.rb +57 -0
- data/test/lib/vedeu/output/clear/named_interface_test.rb +1 -1
- data/test/lib/vedeu/output/renderers/json_test.rb +1 -1
- data/test/lib/vedeu/output/viewport_test.rb +15 -9
- data/test/lib/vedeu/refresh/refresh_buffer_test.rb +12 -12
- data/test/lib/vedeu/repositories/repositories_test.rb +1 -1
- data/test/lib/vedeu/repositories/repository_test.rb +7 -0
- data/test/lib/vedeu/terminal/terminal_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/vedeu.gemspec +2 -2
- metadata +57 -63
- data/lib/vedeu/borders/borders.rb +0 -15
- data/lib/vedeu/borders/render_border.rb +0 -331
- data/lib/vedeu/buffers/buffers.rb +0 -20
- data/lib/vedeu/cursor/cursor.rb +0 -174
- data/lib/vedeu/cursor/cursors.rb +0 -30
- data/lib/vedeu/cursor/move.rb +0 -239
- data/lib/vedeu/cursor/reposition.rb +0 -78
- data/lib/vedeu/geometry/geometries.rb +0 -15
- data/lib/vedeu/refresh/refresh_cursor.rb +0 -92
- data/test/lib/vedeu/borders/borders_test.rb +0 -13
- data/test/lib/vedeu/borders/render_border_test.rb +0 -121
- data/test/lib/vedeu/buffers/buffers_test.rb +0 -14
- data/test/lib/vedeu/cursor/cursor_test.rb +0 -246
- data/test/lib/vedeu/cursor/cursors_test.rb +0 -37
- data/test/lib/vedeu/cursor/move_test.rb +0 -301
- data/test/lib/vedeu/cursor/reposition_test.rb +0 -63
- data/test/lib/vedeu/geometry/geometries_test.rb +0 -15
- data/test/lib/vedeu/refresh/refresh_cursor_test.rb +0 -65
@@ -2,51 +2,55 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
|
5
|
+
module Geometry
|
6
6
|
|
7
|
-
|
8
|
-
let(:instance) { described.new(_value) }
|
9
|
-
let(:_value) { 2 }
|
7
|
+
describe Grid do
|
10
8
|
|
11
|
-
|
9
|
+
let(:described) { Vedeu::Geometry::Grid }
|
10
|
+
let(:instance) { described.new(_value) }
|
11
|
+
let(:_value) { 2 }
|
12
12
|
|
13
|
-
|
14
|
-
it { instance.must_be_instance_of(described) }
|
15
|
-
it { instance.instance_variable_get('@value').must_equal(_value) }
|
16
|
-
end
|
13
|
+
before { IO.console.stubs(:winsize).returns([25, 80]) }
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
it {
|
15
|
+
describe '#initialize' do
|
16
|
+
it { instance.must_be_instance_of(described) }
|
17
|
+
it { instance.instance_variable_get('@value').must_equal(_value) }
|
21
18
|
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
describe '.columns' do
|
21
|
+
context 'when the value is less than 1' do
|
22
|
+
it { proc { Vedeu::Geometry::Grid.columns(0) }.must_raise(Vedeu::Error::OutOfRange) }
|
23
|
+
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
Grid.columns(7).must_equal(42)
|
25
|
+
context 'when the value is greater than 12' do
|
26
|
+
it { proc { Vedeu::Geometry::Grid.columns(13) }.must_raise(Vedeu::Error::OutOfRange) }
|
30
27
|
end
|
31
|
-
end
|
32
|
-
end
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
context 'when the value is in range' do
|
30
|
+
it 'returns the value of the column' do
|
31
|
+
Vedeu::Geometry::Grid.columns(7).must_equal(42)
|
32
|
+
end
|
33
|
+
end
|
37
34
|
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
describe '.rows' do
|
37
|
+
context 'when the value is less than 1' do
|
38
|
+
it { proc { Vedeu::Geometry::Grid.rows(0) }.must_raise(Vedeu::Error::OutOfRange) }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when the value is greater than 12' do
|
42
|
+
it { proc { Vedeu::Geometry::Grid.rows(13) }.must_raise(Vedeu::Error::OutOfRange) }
|
43
|
+
end
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
context 'when the value is in range' do
|
46
|
+
it 'returns the value of the row' do
|
47
|
+
Vedeu::Geometry::Grid.rows(7).must_equal(14)
|
48
|
+
end
|
46
49
|
end
|
47
50
|
end
|
48
|
-
end
|
49
51
|
|
50
|
-
|
52
|
+
end # Grid
|
53
|
+
|
54
|
+
end # Geometry
|
51
55
|
|
52
56
|
end # Vedeu
|
@@ -2,11 +2,11 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
module
|
5
|
+
module Geometry
|
6
6
|
|
7
|
-
describe
|
7
|
+
describe Null do
|
8
8
|
|
9
|
-
let(:described) { Vedeu::Null
|
9
|
+
let(:described) { Vedeu::Geometry::Null }
|
10
10
|
let(:instance) { described.new(attributes) }
|
11
11
|
let(:attributes){
|
12
12
|
{
|
@@ -95,8 +95,8 @@ module Vedeu
|
|
95
95
|
it { instance.yn.must_equal(25) }
|
96
96
|
end
|
97
97
|
|
98
|
-
end #
|
98
|
+
end # Null
|
99
99
|
|
100
|
-
end #
|
100
|
+
end # Geometry
|
101
101
|
|
102
102
|
end # Vedeu
|
@@ -2,217 +2,221 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
|
5
|
+
module Geometry
|
6
6
|
|
7
|
-
|
8
|
-
let(:instance) { described.new(y, x) }
|
9
|
-
let(:y) { 12 }
|
10
|
-
let(:x) { 19 }
|
7
|
+
describe Position do
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
it { instance.must_respond_to(:last) }
|
17
|
-
end
|
9
|
+
let(:described) { Vedeu::Geometry::Position }
|
10
|
+
let(:instance) { described.new(y, x) }
|
11
|
+
let(:y) { 12 }
|
12
|
+
let(:x) { 19 }
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
describe 'accessors' do
|
15
|
+
it { instance.must_respond_to(:y) }
|
16
|
+
it { instance.must_respond_to(:first) }
|
17
|
+
it { instance.must_respond_to(:x) }
|
18
|
+
it { instance.must_respond_to(:last) }
|
19
|
+
end
|
24
20
|
|
25
|
-
|
26
|
-
|
21
|
+
describe '#initialize' do
|
22
|
+
it { instance.must_be_instance_of(described) }
|
23
|
+
it { instance.instance_variable_get('@y').must_equal(y) }
|
24
|
+
it { instance.instance_variable_get('@x').must_equal(x) }
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
27
|
+
describe '.[]' do
|
28
|
+
subject { described.[](y, x) }
|
30
29
|
|
31
|
-
|
32
|
-
|
30
|
+
it { instance.must_be_instance_of(described) }
|
31
|
+
end
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
let(:other) { described.new(12, 19) }
|
33
|
+
describe '#<=>' do
|
34
|
+
subject { instance.<=>(other) }
|
37
35
|
|
38
|
-
|
39
|
-
|
36
|
+
context 'when y is the same as other.y' do
|
37
|
+
context 'when x is the same as other.x' do
|
38
|
+
let(:other) { described.new(12, 19) }
|
40
39
|
|
41
|
-
|
42
|
-
|
40
|
+
it { subject.must_equal(0) }
|
41
|
+
end
|
43
42
|
|
44
|
-
|
43
|
+
context 'when x is different to other.x' do
|
44
|
+
let(:other) { described.new(12, 21) }
|
45
|
+
|
46
|
+
it { subject.must_equal(-1) }
|
47
|
+
end
|
45
48
|
end
|
46
|
-
end
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
+
context 'when y is different to other.y' do
|
51
|
+
let(:other) { described.new(14, 19) }
|
50
52
|
|
51
|
-
|
53
|
+
it { subject.must_equal(-1) }
|
54
|
+
end
|
52
55
|
end
|
53
|
-
end
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
+
describe '.coerce' do
|
58
|
+
let(:_value) {}
|
57
59
|
|
58
|
-
|
60
|
+
subject { described.coerce(_value) }
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
+
context 'when the value is already a Position' do
|
63
|
+
let(:_value) { instance }
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
+
it { subject.must_equal(instance) }
|
66
|
+
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
+
context 'when the value is an Array' do
|
69
|
+
let(:_value) { [2, 8] }
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
it { subject.must_be_instance_of(described) }
|
72
|
+
it { subject.y.must_equal(2) }
|
73
|
+
it { subject.x.must_equal(8) }
|
74
|
+
end
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
+
context 'when the value is a Hash' do
|
77
|
+
let(:_value) { { y: 3, x: 9 } }
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
it { subject.must_be_instance_of(described) }
|
80
|
+
it { subject.y.must_equal(3) }
|
81
|
+
it { subject.x.must_equal(9) }
|
82
|
+
end
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
+
context 'when the value is something unhandled' do
|
85
|
+
it { subject.must_be_instance_of(NilClass) }
|
86
|
+
end
|
84
87
|
end
|
85
|
-
end
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
+
describe '#eql?' do
|
90
|
+
let(:other) { described.new(12, 19) }
|
89
91
|
|
90
|
-
|
92
|
+
subject { instance.eql?(other) }
|
91
93
|
|
92
|
-
|
94
|
+
it { subject.must_equal(true) }
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
+
context 'when different to other' do
|
97
|
+
let(:other) { described.new(2, 9) }
|
96
98
|
|
97
|
-
|
99
|
+
it { subject.must_equal(false) }
|
100
|
+
end
|
98
101
|
end
|
99
|
-
end
|
100
102
|
|
101
|
-
|
102
|
-
|
103
|
+
describe '#to_a' do
|
104
|
+
subject { Vedeu::Geometry::Position.new.to_a }
|
103
105
|
|
104
|
-
|
105
|
-
|
106
|
+
it { subject.must_equal([1, 1]) }
|
107
|
+
end
|
106
108
|
|
107
|
-
|
108
|
-
|
109
|
+
describe '#to_position' do
|
110
|
+
subject { instance.to_position }
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
112
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Position) }
|
113
|
+
it { subject.must_equal(instance) }
|
114
|
+
end
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
+
describe '#to_s' do
|
117
|
+
# subject { described.new.to_s }
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
-
|
119
|
+
it 'returns an escape sequence when no coordinates are provided' do
|
120
|
+
Vedeu::Geometry::Position.new.to_s.must_equal("\e[1;1H")
|
121
|
+
end
|
120
122
|
|
121
|
-
|
122
|
-
|
123
|
-
|
123
|
+
it 'returns an escape sequence when coordinates are provided' do
|
124
|
+
Vedeu::Geometry::Position[12, 19].to_s.must_equal("\e[12;19H")
|
125
|
+
end
|
124
126
|
|
125
|
-
|
126
|
-
|
127
|
-
|
127
|
+
it 'returns an escape sequence if a coordinate is missing' do
|
128
|
+
Vedeu::Geometry::Position.new(12).to_s.must_equal("\e[12;1H")
|
129
|
+
end
|
128
130
|
|
129
|
-
|
130
|
-
|
131
|
-
|
131
|
+
it 'returns an escape sequence if the x coordinate is negative' do
|
132
|
+
Vedeu::Geometry::Position[12, -5].to_s.must_equal("\e[12;1H")
|
133
|
+
end
|
132
134
|
|
133
|
-
|
134
|
-
|
135
|
-
|
135
|
+
it 'returns an escape sequence if the y coordinate is negative' do
|
136
|
+
Vedeu::Geometry::Position[-12, 5].to_s.must_equal("\e[1;5H")
|
137
|
+
end
|
136
138
|
|
137
|
-
|
138
|
-
|
139
|
+
it 'resets to starting position when a block is given' do
|
140
|
+
Vedeu::Geometry::Position[4, 9].to_s { 'test' }.must_equal("\e[4;9Htest")
|
141
|
+
end
|
139
142
|
end
|
140
|
-
end
|
141
143
|
|
142
|
-
|
143
|
-
|
144
|
+
describe '#as_indices' do
|
145
|
+
subject { instance.as_indices }
|
144
146
|
|
145
|
-
|
147
|
+
it { subject.must_equal([11, 18]) }
|
146
148
|
|
147
|
-
|
148
|
-
|
149
|
+
context 'when y is less than 1' do
|
150
|
+
let(:y) { -3 }
|
149
151
|
|
150
|
-
|
151
|
-
|
152
|
+
it { subject.must_equal([0, 18]) }
|
153
|
+
end
|
152
154
|
|
153
|
-
|
154
|
-
|
155
|
+
context 'when x is less than 1' do
|
156
|
+
let(:x) { -9 }
|
155
157
|
|
156
|
-
|
158
|
+
it { subject.must_equal([11, 0]) }
|
159
|
+
end
|
157
160
|
end
|
158
|
-
end
|
159
161
|
|
160
|
-
|
161
|
-
|
162
|
+
describe '#down' do
|
163
|
+
subject { instance.down }
|
162
164
|
|
163
|
-
|
164
|
-
|
165
|
-
|
165
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Position) }
|
166
|
+
it { subject.y.must_equal(13) }
|
167
|
+
it { subject.x.must_equal(19) }
|
166
168
|
|
167
|
-
|
168
|
-
|
169
|
+
context 'when y is 0' do
|
170
|
+
let(:y) { 0 }
|
169
171
|
|
170
|
-
|
172
|
+
it { subject.y.must_equal(2) }
|
173
|
+
end
|
171
174
|
end
|
172
|
-
end
|
173
175
|
|
174
|
-
|
175
|
-
|
176
|
+
describe '#left' do
|
177
|
+
subject { instance.left }
|
176
178
|
|
177
|
-
|
178
|
-
|
179
|
-
|
179
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Position) }
|
180
|
+
it { subject.y.must_equal(12) }
|
181
|
+
it { subject.x.must_equal(18) }
|
180
182
|
|
181
|
-
|
182
|
-
|
183
|
+
context 'when x is 0' do
|
184
|
+
let(:x) { 0 }
|
183
185
|
|
184
|
-
|
186
|
+
it { subject.x.must_equal(1) }
|
187
|
+
end
|
185
188
|
end
|
186
|
-
end
|
187
189
|
|
188
|
-
|
189
|
-
|
190
|
+
describe '#right' do
|
191
|
+
subject { instance.right }
|
190
192
|
|
191
|
-
|
192
|
-
|
193
|
-
|
193
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Position) }
|
194
|
+
it { subject.y.must_equal(12) }
|
195
|
+
it { subject.x.must_equal(20) }
|
194
196
|
|
195
|
-
|
196
|
-
|
197
|
+
context 'when x is 0' do
|
198
|
+
let(:x) { 0 }
|
197
199
|
|
198
|
-
|
200
|
+
it { subject.x.must_equal(2) }
|
201
|
+
end
|
199
202
|
end
|
200
|
-
end
|
201
203
|
|
202
|
-
|
203
|
-
|
204
|
+
describe '#up' do
|
205
|
+
subject { instance.up }
|
204
206
|
|
205
|
-
|
206
|
-
|
207
|
-
|
207
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Position) }
|
208
|
+
it { subject.y.must_equal(11) }
|
209
|
+
it { subject.x.must_equal(19) }
|
208
210
|
|
209
|
-
|
210
|
-
|
211
|
+
context 'when y is 0' do
|
212
|
+
let(:y) { 0 }
|
211
213
|
|
212
|
-
|
214
|
+
it { subject.y.must_equal(1) }
|
215
|
+
end
|
213
216
|
end
|
214
|
-
end
|
215
217
|
|
216
|
-
|
218
|
+
end # Position
|
219
|
+
|
220
|
+
end # Geometry
|
217
221
|
|
218
222
|
end # Vedeu
|