vedeu 0.4.13 → 0.4.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -1
  3. data/.travis.yml +2 -1
  4. data/Guardfile +6 -5
  5. data/README.md +3 -30
  6. data/Rakefile +5 -5
  7. data/bin/vedeu_drb_client +1 -1
  8. data/bin/vedeu_drb_server +91 -89
  9. data/bin/vedeu_test +4 -0
  10. data/config/rubocop_enabled.yml +5 -10
  11. data/examples/borders_app.rb +2 -1
  12. data/examples/colours_app.rb +13 -8
  13. data/examples/configuration_app.rb +3 -2
  14. data/examples/cursor_app.rb +16 -11
  15. data/examples/drb_app.rb +88 -89
  16. data/examples/focus_app.rb +31 -32
  17. data/examples/geometry_app.rb +2 -1
  18. data/examples/hello_world.rb +2 -1
  19. data/examples/lines_app.rb +2 -1
  20. data/examples/material_colours_app.rb +126 -0
  21. data/examples/typed_commands/typed_commands_app.rb +5 -1
  22. data/examples/view_templates_app/view_templates_app.rb +6 -3
  23. data/lib/vedeu/all.rb +1 -1
  24. data/lib/vedeu/api.rb +18 -10
  25. data/lib/vedeu/application.rb +0 -1
  26. data/lib/vedeu/bindings.rb +77 -16
  27. data/lib/vedeu/buffers/all.rb +2 -5
  28. data/lib/vedeu/buffers/buffer.rb +69 -25
  29. data/lib/vedeu/buffers/display_buffer.rb +3 -7
  30. data/lib/vedeu/configuration/all.rb +3 -6
  31. data/lib/vedeu/configuration/api.rb +28 -4
  32. data/lib/vedeu/configuration/cli.rb +9 -9
  33. data/lib/vedeu/configuration/configuration.rb +11 -7
  34. data/lib/vedeu/cursor/all.rb +3 -6
  35. data/lib/vedeu/cursor/cursor.rb +22 -14
  36. data/lib/vedeu/cursor/move.rb +32 -22
  37. data/lib/vedeu/cursor/refresh_cursor.rb +1 -1
  38. data/lib/vedeu/debug.rb +2 -1
  39. data/lib/vedeu/distributed/client.rb +1 -7
  40. data/lib/vedeu/distributed/server.rb +0 -4
  41. data/lib/vedeu/distributed/subprocess.rb +1 -1
  42. data/lib/vedeu/distributed/templates/default_configuration.vedeu +1 -1
  43. data/lib/vedeu/distributed/test_application.rb +3 -5
  44. data/lib/vedeu/distributed/uri.rb +2 -2
  45. data/lib/vedeu/dsl/all.rb +6 -6
  46. data/lib/vedeu/dsl/components/all.rb +0 -3
  47. data/lib/vedeu/dsl/components/border.rb +20 -12
  48. data/lib/vedeu/dsl/components/geometry.rb +68 -3
  49. data/lib/vedeu/dsl/components/keymap.rb +1 -2
  50. data/lib/vedeu/dsl/composition.rb +8 -1
  51. data/lib/vedeu/dsl/interface.rb +61 -11
  52. data/lib/vedeu/dsl/line.rb +12 -12
  53. data/lib/vedeu/dsl/shared/all.rb +4 -7
  54. data/lib/vedeu/dsl/shared/colour.rb +2 -2
  55. data/lib/vedeu/dsl/shared/text.rb +2 -35
  56. data/lib/vedeu/dsl/shared/use.rb +2 -2
  57. data/lib/vedeu/dsl/view.rb +4 -4
  58. data/lib/vedeu/events/all.rb +3 -5
  59. data/lib/vedeu/events/event.rb +5 -5
  60. data/lib/vedeu/geometry/all.rb +11 -16
  61. data/lib/vedeu/geometry/area.rb +2 -5
  62. data/lib/vedeu/geometry/canvas.rb +12 -16
  63. data/lib/vedeu/geometry/dimension.rb +20 -22
  64. data/lib/vedeu/geometry/geometry.rb +28 -30
  65. data/lib/vedeu/geometry/grid.rb +1 -1
  66. data/lib/vedeu/geometry/index_position.rb +7 -0
  67. data/lib/vedeu/geometry/null_geometry.rb +61 -0
  68. data/lib/vedeu/geometry/position.rb +0 -3
  69. data/lib/vedeu/geometry/position_index.rb +7 -0
  70. data/lib/vedeu/geometry/position_validator.rb +44 -33
  71. data/lib/vedeu/input/all.rb +5 -4
  72. data/lib/vedeu/input/keymap.rb +0 -1
  73. data/lib/vedeu/input/mapper.rb +1 -3
  74. data/lib/vedeu/launcher.rb +6 -7
  75. data/lib/vedeu/main_loop.rb +1 -2
  76. data/lib/vedeu/models/all.rb +1 -0
  77. data/lib/vedeu/models/cell.rb +5 -8
  78. data/lib/vedeu/models/char.rb +50 -15
  79. data/lib/vedeu/models/composition.rb +8 -1
  80. data/lib/vedeu/models/focus.rb +4 -4
  81. data/lib/vedeu/models/group.rb +3 -3
  82. data/lib/vedeu/models/interface.rb +62 -46
  83. data/lib/vedeu/models/line.rb +1 -1
  84. data/lib/vedeu/models/null.rb +48 -0
  85. data/lib/vedeu/models/stream.rb +5 -5
  86. data/lib/vedeu/output/all.rb +20 -30
  87. data/lib/vedeu/output/border.rb +93 -40
  88. data/lib/vedeu/output/clear.rb +100 -15
  89. data/lib/vedeu/output/colour.rb +56 -12
  90. data/lib/vedeu/output/compressor.rb +59 -0
  91. data/lib/vedeu/output/html_char.rb +4 -2
  92. data/lib/vedeu/output/null_border.rb +16 -4
  93. data/lib/vedeu/output/output.rb +13 -21
  94. data/lib/vedeu/output/presentation.rb +28 -23
  95. data/lib/vedeu/output/refresh.rb +2 -2
  96. data/lib/vedeu/output/renderers/all.rb +80 -3
  97. data/lib/vedeu/output/renderers/file_renderer.rb +38 -2
  98. data/lib/vedeu/output/renderers/html_renderer.rb +6 -4
  99. data/lib/vedeu/output/renderers/json_renderer.rb +52 -0
  100. data/lib/vedeu/output/renderers/null_renderer.rb +14 -0
  101. data/lib/vedeu/output/renderers/terminal_renderer.rb +2 -12
  102. data/lib/vedeu/output/style.rb +33 -3
  103. data/lib/vedeu/output/text.rb +98 -1
  104. data/lib/vedeu/output/translator.rb +30 -7
  105. data/lib/vedeu/output/viewport.rb +43 -79
  106. data/lib/vedeu/output/wordwrap.rb +4 -4
  107. data/lib/vedeu/repositories/all.rb +22 -179
  108. data/lib/vedeu/repositories/collection.rb +11 -13
  109. data/lib/vedeu/repositories/collections/all.rb +8 -0
  110. data/lib/vedeu/repositories/collections/chars.rb +9 -0
  111. data/lib/vedeu/repositories/collections/events.rb +9 -0
  112. data/lib/vedeu/repositories/collections/interfaces.rb +9 -0
  113. data/lib/vedeu/repositories/collections/keys.rb +9 -0
  114. data/lib/vedeu/repositories/collections/lines.rb +9 -0
  115. data/lib/vedeu/repositories/collections/streams.rb +9 -0
  116. data/lib/vedeu/repositories/model.rb +7 -2
  117. data/lib/vedeu/repositories/repositories/all.rb +14 -0
  118. data/lib/vedeu/repositories/repositories/background_colours.rb +14 -0
  119. data/lib/vedeu/repositories/repositories/borders.rb +38 -0
  120. data/lib/vedeu/repositories/repositories/buffers.rb +36 -0
  121. data/lib/vedeu/repositories/repositories/colours.rb +63 -0
  122. data/lib/vedeu/repositories/repositories/cursors.rb +29 -0
  123. data/lib/vedeu/repositories/repositories/events_repository.rb +24 -0
  124. data/lib/vedeu/repositories/repositories/foreground_colours.rb +14 -0
  125. data/lib/vedeu/repositories/repositories/geometries.rb +37 -0
  126. data/lib/vedeu/repositories/repositories/groups.rb +24 -0
  127. data/lib/vedeu/repositories/repositories/interfaces_repository.rb +24 -0
  128. data/lib/vedeu/repositories/repositories/keymaps.rb +24 -0
  129. data/lib/vedeu/repositories/repositories/menus.rb +24 -0
  130. data/lib/vedeu/repositories/repository.rb +29 -47
  131. data/lib/vedeu/storage/all.rb +6 -0
  132. data/lib/vedeu/storage/associative_store.rb +47 -0
  133. data/lib/vedeu/storage/conveyor_store.rb +69 -0
  134. data/lib/vedeu/storage/fifo_store.rb +37 -0
  135. data/lib/vedeu/storage/store.rb +58 -0
  136. data/lib/vedeu/support/all.rb +5 -10
  137. data/lib/vedeu/support/common.rb +0 -8
  138. data/lib/vedeu/support/log.rb +13 -24
  139. data/lib/vedeu/support/template.rb +4 -1
  140. data/lib/vedeu/support/terminal.rb +10 -10
  141. data/lib/vedeu/support/trace.rb +15 -88
  142. data/lib/vedeu/support/visibility.rb +73 -0
  143. data/lib/vedeu.rb +37 -0
  144. data/test/lib/vedeu/api_test.rb +7 -3
  145. data/test/lib/vedeu/application_test.rb +9 -3
  146. data/test/lib/vedeu/bindings_test.rb +21 -0
  147. data/test/lib/vedeu/buffers/buffer_test.rb +110 -134
  148. data/test/lib/vedeu/buffers/display_buffer_test.rb +8 -0
  149. data/test/lib/vedeu/configuration/api_test.rb +5 -1
  150. data/test/lib/vedeu/configuration/configuration_test.rb +4 -6
  151. data/test/lib/vedeu/cursor/cursor_test.rb +25 -17
  152. data/test/lib/vedeu/cursor/move_test.rb +7 -7
  153. data/test/lib/vedeu/distributed/client_test.rb +1 -1
  154. data/test/lib/vedeu/distributed/subprocess_test.rb +3 -1
  155. data/test/lib/vedeu/distributed/uri_test.rb +5 -5
  156. data/test/lib/vedeu/dsl/components/geometry_test.rb +43 -0
  157. data/test/lib/vedeu/dsl/components/keymap_test.rb +1 -1
  158. data/test/lib/vedeu/dsl/composition_test.rb +6 -5
  159. data/test/lib/vedeu/dsl/interface_test.rb +81 -16
  160. data/test/lib/vedeu/dsl/shared/colour_test.rb +4 -4
  161. data/test/lib/vedeu/dsl/shared/text_test.rb +87 -9
  162. data/test/lib/vedeu/dsl/stream_test.rb +1 -1
  163. data/test/lib/vedeu/events/event_test.rb +3 -1
  164. data/test/lib/vedeu/events/trigger_test.rb +8 -4
  165. data/test/lib/vedeu/geometry/dimension_test.rb +1 -1
  166. data/test/lib/vedeu/geometry/geometry_test.rb +5 -3
  167. data/test/lib/vedeu/geometry/index_position_test.rb +30 -7
  168. data/test/lib/vedeu/geometry/null_geometry_test.rb +57 -0
  169. data/test/lib/vedeu/geometry/position_index_test.rb +14 -0
  170. data/test/lib/vedeu/geometry/position_validator_test.rb +17 -3
  171. data/test/lib/vedeu/input/keymap_test.rb +3 -1
  172. data/test/lib/vedeu/input/mapper_test.rb +8 -4
  173. data/test/lib/vedeu/launcher_test.rb +1 -1
  174. data/test/lib/vedeu/models/cell_test.rb +10 -8
  175. data/test/lib/vedeu/models/char_test.rb +52 -28
  176. data/test/lib/vedeu/models/composition_test.rb +26 -4
  177. data/test/lib/vedeu/models/group_test.rb +11 -5
  178. data/test/lib/vedeu/models/interface_test.rb +32 -19
  179. data/test/lib/vedeu/models/line_test.rb +21 -25
  180. data/test/lib/vedeu/models/menu_test.rb +10 -6
  181. data/test/lib/vedeu/models/null_test.rb +66 -0
  182. data/test/lib/vedeu/models/stream_test.rb +13 -10
  183. data/test/lib/vedeu/output/border_test.rb +29 -8
  184. data/test/lib/vedeu/output/clear_test.rb +23 -4
  185. data/test/lib/vedeu/output/colour_test.rb +20 -4
  186. data/test/lib/vedeu/output/compressor_test.rb +43 -0
  187. data/test/lib/vedeu/output/html_char_test.rb +29 -17
  188. data/test/lib/vedeu/output/null_border_test.rb +2 -1
  189. data/test/lib/vedeu/output/output_test.rb +20 -30
  190. data/test/lib/vedeu/output/presentation_test.rb +39 -16
  191. data/test/lib/vedeu/output/refresh_test.rb +14 -10
  192. data/test/lib/vedeu/output/renderers/all_test.rb +96 -0
  193. data/test/lib/vedeu/output/renderers/file_renderer_test.rb +1 -1
  194. data/test/lib/vedeu/output/renderers/html_renderer_test.rb +13 -9
  195. data/test/lib/vedeu/output/renderers/json_renderer_test.rb +52 -0
  196. data/test/lib/vedeu/output/renderers/null_renderer_test.rb +19 -0
  197. data/test/lib/vedeu/output/style_test.rb +41 -1
  198. data/test/lib/vedeu/output/text_test.rb +61 -10
  199. data/test/lib/vedeu/output/translator_test.rb +14 -0
  200. data/test/lib/vedeu/output/viewport_test.rb +22 -3
  201. data/test/lib/vedeu/output/virtual_terminal_test.rb +3 -3
  202. data/test/lib/vedeu/output/wordwrap_test.rb +58 -45
  203. data/test/lib/vedeu/repositories/collections/chars_test.rb +16 -0
  204. data/test/lib/vedeu/repositories/collections/events_test.rb +16 -0
  205. data/test/lib/vedeu/repositories/collections/interfaces_test.rb +16 -0
  206. data/test/lib/vedeu/repositories/collections/keys_test.rb +16 -0
  207. data/test/lib/vedeu/repositories/collections/lines_test.rb +16 -0
  208. data/test/lib/vedeu/repositories/collections/streams_test.rb +16 -0
  209. data/test/lib/vedeu/repositories/repositories/background_colours_test.rb +17 -0
  210. data/test/lib/vedeu/repositories/repositories/borders_test.rb +51 -0
  211. data/test/lib/vedeu/repositories/repositories/buffers_test.rb +52 -0
  212. data/test/lib/vedeu/repositories/repositories/colours_test.rb +16 -0
  213. data/test/lib/vedeu/repositories/repositories/cursors_test.rb +39 -0
  214. data/test/lib/vedeu/repositories/repositories/events_repository_test.rb +17 -0
  215. data/test/lib/vedeu/repositories/repositories/foreground_colours_test.rb +17 -0
  216. data/test/lib/vedeu/repositories/repositories/geometries_test.rb +42 -0
  217. data/test/lib/vedeu/repositories/repositories/groups_test.rb +17 -0
  218. data/test/lib/vedeu/repositories/repositories/interfaces_repositories_test.rb +17 -0
  219. data/test/lib/vedeu/repositories/repositories/keymaps_test.rb +17 -0
  220. data/test/lib/vedeu/repositories/repositories/menus_test.rb +17 -0
  221. data/test/lib/vedeu/repositories/repository_test.rb +16 -36
  222. data/test/lib/vedeu/storage/associative_store_test.rb +69 -0
  223. data/test/lib/vedeu/storage/conveyor_store_test.rb +135 -0
  224. data/test/lib/vedeu/storage/fifo_store_test.rb +47 -0
  225. data/test/lib/vedeu/storage/store_test.rb +123 -0
  226. data/test/lib/vedeu/support/common_test.rb +0 -9
  227. data/test/lib/vedeu/support/terminal_test.rb +78 -55
  228. data/test/lib/vedeu/support/visibility_test.rb +80 -0
  229. data/test/test_helper.rb +13 -11
  230. data/vedeu.gemspec +4 -3
  231. metadata +92 -32
  232. data/lib/vedeu/cursor/toggle.rb +0 -55
  233. data/lib/vedeu/exceptions.rb +0 -37
  234. data/lib/vedeu/geometry/centre.rb +0 -85
  235. data/lib/vedeu/geometry/content.rb +0 -70
  236. data/lib/vedeu/geometry/limit.rb +0 -58
  237. data/lib/vedeu/output/compositor.rb +0 -62
  238. data/lib/vedeu/repositories/collections.rb +0 -41
  239. data/lib/vedeu/support/coercions.rb +0 -60
  240. data/lib/vedeu/support/sentence.rb +0 -91
  241. data/lib/vedeu/support/visible.rb +0 -90
  242. data/test/lib/vedeu/cursor/toggle_test.rb +0 -63
  243. data/test/lib/vedeu/geometry/centre_test.rb +0 -58
  244. data/test/lib/vedeu/geometry/content_test.rb +0 -98
  245. data/test/lib/vedeu/geometry/limit_test.rb +0 -30
  246. data/test/lib/vedeu/output/compositor_test.rb +0 -48
  247. data/test/lib/vedeu/repositories/all_test.rb +0 -135
  248. data/test/lib/vedeu/repositories/collections_test.rb +0 -71
  249. data/test/lib/vedeu/support/coercions_test.rb +0 -84
  250. data/test/lib/vedeu/support/sentence_test.rb +0 -56
  251. data/test/lib/vedeu/support/visible_test.rb +0 -161
