vedeu 0.6.9 → 0.6.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/lib/vedeu/all.rb +3 -3
  4. data/lib/vedeu/api/external.rb +194 -0
  5. data/lib/vedeu/api/internal.rb +173 -0
  6. data/lib/vedeu/application/controller.rb +3 -2
  7. data/lib/vedeu/bindings/application.rb +1 -1
  8. data/lib/vedeu/bindings/drb.rb +2 -3
  9. data/lib/vedeu/bindings/movement.rb +1 -1
  10. data/lib/vedeu/buffers/all.rb +0 -2
  11. data/lib/vedeu/colours/translator.rb +2 -1
  12. data/lib/vedeu/common.rb +4 -2
  13. data/lib/vedeu/configuration/api.rb +1 -1
  14. data/lib/vedeu/configuration/cli.rb +1 -1
  15. data/lib/vedeu/cursors/repository.rb +1 -1
  16. data/lib/vedeu/editor/insert.rb +12 -13
  17. data/lib/vedeu/geometry/position.rb +1 -1
  18. data/lib/vedeu/models/cell.rb +35 -21
  19. data/lib/vedeu/models/escape.rb +18 -1
  20. data/lib/vedeu/models/page.rb +20 -10
  21. data/lib/vedeu/models/row.rb +18 -8
  22. data/lib/vedeu/models/views/char.rb +9 -7
  23. data/lib/vedeu/models/views/view.rb +1 -1
  24. data/lib/vedeu/output/compressor.rb +22 -14
  25. data/lib/vedeu/output/output.rb +1 -10
  26. data/lib/vedeu/output/renderers/escape_sequence.rb +8 -4
  27. data/lib/vedeu/output/renderers/file.rb +7 -23
  28. data/lib/vedeu/output/renderers/html.rb +47 -26
  29. data/lib/vedeu/output/renderers/json.rb +11 -16
  30. data/lib/vedeu/output/renderers/null.rb +1 -1
  31. data/lib/vedeu/output/renderers/renderer_options.rb +2 -1
  32. data/lib/vedeu/output/renderers/terminal.rb +7 -15
  33. data/lib/vedeu/output/renderers/text.rb +1 -1
  34. data/lib/vedeu/output/viewport.rb +154 -143
  35. data/lib/vedeu/repositories/collection.rb +2 -2
  36. data/lib/vedeu/repositories/model.rb +25 -26
  37. data/lib/vedeu/repositories/registerable.rb +9 -8
  38. data/lib/vedeu/repositories/repository.rb +21 -16
  39. data/lib/vedeu/repositories/store.rb +6 -4
  40. data/lib/vedeu/runtime/bootstrap.rb +7 -5
  41. data/lib/vedeu/runtime/main_loop.rb +2 -0
  42. data/lib/vedeu/runtime/router.rb +155 -149
  43. data/lib/vedeu/templating/decoder.rb +8 -5
  44. data/lib/vedeu/templating/encoder.rb +6 -4
  45. data/lib/vedeu/templating/template.rb +2 -2
  46. data/lib/vedeu/templating/view_template.rb +8 -7
  47. data/lib/vedeu/terminal/buffer.rb +132 -0
  48. data/lib/vedeu/terminal/terminal.rb +0 -5
  49. data/lib/vedeu/version.rb +1 -1
  50. data/lib/vedeu.rb +2 -2
  51. data/out_ +50 -0
  52. data/test/lib/vedeu/api/external_test.rb +62 -0
  53. data/test/lib/vedeu/{internal_api_test.rb → api/internal_test.rb} +6 -2
  54. data/test/lib/vedeu/application/controller_test.rb +3 -3
  55. data/test/lib/vedeu/bindings/application_test.rb +2 -2
  56. data/test/lib/vedeu/models/cell_test.rb +48 -17
  57. data/test/lib/vedeu/models/escape_test.rb +29 -7
  58. data/test/lib/vedeu/models/page_test.rb +70 -50
  59. data/test/lib/vedeu/models/row_test.rb +40 -20
  60. data/test/lib/vedeu/output/compressor_test.rb +12 -12
  61. data/test/lib/vedeu/output/output_test.rb +17 -23
  62. data/test/lib/vedeu/output/renderers/escape_sequence_test.rb +15 -11
  63. data/test/lib/vedeu/output/renderers/html_test.rb +66 -68
  64. data/test/lib/vedeu/output/renderers/json_test.rb +36 -83
  65. data/test/lib/vedeu/output/renderers/terminal_test.rb +22 -2
  66. data/test/lib/vedeu/output/viewport_test.rb +201 -197
  67. data/test/lib/vedeu/runtime/router_test.rb +144 -140
  68. data/test/lib/vedeu/terminal/buffer_test.rb +307 -0
  69. data/test/support/examples/material_colours_app.rb +2 -2
  70. data/test/support/templates/html_renderer.vedeu +24 -0
  71. metadata +14 -17
  72. data/lib/vedeu/api.rb +0 -190
  73. data/lib/vedeu/buffers/virtual_buffer.rb +0 -136
  74. data/lib/vedeu/buffers/virtual_buffers.rb +0 -77
  75. data/lib/vedeu/internal_api.rb +0 -173
  76. data/lib/vedeu/terminal/content.rb +0 -88
  77. data/test/lib/vedeu/api_test.rb +0 -58
  78. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +0 -148
  79. data/test/lib/vedeu/buffers/virtual_buffers_test.rb +0 -73
  80. data/test/lib/vedeu/terminal/content_test.rb +0 -108
