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
@@ -136,28 +136,28 @@ module Vedeu
136
136
  def bx
137
137
  bo = (enabled? && left?) ? 1 : 0
138
138
 
139
- interface.x + bo
139
+ geometry.x + bo
140
140
  end
141
141
 
142
142
  # @return [Fixnum]
143
143
  def bxn
144
144
  bo = (enabled? && right?) ? 1 : 0
145
145
 
146
- interface.xn - bo
146
+ geometry.xn - bo
147
147
  end
148
148
 
149
149
  # @return [Fixnum]
150
150
  def by
151
151
  bo = (enabled? && top?) ? 1 : 0
152
152
 
153
- interface.y + bo
153
+ geometry.y + bo
154
154
  end
155
155
 
156
156
  # @return [Fixnum]
157
157
  def byn
158
158
  bo = (enabled? && bottom?) ? 1 : 0
159
159
 
160
- interface.yn - bo
160
+ geometry.yn - bo
161
161
  end
162
162
 
163
163
  # Returns the width of the interface determined by whether a left, right,
@@ -190,6 +190,7 @@ module Vedeu
190
190
 
191
191
  # @return [Array<Array<Vedeu::Char>>]
192
192
  def render
193
+ return [] unless interface.visible?
193
194
  return [] unless enabled?
194
195
 
195
196
  out = [top, bottom]
@@ -262,20 +263,8 @@ module Vedeu
262
263
  out = []
263
264
  out << border(send(prefix_left), prefix_left) if left?
264
265
 
265
- if prefix == 'top' && defined_value?(title)
266
- title_out = []
267
- width.times do |ix|
268
- title_out << border(horizontal, prefix_horizontal, nil, ix)
269
- end
270
-
271
- truncate = title.chomp.slice(0..(width - 5))
272
- pad = truncate.center(truncate.size + 2).chars
273
- out << title_out.each_with_index do |b, i|
274
- if i >= 1 && i <= pad.size
275
- b.border = nil
276
- b.value = pad[(i - 1)]
277
- end
278
- end
266
+ if prefix == 'top' && title?
267
+ out << titlebar
279
268
 
280
269
  else
281
270
  width.times do |ix|
@@ -288,18 +277,90 @@ module Vedeu
288
277
  out
289
278
  end
290
279
 
280
+ # @return [Array<Vedeu::Char>]
281
+ def horizontal_border
282
+ width.times.inject([]) do |a, ix|
283
+ a << border(horizontal, :top_horizontal, nil, ix)
284
+ a
285
+ end
286
+ end
287
+
288
+ # From the second element of {#title_characters} remove the border from each
289
+ # {#horizontal_border} Vedeu::Char, and add the title character.
290
+ #
291
+ # @return [Array<Vedeu::Char>]
292
+ def titlebar
293
+ horizontal_border.each_with_index do |char, index|
294
+ if index >= 1 && index <= title_characters.size
295
+ char.border = nil
296
+ char.value = title_characters[(index - 1)]
297
+ end
298
+ end
299
+ end
300
+
301
+ # @return [Array<String>]
302
+ def title_characters
303
+ @title_characters ||= padded_title.chars
304
+ end
305
+
306
+ # Pads the title with a single whitespace either side.
307
+ #
308
+ # @example
309
+ # title = 'Truncated!'
310
+ # width = 20
311
+ # # => ' Truncated! '
312
+ #
313
+ # width = 10
314
+ # # => ' Trunca '
315
+ #
316
+ # @return [String]
317
+ # @see #truncated_title
318
+ def padded_title
319
+ truncated_title.center(truncated_title.size + 2)
320
+ end
321
+
322
+ # Truncates the title to the width of the interface, minus characters needed
323
+ # to ensure there is at least a single character of horizontal border and a
324
+ # whitespace on either side of the title.
325
+ #
326
+ # @example
327
+ # title = 'Truncated!'
328
+ # width = 20
329
+ # # => 'Truncated!'
330
+ #
331
+ # width = 10
332
+ # # => 'Trunca'
333
+ #
334
+ # @return [String]
335
+ def truncated_title
336
+ title.chomp.slice(0..(width - 5))
337
+ end
338
+
339
+ # Return boolean indicating whether this border has a non-empty title.
340
+ #
341
+ # @return [Boolean]
342
+ def title?
343
+ defined_value?(title)
344
+ end
345
+
291
346
  # @param value [String]
