vedeu 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +6 -0
  4. data/bin/vedeu_drb_client +8 -3
  5. data/bin/vedeu_drb_server +113 -0
  6. data/bin/vedeu_test +1 -1
  7. data/docs/events.md +0 -127
  8. data/examples/borders_app.rb +17 -7
  9. data/examples/configuration_app.rb +1 -1
  10. data/examples/cursor_app.rb +4 -2
  11. data/examples/drb_app.rb +113 -0
  12. data/examples/focus_app.rb +1 -1
  13. data/examples/geometry_app.rb +1 -1
  14. data/examples/hello_world.rb +1 -1
  15. data/examples/lines_app.rb +1 -1
  16. data/features/start_stop.feature +1 -1
  17. data/inch.yml +5 -0
  18. data/lib/vedeu/all.rb +2 -0
  19. data/lib/vedeu/api.rb +1 -0
  20. data/lib/vedeu/application.rb +17 -36
  21. data/lib/vedeu/bindings.rb +134 -27
  22. data/lib/vedeu/buffers/display_buffer.rb +1 -4
  23. data/lib/vedeu/configuration/api.rb +15 -14
  24. data/lib/vedeu/configuration/cli.rb +17 -16
  25. data/lib/vedeu/configuration/configuration.rb +3 -1
  26. data/lib/vedeu/cursor/cursor.rb +6 -8
  27. data/lib/vedeu/cursor/move_cursor.rb +1 -0
  28. data/lib/vedeu/cursor/toggle_cursor.rb +1 -0
  29. data/lib/vedeu/debug.rb +23 -0
  30. data/lib/vedeu/distributed/all.rb +1 -1
  31. data/lib/vedeu/distributed/client.rb +55 -13
  32. data/lib/vedeu/distributed/server.rb +207 -0
  33. data/lib/vedeu/distributed/subprocess.rb +22 -21
  34. data/lib/vedeu/distributed/templates/default_application.vedeu +3 -1
  35. data/lib/vedeu/distributed/test_application.rb +2 -1
  36. data/lib/vedeu/distributed/uri.rb +1 -0
  37. data/lib/vedeu/dsl/all.rb +4 -2
  38. data/lib/vedeu/dsl/components/border.rb +11 -10
  39. data/lib/vedeu/dsl/components/geometry.rb +1 -0
  40. data/lib/vedeu/dsl/components/keymap.rb +1 -0
  41. data/lib/vedeu/dsl/components/menu.rb +1 -0
  42. data/lib/vedeu/dsl/interface.rb +1 -0
  43. data/lib/vedeu/dsl/line.rb +3 -1
  44. data/lib/vedeu/dsl/shared/colour.rb +1 -0
  45. data/lib/vedeu/dsl/shared/style.rb +1 -0
  46. data/lib/vedeu/dsl/shared/text.rb +2 -0
  47. data/lib/vedeu/dsl/shared/use.rb +3 -0
  48. data/lib/vedeu/dsl/stream.rb +3 -1
  49. data/lib/vedeu/dsl/view.rb +1 -0
  50. data/lib/vedeu/events/event.rb +9 -6
  51. data/lib/vedeu/events/trigger.rb +18 -7
  52. data/lib/vedeu/exceptions.rb +4 -1
  53. data/lib/vedeu/input/input.rb +1 -0
  54. data/lib/vedeu/input/key.rb +0 -1
  55. data/lib/vedeu/input/keymap.rb +5 -3
  56. data/lib/vedeu/input/keys.rb +1 -0
  57. data/lib/vedeu/input/mapper.rb +1 -0
  58. data/lib/vedeu/launcher.rb +35 -12
  59. data/lib/vedeu/main_loop.rb +53 -0
  60. data/lib/vedeu/models/collection.rb +11 -3
  61. data/lib/vedeu/models/focus.rb +3 -3
  62. data/lib/vedeu/models/geometry.rb +8 -16
  63. data/lib/vedeu/models/group.rb +1 -0
  64. data/lib/vedeu/models/menu.rb +2 -1
  65. data/lib/vedeu/models/model.rb +7 -1
  66. data/lib/vedeu/models/view/char.rb +52 -44
  67. data/lib/vedeu/models/view/chars.rb +1 -0
  68. data/lib/vedeu/models/view/composition.rb +2 -1
  69. data/lib/vedeu/models/view/interface.rb +5 -3
  70. data/lib/vedeu/models/view/interfaces.rb +1 -0
  71. data/lib/vedeu/models/view/line.rb +2 -1
  72. data/lib/vedeu/models/view/stream.rb +2 -1
  73. data/lib/vedeu/models/view/streams.rb +1 -0
  74. data/lib/vedeu/output/all.rb +4 -0
  75. data/lib/vedeu/output/border.rb +75 -206
  76. data/lib/vedeu/output/compositor.rb +1 -0
  77. data/lib/vedeu/output/html_char.rb +119 -0
  78. data/lib/vedeu/output/html_renderer.rb +89 -0
  79. data/lib/vedeu/output/output.rb +48 -44
  80. data/lib/vedeu/output/position_index.rb +12 -1
  81. data/lib/vedeu/output/renderer.rb +28 -0
  82. data/lib/vedeu/output/viewport.rb +14 -14
  83. data/lib/vedeu/output/virtual_buffer.rb +56 -0
  84. data/lib/vedeu/output/virtual_terminal.rb +42 -34
  85. data/lib/vedeu/output/wordwrap.rb +3 -0
  86. data/lib/vedeu/output/writer.rb +13 -1
  87. data/lib/vedeu/presentation/background.rb +1 -0
  88. data/lib/vedeu/presentation/colour.rb +8 -7
  89. data/lib/vedeu/presentation/foreground.rb +1 -0
  90. data/lib/vedeu/presentation/presentation.rb +43 -7
  91. data/lib/vedeu/presentation/translator.rb +12 -0
  92. data/lib/vedeu/repositories/repository.rb +8 -8
  93. data/lib/vedeu/support/bounding_area.rb +2 -0
  94. data/lib/vedeu/support/coercions.rb +2 -1
  95. data/lib/vedeu/support/common.rb +1 -0
  96. data/lib/vedeu/support/console.rb +17 -23
  97. data/lib/vedeu/support/content_geometry.rb +2 -0
  98. data/lib/vedeu/support/coordinate.rb +1 -0
  99. data/lib/vedeu/support/esc.rb +58 -29
  100. data/lib/vedeu/support/grid.rb +1 -0
  101. data/lib/vedeu/support/limit.rb +9 -0
  102. data/lib/vedeu/support/log.rb +31 -9
  103. data/lib/vedeu/support/node.rb +8 -18
  104. data/lib/vedeu/support/position.rb +13 -34
  105. data/lib/vedeu/support/position_validator.rb +3 -0
  106. data/lib/vedeu/support/read.rb +1 -0
  107. data/lib/vedeu/support/refresh.rb +3 -2
  108. data/lib/vedeu/support/terminal.rb +11 -5
  109. data/lib/vedeu/support/trace.rb +16 -1
  110. data/lib/vedeu/support/visible.rb +2 -0
  111. data/lib/vedeu/support/write.rb +1 -0
  112. data/lib/vedeu/traps.rb +1 -0
  113. data/lib/vedeu.rb +2 -0
  114. data/test/integration/distributed_test.rb +10 -8
  115. data/test/lib/vedeu/api_test.rb +3 -7
  116. data/test/lib/vedeu/application_test.rb +2 -5
  117. data/test/lib/vedeu/configuration/api_test.rb +12 -0
  118. data/test/lib/vedeu/cursor/cursor_test.rb +2 -0
  119. data/test/lib/vedeu/distributed/client_test.rb +17 -7
  120. data/test/lib/vedeu/distributed/server_test.rb +56 -0
  121. data/test/lib/vedeu/distributed/test_application_test.rb +7 -3
  122. data/test/lib/vedeu/dsl/components/border_test.rb +10 -2
  123. data/test/lib/vedeu/dsl/interface_test.rb +6 -0
  124. data/test/lib/vedeu/dsl/line_test.rb +19 -0
  125. data/test/lib/vedeu/dsl/shared/colour_test.rb +4 -26
  126. data/test/lib/vedeu/dsl/shared/text_test.rb +8 -1
  127. data/test/lib/vedeu/dsl/stream_test.rb +13 -1
  128. data/test/lib/vedeu/input/input_test.rb +1 -1
  129. data/test/lib/vedeu/input/key_test.rb +3 -16
  130. data/test/lib/vedeu/launcher_test.rb +11 -1
  131. data/test/lib/vedeu/main_loop_test.rb +41 -0
  132. data/test/lib/vedeu/models/geometry_test.rb +15 -34
  133. data/test/lib/vedeu/models/view/char_test.rb +44 -45
  134. data/test/lib/vedeu/models/view/interface_test.rb +6 -0
  135. data/test/lib/vedeu/models/view/line_test.rb +1 -1
  136. data/test/lib/vedeu/models/view/stream_test.rb +1 -1
  137. data/test/lib/vedeu/output/border_test.rb +6 -5
  138. data/test/lib/vedeu/output/compositor_test.rb +2 -20
  139. data/test/lib/vedeu/output/html_char_test.rb +85 -0
  140. data/test/lib/vedeu/output/html_renderer_test.rb +37 -0
  141. data/test/lib/vedeu/output/position_index_test.rb +2 -10
  142. data/test/lib/vedeu/output/renderer_test.rb +24 -0
  143. data/test/lib/vedeu/output/virtual_buffer_test.rb +53 -0
  144. data/test/lib/vedeu/output/virtual_terminal_test.rb +32 -2
  145. data/test/lib/vedeu/presentation/background_test.rb +41 -1
  146. data/test/lib/vedeu/presentation/colour_test.rb +10 -6
  147. data/test/lib/vedeu/presentation/foreground_test.rb +46 -6
  148. data/test/lib/vedeu/presentation/presentation_test.rb +44 -1
  149. data/test/lib/vedeu/presentation/translator_test.rb +34 -0
  150. data/test/lib/vedeu/repositories/repository_test.rb +1 -1
  151. data/test/lib/vedeu/support/bounding_area_test.rb +4 -12
  152. data/test/lib/vedeu/support/console_test.rb +9 -50
  153. data/test/lib/vedeu/support/esc_test.rb +7 -7
  154. data/test/lib/vedeu/support/position_test.rb +42 -0
  155. data/test/lib/vedeu/support/terminal_test.rb +5 -20
  156. data/test/lib/vedeu/support/write_test.rb +42 -18
  157. data/test/support/helpers/all.rb +0 -1
  158. data/test/support/helpers/repository_test_module.rb +1 -0
  159. data/test/test_helper.rb +5 -2
  160. data/vedeu.gemspec +7 -5
  161. metadata +60 -14
  162. data/lib/vedeu/distributed/application.rb +0 -91
  163. data/test/lib/vedeu/distributed/application_test.rb +0 -24
  164. data/test/support/helpers/presentation.rb +0 -16
