vedeu 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/examples/borders_app.rb +15 -14
  3. data/examples/colours_app.rb +1 -2
  4. data/examples/cursor_app.rb +2 -5
  5. data/examples/geometry_app.rb +141 -0
  6. data/lib/vedeu.rb +0 -17
  7. data/lib/vedeu/api.rb +18 -3
  8. data/lib/vedeu/buffers/all.rb +0 -6
  9. data/lib/vedeu/buffers/buffer.rb +5 -2
  10. data/lib/vedeu/cursor/all.rb +0 -13
  11. data/lib/vedeu/cursor/cursor.rb +1 -1
  12. data/lib/vedeu/dsl/components/border.rb +94 -12
  13. data/lib/vedeu/dsl/components/geometry.rb +40 -48
  14. data/lib/vedeu/dsl/components/keymap.rb +36 -0
  15. data/lib/vedeu/dsl/interface.rb +20 -5
  16. data/lib/vedeu/dsl/stream.rb +2 -0
  17. data/lib/vedeu/events/all.rb +0 -5
  18. data/lib/vedeu/events/event.rb +2 -1
  19. data/lib/vedeu/events/trigger.rb +1 -3
  20. data/lib/vedeu/input/all.rb +7 -12
  21. data/lib/vedeu/input/keymap.rb +10 -34
  22. data/lib/vedeu/input/keys.rb +1 -0
  23. data/lib/vedeu/input/mapper.rb +1 -5
  24. data/lib/vedeu/models/collection.rb +4 -0
  25. data/lib/vedeu/models/geometry.rb +2 -1
  26. data/lib/vedeu/models/model.rb +4 -0
  27. data/lib/vedeu/models/view/char.rb +10 -0
  28. data/lib/vedeu/models/view/chars.rb +3 -2
  29. data/lib/vedeu/models/view/interface.rb +18 -28
  30. data/lib/vedeu/models/view/interfaces.rb +3 -2
  31. data/lib/vedeu/models/view/lines.rb +3 -2
  32. data/lib/vedeu/models/view/stream.rb +1 -1
  33. data/lib/vedeu/models/view/streams.rb +3 -2
  34. data/lib/vedeu/output/border.rb +29 -21
  35. data/lib/vedeu/output/compositor.rb +2 -3
  36. data/lib/vedeu/output/output.rb +5 -1
  37. data/lib/vedeu/output/viewport.rb +45 -24
  38. data/lib/vedeu/output/wordwrap.rb +7 -1
  39. data/lib/vedeu/output/writer.rb +3 -0
  40. data/lib/vedeu/presentation/presentation.rb +2 -0
  41. data/lib/vedeu/repositories/all.rb +107 -1
  42. data/lib/vedeu/repositories/repository.rb +4 -0
  43. data/lib/vedeu/support/bounding_area.rb +1 -1
  44. data/lib/vedeu/support/position_validator.rb +18 -0
  45. data/test/lib/vedeu/buffers/buffer_test.rb +8 -8
  46. data/test/lib/vedeu/cursor/move_cursor_test.rb +3 -6
  47. data/test/lib/vedeu/dsl/components/border_test.rb +53 -4
  48. data/test/lib/vedeu/dsl/components/geometry_test.rb +0 -24
  49. data/test/lib/vedeu/dsl/interface_test.rb +11 -3
  50. data/test/lib/vedeu/events/event_test.rb +2 -2
  51. data/test/lib/vedeu/models/view/interface_test.rb +1 -25
  52. data/test/lib/vedeu/models/view/stream_test.rb +8 -0
  53. data/test/lib/vedeu/output/border_test.rb +159 -81
  54. data/test/lib/vedeu/output/output_test.rb +1 -2
  55. data/test/lib/vedeu/output/viewport_test.rb +3 -10
  56. data/test/lib/vedeu/repositories/all_test.rb +128 -0
  57. data/test/lib/vedeu/support/content_geometry_test.rb +1 -2
  58. data/vedeu.gemspec +1 -1
  59. metadata +3 -13
  60. data/lib/vedeu/repositories/menus.rb +0 -13
  61. data/test/lib/vedeu/buffers/all_test.rb +0 -11
  62. data/test/lib/vedeu/cursor/all_test.rb +0 -33
  63. data/test/lib/vedeu/events/all_test.rb +0 -11
  64. data/test/lib/vedeu/input/all_test.rb +0 -11
  65. data/test/lib/vedeu/repositories/menus_test.rb +0 -15