292
347
  # @param type [Symbol|NilClass]
293
348
  # @param iy [Fixnum]
294
349
  # @param ix [Fixnum]
295
350
  # @return [Vedeu::Char]
296
351
  def border(value, type = :border, iy = 0, ix = 0)
297
- Vedeu::Char.new({ value: value,
298
- parent: interface,
299
- colour: colour,
300
- style: style,
301
- position: position(type, iy, ix),
302
- border: type })
352
+ Vedeu::Char.new(value: value,
353
+ parent: interface,
354
+ colour: colour,
355
+ style: style,
356
+ position: position(type, iy, ix),
357
+ border: type)
358
+ end
359
+
360
+ # @return [Vedeu::Geometry]
361
+ def geometry
362
+ # @geometry ||= Vedeu.geometry.find(name)
363
+ interface.geometry
303
364
  end
304
365
 
305
366
  # @return [Vedeu::Interface]
@@ -335,11 +396,6 @@ module Vedeu
335
396
  }
336
397
  end
337
398
 
338
- # @return [Vedeu::Interface]
339
- def interface
340
- @interface ||= Vedeu.interfaces.find(name)
341
- end
342
-
343
399
  # @param name [Symbol]
344
400
  # @param iy [Fixnum]
345
401
  # @param ix [Fixnum]
@@ -347,24 +403,21 @@ module Vedeu
347
403
  def position(name, iy = 0, ix = 0)
348
404
  case name
349
405
  when :top_horizontal
350
- Vedeu::Position[interface.y, (bx + ix)]
406
+ Vedeu::Position[geometry.y, (bx + ix)]
351
407
 
352
408
  when :bottom_horizontal
353
- Vedeu::Position[interface.yn, (bx + ix)]
409
+ Vedeu::Position[geometry.yn, (bx + ix)]
354
410
 
355
411
  when :left_vertical
356
- Vedeu::Position[(by + iy), interface.x]
412
+ Vedeu::Position[(by + iy), geometry.x]
357
413
 
358
414
  when :right_vertical
359
- Vedeu::Position[(by + iy), interface.xn]
360
-
361
- when :bottom_left then interface.bottom_left
362
- when :bottom_right then interface.bottom_right
363
- when :top_left then interface.top_left
364
- when :top_right then interface.top_right
365
- else
366
- nil
415
+ Vedeu::Position[(by + iy), geometry.xn]
367
416
 
417
+ when :bottom_left then geometry.bottom_left
418
+ when :bottom_right then geometry.bottom_right
419
+ when :top_left then geometry.top_left
420
+ when :top_right then geometry.top_right
368
421
  end
369
422
  end
370
423
 
@@ -10,8 +10,14 @@ module Vedeu
10
10
  #
11
11
  # @return [Array|String]
12
12
  # @see #initialize
13
- def clear(interface)
14
- new(interface).write
13
+ def clear(interface, options = {})
14
+ if interface.visible?
15
+ new(interface, options).write
16
+
17
+ else
18
+ []
19
+
20
+ end
15
21
  end
16
22
  alias_method :render, :clear
17
23
 
@@ -20,9 +26,14 @@ module Vedeu
20
26
  # Return a new instance of Vedeu::Clear.
21
27
  #
22
28
  # @param interface [Interface]
29
+ # @param options [Hash]
30
+ # @option options clear_border [Boolean] see {#clear_border?}
31
+ # @option options use_terminal_colours [Boolean] see
32
+ # {#use_terminal_colours?}
23
33
  # @return [Vedeu::Clear]
24
- def initialize(interface)
34
+ def initialize(interface, options = {})
25
35
  @interface = interface
36
+ @options = options
26
37
  end
27
38
 
28
39
  # For each visible line of the interface, set the foreground and background
@@ -31,31 +42,36 @@ module Vedeu
31
42
  #
32
43
  # @return [Array<Array<Vedeu::Char>>]
33
44
  def clear
34
- @clear ||= Array.new(interface.border.height) do |iy|
35
- Array.new(interface.border.width) do |ix|
36
- Vedeu::Char.new({ value: ' ',
37
- colour: interface.colour,
45
+ if interface.visible?
46
+ Vedeu.log(type: :output, message: "Clearing: '#{interface.name}'")
47
+
48
+ @clear ||= Array.new(height) do |iy|
49
+ Array.new(width) do |ix|
50
+ Vedeu::Char.new(value: ' ',
51
+ colour: colour,
38
52
  style: interface.style,
39
- position: position(iy, ix) })
53
+ position: position(iy, ix))
54
+ end
40
55
  end
