vedeu 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +5 -0
  3. data/README.md +34 -0
  4. data/deps.md +13 -13
  5. data/lib/vedeu.rb +1 -1
  6. data/lib/vedeu/instrumentation.rb +1 -1
  7. data/lib/vedeu/models/geometry.rb +76 -0
  8. data/lib/vedeu/models/interface.rb +9 -21
  9. data/lib/vedeu/models/stream.rb +16 -4
  10. data/lib/vedeu/output/clear_interface.rb +4 -4
  11. data/lib/vedeu/{support/translator.rb → output/colour_translator.rb} +1 -1
  12. data/lib/vedeu/output/erb_parser.rb +11 -0
  13. data/lib/vedeu/output/raw_parser.rb +9 -1
  14. data/lib/vedeu/output/render_interface.rb +3 -3
  15. data/lib/vedeu/support/esc.rb +8 -6
  16. data/lib/vedeu/support/helpers.rb +39 -18
  17. data/lib/vedeu/support/interface_template.rb +42 -19
  18. data/test/lib/vedeu/models/composition_test.rb +27 -21
  19. data/test/lib/vedeu/models/geometry_test.rb +183 -0
  20. data/test/lib/vedeu/models/interface_test.rb +26 -59
  21. data/test/lib/vedeu/models/stream_test.rb +57 -7
  22. data/test/lib/vedeu/output/clear_interface_test.rb +8 -4
  23. data/test/lib/vedeu/{support/translator_test.rb → output/colour_translator_test.rb} +8 -8
  24. data/test/lib/vedeu/output/erb_parser_test.rb +158 -70
  25. data/test/lib/vedeu/output/render_interface_test.rb +4 -3
  26. data/test/lib/vedeu/support/esc_test.rb +10 -2
  27. data/test/lib/vedeu/support/helpers_test.rb +11 -4
  28. data/test/lib/vedeu/support/interface_template_test.rb +58 -34
  29. data/test/support/colours.rb +2 -2
  30. data/test/support/erb/line.erb +4 -0
  31. data/test/support/erb/line_2x.erb +10 -0
  32. data/test/support/erb/line_foreground.erb +4 -0
  33. data/test/support/erb/line_foreground_2x.erb +5 -0
  34. data/vedeu.gemspec +2 -1
  35. metadata +30 -8
  36. data/lib/vedeu/support/geometry.rb +0 -172
  37. data/test/lib/vedeu/support/geometry_test.rb +0 -408
@@ -11,10 +11,12 @@ module Vedeu
11
11
  foreground: '#ff0000',
12
12
  background: '#000000'
13
13
  },
14
- y: 3,
15
- x: 5,
16
- width: 10,
17
- height: 15,
14
+ geometry: {
15
+ y: 3,
16
+ x: 5,
17
+ width: 10,
18
+ height: 15,
19
+ },
18
20
  current: "\e[1;1H#initialize"
19
21
  })
20
22
  }
@@ -31,24 +33,6 @@ module Vedeu
31
33
  interface.colour.must_be_instance_of(Colour)
32
34
  end
33
35
 
34
- it 'has a y attribute' do
35
- interface.y.must_equal(3)
36
- Interface.new.y.must_equal(1)
37
- end
38
-
39
- it 'has an x attribute' do
40
- interface.x.must_equal(5)
41
- Interface.new.x.must_equal(1)
42
- end
43
-
44
- it 'has a width attribute' do
45
- interface.width.must_equal(10)
46
- end
47
-
48
- it 'has a height attribute' do
49
- interface.height.must_equal(15)
50
- end
51
-
52
36
  it 'has a current attribute' do
53
37
  interface.current.must_equal("\e[1;1H#initialize")
54
38
  end
@@ -58,18 +42,15 @@ module Vedeu
58
42
  Interface.new({ cursor: false }).cursor.must_equal(false)
59
43
  end
60
44
 
61
- it 'has a centred attribute' do
62
- interface.centred.must_equal(false)
63
- Interface.new({ centred: true }).centred.must_equal(true)
64
- end
65
-
66
45
  describe '#enqueue' do
67
46
  it 'delegates to the Queue class to enqueue itself' do
68
47
  Queue.reset
69
48
  interface = Interface.new({
70
49
  name: 'Interface#enqueue',
71
- width: 8,
72
- height: 2,
50
+ geometry: {
51
+ width: 8,
52
+ height: 2,
53
+ },
73
54
  lines: [ { streams: { text: 'a8f39' } } ]
74
55
  })
75
56
  interface.enqueue
@@ -81,28 +62,6 @@ module Vedeu
81
62
  end
82
63
  end
83
64
 