@@ -74,30 +74,6 @@ module Vedeu
74
74
  end
75
75
  end
76
76
 
77
- describe '#name' do
78
- subject { Vedeu::Geometry.build({}) { name 'chlorine' } }
79
-
80
- it 'sets the attribute to the value' do
81
- subject.name.must_equal('chlorine')
82
- end
83
-
84
- context 'DSL #name' do
85
- subject {
86
- Vedeu.interface 'geometry' do
87
- geometry do
88
- name 'other_name'
89
- end
90
- end
91
- }
92
-
93
- it { subject.must_be_instance_of(Vedeu::Interface) }
94
-
95
- it 'allows the use of name within geometry' do
96
- subject.geometry.name.must_equal('other_name')
97
- end
98
- end
99
- end
100
-
101
77
  describe '#width' do
102
78
  subject { Vedeu::Geometry.build({}) { width 25 } }
103
79
 
@@ -9,8 +9,8 @@ module Vedeu
9
9
  let(:described) { Vedeu::DSL::Interface }
10
10
  let(:instance) { described.new(model) }
11
11
  let(:model) {
12
- Vedeu::Interface.build do
13
- name 'actinium'
12
+ Vedeu.interface 'actinium' do
13
+ # ...
14
14
  end
15
15
  }
16
16
  let(:client) {}
@@ -301,9 +301,17 @@ module Vedeu
301
301
  end
302
302
 
303
303
  describe '#group' do
304
- subject { instance.group('elements') }
304
+ let(:value) { 'elements' }
305
+
306
+ subject { instance.group(value) }
305
307
 
306
308
  it { subject.must_be_instance_of(String) }
309
+
310
+ context 'when the value is empty or nil' do
311
+ let(:value) { '' }
312
+
313
+ it { subject.must_equal(false) }
314
+ end
307
315
  end
308
316
 
309
317
  describe '#keys' do
@@ -45,11 +45,11 @@ module Vedeu
45
45
 
46
46
  describe '#trigger' do
47
47
  it 'returns the result of calling the closure when debouncing' do
48
- event = Event.new(event_name, { debounce: 0.0025 }, closure)
48
+ event = Event.new(event_name, { debounce: 0.002 }, closure)
49
49
  event.trigger.must_equal(nil)
50
50
  sleep 0.001
51
51
  event.trigger.must_equal(nil)
52
- sleep 0.001
52
+ sleep 0.0015
53
53
  event.trigger.must_equal(:event_triggered)
54
54
  sleep 0.001
55
55
  event.trigger.must_equal(nil)
@@ -31,7 +31,7 @@ module Vedeu
31
31
  subject { instance.border? }
32
32
 
33
33
  context 'when the interface has a border' do
34
- before { instance.stubs(:border).returns(mock('Border')) }
34
+ before { Vedeu.borders.stubs(:registered?).with(_name).returns(true) }
35
35
 
36
36
  it { subject.must_equal(true) }
37
37
  end
@@ -61,23 +61,6 @@ module Vedeu
61
61
  it { subject.must_be_instance_of(Vedeu::Cursor) }
62
62
  end
63
63
 
64
- # TODO: when the interface does not have any geometry defined?
65
- # describe '#render' do
66
- # subject { instance.render }
67
-
68
- # context 'when the interface has a border' do
69
- # let(:border) { Vedeu::Border.new(instance, { enabled: true }) }
70
-
71
- # before { instance.stubs(:border).returns(border) }
72
-
73
- # it { skip }
74
- # end
75
-
76
- # context 'when the interface does not have a border' do
77
- # it { skip }
78
- # end
79
- # end
80
-
81
64
  describe '#inspect' do
82
65
  subject { instance.inspect }
83
66
 
@@ -116,13 +99,6 @@ module Vedeu
116
99
  # end
117
100
  end
118
101
 
119
- # TODO: when the interface does not have any geometry defined?
120
- describe '#viewport' do
121
- subject { instance.viewport }
122
-
123
- # it { skip }
124
- end
125
-
126
102
  end # Interface
127
103
 
128
104
  end # Vedeu
