vedeu 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +5 -0
  3. data/README.md +34 -0
  4. data/deps.md +13 -13
  5. data/lib/vedeu.rb +1 -1
  6. data/lib/vedeu/instrumentation.rb +1 -1
  7. data/lib/vedeu/models/geometry.rb +76 -0
  8. data/lib/vedeu/models/interface.rb +9 -21
  9. data/lib/vedeu/models/stream.rb +16 -4
  10. data/lib/vedeu/output/clear_interface.rb +4 -4
  11. data/lib/vedeu/{support/translator.rb → output/colour_translator.rb} +1 -1
  12. data/lib/vedeu/output/erb_parser.rb +11 -0
  13. data/lib/vedeu/output/raw_parser.rb +9 -1
  14. data/lib/vedeu/output/render_interface.rb +3 -3
  15. data/lib/vedeu/support/esc.rb +8 -6
  16. data/lib/vedeu/support/helpers.rb +39 -18
  17. data/lib/vedeu/support/interface_template.rb +42 -19
  18. data/test/lib/vedeu/models/composition_test.rb +27 -21
  19. data/test/lib/vedeu/models/geometry_test.rb +183 -0
  20. data/test/lib/vedeu/models/interface_test.rb +26 -59
  21. data/test/lib/vedeu/models/stream_test.rb +57 -7
  22. data/test/lib/vedeu/output/clear_interface_test.rb +8 -4
  23. data/test/lib/vedeu/{support/translator_test.rb → output/colour_translator_test.rb} +8 -8
  24. data/test/lib/vedeu/output/erb_parser_test.rb +158 -70
  25. data/test/lib/vedeu/output/render_interface_test.rb +4 -3
  26. data/test/lib/vedeu/support/esc_test.rb +10 -2
  27. data/test/lib/vedeu/support/helpers_test.rb +11 -4
  28. data/test/lib/vedeu/support/interface_template_test.rb +58 -34
  29. data/test/support/colours.rb +2 -2
  30. data/test/support/erb/line.erb +4 -0
  31. data/test/support/erb/line_2x.erb +10 -0
  32. data/test/support/erb/line_foreground.erb +4 -0
  33. data/test/support/erb/line_foreground_2x.erb +5 -0
  34. data/vedeu.gemspec +2 -1
  35. metadata +30 -8
  36. data/lib/vedeu/support/geometry.rb +0 -172
  37. data/test/lib/vedeu/support/geometry_test.rb +0 -408