84
- describe '#geometry' do
85
- it 'delegates to the Geometry class' do
86
- interface = Interface.new({
87
- name: '#geometry',
88
- width: 5,
89
- height: 5
90
- })
91
- interface.geometry.must_be_instance_of(Geometry)
92
- end
93
- end
94
-
95
- describe '#origin' do
96
- it 'delegates to the Geometry class to get the origin' do
97
- interface = Interface.new({
98
- name: '#origin',
99
- width: 5,
100
- height: 5
101
- })
102
- interface.origin.must_equal("\e[1;1H")
103
- end
104
- end
105
-
106
65
  describe '#refresh' do
107
66
  let(:attributes) {
108
67
  {
@@ -112,8 +71,10 @@ module Vedeu
112
71
  foreground: '#ff0000',
113
72
  background: '#000000'
114
73
  },
115
- width: 3,
116
- height: 3
74
+ geometry: {
75
+ width: 3,
76
+ height: 3
77
+ }
117
78
  }
118
79
  }
119
80
 
@@ -140,8 +101,10 @@ module Vedeu
140
101
  foreground: '#ff0000',
141
102
  background: '#000000'
142
103
  },
143
- width: 11,
144
- height: 3
104
+ geometry: {
105
+ width: 11,
106
+ height: 3
107
+ }
145
108
  }
146
109
  interface = Interface.new(attributes)
147
110
  interface.enqueue
@@ -167,8 +130,10 @@ module Vedeu
167
130
  foreground: '#ff0000',
168
131
  background: '#000000'
169
132
  },
170
- width: 11,
171
- height: 3
133
+ geometry: {
134
+ width: 11,
135
+ height: 3
136
+ }
172
137
  }
173
138
  interface = Interface.new(attributes)
174
139
  interface.current = "\e[38;5;196m\e[48;5;16m" \
@@ -202,8 +167,10 @@ module Vedeu
202
167
  foreground: '#ff0000',
203
168
  background: '#000000'
204
169
  },
205
- width: 3,
206
- height: 3
170
+ geometry: {
171
+ width: 3,
172
+ height: 3
173
+ }
207
174
  }).to_s.must_equal(
208
175
  "\e[38;5;196m\e[48;5;16m" \
209
176
  "\e[1;1H \e[1;1H" \
@@ -10,9 +10,13 @@ module Vedeu
10
10
  background: '#000000'
11
11
  },
12
12
  text: 'Some text',
13
- style: 'normal'
13
+ style: 'normal',
14
+ width: width,
15
+ align: align
14
16
  })
15
17
  }
18
+ let(:align) { :left }
19
+ let(:width) { 9 }
16
20
 
17
21
  it 'has a colour attribute' do
18
22
  stream.colour.must_be_instance_of(Colour)
@@ -26,13 +30,59 @@ module Vedeu
26
30
  stream.style.must_equal("\e[24m\e[21m\e[27m")
27
31
  end
28
32
 
33
+ it 'has a width attribute' do
34
+ stream.width.must_equal(9)
35
+ end
36
+
37
+ it 'has an align attribute' do
38
+ stream.align.must_equal(:left)
39
+ end
40
+
29
41
  describe '#to_s' do
30
- it 'returns a String' do
31
- stream.to_s.must_equal(
32
- "\e[38;5;196m\e[48;5;16m" \
33
- "\e[24m\e[21m\e[27m" \
34
- "Some text"
35
- )
42
+ describe 'when a width is set and align is default' do
43
+ let(:width) { 20 }
44
+
45
+ it 'returns a String' do
46
+ stream.to_s.must_equal(
47
+ "\e[38;5;196m\e[48;5;16m" \
48
+ "\e[24m\e[21m\e[27m" \
49
+ "Some text "
50
+ )
51
+ end
52
+
53
+ describe 'and align is :centre' do
54
+ let(:align) { :centre }
55
+
56
+ it 'returns a String' do
57
+ stream.to_s.must_equal(
58
+ "\e[38;5;196m\e[48;5;16m" \
59
+ "\e[24m\e[21m\e[27m" \
60
+ " Some text "
61
+ )
62
+ end
63
+ end
64
+
65
+ describe 'and align is :right' do
66
+ let(:align) { :right }
67
+
68
+ it 'returns a String' do
69
+ stream.to_s.must_equal(
70
+ "\e[38;5;196m\e[48;5;16m" \
71
+ "\e[24m\e[21m\e[27m" \
72
+ " Some text"
73
+ )
74
+ end
75
+ end
76
+ end
77
+
78
+ describe 'when a width is not set' do
79
+ it 'returns a String' do
80
+ stream.to_s.must_equal(
81
+ "\e[38;5;196m\e[48;5;16m" \
82
+ "\e[24m\e[21m\e[27m" \
83
+ "Some text"
84
+ )
85
+ end
36
86
  end
37
87
  end
38
88
  end
@@ -11,8 +11,10 @@ module Vedeu
11
11
  it 'returns the escape sequence to clear the whole interface' do
