vedeu 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +9 -0
  3. data/README.md +1 -1
  4. data/docs/api.md +60 -67
  5. data/docs/configuration.md +8 -5
  6. data/docs/events.md +31 -15
  7. data/docs/events/application.md +12 -0
  8. data/docs/events/document.md +57 -0
  9. data/docs/events/drb.md +43 -0
  10. data/docs/events/focus.md +24 -0
  11. data/docs/events/menu.md +57 -0
  12. data/docs/events/movement.md +57 -0
  13. data/docs/events/refresh.md +25 -0
  14. data/docs/events/system.md +90 -0
  15. data/docs/events/visibility.md +68 -0
  16. data/lib/vedeu.rb +2 -2
  17. data/lib/vedeu/all.rb +3 -2
  18. data/lib/vedeu/api.rb +18 -18
  19. data/lib/vedeu/application/controller.rb +1 -1
  20. data/lib/vedeu/application/helper.rb +1 -1
  21. data/lib/vedeu/application/view.rb +1 -1
  22. data/lib/vedeu/bindings/application.rb +1 -12
  23. data/lib/vedeu/bindings/bindings.rb +3 -1
  24. data/lib/vedeu/bindings/document.rb +9 -62
  25. data/lib/vedeu/bindings/drb.rb +12 -56
  26. data/lib/vedeu/bindings/focus.rb +3 -28
  27. data/lib/vedeu/bindings/menus.rb +10 -66
  28. data/lib/vedeu/bindings/movement.rb +4 -69
  29. data/lib/vedeu/bindings/refresh.rb +3 -33
  30. data/lib/vedeu/bindings/system.rb +14 -100
  31. data/lib/vedeu/bindings/visibility.rb +20 -71
  32. data/lib/vedeu/borders/all.rb +4 -3
  33. data/lib/vedeu/borders/border.rb +39 -33
  34. data/lib/vedeu/borders/dsl.rb +40 -33
  35. data/lib/vedeu/borders/null.rb +2 -2
  36. data/lib/vedeu/borders/render.rb +29 -24
  37. data/lib/vedeu/borders/repository.rb +2 -2
  38. data/lib/vedeu/buffers/all.rb +8 -7
  39. data/lib/vedeu/buffers/buffer.rb +47 -39
  40. data/lib/vedeu/buffers/null.rb +2 -2
  41. data/lib/vedeu/buffers/refresh.rb +4 -3
  42. data/lib/vedeu/buffers/virtual_buffer.rb +122 -118
  43. data/lib/vedeu/buffers/virtual_buffers.rb +62 -56
  44. data/lib/vedeu/colours/background.rb +2 -1
  45. data/lib/vedeu/colours/colour.rb +21 -19
  46. data/lib/vedeu/colours/foreground.rb +2 -1
  47. data/lib/vedeu/colours/repository.rb +6 -5
  48. data/lib/vedeu/colours/translator.rb +39 -35
  49. data/lib/vedeu/configuration/api.rb +59 -51
  50. data/lib/vedeu/configuration/cli.rb +9 -7
  51. data/lib/vedeu/configuration/configuration.rb +41 -32
  52. data/lib/vedeu/cursors/cursor.rb +1 -1
  53. data/lib/vedeu/cursors/refresh.rb +20 -16
  54. data/lib/vedeu/distributed/server.rb +8 -6
  55. data/lib/vedeu/distributed/subprocess.rb +90 -86
  56. data/lib/vedeu/distributed/uri.rb +4 -3
  57. data/lib/vedeu/dsl/composition.rb +2 -2
  58. data/lib/vedeu/dsl/group.rb +4 -4
  59. data/lib/vedeu/dsl/interface.rb +5 -5
  60. data/lib/vedeu/dsl/presentation.rb +2 -2
  61. data/lib/vedeu/dsl/text.rb +1 -1
  62. data/lib/vedeu/editor/cropper.rb +4 -4
  63. data/lib/vedeu/editor/cursor.rb +6 -4
  64. data/lib/vedeu/editor/document.rb +20 -18
  65. data/lib/vedeu/editor/editor.rb +2 -2
  66. data/lib/vedeu/editor/line.rb +10 -5
  67. data/lib/vedeu/editor/lines.rb +2 -2
  68. data/lib/vedeu/internal_api.rb +4 -4
  69. data/lib/vedeu/models/focus.rb +197 -191
  70. data/lib/vedeu/models/group.rb +171 -159
  71. data/lib/vedeu/models/groups.rb +14 -10
  72. data/lib/vedeu/models/interface.rb +116 -110
  73. data/lib/vedeu/models/interfaces.rb +24 -20
  74. data/lib/vedeu/models/toggleable.rb +4 -4
  75. data/lib/vedeu/models/views/char.rb +1 -1
  76. data/lib/vedeu/models/views/composition.rb +1 -1
  77. data/lib/vedeu/models/views/line.rb +1 -1
  78. data/lib/vedeu/models/views/stream.rb +1 -1
  79. data/lib/vedeu/models/views/view.rb +1 -1
  80. data/lib/vedeu/null/interface.rb +1 -1
  81. data/lib/vedeu/null/view.rb +1 -1
  82. data/lib/vedeu/output/clear/named_interface.rb +1 -1
  83. data/lib/vedeu/output/compressor.rb +78 -73
  84. data/lib/vedeu/output/direct.rb +61 -57
  85. data/lib/vedeu/output/output.rb +34 -29
  86. data/lib/vedeu/output/{presentation.rb → presentation/presentation.rb} +2 -1
  87. data/lib/vedeu/output/presentation/style.rb +64 -18
  88. data/lib/vedeu/output/presentation/styles.rb +39 -0
  89. data/lib/vedeu/output/renderers/html.rb +2 -2
  90. data/lib/vedeu/output/renderers/json.rb +2 -1
  91. data/lib/vedeu/output/renderers/terminal.rb +3 -3
  92. data/lib/vedeu/output/renderers/text.rb +3 -3
  93. data/lib/vedeu/output/text.rb +186 -180
  94. data/lib/vedeu/output/wordwrap.rb +142 -138
  95. data/lib/vedeu/refresh/refresh.rb +2 -2
  96. data/lib/vedeu/templating/helpers.rb +11 -6
  97. data/lib/vedeu/templating/view_template.rb +1 -1
  98. data/lib/vedeu/terminal/terminal.rb +2 -2
  99. data/lib/vedeu/version.rb +1 -1
  100. data/test/lib/vedeu/borders/render_test.rb +1 -1
  101. data/test/lib/vedeu/buffers/buffer_test.rb +16 -14
  102. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +105 -101
  103. data/test/lib/vedeu/buffers/virtual_buffers_test.rb +43 -39
  104. data/test/lib/vedeu/colours/colour_test.rb +4 -4
  105. data/test/lib/vedeu/cursors/cursor_test.rb +2 -2
  106. data/test/lib/vedeu/cursors/repository_test.rb +3 -3
  107. data/test/lib/vedeu/distributed/subprocess_test.rb +33 -29
  108. data/test/lib/vedeu/dsl/group_test.rb +3 -3
  109. data/test/lib/vedeu/dsl/interface_test.rb +6 -5
  110. data/test/lib/vedeu/dsl/line_test.rb +4 -2
  111. data/test/lib/vedeu/dsl/presentation_test.rb +2 -2
  112. data/test/lib/vedeu/dsl/text_test.rb +8 -8
  113. data/test/lib/vedeu/editor/document_test.rb +10 -6
  114. data/test/lib/vedeu/input/keymap_test.rb +1 -10
  115. data/test/lib/vedeu/models/focus_test.rb +177 -170
  116. data/test/lib/vedeu/models/group_test.rb +99 -95
  117. data/test/lib/vedeu/models/groups_test.rb +13 -9
  118. data/test/lib/vedeu/models/interface_test.rb +93 -87
  119. data/test/lib/vedeu/models/interfaces_test.rb +24 -20
  120. data/test/lib/vedeu/models/views/char_test.rb +2 -2
  121. data/test/lib/vedeu/models/views/line_test.rb +11 -7
  122. data/test/lib/vedeu/models/views/stream_test.rb +1 -1
  123. data/test/lib/vedeu/models/views/view_test.rb +1 -1
  124. data/test/lib/vedeu/output/clear/named_group_test.rb +1 -1
  125. data/test/lib/vedeu/output/clear/named_interface_test.rb +3 -1
  126. data/test/lib/vedeu/output/compressor_test.rb +126 -122
  127. data/test/lib/vedeu/output/direct_test.rb +49 -43
  128. data/test/lib/vedeu/output/output_test.rb +35 -31
  129. data/test/lib/vedeu/output/{presentation_test.rb → presentation/presentation_test.rb} +11 -7
  130. data/test/lib/vedeu/output/presentation/style_test.rb +88 -48
  131. data/test/lib/vedeu/output/presentation/styles_test.rb +84 -0
  132. data/test/lib/vedeu/output/text_test.rb +109 -105
  133. data/test/lib/vedeu/output/viewport_test.rb +3 -1
  134. data/test/lib/vedeu/output/wordwrap_test.rb +209 -205
  135. data/test/lib/vedeu/refresh/refresh_test.rb +3 -1
  136. data/test/lib/vedeu/templating/helpers_test.rb +6 -6
  137. data/test/lib/vedeu/templating/view_template_test.rb +1 -1
  138. metadata +17 -8
  139. data/lib/vedeu/output/style.rb +0 -76
  140. 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 DRb.
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 and
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
 