@@ -1,408 +0,0 @@
1
- require 'test_helper'
2
- require 'vedeu/support/geometry'
3
-
4
- module Vedeu
5
- describe Geometry do
6
- describe '#origin' do
7
- it 'returns the origin for the interface' do
8
- geometry = Geometry.new({ width: 5, height: 5, centred: false })
9
- geometry.origin.must_equal("\e[1;1H")
10
- end
11
-
12
- it 'returns the origin for the interface' do
13
- console = IO.console
14
- console.stub :winsize, [25, 80] do
15
- geometry = Geometry.new({ width: 5, height: 5 })
16
- geometry.origin.must_equal("\e[10;38H")
17
- end
18
- end
19
-
20
- it 'returns the line position relative to the origin' do
21
- geometry = Geometry.new({ width: 5, height: 5, centred: false })
22
- geometry.origin(3).must_equal("\e[4;1H")
23
- end
24
-
25
- it 'returns the origin for the interface when the interface' \
26
- ' is at a custom position' do
27
- geometry = Geometry.new({ width: 5, height: 5, x: 3, y: 6, centred: false })
28
- geometry.origin.must_equal("\e[6;3H")
29
- end
30
-
31
- it 'returns the line position relative to the origin when the' \
32
- ' interface is at a custom position' do
33
- geometry = Geometry.new({ width: 5, height: 5, x: 3, y: 6, centred: false })
34
- geometry.origin(3).must_equal("\e[9;3H")
35
- end
36
- end
37
-
38
- describe '#terminal_height' do
39
- it 'raises an exception when the value is less than 1' do
40
- geometry = Geometry.new({ height: 6, width: 18, terminal_height: -2 })
41
- proc { geometry.terminal_height }.must_raise(OutOfBoundsError)
42
- end
43
-
44
- it 'raises an exception when the value is greater than the terminal height' do
45
- console = IO.console
46
- console.stub :winsize, [25, 80] do
47
- geometry = Geometry.new({ height: 6, width: 18, terminal_height: 30 })
48
- proc { geometry.terminal_height }.must_raise(OutOfBoundsError)
49
- end
50
- end
51
-
52
- it 'returns the value of terminal_height' do
53
- console = IO.console
54
- console.stub :winsize, [25, 80] do
55
- geometry = Geometry.new({ height: 6, width: 18, terminal_height: 20 })
56
- geometry.terminal_height.must_equal(20)
57
- end
58
- end
59
-
60
- it 'returns the default height when not set' do
61
- console = IO.console
62
- console.stub :winsize, [25, 80] do
63
- geometry = Geometry.new({ height: 6, width: 18 })
64
- geometry.terminal_height.must_equal(25)
65
- end
66
- end
67
- end
68
-
69
- describe '#height' do
70
- it 'raises an exception when the height attribute is not set' do
71
- proc { Geometry.new({ width: 18 }).height }.must_raise(InvalidHeight)
72
- end
73
-
74
- it 'raises an exception when the value is less than 1' do
75
- geometry = Geometry.new({ height: -6, width: 18 })
76
- proc { geometry.height }.must_raise(OutOfBoundsError)
77
- end
78
-
79
- it 'raises an exception when the value is greater than the terminal height' do
80
- console = IO.console
81
- console.stub :winsize, [25, 80] do
82
- geometry = Geometry.new({ height: 30, width: 18 })
83
- proc { geometry.height }.must_raise(OutOfBoundsError)
84
- end
85
- end
86
-
87
- it 'returns the value of height' do
88
- geometry = Geometry.new({ height: 6, width: 18 })
89
- geometry.height.must_equal(6)
90
- end
91
- end
92
-
93
- describe '#y' do
94
- it 'raises an exception when the value is less than 1' do
95
- geometry = Geometry.new({ height: 6, width: 18, y: -2 })
96
- proc { geometry.y }.must_raise(OutOfBoundsError)
97
- end
98
-
99
- it 'raises an exception when the value is greater than the terminal height' do
100
- console = IO.console
101
- console.stub :winsize, [25, 80] do
102
- geometry = Geometry.new({ height: 6, width: 18, y: 30 })
103
- proc { geometry.y }.must_raise(OutOfBoundsError)
104
- end
105
- end
106
-
107
- it 'returns the value of y' do
108
- geometry = Geometry.new({ height: 6, width: 18, y: 6 })
109
- geometry.y.must_equal(6)
110
- end
111
-
112
- it 'returns 1 when not set' do
113
- geometry = Geometry.new({ height: 6, width: 18 })
114
- geometry.y.must_equal(1)
115
- end
116
- end
117
-
118
- describe '#terminal_width' do
119
- it 'raises an exception when the value is less than 1' do
120
- geometry = Geometry.new({ height: 6, width: 18, terminal_width: -2 })
121
- proc { geometry.terminal_width }.must_raise(OutOfBoundsError)
122
- end
123
-
124
- it 'raises an exception when the value is greater than the terminal width' do
125
- console = IO.console
126
- console.stub :winsize, [25, 80] do
127
- geometry = Geometry.new({ height: 6, width: 18, terminal_width: 85 })
128
- proc { geometry.terminal_width }.must_raise(OutOfBoundsError)
129
- end
130
- end
131
-
132
- it 'returns the value of terminal_width' do
133
- console = IO.console
134
- console.stub :winsize, [25, 80] do
135
- geometry = Geometry.new({ height: 6, width: 18, terminal_width: 40 })
136
- geometry.terminal_width.must_equal(40)
137
- end
138
- end
139
-
140
- it 'returns the default width when not set' do
141
- console = IO.console
142
- console.stub :winsize, [25, 80] do
143
- geometry = Geometry.new({ height: 6, width: 18 })
144
- geometry.terminal_width.must_equal(80)
145
- end
146
- end
147
- end
148
-
149
- describe '#width' do
150
- it 'raises an exception when the width attribute is not set' do
151
- proc { Geometry.new({ height: 6 }).width }.must_raise(InvalidWidth)
152
- end
153
-
154
- it 'raises an exception when the value is less than 1' do
155
- geometry = Geometry.new({ height: 6, width: -18 })
156
- proc { geometry.width }.must_raise(OutOfBoundsError)
157
- end
158
-
159
- it 'raises an exception when the value is greater than the terminal width' do
160
- console = IO.console
161
- console.stub :winsize, [25, 80] do
162
- geometry = Geometry.new({ height: 6, width: 85 })
163
- proc { geometry.width }.must_raise(OutOfBoundsError)
164
- end
165
- end
166
-
167
- it 'returns the value of width' do
168
- geometry = Geometry.new({ height: 6, width: 18, x: 6 })
169
- geometry.width.must_equal(18)
170
- end
171
- end
172
-
173
- describe '#x' do
174
- it 'raises an exception when the value is less than 1' do
175
- geometry = Geometry.new({ height: 6, width: 18, x: -2 })
176
- proc { geometry.x }.must_raise(OutOfBoundsError)
177
- end
178
-
179
- it 'raises an exception when the value is greater than the terminal width' do
180
- console = IO.console
181
- console.stub :winsize, [25, 80] do
182
- geometry = Geometry.new({ height: 6, width: 18, x: 85 })
183
- proc { geometry.x }.must_raise(OutOfBoundsError)
184
- end
185
- end
186
-
187
- it 'returns the value of x' do
188
- geometry = Geometry.new({ height: 6, width: 18, x: 6 })
189
- geometry.x.must_equal(6)
190
- end
191
-
192
- it 'returns 1 when not set' do
193
- geometry = Geometry.new({ height: 6, width: 18 })
194
- geometry.x.must_equal(1)
195
- end
196
- end
197
-
198
- describe '#centered' do
199
- it 'has a centred attribute' do
200
- geometry = Geometry.new({ height: 6, width: 18, centred: false })
201
- geometry.centred.must_equal(false)
202
- end
203
-
204
- it 'sets the centred attribute to true when not set' do
205
- geometry = Geometry.new({ height: 6, width: 18 })
206
- geometry.centred.must_equal(true)
207
- end
208
- end
209
-
210
- describe '#centre' do
211
- it 'returns a tuple containing the default centre coordinates' do
212
- console = IO.console
213
- console.stub :winsize, [25, 80] do
214
- geometry = Geometry.new({ height: 6, width: 18 })
215
- geometry.centre.must_equal([12, 40])
216
- end
217
- end
218
-
219
- it 'returns a tuple containing the centre coordinates' do
220
- geometry = Geometry.new({ height: 6, width: 18, terminal_height: 12, terminal_width: 40 })
221
- geometry.centre.must_equal([6, 20])
222
- end
223
-
224
- it 'returns a tuple containing the centre coordinates when an' \
225
- ' alternative terminal height is set' do
226
- console = IO.console
227
- console.stub :winsize, [25, 80] do
228
- geometry = Geometry.new({ height: 6, width: 18, terminal_height: 12 })
229
- geometry.centre.must_equal([6, 40])
230
- end
231
- end
232
-
233
- it 'returns a tuple containing the centre coordinates when an' \
234
- ' alternative terminal width is set' do
235
- console = IO.console
236
- console.stub :winsize, [25, 80] do
237
- geometry = Geometry.new({ height: 6, width: 18, terminal_width: 40 })
238
- geometry.centre.must_equal([12, 20])
239
- end
240
- end
241
- end
242
-
243
- describe '#top' do
244
- it 'centred is true and terminal height is set' do
245
- geometry = Geometry.new({ height: 6, width: 18, terminal_height: 12 })
246
- geometry.top.must_equal(3)
247
- end
248
-
249
- it 'centred is true and with default terminal height' do
250
- console = IO.console
251
- console.stub :winsize, [25, 80] do
252
- geometry = Geometry.new({ height: 6, width: 18 })
253
- geometry.top.must_equal(9)
254
- end
255
- end
256
-
257
- it 'centred is false' do
258
- geometry = Geometry.new({ height: 6, width: 18, centred: false })
259
- geometry.top.must_equal(1)
260
- end
261
-
262
- it 'centred is false and y is set' do
263
- geometry = Geometry.new({ height: 6, width: 18, y: 4, centred: false })
264
- geometry.top.must_equal(4)
265
- end
266
- end
267
-
268
- describe '#left' do
269
- it 'centred is true and terminal width is set' do
270
- geometry = Geometry.new({ height: 6, width: 18, terminal_width: 40 })
271
- geometry.left.must_equal(11)
272
- end
273
-
274
- it 'centred is true and with default terminal width' do
275
- console = IO.console
276
- console.stub :winsize, [25, 80] do
277
- geometry = Geometry.new({ height: 6, width: 18 })
278
- geometry.left.must_equal(31)
279
- end
280
- end
281
-
282
- it 'centred is false' do
283
- geometry = Geometry.new({ height: 6, width: 18, centred: false })
284
- geometry.left.must_equal(1)
285
- end
286
-
287
- it 'centred is false and x is set' do
288
- geometry = Geometry.new({ height: 6, width: 18, x: 5, centred: false })
289
- geometry.left.must_equal(5)
290
- end
291
- end
292
-
293
- describe '#bottom' do
294
- it 'centred is true and terminal height is set' do
295
- geometry = Geometry.new({ height: 6, width: 18, terminal_height: 12 })
296
- geometry.bottom.must_equal(9)
297
- end
298
-
299
- it 'centred is true and with default terminal height' do
300
- console = IO.console
301
- console.stub :winsize, [25, 80] do
302
- geometry = Geometry.new({ height: 6, width: 18 })
303
- geometry.bottom.must_equal(15)
304
- end
305
- end
306
-
307
- it 'centred is false' do
308
- geometry = Geometry.new({ height: 6, width: 18, centred: false })
309
- geometry.bottom.must_equal(7)
310
- end
311
-
312
- it 'centred is false and y is set' do
313
- geometry = Geometry.new({ height: 6, width: 18, y: 5, centred: false })
314
- geometry.bottom.must_equal(11)
315
- end
316
- end
317
-
318
- describe '#right' do
319
- it 'centred is true and terminal width is set' do
320
- geometry = Geometry.new({ height: 6, width: 18, terminal_width: 40 })
321
- geometry.right.must_equal(29)
322
- end
323
-
324
- it 'centred is true and with default terminal width' do
325
- console = IO.console
326
- console.stub :winsize, [25, 80] do
327
- geometry = Geometry.new({ height: 6, width: 18 })
328
- geometry.right.must_equal(49)
329
- end
330
- end
331
-
332
- it 'centred is false' do
333
- geometry = Geometry.new({ height: 6, width: 18, centred: false })
334
- geometry.right.must_equal(19)
335
- end
336
-
337
- it 'centred is false and x is set' do
338
- geometry = Geometry.new({ height: 6, width: 18, x: 5, centred: false })
339
- geometry.right.must_equal(23)
340
- end
341
- end
342
-
343
- describe '#position' do
344
- it 'centred is true' do
345
- console = IO.console
346
- console.stub :winsize, [25, 80] do
347
- geometry = Geometry.new({ height: 6, width: 18 })
348
- geometry.position.must_equal({
349
- y: 9,
350
- x: 31,
351
- height: 6,
352
- width: 18,
353
- centred: true,
354
- top: 9,
355
- bottom: 15,
356
- left: 31,
357
- right: 49,
358
- })
359
- end
360
- end
361
-
362
- it 'centred is false and x is set' do
363
- geometry = Geometry.new({ height: 6, width: 18, x: 7, centred: false })
364
- geometry.position.must_equal({
365
- y: 1,
366
- x: 7,
367
- height: 6,
368
- width: 18,
369
- centred: false,
370
- top: 1,
371
- bottom: 7,
372
- left: 7,
373
- right: 25,
374
- })
375
- end
376
-
377
- it 'centred is false and y is set' do
378
- geometry = Geometry.new({ height: 6, width: 18, y: 5, centred: false })
379
- geometry.position.must_equal({
380
- y: 5,
381
- x: 1,
382
- height: 6,
383
- width: 18,
384
- centred: false,
385
- top: 5,
386
- bottom: 11,
387
- left: 1,
388
- right: 19,
389
- })
390
- end
391
-
392
- it 'centred is false' do
393
- geometry = Geometry.new({ height: 6, width: 18, centred: false })
394
- geometry.position.must_equal({
395
- y: 1,
396
- x: 1,
397
- height: 6,
398
- width: 18,
399
- centred: false,
400
- top: 1,
401
- bottom: 7,
402
- left: 1,
403
- right: 19,
404
- })
405
- end
406
- end
407
- end
408
- end