vedeu 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/LICENSE.txt +5 -0
  4. data/bin/vedeu +3 -1
  5. data/docs/api.md +2 -0
  6. data/examples/cursor_app/cursor_app.rb +22 -7
  7. data/examples/hello_world.rb +42 -0
  8. data/lib/vedeu.rb +5 -5
  9. data/lib/vedeu/api/api.rb +16 -33
  10. data/lib/vedeu/api/helpers.rb +86 -0
  11. data/lib/vedeu/api/interface.rb +60 -17
  12. data/lib/vedeu/api/keymap.rb +5 -0
  13. data/lib/vedeu/api/line.rb +52 -34
  14. data/lib/vedeu/api/menu.rb +1 -1
  15. data/lib/vedeu/api/stream.rb +0 -34
  16. data/lib/vedeu/configuration/api.rb +10 -10
  17. data/lib/vedeu/configuration/cli.rb +1 -1
  18. data/lib/vedeu/launcher.rb +21 -6
  19. data/lib/vedeu/models/background.rb +1 -1
  20. data/lib/vedeu/models/composition.rb +1 -1
  21. data/lib/vedeu/models/cursor.rb +25 -35
  22. data/lib/vedeu/models/foreground.rb +1 -1
  23. data/lib/vedeu/models/geometry.rb +216 -6
  24. data/lib/vedeu/models/interface.rb +14 -16
  25. data/lib/vedeu/models/keymap.rb +38 -6
  26. data/lib/vedeu/models/line.rb +1 -1
  27. data/lib/vedeu/models/stream.rb +1 -1
  28. data/lib/vedeu/output/compositor.rb +1 -1
  29. data/lib/vedeu/output/render.rb +1 -5
  30. data/lib/vedeu/output/viewport.rb +37 -2
  31. data/lib/vedeu/repositories/buffers.rb +21 -27
  32. data/lib/vedeu/repositories/cursors.rb +3 -15
  33. data/lib/vedeu/repositories/focus.rb +2 -6
  34. data/lib/vedeu/repositories/groups.rb +1 -1
  35. data/lib/vedeu/repositories/interfaces.rb +1 -1
  36. data/lib/vedeu/repositories/keymaps.rb +26 -22
  37. data/lib/vedeu/repositories/menus.rb +1 -1
  38. data/lib/vedeu/repositories/offsets.rb +30 -12
  39. data/lib/vedeu/repositories/positional.rb +23 -0
  40. data/lib/vedeu/support/colour_translator.rb +1 -16
  41. data/lib/vedeu/support/esc.rb +23 -28
  42. data/lib/vedeu/support/event.rb +6 -14
  43. data/lib/vedeu/{output → support}/refresh.rb +0 -0
  44. data/lib/vedeu/support/registrar.rb +6 -14
  45. data/lib/vedeu/support/repository.rb +3 -2
  46. data/lib/vedeu/support/terminal.rb +9 -13
  47. data/lib/vedeu/support/trace.rb +2 -3
  48. data/test/integration/cursors_test.rb +9 -0
  49. data/test/integration/views/basic_view_test.rb +19 -0
  50. data/test/lib/vedeu/api/api_test.rb +28 -5
  51. data/test/lib/vedeu/api/composition_test.rb +7 -3
  52. data/test/lib/vedeu/api/defined_test.rb +9 -3
  53. data/test/lib/vedeu/api/helpers_test.rb +39 -5
  54. data/test/lib/vedeu/api/interface_test.rb +88 -8
  55. data/test/lib/vedeu/api/keymap_test.rb +5 -3
  56. data/test/lib/vedeu/api/line_test.rb +9 -3
  57. data/test/lib/vedeu/api/menu_test.rb +11 -7
  58. data/test/lib/vedeu/api/stream_test.rb +9 -31
  59. data/test/lib/vedeu/application_test.rb +25 -2
  60. data/test/lib/vedeu/configuration/api_test.rb +5 -3
  61. data/test/lib/vedeu/configuration/cli_test.rb +5 -3
  62. data/test/lib/vedeu/configuration/configuration_test.rb +5 -2
  63. data/test/lib/vedeu/input/input_test.rb +5 -2
  64. data/test/lib/vedeu/launcher_test.rb +37 -2
  65. data/test/lib/vedeu/models/background_test.rb +6 -2
  66. data/test/lib/vedeu/models/char_test.rb +9 -6
  67. data/test/lib/vedeu/models/colour_test.rb +6 -2
  68. data/test/lib/vedeu/models/composition_test.rb +4 -2
  69. data/test/lib/vedeu/models/cursor_test.rb +27 -16
  70. data/test/lib/vedeu/models/foreground_test.rb +6 -2
  71. data/test/lib/vedeu/models/geometry_test.rb +6 -2
  72. data/test/lib/vedeu/models/interface_test.rb +5 -2
  73. data/test/lib/vedeu/models/keymap_test.rb +6 -4
  74. data/test/lib/vedeu/models/line_test.rb +5 -2
  75. data/test/lib/vedeu/models/offset_test.rb +7 -3
  76. data/test/lib/vedeu/models/stream_test.rb +4 -2
  77. data/test/lib/vedeu/models/style_test.rb +5 -2
  78. data/test/lib/vedeu/output/clear_test.rb +6 -2
  79. data/test/lib/vedeu/output/compositor_test.rb +8 -4
  80. data/test/lib/vedeu/output/render_test.rb +9 -6
  81. data/test/lib/vedeu/output/view_test.rb +7 -3
  82. data/test/lib/vedeu/output/viewport_test.rb +42 -9
  83. data/test/lib/vedeu/repositories/buffers_test.rb +52 -12
  84. data/test/lib/vedeu/repositories/cursors_test.rb +4 -26
  85. data/test/lib/vedeu/repositories/events_test.rb +6 -2
  86. data/test/lib/vedeu/repositories/focus_test.rb +5 -2
  87. data/test/lib/vedeu/repositories/groups_test.rb +5 -2
  88. data/test/lib/vedeu/repositories/interfaces_test.rb +4 -2
  89. data/test/lib/vedeu/repositories/keymaps_test.rb +8 -2
  90. data/test/lib/vedeu/repositories/menus_test.rb +3 -2
  91. data/test/lib/vedeu/repositories/offsets_test.rb +26 -19
  92. data/test/lib/vedeu/repositories/positional_test.rb +50 -0
  93. data/test/lib/vedeu/support/coercions_test.rb +7 -3
  94. data/test/lib/vedeu/support/colour_translator_test.rb +6 -2
  95. data/test/lib/vedeu/support/common_test.rb +5 -3
  96. data/test/lib/vedeu/support/esc_test.rb +6 -2
  97. data/test/lib/vedeu/support/event_test.rb +6 -2
  98. data/test/lib/vedeu/support/grid_test.rb +9 -3
  99. data/test/lib/vedeu/support/keymap_validator_test.rb +5 -2
  100. data/test/lib/vedeu/support/log_test.rb +4 -2
  101. data/test/lib/vedeu/support/menu_test.rb +10 -2
  102. data/test/lib/vedeu/support/position_test.rb +10 -2
  103. data/test/lib/vedeu/support/presentation_test.rb +6 -3
  104. data/test/lib/vedeu/{output → support}/refresh_test.rb +6 -2
  105. data/test/lib/vedeu/support/registrar_test.rb +2 -2
  106. data/test/lib/vedeu/support/repository_test.rb +4 -3
  107. data/test/lib/vedeu/support/terminal_test.rb +6 -2
  108. data/test/lib/vedeu/support/trace_test.rb +17 -2
  109. data/test/lib/vedeu_test.rb +1 -1
  110. data/vedeu.gemspec +2 -2
  111. metadata +13 -13
  112. data/lib/vedeu/output/area.rb +0 -284
  113. data/lib/vedeu/support/move.rb +0 -50
  114. data/test/lib/vedeu/output/area_test.rb +0 -242
  115. data/test/lib/vedeu/support/move_test.rb +0 -35
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  describe API do
6
+
5
7
  let(:event) { mock('Event') }
