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
@@ -12,7 +12,16 @@ module Vedeu
12
12
 
13
13
  # @return [Vedeu::Colour]
14
14
  def colour
15
- @colour ||= Vedeu::Colour.coerce(@colour)
15
+ if @colour
16
+ @colour ||= Vedeu::Colour.coerce(@colour)
17
+
18
+ elsif parent && parent.colour
19
+ @colour ||= Vedeu::Colour.coerce(parent.colour)
20
+
21
+ else
22
+ Vedeu::Colour.coerce(nil)
23
+
24
+ end
16
25
  end
17
26
 
18
27
  # @return [Vedeu::Colour]
@@ -47,7 +56,16 @@ module Vedeu
47
56
 
48
57
  # @return [Vedeu::Style]
49
58
  def style
50
- @style ||= Vedeu::Style.coerce(@style)
59
+ if @style
60
+ @style ||= Vedeu::Style.coerce(@style)
61
+
62
+ elsif parent && parent.style
63
+ @style ||= Vedeu::Style.coerce(parent.style)
64
+
65
+ else
66
+ Vedeu::Style.coerce(nil)
67
+
68
+ end
51
69
  end
52
70
 
53
71
  # @return [Vedeu::Style]
@@ -61,34 +79,22 @@ module Vedeu
61
79
  #
62
80
  # @return [String] An escape sequence with value interpolated.
63
81
  def to_s
64
- render_position { render_colour { render_style { render_border { value } } } }
82
+ render_position { render_colour { render_style { value } } }
65
83
  end
66
84
 
67
85
  private
68
86
 
69
- # @return [String]
70
- def render_border
71
- if self.respond_to?(:border) && !border.nil?
72
- Vedeu::Esc.border { yield }
73
-
74
- else
75
- yield
76
-
77
- end
78
- end
79
-
80
- # Renders the colour attributes of the receiver, yields (to then render the
81
- # the styles) and once returned, attempts to set the colours back to the
82
- # those of the receiver's parent.
87
+ # Renders the colour attributes of the receiver and yields (to then render
88
+ # the styles).
83
89
  #
84
90
  # @return [String]
85
91
  def render_colour
86
- [colour, yield, parent_colour].join
92
+ [colour, yield].join
87
93
  end
88
94
 
89
95
  # @return [String]
90
96
  def render_position
91
- if self.respond_to?(:position) && self.position.is_a?(Vedeu::Position)
97
+ if self.respond_to?(:position) && position.is_a?(Vedeu::Position)
92
98
  position.to_s { yield }
93
99
 
94
100
  else
@@ -97,13 +103,12 @@ module Vedeu
97
103
  end
98
104
  end
99
105
 
100
- # Renders the style attributes of the receiver, yields (to then render the
101
- # next model, or finally, the content) and once returned, attempts to set
102
- # the style back to that of the receiver's parent.
106
+ # Renders the style attributes of the receiver and yields (to then render
107
+ # the next model, or finally, the content).
103
108
  #
104
109
  # @return [String]
105
110
  def render_style
106
- [style, yield, parent_style].join
111
+ [style, yield].join
107
112
  end
108
113
 
109
114
  end # Presentation
@@ -28,7 +28,7 @@ module Vedeu
28
28
  def by_group(group_name)
29
29
  Vedeu.log(type: :info, message: "Refreshing group: '#{group_name}'")
30
30
 
31
- Vedeu.groups.find(group_name).members.each { |name| by_name(name) }
31
+ Vedeu.groups.find!(group_name).members.each { |name| by_name(name) }
32
32
  end
33
33
 
34
34
  # Refresh an interface by name.
@@ -39,7 +39,7 @@ module Vedeu
39
39
  def by_name(name)
40
40
  Vedeu.log(type: :info, message: "Refreshing interface: '#{name}'")
41
41
 
42
- Vedeu::Compositor.compose(name)
42
+ Vedeu.buffers.render(name)
43
43
  end
44
44
 
45
45
  end # Refresh
