vedeu 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +2 -0
- data/README.md +116 -98
- data/lib/vedeu.rb +24 -11
- data/lib/vedeu/api/api.rb +174 -33
- data/lib/vedeu/api/composition.rb +2 -13
- data/lib/vedeu/api/helpers.rb +41 -0
- data/lib/vedeu/api/interface.rb +147 -34
- data/lib/vedeu/api/line.rb +47 -0
- data/lib/vedeu/api/stream.rb +41 -0
- data/lib/vedeu/application.rb +9 -2
- data/lib/vedeu/configuration.rb +66 -8
- data/lib/vedeu/launcher.rb +11 -0
- data/lib/vedeu/models/attributes/background.rb +29 -0
- data/lib/vedeu/models/attributes/coercions.rb +30 -0
- data/lib/vedeu/models/attributes/colour_translator.rb +106 -16
- data/lib/vedeu/models/attributes/foreground.rb +29 -0
- data/lib/vedeu/models/attributes/presentation.rb +15 -0
- data/lib/vedeu/models/colour.rb +12 -7
- data/lib/vedeu/models/composition.rb +23 -5
- data/lib/vedeu/models/geometry.rb +101 -16
- data/lib/vedeu/models/interface.rb +36 -28
- data/lib/vedeu/models/line.rb +16 -14
- data/lib/vedeu/models/stream.rb +17 -25
- data/lib/vedeu/models/style.rb +29 -0
- data/lib/vedeu/support/buffer.rb +36 -21
- data/lib/vedeu/support/buffers.rb +88 -0
- data/lib/vedeu/{output → support}/clear.rb +9 -2
- data/lib/vedeu/support/esc.rb +16 -2
- data/lib/vedeu/support/event.rb +104 -0
- data/lib/vedeu/support/events.rb +61 -0
- data/lib/vedeu/support/focus.rb +69 -0
- data/lib/vedeu/{api → support}/grid.rb +29 -25
- data/lib/vedeu/support/groups.rb +51 -0
- data/lib/vedeu/support/input.rb +5 -0
- data/lib/vedeu/support/log.rb +105 -0
- data/lib/vedeu/support/menu.rb +19 -0
- data/lib/vedeu/support/position.rb +7 -0
- data/lib/vedeu/{output → support}/render.rb +12 -6
- data/lib/vedeu/support/terminal.rb +21 -0
- data/lib/vedeu/support/trace.rb +54 -0
- data/lib/vedeu/{output → support}/view.rb +15 -10
- data/test/lib/vedeu/api/api_test.rb +55 -29
- data/test/lib/vedeu/api/interface_test.rb +3 -49
- data/test/lib/vedeu/api/line_test.rb +71 -0
- data/test/lib/vedeu/api/stream_test.rb +25 -0
- data/test/lib/vedeu/models/attributes/background_test.rb +83 -0
- data/test/lib/vedeu/models/attributes/coercer_test.rb +52 -0
- data/test/lib/vedeu/models/attributes/foreground_test.rb +83 -0
- data/test/lib/vedeu/models/attributes/presentation_test.rb +30 -0
- data/test/lib/vedeu/models/composition_test.rb +6 -6
- data/test/lib/vedeu/models/geometry_test.rb +34 -0
- data/test/lib/vedeu/models/interface_test.rb +0 -12
- data/test/lib/vedeu/models/line_test.rb +1 -13
- data/test/lib/vedeu/models/stream_test.rb +4 -50
- data/test/lib/vedeu/models/style_test.rb +39 -0
- data/test/lib/vedeu/support/buffer_test.rb +7 -3
- data/test/lib/vedeu/support/buffers_test.rb +15 -0
- data/test/lib/vedeu/{output → support}/clear_test.rb +8 -1
- data/test/lib/vedeu/support/esc_test.rb +2 -2
- data/test/lib/vedeu/support/event_test.rb +41 -0
- data/test/lib/vedeu/support/events_test.rb +70 -0
- data/test/lib/vedeu/support/focus_test.rb +114 -0
- data/test/lib/vedeu/support/grid_test.rb +31 -0
- data/test/lib/vedeu/support/groups_test.rb +65 -0
- data/test/lib/vedeu/{output → support}/render_test.rb +8 -1
- data/test/lib/vedeu/{output → support}/view_test.rb +1 -1
- data/test/test_helper.rb +3 -1
- data/vedeu.gemspec +3 -2
- metadata +67 -31
- data/lib/vedeu/api/events.rb +0 -46
- data/lib/vedeu/api/log.rb +0 -84
- data/lib/vedeu/models/attributes/attributes.rb +0 -25
- data/lib/vedeu/models/store.rb +0 -29
- data/lib/vedeu/output/buffers.rb +0 -65
- data/test/lib/vedeu/api/events_test.rb +0 -36
- data/test/lib/vedeu/api/grid_test.rb +0 -33
- data/test/lib/vedeu/models/attributes/attributes_test.rb +0 -39
- data/test/lib/vedeu/models/attributes/colour_translator_test.rb +0 -78
- data/test/lib/vedeu/models/store_test.rb +0 -57
- data/test/lib/vedeu/output/buffers_test.rb +0 -35
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
describe Style do
|
5
|
+
describe '#to_s' do
|
6
|
+
describe 'for a single style' do
|
7
|
+
let(:values) { 'normal' }
|
8
|
+
|
9
|
+
it 'returns an escape sequence' do
|
10
|
+
Style.new(values).to_s.must_equal("\e[24m\e[22m\e[27m")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'for multiple styles' do
|
15
|
+
let(:values) { ['normal', 'underline'] }
|
16
|
+
|
17
|
+
it 'returns an escape sequence for multiple styles' do
|
18
|
+
Style.new(values).to_s.must_equal("\e[24m\e[22m\e[27m\e[4m")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'for an unknown style' do
|
23
|
+
let(:values) { 'unknown' }
|
24
|
+
|
25
|
+
it 'returns an empty string for an unknown style' do
|
26
|
+
Style.new(values).to_s.must_equal('')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'for an empty or nil' do
|
31
|
+
let(:values) { '' }
|
32
|
+
|
33
|
+
it 'returns an empty string for empty or nil' do
|
34
|
+
Style.new(values).to_s.must_equal('')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -3,7 +3,11 @@ require 'test_helper'
|
|
3
3
|
module Vedeu
|
4
4
|
describe Buffer do
|
5
5
|
let(:vars) {
|
6
|
-
{
|
6
|
+
{
|
7
|
+
back: '',
|
8
|
+
front: '',
|
9
|
+
interface: mock('Interface'),
|
10
|
+
}
|
7
11
|
}
|
8
12
|
|
9
13
|
describe '#initialize' do
|
@@ -23,9 +27,9 @@ module Vedeu
|
|
23
27
|
buffer = Buffer.new(vars)
|
24
28
|
new_buffer = buffer.enqueue('some_sequence')
|
25
29
|
|
26
|
-
buffer.
|
30
|
+
buffer.back.must_equal('')
|
27
31
|
new_buffer.wont_equal(buffer)
|
28
|
-
new_buffer.
|
32
|
+
new_buffer.back.must_equal('some_sequence')
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
describe Buffers do
|
5
|
+
before { Buffers.reset }
|
6
|
+
|
7
|
+
describe '.enqueue' do
|
8
|
+
it 'raises an exception if the interface cannot be found by name' do
|
9
|
+
name = 'unknown'
|
10
|
+
view = '...'
|
11
|
+
proc { Buffers.enqueue(name, view) }.must_raise(EntityNotFound)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -2,7 +2,14 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Clear do
|
5
|
-
before {
|
5
|
+
before { Buffers.reset }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'returns an instance of itself' do
|
9
|
+
interface = mock('Interface')
|
10
|
+
Clear.new(interface).must_be_instance_of(Clear)
|
11
|
+
end
|
12
|
+
end
|
6
13
|
|
7
14
|
describe '.call' do
|
8
15
|
it 'returns the escape sequence to clear the whole interface' do
|
@@ -24,7 +24,7 @@ module Vedeu
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'returns an escape sequence when the style is bold off' do
|
27
|
-
Esc.string('bold_off').must_equal("\e[
|
27
|
+
Esc.string('bold_off').must_equal("\e[22m")
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'returns an escape sequence when the style is clear' do
|
@@ -68,7 +68,7 @@ module Vedeu
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'returns an escape sequence when the style is normal' do
|
71
|
-
Esc.string('normal').must_equal("\e[24m\e[
|
71
|
+
Esc.string('normal').must_equal("\e[24m\e[22m\e[27m")
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'returns an escape sequence when the style is dim' do
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
describe Event do
|
5
|
+
let(:closure) { proc { :event_triggered } }
|
6
|
+
let(:options) { {} }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'returns an instance of itself' do
|
10
|
+
Event.new(closure, options).must_be_instance_of(Event)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#trigger' do
|
15
|
+
it 'returns the result of calling the closure when debouncing' do
|
16
|
+
event = Event.new(closure, { debounce: 0.0025 })
|
17
|
+
event.trigger.must_equal(nil)
|
18
|
+
sleep 0.0015
|
19
|
+
event.trigger.must_equal(nil)
|
20
|
+
sleep 0.0015
|
21
|
+
event.trigger.must_equal(:event_triggered)
|
22
|
+
sleep 0.0015
|
23
|
+
event.trigger.must_equal(nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the result of calling the closure when throttling' do
|
27
|
+
event = Event.new(closure, { delay: 0.0025 })
|
28
|
+
event.trigger.must_equal(:event_triggered)
|
29
|
+
sleep 0.0015
|
30
|
+
event.trigger.must_equal(nil)
|
31
|
+
sleep 0.0015
|
32
|
+
event.trigger.must_equal(:event_triggered)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns the result of calling the closure with its arguments' do
|
36
|
+
event = Event.new(closure, options)
|
37
|
+
event.trigger.must_equal(:event_triggered)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
describe Events do
|
5
|
+
describe '#event' do
|
6
|
+
it 'adds the event block to the handlers' do
|
7
|
+
skip
|
8
|
+
events = Events.new
|
9
|
+
events.event(:some_event) { proc { |x| x } }
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'adds the specified throttle to the throttles' do
|
13
|
+
skip
|
14
|
+
events = Events.new
|
15
|
+
events.event(:some_event, 250) { proc { |x| x } }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#unevent' do
|
20
|
+
it 'removes the event by name' do
|
21
|
+
events = Events.new
|
22
|
+
events.event(:chlorine) { proc { |x| x } }
|
23
|
+
events.event(:argon) { proc { |y| y } }
|
24
|
+
events.unevent(:chlorine)
|
25
|
+
events.registered.must_equal([:argon])
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'removes the event by name only if the name exists' do
|
29
|
+
events = Events.new
|
30
|
+
events.event(:chlorine) { proc { |x| x } }
|
31
|
+
events.event(:argon) { proc { |y| y } }
|
32
|
+
events.unevent(:potassium)
|
33
|
+
events.registered.must_equal([:chlorine, :argon])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#registered' do
|
38
|
+
it 'returns all the registered events by name' do
|
39
|
+
events = Events.new do
|
40
|
+
event(:some_event) { proc { |x| x } }
|
41
|
+
end
|
42
|
+
events.registered.must_equal([:some_event])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#trigger' do
|
47
|
+
it 'returns a collection containing the event when the event is ' \
|
48
|
+
'pre-registered' do
|
49
|
+
events = Events.new do
|
50
|
+
event(:_exit_) { fail StopIteration }
|
51
|
+
end
|
52
|
+
proc { events.trigger(:_exit_) }.must_raise(StopIteration)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'returns an empty collection when the event has not been registered' do
|
56
|
+
events = Events.new
|
57
|
+
events.trigger(:_not_found_).must_be_empty
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#reset' do
|
62
|
+
it 'removes all events registered' do
|
63
|
+
events = Events.new do
|
64
|
+
event(:some_event) { proc { |x| x } }
|
65
|
+
end
|
66
|
+
events.reset.must_equal({})
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
# [['thallium', false], ['lead', false], ['bismuth', false]]
|
4
|
+
|
5
|
+
module Vedeu
|
6
|
+
describe Focus do
|
7
|
+
before do
|
8
|
+
Vedeu.unevent(:_focus_next_)
|
9
|
+
Vedeu.unevent(:_focus_prev_)
|
10
|
+
Vedeu.unevent(:_focus_by_name_)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#add' do
|
14
|
+
it 'adds an interface to storage unfocussed' do
|
15
|
+
focus = Focus.new
|
16
|
+
focus.add('thallium').must_equal(['thallium'])
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'does not add it again if already exists' do
|
20
|
+
focus = Focus.new
|
21
|
+
focus.add('thallium')
|
22
|
+
focus.add('thallium').must_equal(['thallium'])
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#by_name' do
|
27
|
+
it 'the named interface is focussed when the method is called' do
|
28
|
+
focus = Focus.new
|
29
|
+
focus.add('thallium')
|
30
|
+
focus.add('lead')
|
31
|
+
focus.add('bismuth')
|
32
|
+
focus.by_name('bismuth').must_equal('bismuth')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'the named interface is focussed when the event is triggered' do
|
36
|
+
focus = Focus.new
|
37
|
+
focus.add('thallium')
|
38
|
+
focus.add('lead')
|
39
|
+
focus.add('bismuth')
|
40
|
+
|
41
|
+
Vedeu.trigger(:_focus_by_name_, 'lead')
|
42
|
+
|
43
|
+
focus.current.must_equal('lead')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'raises an exception if the interface does not exist' do
|
47
|
+
focus = Focus.new
|
48
|
+
proc { Vedeu.trigger(:_focus_by_name_, 'not_found') }.must_raise(InterfaceNotFound)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'raises an exception if the interface does not exist' do
|
52
|
+
focus = Focus.new
|
53
|
+
proc { focus.by_name('not_found') }.must_raise(InterfaceNotFound)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#current' do
|
58
|
+
it 'returns the name of the interface currently in focus' do
|
59
|
+
focus = Focus.new
|
60
|
+
focus.add('thallium')
|
61
|
+
focus.add('lead')
|
62
|
+
focus.add('bismuth')
|
63
|
+
focus.current.must_equal('thallium')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'raises an exception if there are no interfaces defined' do
|
67
|
+
focus = Focus.new
|
68
|
+
proc { focus.current }.must_raise(NoInterfacesDefined)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#next_item' do
|
73
|
+
it 'the next interface is focussed when the method is called' do
|
74
|
+
focus = Focus.new
|
75
|
+
focus.add('thallium')
|
76
|
+
focus.add('lead')
|
77
|
+
focus.add('bismuth')
|
78
|
+
focus.next_item.must_equal('lead')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'the next interface is focussed when the event is triggered' do
|
82
|
+
focus = Focus.new
|
83
|
+
focus.add('thallium')
|
84
|
+
focus.add('lead')
|
85
|
+
focus.add('bismuth')
|
86
|
+
|
87
|
+
Vedeu.trigger(:_focus_next_)
|
88
|
+
|
89
|
+
focus.current.must_equal('lead')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#prev_item' do
|
94
|
+
it 'the previous interface is focussed when the method is called' do
|
95
|
+
focus = Focus.new
|
96
|
+
focus.add('thallium')
|
97
|
+
focus.add('lead')
|
98
|
+
focus.add('bismuth')
|
99
|
+
focus.prev_item.must_equal('bismuth')
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'the previous interface is focussed when the event is triggered' do
|
103
|
+
focus = Focus.new
|
104
|
+
focus.add('thallium')
|
105
|
+
focus.add('lead')
|
106
|
+
focus.add('bismuth')
|
107
|
+
|
108
|
+
Vedeu.trigger(:_focus_prev_)
|
109
|
+
|
110
|
+
focus.current.must_equal('bismuth')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Fixnum do
|
4
|
+
describe '#columns' do
|
5
|
+
it 'returns the width if the value is in range' do
|
6
|
+
IO.console.stub :winsize, [25, 60] do
|
7
|
+
1.columns.must_equal(5)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Vedeu
|
14
|
+
describe Grid do
|
15
|
+
describe '.columns' do
|
16
|
+
it 'raises an exception if the value is less than 1' do
|
17
|
+
proc { Grid.columns(0) }.must_raise(OutOfRange)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'raises an exception if the value is greater than 12' do
|
21
|
+
proc { Grid.columns(13) }.must_raise(OutOfRange)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns the width if the value is in range' do
|
25
|
+
IO.console.stub :winsize, [25, 80] do
|
26
|
+
Grid.columns(7).must_equal(42)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
describe Groups do
|
5
|
+
let(:groups) { Groups.new }
|
6
|
+
|
7
|
+
describe '#all' do
|
8
|
+
before do
|
9
|
+
groups.add('elements', 'cobalt', 0.0)
|
10
|
+
groups.add('elements', 'nickel', 0.0)
|
11
|
+
groups.add('elements', 'copper', 0.0)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns all the groups from storage' do
|
15
|
+
groups.all.must_equal({
|
16
|
+
"elements" => Set["cobalt", "nickel", "copper"]
|
17
|
+
})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#find' do
|
22
|
+
before { groups.add('elements', 'zinc', 0.0) }
|
23
|
+
|
24
|
+
it 'raises an exception if the group cannot be found' do
|
25
|
+
proc { groups.find('not_found') }.must_raise(GroupNotFound)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'returns a collection of interface names belonging to the group' do
|
29
|
+
groups.find('elements').must_equal(Set['zinc'])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#add' do
|
34
|
+
it 'returns false if the group name is empty' do
|
35
|
+
groups.add('', 'gallium', 0.0).must_equal(false)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'adds the interface name to the group in storage' do
|
39
|
+
groups.add('elements', 'germanium', 0.0)
|
40
|
+
groups.all.must_equal({
|
41
|
+
"elements" => Set['germanium']
|
42
|
+
})
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'registers a refresh event for the group' do
|
46
|
+
groups.add('elements', 'arsenic', 0.0)
|
47
|
+
Vedeu.events.registered.must_include(:_refresh_group_elements_)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns the object instance' do
|
51
|
+
groups.add('elements', 'selenium', 0.0).must_be_instance_of(Groups)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#reset' do
|
56
|
+
it 'removes all known groups from the storage' do
|
57
|
+
groups.add('elements', 'bromine', 0.0)
|
58
|
+
groups.all.must_equal({
|
59
|
+
"elements" => Set['bromine']
|
60
|
+
})
|
61
|
+
groups.reset.must_be_empty
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -2,7 +2,14 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Render do
|
5
|
-
before {
|
5
|
+
before { Buffers.reset }
|
6
|
+
|
7
|
+
describe '#initialize' do
|
8
|
+
it 'returns an instance of itself' do
|
9
|
+
interface = mock('Interface')
|
10
|
+
Render.new(interface).must_be_instance_of(Render)
|
11
|
+
end
|
12
|
+
end
|
6
13
|
|
7
14
|
describe '.call' do
|
8
15
|
it 'returns the content for the interface' do
|