56
+ else
57
+ []
58
+
41
59
  end
42
60
  end
61
+ alias_method :render, :clear
62
+ alias_method :rendered, :clear
43
63
 
44
64
  # Clear the view and send to the terminal.
45
65
  #
46
66
  # @return [Array]
47
67
  def write
48
- Vedeu.log(type: :output, message: "Clearing: '#{interface.name}'")
49
-
50
68
  if Vedeu::Configuration.drb?
51
- Vedeu.trigger(:_drb_store_output_, clear)
69
+ Vedeu.trigger(:_drb_store_output_, rendered)
52
70
 
53
71
  Vedeu::HTMLRenderer.to_file(Vedeu::VirtualBuffer.retrieve)
54
72
  end
55
73
 
56
- # Vedeu::FileRenderer.render(clear)
57
-
58
- Vedeu::TerminalRenderer.render(clear)
74
+ Vedeu.renderers.render(rendered)
59
75
  end
60
76
 
61
77
  private
@@ -64,11 +80,80 @@ module Vedeu
64
80
  # @return [Interface]
65
81
  attr_reader :interface
66
82
 
83
+ # @return [Boolean] Indicates whether the area occupied by the border of the
84
+ # interface should be cleared also.
85
+ def clear_border?
86
+ options[:clear_border]
87
+ end
88
+
89
+ # @return [Vedeu::Colour] The default background and foreground colours for
90
+ # the terminal, or the colours of the interface.
91
+ def colour
92
+ if use_terminal_colours?
93
+ Colour.new(background: :default, foreground: :default)
94
+
95
+ else
96
+ interface.colour
97
+
98
+ end
99
+ end
100
+
101
+ # @return [Hash<Symbol => Boolean>]
102
+ def defaults
103
+ {
104
+ clear_border: true,
105
+ use_terminal_colours: true,
106
+ }
107
+ end
108
+
109
+ # Returns the height of the area to be cleared.
110
+ #
111
+ # @return [Fixnum]
112
+ def height
113
+ if clear_border?
114
+ interface.height
115
+
116
+ else
117
+ interface.border.height
118
+
119
+ end
120
+ end
121
+
122
+ # @return [Hash<Symbol => Boolean>]
123
+ def options
124
+ @_options ||= defaults.merge!(@options)
125
+ end
126
+
67
127
  # @param iy [Fixnum]
68
128
  # @param ix [Fixnum]
69
129
  # @return [Vedeu::IndexPosition]
70
130
  def position(iy, ix)
71
- Vedeu::IndexPosition[iy, ix, interface.border.by, interface.border.bx]
131
+ if clear_border?
132
+ Vedeu::IndexPosition[iy, ix, interface.y, interface.x]
133
+
134
+ else
135
+ Vedeu::IndexPosition[iy, ix, interface.border.by, interface.border.bx]
136
+
137
+ end
138
+ end
139
+
140
+ # @return [Boolean] Indicates whether the default terminal colours should be
141
+ # used to clear the area.
142
+ def use_terminal_colours?
143
+ options[:use_terminal_colours]
144
+ end
145
+
146
+ # Returns the width of the area to be cleared.
147
+ #
148
+ # @return [Fixnum]
149
+ def width
150
+ if clear_border?
151
+ interface.width
152
+
153
+ else
154
+ interface.border.width
155
+
156
+ end
72
157
  end
73
158
 
74
159
  end # Clear
@@ -1,15 +1,24 @@
1
- require 'vedeu/support/coercions'
2
-
3
1
  module Vedeu
4
2
 
5
3
  # Provides a container for terminal escape sequences controlling the
6
4
  # foreground and background colours of a character or collection of
7
5
  # characters.
8
6
  #
7
+ # Vedeu uses HTML/CSS style notation (i.e. '#aadd00'), they can be used at the
8
+ # stream level, the line level or for the whole interface. Terminals generally
9
+ # support either 8, 16 or 256 colours, with few supporting full 24-bit colour.
10
+ #
11
+ # Vedeu attempts to detect the colour depth using the `$TERM` environment
12
+ # variable.
13
+ #
14
+ # To set your `$TERM` variable to allow 256 colour support:
15
+ #
16
+ # ```bash
17
+ # echo "export TERM=xterm-256color" >> ~/.bashrc
18
+ # ```
19
+ #
9
20
  class Colour
