vedeu 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +40 -0
  3. data/README.md +1 -0
  4. data/docs/dsl.md +24 -24
  5. data/lib/vedeu/all.rb +21 -44
  6. data/lib/vedeu/api.rb +13 -13
  7. data/lib/vedeu/application/application_controller.rb +2 -0
  8. data/lib/vedeu/bindings/movement.rb +53 -18
  9. data/lib/vedeu/bindings/refresh.rb +1 -1
  10. data/lib/vedeu/bindings/system.rb +2 -2
  11. data/lib/vedeu/bindings/visibility.rb +3 -3
  12. data/lib/vedeu/borders/all.rb +13 -0
  13. data/lib/vedeu/borders/border.rb +209 -202
  14. data/lib/vedeu/{dsl/border.rb → borders/dsl.rb} +15 -15
  15. data/lib/vedeu/{null/border.rb → borders/null.rb} +9 -9
  16. data/lib/vedeu/borders/render.rb +347 -0
  17. data/lib/vedeu/borders/repository.rb +19 -0
  18. data/lib/vedeu/buffers/all.rb +13 -0
  19. data/lib/vedeu/buffers/buffer.rb +182 -176
  20. data/lib/vedeu/{null/buffer.rb → buffers/null.rb} +8 -8
  21. data/lib/vedeu/buffers/repository.rb +24 -0
  22. data/lib/vedeu/buffers/virtual_buffer.rb +2 -2
  23. data/lib/vedeu/cursors/all.rb +11 -0
  24. data/lib/vedeu/cursors/cursor.rb +276 -0
  25. data/lib/vedeu/cursors/refresh.rb +84 -0
  26. data/lib/vedeu/cursors/repository.rb +34 -0
  27. data/lib/vedeu/dsl/interface.rb +9 -9
  28. data/lib/vedeu/dsl/shared.rb +11 -11
  29. data/lib/vedeu/{exceptions.rb → error.rb} +2 -2
  30. data/lib/vedeu/esc/esc.rb +1 -1
  31. data/lib/vedeu/geometry/all.rb +18 -0
  32. data/lib/vedeu/geometry/area.rb +170 -160
  33. data/lib/vedeu/geometry/coordinate.rb +61 -39
  34. data/lib/vedeu/geometry/dimension.rb +139 -132
  35. data/lib/vedeu/{dsl/geometry.rb → geometry/dsl.rb} +11 -11
  36. data/lib/vedeu/geometry/generic_coordinate.rb +159 -153
  37. data/lib/vedeu/geometry/geometry.rb +310 -212
  38. data/lib/vedeu/geometry/grid.rb +73 -69
  39. data/lib/vedeu/{null/geometry.rb → geometry/null.rb} +10 -10
  40. data/lib/vedeu/geometry/position.rb +124 -120
  41. data/lib/vedeu/geometry/repository.rb +19 -0
  42. data/lib/vedeu/input/editor/document.rb +2 -2
  43. data/lib/vedeu/internal_api.rb +8 -8
  44. data/lib/vedeu/models/escape.rb +2 -2
  45. data/lib/vedeu/models/interface.rb +1 -1
  46. data/lib/vedeu/models/page.rb +89 -0
  47. data/lib/vedeu/models/row.rb +66 -0
  48. data/lib/vedeu/models/toggleable.rb +1 -1
  49. data/lib/vedeu/models/views/char.rb +7 -6
  50. data/lib/vedeu/models/views/line.rb +1 -1
  51. data/lib/vedeu/models/views/view.rb +2 -2
  52. data/lib/vedeu/options.rb +19 -0
  53. data/lib/vedeu/output/clear/named_interface.rb +1 -1
  54. data/lib/vedeu/output/direct.rb +1 -1
  55. data/lib/vedeu/output/presentation.rb +2 -1
  56. data/lib/vedeu/output/viewport.rb +3 -3
  57. data/lib/vedeu/repositories/model.rb +9 -1
  58. data/lib/vedeu/repositories/repository.rb +5 -0
  59. data/lib/vedeu/terminal/terminal.rb +3 -3
  60. data/lib/vedeu/version.rb +1 -1
  61. data/test/lib/vedeu/borders/border_test.rb +299 -291
  62. data/test/lib/vedeu/{dsl/border_test.rb → borders/dsl_test.rb} +6 -6
  63. data/test/lib/vedeu/{null/border_test.rb → borders/null_test.rb} +6 -6
  64. data/test/lib/vedeu/borders/render_test.rb +125 -0
  65. data/test/lib/vedeu/borders/repository_test.rb +17 -0
  66. data/test/lib/vedeu/buffers/buffer_test.rb +116 -112
  67. data/test/lib/vedeu/{null/buffer_test.rb → buffers/null_test.rb} +5 -5
  68. data/test/lib/vedeu/buffers/repository_test.rb +18 -0
  69. data/test/lib/vedeu/cursors/cursor_test.rb +370 -0
  70. data/test/lib/vedeu/cursors/refresh_test.rb +69 -0
  71. data/test/lib/vedeu/cursors/repository_test.rb +41 -0
  72. data/test/lib/vedeu/dsl/interface_test.rb +5 -5
  73. data/test/lib/vedeu/{exceptions_test.rb → error_test.rb} +0 -0
  74. data/test/lib/vedeu/geometry/area_test.rb +141 -137
  75. data/test/lib/vedeu/geometry/coordinate_test.rb +93 -89
  76. data/test/lib/vedeu/geometry/dimension_test.rb +137 -133
  77. data/test/lib/vedeu/{dsl/geometry_test.rb → geometry/dsl_test.rb} +17 -17
  78. data/test/lib/vedeu/geometry/generic_coordinate_test.rb +32 -28
  79. data/test/lib/vedeu/geometry/geometry_test.rb +282 -157
  80. data/test/lib/vedeu/geometry/grid_test.rb +35 -31
  81. data/test/lib/vedeu/{null/geometry_test.rb → geometry/null_test.rb} +5 -5
  82. data/test/lib/vedeu/geometry/position_test.rb +146 -142
  83. data/test/lib/vedeu/geometry/repository_test.rb +19 -0
  84. data/test/lib/vedeu/input/editor/document_test.rb +1 -1
  85. data/test/lib/vedeu/models/escape_test.rb +1 -1
  86. data/test/lib/vedeu/models/interface_test.rb +2 -2
  87. data/test/lib/vedeu/models/page_test.rb +235 -0
  88. data/test/lib/vedeu/models/row_test.rb +111 -0
  89. data/test/lib/vedeu/models/views/char_test.rb +3 -3
  90. data/test/lib/vedeu/options_test.rb +57 -0
  91. data/test/lib/vedeu/output/clear/named_interface_test.rb +1 -1
  92. data/test/lib/vedeu/output/renderers/json_test.rb +1 -1
  93. data/test/lib/vedeu/output/viewport_test.rb +15 -9
  94. data/test/lib/vedeu/refresh/refresh_buffer_test.rb +12 -12
  95. data/test/lib/vedeu/repositories/repositories_test.rb +1 -1
  96. data/test/lib/vedeu/repositories/repository_test.rb +7 -0
  97. data/test/lib/vedeu/terminal/terminal_test.rb +1 -1
  98. data/test/test_helper.rb +1 -1
  99. data/vedeu.gemspec +2 -2
  100. metadata +57 -63
  101. data/lib/vedeu/borders/borders.rb +0 -15
  102. data/lib/vedeu/borders/render_border.rb +0 -331
  103. data/lib/vedeu/buffers/buffers.rb +0 -20
  104. data/lib/vedeu/cursor/cursor.rb +0 -174
  105. data/lib/vedeu/cursor/cursors.rb +0 -30
  106. data/lib/vedeu/cursor/move.rb +0 -239
  107. data/lib/vedeu/cursor/reposition.rb +0 -78
  108. data/lib/vedeu/geometry/geometries.rb +0 -15
  109. data/lib/vedeu/refresh/refresh_cursor.rb +0 -92
  110. data/test/lib/vedeu/borders/borders_test.rb +0 -13
  111. data/test/lib/vedeu/borders/render_border_test.rb +0 -121
  112. data/test/lib/vedeu/buffers/buffers_test.rb +0 -14
  113. data/test/lib/vedeu/cursor/cursor_test.rb +0 -246
  114. data/test/lib/vedeu/cursor/cursors_test.rb +0 -37
  115. data/test/lib/vedeu/cursor/move_test.rb +0 -301
  116. data/test/lib/vedeu/cursor/reposition_test.rb +0 -63
  117. data/test/lib/vedeu/geometry/geometries_test.rb +0 -15
  118. data/test/lib/vedeu/refresh/refresh_cursor_test.rb +0 -65