@@ -29,6 +29,14 @@ module Vedeu
29
29
  it { subject.instance_variable_get('@style').must_equal(style) }
30
30
  end
31
31
 
32
+ describe '#add' do
33
+ let(:child) { instance }
34
+
35
+ subject { instance.add(child) }
36
+
37
+ it { subject.must_be_instance_of(Vedeu::Streams) }
38
+ end
39
+
32
40
  describe '#chars' do
33
41
  subject { instance.chars }
34
42
 
@@ -5,28 +5,29 @@ module Vedeu
5
5
  describe Border do
6
6
 
7
7
  let(:described) { Vedeu::Border }
8
- let(:instance) { described.new(interface, attributes) }
9
- # let(:interface) { Interface.new({ name: 'caesium' }) }
10
- let(:interface) {
11
- Vedeu::Interface.build do
8
+ let(:instance) { described.new(attributes) }
9
+ let(:attributes) {
10
+ {
11
+ name: 'borders'
12
+ }
13
+ }
14
+
15
+ before do
16
+ Vedeu.interfaces.reset
17
+ Vedeu.interface 'borders' do
12
18
  geometry do
13
19
  height 5
14
20
  width 8
15
21
  end
16
- name 'caesium'
22
+ lines do
23
+ line 'Beryllium'
24
+ line 'Magnesium'
25
+ line 'Plutonium'
26
+ line 'Potassium'
27
+ line 'Lanthanum'
28
+ line 'Stront­ium'
29
+ end
17
30
  end
18
- }
19
- let(:attributes) { {} }
20
-
21
- before do
22
- interface.lines = [
23
- Line.new([Stream.new('Beryllium')]),
24
- Line.new([Stream.new('Magnesium')]),
25
- Line.new([Stream.new('Plutonium')]),
26
- Line.new([Stream.new('Potassium')]),
27
- Line.new([Stream.new('Lanthanum')]),
28
- Line.new([Stream.new('Stront­ium')])
29
- ]
30
31
  end
31
32
 
32
33
  describe '.build' do
@@ -42,26 +43,29 @@ module Vedeu
42
43
  describe '#initialize' do
43
44
  subject { instance }
44
45
 
45
- it { subject.must_be_instance_of(Border) }
46
- it { subject.instance_variable_get('@interface').must_equal(interface) }
46
+ it { subject.must_be_instance_of(described) }
47
47
  it { subject.instance_variable_get('@attributes').must_equal(
48
48
  {
49
+ bottom_left: 'm',
50
+ bottom_right: 'j',
51
+ colour: {},
49
52
  enabled: false,
53
+ horizontal: 'q',
54
+ name: 'borders',
50
55
  show_bottom: true,
51
56
  show_left: true,
52
57
  show_right: true,
53
58
  show_top: true,
54
- bottom_right: 'j',
55
- top_right: 'k',
56
- top_left: 'l',
57
- bottom_left: 'm',
58
- horizontal: 'q',
59
- colour: {},
60
59
  style: [],
60
+ top_left: 'l',
61
+ top_right: 'k',
61
62
  vertical: 'x',
62
- interface: nil,
63
63
  })
64
64
  }
65
+ it { subject.instance_variable_get('@colour').must_be_instance_of(Vedeu::Colour) }
66
+ it { subject.instance_variable_get('@name').must_equal('borders') }
67
+ it { subject.instance_variable_get('@repository').must_be_instance_of(Vedeu::Borders) }
68
+ it { subject.instance_variable_get('@style').must_be_instance_of(Vedeu::Style) }
65
69
  end
66
70
 
67
71
  describe '#width' do
@@ -75,19 +79,37 @@ module Vedeu
75
79
 
76
80
  context 'when the border is enabled' do
77
81
  context 'when both left and right borders are shown' do
78
- let(:attributes) { { enabled: true } }
82
+ let(:attributes) {
83
+ {
84
+ enabled: true,
85
+ name: 'borders',
86
+ }
87
+ }
79
88
 
80
89
  it { subject.must_equal(6) }
81
90
  end
82
91
 
83
92
  context 'when either the left or right border is shown' do
84
- let(:attributes) { { enabled: true, show_left: false } }
93
+ let(:attributes) {
94
+ {
95
+ enabled: true,
96
+ name: 'borders',
97
+ show_left: false
98
+ }
99
+ }
85
100
 
