vedeu 0.1.18 → 0.1.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +5 -0
  3. data/Dockerfile +40 -0
  4. data/README.md +7 -30
  5. data/docs/api.md +79 -0
  6. data/docs/events.md +121 -0
  7. data/lib/vedeu.rb +61 -18
  8. data/lib/vedeu/api/api.rb +73 -53
  9. data/lib/vedeu/api/composition.rb +4 -1
  10. data/lib/vedeu/api/defined.rb +35 -0
  11. data/lib/vedeu/api/helpers.rb +20 -15
  12. data/lib/vedeu/api/interface.rb +17 -12
  13. data/lib/vedeu/api/line.rb +20 -12
  14. data/lib/vedeu/api/stream.rb +3 -0
  15. data/lib/vedeu/application.rb +34 -1
  16. data/lib/vedeu/configuration.rb +15 -3
  17. data/lib/vedeu/input/input.rb +77 -0
  18. data/lib/vedeu/launcher.rb +7 -0
  19. data/lib/vedeu/models/attributes/background.rb +15 -2
  20. data/lib/vedeu/models/attributes/coercions.rb +18 -3
  21. data/lib/vedeu/models/attributes/colour_translator.rb +23 -17
  22. data/lib/vedeu/models/attributes/foreground.rb +10 -2
  23. data/lib/vedeu/models/attributes/presentation.rb +62 -0
  24. data/lib/vedeu/models/colour.rb +7 -3
  25. data/lib/vedeu/models/composition.rb +17 -19
  26. data/lib/vedeu/models/geometry.rb +13 -5
  27. data/lib/vedeu/models/interface.rb +35 -19
  28. data/lib/vedeu/models/line.rb +24 -8
  29. data/lib/vedeu/models/stream.rb +13 -7
  30. data/lib/vedeu/models/style.rb +17 -7
  31. data/lib/vedeu/{support → output}/clear.rb +14 -0
  32. data/lib/vedeu/output/compositor.rb +77 -0
  33. data/lib/vedeu/output/refresh.rb +129 -0
  34. data/lib/vedeu/{support → output}/render.rb +49 -13
  35. data/lib/vedeu/{support → output}/view.rb +15 -8
  36. data/lib/vedeu/repositories/buffers.rb +181 -0
  37. data/lib/vedeu/{support → repositories}/events.rb +16 -6
  38. data/lib/vedeu/repositories/focus.rb +109 -0
  39. data/lib/vedeu/repositories/groups.rb +76 -0
  40. data/lib/vedeu/repositories/interfaces.rb +74 -0
  41. data/lib/vedeu/support/common.rb +20 -0
  42. data/lib/vedeu/support/cursor.rb +77 -0
  43. data/lib/vedeu/support/esc.rb +181 -46
  44. data/lib/vedeu/support/event.rb +22 -4
  45. data/lib/vedeu/support/grid.rb +10 -3
  46. data/lib/vedeu/support/log.rb +14 -1
  47. data/lib/vedeu/support/menu.rb +51 -12
  48. data/lib/vedeu/support/position.rb +9 -0
  49. data/lib/vedeu/support/terminal.rb +49 -15
  50. data/lib/vedeu/support/trace.rb +11 -4
  51. data/test/integration/defining_interfaces_test.rb +27 -0
  52. data/test/integration/views/basic_view_test.rb +767 -0
  53. data/test/lib/vedeu/api/api_test.rb +32 -37
  54. data/test/lib/vedeu/api/composition_test.rb +23 -61
  55. data/test/lib/vedeu/api/defined_test.rb +49 -0
  56. data/test/lib/vedeu/api/helpers_test.rb +91 -0
  57. data/test/lib/vedeu/api/interface_test.rb +136 -688
  58. data/test/lib/vedeu/api/line_test.rb +28 -32
  59. data/test/lib/vedeu/application_test.rb +6 -0
  60. data/test/lib/vedeu/configuration_test.rb +8 -4
  61. data/test/lib/vedeu/{support → input}/input_test.rb +9 -0
  62. data/test/lib/vedeu/launcher_test.rb +6 -0
  63. data/test/lib/vedeu/models/attributes/{coercer_test.rb → coercions_test.rb} +11 -10
  64. data/test/lib/vedeu/models/attributes/colour_translator_test.rb +13 -0
  65. data/test/lib/vedeu/models/attributes/presentation_test.rb +30 -0
  66. data/test/lib/vedeu/models/colour_test.rb +8 -0
  67. data/test/lib/vedeu/models/composition_test.rb +208 -200
  68. data/test/lib/vedeu/models/geometry_test.rb +39 -0
  69. data/test/lib/vedeu/models/interface_test.rb +11 -1
  70. data/test/lib/vedeu/models/line_test.rb +8 -1
  71. data/test/lib/vedeu/models/stream_test.rb +35 -0
  72. data/test/lib/vedeu/models/style_test.rb +8 -0
  73. data/test/lib/vedeu/{support → output}/clear_test.rb +1 -1
  74. data/test/lib/vedeu/output/compositor_test.rb +64 -0
  75. data/test/lib/vedeu/output/refresh_test.rb +48 -0
  76. data/test/lib/vedeu/{support → output}/render_test.rb +36 -0
  77. data/test/lib/vedeu/{support → output}/view_test.rb +0 -0
  78. data/test/lib/vedeu/repositories/buffers_test.rb +48 -0
  79. data/test/lib/vedeu/{support → repositories}/events_test.rb +0 -0
  80. data/test/lib/vedeu/repositories/focus_test.rb +74 -0
  81. data/test/lib/vedeu/repositories/groups_test.rb +66 -0
  82. data/test/lib/vedeu/repositories/interfaces_test.rb +6 -0
  83. data/test/lib/vedeu/support/common_test.rb +6 -0
  84. data/test/lib/vedeu/support/cursor_test.rb +79 -0
  85. data/test/lib/vedeu/support/log_test.rb +6 -0
  86. data/test/lib/vedeu/support/terminal_test.rb +6 -28
  87. data/test/lib/vedeu/support/trace_test.rb +6 -0
  88. data/test/test_helper.rb +37 -0
  89. data/vedeu.gemspec +1 -1
  90. metadata +65 -33
  91. data/bin/log +0 -13
  92. data/lib/vedeu/support/buffer.rb +0 -69
  93. data/lib/vedeu/support/buffers.rb +0 -106
  94. data/lib/vedeu/support/focus.rb +0 -83
  95. data/lib/vedeu/support/groups.rb +0 -61
  96. data/lib/vedeu/support/input.rb +0 -67
  97. data/test/lib/vedeu/support/buffer_test.rb +0 -83
  98. data/test/lib/vedeu/support/buffers_test.rb +0 -15
  99. data/test/lib/vedeu/support/focus_test.rb +0 -114
  100. data/test/lib/vedeu/support/groups_test.rb +0 -65