@@ -11,23 +11,31 @@ module Vedeu
11
11
  extend Forwardable
12
12
 
13
13
  def_delegators :interface,
14
- :geometry,
15
14
  :lines,
16
15
  :lines?,
17
- :cursor
16
+ :name,
17
+ :visible?
18
+
19
+ def_delegators :border,
20
+ :bx,
21
+ :by,
22
+ :height,
23
+ :width
18
24
 
19
25
  def_delegators :cursor,
20
26
  :ox,
21
27
  :oy
22
28
 
23
- def_delegators :geometry,
24
- :height,
25
- :width
26
-
27
29
  # @param interface [Vedeu::Interface]
28
30
  # @return [Array<Array<Vedeu::Char>>]
29
31
  def self.render(interface)
30
- new(interface).render
32
+ if interface.visible?
33
+ new(interface).render
34
+
35
+ else
36
+ []
37
+
38
+ end
31
39
  end
32
40
 
33
41
  # Returns an instance of Vedeu::Viewport.
@@ -43,20 +51,17 @@ module Vedeu
43
51
  #
44
52
  # @return [Array<Array<String>>]
45
53
  def render
46
- Vedeu.log(type: :output, message: "Rendering: '#{interface.name}'")
54
+ return [] unless visible?
47
55
 
48
- out = []
56
+ Vedeu.log(type: :output, message: "Rendering: '#{name}'")
49
57
 