@@ -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
@@ -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
@@ -56,7 +56,7 @@ module Vedeu
56
56
  def text(value = '', options = {})
57
57
  options.merge!(anchor: __callee__, model: model)
58
58
 
59
- Vedeu::Text.add(value, options)
59
+ Vedeu::Output::Text.add(value, options)
60
60
  end
61
61
  alias_method :text=, :text
62
62
  alias_method :align, :text
@@ -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 by the
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 array. If
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
@@ -2,7 +2,8 @@ module Vedeu
2
2
 
3
3
  module Editor
4
4
 
5
- # Maintains a cursor position within the Vedeu::Editor::Document class.
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 line.
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 show the
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 currently
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 more than
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 currently
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 content.
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 render the
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 the same
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 using.
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 the
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 current
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
@@ -2,8 +2,8 @@ module Vedeu
2
2
 
3
3
  module Editor
4
4
 
5
- # Handles keypresses for a named document whilst the terminal is in fake
6
- # mode.
5
+ # Handles keypresses for a named document whilst the terminal is
6
+ # in fake mode.
7
7
  #
8
8
  class Editor
9
9
 
@@ -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 Range).
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 index.
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 index.
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 this line.
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 index.
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]
@@ -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 currently
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]
@@ -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
  #
@@ -1,228 +1,234 @@
1
1
  module Vedeu
