vedeu 0.1.12 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/vedeu.rb +12 -12
- data/lib/vedeu/api/api.rb +23 -18
- data/lib/vedeu/api/events.rb +1 -1
- data/lib/vedeu/api/interface.rb +29 -19
- data/lib/vedeu/api/line.rb +1 -34
- data/lib/vedeu/api/stream.rb +1 -34
- data/lib/vedeu/models/attributes/attributes.rb +7 -7
- data/lib/vedeu/models/attributes/colour_translator.rb +45 -7
- data/lib/vedeu/models/colour.rb +4 -2
- data/lib/vedeu/models/composition.rb +9 -9
- data/lib/vedeu/models/interface.rb +1 -1
- data/lib/vedeu/models/line.rb +17 -3
- data/lib/vedeu/{api → models}/store.rb +0 -2
- data/lib/vedeu/models/stream.rb +17 -3
- data/lib/vedeu/output/buffers.rb +14 -8
- data/lib/vedeu/output/view.rb +7 -3
- data/lib/vedeu/support/esc.rb +1 -14
- data/lib/vedeu/support/position.rb +31 -0
- data/lib/vedeu/support/terminal.rb +4 -0
- data/test/lib/vedeu/api/api_test.rb +21 -0
- data/test/lib/vedeu/api/interface_test.rb +765 -51
- data/test/lib/vedeu/configuration_test.rb +5 -0
- data/test/lib/vedeu/models/composition_test.rb +1 -1
- data/test/lib/vedeu/models/interface_test.rb +59 -17
- data/test/lib/vedeu/{api → models}/store_test.rb +12 -3
- data/test/lib/vedeu/output/clear_test.rb +1 -1
- data/test/lib/vedeu/output/render_test.rb +1 -1
- data/test/lib/vedeu/output/view_test.rb +17 -0
- data/test/lib/vedeu/support/esc_test.rb +0 -10
- data/test/lib/vedeu/support/position_test.rb +19 -0
- data/test/support/colour_test.sh +100 -0
- data/test/{stats.sh → support/stats.sh} +0 -0
- data/vedeu.gemspec +1 -1
- metadata +16 -10
- data/lib/vedeu/api/view.rb +0 -45
- data/test/lib/vedeu/api/view_test.rb +0 -565
data/lib/vedeu/api/view.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
module Vedeu
|
2
|
-
module API
|
3
|
-
InterfaceNotSpecified = Class.new(StandardError)
|
4
|
-
|
5
|
-
class View
|
6
|
-
def self.build(name, &block)
|
7
|
-
new(name).build(&block)
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(name)
|
11
|
-
fail InterfaceNotSpecified if name.nil? || name.empty?
|
12
|
-
|
13
|
-
@name = name.to_s
|
14
|
-
end
|
15
|
-
|
16
|
-
def build(&block)
|
17
|
-
if block_given?
|
18
|
-
@self_before_instance_eval = eval('self', block.binding)
|
19
|
-
|
20
|
-
instance_eval(&block)
|
21
|
-
end
|
22
|
-
|
23
|
-
attributes
|
24
|
-
end
|
25
|
-
|
26
|
-
def line(&block)
|
27
|
-
attributes[:lines] << Line.build(&block)
|
28
|
-
end
|
29
|
-
|
30
|
-
def attributes
|
31
|
-
@_attributes ||= { name: name, lines: [] }
|
32
|
-
end
|
33
|
-
|
34
|
-
def name
|
35
|
-
return @name if Store.query(@name)
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def method_missing(method, *args, &block)
|
41
|
-
@self_before_instance_eval.send method, *args, &block
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,565 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Vedeu
|
4
|
-
module API
|
5
|
-
describe View do
|
6
|
-
before do
|
7
|
-
Store.reset
|
8
|
-
Interface.create('testing_view') do
|
9
|
-
x 1
|
10
|
-
y 1
|
11
|
-
colour foreground: '#ffffff', background: '#000000'
|
12
|
-
centred false
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'builds a basic view' do
|
17
|
-
Vedeu.view 'testing_view' do
|
18
|
-
line do
|
19
|
-
text '1. A line of text.'
|
20
|
-
text '2. Another line of text.'
|
21
|
-
end
|
22
|
-
end.must_equal(
|
23
|
-
{
|
24
|
-
name: 'testing_view',
|
25
|
-
lines: [
|
26
|
-
{
|
27
|
-
colour: {},
|
28
|
-
style: [],
|
29
|
-
streams: [
|
30
|
-
{
|
31
|
-
text: '1. A line of text.',
|
32
|
-
}, {
|
33
|
-
text: '2. Another line of text.',
|
34
|
-
}
|
35
|
-
]
|
36
|
-
}
|
37
|
-
]
|
38
|
-
}
|
39
|
-
)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'handles coloured lines' do
|
43
|
-
Vedeu.view 'testing_view' do
|
44
|
-
line do
|
45
|
-
text '1. Line without colours.'
|
46
|
-
end
|
47
|
-
end.must_equal(
|
48
|
-
{
|
49
|
-
name: 'testing_view',
|
50
|
-
lines: [
|
51
|
-
{
|
52
|
-
colour: {},
|
53
|
-
style: [],
|
54
|
-
streams: [{ text: '1. Line without colours.' }]
|
55
|
-
}
|
56
|
-
]
|
57
|
-
}
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'handles coloured lines' do
|
62
|
-
Vedeu.view 'testing_view' do
|
63
|
-
line do
|
64
|
-
colour background: '#ff0000', foreground: '#ffff00'
|
65
|
-
text '2. Line with colours.'
|
66
|
-
end
|
67
|
-
end.must_equal(
|
68
|
-
{
|
69
|
-
name: 'testing_view',
|
70
|
-
lines: [
|
71
|
-
{
|
72
|
-
colour: { background: '#ff0000', foreground: '#ffff00' },
|
73
|
-
style: [],
|
74
|
-
streams: [{ text: '2. Line with colours.' }]
|
75
|
-
}
|
76
|
-
]
|
77
|
-
}
|
78
|
-
)
|
79
|
-
end
|
80
|
-
|
81
|
-
it 'handles coloured lines' do
|
82
|
-
Vedeu.view 'testing_view' do
|
83
|
-
line do
|
84
|
-
colour foreground: '#a7ff00', background: '#005700'
|
85
|
-
text '3. Line with explicit colour declaration.'
|
86
|
-
end
|
87
|
-
end.must_equal(
|
88
|
-
{
|
89
|
-
name: 'testing_view',
|
90
|
-
lines: [
|
91
|
-
{
|
92
|
-
colour: { background: '#005700', foreground: '#a7ff00' },
|
93
|
-
style: [],
|
94
|
-
streams: [{ text: '3. Line with explicit colour declaration.' }]
|
95
|
-
}
|
96
|
-
]
|
97
|
-
}
|
98
|
-
)
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'handles coloured lines' do
|
102
|
-
Vedeu.view 'testing_view' do
|
103
|
-
line do # actually uses streams
|
104
|
-
foreground '#ff00ff' do
|
105
|
-
text '4. Line with only foreground set.'
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end.must_equal(
|
109
|
-
{
|
110
|
-
name: 'testing_view',
|
111
|
-
lines: [
|
112
|
-
{
|
113
|
-
colour: {},
|
114
|
-
style: [],
|
115
|
-
streams: [{
|
116
|
-
colour: { foreground: '#ff00ff' },
|
117
|
-
style: [],
|
118
|
-
text: '4. Line with only foreground set.'
|
119
|
-
}]
|
120
|
-
}
|
121
|
-
]
|
122
|
-
}
|
123
|
-
)
|
124
|
-
end
|
125
|
-
|
126
|
-
it 'handles coloured lines' do
|
127
|
-
Vedeu.view 'testing_view' do
|
128
|
-
line do # actually uses streams
|
129
|
-
background '#00ff00' do
|
130
|
-
text '5. Line with only background set.'
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end.must_equal(
|
134
|
-
{
|
135
|
-
name: 'testing_view',
|
136
|
-
lines: [
|
137
|
-
{
|
138
|
-
colour: {},
|
139
|
-
style: [],
|
140
|
-
streams: [{
|
141
|
-
colour: { background: '#00ff00' },
|
142
|
-
style: [],
|
143
|
-
text: '5. Line with only background set.'
|
144
|
-
}]
|
145
|
-
}
|
146
|
-
]
|
147
|
-
}
|
148
|
-
)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'handles styles' do
|
152
|
-
Vedeu.view 'testing_view' do
|
153
|
-
line do
|
154
|
-
style 'normal'
|
155
|
-
text '1. Line with a normal style.'
|
156
|
-
end
|
157
|
-
end.must_equal(
|
158
|
-
{
|
159
|
-
name: 'testing_view',
|
160
|
-
lines: [
|
161
|
-
{
|
162
|
-
colour: {},
|
163
|
-
style: ['normal'],
|
164
|
-
streams: [{
|
165
|
-
text: '1. Line with a normal style.'
|
166
|
-
}]
|
167
|
-
}
|
168
|
-
]
|
169
|
-
}
|
170
|
-
)
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'handles styles' do
|
174
|
-
Vedeu.view 'testing_view' do
|
175
|
-
line do
|
176
|
-
style 'underline'
|
177
|
-
text '2. Line with an underline style.'
|
178
|
-
end
|
179
|
-
end.must_equal(
|
180
|
-
{
|
181
|
-
name: 'testing_view',
|
182
|
-
lines: [
|
183
|
-
{
|
184
|
-
colour: {},
|
185
|
-
style: ['underline'],
|
186
|
-
streams: [{
|
187
|
-
text: '2. Line with an underline style.'
|
188
|
-
}]
|
189
|
-
}
|
190
|
-
]
|
191
|
-
}
|
192
|
-
)
|
193
|
-
end
|
194
|
-
|
195
|
-
it 'handles styles' do
|
196
|
-
Vedeu.view 'testing_view' do
|
197
|
-
line do # actually uses streams
|
198
|
-
style 'normal' do
|
199
|
-
text '3. Line with a normal style.'
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end.must_equal(
|
203
|
-
{
|
204
|
-
name: 'testing_view',
|
205
|
-
lines: [
|
206
|
-
{
|
207
|
-
colour: {},
|
208
|
-
style: [],
|
209
|
-
streams: [{
|
210
|
-
colour: {},
|
211
|
-
style: ['normal'],
|
212
|
-
text: '3. Line with a normal style.'
|
213
|
-
}]
|
214
|
-
}
|
215
|
-
]
|
216
|
-
}
|
217
|
-
)
|
218
|
-
end
|
219
|
-
|
220
|
-
it 'handles styles' do
|
221
|
-
Vedeu.view 'testing_view' do
|
222
|
-
line do # actually uses streams
|
223
|
-
style 'underline' do
|
224
|
-
text '4. Line with an underlined style.'
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end.must_equal(
|
228
|
-
{
|
229
|
-
name: 'testing_view',
|
230
|
-
lines: [
|
231
|
-
{
|
232
|
-
colour: {},
|
233
|
-
style: [],
|
234
|
-
streams: [{
|
235
|
-
colour: {},
|
236
|
-
style: ['underline'],
|
237
|
-
text: '4. Line with an underlined style.'
|
238
|
-
}]
|
239
|
-
}
|
240
|
-
]
|
241
|
-
}
|
242
|
-
)
|
243
|
-
end
|
244
|
-
|
245
|
-
it 'handles streams, which means sub-line colours and styles' do
|
246
|
-
Vedeu.view 'testing_view' do
|
247
|
-
line do
|
248
|
-
stream do
|
249
|
-
text 'A stream of text.'
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end.must_equal(
|
253
|
-
{
|
254
|
-
name: 'testing_view',
|
255
|
-
lines: [
|
256
|
-
{
|
257
|
-
colour: {},
|
258
|
-
style: [],
|
259
|
-
streams: [
|
260
|
-
{
|
261
|
-
colour: {},
|
262
|
-
style: [],
|
263
|
-
text: 'A stream of text.'
|
264
|
-
}
|
265
|
-
]
|
266
|
-
}
|
267
|
-
]
|
268
|
-
}
|
269
|
-
)
|
270
|
-
end
|
271
|
-
|
272
|
-
it 'handles streams, which means sub-line colours and styles' do
|
273
|
-
Vedeu.view 'testing_view' do
|
274
|
-
line do
|
275
|
-
stream do # Stream is an 'explicit declaration'.
|
276
|
-
# We don't need it unless we want to add colours and styles.
|
277
|
-
# See below.
|
278
|
-
text '1. Two streams of text, these will be'
|
279
|
-
end
|
280
|
-
|
281
|
-
stream do
|
282
|
-
text ' on the same line- note the space.'
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end.must_equal(
|
286
|
-
{
|
287
|
-
name: 'testing_view',
|
288
|
-
lines: [
|
289
|
-
{
|
290
|
-
colour: {},
|
291
|
-
style: [],
|
292
|
-
streams: [
|
293
|
-
{
|
294
|
-
colour: {},
|
295
|
-
style: [],
|
296
|
-
text: '1. Two streams of text, these will be'
|
297
|
-
}, {
|
298
|
-
colour: {},
|
299
|
-
style: [],
|
300
|
-
text: ' on the same line- note the space.'
|
301
|
-
}
|
302
|
-
]
|
303
|
-
}
|
304
|
-
]
|
305
|
-
}
|
306
|
-
)
|
307
|
-
end
|
308
|
-
|
309
|
-
it 'handles streams, which means sub-line colours and styles' do
|
310
|
-
Vedeu.view 'testing_view' do
|
311
|
-
line do
|
312
|
-
stream do
|
313
|
-
text '2. Streams can have'
|
314
|
-
end
|
315
|
-
|
316
|
-
stream do
|
317
|
-
colour foreground: '#ff0000', background: '#00ff00'
|
318
|
-
text ' colours too.'
|
319
|
-
end
|
320
|
-
end
|
321
|
-
end.must_equal(
|
322
|
-
{
|
323
|
-
name: 'testing_view',
|
324
|
-
lines: [
|
325
|
-
{
|
326
|
-
colour: {},
|
327
|
-
style: [],
|
328
|
-
streams: [
|
329
|
-
{
|
330
|
-
colour: {},
|
331
|
-
style: [],
|
332
|
-
text: '2. Streams can have'
|
333
|
-
}, {
|
334
|
-
colour: {
|
335
|
-
foreground: '#ff0000',
|
336
|
-
background: '#00ff00'
|
337
|
-
},
|
338
|
-
style: [],
|
339
|
-
text: ' colours too.'
|
340
|
-
}
|
341
|
-
]
|
342
|
-
}
|
343
|
-
]
|
344
|
-
}
|
345
|
-
)
|
346
|
-
end
|
347
|
-
|
348
|
-
it 'handles streams, which means sub-line colours and styles' do
|
349
|
-
Vedeu.view 'testing_view' do
|
350
|
-
line do
|
351
|
-
stream do
|
352
|
-
text '3. Streams can have'
|
353
|
-
end
|
354
|
-
|
355
|
-
stream do
|
356
|
-
style 'underline'
|
357
|
-
text ' styles too.'
|
358
|
-
end
|
359
|
-
end
|
360
|
-
end.must_equal(
|
361
|
-
{
|
362
|
-
name: 'testing_view',
|
363
|
-
lines: [
|
364
|
-
{
|
365
|
-
colour: {},
|
366
|
-
style: [],
|
367
|
-
streams: [
|
368
|
-
{
|
369
|
-
colour: {},
|
370
|
-
style: [],
|
371
|
-
text: '3. Streams can have'
|
372
|
-
}, {
|
373
|
-
colour: {},
|
374
|
-
style: ['underline'],
|
375
|
-
text: ' styles too.'
|
376
|
-
}
|
377
|
-
]
|
378
|
-
}
|
379
|
-
]
|
380
|
-
}
|
381
|
-
)
|
382
|
-
end
|
383
|
-
|
384
|
-
it 'handles alignment' do
|
385
|
-
Vedeu.view 'testing_view' do
|
386
|
-
line do
|
387
|
-
stream do
|
388
|
-
width 80
|
389
|
-
text 'This is aligned left, and padded with spaces.'
|
390
|
-
end
|
391
|
-
end
|
392
|
-
end.must_equal(
|
393
|
-
{
|
394
|
-
name: 'testing_view',
|
395
|
-
lines: [{
|
396
|
-
colour: {},
|
397
|
-
style: [],
|
398
|
-
streams: [{
|
399
|
-
colour: {},
|
400
|
-
style: [],
|
401
|
-
width: 80,
|
402
|
-
text: 'This is aligned left, and padded with spaces.'
|
403
|
-
}]
|
404
|
-
}]
|
405
|
-
}
|
406
|
-
)
|
407
|
-
end
|
408
|
-
|
409
|
-
it 'handles alignment' do
|
410
|
-
Vedeu.view 'testing_view' do
|
411
|
-
line do
|
412
|
-
stream do
|
413
|
-
width 80
|
414
|
-
align :left # explicit
|
415
|
-
text 'This is aligned left, and padded with spaces.'
|
416
|
-
end
|
417
|
-
end
|
418
|
-
end.must_equal(
|
419
|
-
{
|
420
|
-
name: 'testing_view',
|
421
|
-
lines: [{
|
422
|
-
colour: {},
|
423
|
-
style: [],
|
424
|
-
streams: [{
|
425
|
-
colour: {},
|
426
|
-
style: [],
|
427
|
-
width: 80,
|
428
|
-
align: :left,
|
429
|
-
text: 'This is aligned left, and padded with spaces.'
|
430
|
-
}]
|
431
|
-
}]
|
432
|
-
}
|
433
|
-
)
|
434
|
-
end
|
435
|
-
|
436
|
-
it 'handles alignment' do
|
437
|
-
Vedeu.view 'testing_view' do
|
438
|
-
line do
|
439
|
-
stream do
|
440
|
-
width 80
|
441
|
-
align :centre
|
442
|
-
text 'This is aligned centrally, and padded with spaces.'
|
443
|
-
end
|
444
|
-
end
|
445
|
-
end.must_equal(
|
446
|
-
{
|
447
|
-
name: 'testing_view',
|
448
|
-
lines: [{
|
449
|
-
colour: {},
|
450
|
-
style: [],
|
451
|
-
streams: [{
|
452
|
-
colour: {},
|
453
|
-
style: [],
|
454
|
-
width: 80,
|
455
|
-
align: :centre,
|
456
|
-
text: 'This is aligned centrally, and padded with spaces.'
|
457
|
-
}]
|
458
|
-
}]
|
459
|
-
}
|
460
|
-
)
|
461
|
-
end
|
462
|
-
|
463
|
-
it 'handles alignment' do
|
464
|
-
Vedeu.view 'testing_view' do
|
465
|
-
line do
|
466
|
-
stream do
|
467
|
-
width 80
|
468
|
-
align :right
|
469
|
-
text 'This is aligned right, and padded with spaces.'
|
470
|
-
end
|
471
|
-
end
|
472
|
-
end.must_equal(
|
473
|
-
{
|
474
|
-
name: 'testing_view',
|
475
|
-
lines: [{
|
476
|
-
colour: {},
|
477
|
-
style: [],
|
478
|
-
streams: [{
|
479
|
-
colour: {},
|
480
|
-
style: [],
|
481
|
-
width: 80,
|
482
|
-
align: :right,
|
483
|
-
text: 'This is aligned right, and padded with spaces.'
|
484
|
-
}]
|
485
|
-
}]
|
486
|
-
}
|
487
|
-
)
|
488
|
-
end
|
489
|
-
|
490
|
-
it 'handles multiple colour and text statements correctly' do
|
491
|
-
Vedeu.view 'testing_view' do
|
492
|
-
line do
|
493
|
-
foreground('#ffff00') { text "\u{25B2}" }
|
494
|
-
text " Prev"
|
495
|
-
|
496
|
-
foreground('#ffff00') { text "\u{25BC}" }
|
497
|
-
text " Next"
|
498
|
-
|
499
|
-
foreground('#ffff00') { text "\u{21B2}" }
|
500
|
-
text " Select"
|
501
|
-
|
502
|
-
foreground('#ffff00') { text "\u{2395}" }
|
503
|
-
text " Pause"
|
504
|
-
|
505
|
-
foreground('#ffff00') { text "Q" }
|
506
|
-
text " Quit"
|
507
|
-
end
|
508
|
-
end.must_equal(
|
509
|
-
{
|
510
|
-
name: 'testing_view',
|
511
|
-
lines: [
|
512
|
-
{
|
513
|
-
colour: {},
|
514
|
-
style: [],
|
515
|
-
streams: [
|
516
|
-
{
|
517
|
-
colour: {
|
518
|
-
foreground: "#ffff00"
|
519
|
-
},
|
520
|
-
style: [],
|
521
|
-
text: "▲"
|
522
|
-
}, {
|
523
|
-
text: " Prev"
|
524
|
-
}, {
|
525
|
-
colour: {
|
526
|
-
foreground: "#ffff00"
|
527
|
-
},
|
528
|
-
style: [],
|
529
|
-
text: "▼"
|
530
|
-
}, {
|
531
|
-
text: " Next"
|
532
|
-
}, {
|
533
|
-
colour: {
|
534
|
-
foreground: "#ffff00"
|
535
|
-
},
|
536
|
-
style: [],
|
537
|
-
text: "↲"
|
538
|
-
}, {
|
539
|
-
text: " Select"
|
540
|
-
}, {
|
541
|
-
colour: {
|
542
|
-
foreground: "#ffff00"
|
543
|
-
},
|
544
|
-
style: [],
|
545
|
-
text: "⎕"
|
546
|
-
}, {
|
547
|
-
text: " Pause"
|
548
|
-
}, {
|
549
|
-
colour: {
|
550
|
-
foreground: "#ffff00"
|
551
|
-
},
|
552
|
-
style: [],
|
553
|
-
text: "Q"
|
554
|
-
}, {
|
555
|
-
text: " Quit"
|
556
|
-
}
|
557
|
-
]
|
558
|
-
}
|
559
|
-
]
|
560
|
-
}
|
561
|
-
)
|
562
|
-
end
|
563
|
-
end
|
564
|
-
end
|
565
|
-
end
|