@@ -1,3 +1,80 @@
1
- require 'vedeu/output/renderers/file_renderer'
2
- require 'vedeu/output/renderers/html_renderer'
3
- require 'vedeu/output/renderers/terminal_renderer'
1
+ require_relative 'file_renderer'
2
+ require_relative 'html_renderer'
3
+ require_relative 'json_renderer'
4
+ require_relative 'null_renderer'
5
+ require_relative 'terminal_renderer'
6
+
7
+ module Vedeu
8
+
9
+ # Provides a single interface to all registered renderers.
10
+ #
11
+ module Renderers
12
+
13
+ extend Enumerable
14
+ extend self
15
+
16
+ # Provides access to the list of renderers.
17
+ #
18
+ # @return [Module]
19
+ def renderers
20
+ self
21
+ end
22
+
23
+ # @return [Array<void>]
24
+ def render(*args)
25
+ # acc = []
26
+ threads = storage.map do |renderer|
27
+ Thread.new(renderer) do
28
+ mutex.synchronize do
29
+ Vedeu.log(type: :debug,
30
+ message: "Sending to renderer: '#{renderer}'")
31
+ # acc << renderer.render(*args)
32
+ renderer.render(*args)
33
+ end
34
+ end
35
+ end
36
+ threads.each(&:join)
37
+ # acc
38
+
39
+ # storage.inject([]) do |acc, renderer|
40
+ # acc << renderer.render(*args)
41
+ # acc
42
+ # end
43
+ end
44
+
45
+ # Adds the given renderer class(es) to the list of renderers.
46
+ #
47
+ # @example
48
+ # Vedeu.renderer SomeRenderer
49
+ #
50
+ # @note
51
+ # A renderer class must respond to the '.render' class method.
52
+ #
53
+ # @param renderers [Class]
54
+ # @return [Set]
55
+ def renderer(*renderers)
56
+ renderers.each { |renderer| storage.add(renderer) unless renderer.nil? }
57
+
58
+ storage
59
+ end
60
+
61
+ # @return [Set]
62
+ def reset
63
+ @storage = Set.new
64
+ end
65
+
66
+ # @return [Set]
67
+ def storage
68
+ @storage ||= reset
69
+ end
70
+
71
+ private
72
+
73
+ # @return [Mutex]
74
+ def mutex
75
+ @mutex ||= Mutex.new
76
+ end
77
+
78
+ end # Renderers
79
+
80
+ end # Vedeu
@@ -18,11 +18,12 @@ module Vedeu
18
18
  # @return [Vedeu::FileRenderer]
19
19
  def initialize(*output)
20
20
  @output = output
21
+ @options = {}
21
22
  end
22
23
 
23
24
  # @return [String]
24
25
  def render
25
- File.open("/tmp/out_#{Time.now.to_f}", 'w') { |f| f.write(parsed) }
26
+ File.open("/tmp/#{filename}", 'w') { |f| f.write(parsed) }
26
27
  end
27
28
 
28
29
  private
@@ -31,9 +32,44 @@ module Vedeu
31
32
  # @return [Array<Array<Vedeu::Char>>]
32
33
  attr_reader :output
33
34
 
35
+ # @return [String]
36
+ def filename
37
+ if timestamp?
38
+ "out_#{timestamp}"
39
+
40
+ else
41
+ 'out'
42
+
43
+ end
44
+ end
45
+
34
46
  # @return [String]
35
47
  def parsed
36
- Array(output).flatten.map(&:to_s).join
48
+ Vedeu::Compressor.new(output).render
49
+ end
50
+
51
+ # @return [Float]
52
+ def timestamp
53
+ Time.now.to_f
54
+ end
55
+
56
+ # @return [Boolean]
57
+ def timestamp?
58
+ return true if options[:timestamp]
59
+
60
+ false
61
+ end
62
+
63
+ # @return [Hash]
64
+ def options
65
+ defaults.merge!(@options)
66
+ end
67
+
68
+ # @return [Hash]
69
+ def defaults
70
+ {
71
+ timestamp: false,
72
+ }
37
73
  end
38
74
 
39
75
  end # FileRenderer
@@ -7,7 +7,7 @@ module Vedeu
7
7
  # @param output [Array<Array<Vedeu::Char>>]
8
8
  # @return [String]
9
9
  def self.render(output)
10
- new(output).render
10
+ new(output).to_file
11
11
  end
12
12
 
13
13
  # @param output [Array<Array<Vedeu::Char>>]
@@ -38,7 +38,7 @@ module Vedeu
38
38
  def to_file(path = file_path)
39
39
  content = render
40
40
 
41
- File.open(path, "w", 0644) { |file| file.write(content) }
41
+ File.open(path, 'w', 0644) { |file| file.write(content) }
42
42
 
43
43
  content
44
44
  end