2
2
 
3
- # The Focus repository is simply a collection of interface names, this module
4
- # serving to store and manipulate the which interface is currently being
5
- # focussed.
6
- #
7
- # @note
8
- # - Interfaces are added to the collection in the order they are defined.
9
- # - If the interface definition contains `focus!`,
10
- # (see Vedeu::DSL::Interface#focus!) then that interface is prepended to
11
- # the list.
12
- # - If the `Vedeu.focus_by_name 'some_interface'` declaration is used, then
13
- # the list pointer (`current`) is set to the interface of that name.
14
- #
15
- module Focus
16
-
17
- extend self
18
-
19
- # Add an interface name to the focus list unless it is already registered.
20
- #
21
- # @param name [String] The name of the interface.
22
- # @param focus [Boolean] When true, prepends the interface name to the
23
- # collection, making that interface the currently focussed interface.
24
- # @return [Array] The collection of interface names.
25
- def add(name, focus = false)
26
- if registered?(name)
27
- return storage unless focus
28
-
29
- by_name(name)
30
- storage
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
- else
33
- Vedeu.log(type: :store, message: "Storing focus entry: '#{name}'")
35
+ else
36
+ Vedeu.log(type: :store, message: "Storing focus entry: '#{name}'")
34
37
 
35
- if focus
36
- storage.unshift(name)
38
+ if focus
39
+ storage.unshift(name)
37
40
 