@@ -0,0 +1,119 @@
1
+ require 'vedeu/support/common'
2
+
3
+ module Vedeu
4
+
5
+ class HTMLChar
6
+
7
+ include Vedeu::Common
8
+
9
+ # @param char [Vedeu::Char]
10
+ # @return [String]
11
+ def self.render(char)
12
+ new(char).render
13
+ end
14
+
15
+ # @param char [Vedeu::Char]
16
+ # @return [Vedeu::HTMLChar]
17
+ def initialize(char)
18
+ @char = char
19
+ end
20
+
21
+ # @return [String]
22
+ def render
23
+ "<td#{td_style}>#{td_value}</td>"
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :char
29
+
30
+ # @return [String]
31
+ def td_style
32
+ return '' unless border || defined_value?(value)
33
+
34
+ " style='background:#{bg};color:#{fg};border:1px #{bg} solid;#{border_style}'"
35
+ end
36
+
37
+ # @return [String]
38
+ def td_value
39
+ return '&nbsp;' if border || !defined_value?(value)
40
+
41
+ value
42
+ end
43
+
44
+ # @return [String]
45
+ def border_style
46
+ case border
47
+ when nil then ''
48
+ when :top_horizontal then border_css('top')
49
+ when :left_vertical then border_css('left')
50
+ when :right_vertical then border_css('right')
51
+ when :bottom_horizontal then border_css('bottom')
52
+ when :top_left then [border_css('top'), border_css('left')].join
53
+ when :top_right then [border_css('top'), border_css('right')].join
54
+ when :bottom_left then [border_css('bottom'), border_css('left')].join
55
+ when :bottom_right then [border_css('bottom'), border_css('right')].join
56
+ when :horizontal then ''
57
+ when :vertical then ''
58
+ else
59
+ # ... should not get here
60
+ ''
61
+ end
62
+ end
63
+
64
+ # @return [String]
65
+ def border_css(direction = '')
66
+ "border-#{direction}:1px #{fg} solid;"
67
+ end
68
+
69
+ # @return [String]
70
+ def fg
71
+ @fg ||= colour_fg || parent_fg || '#222'
72
+ end
73
+
74
+ # @return [String]
75
+ def bg
76
+ @bg ||= colour_bg || parent_bg || '#000'
77
+ end
78
+
79
+ # @return [String|NilClass]
80
+ def colour_bg
81
+ if char.background && defined_value?(char.background.to_html)
82
+ char.background.to_html
83
+ end
84
+ end
85
+
86
+ # @return [String|NilClass]
87
+ def colour_fg
88
+ if char.foreground && defined_value?(char.foreground.to_html)
89
+ char.foreground.to_html
90
+ end
91
+ end
92
+
93
+ # @return [String|NilClass]
94
+ def parent_bg
95
+ if char.parent_background && defined_value?(char.parent_background.to_html)
96
+ char.parent_background.to_html
97
+ end
98
+ end
99
+
100
+ # @return [String|NilClass]
101
+ def parent_fg
102
+ if char.parent_foreground && defined_value?(char.parent_foreground.to_html)
103
+ char.parent_foreground.to_html
104
+ end
105
+ end
106
+
107
+ # @return [Symbol|NilClass]
108
+ def border
109
+ char.border
110
+ end
111
+
112
+ # @return [String]
113
+ def value
114
+ char.value
115
+ end
116
+
117
+ end # HTMLChar
118
+
119
+ end # Vedeu
@@ -0,0 +1,89 @@
1
+ module Vedeu
2
+
3
+ class HTMLRenderer
4
+
5
+ # @param output [Array<Array<Vedeu::Char>>]
6
+ # @return [String]
7
+ def self.render(output)
8
+ new(output).render
9
+ end
10
+
11
+ # @param output [Array<Array<Vedeu::Char>>]
12
+ # @return [Vedeu::HTMLRenderer]
13
+ def initialize(output)
14
+ @output = output
15
+ end
16
+
17
+ # @return [String]
18
+ def render
19
+ html_header + html_body + html_footer
20
+ end
21
+
22
+ # @param path [String]
23
+ # @return [String]
24
+ def to_file(path = file_path)
25
+ content = render
26
+
27
+ File.open(path, "w", 0644) { |file| file.write(content) }
28
+
29
+ content
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :output
35
+
36
+ # @return [String]
37
+ def html_body
38
+ out = ''
39
+ Array(output).each do |line|
40
+ out << "<tr>\n"
41
+ line.each do |char|
42
+ out << char.to_html
43
+ out << "\n"
44
+ end
45
+ out << "</tr>\n"
46
+ end
47
+ out
48
+ end
49
+
50
+ # @return [String]
51
+ def html_header
52
+ <<-HTML
53
+ <html>
54
+ <head>
55
+ <style type='text/css'>
56
+ body { background:#000; }
57
+ td { border:1px #171717 solid;
58
+ font-size:12px;
59
+ font-family:monospace;
60
+ height:18px;
61
+ margin:1px;
62
+ text-align:center;
63
+ vertical-align:center;
64
+ width:18px; }
65
+ </style>
66
+ </head>
67
+ <body>
68
+ <table>
69
+ HTML
70
+ end
71
+
72
+ # @return [String]
73
+ def html_footer
74
+ "</table></body></html>"
75
+ end
76
+
77
+ # @return [String]
78
+ def file_path
79
+ "/tmp/vedeu_html_#{timestamp}.html"
80
+ end
81
+
82
+ # return [Fixnum]
83
+ def timestamp
84
+ @timestamp ||= Time.now.to_i
85
+ end
86
+
87
+ end # HTMLRenderer
88
+
89
+ end # Vedeu
@@ -25,9 +25,11 @@ module Vedeu
25
25
  #
26
26
  # @return [Array]
27
27
  def render
28
- Vedeu.trigger(:_output_, virtual_view)
28
+ if Vedeu::Configuration.drb?
29
+ Vedeu.trigger(:_drb_store_output_, virtual_view)
30
+ end
29
31
 
30
- Terminal.output(view, interface.cursor.to_s)
32
+ Terminal.output(Renderer.render(virtual_view, interface.cursor))
31
33
  end
32
34
 
33
35
  private
@@ -38,66 +40,45 @@ module Vedeu
38
40
  # colours to those specified when the interface was defined, then starting
39
41
  # write space characters over the area which the interface occupies.
40
42
  #
41
- # @return [String]
42
- def clear
43
- Vedeu.log("Clearing view: '#{interface.name}'")
44
-
45
- interface.height.times.inject([interface.colour]) do |line, index|
46
- line << interface.origin(index) { ' ' * interface.width }
47
- end.join
48
- end
49
-
50
- # Produces a single string which contains all content and escape sequences
51
- # required to render this interface in the terminal window.
43
+ # @note
44
+ # omg!
52
45
  #
53
- # @return [String]
54
- def view
55
- out = [ clear ]
56
-
57
- Vedeu.log("Rendering view: '#{interface.name}'")
58
-
59
- viewport.each_with_index do |line, index|
60
- out << interface.origin(index)
61
- out << line.join
62
- end
63
-
64
- out.join
65
- end
66
-
67
- def viewport
68
- @_viewport ||= Vedeu::Viewport.new(interface).render
69
- end
70
-
71
- # omg!
46
+ # @return [Array<Array<Vedeu::Char>>]
72
47
  def virtual_clear
48
+ Vedeu.log(type: :output, message: "Clearing: '#{interface.name}'")
49
+
73
50
  out = []
74
- interface.height.times do |hi|
51
+ interface.height.times do |iy|
75
52
  row = []
76
- interface.width.times do |wi|
77
- v = interface.raw_origin(hi)
78
- pos = Vedeu::Position.new(v.first, (v.last + wi))
79
- row << Vedeu::Char.new(' ', nil, interface.colour, nil, pos)
53
+ interface.width.times do |ix|
54
+ row << char_builder(' ', iy, ix)
80
55
  end
81
56
  out << row
82
57
  end
83
58
  out
84
59
  end
85
60
 
86
- # omg!
61
+ # Builds up a virtual view; a grid of Vedeu::Char objects- each one holding
62
+ # one character along with its colour, style and position attributes.
63
+ #
64
+ # @note
65
+ # omg!
66
+ #
67
+ # @return [Array<Array<Vedeu::Char>>]
87
68
  def virtual_view
88
69
  out = [ virtual_clear ]
89
70
 
90
- viewport.each_with_index do |line, line_index|
71
+ Vedeu.log(type: :output, message: "Rendering: '#{interface.name}'")
72
+
73
+ viewport.each_with_index do |line, iy|
91
74
  row = []
92
- line.each_with_index do |char, char_index|
93
- v = interface.raw_origin(line_index)
94
- pos = Vedeu::Position.new(v.first, (v.last + char_index))
75
+ line.each_with_index do |char, ix|
95
76
  row << if char.is_a?(Vedeu::Char)
96
- char.position=(pos)
77
+ char.position = position(iy, ix)
97
78
  char
98
79
 
99
80
  else
100
- Vedeu::Char.new(char, nil, interface.colour, nil, pos)
81
+ char_builder(char, iy, ix)
101
82
 
102
83
  end
103
84
  end
@@ -106,6 +87,29 @@ module Vedeu
106
87
  out
107
88
  end
108
89
 
90
+ # @return [void]
91
+ def viewport
92
+ @_viewport ||= Vedeu::Viewport.new(interface).render
93
+ end
94
+
95
+ # @param iy [Fixnum]
96
+ # @param ix [Fixnum]
97
+ # @return [Vedeu::Position]
98
+ def position(iy, ix)
99
+ interface.origin(iy, ix)
100
+ end
101
+
102
+ # @param value [String]
103
+ # @param iy [Fixnum]
104
+ # @param ix [Fixnum]
105
+ # @return [Vedeu::Char]
106
+ def char_builder(value, iy, ix)
107
+ Vedeu::Char.new({ value: value,
108
+ colour: interface.colour,
109
+ style: interface.style,
110
+ position: position(iy, ix) })
111
+ end
112
+
109
113
  end # Output
110
114
 
111
115
  end # Vedeu
@@ -1,20 +1,31 @@
1
1
  module Vedeu
2
2
 
3
+ # Converts a position into an index for the terminal.
4
+ #
3
5
  class PositionIndex
4
6
 
5
- attr_reader :y, :x
7
+ attr_reader :y,
8
+ :x
9
+
6
10
  alias_method :first, :y
7
11
  alias_method :last, :x
8
12
 
13
+ # @param y [Fixnum]
14
+ # @param x [Fixnum]
15
+ # @return [Array]
9
16
  def self.[](y, x)
10
17
  new(y, x).[]
11
18
  end
12
19
 
20
+ # @param y [Fixnum]
21
+ # @param x [Fixnum]
22
+ # @return [Vedeu::PositionIndex]
13
23
  def initialize(y, x)
14
24
  @y = [(y - 1), 1].max
15
25
  @x = [(x - 1), 1].max
16
26
  end
17
27
 
28
+ # @return [Array]
18
29
  def []
19
30
  [y, x]
20
31
  end
@@ -0,0 +1,28 @@
1
+ module Vedeu
2
+
3
+ class Renderer
4
+
5
+ # @param output [Array<Array<Vedeu::Char>>]
6
+ # @return [String]
7
+ def self.render(*output)
8
+ new(*output).render
9
+ end
10
+
11
+ # @param output [Array<Array<Vedeu::Char>>]
12
+ # @return [Vedeu::Renderer]
13
+ def initialize(*output)
14
+ @output = output
15
+ end
16
+
17
+ # @return [String]
18
+ def render
19
+ Array(output).flatten.map(&:to_s).join
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :output
25
+
26
+ end # Renderer
27
+
28
+ end # Vedeu
@@ -114,18 +114,18 @@ module Vedeu
114
114
  end
115
115
  end
116
116
 
117
- # Using the current cursor's x position, return a range of visible lines.
117
+ # Using the current cursor's y position, return a range of visible lines.
118
118
  #
119
- # Scrolls the content horizontally when the stored cursor's x position for
120
- # the interface is outside of the visible area.
119
+ # Scrolls the content vertically when the stored cursor's y position for the
120
+ # interface is outside of the visible area.
121
121
  #
122
122
  # @note
123
- # [value, 0].max # this allows us to set a left that is greater
124
- # # than the content width.
123
+ # [value, 0].max # this allows us to set a top that is greater than
124
+ # # the content height.
125
125
  #
126
- # [[value, (content_width - width)].min, 0].max
126
+ # [[value, (content_height - height)].min, 0].max
127
127
  # # this does not allow us to have a position
128
- # # greater than the content width.
128
+ # # greater than the content height.
129
129
  #
130
130
  # @return [Range]
131
131
  def rows
@@ -140,18 +140,18 @@ module Vedeu
140
140
  top..(top + (height - 1))
141
141
  end
142
142
 
143
- # Using the current cursor's y position, return a range of visible columns.
143
+ # Using the current cursor's x position, return a range of visible columns.
144
144
  #
145
- # Scrolls the content vertically when the stored cursor's y position for the
146
- # interface is outside of the visible area.
145
+ # Scrolls the content horizontally when the stored cursor's x position for
146
+ # the interface is outside of the visible area.
147
147
  #
148
148
  # @note
149
- # [value, 0].max # this allows us to set a top that is greater than
150
- # # the content height.
149
+ # [value, 0].max # this allows us to set a left that is greater
150
+ # # than the content width.
151
151
  #
152
- # [[value, (content_height - height)].min, 0].max
152
+ # [[value, (content_width - width)].min, 0].max
153
153
  # # this does not allow us to have a position
154
- # # greater than the content height.
154
+ # # greater than the content width.
155
155
  #
156
156
  # @return [Range]
157
157
  def columns
@@ -0,0 +1,56 @@
1
+ module Vedeu
2
+
3
+ # Store and retrieve virtual terminals.
4
+ #
5
+ module VirtualBuffer
6
+
7
+ extend self
8
+
9
+ # Fetch the oldest stored virtual buffer first.
10
+ #
11
+ # @return [Array<Array<Vedeu::Char>>|NilClass]
12
+ def retrieve
13
+ storage.pop
14
+ end
15
+
16
+ # Store a new virtual buffer.
17
+ #
18
+ # @return [Array<Array<Vedeu::Char>>]
19
+ def store(data)
20
+ storage.unshift(data)
21
+ end
22
+
23
+ # Return the number of virtual buffers currently stored.
24
+ #
25
+ # @return [Fixnum]
26
+ def size
27
+ storage.size
28
+ end
29
+
30
+ # Destroy all virtual buffers currently stored.
31
+ #
32
+ # @return [Array]
33
+ def clear
34
+ @_storage = in_memory
35
+ end
36
+ alias_method :reset, :clear
37
+
38
+ private
39
+
40
+ # Access to the storage for this repository.
41
+ #
42
+ # @return [Array]
43
+ def storage
44
+ @_storage ||= in_memory
45
+ end
46
+
47
+ # Returns an empty collection ready for the storing of virtual buffers.
48
+ #
49
+ # @return [Array]
50
+ def in_memory
51
+ []
52
+ end
53
+
54
+ end # VirtualBuffer
55
+
56
+ end # Vedeu
@@ -1,52 +1,28 @@
1
1
  module Vedeu
2
2
 
3
- # class Cell < Struct.new(:value)
4
- # def initialize(value = [])
5
- # super
6
- # end
7
- # end
8
-
9
- # class Cells
10
- # attr_reader :size, :value
11
-
12
- # def initialize(size = 0, &block)
13
- # @size = size
14
- # @value = if block_given?
15
- # [instance_eval(&block)] * size
16
-
17
- # else
18
- # [Cell.new] * size
19
-
20
- # end
21
- # end
22
-
23
- # def [](index)
24
- # value[index] || self
25
- # end
26
-
27
- # private
28
-
29
- # attr_reader :size, :value
30
- # end
31
-
32
3
  class VirtualTerminal
33
4
 
5
+ attr_accessor :renderer
34
6
  attr_reader :cell_height, :cell_width, :height, :width
35
7
 
36
8
  # @param height [Fixnum]
37
9
  # @param width [Fixnum]
10
+ # @param renderer [Object|HTMLRenderer] An object responding to .render.
38
11
  # @return [Vedeu::VirtualTerminal]
39
- def initialize(height, width)
12
+ def initialize(height, width, renderer = HTMLRenderer)
40
13
  @cell_height, @cell_width = Vedeu::PositionIndex[height, width]
41
- @height = height
42
- @width = width
14
+ @height = height
15
+ @width = width
16
+ @renderer = renderer
43
17
  end
44
18
 
45
- # @return [Array<Vedeu::Char>]
19
+ # @return [Array<Array<Vedeu::Char>>]
46
20
  def cells
47
- Array.new(cell_height) { Array.new(cell_width) { Vedeu::Char.new } }
21
+ @cells ||= new_virtual_terminal
48
22
  end
49
23
 
24
+ # Read a single cell from the virtual terminal.
25
+ #
50
26
  # @param y [Fixnum]
51
27
  # @param x [Fixnum]
52
28
  # @return [Vedeu::Char]
@@ -59,6 +35,33 @@ module Vedeu
59
35
  cell
60
36
  end
61
37
 
38
+ # Write a collection of cells to the virtual terminal.
39
+ #
40
+ # @param data [Array<Array<Vedeu::Char>>]
41
+ # @return [Array<Array<Vedeu::Char>>]
42
+ def output(data)
43
+ Array(data).flatten.each do |char|
44
+ write(char.y, char.x, char) if char.is_a?(Vedeu::Char)
45
+ end
46
+
47
+ cells
48
+ end
49
+
50
+ # @return [void]
51
+ def render
52
+ renderer.render(cells)
53
+ end
54
+
55
+ # Removes all content from the virtual terminal; effectively clearing it.
56
+ #
57
+ # @return [Array<Array<Vedeu::Char>>]
58
+ def reset
59
+ @cells = new_virtual_terminal
60
+ end
61
+ alias_method :clear, :reset
62
+
63
+ # Write a single cell to the virtual terminal.
64
+ #
62
65
  # @param y [Fixnum]
63
66
  # @param x [Fixnum]
64
67
  # @param data [Vedeu::Char]
@@ -81,6 +84,11 @@ module Vedeu
81
84
  from[which] || []
82
85
  end
83
86
 
87
+ # @return [Array<Array<Vedeu::Char>>]
88
+ def new_virtual_terminal
89
+ Array.new(cell_height) { Array.new(cell_width) { Vedeu::Char.new } }
90
+ end
91
+
84
92
  end # VirtualTerminal
85
93
 
86
94
  end # Vedeu
@@ -99,6 +99,9 @@ module Vedeu
99
99
  text.split(/\n/)
100
100
  end
101
101
 
102
+ # @note
103
+ # This may be unused. (GL 2015-02-20)
104
+ #
102
105
  # @return [String]
103
106
  def output
104
107
  processed.reduce([]) do |output, line|
@@ -1,32 +1,44 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides access to all possible mechanisms to write content.
4
+ #
5
+ # @note
6
+ # Will be used to translate output into HTML, etc.
7
+ #
3
8
  class Writer
4
9
 
5
10
  attr_reader :writers
6
11
 
12
+ # @param args []
7
13
  # @return [Vedeu::Writer]
8
14
  def self.[](*args)
9
15
  new(args)
10
16
  end
11
17
 
18
+ # @param writers []
12
19
  # @return [Vedeu::Writer]
13
20
  def initialize(writers)
14
21
  @writers = writers
15
22
  end
16
23
 
24
+ # @param other []
25
+ # @return [Boolean]
17
26
  def ==(other)
18
27
  writers == other.writers
19
28
  end
20
29
 
30
+ # @param other []
21
31
  # @return [Vedeu::Writer]
22
32
  def +(other)
23
33
  Writer[*(writers + other.writers)]
24
34
  end
25
35
 
36
+ # @param stream []
37
+ # @return [Array]
26
38
  def write(stream)
27
39
  @writers.each { |writer| writer.write(stream) }
28
40
  end
29
41
 
30
- end # Consoles
42
+ end # Writer
31
43
 
32
44
  end # Vedeu
@@ -4,6 +4,7 @@ module Vedeu
4
4
  # {Vedeu::Foreground}) of a terminal colour escape sequence.
5
5
  #
6
6
  # @api private
7
+ #
7
8
  class Background < Translator
8
9
 
9
10
  private