10
21
 
11
- include Vedeu::Coercions
12
-
13
22
  # @!attribute [r] attributes
14
23
  # @return [Hash]
15
24
  attr_reader :attributes
@@ -22,6 +31,33 @@ module Vedeu
22
31
  # @return [Foreground|String]
23
32
  attr_reader :foreground
24
33
 
34
+ # @param value []
35
+ # @return [Object]
36
+ def self.coerce(value)
37
+ if value.nil?
38
+ new
39
+
40
+ elsif value.is_a?(self)
41
+ value
42
+
43
+ elsif value.is_a?(Hash)
44
+ if value.key?(:colour) && value[:colour].is_a?(self)
45
+ value
46
+
47
+ elsif value.key?(:background) || value.key?(:foreground)
48
+ new(value)
49
+
50
+ else
51
+ new
52
+
53
+ end
54
+
55
+ else
56
+ new(value)
57
+
58
+ end
59
+ end
60
+
25
61
  # Returns a new instance of Vedeu::Colour.
26
62
  #
27
63
  # @param attributes [Hash]
@@ -35,20 +71,28 @@ module Vedeu
35
71
  @foreground = Vedeu::Foreground.coerce(@attributes[:foreground])
36
72
  end
37
73
 
38
- # Converts the value into a Vedeu::Foreground.
74
+ # Converts the value into a Vedeu::Background.
39
75
  #
40
76
  # @param value [String]
41
77
  # @return [String]
42
- def foreground=(value)
43
- @foreground = Vedeu::Foreground.coerce(value)
78
+ def background=(value)
79
+ @background = Vedeu::Background.coerce(value)
44
80
  end
45
81
 
46
- # Converts the value into a Vedeu::Background.
82
+ # @param other [Vedeu::Char]
83
+ # @return [Boolean]
84
+ def eql?(other)
85
+ self.class == other.class && background == other.background &&
86
+ foreground == other.foreground
87
+ end
88
+ alias_method :==, :eql?
89
+
90
+ # Converts the value into a Vedeu::Foreground.
47
91
  #
48
92
  # @param value [String]
49
93
  # @return [String]
50
- def background=(value)
51
- @background = Vedeu::Background.coerce(value)
94
+ def foreground=(value)
95
+ @foreground = Vedeu::Foreground.coerce(value)
52
96
  end
53
97
 
54
98
  # Returns both or either of the converted attributes into a single escape
@@ -63,11 +107,11 @@ module Vedeu
63
107
 
64
108
  # The default values for a new instance of this class.
65
109
  #
66
- # @return [Hash<Symbol => String>]
110
+ # @return [Hash<Symbol => NilClass>]
67
111
  def defaults
68
112
  {
113
+ background: '',
69
114
  foreground: '',
70
- background: ''
71
115
  }
72
116
  end
73
117
 
@@ -0,0 +1,59 @@
1
+ module Vedeu
2
+
3
+ # During the conversion of a Vedeu::Char object into a string of escape
4
+ # sequences, this class removes multiple occurences of the same escape
5
+ # sequence, resulting in a smaller payload being sent to the renderer.
6
+ #
7
+ class Compressor
8
+
9
+ # @param output [Array<Array<Vedeu::Char>>]
10
+ # @return [Vedeu::Compressor]
11
+ def initialize(output)
12
+ @output = output
13
+ @colour = ''
14
+ @style = ''
15
+ end
16
+
17
+ # @return [String]
18
+ def render
19
+ Array(output).flatten.map do |char|
20
+ if char.is_a?(Vedeu::Char)
21
+ out = ''
22
+ out << char.position.to_s
23
+ out << colour_for(char)
24
+ out << style_for(char)
25
+ out << char.value
26
+ out
27
+
28
+ else
29
+ char.to_s
30
+
31
+ end
32
+ end.join
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :output
38
+
39
+ # @param char [Vedeu::Char]
40
+ # @return [String]
41
+ def colour_for(char)
42
+ return '' if char.colour == @colour
43
+
44
+ @colour = char.colour
45
+ @colour.to_s
46
+ end
47
+
48
+ # @param char [Vedeu::Char]
49
+ # @return [String]
50
+ def style_for(char)
51
+ return '' if char.style == @style
52
+
53
+ @style = char.style
54
+ @style.to_s
55
+ end
56
+
57
+ end # Compressor
58
+
59
+ end # Vedeu
@@ -102,14 +102,16 @@ module Vedeu
102
102
 