@@ -2,11 +2,11 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
 
5
- module Null
5
+ module Buffers
6
6
 
7
- describe Buffer do
7
+ describe Null do
8
8
 
9
- let(:described) { Vedeu::Null::Buffer }
9
+ let(:described) { Vedeu::Buffers::Null }
10
10
  let(:instance) { described.new(attributes) }
11
11
  let(:attributes){
12
12
  {
@@ -45,8 +45,8 @@ module Vedeu
45
45
  it { subject.must_be_instance_of(TrueClass) }
46
46
  end
47
47
 
48
- end # Buffer
48
+ end # Null
49
49
 
50
- end # Null
50
+ end # Buffers
51
51
 
52
52
  end # Vedeu
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Buffers
6
+
7
+ describe Repository do
8
+
9
+ let(:described) { Vedeu::Buffers::Repository }
10
+ let(:instance) { described.buffers }
11
+
12
+ it { described.must_respond_to(:buffers) }
13
+
14
+ end # Repository
15
+
16
+ end # Buffers
17
+
18
+ end # Vedeu
@@ -0,0 +1,370 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Cursors
6
+
7
+ describe Cursor do
8
+
9
+ let(:described) { Vedeu::Cursors::Cursor }
10
+ let(:instance) { described.new(attributes) }
11
+ let(:attributes) {
12
+ {
13
+ name: _name,
14
+ ox: ox,
15
+ oy: oy,
16
+ repository: repository,
17
+ visible: visible,
18
+ x: x,
19
+ y: y,
20
+ }
21
+ }
22
+ let(:_name) { 'silver' }
23
+ let(:ox) { 3 }
24
+ let(:oy) { 2 }
25
+ let(:repository) { Vedeu.cursors }
26
+ let(:visible) { true }
27
+ let(:x) { 19 }
28
+ let(:y) { 8 }
29
+ let(:border) {
30
+ Vedeu::Borders::Border.new(name: _name, enabled: enabled)
31
+ }
32
+ let(:geometry) {
33
+ Vedeu::Geometry::Geometry.new(
34
+ name: _name,
35
+ x: 5,
36
+ xn: 35,
37
+ y: 5,
38
+ yn: 10
39
+ )
40
+ }
41
+ let(:enabled) { true }
42
+
43
+ before do
44
+ Vedeu.borders.stubs(:by_name).returns(border)
45
+ Vedeu.geometries.stubs(:by_name).returns(geometry)
46
+ end
47
+
48
+ describe '#initialize' do
49
+ subject { instance }
50
+
51
+ it { subject.must_be_instance_of(described) }
52
+ it { subject.instance_variable_get('@name').must_equal('silver') }
53
+ it { subject.instance_variable_get('@ox').must_equal(ox) }
54
+ it { subject.instance_variable_get('@oy').must_equal(oy) }
55
+ it { subject.instance_variable_get('@repository').must_equal(repository) }
56
+ it { subject.instance_variable_get('@visible').must_equal(true) }
57
+ it { subject.instance_variable_get('@x').must_equal(x) }
58
+ it { subject.instance_variable_get('@y').must_equal(y) }
59
+ end
60
+
61
+ describe 'accessors' do
62
+ it { instance.must_respond_to(:attributes) }
63
+ it { instance.must_respond_to(:name) }
64
+ it { instance.must_respond_to(:ox) }
65
+ it { instance.must_respond_to(:ox=) }
66
+ it { instance.must_respond_to(:oy) }
67
+ it { instance.must_respond_to(:oy=) }
68
+ it { instance.must_respond_to(:state) }
69
+ it { instance.must_respond_to(:x=) }
70
+ it { instance.must_respond_to(:y=) }
71
+ end
72
+
73
+ describe '#hide' do
74
+ let(:visible) { true }
75
+ let(:hide_cursor) { Vedeu::Escape.new(value: Vedeu::Esc.hide_cursor) }
76
+
77
+ before do
78
+ Vedeu::Output.stubs(:render).
79
+ with(hide_cursor).returns(hide_cursor)
80
+ end
81
+
82
+ subject { instance.hide }
83
+
84
+ it { subject.must_be_instance_of(Vedeu::Escape) }
85
+ end
86
+
87
+ describe '#move_down' do
88
+ let(:x) { 19 }
89
+ let(:y) { 8 }
90
+ let(:ox) { 3 }
91
+ let(:oy) { 2 }
92
+
93
+ subject { instance.move_down }
94
+
95
+ it { subject.must_be_instance_of(described) }
96
+
97
+ it { subject.x.must_equal(19) }
98
+ it { subject.y.must_equal(8) }
99
+ it { subject.ox.must_equal(3) }
100
+ it { subject.oy.must_equal(3) }
101
+ end
102
+
103
+ describe '#move_left' do
104
+ let(:x) { 19 }
105
+ let(:y) { 8 }
106
+ let(:ox) { 3 }
107
+ let(:oy) { 2 }
108
+
109
+ subject { instance.move_left }
110
+
111
+ it { subject.must_be_instance_of(described) }
112
+
113
+ it { subject.x.must_equal(7) }
114
+ it { subject.y.must_equal(8) }
115
+ it { subject.ox.must_equal(2) }
116
+ it { subject.oy.must_equal(2) }
117
+ end
118
+
119
+ describe '#move_origin' do
120
+ let(:x) { 19 }
121
+ let(:y) { 8 }
122
+ let(:ox) { 3 }
123
+ let(:oy) { 2 }
124
+
125
+ subject { instance.move_origin }
126
+
127
+ it { subject.must_be_instance_of(described) }
128
+
129
+ it { subject.x.must_equal(6) }
130
+ it { subject.y.must_equal(6) }
131
+ it { subject.ox.must_equal(0) }
132
+ it { subject.oy.must_equal(0) }
133
+ end
134
+
135
+ describe '#move_right' do
136
+ let(:x) { 19 }
137
+ let(:y) { 8 }
138
+ let(:ox) { 3 }
139
+ let(:oy) { 2 }
140
+
141
+ subject { instance.move_right }
142
+
143
+ it { subject.must_be_instance_of(described) }
144
+
145
+ it { subject.x.must_equal(9) }
146
+ it { subject.y.must_equal(8) }
147
+ it { subject.ox.must_equal(4) }
148
+ it { subject.oy.must_equal(2) }
149
+ end
150
+
151
+ describe '#move_up' do
152
+ let(:x) { 19 }
153
+ let(:y) { 8 }
154
+ let(:ox) { 3 }
155
+ let(:oy) { 2 }
156
+
157
+ subject { instance.move_up }
158
+
159
+ it { subject.must_be_instance_of(described) }
160
+
161
+ it { subject.x.must_equal(19) }
162
+ it { subject.y.must_equal(6) }
163
+ it { subject.ox.must_equal(3) }
164
+ it { subject.oy.must_equal(1) }
165
+ end
166
+
167
+ describe '#ox' do
168
+ subject { instance.ox }
169
+
170
+ it { subject.must_equal(3) }
171
+
172
+ context 'when < 0' do
173
+ let(:ox) { -2 }
174
+
175
+ it { subject.must_equal(0) }
176
+ end
177
+ end
178
+
179
+ describe '#oy' do
180
+ subject { instance.oy }
181
+
182
+ it { subject.must_equal(2) }
183
+
184
+ context 'when < 0' do
185
+ let(:oy) { -4 }
186
+
187
+ it { subject.must_equal(0) }
188
+ end
189
+ end
190
+
191
+ describe '#position' do
192
+ subject { instance.position }
193
+
194
+ it { subject.must_be_instance_of(Vedeu::Geometry::Position) }
195
+ end
196
+
197
+ describe '#show' do
198
+ let(:visible) { false }
199
+ let(:show_cursor) { Vedeu::Escape.new(value: Vedeu::Esc.show_cursor) }
200
+
201
+ before do
202
+ Vedeu::Output.stubs(:render).
203
+ with(show_cursor).returns(show_cursor)
204
+ end
205
+
206
+ subject { instance.show }
207
+
208
+ it { subject.must_be_instance_of(Vedeu::Escape) }
209
+ end
210
+
211
+ describe '#reposition' do
212
+ let(:new_y) { 3 }
213
+ let(:new_x) { 5 }
214
+
215
+ subject { instance.reposition(new_y, new_x) }
216
+
217
+ it { subject.must_be_instance_of(described) }
218
+
219
+ it { subject.x.must_equal(8) }
220
+ it { subject.y.must_equal(7) }
221
+ it { subject.ox.must_equal(5) }
222
+ it { subject.oy.must_equal(3) }
223
+ end
224
+
225
+ describe '#to_s' do
226
+ let(:visible) { true }
227
+
228
+ subject { instance.to_s }
229
+
230
+ it { instance.must_respond_to(:to_str) }
231
+ it { subject.must_be_instance_of(String) }
232
+
233
+ context 'when the cursor is visible' do
234
+ it 'returns an visible cursor escape sequence with position' do
235
+ subject.must_equal("\e[8;19H\e[?25h")
236
+ end
237
+ end
238
+
239
+ context 'when the cursor is invisible' do
240
+ let(:visible) { false }
241
+
242
+ it 'returns the invisible cursor escape sequence with position' do
243
+ subject.must_equal("\e[8;19H\e[?25l")
244
+ end
245
+ end
246
+
247
+ context 'when a block is given' do
248
+ subject {
249
+ instance.to_s do
250
+ # ...
251
+ end
252
+ }
253
+
254
+ it 'returns the escape sequence to position and set the visibility ' \
255
+ 'of the cursor and returns to that position after yielding the ' \
256
+ 'block' do
257
+ subject.must_equal("\e[8;19H\e[8;19H\e[?25h")
258
+ end
259
+ end
260
+ end
261
+
262
+ describe '#x' do
263
+ subject { instance.x }
264
+
265
+ context 'when x is less than tx' do
266
+ let(:x) { -2 }
267
+
268
+ it { subject.must_equal(6) }
269
+ end
270
+
271
+ context 'when x is less than left' do
272
+ let(:x) { 2 }
273
+
274
+ it { subject.must_equal(6) }
275
+ end
276
+
277
+ context 'when x is less than bx' do
278
+ let(:x) { 5 }
279
+
280
+ it { subject.must_equal(6) }
281
+
282
+ context 'when border is not enabled' do
283
+ let(:enabled) { false }
284
+
285
+ it { subject.must_equal(5) }
286
+ end
287
+ end
288
+
289
+ context 'when x is more than txn' do
290
+ let(:x) { 47 }
291
+
292
+ it { subject.must_equal(34) }
293
+ end
294
+
295
+ context 'when x is more than right' do
296
+ let(:x) { 37 }
297
+
298
+ it { subject.must_equal(34) }
299
+ end
300
+
301
+ context 'when x is more than bxn' do
302
+ let(:x) { 35 }
303
+
304
+ it { subject.must_equal(34) }
305
+
306
+ context 'when border is not enabled' do
307
+ let(:enabled) { false }
308
+
309
+ it { subject.must_equal(35) }
310
+ end
311
+ end
312
+ end
313
+
314
+ describe '#y' do
315
+ subject { instance.y }
316
+
317
+ context 'when y is less than ty' do
318
+ let(:y) { -2 }
319
+
320
+ it { subject.must_equal(6) }
321
+ end
322
+
323
+ context 'when y is less than top' do
324
+ let(:y) { 2 }
325
+
326
+ it { subject.must_equal(6) }
327
+ end
328
+
329
+ context 'when y is less than by' do
330
+ let(:y) { 5 }
331
+
332
+ it { subject.must_equal(6) }
333
+
334
+ context 'when border is not enabled' do
335
+ let(:enabled) { false }
336
+
337
+ it { subject.must_equal(5) }
338
+ end
339
+ end
340
+
341
+ context 'when y is more than tyn' do
342
+ let(:y) { 17 }
343
+
344
+ it { subject.must_equal(9) }
345
+ end
346
+
347
+ context 'when y is more than bottom' do
348
+ let(:y) { 12 }
349
+
350
+ it { subject.must_equal(9) }
351
+ end
352
+
353
+ context 'when y is more than byn' do
354
+ let(:y) { 10 }
355
+
356
+ it { subject.must_equal(9) }
357
+
358
+ context 'when border is not enabled' do
359
+ let(:enabled) { false }
360
+
361
+ it { subject.must_equal(10) }
362
+ end
363
+ end
364
+ end
365
+
366
+ end # Cursor
367
+
368
+ end # Cursors
369
+
370
+ end # Vedeu
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Cursors
6
+
7
+ describe Refresh do
8
+
9
+ let(:described) { Vedeu::Cursors::Refresh }
10
+ let(:instance) { described.new(_name) }
11
+ let(:_name) { 'refresh_cursor' }
12
+ let(:expected) {}
13
+ let(:ox) { 0 }
14
+ let(:oy) { 0 }
15
+
16
+ describe '#initialize' do
17
+ it { instance.must_be_instance_of(described) }
18
+ it { instance.instance_variable_get('@name').must_equal(_name) }
19
+ end
20
+
21
+ describe '.by_name' do
22
+ before do
23
+ Vedeu.geometry 'refresh_cursor' do
24
+ x 1
25
+ xn 3
26
+ y 1
27
+ yn 3
28
+ end
29
+ Vedeu::Cursors::Cursor.new(name: 'refresh_cursor', ox: ox, oy: oy).store
30
+
31
+ Vedeu::Terminal.stubs(:output).returns(expected)
32
+
33
+ Vedeu.stubs(:trigger)
34
+ end
35
+
36
+ subject { described.by_name(_name) }
37
+
38
+ it 'renders the cursor in the terminal' do
39
+ Vedeu::Terminal.expects(:output).with("\e[1;1H\e[?25l")
40
+ subject
41
+ end
42
+
43
+ context 'when the cursors offset position is outside the viewable area' do
44
+ let(:ox) { 3 }
45
+ let(:oy) { 3 }
46
+
47
+ it 'refreshes the view' do
48
+ Vedeu.expects(:trigger).with(:_refresh_, _name)
49
+ subject
50
+ end
51
+ end
52
+
53
+ context 'when the cursors offset position is inside the viewable area' do
54
+ it 'does not refresh the view' do
55
+ Vedeu.expects(:trigger).with(:_refresh_, _name).never
56
+ subject
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '#by_name' do
62
+ it { instance.must_respond_to(:by_name) }
63
+ end
64
+
65
+ end # Refresh
66
+
67
+ end # Cursors
68
+
69
+ end # Vedeu