50
- show[0...bordered_height].each_with_index do |line, iy|
51
- line[0...bordered_width].each_with_index do |column, ix|
52
- column.position = IndexPosition[iy,
53
- ix,
54
- interface.border.by,
55
- interface.border.bx]
58
+ out = []
59
+ show[0...height].each_with_index do |line, iy|
60
+ line[0...width].each_with_index do |column, ix|
61
+ column.position = IndexPosition[iy, ix, by, bx]
56
62
  out << column
57
63
  end
58
64
  end
59
-
60
65
  out
61
66
  end
62
67
 
@@ -97,7 +102,7 @@ module Vedeu
97
102
  #
98
103
  # @return [Range]
99
104
  def rows
100
- top..(top + (height - 1))
105
+ top..(top + (geometry.height - 1))
101
106
  end
102
107
 
103
108
  # Using the current cursor's x position, return a range of visible columns.
@@ -110,87 +115,46 @@ module Vedeu
110
115
  #
111
116
  # @return [Range]
112
117
  def columns
113
- left..(left + (width - 1))
118
+ left..(left + (geometry.width - 1))
114
119
  end
115
120
 
116
- # Returns the offset for the content based on the offset.
121
+ # Returns the offset for the content (the number of columns to change the
122
+ # viewport by on the x axis) determined by the offset (the cursor's x
123
+ # offset position).
117
124
  #