@@ -6,6 +6,12 @@ module Vedeu
6
6
 
7
7
  before { Event.stubs(:new).returns(event) }
8
8
 
9
+ describe '.defined' do
10
+ it 'returns a reference to the API::Defined module' do
11
+ Vedeu.defined.must_equal(Vedeu::API::Defined)
12
+ end
13
+ end
14
+
9
15
  describe '.event' do
10
16
  it 'registers and returns the event' do
11
17
  Vedeu.event(:some_event).must_equal(
@@ -75,23 +81,24 @@ module Vedeu
75
81
  end
76
82
 
77
83
  describe '.use' do
78
- it 'raises an exception if the interface has not been defined' do
79
- Vedeu::Buffers.reset
84
+ before { Vedeu::Interfaces.reset }
80
85
 
81
- proc { Vedeu.use('some_interface') }.must_raise(Vedeu::EntityNotFound)
86
+ it 'raises an exception if the interface has not been defined' do
87
+ proc { Vedeu.use('unknown') }
88
+ .must_raise(Vedeu::InterfaceNotFound)
82
89
  end
83
90
 
84
91
  it 'returns' do
85
- Vedeu.interface('some_interface')
92
+ Vedeu.interface('aluminium')
86
93
 
87
- Vedeu.use('some_interface').must_be_instance_of(Vedeu::Interface)
94
+ Vedeu.use('aluminium').must_be_instance_of(Vedeu::Interface)
88
95
  end
89
96
  end
90
97
 
91
98
  describe '.view' do
92
- it 'returns the view attributes for an interface (see View)' do
93
- Vedeu.view('some_interface').must_equal(
94
- { interfaces: [{
99
+ let(:composition) {
100
+ {
101
+ interfaces: [{
95
102
  name: "some_interface",
96
103
  group: "",
97
104
  lines: [],
@@ -99,43 +106,25 @@ module Vedeu
99
106
  style: "",
100
107
  geometry: {},
101
108
  cursor: true,
102
- delay: 0.0
103
- }] }
104
- )
109
+ delay: 0.0,
110
+ parent: {}
111
+ }]
112
+ }
113
+ }
114
+
115
+ it 'returns the view attributes for an interface (see View)' do
116
+ Vedeu.view('some_interface').must_equal(composition)
105
117
  end
106
118
  end
107
119
 
108
120
  describe '.views' do
109
121
  it 'returns the view attributes for a composition (a collection of ' \
110
122
  'interfaces)' do
111
- Vedeu.views do
123
+ attrs = Vedeu.views do
112
124
  view 'osmium'
113
125
  view 'iridium'
114
- end.must_equal(
115
- {
116
- interfaces: [
117
- {
118
- name: "osmium",
119
- group: "",
120
- lines: [],
121
- colour: {},
122
- style: "",
123
- geometry: {},
124
- cursor: true,
125
- delay: 0.0
126
- }, {
127
- name: "iridium",
128
- group: "",
129
- lines: [],
130
- colour: {},
131
- style: "",
132
- geometry: {},
133
- cursor: true,
134
- delay: 0.0
135
- }
136
- ]
137
- }
138
- )
126
+ end
127
+ attrs[:interfaces].size.must_equal(2)
139
128
  end
140
129
 
141
130
  it 'raises an exception if a block was not given' do
@@ -150,5 +139,11 @@ module Vedeu
150
139
  end
151
140
  end
152
141
  end
142
+
143
+ describe '.resize' do
144
+ it 'triggers the :_clear_ and :_refresh_ events' do
145
+ skip
146
+ end
147
+ end
153
148
  end
154
149
  end
@@ -2,70 +2,32 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
  module API
5
- describe '#views' do
6
- it 'allows multiple views to be defined at once' do
7
- Vedeu.views do
8
- view 'view_1' do
9
- line do
10
- text '1. A line of text in view 1.'
11
- text '2. Another line of text in view 1.'
5
+ describe Composition do
6
+ describe '#view' do
7
+ end
8
+
9
+ describe '#views' do
10
+ it 'allows multiple views to be defined at once' do
11
+ attrs = Vedeu.views do
12
+ view 'view_1' do
13
+ line do
14
+ text '1. A line of text in view 1.'
15
+ text '2. Another line of text in view 1.'
16
+ end
12
17
  end
13
- end
14
- view 'view_2' do
15
- line do
16
- text '1. A line of text in view 2.'
17
- text '2. Another line of text in view 2.'
18
+ view 'view_2' do
19
+ line do
20
+ text '1. A line of text in view 2.'
21
+ text '2. Another line of text in view 2.'
22
+ end
18
23
  end
19
24
  end
20
- end.must_equal(
21
- {
22
- interfaces: [
23
- {
24
- name: "view_1",
25
- group: "",
26
- lines: [
27
- {
28
- colour: {},
29
- streams: [
30
- {
31
- text: "1. A line of text in view 1."
32
- }, {
33
- text: "2. Another line of text in view 1."
34
- }
35
- ],
36
- style: []
37
- }
38
- ],
39
- colour: {},
40
- style: "",
41
- geometry: {},
42
- cursor: true,
43
- delay: 0.0
44
- }, {
45
- name: "view_2",
46
- group: "",
47
- lines: [
48
- {
49
- colour: {},
50
- streams: [
51
- {
52
- text: "1. A line of text in view 2."
53
- }, {
54
- text: "2. Another line of text in view 2."
55
- }
56
- ],
57
- style: []
58
- }
59
- ],
60
- colour: {},
61
- style: "",
62
- geometry: {},
63
- cursor: true,
64
- delay: 0.0
65
- }
66
- ]
67
- }
68
- )
25
+ attrs[:interfaces].size.must_equal(2)
26
+ end
27
+
28
+ it 'raises an exception when a block is not given' do
29
+ proc { Vedeu.views }.must_raise(InvalidSyntax)
30
+ end
69
31
  end
70
32
  end
71
33
  end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+ module API
5
+ describe Defined do
6
+ describe '#events' do
7
+ before { Vedeu.events.reset }
8
+
9
+ it 'returns no events when none currently registered' do
10
+ Defined.events.must_equal([])
11
+ end
12
+
13
+ it 'returns all events currently registered' do
14
+ Vedeu.event(:birthday) { :eat_too_much_cake }
15
+
16
+ Defined.events.must_equal([:birthday])
17
+ end
18
+ end
19
+
20
+ describe '#groups' do
21
+ before { Vedeu::Groups.reset }
22
+
23
+ it 'returns no groups when none currently registered' do
24
+ Defined.groups.must_equal([])
25
+ end
26
+
27
+ it 'returns all groups currently registered' do
28
+ Vedeu.interface('hydrogen') { group 'elements' }
29
+
30
+ Defined.groups.must_equal(['elements'])
31
+ end
32
+ end
33
+
34
+ describe '#interfaces' do
35
+ before { Vedeu::Interfaces.reset }
36
+
37
+ it 'returns no interfaces when none currently registered' do
38
+ Defined.interfaces.must_equal([])
39
+ end
40
+
41
+ it 'returns all interfaces currently registered' do
42
+ Vedeu.interface('hydrogen') { group 'elements' }
43
+
44
+ Defined.interfaces.must_equal(['hydrogen'])
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,91 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+ module API
5
+ class HelpersTestClass
6
+ include Helpers
7
+
8
+ attr_accessor :attributes
9
+
10
+ def initialize
11
+ @attributes = { streams: [], style: [] }
12
+ end
13
+ end
14
+
15
+ describe Helpers do
16
+ describe '#colour' do
17
+ it 'raises an exception if neither a :foreground or :background ' \
18
+ 'attribute exists' do
19
+ proc { HelpersTestClass.new.colour({}) }.must_raise(InvalidSyntax)
20
+ end
21
+
22
+ it 'sets the attribute when a :foreground is given' do
23
+ HelpersTestClass.new.colour({ foreground: '#ff0000' })
24
+ .must_equal({ foreground: '#ff0000' })
25
+ end
26
+
27
+ it 'sets the attribute when a :background is given' do
28
+ HelpersTestClass.new.colour({ background: '#ff0000' })
29
+ .must_equal({ background: '#ff0000' })
30
+ end
31
+ end
32
+
33
+ describe '#style' do
34
+ it 'return an empty collection with no arguments' do
35
+ HelpersTestClass.new.style.must_equal([])
36
+ end
37
+
38
+ it 'return a collection containing the style' do
39
+ HelpersTestClass.new.style('normal').must_equal(['normal'])
40
+ end
41
+
42
+ it 'return a collection containing the styles' do
43
+ HelpersTestClass.new.style(['bold', 'underline'])
44
+ .must_equal(['bold', 'underline'])
45
+ end
46
+
47
+ it 'returns Stream attributes with an empty block' do
48
+ HelpersTestClass.new.style do
49
+ #...
50
+ end.must_equal(
51
+ [{ colour: {}, style: [], text: "", width: nil, align: :left, parent: nil, }]
52
+ )
53
+ end
54
+
55
+ it 'returns Stream attributes with a block' do
56
+ HelpersTestClass.new.style do
57
+ style 'italic'
58
+ end.must_equal(
59
+ [
60
+ {
61
+ colour: {},
62
+ style: ['italic'],
63
+ text: "",
64
+ width: nil,
65
+ align: :left,
66
+ parent: nil,
67
+ }
68
+ ]
69
+ )
70
+ end
71
+
72
+ it 'returns Stream attributes with a block' do
73
+ HelpersTestClass.new.style do
74
+ style ['italic', 'blink']
75
+ end.must_equal(
76
+ [
77
+ {
78
+ colour: {},
79
+ style: ['italic', 'blink'],
80
+ text: "",
81
+ width: nil,
82
+ align: :left,
83
+ parent: nil,
84
+ }
85
+ ]
86
+ )
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -4,6 +4,7 @@ module Vedeu
4
4
  module API
5
5
  describe Interface do
6
6
  before { Vedeu::Buffers.reset }
7
+
7
8
  describe '#define' do
8
9
  interface = Interface.new({ name: 'widget' })
9
10
 
@@ -26,7 +27,8 @@ module Vedeu
26
27
  style: "",
27
28
  geometry: {},
28
29
  cursor: true,
29
- delay: 0.0
30
+ delay: 0.0,
31
+ parent: nil,
30
32
  }