38
- else
39
- storage.push(name)
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
- # Returns a boolean indicating whether the named interface is focussed.
79
- #
80
- # @example
81
- # Vedeu.focussed?(name)
82
- #
83
- # @param name [String]
84
- # @return [Boolean]
85
- def current?(name)
86
- current == name
87
- end
88
- alias_method :focussed?, :current?
89
-
90
- # Return a boolean indicating whether the storage is empty.
91
- #
92
- # @return [Boolean]
93
- def empty?
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
- update
108
- end
109
- alias_method :next, :next_item
65
+ storage.rotate!(storage.index(name))
110
66
 
111
- # Put the next visible interface relative to the current interfaces in
112
- # focus.
113
- #
114
- # @return [String]
115
- def next_visible_item
116
- return update unless visible_items?
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
- loop do
119
- storage.rotate!
120
- break if Vedeu.interfaces.by_name(current).visible?
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
- update
124
- end
125
- alias_method :focus_next, :next_visible_item
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
- # Put the previous interface relative to the current interface in focus.
128
- #
129
- # @example
130
- # Vedeu.trigger(:_focus_prev_)
131
- # Vedeu.focus_previous
132
- #
133
- # @return [String]
134
- def prev_item
135
- storage.rotate!(-1)
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
- update
138
- end
139
- alias_method :prev, :prev_item
140
- alias_method :previous, :prev_item
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
- # Put the previous visible interface relative to the current interfaces in
143
- # focus.
144
- #
145
- # @return [String]
146
- def prev_visible_item
147
- return update unless visible_items?
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
- loop do
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
- update
155
- end
156
- alias_method :focus_previous, :prev_visible_item
162
+ # Refresh the interface in focus.
163
+ #
164
+ # @return [Array]
165
+ def refresh
166
+ Vedeu.trigger(:_refresh_, current)
167
+ end
157
168
 
158
- # Refresh the interface in focus.
159
- #
160
- # @return [Array]
161
- def refresh
162
- Vedeu.trigger(:_refresh_, current)
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
- # Returns a collection of the names of all the registered entities.
166
- #
167
- # @return [Array]
168
- def registered
169
- return [] if empty?
175
+ storage
176
+ end
170
177
 
171
- storage
172
- end
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
- # Returns a boolean indicating whether the named model is registered.
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
- storage.include?(name)
182
- end
188
+ # Reset the repository.
189
+ #
190
+ # @return [Array|Hash|Set]
191
+ def reset
192
+ @storage = in_memory
193
+ end
183
194
 
184
- # Reset the repository.
185
- #
186
- # @return [Array|Hash|Set]
187
- def reset
188
- @storage = in_memory
189
- end
195
+ private
190
196
 
191
- private
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
- # Return the name of the interface in focus after triggering the refresh
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
- Vedeu.log(type: :info, message: "Interface in focus: '#{current}'")
206
+ refresh
201
207
 
202
- refresh
208
+ current
209
+ end
203
210
 
204
- current
205
- end
211
+ # Access to the storage for this repository.
212
+ #
213
+ # @return [Array]
214
+ def storage
215
+ @storage ||= in_memory
216
+ end
206
217
 
207
- # Access to the storage for this repository.
208
- #
209
- # @return [Array]
210
- def storage
211
- @storage ||= in_memory
212
- end
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
- # Returns an empty collection ready for the storing of interface names.
215
- #
216
- # @return [Array]
217
- def in_memory
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
- # @return [Boolean]
222
- def visible_items?
223
- storage.any? { |name| Vedeu.interfaces.by_name(name).visible? }
224
- end
230
+ end # Focus
225
231
 
226
- end # Focus
232
+ end # Models
227
233
 
228
234
  end # Vedeu