118
125
  # @return [Fixnum]
119
126
  def left
120
- @left ||= reposition_x? ? reposition_x : 0
127
+ @left ||= (ox >= width && ((ox - width) > 0)) ? ox - width : 0
121
128
  end
122
129
 
123
- # Returns the offset for the content based on the offset.
130
+ # Returns the offset for the content (the number of rows to change the
131
+ # viewport by on the y axis) determined by the offset (the cursor's y offset
132
+ # position.
124
133
  #
125
134
  # @return [Fixnum]
126
135
  def top
127
- @top ||= reposition_y? ? reposition_y : 0
128
- end
129
-
130
- # Returns a boolean indicating whether the x offset is greater than or equal
131
- # to the bordered width.
132
- #
133
- # @return [Boolean]
134
- def reposition_x?
135
- ox >= bordered_width
136
+ @top ||= (oy >= height && ((oy - height) > 0)) ? oy - height : 0
136
137
  end
137
138
 
138
- # Returns a boolean indicating whether the y offset is greater than or equal
139
- # to the bordered height.
140
- #
141
- # @return [Boolean]
142
- def reposition_y?
143
- oy >= bordered_height
144
- end
145
-
146
- # Returns the number of columns to change the viewport by on the x axis,
147
- # determined by the position of the x offset.
148
- #
149
- # @return [Fixnum]
150
- def reposition_x
151
- ((ox - bordered_width) <= 0) ? 0 : (ox - bordered_width)
152
- end
153
-
154
- # Returns the number of rows to change the viewport by on the y axis,
155
- # determined by the position of the y offset.
156
- #
157
- # @return [Fixnum]
158
- def reposition_y
159
- ((oy - bordered_height) <= 0) ? 0 : (oy - bordered_height)
160
- end
161
-
162
- # When the viewport has a border, we need to account for that in our
163
- # redrawing.
164
- #
165
- # @return [Fixnum]
166
- def bordered_width
167
- return border.width if border?
168
-
169
- width
170
- end
171
-
172
- # When the viewport has a border, we need to account for that in our
173
- # redrawing.
139
+ # Return the border associated with the interface we are drawing.
174
140
  #