31
33
  )
32
34
  end
@@ -43,14 +45,15 @@ module Vedeu
43
45
  style: "underline",
44
46
  geometry: {},
45
47
  cursor: true,
46
- delay: 0.0
48
+ delay: 0.0,
49
+ parent: nil,
47
50
  }
48
51
  )
49
52
  end
50
53
 
51
54
  it 'allows the use of other interfaces for attributes like geometry' do
52
55
  IO.console.stub(:winsize, [25, 40]) do
53
- Vedeu.interface 'my_interface' do
56
+ interface = Vedeu.interface 'my_interface' do
54
57
  x 5
55
58
  y 5
56
59
  width 5
@@ -69,7 +72,8 @@ module Vedeu
69
72
  y: 11
70
73
  },
71
74
  cursor: true,
72
- delay: 0.0
75
+ delay: 0.0,
76
+ parent: nil,
73
77
  })
74
78
  end
75
79
  end
@@ -87,7 +91,8 @@ module Vedeu
87
91
  style: "",
88
92
  geometry: {},
89
93
  cursor: true,
90
- delay: 1.0
94
+ delay: 1.0,
95
+ parent: nil,
91
96
  })
92
97
  end
93
98
 
@@ -104,7 +109,8 @@ module Vedeu
104
109
  style: "",
