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
@@ -14,14 +14,6 @@ module Vedeu
14
14
  #
15
15
  module Bindings
16
16
 
17
- # Vedeu triggers this event when `:_exit_` is triggered. You can hook into
18
- # this to perform a special action before the application terminates. Saving
19
- # the user's work, session or preferences might be popular here.
20
- Vedeu.bind(:_cleanup_) do
21
- Vedeu.trigger(:_drb_stop_)
22
- Vedeu.trigger(:cleanup)
23
- end
24
-
25
17
  Vedeu.bind(:_drb_input_) do |data, type|
26
18
  Vedeu.log(type: :drb, message: "Sending input (#{type})")
27
19
 
@@ -46,6 +38,14 @@ module Vedeu
46
38
  Vedeu.bind(:_drb_status_) { Vedeu::Distributed::Server.status }
47
39
  Vedeu.bind(:_drb_stop_) { Vedeu::Distributed::Server.stop }
48
40
 
41
+ # Vedeu triggers this event when `:_exit_` is triggered. You can hook into
42
+ # this to perform a special action before the application terminates. Saving
43
+ # the user's work, session or preferences might be popular here.
44
+ Vedeu.bind(:_cleanup_) do
45
+ Vedeu.trigger(:_drb_stop_)
46
+ Vedeu.trigger(:cleanup)
47
+ end
48
+
49
49
  # When triggered, Vedeu will trigger a `:cleanup` event which you can define
50
50
  # (to save files, etc) and attempt to exit.
51
51
  Vedeu.bind(:_exit_) { Vedeu::Application.stop }
@@ -82,23 +82,27 @@ module Vedeu
82
82
 
83
83
  # When triggered will cause Vedeu to trigger the `:_clear_` and `:_refresh_`
84
84
  # events. Please see those events for their behaviour.
85
- Vedeu.bind(:_resize_, { delay: 0.25 }) { Vedeu.resize }
85
+ Vedeu.bind(:_resize_, delay: 0.25) { Vedeu.resize }
86
86
 
87
- Vedeu.bind(:tick) { |time| Vedeu.log(type: :debug, message: "Tick: #{time}") }
88
- Vedeu.bind(:tock) { |time| Vedeu.log(type: :debug, message: "Tock: #{time}") }
87
+ Vedeu.bind(:tick) do |time|
88
+ Vedeu.log(type: :debug, message: "Tick: #{time}")
89
+ end
90
+ Vedeu.bind(:tock) do |time|
91
+ Vedeu.log(type: :debug, message: "Tock: #{time}")
92
+ end
89
93
 
90
94
  # Hide the cursor of the named interface or interface currently in focus.
91
95
  Vedeu.bind(:_cursor_hide_) do |name|
92
96
  named = name ? Vedeu.cursors.by_name(name) : Vedeu.cursor
93
97
 
94
- Vedeu::Toggle.hide(named)
98
+ Vedeu::Visibility.hide(named)
95
99
  end
96
100
 
97
101
  # Show the cursor of the named interface or interface currently in focus.
98
102
  Vedeu.bind(:_cursor_show_) do |name|
99
103
  named = name ? Vedeu.cursors.by_name(name) : Vedeu.cursor
100
104
 
101
- Vedeu::Toggle.show(named)
105
+ Vedeu::Visibility.show(named)
102
106
  end
103
107
 
104
108
  # @see {Vedeu::Move}
@@ -182,13 +186,16 @@ module Vedeu
182
186
  end
183
187
 
184
188
  # Clears the spaces occupied by the interfaces belonging to the named group.
185
- Vedeu.bind(:_clear_group_) do |name|
186
- Vedeu.groups.find(name).members.each do |group_name|
187
- Vedeu.trigger(:_clear_, group_name)
189
+ Vedeu.bind(:_clear_group_) do |group_name|
190
+ Vedeu.groups.find(group_name).members.each do |interface_name|
191
+ Vedeu.trigger(:_clear_, interface_name)
188
192
  end
189
193
  end
190
194
 
191
195
  # Will cause all interfaces to refresh, or the named interface if given.
196
+ #
197
+ # @note
198
+ # Hidden interfaces will be still refreshed in memory but not shown.
192
199
  Vedeu.bind(:_refresh_) do |name|
193
200
  name ? Vedeu::Refresh.by_name(name) : Vedeu::Refresh.all
194
201
  end