175
- # @return [Fixnum]
176
- def bordered_height
177
- return border.height if border?
178
-
179
- height
141
+ # @return [Vedeu::Border|Vedeu::NullBorder]
142
+ def border
143
+ @border ||= Vedeu.borders.by_name(name)
180
144
  end
181
145
 
182
- # Return the border associated with the interface we are drawing.
146
+ # Fetch the cursor associated with the interface we are drawing.
183
147
  #
184
- # @return [Vedeu::Border]
185
- def border
186
- @border ||= Vedeu.borders.find(interface.name)
148
+ # @return [Vedeu::Cursor]
149
+ def cursor
150
+ @cursor ||= Vedeu.cursors.by_name(name)
187
151
  end
188
152
 
189
- # Returns a boolean indicating the interface we are drawing has a border.
153
+ # Return the geometry associated with the interface we are drawing.
190
154
  #
191
- # @return [Boolean]
192
- def border?
193
- Vedeu.borders.registered?(interface.name)
155
+ # @return [Vedeu::Geometry|Vedeu::NullGeometry]
156
+ def geometry
157
+ @geometry || Vedeu.geometries.by_name(name)
194
158
  end
195
159
 
196
160
  end # Viewport
@@ -15,7 +15,7 @@ module Vedeu
15
15
  # @param options [Hash]
16
16
  # @option options ellipsis [String] For when using mode `:prune`.
17
17
  # @option options mode [Symbol] One of :default, :prune, :wrap