12
12
  interface = Interface.new({
13
13
  name: 'ClearInterface.call',
14
- width: 5,
15
- height: 2
14
+ geometry: {
15
+ width: 5,
16
+ height: 2
17
+ }
16
18
  })
17
19
  ClearInterface.call(interface).must_equal(
18
20
  "\e[1;1H \e[1;1H" \
@@ -23,8 +25,10 @@ module Vedeu
23
25
  it 'returns the escape sequence to clear the whole interface with specified colours' do
24
26
  interface = Interface.new({
25
27
  name: 'ClearInterface.call',
26
- width: 5,
27
- height: 2,
28
+ geometry: {
29
+ width: 5,
30
+ height: 2,
31
+ },
28
32
  colour: {
29
33
  foreground: '#00ff00',
30
34
  background: '#ffff00'
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
- require 'vedeu/support/translator'
2
+ require 'vedeu/output/colour_translator'
3
3
 
4
4
  module Vedeu
5
- describe Translator do
5
+ describe ColourTranslator do
6
6
  describe '#translate' do
7
7
  {
8
8
  '#ff0000' => 196, # red
@@ -13,29 +13,29 @@ module Vedeu
13
13
  '#b94f1c' => 130, # sunset orange
14
14
  }.map do |html_colour, terminal_colour|
15
15
  it 'translation is performed' do
16
- Translator.translate(html_colour)
16
+ ColourTranslator.translate(html_colour)
17
17
  .must_equal(terminal_colour)
18
18
  end
19
19
  end
20
20
 
21
21
  it 'returns empty string when not present' do
22
- Translator.translate.must_equal('')
22
+ ColourTranslator.translate.must_equal('')
23
23
  end
24
24
 
25
25
  it 'returns empty string when the wrong type!' do
26
- Translator.translate(:wrong_type).must_equal('')
26
+ ColourTranslator.translate(:wrong_type).must_equal('')
27
27
  end
28
28
 
29
29
  it 'returns empty string when invalid format' do
30
- Translator.translate('345678').must_equal('')
30
+ ColourTranslator.translate('345678').must_equal('')
31
31
  end
32
32
 
33
33
  it 'returns empty string when invalid format' do
34
- Translator.translate('#h11111').must_equal('')
34
+ ColourTranslator.translate('#h11111').must_equal('')
35
35
  end
36
36
 
37
37
  it 'returns empty string when invalid format' do
38
- Translator.translate('#1111').must_equal('')
38
+ ColourTranslator.translate('#1111').must_equal('')
39
39
  end
40
40
  end
41
41
  end
@@ -68,85 +68,173 @@ module Vedeu
68
68
  end
69
69
  end
70
70
 
71
- describe 'colour parsing' do
72
- it 'parses the template and colour directives within' do
73
- user_view = UserView.new
74
- user_view.stub(:path, 'test/support/erb/colour.erb') do
75
- ERBParser.parse(user_view).must_equal(
76
- {
77
- interfaces: [
78
- {
79
- name: 'test',
80
- lines: [
81
- {
82
- streams: {
83
- text: "\e[38;5;52mDark red text on default background."
84
- }
85
- }, {
86
- streams: {
87
- text: "\e[48;5;201mDefault text on magenta background."
88
- }
89
- }, {
90
- streams: {
91
- text: "\e[38;5;196m\e[48;5;17mRed text on dark blue background."
92
- }
71
+
72
+ it 'parses the template and colour directives within' do
73
+ user_view = UserView.new
74
+ user_view.stub(:path, 'test/support/erb/colour.erb') do
75
+ ERBParser.parse(user_view).must_equal(
76
+ {
77
+ interfaces: [
78
+ {
79
+ name: 'test',
80
+ lines: [
81
+ {
82
+ streams: {
83
+ text: "\e[38;5;52mDark red text on default background."
93
84
  }
94
- ]
95
- }
96
- ]
97
- }
98
- )
99
- end
85
+ }, {
86
+ streams: {
87
+ text: "\e[48;5;201mDefault text on magenta background."
88
+ }
89
+ }, {
90
+ streams: {
91
+ text: "\e[38;5;196m\e[48;5;17mRed text on dark blue background."
92
+ }
93
+ }
94
+ ]
95
+ }
96
+ ]
97
+ }
98
+ )
100
99
  end
101
100
  end
102
101
 
103
- describe 'style parsing' do
104
- it 'parses the template and style directives within' do
105
- user_view = UserView.new
106
- user_view.stub(:path, 'test/support/erb/style.erb') do
107
- ERBParser.parse(user_view).must_equal(
108
- {
109
- interfaces: [
110
- {
111
- name: 'test',
112
- lines: [
113
- {
114
- streams: { text: 'Empty style leads to nothing.' }
115
- }, {
116
- streams: { text: "\e[4mUnderlined text." }
117
- }, {
118
- streams: { text: 'Unknown style leads to nothing.' }
102
+ it 'parses the template and style directives within' do
103
+ user_view = UserView.new
104
+ user_view.stub(:path, 'test/support/erb/style.erb') do
105
+ ERBParser.parse(user_view).must_equal(
106
+ {
107
+ interfaces: [
108
+ {
109
+ name: 'test',
110
+ lines: [
111
+ {
112
+ streams: { text: 'Empty style leads to nothing.' }
113
+ }, {
114
+ streams: { text: "\e[4mUnderlined text." }
115
+ }, {
116
+ streams: { text: 'Unknown style leads to nothing.' }
117
+ }
118
+ ]
119
+ }
120
+ ]
121
+ }
122
+ )
123
+ end
124
+ end
125
+
126
+ it 'parses the template and both colour and style directives within' do
127
+ user_view = UserView.new
128
+ user_view.stub(:path, 'test/support/erb/colour_style.erb') do
129
+ ERBParser.parse(user_view).must_equal(
130
+ {
131
+ interfaces: [
132
+ {
133
+ name: 'test',
134
+ lines: [
135
+ {
136
+ streams: {
137
+ text: "\e[38;5;21m\e[4m\e[48;5;17mBlue underline text on dark blue background."
119
138
  }
120
- ]
121
- }
122
- ]
123
- }
124
- )
125
- end
139
+ }
140
+ ]
141
+ }
142
+ ]
143
+ }
144
+ )
126
145
  end
127
146
  end
128
147
 
129
- describe 'colour and style parsing' do
130
- it 'parses the template and both colour and style directives within' do
131
- user_view = UserView.new
132
- user_view.stub(:path, 'test/support/erb/colour_style.erb') do
133
- ERBParser.parse(user_view).must_equal(
134
- {
135
- interfaces: [
136
- {
137
- name: 'test',
138
- lines: [
139
- {
140
- streams: {
141
- text: "\e[38;5;21m\e[4m\e[48;5;17mBlue underline text on dark blue background."
142
- }
148
+ it 'treats sections of the template as one line' do
149
+ user_view = UserView.new
150
+ user_view.stub(:path, 'test/support/erb/line.erb') do
151
+ ERBParser.parse(user_view).must_equal(
152
+ {
153
+ interfaces: [
154
+ {
155
+ name: 'test',
156
+ lines: [
157
+ {
158
+ streams: {
159
+ text: " This is line one. This is line two."
143
160
  }
144
- ]
145
- }
146
- ]
147
- }
148
- )
149
- end
161
+ }
162
+ ]
163
+ }
164
+ ]
165
+ }
166
+ )
167
+ end
168
+ end
169
+
170
+ it 'treats sections of the template as one line with a foreground' do
171
+ user_view = UserView.new
172
+ user_view.stub(:path, 'test/support/erb/line_foreground.erb') do
173
+ ERBParser.parse(user_view).must_equal(
174
+ {
175
+ interfaces: [
176
+ {
177
+ name: 'test',
178
+ lines: [
179
+ {
180
+ streams: {
181
+ text: " \e[38;5;226mThis is line one.\e[38;2;39m This is line two."
182
+ }
183
+ }
184
+ ]
185
+ }
186
+ ]
187
+ }
188
+ )
189
+ end
190
+ end
191
+
192
+ it 'treats sections of the template as one line with a foreground' do
193
+ user_view = UserView.new
194
+ user_view.stub(:path, 'test/support/erb/line_foreground_2x.erb') do
195
+ ERBParser.parse(user_view).must_equal(
196
+ {
197
+ interfaces: [
198
+ {
199
+ name: 'test',
200
+ lines: [
201
+ {
202
+ streams: {
203
+ text: " \e[38;5;226mThis is line one.\e[38;2;39m \e[38;5;196mThis is line two.\e[38;2;39m This is line three."
204
+ }
205
+ }
206
+ ]
207
+ }
208
+ ]
209
+ }
210
+ )
211
+ end
212
+ end
213
+
214
+ it 'treats sections of the template as one line' do
215
+ skip
216
+ user_view = UserView.new
217
+ user_view.stub(:path, 'test/support/erb/line_2x.erb') do
218
+ ERBParser.parse(user_view).must_equal(
219
+ {
220
+ interfaces: [
221
+ {
222
+ name: 'test',
223
+ lines: [
224
+ {
225
+ streams: {
226
+ text: " This is line one. This is line two."
227
+ }
228
+ }, {
229
+ streams: {
230
+ text: " This is line three. This is line four."
231
+ }
232
+ }
233
+ ]
234
+ }
235
+ ]
236
+ }
237
+ )
150
238
  end
151
239
  end
152
240
  end