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,50 +0,0 @@
1
- module Vedeu
2
-
3
- # Facade to access Offsets when a movement action occurs.
4
- #
5
- module Move
6
-
7
- extend self
8
-
9
- # @return [Array]
10
- def down
11
- move(1, 0)
12
- end
13
-
14
- # @return [Array]
15
- def up
16
- move(-1, 0)
17
- end
18
-
19
- # @return [Array]
20
- def right
21
- move(0, 1)
22
- end
23
-
24
- # @return [Array]
25
- def left
26
- move(0, -1)
27
- end
28
-
29
- private
30
-
31
- # @param y [Fixnum]
32
- # @param x [Fixnum]
33
- # @return [Array]
34
- def move(y, x)
35
- Offsets.move(y, x)
36
-
37
- Focus.refresh
38
- end
39
-
40
- # System events which when called will move in the direction specified;
41
- # these will update the cursor position or content offset (scrolling)
42
- # according to the interface in focus.
43
- Vedeu.event(:_cursor_up_) { up }
44
- Vedeu.event(:_cursor_right_) { right }
45
- Vedeu.event(:_cursor_down_) { down }
46
- Vedeu.event(:_cursor_left_) { left }
47
-
48
- end # Move
49
-
50
- end # Vedeu
@@ -1,242 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
- describe Area do
5
- let(:area) { Area.new(attributes) }
6
- let(:attributes) {
7
- {
8
- y_min: 1,
9
- x_min: 1,
10
- height: 3,
11
- width: 3,
12
- }
13
- }
14
-
15
- describe '#initialize' do
16
- it 'returns an instance of itself' do
17
- area.must_be_instance_of(Area)
18
- end
19
- end
20
-
21
- describe '#y_range' do
22
- let(:attributes) { { y_min: 7, x_min: 1, height: 4, width: 3 } }
23
-
24
- it 'returns the actual y range' do
25
- area.y_range.must_equal([7, 8, 9, 10])
26
- end
27
-
28
- context 'when the height is 0' do
29
- let(:attributes) { { y_min: 7, x_min: 1, height: 0, width: 3 } }
30
-
31
- it 'returns an empty range' do
32
- area.y_range.must_equal([])
33
- end
34
- end
35
- end
36
-
37
- describe '#x_range' do
38
- let(:attributes) { { y_min: 1, x_min: 4, height: 3, width: 10 } }
39
-
40
- it 'returns the actual x range' do
41
- area.x_range.must_equal([4, 5, 6, 7, 8, 9, 10, 11, 12, 13])
42
- end
43
-
44
- context 'when the width is 0' do
45
- let(:attributes) { { y_min: 1, x_min: 4, height: 3, width: 0 } }
46
-
47
- it 'returns an empty range' do
48
- area.x_range.must_equal([])
49
- end
50
- end
51
- end
52
-
53
- describe '#y_indices' do
54
- let(:attributes) { { y_min: 7, x_min: 1, height: 4, width: 3 } }
55
-
56
- it 'returns the indices for y' do
57
- area.y_indices.must_equal([0, 1, 2, 3])
58
- end
59
-
60
- context 'when the height is 0' do
61
- let(:attributes) { { y_min: 7, x_min: 1, height: 0, width: 3 } }
62
-
63
- it { area.y_indices.must_be_empty }
64
- end
65
-
66
- context 'when the height is less than 0' do
67
- let(:attributes) { { y_min: 7, x_min: 1, height: -3, width: 3 } }
68
-
69
- it { area.y_indices.must_be_empty }
70
- end
71
- end
72
-
73
- describe '#x_indices' do
74
- let(:attributes) { { y_min: 1, x_min: 4, height: 3, width: 10 } }
75
-
76
- it 'returns the indices for x' do
77
- area.x_indices.must_equal([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
78
- end
79
-
80
- context 'when the width is 0' do
81
- let(:attributes) { { y_min: 7, x_min: 1, height: 3, width: 0 } }
82
-
83
- it { area.x_indices.must_be_empty }
84
- end
85
-
86
- context 'when the width is less than 0' do
87
- let(:attributes) { { y_min: 7, x_min: 1, height: 3, width: -2 } }
88
-
89
- it { area.x_indices.must_be_empty }
90
- end
91
- end
92
-
93
- describe '#y_max' do
94
- context 'when the height is > 0' do
95
- let(:attributes) { { y_min: 7, x_min: 1, height: 3, width: 6 } }
96
-
97
- it { area.y_max.must_equal(10) }
98
- end
99
-
100
- context 'when the height is 0 or negative' do
101
- let(:attributes) { { y_min: 7, x_min: 1, height: 0, width: 6 } }
102
-
103
- it { area.y_max.must_equal(0) }
104
- end
105
- end
106
-
107
- describe '#x_max' do
108
- context 'when the width is > 0' do
109
- let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: 6 } }
110
-
111
- it { area.x_max.must_equal(7) }
112
- end
113
-
114
- context 'when the width is 0 or negative' do
115
- let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: 0 } }
116
-
117
- it { area.x_max.must_equal(0) }
118
- end
119
- end
120
-
121
- describe '#y_max_index' do
122
- context 'when the height is > 0' do
123
- let(:attributes) { { y_min: 7, x_min: 1, height: 3, width: 6 } }
124
-
125
- it { area.y_max_index.must_equal(2) }
126
- end
127
-
128
- context 'when the height is 0' do
129
- let(:attributes) { { y_min: 7, x_min: 1, height: 0, width: 6 } }
130
-
131
- it { area.y_max_index.must_equal(0) }
132
- end
133
-
134
- context 'when the height is < 0' do
135
- let(:attributes) { { y_min: 9, x_min: 1, height: -3, width: 6 } }
136
-
137
- it { area.y_max_index.must_equal(0) }
138
- end
139
- end
140
-
141
- describe '#x_max_index' do
142
- context 'when the width is > 0' do
143
- let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: 6 } }
144
-
145
- it { area.x_max_index.must_equal(5) }
146
- end
147
-
148
- context 'when the width is 0' do
149
- let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: 0 } }
150
-
151
- it { area.x_max_index.must_equal(0) }
152
- end
153
-
154
- context 'when the width is < 0' do
155
- let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: -2 } }
156
-
157
- it { area.x_max_index.must_equal(0) }
158
- end
159
- end
160
-
161
- describe '#y_index' do
162
- let(:attributes) { { y_min: 7, x_min: 4, height: height, width: 10, x: 8, y: y } }
163
- let(:height) { 3 }
164
- let(:y) { 8 }
165
-
166
- it 'returns the offset index of the cursors y position' do
167
- area.y_index.must_equal(1)
168
- end
169
-
170
- context 'when the area height is 0' do
171
- let(:height) { 0 }
172
-
173
- it { area.y_index.must_equal(0) }
174
- end
175
-
176
- context 'when the cursor y is less than or equal to the area y_min' do
177
- let(:y) { 6 }
178
-
179
- it { area.y_index.must_equal(0) }
180
- end
181
-
182
- context 'when the cursor y is more than or equal to the area y_max' do
183
- let(:y) { 20 }
184
-
185
- it 'returns the last y coordinate as an index' do
186
- area.y_index.must_equal(2)
187
- end
188
- end
189
- end
190
-
191
- describe '#x_index' do
192
- let(:attributes) { { y_min: 7, x_min: 4, height: 3, width: width, x: x, y: 8 } }
193
- let(:x) { 8 }
194
- let(:width) { 10 }
195
-
196
- it 'returns the offset index of the cursors x position' do
197
- area.x_index.must_equal(4)
198
- end
199
-
200
- context 'when the area width is 0' do
201
- let(:width) { 0 }
202
-
203
- it { area.x_index.must_equal(0) }
204
- end
205
-
206
- context 'when the cursor x is less than or equal to the area x_min' do
207
- let(:x) { 3 }
208
-
209
- it { area.x_index.must_equal(0) }
210
- end
211
-
212
- context 'when the cursor x is more than or equal to the area x_min' do
213
- let(:x) { 20 }
214
-
215
- it 'returns the last x coordinate as an index' do
216
- area.x_index.must_equal(9)
217
- end
218
- end
219
- end
220
-
221
- describe '#y_position' do
222
- context 'when the index is less than or equal to 0' do
223
- it 'returns #y_min' do
224
-
225
- end
226
- end
227
-
228
- context 'when the index is greater than or equal to y_max_index' do
229
- it 'returns #y_max' do
230
-
231
- end
232
- end
233
-
234
- context 'when the index is in range' do
235
- it 'returns the associated real position' do
236
-
237
- end
238
- end
239
- end
240
-
241
- end
242
- end
@@ -1,35 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
- describe Move do
5
- before do
6
- Interfaces.reset
7
- Registrar.record({ name: 'thorium' })
8
- Terminal.console.stubs(:print)
9
- end
10
-
11
- context 'when no interfaces are defined' do
12
- before { Interfaces.reset }
13
-
14
- it { proc { Move.down }.must_raise(NoInterfacesDefined) }
15
-
16
- it { proc { Move.up }.must_raise(NoInterfacesDefined) }
17
-
18
- it { proc { Move.right }.must_raise(NoInterfacesDefined) }
19
-
20
- it { proc { Move.left }.must_raise(NoInterfacesDefined) }
21
- end
22
-
23
- context 'when there is at least one interface defined' do
24
- before { Focus.stubs(:current).returns('thorium') }
25
-
26
- it { Move.down.must_be_instance_of(Array) }
27
-
28
- it { Move.up.must_be_instance_of(Array) }
29
-
30
- it { Move.right.must_be_instance_of(Array) }
31
-
32
- it { Move.left.must_be_instance_of(Array) }
33
- end
34
- end
35
- end