105
110
  geometry: {},
106
111
  cursor: true,
107
- delay: 0.0
112
+ delay: 0.0,
113
+ parent: nil,
108
114
  }
109
115
  )
110
116
  end
@@ -122,732 +128,112 @@ module Vedeu
122
128
  style: "",
123
129
  geometry: {},
124
130
  cursor: false,
125
- delay: 0.0
131
+ delay: 0.0,
132
+ parent: nil,
126
133
  }
127
134
  )
128
135
  end
129
136
  end
130
137
 
131
- describe '#build' do
132
- before do
133
-
134
- Vedeu.interface('testing_view') do
135
- x 1
136
- y 1
137
- colour foreground: '#ffffff', background: '#000000'
138
- centred false
139
- end
140
- end
141
-
142
- it 'builds a basic view' do
143
- Vedeu.view 'testing_view' do
144
- line do
145
- text '1. A line of text.'
146
- text '2. Another line of text.'
147
- end
148
- end.must_equal(
149
- { interfaces: [{
150
- name: 'testing_view',
151
- group: '',
152
- colour: {},
153
- style: '',
154
- geometry: {},
155
- cursor: true,
156
- delay: 0.0,
157
- lines: [
158
- {
159
- colour: {},
160
- style: [],
161
- streams: [
162
- {
163
- text: '1. A line of text.',
164
- }, {
165
- text: '2. Another line of text.',
166
- }
167
- ]
168
- }
169
- ]
170
- }] }
171
- )
172
- end
173
-
174
- it 'handles coloured lines' do
175
- Vedeu.view 'testing_view' do
176
- line do
177
- text '1. Line without colours.'
178
- end
179
- end.must_equal(
180
- { interfaces: [{
181
- name: 'testing_view',
182
- group: '',
183
- colour: {},
184
- style: '',
185
- geometry: {},
186
- cursor: true,
187
- delay: 0.0,
188
- lines: [
189
- {
190
- colour: {},
191
- style: [],
192
- streams: [{ text: '1. Line without colours.' }]
193
- }
194
- ]
195
- }] }
196
- )
197
- end
198
-
199
- it 'handles coloured lines' do
200
- Vedeu.view 'testing_view' do
201
- line do
202
- colour background: '#ff0000', foreground: '#ffff00'
203
- text '2. Line with colours.'
204
- end
205
- end.must_equal(
206
- { interfaces: [{
207
- name: 'testing_view',
208
- group: '',
209
- colour: {},
210
- style: '',
211
- geometry: {},
212
- cursor: true,
213
- delay: 0.0,
214
- lines: [
215
- {
216
- colour: { background: '#ff0000', foreground: '#ffff00' },
217
- style: [],
218
- streams: [{ text: '2. Line with colours.' }]
219
- }
220
- ]
221
- }] }
222
- )
223
- end
224
-
225
- it 'handles coloured lines' do
226
- Vedeu.view 'testing_view' do
227
- line do
228
- colour foreground: '#a7ff00', background: '#005700'
229
- text '3. Line with explicit colour declaration.'
230
- end
231
- end.must_equal(
232
- { interfaces: [{
233
- name: 'testing_view',
234
- group: '',
235
- colour: {},
236
- style: '',
237
- geometry: {},
238
- cursor: true,
239
- delay: 0.0,
240
- lines: [
241
- {
242
- colour: { background: '#005700', foreground: '#a7ff00' },
243
- style: [],
244
- streams: [{ text: '3. Line with explicit colour declaration.' }]
245
- }
246
- ]
247
- }] }
248
- )
249
- end
250
-
251
- it 'handles coloured lines' do
252
- Vedeu.view 'testing_view' do
253
- line do # actually uses streams
254
- foreground '#ff00ff' do
255
- text '4. Line with only foreground set.'
256
- end
257
- end
258
- end.must_equal(
259
- { interfaces: [{
260
- name: 'testing_view',
261
- group: '',
262
- colour: {},
263
- style: '',
264
- geometry: {},
265
- cursor: true,
266
- delay: 0.0,
267
- lines: [
268
- {
269
- colour: {},
270
- style: [],
271
- streams: [{
272
- colour: { foreground: '#ff00ff' },
273
- style: [],
274
- text: '4. Line with only foreground set.',
275
- width: nil,
276
- align: :left
277
- }]
278
- }
279
- ]
280
- }] }
281
- )
282
- end
283
-
284
- it 'handles coloured lines' do
285
- Vedeu.view 'testing_view' do
286
- line do # actually uses streams
287
- background '#00ff00' do
288
- text '5. Line with only background set.'
289
- end
290
- end
291
- end.must_equal(
292
- { interfaces: [{
293
- name: 'testing_view',
294
- group: '',
295
- colour: {},
296
- style: '',
297
- geometry: {},
298
- cursor: true,
299
- delay: 0.0,
300
- lines: [
301
- {
302
- colour: {},
303
- style: [],
304
- streams: [{
305
- colour: { background: '#00ff00' },
306
- style: [],
307
- text: '5. Line with only background set.',
308
- width: nil,
309
- align: :left
310
- }]
311
- }
312
- ]
313
- }] }
314
- )
315
- end
138
+ describe '#use' do
139
+ it 'returns the interface by name' do
140
+ interface = Vedeu.interface('tungsten') {}
316
141
 