@@ -219,6 +226,60 @@ module Vedeu
219
226
  Vedeu.trigger(:_clear_group_, name)
220
227
  end
221
228
 
229
+ # Will hide the named interface. If the interface is currently visible, it
230
+ # will be cleared- rendered blank. To show the interface, the
231
+ # ':_show_interface_' event should be triggered.
232
+ # Triggering the ':_hide_group_' event to which this named interface belongs
233
+ # will also hide the interface.
234
+ Vedeu.bind(:_hide_interface_) do |name|
235
+ if name && Vedeu.interfaces.registered?(name)
236
+ interface = Vedeu.interfaces.find(name)
237
+
238
+ if interface.visible?
239
+ interface = Vedeu::Visibility.hide(interface)
240
+ Vedeu.buffers.clear(interface.name)
241
+ end
242
+ end
243
+ end
244
+
245
+ # Will show the named interface. If the interface is currently invisible, it
246
+ # will be shown- rendered with its latest content. To hide the interface,
247
+ # the ':_hide_interface_' event should be triggered.
248
+ # Triggering the ':_show_group_' event to which this named interface belongs
249
+ # will also show the interface.
250
+ Vedeu.bind(:_show_interface_) do |name|
251
+ if name && Vedeu.interfaces.registered?(name)
252
+ interface = Vedeu.interfaces.find(name)
253
+
254
+ interface = Vedeu::Visibility.show(interface) unless interface.visible?
255
+
256
+ Vedeu.buffers.render(interface.name)
257
+ end
258
+ end
259
+
260
+ # Will toggle the visibility of the named interface. If the interface is
261
+ # currently visible, the area it occupies will be clears and the interface
262
+ # will be marked invisible. If the interface is invisible, then the
263
+ # interface will be marked visible and rendered in the area it occupies.
264
+ #
265
+ # @note
266
+ # If an interface is marked visible whilst another view is occupying some
267
+ # or all of the interface's current position, the interface will overwrite
268
+ # this area- this may cause visual corruption.
269
+ Vedeu.bind(:_toggle_interface_) do |name|
270
+ if name && Vedeu.interfaces.registered?(name)
271
+ interface = Vedeu.interfaces.find(name)
272
+
273
+ if interface.visible?
274
+ Vedeu.trigger(:_hide_interface_, name)
275
+
276
+ else
277
+ Vedeu.trigger(:_show_interface_, name)
278
+
279
+ end
280
+ end
281
+ end
282
+
222
283
  end # Bindings
223
284
  # :nocov:
224
285
 
@@ -1,5 +1,2 @@
1
- require 'vedeu/buffers/buffer'
2
- require 'vedeu/buffers/display_buffer'
3
-
4
- module Vedeu
5
- end # Vedeu
1
+ require_relative 'buffer'
2
+ require_relative 'display_buffer'
@@ -37,26 +37,33 @@ module Vedeu
37
37
  # Return a new instance of Buffer. Generally a Buffer is initialized with
38
38
  # only a 'name' and 'back' parameter.
39
39
  #
40
- # @param name [String] The name of the interface for which the buffer
41
- # belongs.
42
- # @param back [Interface]
43
- # @param front [Interface]
44
- # @param previous [Interface]
40
+ # @option attributes name [String] The name of the interface for which the
41
+ # buffer belongs.
42
+ # @option attributes back [Interface]
43
+ # @option attributes front [Interface]
44
+ # @option attributes previous [Interface]
45
+ # @option attributes repository [Vedeu::Buffers]
45
46
  # @return [Buffer]
46
- def initialize(name, back = nil, front = nil, previous = nil, repository = nil)
47
- @name = name
48
- @back = back
49
- @front = front
50
- @previous = previous
51
- @repository = repository || Vedeu.buffers
47
+ def initialize(attributes = {})
48
+ @attributes = defaults.merge!(attributes)
49
+
50
+ @name = @attributes[:name]
51
+ @back = @attributes[:back]
52
+ @front = @attributes[:front]
53
+ @previous = @attributes[:previous]
54
+ @repository = @attributes[:repository] || Vedeu.buffers
52
55
  end
53
56
 
54
57
  # Add the content to the back buffer, then update the repository. Returns
55
- # boolean indicating that the repository was updated.
58
+ # boolean indicating that the repository was updated. Here we also apply any
59
+ # overridden colours or styles in the buffered view to the stored interface.
56
60
  #
57
61
  # @param content [Interface]
58
62
  # @return [Boolean]