18
- # @option options width [Fixnum] The width in characters to prune or wrap to.
18
+ # @option options width [Fixnum] The width to prune or wrap to.
19
19
  # @return [Vedeu::Wordwrap]
20
20
  def initialize(text, options = {})
21
21
  @text = text
@@ -24,7 +24,7 @@ module Vedeu
24
24
 
25
25
  # @return [Vedeu::Lines]
26
26
  def content
27
- case(mode)
27
+ case mode
28
28
  when :prune then to_line_objects(prune)
29
29
  when :wrap then to_line_objects(wrap)
30
30
  else
@@ -63,7 +63,7 @@ module Vedeu
63
63
 
64
64
  if (line_length += word_length) >= width
65
65
  line_length = word_length
66
- processed << reformatted
66
+ processed << reformatted
67
67
  reformatted = []
68
68
  end
69
69
 
@@ -92,7 +92,7 @@ module Vedeu
92
92
  # @return [Vedeu::Lines]
93
93
  def to_line_objects(text_as_lines)
94
94
  line_objects = Array(text_as_lines).map do |text_line|
95
- stream = Vedeu::Stream.new({ value: text_line })
95
+ stream = Vedeu::Stream.new(value: text_line)
96
96
  line = Vedeu::Line.new
97
97
  stream.parent = line
98
98
  line.add(stream)
@@ -1,196 +1,39 @@
1
- require 'vedeu/repositories/collection'
2
- require 'vedeu/repositories/collections'
3
- require 'vedeu/repositories/model'
4
- require 'vedeu/repositories/repository'
1
+ require_relative 'collection'
2
+ require_relative 'collections/all'
3
+ require_relative 'model'
4
+ require_relative 'repositories/all'
5
+ require_relative 'repository'
5
6
 
6
7
  module Vedeu
7
8
 
8
- # Allows the storing of interface/view borders independent of the interface
9
- # instance.
9
+ # Provides all registered repositories.
10
10
  #
11
- class Borders < Repository
11
+ module Repositories
12
12
 
13
- # @return [Vedeu::Borders]
14
- def self.borders
15
- @borders ||= Vedeu::Borders.new(Vedeu::Border)
16
- end
17
-
18
- end # Borders
19
-
20
- # Allows the storing of view buffers.
21
- #
22
- class Buffers < Repository
23
-
24
- # @return [Vedeu::Buffers]
25
- def self.buffers
26
- @buffers ||= Vedeu::Buffers.new(Vedeu::Buffer)
27
- end
28
-
29
- end # Buffers
30
-
31
- # Allows the storing of HTML/CSS colours and their respective escape
32
- # sequences.
33
- #
34
- class Colours
13
+ extend self
35
14
 
36
- # @!attribute [r] storage
37
- # @return [Hash<String => String>]
38
- attr_reader :storage
39
-
40
- # Returns a new instance of Vedeu::Colours.
41
- #
42
- # @return [Vedeu::Colours]
43
- def initialize
44
- @storage = {}
45
- end
46
-
47
- # Registers a colour with respective escape sequence.
48
- #
49
- # @return [String]
50
- def register(colour, escape_sequence)
51
- storage.store(colour, escape_sequence)
15
+ # @param klass [Class]
16
+ # @return [Set]
17
+ def register(klass)
18
+ storage.add(klass)
52
19
  end
53
20
 
54
- # Returns a boolean indicating whether the colour has been registered.
55
- #
56
- # @return [Boolean]
57
- def registered?(colour)
58
- storage.key?(colour)
59
- end
60
-
61
- # Removes all stored colours.
62
- #
63
- # @return [Hash]
21
+ # @return [TrueClass]
64
22
  def reset!
65
- storage.clear
66
- end
67
-
68
- # Retrieves a registered colour.
69
- #
70
- # @return [String]
71
- def retrieve(colour)
72
- storage.fetch(colour, '')
73
- end
74
-
75
- # Retrieves a registered colour, or registers the colour with its respective
76
- # escape sequence.
77
- #
78
- # @return [String]
79
- def retrieve_or_register(colour, escape_sequence)
80
- if registered?(colour)
81
- retrieve(colour)
82
-
83
- else
84
- register(colour, escape_sequence)
85
-
86
- end
87
- end
88
-
89
- end # Colours
90
-
91
- # Store background colour escape sequences by HTML/CSS code.
92
- #
93
- class BackgroundColours < Colours
94
-
95
- # @return [Vedeu::BackgroundColours]
96
- def self.background_colours
97
- @background_colours ||= new
98
- end
99
-
100
- end # BackgroundColours
101
-
102
- # Store foreground colour escape sequences by HTML/CSS code.
103
- #
104
- class ForegroundColours < Colours
23
+ storage.map(&:repository).map { |repository| repository.send(:reset) }
105
24
 
106
- # @return [Vedeu::ForegroundColours]
107
- def self.foreground_colours
108
- @foreground_colours ||= new
25
+ true
109
26
  end
110
27
 
111
- end # ForegroundColours
28
+ private
112
29
 