317
- it 'handles styles' do
318
- Vedeu.view 'testing_view' do
319
- line do
320
- style 'normal'
321
- text '1. Line with a normal style.'
322
- end
323
- end.must_equal(
324
- { interfaces: [{
325
- name: 'testing_view',
326
- group: '',
327
- colour: {},
328
- style: '',
329
- geometry: {},
330
- cursor: true,
331
- delay: 0.0,
332
- lines: [
333
- {
334
- colour: {},
335
- style: ['normal'],
336
- streams: [{
337
- text: '1. Line with a normal style.'
338
- }]
339
- }
340
- ]
341
- }] }
342
- )
343
- end
344
-
345
- it 'handles styles' do
346
- Vedeu.view 'testing_view' do
347
- line do
348
- style 'underline'
349
- text '2. Line with an underline style.'
350
- end
351
- end.must_equal(
352
- { interfaces: [{
353
- name: 'testing_view',
354
- group: '',
355
- colour: {},
356
- style: '',
357
- geometry: {},
358
- cursor: true,
359
- delay: 0.0,
360
- lines: [
361
- {
362
- colour: {},
363
- style: ['underline'],
364
- streams: [{
365
- text: '2. Line with an underline style.'
366
- }]
367
- }
368
- ]
369
- }] }
370
- )
142
+ Interface.new.use('tungsten').must_be_instance_of(Vedeu::Interface)
371
143
  end
