vedeu 0.0.31 → 0.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/vedeu.rb +1 -0
- data/lib/vedeu/models/collection.rb +17 -0
- data/lib/vedeu/models/colour.rb +27 -5
- data/lib/vedeu/models/line_collection.rb +4 -9
- data/lib/vedeu/models/stream.rb +1 -1
- data/lib/vedeu/models/stream_collection.rb +4 -9
- data/lib/vedeu/support/coordinate.rb +149 -0
- data/lib/vedeu/support/esc.rb +4 -0
- data/lib/vedeu/support/menu.rb +103 -0
- data/lib/vedeu/support/terminal.rb +4 -0
- data/test/example_app/lib/app.rb +25 -6
- data/test/lib/vedeu/models/collection_test.rb +50 -0
- data/test/lib/vedeu/models/colour_test.rb +58 -1
- data/test/lib/vedeu/models/command_test.rb +2 -1
- data/test/lib/vedeu/models/interface_collection_test.rb +4 -3
- data/test/lib/vedeu/models/line_test.rb +3 -1
- data/test/lib/vedeu/models/stream_test.rb +6 -3
- data/test/lib/vedeu/output/text_adaptor_test.rb +1 -1
- data/test/lib/vedeu/repository/command_repository_test.rb +2 -1
- data/test/lib/vedeu/repository/interface_repository_test.rb +2 -1
- data/test/lib/vedeu/repository/repository_test.rb +2 -1
- data/test/lib/vedeu/repository/storage_test.rb +6 -3
- data/test/lib/vedeu/support/coordinate_test.rb +363 -0
- data/test/lib/vedeu/support/esc_test.rb +8 -0
- data/test/lib/vedeu/support/menu_test.rb +202 -0
- data/test/lib/vedeu/support/parser_test.rb +2 -1
- data/test/lib/vedeu/support/parsing/hash_parser_test.rb +6 -3
- data/test/lib/vedeu/support/parsing/json_parser_test.rb +2 -1
- data/test/lib/vedeu/support/terminal_test.rb +9 -0
- data/test/lib/vedeu/support/translator_test.rb +2 -1
- data/test/test_helper.rb +12 -0
- data/vedeu.gemspec +1 -1
- metadata +11 -8
- data/lib/vedeu/models/background.rb +0 -13
- data/lib/vedeu/models/foreground.rb +0 -13
- data/test/lib/vedeu/models/background_test.rb +0 -19
- data/test/lib/vedeu/models/foreground_test.rb +0 -18
@@ -7,6 +7,10 @@ module Vedeu
|
|
7
7
|
it 'returns an escape sequence' do
|
8
8
|
Esc.background_colour.must_equal("\e[48;5;16m")
|
9
9
|
end
|
10
|
+
|
11
|
+
it 'returns an empty string if the value is empty' do
|
12
|
+
Esc.background_colour('').must_equal('')
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
describe '.clear_line' do
|
@@ -27,6 +31,10 @@ module Vedeu
|
|
27
31
|
it 'returns an escape sequence' do
|
28
32
|
Esc.foreground_colour.must_equal("\e[38;5;231m")
|
29
33
|
end
|
34
|
+
|
35
|
+
it 'returns an empty string if the value is empty' do
|
36
|
+
Esc.foreground_colour('').must_equal('')
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
describe '.set_position' do
|
@@ -0,0 +1,202 @@
|
|
1
|
+
require_relative '../../../test_helper'
|
2
|
+
require_relative '../../../../lib/vedeu/support/menu'
|
3
|
+
|
4
|
+
module Vedeu
|
5
|
+
describe Menu do
|
6
|
+
let(:collection) { ['hydrogen', 'carbon', 'nitrogen', 'oxygen'] }
|
7
|
+
let(:menu) { Menu.new(collection) }
|
8
|
+
|
9
|
+
describe '#current' do
|
10
|
+
it 'returns the current index' do
|
11
|
+
menu.current.must_equal(0)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#selected' do
|
16
|
+
it 'returns nil when no item is selected' do
|
17
|
+
menu.selected.must_equal(nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns the selected index when an item is selected' do
|
21
|
+
menu.next.select
|
22
|
+
menu.selected.must_equal(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#current_item' do
|
27
|
+
it 'returns a tuple containing the current index and item' do
|
28
|
+
menu.current_item.must_equal([0, 'hydrogen'])
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'when the current item has changed, the tuple will change' do
|
32
|
+
menu.next.next
|
33
|
+
menu.current_item.must_equal([2, 'nitrogen'])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#selected_item' do
|
38
|
+
it 'returns nil when nothing is selected' do
|
39
|
+
menu.selected_item.must_equal(nil)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns a tuple containing the selected index and item' do
|
43
|
+
menu.next.select
|
44
|
+
menu.selected_item.must_equal([1, 'carbon'])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#items' do
|
49
|
+
it 'returns a tuple' do
|
50
|
+
menu.items.must_equal(
|
51
|
+
[
|
52
|
+
[false, true, 'hydrogen'],
|
53
|
+
[false, false, 'carbon'],
|
54
|
+
[false, false, 'nitrogen'],
|
55
|
+
[false, false, 'oxygen']
|
56
|
+
]
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns a tuple when the current has changed' do
|
61
|
+
menu.next.items.must_equal(
|
62
|
+
[
|
63
|
+
[false, false, "hydrogen"],
|
64
|
+
[false, true, "carbon"],
|
65
|
+
[false, false, "nitrogen"],
|
66
|
+
[false, false, "oxygen"]
|
67
|
+
]
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns a tuple when an item is selected' do
|
72
|
+
menu.next.select
|
73
|
+
menu.items.must_equal(
|
74
|
+
[
|
75
|
+
[false, false, "hydrogen"],
|
76
|
+
[true, true, "carbon"],
|
77
|
+
[false, false, "nitrogen"],
|
78
|
+
[false, false, "oxygen"]
|
79
|
+
]
|
80
|
+
)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'returns a tuple when the current has changed and an item ' \
|
84
|
+
'is selected' do
|
85
|
+
menu.next.select
|
86
|
+
menu.next.next
|
87
|
+
menu.items.must_equal(
|
88
|
+
[
|
89
|
+
[false, false, "hydrogen"],
|
90
|
+
[true, false, "carbon"],
|
91
|
+
[false, false, "nitrogen"],
|
92
|
+
[false, true, "oxygen"]
|
93
|
+
]
|
94
|
+
)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#render' do
|
99
|
+
it 'returns a tuple' do
|
100
|
+
menu.render.must_equal(
|
101
|
+
[" > hydrogen", " carbon", " nitrogen", " oxygen"]
|
102
|
+
)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns a tuple when the current has changed' do
|
106
|
+
menu.next.render.must_equal(
|
107
|
+
[" hydrogen", " > carbon", " nitrogen", " oxygen"]
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'returns a tuple when an item is selected' do
|
112
|
+
menu.next.select
|
113
|
+
menu.render.must_equal(
|
114
|
+
[" hydrogen", "*> carbon", " nitrogen", " oxygen"]
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'returns a tuple when the current has changed and an item ' \
|
119
|
+
'is selected' do
|
120
|
+
menu.next.select
|
121
|
+
menu.next.next
|
122
|
+
menu.render.must_equal(
|
123
|
+
[" hydrogen", "* carbon", " nitrogen", " > oxygen"]
|
124
|
+
)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe '#top' do
|
129
|
+
it 'sets current to the index of the first item' do
|
130
|
+
menu.next
|
131
|
+
menu.top.must_equal(0)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#bottom' do
|
136
|
+
it 'sets current to the index of the last item' do
|
137
|
+
menu.bottom.must_equal(3)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#next' do
|
142
|
+
it 'sets the current to the index of the next item' do
|
143
|
+
menu.next.current.must_equal(1)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'returns the instance' do
|
147
|
+
menu.next.must_equal(menu)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'is chainable but does not loop' do
|
151
|
+
menu.next.next.next.next.next.current.must_equal(3)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe '#prev' do
|
156
|
+
it 'does not loop' do
|
157
|
+
menu.prev.current.must_equal(0)
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'sets the current to the index of the previous item' do
|
161
|
+
menu.next.next.prev.current.must_equal(1)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'returns the instance' do
|
165
|
+
menu.prev.must_equal(menu)
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'is chainable' do
|
169
|
+
menu.next.next.next.prev.prev.current.must_equal(1)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe '#select' do
|
174
|
+
it 'sets the selected index to the current index' do
|
175
|
+
menu.select.must_equal(0)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'sets the selected index to the current index' do
|
179
|
+
menu.next.select.must_equal(1)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
describe '#deselect' do
|
184
|
+
it 'sets the selected index to nil' do
|
185
|
+
menu.next.next.select
|
186
|
+
menu.deselect.must_equal(nil)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
describe '#last' do
|
191
|
+
it 'returns the index of the last item' do
|
192
|
+
menu.last.must_equal(3)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#size' do
|
197
|
+
it 'returns the collection size' do
|
198
|
+
menu.size.must_equal(4)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -9,7 +9,8 @@ module Vedeu
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'returns a Composition when the output is JSON' do
|
12
|
-
Parser.parse("{\"some\": \"JSON\"}")
|
12
|
+
Parser.parse("{\"some\": \"JSON\"}")
|
13
|
+
.must_be_instance_of(Composition)
|
13
14
|
end
|
14
15
|
|
15
16
|
it 'returns a Composition when the output is a Hash' do
|
@@ -10,8 +10,10 @@ module Vedeu
|
|
10
10
|
dummy: 'More content...'
|
11
11
|
}).must_equal({
|
12
12
|
interfaces: [
|
13
|
-
{ name: "test", lines:
|
14
|
-
|
13
|
+
{ name: "test", lines: [
|
14
|
+
{ streams: { text: "Some content..." } }] },
|
15
|
+
{ name: "dummy", lines: [
|
16
|
+
{ streams: { text: "More content..." } }] }
|
15
17
|
]
|
16
18
|
})
|
17
19
|
end
|
@@ -21,7 +23,8 @@ module Vedeu
|
|
21
23
|
dummy: 'Some content...'
|
22
24
|
}).must_equal({
|
23
25
|
interfaces: [
|
24
|
-
{ name: "dummy", lines: [
|
26
|
+
{ name: "dummy", lines: [
|
27
|
+
{ streams: { text: "Some content..." } }] }
|
25
28
|
]
|
26
29
|
})
|
27
30
|
end
|
@@ -5,7 +5,8 @@ module Vedeu
|
|
5
5
|
describe JSONParser do
|
6
6
|
describe '.parse' do
|
7
7
|
it 'returns a hash when the JSON is valid' do
|
8
|
-
JSONParser.parse("{\"some\": \"JSON\"}")
|
8
|
+
JSONParser.parse("{\"some\": \"JSON\"}")
|
9
|
+
.must_be_instance_of(Hash)
|
9
10
|
end
|
10
11
|
|
11
12
|
it 'returns an empty hash when the JSON is invalid' do
|
@@ -18,6 +18,15 @@ module Vedeu
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
describe '.centre' do
|
22
|
+
it 'returns the centre point on the terminal' do
|
23
|
+
console = IO.console
|
24
|
+
console.stub :winsize, [25, 80] do
|
25
|
+
Terminal.centre.must_equal([12, 40])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
21
30
|
describe '.width' do
|
22
31
|
it 'returns the width of the terminal' do
|
23
32
|
console = IO.console
|
@@ -13,7 +13,8 @@ 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
|
+
Translator.translate(html_colour)
|
17
|
+
.must_equal(terminal_colour)
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
data/test/test_helper.rb
CHANGED
@@ -18,3 +18,15 @@ end
|
|
18
18
|
# Minitest::Reporters::DefaultReporter.new({ color: true, slow_count: 5 }),
|
19
19
|
# Minitest::Reporters::SpecReporter.new
|
20
20
|
# )
|
21
|
+
|
22
|
+
# trace method execution with local variables
|
23
|
+
# my_event = 'call'
|
24
|
+
# my_class = /^Vedeu/
|
25
|
+
# set_trace_func proc { |event, file, line, id, binding, classname|
|
26
|
+
# if event == my_event && classname.to_s.match(my_class)
|
27
|
+
# printf("\e[38;5;#{rand(22..231)}m%s %s #%s\e[38;2;39m\n", event, classname, id)
|
28
|
+
# binding.eval('local_variables').each do |var|
|
29
|
+
# print("#{var.to_s} = #{binding.local_variable_get(var).inspect}\n")
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# }
|
data/vedeu.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'vedeu'
|
7
|
-
spec.version = '0.0.
|
7
|
+
spec.version = '0.0.32'
|
8
8
|
spec.authors = ['Gavin Laking']
|
9
9
|
spec.email = ['gavinlaking@gmail.com']
|
10
10
|
spec.summary = %q{A terminal case of wonderland.}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vedeu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gavin Laking
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -186,11 +186,10 @@ files:
|
|
186
186
|
- lib/vedeu/configuration.rb
|
187
187
|
- lib/vedeu/input/input.rb
|
188
188
|
- lib/vedeu/launcher.rb
|
189
|
-
- lib/vedeu/models/
|
189
|
+
- lib/vedeu/models/collection.rb
|
190
190
|
- lib/vedeu/models/colour.rb
|
191
191
|
- lib/vedeu/models/command.rb
|
192
192
|
- lib/vedeu/models/composition.rb
|
193
|
-
- lib/vedeu/models/foreground.rb
|
194
193
|
- lib/vedeu/models/interface.rb
|
195
194
|
- lib/vedeu/models/interface_collection.rb
|
196
195
|
- lib/vedeu/models/line.rb
|
@@ -209,9 +208,11 @@ files:
|
|
209
208
|
- lib/vedeu/repository/interface_repository.rb
|
210
209
|
- lib/vedeu/repository/repository.rb
|
211
210
|
- lib/vedeu/repository/storage.rb
|
211
|
+
- lib/vedeu/support/coordinate.rb
|
212
212
|
- lib/vedeu/support/esc.rb
|
213
213
|
- lib/vedeu/support/exit.rb
|
214
214
|
- lib/vedeu/support/geometry.rb
|
215
|
+
- lib/vedeu/support/menu.rb
|
215
216
|
- lib/vedeu/support/parser.rb
|
216
217
|
- lib/vedeu/support/parsing/hash_parser.rb
|
217
218
|
- lib/vedeu/support/parsing/json_parser.rb
|
@@ -226,11 +227,10 @@ files:
|
|
226
227
|
- test/lib/vedeu/configuration_test.rb
|
227
228
|
- test/lib/vedeu/input/input_test.rb
|
228
229
|
- test/lib/vedeu/launcher_test.rb
|
229
|
-
- test/lib/vedeu/models/
|
230
|
+
- test/lib/vedeu/models/collection_test.rb
|
230
231
|
- test/lib/vedeu/models/colour_test.rb
|
231
232
|
- test/lib/vedeu/models/command_test.rb
|
232
233
|
- test/lib/vedeu/models/composition_test.rb
|
233
|
-
- test/lib/vedeu/models/foreground_test.rb
|
234
234
|
- test/lib/vedeu/models/interface_collection_test.rb
|
235
235
|
- test/lib/vedeu/models/interface_test.rb
|
236
236
|
- test/lib/vedeu/models/line_collection_test.rb
|
@@ -248,10 +248,12 @@ files:
|
|
248
248
|
- test/lib/vedeu/repository/interface_repository_test.rb
|
249
249
|
- test/lib/vedeu/repository/repository_test.rb
|
250
250
|
- test/lib/vedeu/repository/storage_test.rb
|
251
|
+
- test/lib/vedeu/support/coordinate_test.rb
|
251
252
|
- test/lib/vedeu/support/esc_test.rb
|
252
253
|
- test/lib/vedeu/support/event_repository_test.rb
|
253
254
|
- test/lib/vedeu/support/exit_test.rb
|
254
255
|
- test/lib/vedeu/support/geometry_test.rb
|
256
|
+
- test/lib/vedeu/support/menu_test.rb
|
255
257
|
- test/lib/vedeu/support/parser_test.rb
|
256
258
|
- test/lib/vedeu/support/parsing/hash_parser_test.rb
|
257
259
|
- test/lib/vedeu/support/parsing/json_parser_test.rb
|
@@ -307,11 +309,10 @@ test_files:
|
|
307
309
|
- test/lib/vedeu/configuration_test.rb
|
308
310
|
- test/lib/vedeu/input/input_test.rb
|
309
311
|
- test/lib/vedeu/launcher_test.rb
|
310
|
-
- test/lib/vedeu/models/
|
312
|
+
- test/lib/vedeu/models/collection_test.rb
|
311
313
|
- test/lib/vedeu/models/colour_test.rb
|
312
314
|
- test/lib/vedeu/models/command_test.rb
|
313
315
|
- test/lib/vedeu/models/composition_test.rb
|
314
|
-
- test/lib/vedeu/models/foreground_test.rb
|
315
316
|
- test/lib/vedeu/models/interface_collection_test.rb
|
316
317
|
- test/lib/vedeu/models/interface_test.rb
|
317
318
|
- test/lib/vedeu/models/line_collection_test.rb
|
@@ -329,10 +330,12 @@ test_files:
|
|
329
330
|
- test/lib/vedeu/repository/interface_repository_test.rb
|
330
331
|
- test/lib/vedeu/repository/repository_test.rb
|
331
332
|
- test/lib/vedeu/repository/storage_test.rb
|
333
|
+
- test/lib/vedeu/support/coordinate_test.rb
|
332
334
|
- test/lib/vedeu/support/esc_test.rb
|
333
335
|
- test/lib/vedeu/support/event_repository_test.rb
|
334
336
|
- test/lib/vedeu/support/exit_test.rb
|
335
337
|
- test/lib/vedeu/support/geometry_test.rb
|
338
|
+
- test/lib/vedeu/support/menu_test.rb
|
336
339
|
- test/lib/vedeu/support/parser_test.rb
|
337
340
|
- test/lib/vedeu/support/parsing/hash_parser_test.rb
|
338
341
|
- test/lib/vedeu/support/parsing/json_parser_test.rb
|