59
63
  def add(content)
64
+ content.colour = interface.colour unless content.colour
65
+ content.style = interface.style unless content.style
66
+
60
67
  @back = content
61
68
 
62
69
  store
@@ -76,22 +83,56 @@ module Vedeu
76
83
  # - If the 'previous' buffer is empty, return an empty collection.
77
84
  #
78
85
  # @return [Array<Hash>]
79
- def content
80
- if content_for?(:back)
81
- swap
86
+ def render
87
+ buffer = if content_for?(:back)
88
+ swap
89
+
90
+ [front.render]
91
+
92
+ elsif content_for?(:front)
93
+ [front.render]
94
+
95
+ elsif content_for?(:previous)
96
+ [previous.render]
97
+
98
+ else
99
+ []
100
+
101
+ end
102
+
103
+ Vedeu::Output.render(buffer) unless buffer.empty?
104
+
105
+ buffer
106
+ end
107
+ alias_method :content, :render
82
108
 
83
- [front]
109
+ # Returns the front buffer or, if that is empty, the interface cleared.
110
+ #
111
+ # @return [void]
112
+ def clear
113
+ buffer = if content_for?(:front)
114
+ front.clear.clear
115
+
116
+ else
117
+ interface.clear.clear
84
118
 
85
- elsif content_for?(:front)
86
- [front]
119
+ end
87
120
 
88
- elsif content_for?(:previous)
89
- [previous]
121
+ Vedeu::Output.render(buffer) unless buffer.empty?
90
122
 
91
- else
92
- []
123
+ buffer
124
+ end
125
+
126
+ private
93
127
 
94
- end
128
+ # @return [Hash<Symbol => NilClass, String>]
129
+ def defaults
130
+ {
131
+ back: nil,
132
+ front: nil,
133
+ name: '',
134
+ previous: nil,
135
+ }
95
136
  end
96
137
 
97
138
  # Return a boolean indicating content was swapped between buffers.
@@ -107,8 +148,6 @@ module Vedeu
107
148
  true
108
149
  end
109
150
 
110
- private
111
-
112
151
  # Return a boolean indicating content presence on the buffer type.
113
152
  #
114
153
  # @param buffer [Symbol] One of; :back, :front or :previous.
@@ -120,6 +159,11 @@ module Vedeu
120
159
  true
121
160
  end
122
161
 
162
+ # @return [Vedeu::Interface]
163
+ def interface
164
+ @interface ||= Vedeu.interfaces.find(name)
165
+ end
166
+
123
167
  end # Buffer
124
168
 
125
169
  end # Vedeu
@@ -48,7 +48,7 @@ module Vedeu
48
48
  Vedeu.buffers.find(name).add(self)
49
49
 
50
50
  else
51
- Vedeu::Buffer.new(name, self).store
51
+ Vedeu::Buffer.new(name: name, back: self).store
52
52
 
53
53
  end
54
54
 
@@ -59,9 +59,7 @@ module Vedeu
59
59
  #
60
60
  # @return [Interface]
61
61
  def store_focusable
62
- unless Vedeu.focusable.registered?(name)
63
- Vedeu.focusable.add(name)
64
- end
62
+ Vedeu.focusable.add(name) unless Vedeu.focusable.registered?(name)
65
63
 
66
64
  self
67
65
  end
@@ -70,9 +68,7 @@ module Vedeu
70
68
  #
71
69
  # @return [Interface]
72
70
  def store_cursor
73
- unless Vedeu.cursors.registered?(name)
74
- Vedeu::Cursor.new({ name: name }).store
75
- end
71
+ Vedeu::Cursor.new(name: name).store unless Vedeu.cursors.registered?(name)
76
72
 
77
73
  self
78
74
  end
@@ -1,6 +1,3 @@
1
- require 'vedeu/configuration/cli'
2
- require 'vedeu/configuration/api'
3
- require 'vedeu/configuration/configuration'
4
-
5
- module Vedeu
6
- end # Vedeu
1
+ require_relative 'cli'
2
+ require_relative 'api'
3
+ require_relative 'configuration'
@@ -34,11 +34,10 @@ module Vedeu
34
34
  #
35
35
  # @return [Hash<Symbol => Boolean, Fixnum, String>]
36
36
  def configuration
