vedeu 0.6.8 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardopts +9 -0
- data/README.md +1 -1
- data/docs/api.md +60 -67
- data/docs/configuration.md +8 -5
- data/docs/events.md +31 -15
- data/docs/events/application.md +12 -0
- data/docs/events/document.md +57 -0
- data/docs/events/drb.md +43 -0
- data/docs/events/focus.md +24 -0
- data/docs/events/menu.md +57 -0
- data/docs/events/movement.md +57 -0
- data/docs/events/refresh.md +25 -0
- data/docs/events/system.md +90 -0
- data/docs/events/visibility.md +68 -0
- data/lib/vedeu.rb +2 -2
- data/lib/vedeu/all.rb +3 -2
- data/lib/vedeu/api.rb +18 -18
- data/lib/vedeu/application/controller.rb +1 -1
- data/lib/vedeu/application/helper.rb +1 -1
- data/lib/vedeu/application/view.rb +1 -1
- data/lib/vedeu/bindings/application.rb +1 -12
- data/lib/vedeu/bindings/bindings.rb +3 -1
- data/lib/vedeu/bindings/document.rb +9 -62
- data/lib/vedeu/bindings/drb.rb +12 -56
- data/lib/vedeu/bindings/focus.rb +3 -28
- data/lib/vedeu/bindings/menus.rb +10 -66
- data/lib/vedeu/bindings/movement.rb +4 -69
- data/lib/vedeu/bindings/refresh.rb +3 -33
- data/lib/vedeu/bindings/system.rb +14 -100
- data/lib/vedeu/bindings/visibility.rb +20 -71
- data/lib/vedeu/borders/all.rb +4 -3
- data/lib/vedeu/borders/border.rb +39 -33
- data/lib/vedeu/borders/dsl.rb +40 -33
- data/lib/vedeu/borders/null.rb +2 -2
- data/lib/vedeu/borders/render.rb +29 -24
- data/lib/vedeu/borders/repository.rb +2 -2
- data/lib/vedeu/buffers/all.rb +8 -7
- data/lib/vedeu/buffers/buffer.rb +47 -39
- data/lib/vedeu/buffers/null.rb +2 -2
- data/lib/vedeu/buffers/refresh.rb +4 -3
- data/lib/vedeu/buffers/virtual_buffer.rb +122 -118
- data/lib/vedeu/buffers/virtual_buffers.rb +62 -56
- data/lib/vedeu/colours/background.rb +2 -1
- data/lib/vedeu/colours/colour.rb +21 -19
- data/lib/vedeu/colours/foreground.rb +2 -1
- data/lib/vedeu/colours/repository.rb +6 -5
- data/lib/vedeu/colours/translator.rb +39 -35
- data/lib/vedeu/configuration/api.rb +59 -51
- data/lib/vedeu/configuration/cli.rb +9 -7
- data/lib/vedeu/configuration/configuration.rb +41 -32
- data/lib/vedeu/cursors/cursor.rb +1 -1
- data/lib/vedeu/cursors/refresh.rb +20 -16
- data/lib/vedeu/distributed/server.rb +8 -6
- data/lib/vedeu/distributed/subprocess.rb +90 -86
- data/lib/vedeu/distributed/uri.rb +4 -3
- data/lib/vedeu/dsl/composition.rb +2 -2
- data/lib/vedeu/dsl/group.rb +4 -4
- data/lib/vedeu/dsl/interface.rb +5 -5
- data/lib/vedeu/dsl/presentation.rb +2 -2
- data/lib/vedeu/dsl/text.rb +1 -1
- data/lib/vedeu/editor/cropper.rb +4 -4
- data/lib/vedeu/editor/cursor.rb +6 -4
- data/lib/vedeu/editor/document.rb +20 -18
- data/lib/vedeu/editor/editor.rb +2 -2
- data/lib/vedeu/editor/line.rb +10 -5
- data/lib/vedeu/editor/lines.rb +2 -2
- data/lib/vedeu/internal_api.rb +4 -4
- data/lib/vedeu/models/focus.rb +197 -191
- data/lib/vedeu/models/group.rb +171 -159
- data/lib/vedeu/models/groups.rb +14 -10
- data/lib/vedeu/models/interface.rb +116 -110
- data/lib/vedeu/models/interfaces.rb +24 -20
- data/lib/vedeu/models/toggleable.rb +4 -4
- data/lib/vedeu/models/views/char.rb +1 -1
- data/lib/vedeu/models/views/composition.rb +1 -1
- data/lib/vedeu/models/views/line.rb +1 -1
- data/lib/vedeu/models/views/stream.rb +1 -1
- data/lib/vedeu/models/views/view.rb +1 -1
- data/lib/vedeu/null/interface.rb +1 -1
- data/lib/vedeu/null/view.rb +1 -1
- data/lib/vedeu/output/clear/named_interface.rb +1 -1
- data/lib/vedeu/output/compressor.rb +78 -73
- data/lib/vedeu/output/direct.rb +61 -57
- data/lib/vedeu/output/output.rb +34 -29
- data/lib/vedeu/output/{presentation.rb → presentation/presentation.rb} +2 -1
- data/lib/vedeu/output/presentation/style.rb +64 -18
- data/lib/vedeu/output/presentation/styles.rb +39 -0
- data/lib/vedeu/output/renderers/html.rb +2 -2
- data/lib/vedeu/output/renderers/json.rb +2 -1
- data/lib/vedeu/output/renderers/terminal.rb +3 -3
- data/lib/vedeu/output/renderers/text.rb +3 -3
- data/lib/vedeu/output/text.rb +186 -180
- data/lib/vedeu/output/wordwrap.rb +142 -138
- data/lib/vedeu/refresh/refresh.rb +2 -2
- data/lib/vedeu/templating/helpers.rb +11 -6
- data/lib/vedeu/templating/view_template.rb +1 -1
- data/lib/vedeu/terminal/terminal.rb +2 -2
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/borders/render_test.rb +1 -1
- data/test/lib/vedeu/buffers/buffer_test.rb +16 -14
- data/test/lib/vedeu/buffers/virtual_buffer_test.rb +105 -101
- data/test/lib/vedeu/buffers/virtual_buffers_test.rb +43 -39
- data/test/lib/vedeu/colours/colour_test.rb +4 -4
- data/test/lib/vedeu/cursors/cursor_test.rb +2 -2
- data/test/lib/vedeu/cursors/repository_test.rb +3 -3
- data/test/lib/vedeu/distributed/subprocess_test.rb +33 -29
- data/test/lib/vedeu/dsl/group_test.rb +3 -3
- data/test/lib/vedeu/dsl/interface_test.rb +6 -5
- data/test/lib/vedeu/dsl/line_test.rb +4 -2
- data/test/lib/vedeu/dsl/presentation_test.rb +2 -2
- data/test/lib/vedeu/dsl/text_test.rb +8 -8
- data/test/lib/vedeu/editor/document_test.rb +10 -6
- data/test/lib/vedeu/input/keymap_test.rb +1 -10
- data/test/lib/vedeu/models/focus_test.rb +177 -170
- data/test/lib/vedeu/models/group_test.rb +99 -95
- data/test/lib/vedeu/models/groups_test.rb +13 -9
- data/test/lib/vedeu/models/interface_test.rb +93 -87
- data/test/lib/vedeu/models/interfaces_test.rb +24 -20
- data/test/lib/vedeu/models/views/char_test.rb +2 -2
- data/test/lib/vedeu/models/views/line_test.rb +11 -7
- data/test/lib/vedeu/models/views/stream_test.rb +1 -1
- data/test/lib/vedeu/models/views/view_test.rb +1 -1
- data/test/lib/vedeu/output/clear/named_group_test.rb +1 -1
- data/test/lib/vedeu/output/clear/named_interface_test.rb +3 -1
- data/test/lib/vedeu/output/compressor_test.rb +126 -122
- data/test/lib/vedeu/output/direct_test.rb +49 -43
- data/test/lib/vedeu/output/output_test.rb +35 -31
- data/test/lib/vedeu/output/{presentation_test.rb → presentation/presentation_test.rb} +11 -7
- data/test/lib/vedeu/output/presentation/style_test.rb +88 -48
- data/test/lib/vedeu/output/presentation/styles_test.rb +84 -0
- data/test/lib/vedeu/output/text_test.rb +109 -105
- data/test/lib/vedeu/output/viewport_test.rb +3 -1
- data/test/lib/vedeu/output/wordwrap_test.rb +209 -205
- data/test/lib/vedeu/refresh/refresh_test.rb +3 -1
- data/test/lib/vedeu/templating/helpers_test.rb +6 -6
- data/test/lib/vedeu/templating/view_template_test.rb +1 -1
- metadata +17 -8
- data/lib/vedeu/output/style.rb +0 -76
- data/test/lib/vedeu/output/style_test.rb +0 -120
@@ -1,11 +1,12 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
# Provides a mechanism to control a running client application via
|
3
|
+
# Provides a mechanism to control a running client application via
|
4
|
+
# DRb.
|
4
5
|
#
|
5
6
|
module Distributed
|
6
7
|
|
7
|
-
# Value class which provides the host and port for the DRb server
|
8
|
-
# client.
|
8
|
+
# Value class which provides the host and port for the DRb server
|
9
|
+
# and client.
|
9
10
|
#
|
10
11
|
class Uri
|
11
12
|
|
@@ -97,7 +97,7 @@ module Vedeu
|
|
97
97
|
# paths.
|
98
98
|
# @param object [Object] The object for which the values of template's
|
99
99
|
# variables can be obtained.
|
100
|
-
# @param options [Hash] See {Vedeu::Wordwrap}
|
100
|
+
# @param options [Hash] See {Vedeu::Output::Wordwrap}
|
101
101
|
# @raise [Vedeu::Error::MissingRequired]
|
102
102
|
# @return [Vedeu::Views::Views<Vedeu::Views::View>]
|
103
103
|
def template_for(name, filename, object = nil, options = {})
|
@@ -112,7 +112,7 @@ module Vedeu
|
|
112
112
|
filename,
|
113
113
|
options)
|
114
114
|
|
115
|
-
# lines = Vedeu::Wordwrap.for(content, options)
|
115
|
+
# lines = Vedeu::Output::Wordwrap.for(content, options)
|
116
116
|
|
117
117
|
new_model = model.member.build(template_attributes(name, content))
|
118
118
|
|
data/lib/vedeu/dsl/group.rb
CHANGED
@@ -51,16 +51,16 @@ module Vedeu
|
|
51
51
|
# @param name [String] The name of this group.
|
52
52
|
# @param block [Proc]
|
53
53
|
# @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
|
54
|
-
# @return [Vedeu::Group]
|
54
|
+
# @return [Vedeu::Models::Group]
|
55
55
|
def self.group(name, &block)
|
56
56
|
fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
|
57
57
|
|
58
|
-
Vedeu::Group.build(name: name, &block).store
|
58
|
+
Vedeu::Models::Group.build(name: name, &block).store
|
59
59
|
end
|
60
60
|
|
61
61
|
# Returns an instance of DSL::Group.
|
62
62
|
#
|
63
|
-
# @param model [Vedeu::Group]
|
63
|
+
# @param model [Vedeu::Models::Group]
|
64
64
|
# @param client [Object]
|
65
65
|
# @return [Vedeu::DSL::Group]
|
66
66
|
def initialize(model, client = nil)
|
@@ -75,7 +75,7 @@ module Vedeu
|
|
75
75
|
# end
|
76
76
|
#
|
77
77
|
# @param interface_name [String]
|
78
|
-
# @return [Vedeu::Group]
|
78
|
+
# @return [Vedeu::Models::Group]
|
79
79
|
def add(interface_name)
|
80
80
|
model.add(interface_name)
|
81
81
|
end
|
data/lib/vedeu/dsl/interface.rb
CHANGED
@@ -30,7 +30,7 @@ module Vedeu
|
|
30
30
|
# @param block [Proc] A set of attributes which define the features of
|
31
31
|
# the interface.
|
32
32
|
# @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
|
33
|
-
# @return [Vedeu::Interface]
|
33
|
+
# @return [Vedeu::Models::Interface]
|
34
34
|
# @todo More documentation required.
|
35
35
|
def interface(name, &block)
|
36
36
|
fail Vedeu::Error::InvalidSyntax,
|
@@ -44,7 +44,7 @@ module Vedeu
|
|
44
44
|
|
45
45
|
attributes = { client: client(&block), name: name }
|
46
46
|
|
47
|
-
Vedeu::Interface.build(attributes, &block).store
|
47
|
+
Vedeu::Models::Interface.build(attributes, &block).store
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
@@ -166,7 +166,7 @@ module Vedeu
|
|
166
166
|
#
|
167
167
|
# @return [Array<String>] A list of focusable interfaces.
|
168
168
|
def focus!
|
169
|
-
Vedeu::Focus.add(model.name, true) if present?(model.name)
|
169
|
+
Vedeu::Models::Focus.add(model.name, true) if present?(model.name)
|
170
170
|
end
|
171
171
|
|
172
172
|
# Specify a group for an interface. Interfaces of the same group can be
|
@@ -181,7 +181,7 @@ module Vedeu
|
|
181
181
|
#
|
182
182
|
# @param name [String] The name of the group to which this interface
|
183
183
|
# should belong.
|
184
|
-
# @return [Vedeu::Group]
|
184
|
+
# @return [Vedeu::Models::Group]
|
185
185
|
def group(name)
|
186
186
|
return false unless present?(name)
|
187
187
|
|
@@ -249,7 +249,7 @@ module Vedeu
|
|
249
249
|
#
|
250
250
|
# @param name [String] The name of the interface model you wish to use a
|
251
251
|
# value from.
|
252
|
-
# @return [Vedeu::Interface]
|
252
|
+
# @return [Vedeu::Models::Interface]
|
253
253
|
def use(name)
|
254
254
|
model.repository.by_name(name)
|
255
255
|
end
|
@@ -107,9 +107,9 @@ module Vedeu
|
|
107
107
|
# # ...
|
108
108
|
# end
|
109
109
|
#
|
110
|
-
# @return [Vedeu::Style]
|
110
|
+
# @return [Vedeu::Presentation::Style]
|
111
111
|
def style(value)
|
112
|
-
model.style = Vedeu::Style.coerce(value)
|
112
|
+
model.style = Vedeu::Presentation::Style.coerce(value)
|
113
113
|
end
|
114
114
|
alias_method :style=, :style
|
115
115
|
alias_method :styles, :style
|
data/lib/vedeu/dsl/text.rb
CHANGED
data/lib/vedeu/editor/cropper.rb
CHANGED
@@ -2,8 +2,8 @@ module Vedeu
|
|
2
2
|
|
3
3
|
module Editor
|
4
4
|
|
5
|
-
# Crop the lines to the visible area of the document, as defined
|
6
|
-
# geometry provided.
|
5
|
+
# Crop the lines to the visible area of the document, as defined
|
6
|
+
# by the geometry provided.
|
7
7
|
#
|
8
8
|
class Cropper
|
9
9
|
|
@@ -25,8 +25,8 @@ module Vedeu
|
|
25
25
|
|
26
26
|
# Returns the lines cropped.
|
27
27
|
#
|
28
|
-
# @note If there are no lines of content, we return an empty
|
29
|
-
# there are any empty lines, then they are discarded.
|
28
|
+
# @note If there are no lines of content, we return an empty
|
29
|
+
# array. If there are any empty lines, then they are discarded.
|
30
30
|
#
|
31
31
|
# @return [Array<void>]
|
32
32
|
def cropped
|
data/lib/vedeu/editor/cursor.rb
CHANGED
@@ -2,7 +2,8 @@ module Vedeu
|
|
2
2
|
|
3
3
|
module Editor
|
4
4
|
|
5
|
-
# Maintains a cursor position within the Vedeu::Editor::Document
|
5
|
+
# Maintains a cursor position within the {Vedeu::Editor::Document}
|
6
|
+
# class.
|
6
7
|
#
|
7
8
|
class Cursor
|
8
9
|
|
@@ -42,7 +43,8 @@ module Vedeu
|
|
42
43
|
#
|
43
44
|
# @param attributes [Hash]
|
44
45
|
# @option attributes y [Fixnum] The current line.
|
45
|
-
# @option attributes x [Fixnum] The current character with the
|
46
|
+
# @option attributes x [Fixnum] The current character with the
|
47
|
+
# line.
|
46
48
|
# @option attributes by [Fixnum]
|
47
49
|
# @option attributes bx [Fixnum]
|
48
50
|
# @option attributes byn [Fixnum]
|
@@ -108,8 +110,8 @@ module Vedeu
|
|
108
110
|
self
|
109
111
|
end
|
110
112
|
|
111
|
-
# Return the escape sequence for setting the cursor position and
|
112
|
-
# cursor.
|
113
|
+
# Return the escape sequence for setting the cursor position and
|
114
|
+
# show the cursor.
|
113
115
|
#
|
114
116
|
# @return [String]
|
115
117
|
def to_s
|
@@ -55,11 +55,11 @@ module Vedeu
|
|
55
55
|
#
|
56
56
|
# @return [void]
|
57
57
|
def clear
|
58
|
-
Vedeu::Direct.write(value: clear_output, x: bx, y: by)
|
58
|
+
Vedeu::Output::Direct.write(value: clear_output, x: bx, y: by)
|
59
59
|
end
|
60
60
|
|
61
|
-
# Deletes the character from the line where the cursor is
|
62
|
-
# positioned.
|
61
|
+
# Deletes the character from the line where the cursor is
|
62
|
+
# currently positioned.
|
63
63
|
#
|
64
64
|
# @return [Vedeu::Editor::Document]
|
65
65
|
def delete_character
|
@@ -90,8 +90,8 @@ module Vedeu
|
|
90
90
|
refresh
|
91
91
|
end
|
92
92
|
|
93
|
-
# Returns the document as a string with line breaks if there is
|
94
|
-
# one line.
|
93
|
+
# Returns the document as a string with line breaks if there is
|
94
|
+
# more than one line.
|
95
95
|
#
|
96
96
|
# @return [String]
|
97
97
|
def execute
|
@@ -106,8 +106,8 @@ module Vedeu
|
|
106
106
|
command
|
107
107
|
end
|
108
108
|
|
109
|
-
# Inserts the given character in to the line where the cursor is
|
110
|
-
# positioned.
|
109
|
+
# Inserts the given character in to the line where the cursor is
|
110
|
+
# currently positioned.
|
111
111
|
#
|
112
112
|
# @param character [String|Symbol]
|
113
113
|
# @return [Vedeu::Editor::Document]
|
@@ -150,7 +150,8 @@ module Vedeu
|
|
150
150
|
lines.line(y)
|
151
151
|
end
|
152
152
|
|
153
|
-
# Returns the collection of lines which constitutes the document
|
153
|
+
# Returns the collection of lines which constitutes the document
|
154
|
+
# content.
|
154
155
|
#
|
155
156
|
# @return [Array<String|void>]
|
156
157
|
def lines
|
@@ -163,7 +164,7 @@ module Vedeu
|
|
163
164
|
def render
|
164
165
|
clear
|
165
166
|
|
166
|
-
Vedeu::Direct.write(value: output, x: bx, y: by)
|
167
|
+
Vedeu::Output::Direct.write(value: output, x: bx, y: by)
|
167
168
|
end
|
168
169
|
|
169
170
|
# Reset the document to the empty state.
|
@@ -177,8 +178,8 @@ module Vedeu
|
|
177
178
|
refresh
|
178
179
|
end
|
179
180
|
|
180
|
-
# Store the document in the documents repository, clear and
|
181
|
-
# view.
|
181
|
+
# Store the document in the documents repository, clear and
|
182
|
+
# render the view.
|
182
183
|
#
|
183
184
|
# @return [Vedeu::Editor::Document]
|
184
185
|
def refresh
|
@@ -209,15 +210,16 @@ module Vedeu
|
|
209
210
|
|
210
211
|
private
|
211
212
|
|
212
|
-
# Retrieve the dimensions of the document from the interface of
|
213
|
-
# name.
|
213
|
+
# Retrieve the dimensions of the document from the interface of
|
214
|
+
# the same name.
|
214
215
|
#
|
215
216
|
# @return [Vedeu::Borders::Border]
|
216
217
|
def border
|
217
218
|
@border ||= Vedeu.borders.by_name(name)
|
218
219
|
end
|
219
220
|
|
220
|
-
# Return the data needed to clear the area which the document is
|
221
|
+
# Return the data needed to clear the area which the document is
|
222
|
+
# using.
|
221
223
|
#
|
222
224
|
# @return [String]
|
223
225
|
def clear_output
|
@@ -258,8 +260,8 @@ module Vedeu
|
|
258
260
|
output
|
259
261
|
end
|
260
262
|
|
261
|
-
# Return a virtual cursor to track the cursor position within
|
262
|
-
# document.
|
263
|
+
# Return a virtual cursor to track the cursor position within
|
264
|
+
# the document.
|
263
265
|
#
|
264
266
|
# @return [Vedeu::Editor::Cursor]
|
265
267
|
def cursor
|
@@ -271,8 +273,8 @@ module Vedeu
|
|
271
273
|
bxn: bxn)
|
272
274
|
end
|
273
275
|
|
274
|
-
# Return only the visible lines for the document based on the
|
275
|
-
# virtual cursor position.
|
276
|
+
# Return only the visible lines for the document based on the
|
277
|
+
# current virtual cursor position.
|
276
278
|
#
|
277
279
|
# @return [Vedeu::Editor::Lines]
|
278
280
|
def visible
|
data/lib/vedeu/editor/editor.rb
CHANGED
data/lib/vedeu/editor/line.rb
CHANGED
@@ -35,7 +35,8 @@ module Vedeu
|
|
35
35
|
@line = line || ''
|
36
36
|
end
|
37
37
|
|
38
|
-
# Return a character or collection of characters (if index is a
|
38
|
+
# Return a character or collection of characters (if index is a
|
39
|
+
# Range).
|
39
40
|
#
|
40
41
|
# @param index [Fixnum|Range]
|
41
42
|
# @return [String]
|
@@ -43,7 +44,8 @@ module Vedeu
|
|
43
44
|
line[index]
|
44
45
|
end
|
45
46
|
|
46
|
-
# Return the character from the line positioned at the given
|
47
|
+
# Return the character from the line positioned at the given
|
48
|
+
# index.
|
47
49
|
#
|
48
50
|
# @param index [Fixnum|NilClass]
|
49
51
|
# @return [String|NilClass]
|
@@ -63,7 +65,8 @@ module Vedeu
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
|
-
# Delete the character from the line positioned at the given
|
68
|
+
# Delete the character from the line positioned at the given
|
69
|
+
# index.
|
67
70
|
#
|
68
71
|
# @param index [Fixnum|NilClass]
|
69
72
|
# @return [String]
|
@@ -81,7 +84,8 @@ module Vedeu
|
|
81
84
|
Vedeu::Editor::Line.coerce(new_line)
|
82
85
|
end
|
83
86
|
|
84
|
-
# Returns a boolean indicating whether there are characters on
|
87
|
+
# Returns a boolean indicating whether there are characters on
|
88
|
+
# this line.
|
85
89
|
#
|
86
90
|
# @return [Boolean]
|
87
91
|
def empty?
|
@@ -97,7 +101,8 @@ module Vedeu
|
|
97
101
|
end
|
98
102
|
alias_method :==, :eql?
|
99
103
|
|
100
|
-
# Insert the character on the line positioned at the given
|
104
|
+
# Insert the character on the line positioned at the given
|
105
|
+
# index.
|
101
106
|
#
|
102
107
|
# @param character [String]
|
103
108
|
# @param index [Fixnum|NilClass]
|
data/lib/vedeu/editor/lines.rb
CHANGED
@@ -65,8 +65,8 @@ module Vedeu
|
|
65
65
|
lines[index]
|
66
66
|
end
|
67
67
|
|
68
|
-
# Deletes the character from the line where the cursor is
|
69
|
-
# positioned.
|
68
|
+
# Deletes the character from the line where the cursor is
|
69
|
+
# currently positioned.
|
70
70
|
#
|
71
71
|
# @param y [Fixnum]
|
72
72
|
# @param x [Fixnum]
|
data/lib/vedeu/internal_api.rb
CHANGED
@@ -98,8 +98,8 @@ module Vedeu
|
|
98
98
|
# Vedeu.groups
|
99
99
|
#
|
100
100
|
# @!method groups
|
101
|
-
# @return [Vedeu::Groups]
|
102
|
-
def_delegators Vedeu::Groups, :groups
|
101
|
+
# @return [Vedeu::Models::Groups]
|
102
|
+
def_delegators Vedeu::Models::Groups, :groups
|
103
103
|
|
104
104
|
# Manipulate the repository of interfaces.
|
105
105
|
#
|
@@ -107,8 +107,8 @@ module Vedeu
|
|
107
107
|
# Vedeu.interfaces
|
108
108
|
#
|
109
109
|
# @!method interfaces
|
110
|
-
# @return [Vedeu::Interfaces]
|
111
|
-
def_delegators Vedeu::Interfaces, :interfaces
|
110
|
+
# @return [Vedeu::Models::Interfaces]
|
111
|
+
def_delegators Vedeu::Models::Interfaces, :interfaces
|
112
112
|
|
113
113
|
# Manipulate the repository of keymaps.
|
114
114
|
#
|
data/lib/vedeu/models/focus.rb
CHANGED
@@ -1,228 +1,234 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
3
|
+
module Models
|
4
|
+
|
5
|
+
# The Focus repository is simply a collection of interface names,
|
6
|
+
# this module serving to store and manipulate the which interface
|
7
|
+
# is currently being focussed.
|
8
|
+
#
|
9
|
+
# @note
|
10
|
+
# - Interfaces are added to the collection in the order they are defined.
|
11
|
+
# - If the interface definition contains `focus!`,
|
12
|
+
# (see Vedeu::DSL::Interface#focus!) then that interface is prepended to
|
13
|
+
# the list.
|
14
|
+
# - If the `Vedeu.focus_by_name 'some_interface'` declaration is used,
|
15
|
+
# then the list pointer (`current`) is set to the interface of
|
16
|
+
# that name.
|
17
|
+
#
|
18
|
+
module Focus
|
19
|
+
|
20
|
+
extend self
|
21
|
+
|
22
|
+
# Add an interface name to the focus list unless it is already registered.
|
23
|
+
#
|
24
|
+
# @param name [String] The name of the interface.
|
25
|
+
# @param focus [Boolean] When true, prepends the interface name to the
|
26
|
+
# collection, making that interface the currently focussed interface.
|
27
|
+
# @return [Array] The collection of interface names.
|
28
|
+
def add(name, focus = false)
|
29
|
+
if registered?(name)
|
30
|
+
return storage unless focus
|
31
|
+
|
32
|
+
by_name(name)
|
33
|
+
storage
|
31
34
|
|
32
|
-
|
33
|
-
|
35
|
+
else
|
36
|
+
Vedeu.log(type: :store, message: "Storing focus entry: '#{name}'")
|
34
37
|
|
35
|
-
|
36
|
-
|
38
|
+
if focus
|
39
|
+
storage.unshift(name)
|
37
40
|
|
38
|
-
|
39
|
-
|
41
|
+
else
|
42
|
+
storage.push(name)
|
40
43
|
|
44
|
+
end
|
41
45
|
end
|
42
46
|
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# Focus an interface by name. Used after defining an interface or interfaces
|
46
|
-
# to set the initially focussed interface.
|
47
|
-
#
|
48
|
-
# @example
|
49
|
-
# Vedeu.trigger(:_focus_by_name_, name)
|
50
|
-
# Vedeu.focus_by_name('name')
|
51
|
-
#
|
52
|
-
# @param name [String] The interface to focus; must be defined.
|
53
|
-
# @raise [Vedeu::Error::ModelNotFound] When the interface cannot be found.
|
54
|
-
# @return [String] The name of the interface now in focus.
|
55
|
-
def by_name(name)
|
56
|
-
unless registered?(name)
|
57
|
-
fail Vedeu::Error::ModelNotFound,
|
58
|
-
"Cannot focus '#{name}' as this interface has not been registered."
|
59
|
-
end
|
60
|
-
|
61
|
-
storage.rotate!(storage.index(name))
|
62
|
-
|
63
|
-
update
|
64
|
-
end
|
65
|
-
alias_method :focus_by_name, :by_name
|
66
|
-
|
67
|
-
# Return the interface currently focussed.
|
68
|
-
#
|
69
|
-
# @example
|
70
|
-
# Vedeu.focus
|
71
|
-
#
|
72
|
-
# @return [String]
|
73
|
-
def current
|
74
|
-
storage[0]
|
75
|
-
end
|
76
|
-
alias_method :focus, :current
|
77
47
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
storage.empty?
|
95
|
-
end
|
96
|
-
|
97
|
-
# Put the next interface relative to the current interfaces in focus.
|
98
|
-
#
|
99
|
-
# @example
|
100
|
-
# Vedeu.trigger(:_focus_next_)
|
101
|
-
# Vedeu.focus_next
|
102
|
-
#
|
103
|
-
# @return [String]
|
104
|
-
def next_item
|
105
|
-
storage.rotate!
|
48
|
+
# Focus an interface by name. Used after defining an interface
|
49
|
+
# or interfaces to set the initially focussed interface.
|
50
|
+
#
|
51
|
+
# @example
|
52
|
+
# Vedeu.trigger(:_focus_by_name_, name)
|
53
|
+
# Vedeu.focus_by_name('name')
|
54
|
+
#
|
55
|
+
# @param name [String] The interface to focus; must be defined.
|
56
|
+
# @raise [Vedeu::Error::ModelNotFound] When the interface cannot be found.
|
57
|
+
# @return [String] The name of the interface now in focus.
|
58
|
+
def by_name(name)
|
59
|
+
unless registered?(name)
|
60
|
+
fail Vedeu::Error::ModelNotFound,
|
61
|
+
"Cannot focus '#{name}' as this interface has not been " \
|
62
|
+
'registered.'
|
63
|
+
end
|
106
64
|
|
107
|
-
|
108
|
-
end
|
109
|
-
alias_method :next, :next_item
|
65
|
+
storage.rotate!(storage.index(name))
|
110
66
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
67
|
+
update
|
68
|
+
end
|
69
|
+
alias_method :focus_by_name, :by_name
|
70
|
+
|
71
|
+
# Return the interface currently focussed.
|
72
|
+
#
|
73
|
+
# @example
|
74
|
+
# Vedeu.focus
|
75
|
+
#
|
76
|
+
# @return [String]
|
77
|
+
def current
|
78
|
+
storage[0]
|
79
|
+
end
|
80
|
+
alias_method :focus, :current
|
81
|
+
|
82
|
+
# Returns a boolean indicating whether the named interface is focussed.
|
83
|
+
#
|
84
|
+
# @example
|
85
|
+
# Vedeu.focussed?(name)
|
86
|
+
#
|
87
|
+
# @param name [String]
|
88
|
+
# @return [Boolean]
|
89
|
+
def current?(name)
|
90
|
+
current == name
|
91
|
+
end
|
92
|
+
alias_method :focussed?, :current?
|
117
93
|
|
118
|
-
|
119
|
-
|
120
|
-
|
94
|
+
# Return a boolean indicating whether the storage is empty.
|
95
|
+
#
|
96
|
+
# @return [Boolean]
|
97
|
+
def empty?
|
98
|
+
storage.empty?
|
121
99
|
end
|
122
100
|
|
123
|
-
|
124
|
-
|
125
|
-
|
101
|
+
# Put the next interface relative to the current interfaces in focus.
|
102
|
+
#
|
103
|
+
# @example
|
104
|
+
# Vedeu.trigger(:_focus_next_)
|
105
|
+
# Vedeu.focus_next
|
106
|
+
#
|
107
|
+
# @return [String]
|
108
|
+
def next_item
|
109
|
+
storage.rotate!
|
126
110
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
111
|
+
update
|
112
|
+
end
|
113
|
+
alias_method :next, :next_item
|
114
|
+
|
115
|
+
# Put the next visible interface relative to the current interfaces in
|
116
|
+
# focus.
|
117
|
+
#
|
118
|
+
# @return [String]
|
119
|
+
def next_visible_item
|
120
|
+
return update unless visible_items?
|
121
|
+
|
122
|
+
loop do
|
123
|
+
storage.rotate!
|
124
|
+
break if Vedeu.interfaces.by_name(current).visible?
|
125
|
+
end
|
136
126
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
127
|
+
update
|
128
|
+
end
|
129
|
+
alias_method :focus_next, :next_visible_item
|
130
|
+
|
131
|
+
# Put the previous interface relative to the current interface in focus.
|
132
|
+
#
|
133
|
+
# @example
|
134
|
+
# Vedeu.trigger(:_focus_prev_)
|
135
|
+
# Vedeu.focus_previous
|
136
|
+
#
|
137
|
+
# @return [String]
|
138
|
+
def prev_item
|
139
|
+
storage.rotate!(-1)
|
141
140
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
141
|
+
update
|
142
|
+
end
|
143
|
+
alias_method :prev, :prev_item
|
144
|
+
alias_method :previous, :prev_item
|
145
|
+
|
146
|
+
# Put the previous visible interface relative to the current interfaces in
|
147
|
+
# focus.
|
148
|
+
#
|
149
|
+
# @return [String]
|
150
|
+
def prev_visible_item
|
151
|
+
return update unless visible_items?
|
152
|
+
|
153
|
+
loop do
|
154
|
+
storage.rotate!(-1)
|
155
|
+
break if Vedeu.interfaces.by_name(current).visible?
|
156
|
+
end
|
148
157
|
|
149
|
-
|
150
|
-
storage.rotate!(-1)
|
151
|
-
break if Vedeu.interfaces.by_name(current).visible?
|
158
|
+
update
|
152
159
|
end
|
160
|
+
alias_method :focus_previous, :prev_visible_item
|
153
161
|
|
154
|
-
|
155
|
-
|
156
|
-
|
162
|
+
# Refresh the interface in focus.
|
163
|
+
#
|
164
|
+
# @return [Array]
|
165
|
+
def refresh
|
166
|
+
Vedeu.trigger(:_refresh_, current)
|
167
|
+
end
|
157
168
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
end
|
169
|
+
# Returns a collection of the names of all the registered entities.
|
170
|
+
#
|
171
|
+
# @return [Array]
|
172
|
+
def registered
|
173
|
+
return [] if empty?
|
164
174
|
|
165
|
-
|
166
|
-
|
167
|
-
# @return [Array]
|
168
|
-
def registered
|
169
|
-
return [] if empty?
|
175
|
+
storage
|
176
|
+
end
|
170
177
|
|
171
|
-
|
172
|
-
|
178
|
+
# Returns a boolean indicating whether the named model is registered.
|
179
|
+
#
|
180
|
+
# @param name [String]
|
181
|
+
# @return [Boolean]
|
182
|
+
def registered?(name)
|
183
|
+
return false if empty?
|
173
184
|
|
174
|
-
|
175
|
-
|
176
|
-
# @param name [String]
|
177
|
-
# @return [Boolean]
|
178
|
-
def registered?(name)
|
179
|
-
return false if empty?
|
185
|
+
storage.include?(name)
|
186
|
+
end
|
180
187
|
|
181
|
-
|
182
|
-
|
188
|
+
# Reset the repository.
|
189
|
+
#
|
190
|
+
# @return [Array|Hash|Set]
|
191
|
+
def reset
|
192
|
+
@storage = in_memory
|
193
|
+
end
|
183
194
|
|
184
|
-
|
185
|
-
#
|
186
|
-
# @return [Array|Hash|Set]
|
187
|
-
def reset
|
188
|
-
@storage = in_memory
|
189
|
-
end
|
195
|
+
private
|
190
196
|
|
191
|
-
|
197
|
+
# Return the name of the interface in focus after triggering the refresh
|
198
|
+
# event for that interface. Returns false when the storage is empty.
|
199
|
+
#
|
200
|
+
# @return [String|FalseClass]
|
201
|
+
def update
|
202
|
+
return false if empty?
|
192
203
|
|
193
|
-
|
194
|
-
# event for that interface. Returns false when the storage is empty.
|
195
|
-
#
|
196
|
-
# @return [String|FalseClass]
|
197
|
-
def update
|
198
|
-
return false if empty?
|
204
|
+
Vedeu.log(type: :info, message: "Interface in focus: '#{current}'")
|
199
205
|
|
200
|
-
|
206
|
+
refresh
|
201
207
|
|
202
|
-
|
208
|
+
current
|
209
|
+
end
|
203
210
|
|
204
|
-
|
205
|
-
|
211
|
+
# Access to the storage for this repository.
|
212
|
+
#
|
213
|
+
# @return [Array]
|
214
|
+
def storage
|
215
|
+
@storage ||= in_memory
|
216
|
+
end
|
206
217
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
218
|
+
# Returns an empty collection ready for the storing of interface names.
|
219
|
+
#
|
220
|
+
# @return [Array]
|
221
|
+
def in_memory
|
222
|
+
[]
|
223
|
+
end
|
213
224
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
[]
|
219
|
-
end
|
225
|
+
# @return [Boolean]
|
226
|
+
def visible_items?
|
227
|
+
storage.any? { |name| Vedeu.interfaces.by_name(name).visible? }
|
228
|
+
end
|
220
229
|
|
221
|
-
#
|
222
|
-
def visible_items?
|
223
|
-
storage.any? { |name| Vedeu.interfaces.by_name(name).visible? }
|
224
|
-
end
|
230
|
+
end # Focus
|
225
231
|
|
226
|
-
end #
|
232
|
+
end # Models
|
227
233
|
|
228
234
|
end # Vedeu
|