@@ -49,8 +49,10 @@ module Vedeu
49
49
  Array(output).each do |line|
50
50
  out << "<tr>\n"
51
51
  line.each do |char|
52
- out << char.to_html
53
- out << "\n"
52
+ if char.is_a?(Vedeu::Char)
53
+ out << char.to_html
54
+ out << "\n"
55
+ end
54
56
  end
55
57
  out << "</tr>\n"
56
58
  end
@@ -0,0 +1,52 @@
1
+ module Vedeu
2
+
3
+ # Renders a {Vedeu::VirtualBuffer} or {Vedeu::Output} as JSON.
4
+ #
5
+ class JSONRenderer
6
+
7
+ # @param output [Array<Array<Vedeu::Char>>]
8
+ # @return [String]
9
+ def self.render(output)
10
+ new(output).render
11
+ end
12
+
13
+ # @param output [Array<Array<Vedeu::Char>>]
14
+ # @param path [String]
15
+ # @return [String]
16
+ # def self.to_file(output, path = nil)
17
+ # new(output).to_file(path)
18
+ # end
19
+
20
+ # Returns a new instance of Vedeu::JSONRenderer.
21
+ #
22
+ # @param output [Array<Array<Vedeu::Char>>]
23
+ # @return [Vedeu::JSONRenderer]
24
+ def initialize(output)
25
+ @output = output
26
+ end
27
+
28
+ # @return [String]
29
+ def render
30
+ return '' if output.nil? || output.empty?
31
+
32
+ out = ''
33
+ Array(output).each do |line|
34
+ out << ''
35
+ line.each do |char|
36
+ out << char.to_json
37
+ out << "\n"
38
+ end
39
+ out << "\n"
40
+ end
41
+ out
42
+ end
43
+
44
+ private
45
+
46
+ # @!attribute [r] output
47
+ # @return [Array<Array<Vedeu::Char>>]
48
+ attr_reader :output
49
+
50
+ end # JSONRenderer
51
+
52
+ end # Vedeu
@@ -0,0 +1,14 @@
1
+ module Vedeu
2
+
3
+ # A renderer which returns nothing.
4
+ #
5
+ class NullRenderer
6
+
7
+ # @return [NilClass]
8
+ def self.render(*)
9
+ nil
10
+ end
11
+
12
+ end # NullRenderer
13
+
14
+ end # Vedeu
@@ -21,7 +21,7 @@ module Vedeu
21
21
 
22
22
  # @return [Array<String>]
23
23
  def render
24
- Vedeu::Terminal.output(hide_cursor, parsed, show_cursor)
24
+ Vedeu::Terminal.output(parsed)
25
25
  end
26
26
 
27
27
  private
@@ -30,19 +30,9 @@ module Vedeu
30
30
  # @return [Array<Array<Vedeu::Char>>]
31
31
  attr_reader :output
32
32
 
33
- # @return [String]
34
- def show_cursor
35
- Vedeu::Esc.string(:show_cursor)
36
- end
37
-
38
33
  # @return [String]
39
34
  def parsed
40
- output.flatten.map(&:to_s).join
41
- end
42
-
43
- # @return [String]
44
- def hide_cursor
45
- Vedeu::Esc.string(:hide_cursor)
35
+ Vedeu::Compressor.new(output).render
46
36
  end
47
37
 
48
38
  end # TerminalRenderer
@@ -1,20 +1,43 @@
1
1
  require 'vedeu/support/common'
2
- require 'vedeu/support/coercions'
3
2
 
4
3
  module Vedeu
5
4
 
6
5
  # Converts the style value or value collection into a terminal escape
7
6
  # sequence. Unrecognised values are discarded- an empty string is returned.
8
7
  #
8
+ # Vedeu has a range of symbol styles which are compatible with most terminals
9
+ # which are ANSI compatible. Like colours, they can be defined in either
10
+ # interfaces, for specific lines or within streams.
11
+ # Styles are applied as encountered.
12
+ #
13
+ # @see Vedeu::Esc
14
+ #
9
15
  class Style
10
16
 
11
17
  include Vedeu::Common
12
- include Vedeu::Coercions
13
18
 
14
19
  # @!attribute [rw] value
15
20
  # @return [String|Symbol]
16
21
  attr_accessor :value
17
22
 