37
- options.merge!({
38
- system_keys: Configuration.default_system_keys.merge!(system_keys)
39
- }) if system_keys.any?
37
+ new_system_keys = Configuration.default_system_keys.merge!(system_keys)
38
+ options.merge!(system_keys: new_system_keys) if system_keys.any?
40
39
 
41
- Vedeu::Config.log('API', options)
40
+ Vedeu::Config.log(Esc.green { '[api]' }, options)
42
41
  end
43
42
 
44
43
  # Sets boolean to allow user input. The default behaviour of Vedeu is to
@@ -238,6 +237,12 @@ module Vedeu
238
237
  # colour_mode 256
239
238
  # ...
240
239
  #
240
+ # @note
241
+ # iTerm 2 on Mac OSX will handle the true colour setting (16777216),
242
+ # whereas Terminator on Linux will not display colours correctly. For
243
+ # compatibility across platforms, it is recommended to either not set
244
+ # the colour mode at all and allow it to be detected, or use 256 here.
245
+ #
241
246
  # @param value [Fixnum]
242
247
  # @raise [InvalidSyntax] When the value parameter is not one of +8+, +16+,
243
248
  # +256+ or +16777216+.
@@ -261,6 +266,25 @@ module Vedeu
261
266
  options[:log] = filename
262
267
  end
263
268
 
269
+ # Sets the renderers for Vedeu. Each renderer added must have the class
270
+ # method '.render' defined as this will be called when rendering content.
271
+ #
272
+ # @example
273
+ # Vedeu.configure do
274
+ # renderer MyRenderer
275
+ # ...
276
+ #
277
+ # Vedeu.configure do
278
+ # renderers MyRenderer, MyOtherRenderer
279
+ # ...
280
+ #
281
+ # @param renderer [Array<Class>|Class]
282
+ # @return [Array<Class>]
283
+ def renderer(*renderer)
284
+ options[:renderers] = Vedeu::Configuration.renderers + renderer
285
+ end
286
+ alias_method :renderers, :renderer
287
+
264
288
  # Sets the value of STDIN.
265
289
  #
266
290
  # @example
@@ -1,5 +1,3 @@
1
- require 'optparse'
2
-
3
1
  module Vedeu
4
2
 
5
3
  module Config
@@ -39,8 +37,8 @@ module Vedeu
39
37
  end
40
38
 
41
39
  opts.on('-I', '--noninteractive', '--standalone',
42
- 'Run the application non-interactively; i.e. not requiring ' \
43
- 'intervention from the user.') do
40
+ 'Run the application non-interactively; ' \
41
+ 'i.e. not requiring intervention from the user.') do
44
42
  options[:interactive] = false
45
43
  end
46
44
 
@@ -94,8 +92,8 @@ module Vedeu
94
92
  end
95
93
 
96
94
  opts.on('--drb-host',
97
- 'Set the hostname/IP for the DRb server.') do |hostname|
98
- #options[:drb] = true
95
+ 'Set the hostname/IP for the DRb server.') do |hostname|
96
+ # options[:drb] = true
99
97
  options[:drb_host] = hostname
100
98
  end
101
99
 
@@ -104,12 +102,14 @@ module Vedeu
104
102
  options[:drb_port] = port
105
103
  end
106
104
 
107
- opts.on('--drb-height', 'Set the height for fake terminal of the DRb server.') do |height|
105
+ opts.on('--drb-height',
106
+ 'Set the height for fake terminal.') do |height|
108
107
  # options[:drb] = true
109
108
  options[:drb_height] = height
110
109
  end
111
110
 
112
- opts.on('--drb-width', 'Set the width for fake terminal of the DRb server.') do |width|
111
+ opts.on('--drb-width',
112
+ 'Set the width for fake terminal.') do |width|
113
113
  # options[:drb] = true
114
114
  options[:drb_width] = width
115
115
  end
@@ -117,7 +117,7 @@ module Vedeu
117
117
 
118
118
  parser.parse!(args)
119
119
 
120
- Vedeu::Config.log('CLI', options)
120
+ Vedeu::Config.log(Esc.blue { '[cli]' }, options)
121
121
  end
122
122
 
123
123
  private
@@ -1,8 +1,3 @@
1
- require 'singleton'
2
-
3
- require 'vedeu/configuration/api'
4
- require 'vedeu/configuration/cli'
5
-
6
1
  module Vedeu
7
2
 
8
3
  # Namespace for the API configuration and CLI configuration classes.
@@ -19,7 +14,7 @@ module Vedeu
19
14
  def log(from, options)
