vedeu 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/events.md +6 -0
- data/examples/{cursor_app/cursor_app.rb → cursor_app.rb} +1 -1
- data/examples/{lines_app/lines_app.rb → lines_app.rb} +1 -1
- data/lib/vedeu.rb +48 -28
- data/lib/vedeu/api/api.rb +8 -95
- data/lib/vedeu/application.rb +6 -2
- data/lib/vedeu/{models → colours}/background.rb +1 -1
- data/lib/vedeu/{models → colours}/colour.rb +0 -0
- data/lib/vedeu/{models → colours}/foreground.rb +2 -2
- data/lib/vedeu/{support/colour_translator.rb → colours/translator.rb} +7 -7
- data/lib/vedeu/input/input.rb +13 -5
- data/lib/vedeu/models/geometry.rb +30 -2
- data/lib/vedeu/models/key.rb +39 -0
- data/lib/vedeu/output/compositor.rb +30 -76
- data/lib/vedeu/output/output.rb +74 -0
- data/lib/vedeu/output/viewport.rb +36 -44
- data/lib/vedeu/repositories/buffers.rb +5 -18
- data/lib/vedeu/repositories/cursors.rb +16 -8
- data/lib/vedeu/repositories/events.rb +96 -9
- data/lib/vedeu/repositories/focus.rb +21 -20
- data/lib/vedeu/repositories/groups.rb +3 -11
- data/lib/vedeu/repositories/interfaces.rb +6 -9
- data/lib/vedeu/repositories/keymaps.rb +8 -3
- data/lib/vedeu/repositories/menus.rb +6 -21
- data/lib/vedeu/{models → repositories/models}/buffer.rb +62 -28
- data/lib/vedeu/{models → repositories/models}/cursor.rb +8 -2
- data/lib/vedeu/{models → repositories/models}/event.rb +7 -0
- data/lib/vedeu/repositories/models/group.rb +56 -0
- data/lib/vedeu/{models → repositories/models}/interface.rb +6 -0
- data/lib/vedeu/{models → repositories/models}/keymap.rb +7 -1
- data/lib/vedeu/{models → repositories/models}/menu.rb +9 -0
- data/lib/vedeu/{models → repositories/models}/offset.rb +8 -1
- data/lib/vedeu/repositories/offsets.rb +17 -12
- data/lib/vedeu/support/bounding_area.rb +127 -0
- data/lib/vedeu/support/common.rb +8 -0
- data/lib/vedeu/support/exceptions.rb +2 -12
- data/lib/vedeu/support/model.rb +14 -0
- data/lib/vedeu/support/refresh.rb +8 -7
- data/lib/vedeu/support/registrar.rb +7 -1
- data/lib/vedeu/support/repository.rb +31 -10
- data/lib/vedeu/support/sentence.rb +67 -0
- data/lib/vedeu/support/terminal.rb +19 -0
- data/lib/vedeu/support/trace.rb +2 -5
- data/test/integration/api/api_test.rb +97 -0
- data/test/integration/api_dsl/dsl_api_test.rb +4 -0
- data/test/integration/api_dsl/dsl_composition_test.rb +4 -0
- data/test/integration/api_dsl/dsl_defined_test.rb +4 -0
- data/test/integration/api_dsl/dsl_helpers_test.rb +4 -0
- data/test/integration/api_dsl/dsl_interface_test.rb +4 -0
- data/test/integration/api_dsl/dsl_keymap.rb +4 -0
- data/test/integration/api_dsl/dsl_line_test.rb +4 -0
- data/test/integration/api_dsl/dsl_menu_test.rb +4 -0
- data/test/integration/api_dsl/dsl_stream_test.rb +138 -0
- data/test/lib/vedeu/api/api_test.rb +1 -25
- data/test/lib/vedeu/api/helpers_test.rb +0 -10
- data/test/lib/vedeu/{models → colours}/background_test.rb +0 -0
- data/test/lib/vedeu/{models → colours}/colour_test.rb +0 -0
- data/test/lib/vedeu/{models → colours}/foreground_test.rb +0 -0
- data/test/lib/vedeu/{support/colour_translator_test.rb → colours/translator_test.rb} +3 -3
- data/test/lib/vedeu/input/input_test.rb +16 -47
- data/test/lib/vedeu/models/geometry_test.rb +46 -0
- data/test/lib/vedeu/models/group_test.rb +99 -0
- data/test/lib/vedeu/models/key_test.rb +41 -0
- data/test/lib/vedeu/output/compositor_test.rb +25 -101
- data/test/lib/vedeu/output/output_test.rb +108 -0
- data/test/lib/vedeu/repositories/buffers_test.rb +0 -8
- data/test/lib/vedeu/repositories/cursors_test.rb +34 -0
- data/test/lib/vedeu/repositories/focus_test.rb +37 -28
- data/test/lib/vedeu/repositories/interfaces_test.rb +1 -1
- data/test/lib/vedeu/repositories/keymaps_test.rb +6 -20
- data/test/lib/vedeu/repositories/menus_test.rb +0 -6
- data/test/lib/vedeu/{models → repositories/models}/buffer_test.rb +24 -27
- data/test/lib/vedeu/{models → repositories/models}/cursor_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/event_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/interface_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/keymap_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/menu_test.rb +0 -0
- data/test/lib/vedeu/{models → repositories/models}/offset_test.rb +0 -0
- data/test/lib/vedeu/support/bounding_area_test.rb +139 -0
- data/test/lib/vedeu/support/coercions_test.rb +6 -17
- data/test/lib/vedeu/support/grid_test.rb +1 -1
- data/test/lib/vedeu/support/model_test.rb +23 -0
- data/test/lib/vedeu/support/presentation_test.rb +0 -10
- data/test/lib/vedeu/support/refresh_test.rb +2 -2
- data/test/lib/vedeu/support/repository_test.rb +63 -64
- data/test/lib/vedeu/support/sentence_test.rb +48 -0
- data/test/lib/vedeu/support/terminal_test.rb +86 -6
- data/test/support/test_classes/all.rb +5 -0
- data/test/support/test_classes/coercions.rb +16 -0
- data/test/support/test_classes/helpers.rb +19 -0
- data/test/support/test_classes/model.rb +23 -0
- data/test/support/test_classes/presentation.rb +16 -0
- data/test/support/test_classes/repositories.rb +26 -0
- data/test/support/test_modules/all.rb +1 -0
- data/test/support/test_modules/repository.rb +16 -0
- data/test/test_helper.rb +4 -0
- data/vedeu.gemspec +3 -3
- metadata +95 -50
- data/lib/vedeu/output/clear.rb +0 -88
- data/lib/vedeu/output/render.rb +0 -50
- data/lib/vedeu/repositories/positional.rb +0 -23
- data/test/lib/vedeu/output/clear_test.rb +0 -56
- data/test/lib/vedeu/output/render_test.rb +0 -100
- data/test/lib/vedeu/repositories/positional_test.rb +0 -50
@@ -8,9 +8,6 @@ module Vedeu
|
|
8
8
|
include Common
|
9
9
|
extend self
|
10
10
|
|
11
|
-
# System event to refresh all registered interfaces.
|
12
|
-
Vedeu.event(:_refresh_) { Vedeu::Refresh.all }
|
13
|
-
|
14
11
|
# Refresh all registered interfaces.
|
15
12
|
#
|
16
13
|
# @return [Array]
|
@@ -28,7 +25,7 @@ module Vedeu
|
|
28
25
|
# Refresh an interface, or collection of interfaces belonging to a group.
|
29
26
|
#
|
30
27
|
# @param group_name [String] The name of the group to be refreshed.
|
31
|
-
# @return [Array|
|
28
|
+
# @return [Array|ModelNotFound] A collection of the names of interfaces
|
32
29
|
# refreshed, or an exception if the group was not found.
|
33
30
|
def by_group(group_name)
|
34
31
|
Groups.find(group_name).each { |name| by_name(name) }
|
@@ -36,10 +33,14 @@ module Vedeu
|
|
36
33
|
|
37
34
|
# Refresh an interface by name.
|
38
35
|
#
|
39
|
-
# @param name [String] The name of the interface to be refreshed
|
40
|
-
#
|
36
|
+
# @param name [String] The name of the interface to be refreshed using the
|
37
|
+
# named buffer.
|
38
|
+
# @return [Array|ModelNotFound]
|
41
39
|
def by_name(name)
|
42
|
-
|
40
|
+
interface = Interfaces.find(name)
|
41
|
+
buffer = Buffers.find(name)
|
42
|
+
|
43
|
+
Compositor.compose(interface, buffer)
|
43
44
|
end
|
44
45
|
|
45
46
|
# Register a refresh event for an interface or group of interfaces by name.
|
@@ -6,7 +6,7 @@ module Vedeu
|
|
6
6
|
# @api private
|
7
7
|
class Registrar
|
8
8
|
|
9
|
-
REPOSITORIES = [Buffers, Cursors,
|
9
|
+
REPOSITORIES = [Buffers, Cursors, Groups, Interfaces, Offsets]
|
10
10
|
|
11
11
|
# @param attributes [Hash]
|
12
12
|
# @return [TrueClass|MissingRequired]
|
@@ -33,6 +33,8 @@ module Vedeu
|
|
33
33
|
#
|
34
34
|
# @return [TrueClass|MissingRequired]
|
35
35
|
def record
|
36
|
+
focus
|
37
|
+
|
36
38
|
REPOSITORIES.each { |repository| repository.add(attributes) }
|
37
39
|
|
38
40
|
true
|
@@ -42,6 +44,10 @@ module Vedeu
|
|
42
44
|
|
43
45
|
attr_reader :attributes
|
44
46
|
|
47
|
+
def focus
|
48
|
+
Focus.add(attributes[:name], attributes[:focus])
|
49
|
+
end
|
50
|
+
|
45
51
|
end # Registrar
|
46
52
|
|
47
53
|
end # Vedeu
|
@@ -14,7 +14,14 @@ module Vedeu
|
|
14
14
|
storage
|
15
15
|
end
|
16
16
|
|
17
|
-
#
|
17
|
+
# Return a boolean indicating whether the storage is empty.
|
18
|
+
#
|
19
|
+
# @return [Boolean]
|
20
|
+
def empty?
|
21
|
+
storage.empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
# Find the model attributes by name.
|
18
25
|
#
|
19
26
|
# @param name [String]
|
20
27
|
# @return [Hash]
|
@@ -22,16 +29,15 @@ module Vedeu
|
|
22
29
|
storage.fetch(name) { not_found(name) }
|
23
30
|
end
|
24
31
|
|
25
|
-
# Find
|
26
|
-
# not found.
|
32
|
+
# Find a model by name, registers the model by name if not found.
|
27
33
|
#
|
28
34
|
# @param name [String]
|
29
35
|
# @return [Cursor|Offset]
|
30
36
|
def find_or_create(name)
|
31
37
|
storage.fetch(name) do
|
32
|
-
Vedeu.log("
|
38
|
+
Vedeu.log("Model (#{model}) not found, registering: '#{name}'")
|
33
39
|
|
34
|
-
|
40
|
+
model.new({ name: name }).store
|
35
41
|
end
|
36
42
|
end
|
37
43
|
|
@@ -39,7 +45,7 @@ module Vedeu
|
|
39
45
|
#
|
40
46
|
# @return [Array]
|
41
47
|
def registered
|
42
|
-
return [] if
|
48
|
+
return [] if empty?
|
43
49
|
|
44
50
|
return storage.keys if storage.is_a?(Hash)
|
45
51
|
return storage.to_a if storage.is_a?(Set)
|
@@ -47,23 +53,23 @@ module Vedeu
|
|
47
53
|
storage
|
48
54
|
end
|
49
55
|
|
50
|
-
# Returns a boolean indicating whether the named
|
56
|
+
# Returns a boolean indicating whether the named model is registered.
|
51
57
|
#
|
52
58
|
# @param name [String]
|
53
59
|
# @return [Boolean]
|
54
60
|
def registered?(name)
|
55
|
-
return false if
|
61
|
+
return false if empty?
|
56
62
|
|
57
63
|
storage.include?(name)
|
58
64
|
end
|
59
65
|
|
60
|
-
# Returns the storage with the named
|
66
|
+
# Returns the storage with the named model removed, or false if the model
|
61
67
|
# does not exist.
|
62
68
|
#
|
63
69
|
# @param name [String]
|
64
70
|
# @return [Hash|FalseClass]
|
65
71
|
def remove(name)
|
66
|
-
return false if
|
72
|
+
return false if empty?
|
67
73
|
|
68
74
|
if registered?(name)
|
69
75
|
storage.delete(name)
|
@@ -84,6 +90,14 @@ module Vedeu
|
|
84
90
|
@_storage = in_memory
|
85
91
|
end
|
86
92
|
|
93
|
+
# Stores the model instance by name in the repository of the model.
|
94
|
+
#
|
95
|
+
# @param model [void] A model instance.
|
96
|
+
# @return [void] The model instance which was stored.
|
97
|
+
def store(model)
|
98
|
+
storage[model.name] = model
|
99
|
+
end
|
100
|
+
|
87
101
|
private
|
88
102
|
|
89
103
|
# @param method [Symbol]
|
@@ -94,6 +108,13 @@ module Vedeu
|
|
94
108
|
'Updating'
|
95
109
|
end
|
96
110
|
|
111
|
+
# @param name [String]
|
112
|
+
# @raise [ModelNotFound] When the model cannot be found with this name.
|
113
|
+
# @return [ModelNotFound]
|
114
|
+
def not_found(name)
|
115
|
+
fail ModelNotFound, "Cannot find model by name: '#{name}'"
|
116
|
+
end
|
117
|
+
|
97
118
|
# Access to the storage for this repository.
|
98
119
|
#
|
99
120
|
# @return [Hash]
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Vedeu
|
2
|
+
|
3
|
+
class Sentence
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def construct(elements, label = 'elements')
|
8
|
+
new(elements, label).construct
|
9
|
+
end
|
10
|
+
|
11
|
+
end # Sentence eigenclass
|
12
|
+
|
13
|
+
def initialize(elements, label)
|
14
|
+
@elements, @label = elements, label
|
15
|
+
end
|
16
|
+
|
17
|
+
def construct
|
18
|
+
if one?
|
19
|
+
first
|
20
|
+
|
21
|
+
elsif two?
|
22
|
+
elements.join(' and ')
|
23
|
+
|
24
|
+
elsif many?
|
25
|
+
[but_last, last].join(' and ')
|
26
|
+
|
27
|
+
else
|
28
|
+
"No #{label} have been assigned."
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :elements, :label
|
36
|
+
|
37
|
+
def one?
|
38
|
+
count == 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def two?
|
42
|
+
count == 2
|
43
|
+
end
|
44
|
+
|
45
|
+
def many?
|
46
|
+
count > 2
|
47
|
+
end
|
48
|
+
|
49
|
+
def but_last
|
50
|
+
elements[0...-1].join(', ')
|
51
|
+
end
|
52
|
+
|
53
|
+
def first
|
54
|
+
elements.first
|
55
|
+
end
|
56
|
+
|
57
|
+
def last
|
58
|
+
elements[-1]
|
59
|
+
end
|
60
|
+
|
61
|
+
def count
|
62
|
+
elements.size
|
63
|
+
end
|
64
|
+
|
65
|
+
end # Sentence
|
66
|
+
|
67
|
+
end # Vedeu
|
@@ -51,6 +51,7 @@ module Vedeu
|
|
51
51
|
|
52
52
|
end
|
53
53
|
end
|
54
|
+
alias_method :read, :input
|
54
55
|
|
55
56
|
# Prints the streams to the screen and returns the streams.
|
56
57
|
#
|
@@ -170,20 +171,38 @@ module Vedeu
|
|
170
171
|
centre.last
|
171
172
|
end
|
172
173
|
|
174
|
+
# Returns 1. This 1 is either the top-most or left-most coordinate of the
|
175
|
+
# terminal.
|
176
|
+
#
|
177
|
+
# @return [Fixnum]
|
178
|
+
def origin
|
179
|
+
1
|
180
|
+
end
|
181
|
+
alias_method :x, :origin
|
182
|
+
alias_method :y, :origin
|
183
|
+
|
173
184
|
# Returns the total width (number of columns/characters) of the current
|
174
185
|
# terminal.
|
175
186
|
#
|
187
|
+
# @example
|
188
|
+
# Vedeu.width # => provides the width via the Vedeu API.
|
189
|
+
#
|
176
190
|
# @return [Fixnum]
|
177
191
|
def width
|
178
192
|
size.last
|
179
193
|
end
|
194
|
+
alias_method :xn, :width
|
180
195
|
|
181
196
|
# Returns the total height (number of rows/lines) of the current terminal.
|
182
197
|
#
|
198
|
+
# @example
|
199
|
+
# Vedeu.height # => provides the height via the Vedeu API.
|
200
|
+
#
|
183
201
|
# @return [Fixnum]
|
184
202
|
def height
|
185
203
|
size.first
|
186
204
|
end
|
205
|
+
alias_method :yn, :height
|
187
206
|
|
188
207
|
# Returns a tuple containing the height and width of the current terminal.
|
189
208
|
#
|
data/lib/vedeu/support/trace.rb
CHANGED
@@ -146,12 +146,9 @@ module Vedeu
|
|
146
146
|
# @return [Set]
|
147
147
|
def vedeu_exceptions
|
148
148
|
Set.new [
|
149
|
-
'Vedeu::
|
150
|
-
'Vedeu::GroupNotFound',
|
151
|
-
'Vedeu::InterfaceNotFound',
|
149
|
+
'Vedeu::ModelNotFound',
|
152
150
|
'Vedeu::InvalidSyntax',
|
153
151
|
'Vedeu::KeyInUse',
|
154
|
-
'Vedeu::MenuNotFound',
|
155
152
|
'Vedeu::MissingRequired',
|
156
153
|
'Vedeu::ModeSwitch',
|
157
154
|
'Vedeu::NoInterfacesDefined',
|
@@ -174,7 +171,7 @@ module Vedeu
|
|
174
171
|
# 'Vedeu::Clear',
|
175
172
|
'Vedeu::Coercions',
|
176
173
|
'Vedeu::Colour',
|
177
|
-
'Vedeu::
|
174
|
+
'Vedeu::Translator',
|
178
175
|
'Vedeu::Common',
|
179
176
|
# 'Vedeu::Composition',
|
180
177
|
# 'Vedeu::Compositor',
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe 'Testing Vedeu::API methods' do
|
4
|
+
|
5
|
+
describe '.configure' do
|
6
|
+
it 'raises an exception when the required block is not given' do
|
7
|
+
proc { Vedeu.configure }.must_raise(Vedeu::InvalidSyntax)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.defined' do
|
12
|
+
it 'returns the Vedeu::API::Defined module name' do
|
13
|
+
Vedeu.defined.must_equal(Vedeu::API::Defined)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.event' do
|
18
|
+
it 'returns a list of event associated with the provided event name ' \
|
19
|
+
'after adding the event' do
|
20
|
+
skip 'Need to mock an event'
|
21
|
+
Vedeu.event(:_hydrogen_event_).must_equal('')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should raise an exception when the event name is nil or empty' do
|
25
|
+
skip 'Need to raise an exception'
|
26
|
+
Vedeu.event(nil).must_equal('')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '.focus' do
|
31
|
+
it 'raises an exception when the interface does not exist' do
|
32
|
+
proc { Vedeu.focus(nil) }.must_raise(Vedeu::ModelNotFound)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'raises an exception when the interface does not exist' do
|
36
|
+
proc { Vedeu.focus('not_defined') }.must_raise(Vedeu::ModelNotFound)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'sets the specified interface as in focus' do
|
40
|
+
skip 'Finish this test off'
|
41
|
+
Vedeu.focus('hydrogen')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.height' do
|
46
|
+
before { Vedeu::Terminal.console.stubs(:winsize).returns([25, 80]) }
|
47
|
+
|
48
|
+
it 'returns the height of the terminal' do
|
49
|
+
Vedeu.height.must_equal(25)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.interface' do
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '.keypress' do
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '.keys' do
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '.log' do
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '.menu' do
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '.render' do
|
69
|
+
end
|
70
|
+
|
71
|
+
describe '.resize' do
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '.trigger' do
|
75
|
+
end
|
76
|
+
|
77
|
+
describe '.unevent' do
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '.use' do
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '.view' do
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '.views' do
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '.width' do
|
90
|
+
before { Vedeu::Terminal.console.stubs(:winsize).returns([25, 80]) }
|
91
|
+
|
92
|
+
it 'returns the width of the terminal' do
|
93
|
+
Vedeu.width.must_equal(80)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|