86
101
  it { subject.must_equal(7) }
87
102
  end
88
103
 
89
104
  context 'when neither left nor right borders are shown' do
90
- let(:attributes) { { enabled: true, show_left: false, show_right: false } }
105
+ let(:attributes) {
106
+ {
107
+ enabled: true,
108
+ name: 'borders',
109
+ show_left: false,
110
+ show_right: false
111
+ }
112
+ }
91
113
 
92
114
  it { subject.must_equal(8) }
93
115
  end
@@ -105,19 +127,37 @@ module Vedeu
105
127
 
106
128
  context 'when the border is enabled' do
107
129
  context 'when both top and bottom borders are shown' do
108
- let(:attributes) { { enabled: true } }
130
+ let(:attributes) {
131
+ {
132
+ enabled: true,
133
+ name: 'borders',
134
+ }
135
+ }
109
136
 
110
137
  it { subject.must_equal(3) }
111
138
  end
112
139
 
113
140
  context 'when either the top or bottom border is shown' do
114
- let(:attributes) { { enabled: true, show_top: false } }
141
+ let(:attributes) {
142
+ {
143
+ enabled: true,
144
+ name: 'borders',
145
+ show_top: false
146
+ }
147
+ }
115
148
 
116
149
  it { subject.must_equal(4) }
117
150
  end
118
151
 
119
152
  context 'when neither top nor bottom borders are shown' do
120
- let(:attributes) { { enabled: true, show_top: false, show_bottom: false } }
153
+ let(:attributes) {
154
+ {
155
+ enabled: true,
156
+ name: 'borders',
157
+ show_top: false,
158
+ show_bottom: false
159
+ }
160
+ }
121
161
 
122
162
  it { subject.must_equal(5) }
123
163
  end
@@ -146,7 +186,12 @@ module Vedeu
146
186
  it { subject.must_be_instance_of(FalseClass) }
147
187
 
148
188
  context 'when true' do
149
- let(:attributes) { { enabled: true } }
189
+ let(:attributes) {
190
+ {
191
+ enabled: true,
192
+ name: 'borders',
193
+ }
194
+ }
150
195
 
151
196
  it { subject.must_be_instance_of(TrueClass) }
152
197
  end
@@ -158,7 +203,13 @@ module Vedeu
158
203
  it { subject.must_be_instance_of(TrueClass) }
159
204
 
160
205
  context 'when false' do
161
- let(:attributes) { { show_bottom: false } }
206
+ let(:attributes) {
207
+ {
208
+ enabled: true,
209
+ name: 'borders',
210
+ show_bottom: false,
211
+ }
212
+ }
162
213
 
163
214
  it { subject.must_be_instance_of(FalseClass) }
164
215
  end
@@ -170,7 +221,13 @@ module Vedeu
170
221
  it { subject.must_be_instance_of(TrueClass) }
171
222
 
172
223
  context 'when false' do
173
- let(:attributes) { { show_left: false } }
224
+ let(:attributes) {
225
+ {
226
+ enabled: true,
227
+ name: 'borders',
228
+ show_left: false,
229
+ }
230
+ }
174
231
 
175
232
  it { subject.must_be_instance_of(FalseClass) }
176
233
  end
@@ -182,7 +239,13 @@ module Vedeu
182
239
  it { subject.must_be_instance_of(TrueClass) }
183
240
 
184
241
  context 'when false' do
185
- let(:attributes) { { show_right: false } }
242
+ let(:attributes) {
243
+ {
244
+ enabled: true,
245
+ name: 'borders',
246
+ show_right: false,
247
+ }
248
+ }
186
249
 
187
250
  it { subject.must_be_instance_of(FalseClass) }
188
251
  end
@@ -194,7 +257,13 @@ module Vedeu
194
257
  it { subject.must_be_instance_of(TrueClass) }
195
258
 
196
259
  context 'when false' do
197
- let(:attributes) { { show_top: false } }
260
+ let(:attributes) {
261
+ {
262
+ enabled: true,
263
+ name: 'borders',
264
+ show_top: false,
265
+ }
266
+ }
198
267
 
199
268
  it { subject.must_be_instance_of(FalseClass) }
200
269
  end
@@ -204,9 +273,11 @@ module Vedeu
204
273
  subject { instance.to_s }
205
274
 