@@ -2,169 +2,111 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
 
5
- describe Viewport do
6
-
7
- let(:described) { Vedeu::Viewport }
8
- let(:instance) { described.new(view) }
9
- let(:view) {
10
- Vedeu::Views::View.build(name: 'lithium', style: nil) do
11
- lines do
12
- line 'barium'
13
- line 'carbon'
14
- line 'helium'
15
- line 'iodine'
16
- line 'nickel'
17
- line 'osmium'
5
+ module Output
6
+
7
+ describe Viewport do
8
+
9
+ let(:described) { Vedeu::Output::Viewport }
10
+ let(:instance) { described.new(view) }
11
+ let(:view) {
12
+ Vedeu::Views::View.build(name: 'lithium', style: nil) do
13
+ lines do
14
+ line 'barium'
15
+ line 'carbon'
16
+ line 'helium'
17
+ line 'iodine'
18
+ line 'nickel'
19
+ line 'osmium'
20
+ end
18
21
  end
22
+ }
23
+ let(:visible) { true }
24
+ let(:interface) {
25
+ Vedeu::Models::Interface.new(style: nil, visible: visible)
26
+ }
27
+ let(:geometry) { Vedeu::Geometry::Geometry.new(height: 3, width: 3) }
28
+
29
+ before do
30
+ Vedeu.interfaces.stubs(:by_name).returns(interface)
31
+ Vedeu.geometries.stubs(:by_name).returns(geometry)
19
32
  end
20
- }
21
- let(:visible) { true }
22
- let(:interface) {
23
- Vedeu::Models::Interface.new(style: nil, visible: visible)
24
- }
25
- let(:geometry) { Vedeu::Geometry::Geometry.new(height: 3, width: 3) }
26
-
27
- before do
28
- Vedeu.interfaces.stubs(:by_name).returns(interface)
29
- Vedeu.geometries.stubs(:by_name).returns(geometry)
30
- end
31
- after { Vedeu.interfaces.reset }
32
-
33
- describe '#initialize' do
34
- it { instance.must_be_instance_of(described) }
35
- it { instance.instance_variable_get('@view').must_equal(view) }
36
- end
37
-
38
- describe '.render' do
39
- subject { described.render(view) }
40
-
41
- context 'when the interface is visible' do
42
- # @todo Add more tests.
43
- # it { skip }
33
+ after { Vedeu.interfaces.reset }
34
+
35
+ describe '#initialize' do
36
+ it { instance.must_be_instance_of(described) }
37
+ it { instance.instance_variable_get('@view').must_equal(view) }
44
38
  end