144
+ end
372
145
 
373
- it 'handles styles' do
374
- Vedeu.view 'testing_view' do
375
- line do # actually uses streams
376
- style 'normal' do
377
- text '3. Line with a normal style.'
378
- end
379
- end
380
- end.must_equal(
381
- { interfaces: [{
382
- name: 'testing_view',
383
- group: '',
384
- colour: {},
385
- style: '',
386
- geometry: {},
387
- cursor: true,
388
- delay: 0.0,
146
+ describe '#line' do
147
+ it 'adds a blank line with no arguments' do
148
+ interface = Vedeu.interface 'carbon' do
149
+ line
150
+ end
151
+ interface.must_be_instance_of(API::Interface)
152
+ interface.attributes.must_equal(
153
+ {
154
+ name: "carbon",
155
+ group: "",
389
156
  lines: [
390
157
  {
391
- colour: {},
392
- style: [],
393
- streams: [{
394
- colour: {},
395
- style: ['normal'],
396
- text: '3. Line with a normal style.',
397
- width: nil,
398
- align: :left
399
- }]
158
+ colour: {},
159
+ streams: {
160
+ text: ""
161
+ },
162
+ style: [],
163
+ parent: interface.view_attributes,
400
164
  }
401
- ]
402
- }] }
403
- )
404
- end
405
-
406
- it 'handles styles' do
407
- Vedeu.view 'testing_view' do
408
- line do # actually uses streams
409
- style 'underline' do
410
- text '4. Line with an underlined style.'
411
- end
412
- end
413
- end.must_equal(
414
- { interfaces: [{
415
- name: 'testing_view',
416
- group: '',
165
+ ],
417
166
  colour: {},
418
- style: '',
167
+ style: "",
419
168
  geometry: {},
420
169
  cursor: true,
421
170
  delay: 0.0,
422
- lines: [
423
- {
424
- colour: {},
425
- style: [],
426
- streams: [{
427
- colour: {},
428
- style: ['underline'],
429
- text: '4. Line with an underlined style.',
430
- width: nil,
431
- align: :left
432
- }]
433
- }
434
- ]
435
- }] }
171
+ parent: nil,
172
+ }
436
173
  )
437
174
  end
438
175
 
439
- it 'handles streams, which means sub-line colours and styles' do
440
- Vedeu.view 'testing_view' do
441
- line do
442
- stream do
443
- text 'A stream of text.'
444
- end
445
- end
446
- end.must_equal(
447
- { interfaces: [{
448
- name: 'testing_view',
449
- group: '',
450
- colour: {},
451
- style: '',
452
- geometry: {},
453
- cursor: true,
454
- delay: 0.0,
176
+ it 'adds a line directly with a value and no block' do
177
+ interface = Vedeu.interface 'carbon' do
178
+ line 'This is some text...'
179
+ end
180
+ interface.must_be_instance_of(API::Interface)
181
+ interface.attributes.must_equal(
182
+ {
183
+ name: "carbon",
184
+ group: "",
455
185
  lines: [
456
186
  {
457
- colour: {},
458
- style: [],
459
- streams: [
460
- {
461
- colour: {},
462
- style: [],
463
- text: 'A stream of text.',
464
- width: nil,
465
- align: :left
466
- }
467
- ]
187
+ colour: {},
188
+ streams: {
189
+ text: "This is some text..."
190
+ },
191
+ style: [],
192
+ parent: interface.view_attributes,
468
193
  }
469
- ]
470
- }] }
471
- )
472
- end
473
-
474
- it 'handles streams, which means sub-line colours and styles' do
475
- Vedeu.view 'testing_view' do
476
- line do
477
- stream do # Stream is an 'explicit declaration'.
478
- # We don't need it unless we want to add colours and styles.
479
- # See below.
480
- text '1. Two streams of text, these will be'
481
- end
482
-
483
- stream do
484
- text ' on the same line- note the space.'
485
- end
486
- end
487
- end.must_equal(
488
- { interfaces: [{
489
- name: 'testing_view',
490
- group: '',
194
+ ],
491
195
  colour: {},
492
- style: '',
196
+ style: "",
493
197
  geometry: {},
494
198
  cursor: true,
495
199
  delay: 0.0,
496
- lines: [
497
- {
498
- colour: {},
499
- style: [],
500
- streams: [
501
- {
502
- colour: {},
503
- style: [],
504
- text: '1. Two streams of text, these will be',
505
- width: nil,
506
- align: :left
507
- }, {
508
- colour: {},
509
- style: [],
510
- text: ' on the same line- note the space.',
511
- width: nil,
512
- align: :left
513
- }
514
- ]
515
- }
516
- ]
517
- }] }
200
+ parent: nil,
201
+ }
518
202
  )
519
203
  end
520
204
 
521
- it 'handles streams, which means sub-line colours and styles' do
522
- Vedeu.view 'testing_view' do
205
+ it 'allows the addition of more attributes with a block' do
206
+ interface = Vedeu.interface 'silicon' do
523
207
  line do
