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
@@ -2,6 +2,9 @@ module Vedeu
|
|
2
2
|
module Terminal
|
3
3
|
extend self
|
4
4
|
|
5
|
+
# @param mode [Symbol]
|
6
|
+
# @param block [Proc]
|
7
|
+
# @return []
|
5
8
|
def open(mode, &block)
|
6
9
|
@mode = mode
|
7
10
|
|
@@ -18,6 +21,7 @@ module Vedeu
|
|
18
21
|
restore_screen
|
19
22
|
end
|
20
23
|
|
24
|
+
# @return [String]
|
21
25
|
def input
|
22
26
|
if raw_mode?
|
23
27
|
keys = console.getch
|
@@ -33,39 +37,54 @@ module Vedeu
|
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
40
|
+
# @param stream [String]
|
41
|
+
# @return [String]
|
36
42
|
def output(stream = '')
|
37
43
|
console.print(stream)
|
38
44
|
|
39
45
|
stream
|
40
46
|
end
|
41
47
|
|
48
|
+
# @param block [Proc]
|
49
|
+
# @return []
|
42
50
|
def initialize_screen(&block)
|
43
51
|
output Esc.string 'screen_init'
|
44
52
|
|
45
53
|
yield
|
46
54
|
end
|
47
55
|
|
56
|
+
# @return [String]
|
48
57
|
def clear_screen
|
49
58
|
output Esc.string 'clear'
|
50
59
|
end
|
51
60
|
|
61
|
+
# @return [String]
|
52
62
|
def restore_screen
|
53
63
|
output Esc.string 'screen_exit'
|
54
64
|
output clear_last_line
|
55
65
|
end
|
56
66
|
|
67
|
+
# @return [String]
|
57
68
|
def set_cursor_mode
|
58
69
|
output Esc.string 'show_cursor' unless raw_mode?
|
59
70
|
end
|
60
71
|
|
72
|
+
# @return [Boolean]
|
61
73
|
def raw_mode?
|
62
74
|
@mode == :raw
|
63
75
|
end
|
64
76
|
|
77
|
+
# @return [String]
|
65
78
|
def clear_last_line
|
66
79
|
Esc.set_position((height - 1), 1) + Esc.string('clear_line')
|
67
80
|
end
|
68
81
|
|
82
|
+
# @return [Fixnum]
|
83
|
+
def colour_mode
|
84
|
+
Configuration.options[:colour_mode]
|
85
|
+
end
|
86
|
+
|
87
|
+
# @return [Array]
|
69
88
|
def centre
|
70
89
|
[(height / 2), (width / 2)]
|
71
90
|
end
|
@@ -80,10 +99,12 @@ module Vedeu
|
|
80
99
|
size.first
|
81
100
|
end
|
82
101
|
|
102
|
+
# @return [Array]
|
83
103
|
def size
|
84
104
|
console.winsize
|
85
105
|
end
|
86
106
|
|
107
|
+
# @return [File]
|
87
108
|
def console
|
88
109
|
IO.console
|
89
110
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Vedeu
|
2
|
+
class Trace
|
3
|
+
|
4
|
+
# :nocov:
|
5
|
+
# @param options [Hash]
|
6
|
+
# @return []
|
7
|
+
def self.call(options = {})
|
8
|
+
new(options).trace
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param options [Hash]
|
12
|
+
# @return [Trace]
|
13
|
+
def initialize(options = {})
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return []
|
18
|
+
def trace
|
19
|
+
set_trace_func proc { |event, file, line, id, binding, classname|
|
20
|
+
if event == watched && classname.to_s.match(klass)
|
21
|
+
Vedeu.log(sprintf(" %s %-35s #%s", event, classname, id))
|
22
|
+
# binding.eval('local_variables').each do |var|
|
23
|
+
# print("#{var.to_s} = #{binding.local_variable_get(var).inspect}\n")
|
24
|
+
# end
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def watched
|
32
|
+
options[:event]
|
33
|
+
end
|
34
|
+
|
35
|
+
def klass
|
36
|
+
options[:klass]
|
37
|
+
end
|
38
|
+
|
39
|
+
def options
|
40
|
+
defaults.merge!(@options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def defaults
|
44
|
+
{
|
45
|
+
event: 'call',
|
46
|
+
klass: /^Vedeu::(?!.*Log|Interface|Line|Stream|Style|Colour|Geometry|Terminal|Esc|ColourTranslator).*/
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
# everything except Interface, Geometry and Terminal
|
51
|
+
# klass: /^Vedeu::(?!.*Interface|Geometry|Terminal).*/
|
52
|
+
end
|
53
|
+
# :nocov:
|
54
|
+
end
|
@@ -1,26 +1,30 @@
|
|
1
1
|
module Vedeu
|
2
|
-
NotImplemented = Class.new(StandardError)
|
3
|
-
|
4
2
|
class View
|
3
|
+
|
5
4
|
include Vedeu::API
|
6
5
|
|
6
|
+
# @param object []
|
7
|
+
# @return [Array]
|
7
8
|
def self.render(object = nil)
|
8
|
-
new(object).
|
9
|
+
new(object).enqueue
|
9
10
|
end
|
10
11
|
|
12
|
+
# @param object []
|
13
|
+
# @return [View]
|
11
14
|
def initialize(object = nil)
|
12
15
|
@object = object
|
13
16
|
end
|
14
17
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
18
|
+
# @return [Array]
|
19
|
+
def enqueue
|
20
|
+
interfaces.map { |interface| Buffers.enqueue(interface.name, interface) }
|
19
21
|
end
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
+
# @return [Exception]
|
24
|
+
def render
|
25
|
+
fail NotImplemented, 'Implement #render on your subclass of Vedeu::View.'
|
23
26
|
end
|
27
|
+
alias_method :output, :render
|
24
28
|
|
25
29
|
private
|
26
30
|
|
@@ -35,7 +39,8 @@ module Vedeu
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def attributes
|
38
|
-
|
42
|
+
render
|
39
43
|
end
|
44
|
+
|
40
45
|
end
|
41
46
|
end
|
@@ -2,25 +2,34 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe API do
|
5
|
+
let(:event) { mock('Event') }
|
6
|
+
|
7
|
+
before { Event.stubs(:new).returns(event) }
|
8
|
+
|
5
9
|
describe '.event' do
|
6
10
|
it 'registers and returns the event' do
|
7
11
|
Vedeu.event(:some_event).must_equal(
|
8
12
|
{
|
9
|
-
|
10
|
-
events: [nil],
|
11
|
-
last_exec: 0
|
13
|
+
events: [event],
|
12
14
|
}
|
13
15
|
)
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
19
|
+
describe '.unevent' do
|
20
|
+
it 'unregister the event by name' do
|
21
|
+
Vedeu.event(:calcium) { proc { |x| x } }
|
22
|
+
Vedeu.unevent(:calcium).wont_include(:calcium)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
17
26
|
describe '.events' do
|
18
27
|
it 'should not be visible to the client' do
|
19
28
|
skip
|
20
29
|
end
|
21
30
|
|
22
31
|
it 'returns the Events singleton' do
|
23
|
-
Vedeu.events.must_be_instance_of(
|
32
|
+
Vedeu.events.must_be_instance_of(Vedeu::Events)
|
24
33
|
end
|
25
34
|
end
|
26
35
|
|
@@ -33,36 +42,19 @@ module Vedeu
|
|
33
42
|
end
|
34
43
|
|
35
44
|
describe '.interface' do
|
36
|
-
it '
|
37
|
-
|
38
|
-
Vedeu::Store.reset
|
45
|
+
it 'creates and stores a new interface' do
|
46
|
+
Vedeu::Buffers.reset
|
39
47
|
|
40
|
-
Vedeu.interface('Vedeu.interface').must_equal(
|
41
|
-
{
|
42
|
-
"Vedeu.interface" => {
|
43
|
-
name: "Vedeu.interface",
|
44
|
-
group: "",
|
45
|
-
lines: [],
|
46
|
-
colour: {},
|
47
|
-
style: "",
|
48
|
-
geometry: {},
|
49
|
-
cursor: true,
|
50
|
-
delay: 0.0
|
51
|
-
}
|
52
|
-
}
|
53
|
-
)
|
48
|
+
Vedeu.interface('Vedeu.interface').must_equal(true)
|
54
49
|
end
|
55
50
|
end
|
56
51
|
|
57
52
|
describe '.keypress' do
|
58
|
-
|
59
|
-
Vedeu.keypress('k').must_equal()
|
60
|
-
end
|
61
|
-
end
|
53
|
+
before { event.stubs(:trigger).returns(nil) }
|
62
54
|
|
63
|
-
|
64
|
-
|
65
|
-
Vedeu.
|
55
|
+
it 'returns nil' do
|
56
|
+
skip
|
57
|
+
Vedeu.keypress('k').must_equal(nil)
|
66
58
|
end
|
67
59
|
end
|
68
60
|
|
@@ -75,7 +67,7 @@ module Vedeu
|
|
75
67
|
|
76
68
|
describe '.use' do
|
77
69
|
it 'raises an exception if the interface has not been defined' do
|
78
|
-
Vedeu::
|
70
|
+
Vedeu::Buffers.reset
|
79
71
|
|
80
72
|
proc { Vedeu.use('some_interface') }.must_raise(Vedeu::EntityNotFound)
|
81
73
|
end
|
@@ -104,6 +96,40 @@ module Vedeu
|
|
104
96
|
end
|
105
97
|
end
|
106
98
|
|
99
|
+
describe '.views' do
|
100
|
+
it 'returns the view attributes for a composition (a collection of ' \
|
101
|
+
'interfaces)' do
|
102
|
+
Vedeu.views do
|
103
|
+
view 'osmium'
|
104
|
+
view 'iridium'
|
105
|
+
end.must_equal(
|
106
|
+
{
|
107
|
+
interfaces: [
|
108
|
+
{
|
109
|
+
name: "osmium",
|
110
|
+
group: "",
|
111
|
+
lines: [],
|
112
|
+
colour: {},
|
113
|
+
style: "",
|
114
|
+
geometry: {},
|
115
|
+
cursor: true,
|
116
|
+
delay: 0.0
|
117
|
+
}, {
|
118
|
+
name: "iridium",
|
119
|
+
group: "",
|
120
|
+
lines: [],
|
121
|
+
colour: {},
|
122
|
+
style: "",
|
123
|
+
geometry: {},
|
124
|
+
cursor: true,
|
125
|
+
delay: 0.0
|
126
|
+
}
|
127
|
+
]
|
128
|
+
}
|
129
|
+
)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
107
133
|
describe '.width' do
|
108
134
|
it 'returns the terminal width' do
|
109
135
|
IO.console.stub(:winsize, [24, 40]) do
|
@@ -3,58 +3,12 @@ require 'test_helper'
|
|
3
3
|
module Vedeu
|
4
4
|
module API
|
5
5
|
describe Interface do
|
6
|
+
before { Vedeu::Buffers.reset }
|
6
7
|
describe '#define' do
|
7
|
-
before { Vedeu::Store.reset }
|
8
|
-
|
9
8
|
interface = Interface.new({ name: 'widget' })
|
10
9
|
|
11
10
|
it 'creates and stores a new interface' do
|
12
|
-
interface.define.must_equal(
|
13
|
-
{
|
14
|
-
'widget' => {
|
15
|
-
name: 'widget',
|
16
|
-
group: '',
|
17
|
-
lines: [],
|
18
|
-
colour: {},
|
19
|
-
style: '',
|
20
|
-
geometry: {},
|
21
|
-
cursor: true,
|
22
|
-
delay: 0.0
|
23
|
-
}
|
24
|
-
}
|
25
|
-
)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'raises an exception when the value is out of bounds' do
|
29
|
-
proc { interface.define { x 0 } }.must_raise(XOutOfBounds)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'raises an exception when the value is out of bounds' do
|
33
|
-
proc { interface.define { x 999 } }.must_raise(XOutOfBounds)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'raises an exception when the value is out of bounds' do
|
37
|
-
proc { interface.define { y 0 } }.must_raise(YOutOfBounds)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'raises an exception when the value is out of bounds' do
|
41
|
-
proc { interface.define { y 999 } }.must_raise(YOutOfBounds)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'raises an exception when the value is out of bounds' do
|
45
|
-
proc { interface.define { width 0 } }.must_raise(InvalidWidth)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'raises an exception when the value is out of bounds' do
|
49
|
-
proc { interface.define { width 999 } }.must_raise(InvalidWidth)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'raises an exception when the value is out of bounds' do
|
53
|
-
proc { interface.define { height 0 } }.must_raise(InvalidHeight)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'raises an exception when the value is out of bounds' do
|
57
|
-
proc { interface.define { height 999 } }.must_raise(InvalidHeight)
|
11
|
+
interface.define.must_equal(true)
|
58
12
|
end
|
59
13
|
|
60
14
|
it 'allows the setting of colours' do
|
@@ -176,7 +130,7 @@ module Vedeu
|
|
176
130
|
|
177
131
|
describe '#build' do
|
178
132
|
before do
|
179
|
-
|
133
|
+
|
180
134
|
Vedeu.interface('testing_view') do
|
181
135
|
x 1
|
182
136
|
y 1
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
module API
|
5
|
+
describe Line do
|
6
|
+
describe '#stream' do
|
7
|
+
it 'returns the value assigned' do
|
8
|
+
Line.new.stream do
|
9
|
+
text 'Some text...'
|
10
|
+
end.must_equal(
|
11
|
+
[
|
12
|
+
{
|
13
|
+
colour: {},
|
14
|
+
style: [],
|
15
|
+
text: "Some text...",
|
16
|
+
width: nil,
|
17
|
+
align: :left
|
18
|
+
}
|
19
|
+
]
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#text' do
|
25
|
+
it 'returns the value assigned' do
|
26
|
+
Line.new.text('Some text...').must_equal(
|
27
|
+
[
|
28
|
+
{ text: 'Some text...' }
|
29
|
+
]
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#foreground' do
|
35
|
+
it 'returns the value assigned' do
|
36
|
+
Line.new.foreground('#ff0000').must_equal(
|
37
|
+
[
|
38
|
+
{
|
39
|
+
colour: {
|
40
|
+
foreground: "#ff0000"
|
41
|
+
},
|
42
|
+
style: [],
|
43
|
+
text: "",
|
44
|
+
width: nil,
|
45
|
+
align: :left
|
46
|
+
}
|
47
|
+
]
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#background' do
|
53
|
+
it 'returns the value assigned' do
|
54
|
+
Line.new.background('#00ff00').must_equal(
|
55
|
+
[
|
56
|
+
{
|
57
|
+
colour: {
|
58
|
+
background: "#00ff00"
|
59
|
+
},
|
60
|
+
style: [],
|
61
|
+
text: "",
|
62
|
+
width: nil,
|
63
|
+
align: :left
|
64
|
+
}
|
65
|
+
]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|