206
275
  context 'when all borders should be shown' do
207
- let(:attributes) {
208
- { enabled: true }
209
- }
276
+ before do
277
+ Vedeu.border 'borders' do
278
+ # ...
279
+ end
280
+ end
210
281
 
211
282
  it 'returns the escape sequences to draw a border' do
212
283
  subject.must_equal(
@@ -220,13 +291,14 @@ module Vedeu
220
291
  end
221
292
 
222
293
  context 'when no borders are shown' do
223
- let(:attributes) {
224
- { enabled: true,
225
- show_bottom: false,
226
- show_left: false,
227
- show_right: false,
228
- show_top: false }
229
- }
294
+ before do
295
+ Vedeu.border 'borders' do
296
+ show_bottom false
297
+ show_left false
298
+ show_right false
299
+ show_top false
300
+ end
301
+ end
230
302
 
231
303
  it 'returns the escape sequences to draw a border' do
232
304
  subject.must_equal(
@@ -240,11 +312,12 @@ module Vedeu
240
312
  end
241
313
 
242
314
  context 'when the left and right border is not shown' do
243
- let(:attributes) {
244
- { enabled: true,
245
- show_left: false,
246
- show_right: false }
247
- }
315
+ before do
316
+ Vedeu.border 'borders' do
317
+ show_left false
318
+ show_right false
319
+ end
320
+ end
248
321
 
249
322
  it 'returns the escape sequences to draw a border' do
250
323
  subject.must_equal(
@@ -258,11 +331,12 @@ module Vedeu
258
331
  end
259
332
 
260
333
  context 'when the top and bottom border is not shown' do
261
- let(:attributes) {
262
- { enabled: true,
263
- show_bottom: false,
264
- show_top: false }
265
- }
334
+ before do
335
+ Vedeu.border 'borders' do
336
+ show_bottom false
337
+ show_top false
338
+ end
339
+ end
266
340
 
267
341
  it 'returns the escape sequences to draw a border' do
268
342
  subject.must_equal(
@@ -276,12 +350,13 @@ module Vedeu
276
350
  end
277
351
 
278
352
  context 'when the left border is shown, all others not shown' do
279
- let(:attributes) {
280
- { enabled: true,
281
- show_bottom: false,
282
- show_right: false,
283
- show_top: false }
284
- }
353
+ before do
354
+ Vedeu.border 'borders' do
355
+ show_bottom false
356
+ show_right false
357
+ show_top false
358
+ end
359
+ end
285
360
 
286
361
  it 'returns the escape sequences to draw a border' do
287
362
  subject.must_equal(
@@ -295,12 +370,13 @@ module Vedeu
295
370
  end
296
371
 
297
372
  context 'when the right border is shown, all others not shown' do
298
- let(:attributes) {
299
- { enabled: true,
300
- show_bottom: false,
301
- show_left: false,
302
- show_top: false }
303
- }
373
+ before do
374
+ Vedeu.border 'borders' do
375
+ show_bottom false
376
+ show_left false
377
+ show_top false
378
+ end
379
+ end
304
380
 
305
381
  it 'returns the escape sequences to draw a border' do
306
382
  subject.must_equal(
@@ -314,12 +390,13 @@ module Vedeu
314
390
  end
315
391
 
316
392
  context 'when the top border is shown, all others not shown' do
317
- let(:attributes) {
318
- { enabled: true,
319
- show_bottom: false,
320
- show_left: false,
321
- show_right: false }
322
- }
393
+ before do
394
+ Vedeu.border 'borders' do
395
+ show_bottom false
396
+ show_left false
397
+ show_right false
398
+ end
399
+ end
323
400
 
324
401
  it 'returns the escape sequences to draw a border' do
325
402
  subject.must_equal(
@@ -333,12 +410,13 @@ module Vedeu
333
410
  end
334
411
 
335
412
  context 'when the bottom border is shown, all others not shown' do
336
- let(:attributes) {
337
- { enabled: true,
338
- show_left: false,
339
- show_right: false,
340
- show_top: false }
341
- }
413
+ before do
414
+ Vedeu.border 'borders' do
415
+ show_left false
416
+ show_right false
417
+ show_top false
418
+ end
419
+ end
342
420
 
343
421
  it 'returns the escape sequences to draw a border' do
344
422
  subject.must_equal(