524
- stream do
525
- text '2. Streams can have'
526
- end
527
-
528
- stream do
529
- colour foreground: '#ff0000', background: '#00ff00'
530
- text ' colours too.'
531
- end
208
+ text 'This is different text...'
532
209
  end
533
- end.must_equal(
534
- { interfaces: [{
535
- name: 'testing_view',
536
- group: '',
537
- colour: {},
538
- style: '',
539
- geometry: {},
540
- cursor: true,
541
- delay: 0.0,
210
+ end
211
+ interface.must_be_instance_of(API::Interface)
212
+ interface.attributes.must_equal(
213
+ {
214
+ name: "silicon",
215
+ group: "",
542
216
  lines: [
543
217
  {
544
218
  colour: {},
545
- style: [],
546
219
  streams: [
547
220
  {
548
- colour: {},
549
- style: [],
550
- text: '2. Streams can have',
551
- width: nil,
552
- align: :left
553
- }, {
554
- colour: {
555
- foreground: '#ff0000',
556
- background: '#00ff00'
557
- },
558
- style: [],
559
- text: ' colours too.',
560
- width: nil,
561
- align: :left
221
+ text: "This is different text..."
562
222
  }
563
- ]
564
- }
565
- ]
566
- }] }
567
- )
568
- end
569
-
570
- it 'handles streams, which means sub-line colours and styles' do
571
- Vedeu.view 'testing_view' do
572
- line do
573
- stream do
574
- text '3. Streams can have'
575
- end
576
-
577
- stream do
578
- style 'underline'
579
- text ' styles too.'
580
- end
581
- end
582
- end.must_equal(
583
- { interfaces: [{
584
- name: 'testing_view',
585
- group: '',
586
- colour: {},
587
- style: '',
588
- geometry: {},
589
- cursor: true,
590
- delay: 0.0,
591
- lines: [
592
- {
593
- colour: {},
223
+ ],
594
224
  style: [],
595
- streams: [
596
- {
597
- colour: {},
598
- style: [],
599
- text: '3. Streams can have',
600
- width: nil,
601
- align: :left
602
- }, {
603
- colour: {},
604
- style: ['underline'],
605
- text: ' styles too.',
606
- width: nil,
607
- align: :left
608
- }
609
- ]
225
+ parent: interface.view_attributes,
610
226
  }
611
- ]
612
- }] }
613
- )
614
- end
615
-
616
- it 'handles alignment' do
617
- Vedeu.view 'testing_view' do
618
- line do
619
- stream do
620
- width 80
621
- text 'This is aligned left, and padded with spaces.'
622
- end
623
- end
624
- end.must_equal(
625
- { interfaces: [{
626
- name: 'testing_view',
627
- group: '',
628
- colour: {},
629
- style: '',
630
- geometry: {},
631
- cursor: true,
632
- delay: 0.0,
633
- lines: [{
634
- colour: {},
635
- style: [],
636
- streams: [{
637
- align: :left,
638
- colour: {},
639
- style: [],
640
- width: 80,
641
- text: 'This is aligned left, and padded with spaces.'
642
- }]
643
- }]
644
- }] }
645
- )
646
- end
647
-
648
- it 'handles alignment' do
649
- Vedeu.view 'testing_view' do
650
- line do
651
- stream do
652
- width 80
653
- align :left # explicit
654
- text 'This is aligned left, and padded with spaces.'
655
- end
656
- end
657
- end.must_equal(
658
- { interfaces: [{
659
- name: 'testing_view',
660
- group: '',
661
- colour: {},
662
- style: '',
663
- geometry: {},
664
- cursor: true,
665
- delay: 0.0,
666
- lines: [{
667
- colour: {},
668
- style: [],
669
- streams: [{
670
- colour: {},
671
- style: [],
672
- width: 80,
673
- align: :left,
674
- text: 'This is aligned left, and padded with spaces.'
675
- }]
676
- }]
677
- }] }
678
- )
679
- end
680
-
681
- it 'handles alignment' do
682
- Vedeu.view 'testing_view' do
683
- line do
684
- stream do
685
- width 80
686
- align :centre
687
- text 'This is aligned centrally, and padded with spaces.'
688
- end
689
- end
690
- end.must_equal(
691
- { interfaces: [{
692
- name: 'testing_view',
693
- group: '',
694
- colour: {},
695
- style: '',
696
- geometry: {},
697
- cursor: true,
698
- delay: 0.0,
699
- lines: [{
700
- colour: {},
701
- style: [],
702
- streams: [{
703
- colour: {},
704
- style: [],
705
- width: 80,
706
- align: :centre,
707
- text: 'This is aligned centrally, and padded with spaces.'
708
- }]
709
- }]
710
- }] }
711
- )
712
- end
713
-
714
- it 'handles alignment' do
715
- Vedeu.view 'testing_view' do
716
- line do
717
- stream do
718
- width 80
719
- align :right
720
- text 'This is aligned right, and padded with spaces.'
721
- end
722
- end
723
- end.must_equal(
724
- { interfaces: [{
725
- name: 'testing_view',
726
- group: '',
227
+ ],
727
228
  colour: {},
728
- style: '',
729
- geometry: {},
730
- cursor: true,
731
- delay: 0.0,
732
- lines: [{
733
- colour: {},
734
- style: [],
735
- streams: [{
736
- colour: {},
737
- style: [],
738
- width: 80,
739
- align: :right,
740
- text: 'This is aligned right, and padded with spaces.'
741
- }]
742
- }]
743
- }] }
744
- )
745
- end
746
-
747
- it 'handles multiple colour and text statements correctly' do
748
- Vedeu.view 'testing_view' do
749
- line do
750
- foreground('#ffff00') { text "\u{25B2}" }
751
- text " Prev"
752
-
753
- foreground('#ffff00') { text "\u{25BC}" }
754
- text " Next"
755
-
756
- foreground('#ffff00') { text "\u{21B2}" }
757
- text " Select"
758
-
759
- foreground('#ffff00') { text "\u{2395}" }
760
- text " Pause"
761
-
762
- foreground('#ffff00') { text "Q" }
763
- text " Quit"
764
- end
765
- end.must_equal(
766
- { interfaces: [{
767
- name: 'testing_view',
768
- group: '',
769
- colour: {},
770
- style: '',
229
+ style: "",
771
230
  geometry: {},
772
231
  cursor: true,
773
232
  delay: 0.0,
774
- lines: [
775
- {
776
- colour: {},
777
- style: [],
778
- streams: [
779
- {
780
- colour: {
781
- foreground: "#ffff00"
782
- },
783
- style: [],
784
- text: "▲",
785
- width: nil,
786
- align: :left
787
- }, {
788
- text: " Prev",
789
- }, {
790
- colour: {
791
- foreground: "#ffff00"
792
- },
793
- style: [],
794
- text: "▼",
795
- width: nil,
796
- align: :left
797
- }, {
798
- text: " Next",
799
- }, {
800
- colour: {
801
- foreground: "#ffff00"
802
- },
803
- style: [],
804
- text: "↲",
805
- width: nil,
806
- align: :left
807
- }, {
808
- text: " Select",
809
- }, {
810
- colour: {
811
- foreground: "#ffff00"
812
- },
813
- style: [],
814
- text: "⎕",
815
- width: nil,
816
- align: :left
817
- }, {
818
- text: " Pause",
819
- }, {
820
- colour: {
821
- foreground: "#ffff00"
822
- },
823
- style: [],
824
- text: "Q",
825
- width: nil,
826
- align: :left
827
- }, {
828
- text: " Quit",
829
- }
830
- ]
831
- }
832
- ]
833
- }] }
233
+ parent: nil
234
+ }
834
235
  )