20
15
  options.each do |option, value|
21
16
  Vedeu.log(type: :config,
22
- message: "#{from} #{option.to_s}: #{value.to_s}")
17
+ message: "#{from} #{option}: #{value}")
23
18
  end
24
19
  end
25
20
 
@@ -142,6 +137,13 @@ module Vedeu
142
137
  end
143
138
  alias_method :once, :once?
144
139
 
140
+ # Returns the renderers which should receive output.
141
+ #
142
+ # @return [Array<Class>]
143
+ def renderers
144
+ instance.options[:renderers]
145
+ end
146
+
145
147
  # Returns the redefined setting for STDIN.
146
148
  #
147
149
  # @return [File|IO]
@@ -236,9 +238,10 @@ module Vedeu
236
238
  @options.merge!(opts)
237
239
 
238
240
  @options.merge!(Config::API.configure(&block)) if block_given?
239
-
240
241
  @options.merge!(Config::CLI.configure(args)) if args.any?
241
242
 
243
+ Vedeu::Renderers.renderer(*@options[:renderers])
244
+
242
245
  Vedeu::Configuration
243
246
  end
244
247
 
@@ -267,6 +270,7 @@ module Vedeu
267
270
  interactive: true,
268
271
  log: '/tmp/vedeu.log',
269
272
  once: false,
273
+ renderers: [Vedeu::TerminalRenderer],
270
274
  stdin: nil,
271
275
  stdout: nil,
272
276
  stderr: nil,
@@ -1,8 +1,5 @@
1
1
  require 'vedeu/repositories/all'
2
- require 'vedeu/cursor/cursor'
3
- require 'vedeu/cursor/move'
4
- require 'vedeu/cursor/refresh_cursor'
5
- require 'vedeu/cursor/toggle'
6
2
 
7
- module Vedeu
8
- end # Vedeu
3
+ require_relative 'cursor'
4
+ require_relative 'move'
5
+ require_relative 'refresh_cursor'
@@ -1,6 +1,5 @@
1
1
  require 'vedeu/cursor/all'
2
2
  require 'vedeu/geometry/position'
3
- require 'vedeu/support/visible'
4
3
 
5
4
  module Vedeu
6
5
 
@@ -10,10 +9,6 @@ module Vedeu
10
9
  class Cursor
11
10
 
12
11
  extend Forwardable
13
-
14
- def_delegators :state, :visible?,
15
- :invisible?
16
-
17
12
  include Vedeu::Model
18
13
 
19
14
  # @!attribute [r] attributes
@@ -36,6 +31,11 @@ module Vedeu
36
31
  # @return [Boolean|Symbol]
37
32
  attr_reader :state
38
33
 
34
+ # @!attribute [r] visible
35
+ # @return [Boolean|Symbol]
36
+ attr_reader :visible
37
+ alias_method :visible?, :visible
38
+
39
39
  # @!attribute [r] x
40
40
  # @return [Fixnum]
41
41
  attr_reader :x
@@ -52,8 +52,7 @@ module Vedeu
52
52
  # @option attributes ox [Fixnum] The offset x coordinate.
53
53
  # @option attributes oy [Fixnum] The offset y coordinate.
54
54
  # @option attributes repository [Vedeu::Repository]
55
- # @option attributes state [Boolean|Symbol] The visibility of the cursor,
56
- # either +true+ or +false+, +:hide+ or +:show+.
55
+ # @option attributes visible [Boolean] The visibility of the cursor.
57
56
  # @option attributes x [Fixnum] The terminal x coordinate for the cursor.
58
57
  # @option attributes y [Fixnum] The terminal y coordinate for the cursor.
59
58
  #
@@ -61,9 +60,7 @@ module Vedeu
61
60
  def initialize(attributes = {})
62
61
  # Hack because Repository#by_name creates Cursor objects with just a
63
62
  # name.
64
- if attributes.is_a?(String)
65
- attributes = { name: attributes }
66
- end
63
+ attributes = { name: attributes } if attributes.is_a?(String)
67
64
 
68
65
  @attributes = defaults.merge!(attributes)
69
66
 
@@ -71,7 +68,7 @@ module Vedeu
71
68
  @ox = @attributes.fetch(:ox)
72
69
  @oy = @attributes.fetch(:oy)
73
70
  @repository = @attributes.fetch(:repository)
74
- @state = Vedeu::Visible.coerce(@attributes.fetch(:state))
71
+ @visible = @attributes.fetch(:visible)
75
72
  @x = @attributes.fetch(:x)