103
103
  # @return [String|NilClass]
104
104
  def parent_bg
105
- if char.parent_background && defined_value?(char.parent_background.to_html)
105
+ if char.parent_background &&
106
+ defined_value?(char.parent_background.to_html)
106
107
  char.parent_background.to_html
107
108
  end
108
109
  end
109
110
 
110
111
  # @return [String|NilClass]
111
112
  def parent_fg
112
- if char.parent_foreground && defined_value?(char.parent_foreground.to_html)
113
+ if char.parent_foreground &&
114
+ defined_value?(char.parent_foreground.to_html)
113
115
  char.parent_foreground.to_html
114
116
  end
115
117
  end
@@ -15,22 +15,27 @@ module Vedeu
15
15
 
16
16
  # @return [Fixnum]
17
17
  def bx
18
- interface.x
18
+ geometry.x
19
19
  end
20
20
 
21
21
  # @return [Fixnum]
22
22
  def bxn
23
- interface.xn
23
+ geometry.xn
24
24
  end
25
25
 
26
26
  # @return [Fixnum]
27
27
  def by
28
- interface.y
28
+ geometry.y
29
29
  end
30
30
 
31
31
  # @return [Fixnum]
32
32
  def byn
33
- interface.yn
33
+ geometry.yn
34
+ end
35
+
36
+ # @return [FalseClass]
37
+ def enabled?
38
+ false
34
39
  end
35
40
 
36
41
  # @return [Fixnum]
@@ -54,6 +59,13 @@ module Vedeu
54
59
  # @return [Vedeu::Interface]
55
60
  attr_reader :interface
56
61
 
62
+ # Returns the geometry for the interface.
63
+ #
64
+ # @return [Vedeu::Geometry]
65
+ def geometry
66
+ interface.geometry
67
+ end
68
+
57
69
  end # NullBorder
58
70
 
59
71
  end # Vedeu
@@ -1,54 +1,46 @@
1
1
  require 'vedeu/output/renderers/all'
2
2
  require 'vedeu/output/virtual_buffer'
3
- require 'vedeu/support/terminal'
4
3
 
5
4
  module Vedeu
6
5
 
7
- # Sends the interface to the terminal or output device.
6
+ # Sends the content to the renderers.
8
7
  #
9
8
  class Output
10
9
 
11
- # Writes content (the provided interface object with associated lines,
12
- # streams, colours and styles) to the area defined by the interface.
10
+ # Writes content to the defined renderers.
13
11
  #
14
12
  # @return [Array|String]
15
13
  # @see #initialize
16
- def self.render(interface)
17
- new(interface).render
14
+ def self.render(content)
15
+ new(content).render
18
16
  end
19
17
 
20
18
  # Return a new instance of Vedeu::Output.
21
19
  #
22
- # @param interface [Interface]
20
+ # @param content [Array<Array<Vedeu::Char>>]
23
21
  # @return [Output]
24
- def initialize(interface)
25
- @interface = interface
22
+ def initialize(content)
23
+ @content = content
26
24
  end
27
25
 
28
- # Send the view to the terminal.
26
+ # Send the view to the renderers.
29
27
  #
30
28
  # @return [Array]
31
29
  def render
32
30
  if Vedeu::Configuration.drb?
33
- Vedeu.trigger(:_drb_store_output_, rendered)
31
+ Vedeu.trigger(:_drb_store_output_, content)
34
32
 
35
33
  Vedeu::HTMLRenderer.to_file(Vedeu::VirtualBuffer.retrieve)
36
34
  end
37
35
 
38
- # Vedeu::FileRenderer.render(rendered)
39
-
40
- Vedeu::TerminalRenderer.render(rendered)
36
+ Vedeu.renderers.render(content)
41
37
  end
42
38
 
43
39
  private
44
40
 
45
- # @!attribute [r] interface
46
- # @return [Interface]
47
- attr_reader :interface
48
-
49
- def rendered
50
- @rendered ||= interface.render
51
- end
41
+ # @!attribute [r] content
42
+ # @return [Array<Array<Vedeu::Char>>]
43
+ attr_reader :content
52
44
 
53
45
  end # Output
54
46