835
236
  end
836
-
837
- it 'allows inline values for line' do
838
- Vedeu.interface 'helium' do
839
- end
840
- attributes = Vedeu.view 'helium' do
841
- line 'A headline, if you will.'
842
- line # with a spacer line
843
- line 'This is a line of text...'
844
- line do
845
- text '...we can mix and match...'
846
- end
847
- line '...to our hearts content.'
848
- end
849
- attributes[:interfaces].first[:lines].size.must_equal(5)
850
- end
851
237
  end
852
238
 
853
239
  describe '#cursor' do
@@ -876,6 +262,68 @@ module Vedeu
876
262
  end
877
263
  end
878
264
 
265
+ describe '#delay' do
266
+ it 'sets the delay attribute' do
267
+ Vedeu.interface 'cobalt' do
268
+ delay 0.25
269
+ end
270
+
271
+ Vedeu.use('cobalt').attributes[:delay].must_equal(0.25)
272
+ end
273
+ end
274
+
275
+ describe '#group' do
276
+ it 'sets the group attribute' do
277
+ Vedeu.interface 'iron' do
278
+ group 'elements'
279
+ end
280
+
281
+ Vedeu.use('iron').attributes[:group].must_equal('elements')
282
+ end
283
+ end
284
+
285
+ describe '#name' do
286
+ it 'sets the name attribute' do
287
+ Vedeu.interface do
288
+ name 'nickel'
289
+ end
290
+
291
+ Vedeu.use('nickel').attributes[:name].must_equal('nickel')
292
+ end
293
+ end
294
+
295
+ describe '#x' do
296
+ it 'sets the attribute to the block if a block is given' do
297
+ skip
298
+ end
299
+
300
+ it 'sets the attribute to the value if a block is not given' do
301
+ skip
302
+ end
303
+ end
304
+
305
+ describe '#y' do
306
+ it 'sets the attribute to the block if a block is given' do
307
+ skip
308
+ end
309
+
310
+ it 'sets the attribute to the value if a block is not given' do
311
+ skip
312
+ end
313
+ end
314
+
315
+ describe '#width' do
316
+ it 'sets the attribute to the value' do
317
+ skip
318
+ end
319
+ end
320
+
321
+ describe '#height' do
322
+ it 'sets the attribute to the value' do
323
+ skip
324
+ end
325
+ end
326
+
879
327
  describe '#centred' do
880
328
  it 'raises an exception if the value is invalid' do
881
329
  proc {