45
39
 
46
- context 'when the interface is not visible' do
47
- let(:visible) { false }
40
+ describe '.render' do
41
+ subject { described.render(view) }
48
42
 
49
- it { subject.must_be_instance_of(Array) }
43
+ context 'when the interface is visible' do
44
+ # @todo Add more tests.
45
+ # it { skip }
46
+ end
50
47
 
51
- it { subject.must_equal([]) }
52
- end
53
- end
54
-
55
- describe '#render' do
56
- let(:cursor) {
57
- Vedeu::Cursors::Cursor.new(name: 'lithium',
58
- ox: ox,
59
- oy: oy,
60
- visible: true,
61
- x: x,
62
- y: y) }
63
- let(:lines) { [] }
64
- let(:ox) { 0 }
65
- let(:oy) { 0 }
66
- let(:x) { 1 }
67
- let(:y) { 1 }
68
-
69
- subject { instance.render }
70
-
71
- it { subject.must_be_instance_of(Array) }
72
-
73
- context 'when there is no content' do
74
- before { view.stubs(:lines).returns([]) }
75
-
76
- it { subject.must_equal([]) }
77
- end
78
- end
79
-
80
- describe '#to_s' do
81
- let(:cursor) {
82
- Vedeu::Cursors::Cursor.new(name: 'lithium',
83
- ox: ox,
84
- oy: oy,
85
- visible: true,
86
- x: x,
87
- y: y) }
88
- let(:lines) { [] }
89
- let(:ox) { 0 }
90
- let(:oy) { 0 }
91
- let(:x) { 1 }
92
- let(:y) { 1 }
93
-
94
- subject { instance.to_s }
95
-
96
- it { subject.must_be_instance_of(String) }
97
-
98
- context 'when there is no content' do
99
- before { view.stubs(:lines).returns([]) }
100
-
101
- it { subject.must_equal('') }
48
+ context 'when the interface is not visible' do
49
+ let(:visible) { false }
50
+
51
+ it { subject.must_be_instance_of(Array) }
52
+
53
+ it { subject.must_equal([]) }
54
+ end
102
55
  end
103
56
 
104
- context 'when there is content' do
105
- context 'when the cursor y position is outside the viewable area' do
106
- let(:ox) { -4 }
107
- let(:oy) { -4 }
108
-
109
- it 'scrolls the content the correct position' do
110
- subject.must_equal(
111
- "\e[1;1H\e[39m\e[49mb\n" \
112
- "\e[1;2H\e[39m\e[49ma\n" \
113
- "\e[1;3H\e[39m\e[49mr\n" \
114
- "\e[2;1H\e[39m\e[49mc\n" \
115
- "\e[2;2H\e[39m\e[49ma\n" \
116
- "\e[2;3H\e[39m\e[49mr\n" \
117
- "\e[3;1H\e[39m\e[49mh\n" \
118
- "\e[3;2H\e[39m\e[49me\n" \
119
- "\e[3;3H\e[39m\e[49ml"
120
- )
121
- end
57
+ describe '#render' do
58
+ let(:cursor) {
59
+ Vedeu::Cursors::Cursor.new(name: 'lithium',
60
+ ox: ox,
61
+ oy: oy,
62
+ visible: true,
63
+ x: x,
64
+ y: y) }
65
+ let(:lines) { [] }
66
+ let(:ox) { 0 }
67
+ let(:oy) { 0 }
68
+ let(:x) { 1 }
69
+ let(:y) { 1 }
70
+
71
+ subject { instance.render }
72
+
73
+ it { subject.must_be_instance_of(Array) }
74
+
75
+ context 'when there is no content' do
76
+ before { view.stubs(:lines).returns([]) }
77
+
78
+ it { subject.must_equal([]) }
122
79
  end