113
- # Allows the storing of each interface's cursor.
114
- #
115
- class Cursors < Repository
116
-
117
- # @return [Vedeu::Cursors]
118
- def self.cursors
119
- @cursors ||= Vedeu::Cursors.new(Vedeu::Cursor)
120
- end
121
-
122
- # @return [Vedeu::Cursor]
123
- def self.cursor
124
- cursors.current
125
- end
126
-
127
- end # Cursors
128
-
129
- # Allows the storing of events.
130
- #
131
- class EventsRepository < Repository
132
-
133
- # @return [Vedeu::EventsRepository]
134
- def self.events
135
- @events ||= Vedeu::EventsRepository.new(Vedeu::Events)
136
- end
137
-
138
- end # EventsRepository
139
-
140
- # Allows the storing of interface/view geometry independent of the interface
141
- # instance.
142
- #
143
- class Geometries < Repository
144
-
145
- # @return [Vedeu::Geometries]
146
- def self.geometries
147
- @geometries ||= Vedeu::Geometries.new(Vedeu::Geometry)
148
- end
149
-
150
- end # Geometries
151
-
152
- # Allows the storing of view groups.
153
- #
154
- class Groups < Repository
155
-
156
- # @return [Vedeu::Groups]
157
- def self.groups
158
- @groups ||= Vedeu::Groups.new(Vedeu::Group)
159
- end
160
-
161
- end # Groups
162
-
163
- # Allows the storing of interfaces and views.
164
- #
165
- class InterfacesRepository < Repository
166
-
167
- # @return [Vedeu::InterfacesRepository]
168
- def self.interfaces
169
- @interfaces ||= Vedeu::InterfacesRepository.new(Vedeu::Interface)
170
- end
171
-
172
- end # InterfacesRepository
173
-
174
- # Allows the storing of keymaps.
175
- #
176
- class Keymaps < Repository
177
-
178
- # @return [Vedeu::Keymaps]
179
- def self.keymaps
180
- @keymaps ||= Vedeu::Keymaps.new(Vedeu::Keymap)
181
- end
182
-
183
- end # Keymaps
184
-
185
- # Allows the storing of menus by name.
186
- #
187
- class Menus < Repository
188
-
189
- # @return [Vedeu::Menus]
190
- def self.menus
191
- @menus ||= Vedeu::Menus.new(Vedeu::Menu)
30
+ # Access to the storage for this repository.
31
+ #
32
+ # @return [Array]
33
+ def storage
34
+ @storage ||= Set.new
192
35
  end
193
36
 
194
- end # Menus
37
+ end
195
38
 
196
39
  end # Vedeu
@@ -7,6 +7,11 @@ module Vedeu
7
7
 
8
8
  include Enumerable
9
9
 
10
+ # @!attribute [r] collection
11
+ # @return [Array|Vedeu::Collection]
12
+ attr_reader :collection
13
+ alias_method :all, :collection
14
+
10
15
  # @!attribute [rw] parent
11
16
  # @return [Fixnum]
12
17
  attr_accessor :parent
@@ -20,7 +25,7 @@ module Vedeu
20
25
  # @param name [String|NilClass]
21
26
  # @return [Vedeu::Collection]
22
27
  def self.coerce(collection = [], parent = nil, name = nil)
23
- if collection.kind_of?(Vedeu::Collection)
28
+ if collection.is_a?(Vedeu::Collection)
24
29
  collection
25
30
 
26
31
  else
@@ -46,7 +51,7 @@ module Vedeu
46
51
  # @param value [Fixnum]
47
52
  # @return [void]
48
53
  def [](value)
49
- @collection[value]
54
+ collection[value]
50
55
  end
51
56
 
52
57
  # Adds an entry to the collection.
@@ -58,40 +63,33 @@ module Vedeu
58
63
  end
59
64
  alias_method :<<, :add
60
65
 
61
- # Returns the whole collection.
62
- #
63
- # @return [Array]
64
- def all
65
- @collection
66
- end
67
-
68
66
  # Provides iteration over the collection.
69
67
  #
70
68
  # @param block [Proc]
71
69
  # @return [Enumerator]
72
70
  def each(&block)
73
- @collection.each(&block)
71
+ collection.each(&block)
74
72
  end
75
73
 
76
74
  # Returns a boolean indicating whether the collection is empty.
77
75
  #
78
76
  # @return [Boolean]
79
77
  def empty?
80
- @collection.empty?
78
+ collection.empty?
81
79
  end
82
80
 
83
81
  # Returns the size of the collection.
84
82
  #
85
83
  # @return [Fixnum]
86
84
  def size
87
- @collection.size
85
+ collection.size
88
86
  end
89
87
 
90
88
  # Returns the collection as a String.
91
89
  #
92
90
  # @return [String]
93
91
  def to_s
94
- @collection.map(&:to_s).join
92
+ collection.map(&:to_s).join
95
93
  end
96
94
 
97
95
  end # Collection