6
8
 
7
9
  before { Event.stubs(:new).returns(event) }
@@ -51,10 +53,29 @@ module Vedeu
51
53
  end
52
54
 
53
55
  describe '.keypress' do
54
- before { Vedeu::Focus.stubs(:current).returns('') }
56
+ before do
57
+ Interfaces.reset
58
+
59
+ Vedeu.interface('barium') {}
60
+ end
61
+
62
+ context 'when the key is registered' do
63
+ before do
64
+ Vedeu.keys do
65
+ interface 'barium'
66
+ key('j') { :j_pressed }
67
+ end
68
+ end
69
+
70
+ it 'returns the result of proc stored for the keypress' do
71
+ Vedeu.keypress('j').must_equal(:j_pressed)
72
+ end
73
+ end
55
74
 
56
- it 'returns false when the key was not registered' do
57
- Vedeu.keypress('k').must_equal(false)
75
+ context 'when the key is not registered' do
76
+ it 'returns false' do
77
+ Vedeu.keypress('k').must_equal(false)
78
+ end
58
79
  end
59
80
  end
60
81
 
@@ -147,6 +168,7 @@ module Vedeu
147
168
  {
148
169
  interfaces: [{
149
170
  name: "some_interface",
171
+ cursor: :hide,
150
172
  group: '',
151
173
  lines: [],
152
174
  colour: {},
@@ -195,5 +217,6 @@ module Vedeu
195
217
  end
196
218
  end
197
219
 
198
- end
199
- end
220
+ end # API
221
+
222
+ end # Vedeu
@@ -1,7 +1,9 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  module API
6
+
5
7
  describe Composition do
6
8
 
7
9
  describe '.render' do
@@ -22,6 +24,8 @@ module Vedeu
22
24
  end
23
25
  end
24
26
 
25
- end
26
- end
27
- end
27
+ end # Composition
28
+
29
+ end # API
30
+
31
+ end # Vedeu
@@ -1,8 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  module API
6
+
5
7
  describe Defined do
8
+
6
9
  describe '#events' do
7
10
  it 'returns all events currently registered' do
8
11
  Vedeu.event(:birthday) { :eat_too_much_cake }
@@ -68,6 +71,9 @@ module Vedeu
68
71
  Defined.menus.must_equal(['seaborgium'])
69
72
  end
70
73
  end
71
- end
72
- end
73
- end
74
+
75
+ end # Defined
76
+
77
+ end # API
78
+
79
+ end # Vedeu
@@ -1,18 +1,49 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  module API
6
+
5
7
  class HelpersTestClass
6
8
  include Helpers
7
9
 
8
10
  attr_accessor :attributes
9
11
 
10
12
  def initialize
11
- @attributes = { streams: [], style: [] }
13
+ @attributes = { colour: {}, streams: [], style: [] }
12
14
  end
13
- end
15
+ end # HelpersTestClass
14
16
 
15
17
  describe Helpers do
18
+
19
+ describe '#background' do
20
+ it 'returns a Hash' do
21
+ HelpersTestClass.new.background('#00ff00').must_be_instance_of(Hash)
22
+ end
23
+
24
+ it 'returns the value assigned' do
25
+ HelpersTestClass.new.background('#00ff00').must_equal({ background: '#00ff00' })
26
+ end
27
+
28
+ it 'raises an exception if the value is not defined' do
29
+ proc { HelpersTestClass.new.background('') }.must_raise(InvalidSyntax)
30
+ end
31
+ end
32
+
33
+ describe '#foreground' do
34
+ it 'returns a Hash' do
35
+ HelpersTestClass.new.foreground('#00ff00').must_be_instance_of(Hash)
36
+ end
37
+
38
+ it 'returns the value assigned' do
39
+ HelpersTestClass.new.foreground('#00ff00').must_equal({ foreground: '#00ff00' })
40
+ end
41
+
42
+ it 'raises an exception if the value is not defined' do
43
+ proc { HelpersTestClass.new.foreground('') }.must_raise(InvalidSyntax)
44
+ end
45
+ end
46
+
16
47
  describe '#colour' do
17
48
  it 'raises an exception if neither a :foreground or :background ' \
18
49
  'attribute exists' do
@@ -86,6 +117,9 @@ module Vedeu
86
117
  )
87
118
  end
88
119
  end
89
- end
90
- end
91
- end
120
+
121
+ end # Helpers
122
+
123
+ end # API
124
+
125
+ end # Vedeu
@@ -1,10 +1,12 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  module API
5
6
 
6
7
  describe Interface do
7
- before { Vedeu::Buffers.reset }
8
+
9
+ before { Interfaces.reset }
8
10
 
9
11
  describe '#define' do
10
12
  interface = Interface.new({ name: 'widget' })
@@ -19,6 +21,7 @@ module Vedeu
19
21
  end.must_equal(
20
22
  {
21
23
  name: '',
24
+ cursor: :hide,
22
25
  group: '',
23
26
  lines: [],
24
27
  colour: {
@@ -39,6 +42,7 @@ module Vedeu
39
42
  end.must_equal(
40
43
  {
41
44
  name: '',
45
+ cursor: :hide,
42
46
  group: '',
43
47
  lines: [],
44
48
  colour: {},
@@ -63,6 +67,7 @@ module Vedeu
63
67
  y use('my_interface').south
64
68
  end.must_equal({
65
69
  name: "my_other_interface",
70
+ cursor: :hide,
66
71
  group: '',
67
72
  lines: [],
68
73
  colour: {},
@@ -83,6 +88,7 @@ module Vedeu
83
88
  end.must_equal(
84
89
  {
85
90
  name: '',
91
+ cursor: :hide,
86
92
  group: '',
87
93
  lines: [],
88
94
  colour: {},
@@ -100,6 +106,7 @@ module Vedeu
100
106
  end.must_equal(
101
107
  {
102
108
  name: '',
109
+ cursor: :hide,
103
110
  group: "my_group",
104
111
  lines: [],
105
112
  colour: {},
@@ -122,6 +129,32 @@ module Vedeu
122
129
  end
123
130
  end
124
131
 
132
+ describe '#cursor' do
133
+ it 'returns :hide if the value is false or nil' do
134
+ API::Interface.new.cursor(false).must_equal(:hide)
135
+ end
136
+
137
+ it 'returns :hide if the value is false or nil' do
138
+ Vedeu.interface 'cobalt' do
139
+ cursor false
140
+ end
141
+
142
+ Vedeu.use('cobalt').attributes[:cursor].must_equal(:hide)
143
+ end
144
+
145
+ it 'returns :show if any other value' do
146
+ API::Interface.new.cursor.must_equal(:show)
147
+ end
148
+
149
+ it 'returns :show if any other value' do
150
+ Vedeu.interface 'cobalt' do
151
+ cursor true
152
+ end
153
+
154
+ Vedeu.use('cobalt').attributes[:cursor].must_equal(:show)
155
+ end
156
+ end
157
+
125
158
  describe '#delay' do
126
159
  it 'sets the delay attribute' do
127
160
  Vedeu.interface 'cobalt' do
@@ -144,7 +177,37 @@ module Vedeu
144
177
 
145
178
  describe '#height' do
146
179
  it 'sets the attribute to the value' do
147
- skip
180
+ Vedeu.interface 'iron' do
181
+ height 6
182
+ end
183
+
184
+ Vedeu.use('iron').attributes[:geometry][:height].must_equal(6)
185
+ end
186
+ end
187
+
188
+ describe '#keys' do
189
+ before do
190
+ Keymaps.reset
191
+
192
+ Vedeu.interface 'iron' do
193
+ keys do
194
+ key('k') { :k_pressed }
195
+ end
196
+ end
197
+ end
198
+
199
+ it 'defines a keymap for the interface' do
200
+ Keymaps.interface_key?('k').must_equal(true)
201
+ end
202
+
203
+ it 'defines a keymap for the interface' do
204
+ Keymaps.interface_keys('iron').must_equal(['k'])
205
+ end
206
+
207
+ context 'when the block is not given' do
208
+ it 'raises an exception' do
209
+ proc { Vedeu.interface('iron') { keys } }.must_raise(InvalidSyntax)
210
+ end
148
211
  end
149
212
  end
150
213
 
@@ -157,6 +220,7 @@ module Vedeu
157
220
  interface.attributes.must_equal(
158
221
  {
159
222
  name: 'carbon',
223
+ cursor: :hide,
160
224
  group: '',
161
225
  lines: [
162
226
  {
@@ -185,6 +249,7 @@ module Vedeu
185
249
  interface.attributes.must_equal(
186
250
  {
187
251
  name: 'carbon',
252
+ cursor: :hide,
188
253
  group: '',
189
254
  lines: [
190
255
  {
@@ -215,6 +280,7 @@ module Vedeu
215
280
  interface.attributes.must_equal(
216
281
  {
217
282
  name: "silicon",
283
+ cursor: :hide,
218
284
  group: '',
219
285
  lines: [
220
286
  {
@@ -258,7 +324,11 @@ module Vedeu
258
324
 
259
325
  describe '#width' do
260
326
  it 'sets the attribute to the value' do
261
- skip
327
+ Vedeu.interface 'iron' do
328
+ width 25
329
+ end
330
+
331
+ Vedeu.use('iron').attributes[:geometry][:width].must_equal(25)
262
332
  end
263
333
  end
264
334
 
@@ -268,7 +338,11 @@ module Vedeu
268
338
  end
269
339
 
270
340
  it 'sets the attribute to the value if a block is not given' do
271
- skip
341
+ Vedeu.interface 'iron' do
342
+ x 7
343
+ end
344
+
345
+ Vedeu.use('iron').attributes[:geometry][:x].must_equal(7)
272
346
  end
273
347
  end
274
348
 
@@ -278,10 +352,16 @@ module Vedeu
278
352
  end
279
353
 
280
354
  it 'sets the attribute to the value if a block is not given' do
281
- skip
355
+ Vedeu.interface 'iron' do
356
+ y 4
357
+ end
358
+
359
+ Vedeu.use('iron').attributes[:geometry][:y].must_equal(4)
282
360
  end
283
361
  end
284
362
 
285
- end
286
- end
287
- end
363
+ end # Interface
364
+
365
+ end # API
366
+
367
+ end # Vedeu
@@ -1,6 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  module API
5
6
 
6
7
  describe Keymap do
@@ -57,7 +58,8 @@ module Vedeu
57
58
  end
58
59
  end
59
60
 
60
- end
61
+ end # Keymap
62
+
63
+ end # API
61
64
 
62
- end
63
- end
65
+ end # Vedeu
@@ -1,8 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  module API
6
+
5
7
  describe Line do
8
+
6
9
  describe '#stream' do
7
10
  it 'returns the value assigned' do
8
11
  line = Line.new
@@ -72,6 +75,9 @@ module Vedeu
72
75
  attrs.first[:colour].must_equal({ background: '#0000ff' })
73
76
  end
74
77
  end
75
- end
76
- end
77
- end
78
+
79
+ end # Line
80
+
81
+ end # API
82
+
83
+ end # Vedeu
@@ -1,9 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  module API
5
6
 
6
7
  describe Menu do
8
+
7
9
  describe '.define' do
8
10
  before { Menus.reset }
9
11
 
@@ -63,13 +65,15 @@ module Vedeu
63
65
  menu.attributes[:name].must_equal('elements')
64
66
  end
65
67
  end
66
- end
67
68
 
68
- describe '#method_missing' do
69
- it 'returns nil' do
70
- Menu.new.some_missing_method(:test).must_equal(nil)
69
+ describe '#method_missing' do
70
+ it 'returns nil' do
71
+ Menu.new.some_missing_method(:test).must_equal(nil)
72
+ end
71
73
  end
72
- end
73
74
 
74
- end
75
- end
75
+ end # Menu
76
+
77
+ end # API
78
+
79
+ end # Vedeu
@@ -1,8 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
+
4
5
  module API
6
+
5
7
  describe Stream do
8
+
6
9
  describe '#align' do
7
10
  it 'returns a Symbol' do
8
11
  Stream.new.align(:left).must_be_instance_of(Symbol)
@@ -21,34 +24,6 @@ module Vedeu
21
24
  end
22
25
  end
23
26
 
24
- describe '#background' do
25
- it 'returns a Hash' do
26
- Stream.new.background('#00ff00').must_be_instance_of(Hash)
27
- end
28
-
29
- it 'returns the value assigned' do
30
- Stream.new.background('#00ff00').must_equal({ background: '#00ff00' })
31
- end
32
-
33
- it 'raises an exception if the value is not defined' do
34
- proc { Stream.new.background('') }.must_raise(InvalidSyntax)
35
- end
36
- end
37
-
38
- describe '#foreground' do
39
- it 'returns a Hash' do
40
- Stream.new.foreground('#00ff00').must_be_instance_of(Hash)
41
- end
42
-
43
- it 'returns the value assigned' do
44
- Stream.new.foreground('#00ff00').must_equal({ foreground: '#00ff00' })
45
- end
46
-
47
- it 'raises an exception if the value is not defined' do
48
- proc { Stream.new.foreground('') }.must_raise(InvalidSyntax)
49
- end
50
- end
51
-
52
27
  describe '#left' do
53
28
  it 'returns a Symbol' do
54
29
  Stream.new.left.must_equal(:left)
@@ -78,6 +53,9 @@ module Vedeu
78
53
  Stream.new.text(30).must_equal(30)
79
54
  end
80
55
  end
81
- end
82
- end
83
- end
56
+
57
+ end # Stream
58
+
59
+ end # API
60
+
61
+ end # Vedeu