23
+ # Produces new objects of the correct class from the value, ignores objects
24
+ # that have already been coerced.
25
+ #
26
+ # @param value [Object|NilClass]
27
+ # @return [Object]
28
+ def self.coerce(value)
29
+ if value.nil?
30
+ new
31
+
32
+ elsif value.is_a?(self)
33
+ value
34
+
35
+ else
36
+ new(value)
37
+
38
+ end
39
+ end
40
+
18
41
  # Return a new instance of Vedeu::Style.
19
42
  #
20
43
  # @param value [Array<String|Symbol>|String|Symbol]
@@ -29,10 +52,17 @@ module Vedeu
29
52
  # @return [Array<String|Symbol>|String|Symbol]
30
53
  def attributes
31
54
  {
32
- style: value
55
+ style: value,
33
56
  }
34
57
  end
35
58
 
59
+ # @param other [Vedeu::Char]
60
+ # @return [Boolean]
61
+ def eql?(other)
62
+ self.class == other.class && value == other.value
63
+ end
64
+ alias_method :==, :eql?
65
+
36
66
  # Return the terminal escape sequences after converting the style or styles.
37
67
  #
38
68
  # @return [String]
@@ -4,6 +4,11 @@ module Vedeu
4
4
  #
5
5
  class Text
6
6
 
7
+ # @see Vedeu::DSL::Text#text
8
+ def self.add(value = '', options = {})
9
+ new(value, options).add
10
+ end
11
+
7
12
  # @see Vedeu::DSL::Text#text
8
13
  def self.with(value = '', options = {})
9
14
  new(value, options).aligned
@@ -13,9 +18,13 @@ module Vedeu
13
18
  #
14
19
  # @param value [String]
15
20
  # @param options [Hash]
16
- # @option options width [Integer]
17
21
  # @option options anchor [Symbol] See {Text#anchor}
22
+ # @option options background [String]
23
+ # @option options colour [Hash|NilClass]
24
+ # @option options foreground [String]
25
+ # @option options model [Vedeu::Interface|Vedeu::Line|Vedeu::Stream]
18
26
  # @option options pad [String]
27
+ # @option options width [Integer]
19
28
  # @return [Text]
20
29
  def initialize(value = '', options = {})
21
30
  @value = value
@@ -39,6 +48,13 @@ module Vedeu
39
48
  end
40
49
  end
41
50
 
51
+ # Adds the content to the model.
52
+ #
53
+ # @return [void]
54
+ def add
55
+ model.add(content)
56
+ end
57
+
42
58
  private
43
59
 
44
60
  # @!attribute [r] value
@@ -61,12 +77,57 @@ module Vedeu
61
77
  string.center(width, pad)
62
78
  end
63
79
 
80
+ # If a colour, background or foreground option is set, use them as the
81
+ # colour settings for the new Vedeu::Stream.
82
+ #
83
+ # @return [void]
84
+ def colour
85
+ if options[:colour] || options[:background] || options[:foreground]
86
+ attrs = if options[:colour] && options[:colour].is_a?(Hash)
87
+ options[:colour]
88
+
89
+ elsif options[:background] || options[:foreground]
90
+ {
91
+ background: options[:background],
92
+ foreground: options[:foreground],
93
+ }
94
+
95
+ else
96
+ {}
97
+
98
+ end
99
+
100
+ Vedeu::Colour.coerce(attrs)
101
+
102
+ else
103
+ model.colour
104
+
105
+ end
106
+ end
107
+
108
+ # Returns either a Vedeu::Line or Vedeu::Stream containing the text value.
109
+ #
110
+ # @return [Vedeu::Line|Vedeu::Stream]
111
+ def content
112
+ if model.is_a?(Vedeu::Interface)
113
+ stream.parent = line
114
+ line.add(stream)
115
+ line
116
+
117
+ else
118
+ stream
119
+
120
+ end
121
+ end
122
+
64
123
  # The default values for a new instance of this class.
65
124
  #
66
125
  # @return [Hash<Symbol => NilClass, String, Symbol>]
67
126
  def defaults
68
127
  {
69
128
  anchor: :left,
129
+ colour: nil,
130
+ model: nil,
70
131
  pad: ' ',
71
132
  width: nil,
72
133
  }
@@ -79,6 +140,18 @@ module Vedeu
79
140
  string.ljust(width, pad)
80
141
  end
81
142
 