80
+ end
123
81
 
124
- context 'when the cursor y position is inside the viewable area' do
125
- context 'when there is not enough content to fill the height' do
126
- let(:ox) { 3 }
127
- let(:oy) { 7 }
82
+ describe '#to_s' do
83
+ let(:cursor) {
84
+ Vedeu::Cursors::Cursor.new(name: 'lithium',
85
+ ox: ox,
86
+ oy: oy,
87
+ visible: true,
88
+ x: x,
89
+ y: y) }
90
+ let(:lines) { [] }
91
+ let(:ox) { 0 }
92
+ let(:oy) { 0 }
93
+ let(:x) { 1 }
94
+ let(:y) { 1 }
128
95
 
129
- it 'renders the visible content' do
130
- subject.must_equal(
131
- "\e[1;1H\e[39m\e[49mb\n" \
132
- "\e[1;2H\e[39m\e[49ma\n" \
133
- "\e[1;3H\e[39m\e[49mr\n" \
134
- "\e[2;1H\e[39m\e[49mc\n" \
135
- "\e[2;2H\e[39m\e[49ma\n" \
136
- "\e[2;3H\e[39m\e[49mr\n" \
137
- "\e[3;1H\e[39m\e[49mh\n" \
138
- "\e[3;2H\e[39m\e[49me\n" \
139
- "\e[3;3H\e[39m\e[49ml"
140
- )
141
- end
142
- end
96
+ subject { instance.to_s }
143
97
 
144
- context 'when there is more content than the height' do
145
- let(:ox) { 3 }
146
- let(:oy) { 3 }
98
+ it { subject.must_be_instance_of(String) }
147
99
 
148
- it 'is cropped to show only that which fits' do
149
- subject.must_equal(
150
- "\e[1;1H\e[39m\e[49mb\n" \
151
- "\e[1;2H\e[39m\e[49ma\n" \
152
- "\e[1;3H\e[39m\e[49mr\n" \
153
- "\e[2;1H\e[39m\e[49mc\n" \
154
- "\e[2;2H\e[39m\e[49ma\n" \
155
- "\e[2;3H\e[39m\e[49mr\n" \
156
- "\e[3;1H\e[39m\e[49mh\n" \
157
- "\e[3;2H\e[39m\e[49me\n" \
158
- "\e[3;3H\e[39m\e[49ml"
159
- )
160
- end
161
- end
100
+ context 'when there is no content' do
101
+ before { view.stubs(:lines).returns([]) }
102
+
103
+ it { subject.must_equal('') }
162
104
  end
163
105
 
164
- context 'when the cursor x position is outside the viewable area' do
165
- context 'but inside the content' do
166
- let(:ox) { 6 }
167
- let(:oy) { 6 }
106
+ context 'when there is content' do
107
+ context 'when the cursor y position is outside the viewable area' do
108
+ let(:ox) { -4 }
109
+ let(:oy) { -4 }
168
110
 
169
111
  it 'scrolls the content the correct position' do