76
73
  @y = @attributes.fetch(:y)
77
74
 
@@ -80,7 +77,12 @@ module Vedeu
80
77
 
81
78
  # @return [String]
82
79
  def inspect
83
- "<Vedeu::Cursor (#{name}, #{state}, x:#{x}, y:#{y}, ox:#{ox}, oy:#{oy})>"
80
+ "<Vedeu::Cursor (#{name}, " \
81
+ "#{visible}, " \
82
+ "x:#{x}, " \
83
+ "y:#{y}, " \
84
+ "ox:#{ox}, " \
85
+ "oy:#{oy})>"
84
86
  end
85
87
 
86
88
  # Returns an escape sequence to position the cursor and set its visibility.
@@ -114,7 +116,7 @@ module Vedeu
114
116
  ox: 0,
115
117
  oy: 0,
116
118
  repository: Vedeu.cursors,
117
- state: false,
119
+ visible: false,
118
120
  x: 1,
119
121
  y: 1,
120
122
  }
@@ -131,7 +133,13 @@ module Vedeu
131
133
  #
132
134
  # @return [String]
133
135
  def visibility
134
- state.cursor
136
+ if visible?
137
+ Vedeu::Esc.string('show_cursor')
138
+
139
+ else
140
+ Vedeu::Esc.string('hide_cursor')
141
+
142
+ end
135
143
  end
136
144
 
137
145
  end # Cursor
@@ -38,13 +38,13 @@ module Vedeu
38
38
  extend Forwardable
39
39
 
40
40
  def_delegators :@interface, :border,
41
- :border?,
42
- :geometry
41
+ :border?,
42
+ :geometry
43
43
 
44
44
  def_delegators :geometry, :left,
45
- :top,
46
- :height,
47
- :width
45
+ :top,
46
+ :height,
47
+ :width
48
48
 
49
49
  # Returns an instance of Vedeu::Move.
50
50
  #
@@ -174,29 +174,19 @@ module Vedeu
174
174
 
175
175
  # @return [PositionValidator]
176
176
  def validator
177
- @validator ||= Vedeu::PositionValidator.validate(interface,
178
- coordinate.x_position(ox),
179
- coordinate.y_position(oy))
177
+ @validator ||= Vedeu::PositionValidator.validate(interface.name,
178
+ x_position,
179
+ y_position)
180
180
  end
181
181
 
182
- # Apply the direction amount to the cursor offset. If the offset is less
183
- # than 0, correct to 0.
184
- #
185
182
  # @return [Fixnum]
186
- def ox
187
- ox = cursor.ox + dx
188
- ox = 0 if ox < 0
189
- ox
183
+ def x_position
184
+ coordinate.x_position(ox)
190
185
  end
191
186
 
192
- # Apply the direction amount to the cursor offset. If the offset is less
193
- # than 0, correct to 0.
194
- #
195
187
  # @return [Fixnum]
196
- def oy
197
- oy = cursor.oy + dy
198
- oy = 0 if oy < 0
199
- oy
188
+ def y_position
189
+ coordinate.y_position(oy)
200
190
  end
201
191
 
202
192
  # @return [Coordinate]
@@ -225,6 +215,26 @@ module Vedeu
225
215
  width
226
216
  end
227
217
 
218
+ # Apply the direction amount to the cursor offset. If the offset is less
219
+ # than 0, correct to 0.
220
+ #
221
+ # @return [Fixnum]
222
+ def ox
223
+ ox = cursor.ox + dx
224
+ ox = 0 if ox < 0
225
+ ox
226
+ end
227
+
228
+ # Apply the direction amount to the cursor offset. If the offset is less
229
+ # than 0, correct to 0.
230
+ #
231
+ # @return [Fixnum]
232
+ def oy
233
+ oy = cursor.oy + dy
234
+ oy = 0 if oy < 0
235
+ oy
236
+ end
237
+
228
238
  end # Move
229
239
 
230
240
  end # Vedeu
@@ -53,7 +53,7 @@ module Vedeu
53
53
 
54
54
  # @return [Vedeu::PositionValidator]
55
55
  def validated_position
56
- @position ||= Vedeu::PositionValidator.validate(interface,
56
+ @position ||= Vedeu::PositionValidator.validate(interface.name,
57
57
  cursor.x,
58
58
  cursor.y)
59
59
  end