143
+ # @return [Vedeu::Line]
144
+ def line
145
+ @line ||= Vedeu::Line.build(parent: parent)
146
+ end
147
+
148
+ # Returns the model option if set.
149
+ #
150
+ # @return [Vedeu::Interface|Vedeu::Line|Vedeu::Null|Vedeu::Stream]
151
+ def model
152
+ @model ||= options[:model] || Vedeu::Null.new
153
+ end
154
+
82
155
  # The character to use for padding the string.
83
156
  #
84
157
  # @return [String]
@@ -86,6 +159,13 @@ module Vedeu
86
159
  options[:pad]
87
160
  end
88
161
 
162
+ # Returns the parent for the new Vedeu::Stream.
163
+ #
164
+ # @return [void]
165
+ def parent
166
+ model.is_a?(Vedeu::Stream) ? model.parent : model
167
+ end
168
+
89
169
  # The string padded to width, right justified.
90
170
  #
91
171
  # @return [String]
@@ -93,6 +173,16 @@ module Vedeu
93
173
  string.rjust(width, pad)
94
174
  end
95
175
 
176
+ # Builds and returns a new Vedeu::Stream.
177
+ #
178
+ # @return [void]
179
+ def stream
180
+ @stream ||= Vedeu::Stream.build(colour: colour,
181
+ parent: parent,
182
+ style: style,
183
+ value: aligned)
184
+ end
185
+
96
186
  # The string, coerced.
97
187
  #
98
188
  # @return [String]
@@ -100,6 +190,13 @@ module Vedeu
100
190
  value.to_s
101
191
  end
102
192
 
193
+ # Returns the model's styles.
194
+ #
195
+ # @return [void]
196
+ def style
197
+ model.style
198
+ end
199
+
103
200
  # Return a boolean indicating that the string is greater than the width.
104
201
  #
105
202
  # @return [Boolean]
@@ -1,5 +1,3 @@
1
- require 'vedeu/support/coercions'
2
-
3
1
  module Vedeu
4
2
 
5
3
  # Convert a CSS/HTML colour string into a terminal escape sequence.
@@ -23,13 +21,29 @@ module Vedeu
23
21
  # @todo More documentation required (create a fancy chart!)
24
22
  class Translator
25
23
 
26
- include Vedeu::Coercions
27
-
28
24
  # @!attribute [r] colour
29
25
  # @return [String]
30
26
  attr_reader :colour
31
27
  alias_method :value, :colour
32
28
 
29
+ # Produces new objects of the correct class from the value, ignores objects
30
+ # that have already been coerced.
31
+ #
32
+ # @param value [Object|NilClass]
33
+ # @return [Object]
34
+ def self.coerce(value)
35
+ if value.nil?
36
+ new
37
+
38
+ elsif value.is_a?(self)
39
+ value
40
+
41
+ else
42
+ new(value)
43
+
44
+ end
45
+ end
46
+
33
47
  # Convert a CSS/HTML colour string into a terminal escape sequence.
34
48
  #
35
49
  # @param colour [Fixnum|String|Symbol]
@@ -46,6 +60,13 @@ module Vedeu
46
60
  @colour = colour
47
61
  end
48
62
 
63
+ # @param other [Vedeu::Char]
64
+ # @return [Boolean]
65
+ def eql?(other)
66
+ self.class == other.class && colour == other.colour
67
+ end
68
+ alias_method :==, :eql?
69
+
49
70
  # @return [String]
50
71
  # @see Vedeu::Translator
51
72
  def escape_sequence
@@ -147,7 +168,9 @@ module Vedeu
147
168
  #
148
169
  # @return [Boolean]
149
170
  def rgb?
150
- !!(colour =~ /^#([A-Fa-f0-9]{6})$/)
171
+ return true if colour =~ /^#([A-Fa-f0-9]{6})$/
172
+
173
+ false
151
174
  end
152
175
 
153
176
  # Returns an escape sequence.
@@ -155,7 +178,7 @@ module Vedeu
155
178
  # @return [String]
156
179
  def rgb
157
180
  if Vedeu::Configuration.colour_mode == 16_777_216
158
- register(colour, sprintf(rgb_prefix, *css_to_rgb))
181
+ register(colour, format(rgb_prefix, *css_to_rgb))
159
182
 
160
183
  else
161
184
  numbered
@@ -183,7 +206,7 @@ module Vedeu
183
206
  [
184
207
  colour[1..2].to_i(16),
185
208
  colour[3..4].to_i(16),
186
- colour[5..6].to_i(16)
209
+ colour[5..6].to_i(16),
187
210
  ]
188
211
  end
189
212