@@ -0,0 +1,8 @@
1
+ require 'vedeu/repositories/collection'
2
+
3
+ require_relative 'chars'
4
+ require_relative 'events'
5
+ require_relative 'interfaces'
6
+ require_relative 'keys'
7
+ require_relative 'lines'
8
+ require_relative 'streams'
@@ -0,0 +1,9 @@
1
+ module Vedeu
2
+
3
+ # A collection of {Vedeu::Char} instances.
4
+ #
5
+ class Chars < Vedeu::Collection
6
+
7
+ end # Chars
8
+
9
+ end # Vedeu
@@ -0,0 +1,9 @@
1
+ module Vedeu
2
+
3
+ # A collection of {Vedeu::Event} instances.
4
+ #
5
+ class Events < Vedeu::Collection
6
+
7
+ end # Events
8
+
9
+ end # Vedeu
@@ -0,0 +1,9 @@
1
+ module Vedeu
2
+
3
+ # A collection of {Vedeu::Interface} instances.
4
+ #
5
+ class Interfaces < Vedeu::Collection
6
+
7
+ end # Interfaces
8
+
9
+ end # Vedeu
@@ -0,0 +1,9 @@
1
+ module Vedeu
2
+
3
+ # A collection of {Vedeu::Key} instances.
4
+ #
5
+ class Keys < Vedeu::Collection
6
+
7
+ end # Keys
8
+
9
+ end # Vedeu
@@ -0,0 +1,9 @@
1
+ module Vedeu
2
+
3
+ # A collection of {Vedeu::Line} instances.
4
+ #
5
+ class Lines < Vedeu::Collection
6
+
7
+ end # Lines
8
+
9
+ end # Vedeu
@@ -0,0 +1,9 @@
1
+ module Vedeu
2
+
3
+ # A collection of {Vedeu::Stream} instances.
4
+ #
5
+ class Streams < Vedeu::Collection
6
+
7
+ end # Streams
8
+
9
+ end # Vedeu
@@ -5,9 +5,9 @@ module Vedeu
5
5
  #
6
6
  module Model
7
7
 
8
- # @!attribute [r] repository
8
+ # @!attribute [rw] repository
9
9
  # @return [Vedeu::Repository]
10
- attr_reader :repository
10
+ attr_accessor :repository
11
11
 
12
12
  # When {Vedeu::Model} is included in a class, the methods within this module
13
13
  # are included as class methods on that class.
@@ -40,6 +40,11 @@ module Vedeu
40
40
  alias_method :member, :child
41
41
  alias_method :collection, :child
42
42
 
43
+ def repository(klass, as:)
44
+ self.repository = as
45
+ klass.register(as, self)
46
+ end
47
+
43
48
  private
44
49
 
45
50
  # The default values for a new instance of this class.
@@ -0,0 +1,14 @@
1
+ require 'vedeu/repositories/repository'
2
+
3
+ require_relative 'colours'
4
+ require_relative 'background_colours'
5
+ require_relative 'foreground_colours'
6
+ require_relative 'borders'
7
+ require_relative 'buffers'
8
+ require_relative 'cursors'
9
+ require_relative 'events_repository'
10
+ require_relative 'geometries'
11
+ require_relative 'groups'
12
+ require_relative 'interfaces_repository'
13
+ require_relative 'keymaps'
14
+ require_relative 'menus'
@@ -0,0 +1,14 @@
1
+ module Vedeu
2
+
3
+ # Store background colour escape sequences by HTML/CSS code.
4
+ #
5
+ class BackgroundColours < Colours
6
+
7
+ # @return [Vedeu::BackgroundColours]
8
+ def self.background_colours
9
+ @background_colours ||= new
10
+ end
11
+
12
+ end # BackgroundColours
13
+
14
+ end # Vedeu
@@ -0,0 +1,38 @@
1
+ module Vedeu
2
+
3
+ # Allows the storing of interface/view borders independent of the interface
4
+ # instance.
5
+ #
6
+ class Borders < Repository
7
+
8
+ # @return [Vedeu::Borders]
9
+ def self.borders
10
+ @borders ||= reset! # Vedeu::Borders.new(Vedeu::Border)
11
+ end
12
+
13
+ # @return [Vedeu::Borders]
14
+ def self.repository
15
+ Vedeu.borders
16
+ end
17
+
18
+ # @return [Vedeu::Borders]
19
+ def self.reset!
20
+ @borders = Vedeu::Borders.register_repository(Vedeu::Border)
21
+ end
22
+
23
+ # @param name [String] The name of the stored border.
24
+ # @return [Vedeu::Border|Vedeu::NullBorder|NilClass]
25
+ def by_name(name)
26
+ if registered?(name)
27
+ find(name)
28
+
29
+ elsif Vedeu.interfaces.registered?(name)
30
+ interface = Vedeu.interfaces.find(name)
31
+ Vedeu::NullBorder.new(interface)
32
+
33
+ end
34
+ end
35
+
36
+ end # Borders
37
+
38
+ end # Vedeu