170
112
  subject.must_equal(
@@ -181,68 +123,130 @@ module Vedeu
181
123
  end
182
124
  end
183
125
 
184
- context 'and outside the content' do
185
- let(:ox) { 7 }
186
- let(:oy) { 7 }
126
+ context 'when the cursor y position is inside the viewable area' do
127
+ context 'when there is not enough content to fill the height' do
128
+ let(:ox) { 3 }
129
+ let(:oy) { 7 }
130
+
131
+ it 'renders the visible content' do
132
+ subject.must_equal(
133
+ "\e[1;1H\e[39m\e[49mb\n" \
134
+ "\e[1;2H\e[39m\e[49ma\n" \
135
+ "\e[1;3H\e[39m\e[49mr\n" \
136
+ "\e[2;1H\e[39m\e[49mc\n" \
137
+ "\e[2;2H\e[39m\e[49ma\n" \
138
+ "\e[2;3H\e[39m\e[49mr\n" \
139
+ "\e[3;1H\e[39m\e[49mh\n" \
140
+ "\e[3;2H\e[39m\e[49me\n" \
141
+ "\e[3;3H\e[39m\e[49ml"
142
+ )
143
+ end
144
+ end
187
145
 
188
- it 'scrolls the content the correct position' do
189
- subject.must_equal(
190
- "\e[1;1H\e[39m\e[49mb\n" \
191
- "\e[1;2H\e[39m\e[49ma\n" \
192
- "\e[1;3H\e[39m\e[49mr\n" \
193
- "\e[2;1H\e[39m\e[49mc\n" \
194
- "\e[2;2H\e[39m\e[49ma\n" \
195
- "\e[2;3H\e[39m\e[49mr\n" \
196
- "\e[3;1H\e[39m\e[49mh\n" \
197
- "\e[3;2H\e[39m\e[49me\n" \
198
- "\e[3;3H\e[39m\e[49ml"
199
- )
146
+ context 'when there is more content than the height' do
147
+ let(:ox) { 3 }
148
+ let(:oy) { 3 }
149
+
150
+ it 'is cropped to show only that which fits' do
151
+ subject.must_equal(
152
+ "\e[1;1H\e[39m\e[49mb\n" \
153
+ "\e[1;2H\e[39m\e[49ma\n" \
154
+ "\e[1;3H\e[39m\e[49mr\n" \
155
+ "\e[2;1H\e[39m\e[49mc\n" \
156
+ "\e[2;2H\e[39m\e[49ma\n" \
157
+ "\e[2;3H\e[39m\e[49mr\n" \
158
+ "\e[3;1H\e[39m\e[49mh\n" \
159
+ "\e[3;2H\e[39m\e[49me\n" \
160
+ "\e[3;3H\e[39m\e[49ml"
161
+ )
162
+ end
200
163
  end
201
164
  end
202
- end
203
165
 
204
- context 'when the cursor x position is inside the viewable area' do
205
- context 'when there is not enough content to fill the width' do
206
- let(:ox) { 7 }
207
- let(:oy) { 3 }
166
+ context 'when the cursor x position is outside the viewable area' do
167
+ context 'but inside the content' do
168
+ let(:ox) { 6 }
169
+ let(:oy) { 6 }
170
+
171
+ it 'scrolls the content the correct position' do
172
+ subject.must_equal(
173
+ "\e[1;1H\e[39m\e[49mb\n" \
174
+ "\e[1;2H\e[39m\e[49ma\n" \
175
+ "\e[1;3H\e[39m\e[49mr\n" \
176
+ "\e[2;1H\e[39m\e[49mc\n" \
177
+ "\e[2;2H\e[39m\e[49ma\n" \
178
+ "\e[2;3H\e[39m\e[49mr\n" \
179
+ "\e[3;1H\e[39m\e[49mh\n" \
180
+ "\e[3;2H\e[39m\e[49me\n" \
181
+ "\e[3;3H\e[39m\e[49ml"
182
+ )
183
+ end
184
+ end
208
185
 
209
- it 'renders the visible content' do
210
- subject.must_equal(
211
- "\e[1;1H\e[39m\e[49mb\n" \
212
- "\e[1;2H\e[39m\e[49ma\n" \
213
- "\e[1;3H\e[39m\e[49mr\n" \
214
- "\e[2;1H\e[39m\e[49mc\n" \
215
- "\e[2;2H\e[39m\e[49ma\n" \
216
- "\e[2;3H\e[39m\e[49mr\n" \
217
- "\e[3;1H\e[39m\e[49mh\n" \
218
- "\e[3;2H\e[39m\e[49me\n" \
219
- "\e[3;3H\e[39m\e[49ml"
220
- )
186
+ context 'and outside the content' do
187
+ let(:ox) { 7 }
188
+ let(:oy) { 7 }
189
+
190
+ it 'scrolls the content the correct position' do
191
+ subject.must_equal(
192
+ "\e[1;1H\e[39m\e[49mb\n" \
193
+ "\e[1;2H\e[39m\e[49ma\n" \
194
+ "\e[1;3H\e[39m\e[49mr\n" \
195
+ "\e[2;1H\e[39m\e[49mc\n" \
196
+ "\e[2;2H\e[39m\e[49ma\n" \
197
+ "\e[2;3H\e[39m\e[49mr\n" \
198
+ "\e[3;1H\e[39m\e[49mh\n" \
199
+ "\e[3;2H\e[39m\e[49me\n" \
200
+ "\e[3;3H\e[39m\e[49ml"
201
+ )
202
+ end
221
203
  end
222
204
  end
223
205
 
224
- context 'when there is more content than the width' do
225
- let(:ox) { 3 }
226
- let(:oy) { 3 }
206
+ context 'when the cursor x position is inside the viewable area' do
207
+ context 'when there is not enough content to fill the width' do
208
+ let(:ox) { 7 }
209
+ let(:oy) { 3 }
210
+
211
+ it 'renders the visible content' do
212
+ subject.must_equal(
213
+ "\e[1;1H\e[39m\e[49mb\n" \
214
+ "\e[1;2H\e[39m\e[49ma\n" \
215
+ "\e[1;3H\e[39m\e[49mr\n" \
216
+ "\e[2;1H\e[39m\e[49mc\n" \
217
+ "\e[2;2H\e[39m\e[49ma\n" \
218
+ "\e[2;3H\e[39m\e[49mr\n" \
219
+ "\e[3;1H\e[39m\e[49mh\n" \
220
+ "\e[3;2H\e[39m\e[49me\n" \
221
+ "\e[3;3H\e[39m\e[49ml"
222
+ )
223
+ end
224
+ end
227
225
 
228
- it 'is cropped to show only that which fits' do
229
- subject.must_equal(
230
- "\e[1;1H\e[39m\e[49mb\n" \
231
- "\e[1;2H\e[39m\e[49ma\n" \
232
- "\e[1;3H\e[39m\e[49mr\n" \
233
- "\e[2;1H\e[39m\e[49mc\n" \
234
- "\e[2;2H\e[39m\e[49ma\n" \
235
- "\e[2;3H\e[39m\e[49mr\n" \
236
- "\e[3;1H\e[39m\e[49mh\n" \
237
- "\e[3;2H\e[39m\e[49me\n" \
238
- "\e[3;3H\e[39m\e[49ml"
239
- )
226
+ context 'when there is more content than the width' do
227
+ let(:ox) { 3 }
228
+ let(:oy) { 3 }
229
+
230
+ it 'is cropped to show only that which fits' do
231
+ subject.must_equal(
232
+ "\e[1;1H\e[39m\e[49mb\n" \
233
+ "\e[1;2H\e[39m\e[49ma\n" \
234
+ "\e[1;3H\e[39m\e[49mr\n" \
235
+ "\e[2;1H\e[39m\e[49mc\n" \
236
+ "\e[2;2H\e[39m\e[49ma\n" \
237
+ "\e[2;3H\e[39m\e[49mr\n" \
238
+ "\e[3;1H\e[39m\e[49mh\n" \
239
+ "\e[3;2H\e[39m\e[49me\n" \
240
+ "\e[3;3H\e[39m\e[49ml"
241
+ )
242
+ end
240
243
  end
241
244
  end
242
245
  end
243
246
  end
244
- end
245
247
 
246
- end # Viewport
248
+ end # Viewport
249
+
250
+ end # Output
247
251
 
248
252
  end # Vedeu