vedeu 0.6.60 → 0.6.61

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/docs/dsl.md +18 -18
  3. data/docs/events/drb.md +2 -8
  4. data/docs/events/view.md +2 -2
  5. data/docs/events/visibility.md +1 -4
  6. data/lib/vedeu/all.rb +1 -1
  7. data/lib/vedeu/borders/border.rb +1 -1
  8. data/lib/vedeu/borders/refresh.rb +1 -1
  9. data/lib/vedeu/buffers/empty.rb +6 -4
  10. data/lib/vedeu/buffers/view.rb +78 -7
  11. data/lib/vedeu/cursors/cursor.rb +7 -5
  12. data/lib/vedeu/cursors/refresh.rb +1 -1
  13. data/lib/vedeu/cursors/reposition.rb +5 -3
  14. data/lib/vedeu/cursors/repository.rb +4 -6
  15. data/lib/vedeu/dsl/shared.rb +5 -5
  16. data/lib/vedeu/editor/cropper.rb +1 -1
  17. data/lib/vedeu/editor/cursor.rb +2 -2
  18. data/lib/vedeu/editor/item.rb +3 -3
  19. data/lib/vedeu/error.rb +1 -1
  20. data/lib/vedeu/esc/esc.rb +1 -1
  21. data/lib/vedeu/events/aliases.rb +2 -2
  22. data/lib/vedeu/{geometry → geometries}/alignment.rb +8 -8
  23. data/lib/vedeu/geometries/all.rb +31 -0
  24. data/lib/vedeu/{geometry → geometries}/area.rb +8 -8
  25. data/lib/vedeu/{geometry → geometries}/coordinate.rb +5 -5
  26. data/lib/vedeu/{geometry → geometries}/dimension.rb +6 -6
  27. data/lib/vedeu/{geometry → geometries}/dsl.rb +22 -22
  28. data/lib/vedeu/{geometry → geometries}/geometry.rb +15 -15
  29. data/lib/vedeu/{geometry → geometries}/grid.rb +6 -6
  30. data/lib/vedeu/{geometry → geometries}/horizontal_alignment.rb +3 -3
  31. data/lib/vedeu/{geometry → geometries}/move.rb +5 -5
  32. data/lib/vedeu/{geometry → geometries}/position.rb +18 -18
  33. data/lib/vedeu/{geometry → geometries}/repository.rb +9 -9
  34. data/lib/vedeu/{geometry → geometries}/validator.rb +3 -3
  35. data/lib/vedeu/{geometry → geometries}/vertical_alignment.rb +3 -3
  36. data/lib/vedeu/{geometry → geometries}/x_dimension.rb +4 -4
  37. data/lib/vedeu/{geometry → geometries}/y_dimension.rb +4 -4
  38. data/lib/vedeu/groups/group.rb +2 -1
  39. data/lib/vedeu/input/store.rb +2 -1
  40. data/lib/vedeu/interfaces/clear.rb +8 -6
  41. data/lib/vedeu/interfaces/interface.rb +1 -1
  42. data/lib/vedeu/models/cell.rb +2 -2
  43. data/lib/vedeu/models/escape.rb +2 -2
  44. data/lib/vedeu/models/focus.rb +2 -1
  45. data/lib/vedeu/models/page.rb +3 -2
  46. data/lib/vedeu/models/row.rb +10 -1
  47. data/lib/vedeu/models/views/char.rb +6 -6
  48. data/lib/vedeu/models/views/line.rb +1 -1
  49. data/lib/vedeu/output/compressor.rb +10 -15
  50. data/lib/vedeu/output/presentation/presentation.rb +1 -1
  51. data/lib/vedeu/output/renderers/all.rb +7 -8
  52. data/lib/vedeu/output/viewport.rb +1 -1
  53. data/lib/vedeu/repositories/store.rb +2 -2
  54. data/lib/vedeu/terminal/buffer.rb +46 -102
  55. data/lib/vedeu/terminal/terminal.rb +10 -2
  56. data/lib/vedeu/version.rb +1 -1
  57. data/test/lib/vedeu/borders/refresh_test.rb +1 -1
  58. data/test/lib/vedeu/buffers/empty_test.rb +3 -3
  59. data/test/lib/vedeu/buffers/view_test.rb +48 -1
  60. data/test/lib/vedeu/cursors/cursor_test.rb +2 -2
  61. data/test/lib/vedeu/editor/cropper_test.rb +1 -1
  62. data/test/lib/vedeu/editor/cursor_test.rb +1 -1
  63. data/test/lib/vedeu/editor/document_test.rb +2 -2
  64. data/test/lib/vedeu/{geometry → geometries}/alignment_test.rb +5 -5
  65. data/test/lib/vedeu/{geometry → geometries}/area_test.rb +4 -4
  66. data/test/lib/vedeu/{geometry → geometries}/coordinate.rb +5 -5
  67. data/test/lib/vedeu/{geometry → geometries}/dimension_test.rb +7 -5
  68. data/test/lib/vedeu/{geometry → geometries}/dsl_test.rb +31 -27
  69. data/test/lib/vedeu/{geometry → geometries}/geometry_test.rb +10 -7
  70. data/test/lib/vedeu/{geometry → geometries}/grid_test.rb +13 -9
  71. data/test/lib/vedeu/{geometry → geometries}/horizontal_alignment_test.rb +3 -3
  72. data/test/lib/vedeu/{geometry → geometries}/move_test.rb +10 -10
  73. data/test/lib/vedeu/{geometry → geometries}/position_test.rb +16 -15
  74. data/test/lib/vedeu/{geometry → geometries}/repository_test.rb +3 -3
  75. data/test/lib/vedeu/{geometry → geometries}/validator_test.rb +4 -4
  76. data/test/lib/vedeu/{geometry → geometries}/vertical_alignment_test.rb +3 -3
  77. data/test/lib/vedeu/{geometry → geometries}/x_dimension_test.rb +3 -3
  78. data/test/lib/vedeu/{geometry → geometries}/y_dimension_test.rb +3 -3
  79. data/test/lib/vedeu/interfaces/clear_test.rb +1 -1
  80. data/test/lib/vedeu/models/cell_test.rb +1 -1
  81. data/test/lib/vedeu/models/escape_test.rb +2 -2
  82. data/test/lib/vedeu/models/page_test.rb +18 -2
  83. data/test/lib/vedeu/models/views/char_test.rb +3 -3
  84. data/test/lib/vedeu/output/compressor_test.rb +30 -16
  85. data/test/lib/vedeu/output/renderers/html_test.rb +1 -1
  86. data/test/lib/vedeu/output/renderers/json_test.rb +17 -1
  87. data/test/lib/vedeu/output/viewport_test.rb +1 -1
  88. data/test/lib/vedeu/terminal/buffer_test.rb +6 -18
  89. data/test/lib/vedeu/terminal/terminal_test.rb +1 -1
  90. data/test/support/examples/material_colours_app.rb +2 -0
  91. data/test/test_helper.rb +1 -1
  92. metadata +48 -48
  93. data/lib/vedeu/geometry/all.rb +0 -31
@@ -16,7 +16,7 @@ module Vedeu
16
16
  #
17
17
  # @param attributes [String]
18
18
  # @option attributes position
19
- # [Vedeu::Geometry::Position|Array<Fixnum>]
19
+ # [Vedeu::Geometries::Position|Array<Fixnum>]
20
20
  # @option attributes value [String]
21
21
  # @return [Vedeu::Models::Escape]
22
22
  def initialize(attributes = {})
@@ -50,7 +50,7 @@ module Vedeu
50
50
 
51
51
  # @return [String]
52
52
  def position
53
- Vedeu::Geometry::Position.coerce(@position)
53
+ Vedeu::Geometries::Position.coerce(@position)
54
54
  end
55
55
 
56
56
  # Return an empty hash as most escape sequences won't make
@@ -193,9 +193,10 @@ module Vedeu
193
193
  # Reset the repository.
194
194
  #
195
195
  # @return [Array|Hash|Set]
196
- def reset
196
+ def reset!
197
197
  @storage = in_memory
198
198
  end
199
+ alias_method :reset, :reset!
199
200
 
200
201
  private
201
202
 
@@ -25,14 +25,15 @@ module Vedeu
25
25
  elsif value.is_a?(Array) && value.empty?
26
26
  Vedeu::Models::Page.new([Vedeu::Models::Row.coerce(value)])
27
27
 
28
- elsif value.is_a?(Array)
28
+ elsif value.is_a?(Array) || value.is_a?(Vedeu::Buffers::View)
29
29
  values = value.map { |v| Vedeu::Models::Row.coerce(v) }
30
30
 
31
31
  Vedeu::Models::Page.new(values)
32
32
 
33
33
  else
34
34
  fail Vedeu::Error::InvalidSyntax,
35
- 'Cannot coerce as value is not an Array.'.freeze
35
+ 'Cannot coerce as value is not an Array, Vedeu::Models::Page ' \
36
+ "or Vedeu::Models::Row. Is a '#{value.class.name}'.".freeze
36
37
 
37
38
  end
38
39
  end
@@ -48,7 +48,7 @@ module Vedeu
48
48
 
49
49
  # @return [Array<void>]
50
50
  def content
51
- cells.flatten
51
+ cells.flatten << reset_character
52
52
  end
53
53
 
54
54
  # Provides iteration over the collection.
@@ -73,6 +73,15 @@ module Vedeu
73
73
  end
74
74
  alias_method :==, :eql?
75
75
 
76
+ # Provides the reset escape sequence at the end of a row to
77
+ # reset colour and style information to prevent colour bleed on
78
+ # the next line.
79
+ #
80
+ # @return [Vedeu::Views::Char]
81
+ def reset_character
82
+ Vedeu::Views::Char.new(value: Vedeu::EscapeSequences::Esc.reset)
83
+ end
84
+
76
85
  end # Row
77
86
 
78
87
  end # Models
@@ -51,7 +51,7 @@ module Vedeu
51
51
  # @option attributes colour [Vedeu::Colours::Colour]
52
52
  # @option attributes name [String|Symbol]
53
53
  # @option attributes parent [Vedeu::Views::Line]
54
- # @option attributes position [Vedeu::Geometry::Position]
54
+ # @option attributes position [Vedeu::Geometries::Position]
55
55
  # @option attributes style [Vedeu::Presentation::Style]
56
56
  # @option attributes value [String]
57
57
  # @return [Vedeu::Views::Char]
@@ -94,17 +94,17 @@ module Vedeu
94
94
  @interface ||= Vedeu.interfaces.by_name(name)
95
95
  end
96
96
 
97
- # @return [Vedeu::Geometry::Position]
97
+ # @return [Vedeu::Geometries::Position]
98
98
  def position
99
- @position = Vedeu::Geometry::Position.coerce(@attributes[:position])
99
+ @position = Vedeu::Geometries::Position.coerce(@attributes[:position])
100
100
  end
101
101
 
102
102
  # Sets the position of the Vedeu::Views::Char.
103
103
  #
104
- # @param value [Vedeu::Geometry::Position]
105
- # @return [Vedeu::Geometry::Position]
104
+ # @param value [Vedeu::Geometries::Position]
105
+ # @return [Vedeu::Geometries::Position]
106
106
  def position=(value)
107
- @position = @attributes[:position] = Vedeu::Geometry::Position
107
+ @position = @attributes[:position] = Vedeu::Geometries::Position
108
108
  .coerce(value)
109
109
  end
110
110
 
@@ -12,7 +12,7 @@ module Vedeu
12
12
 
13
13
  # Represents a single row of the terminal. It is a container for
14
14
  # {Vedeu::Views::Stream} objects. A line's width is determined by
15
- # the {Vedeu::Geometry::Geometry} it belongs to.
15
+ # the {Vedeu::Geometries::Geometry} it belongs to.
16
16
  #
17
17
  class Line
18
18
 
@@ -59,16 +59,15 @@ module Vedeu
59
59
  # @return [String]
60
60
  def compress
61
61
  Vedeu.timer("Compression for #{content.size} objects".freeze) do
62
- out = ''
63
-
64
- content.each do |cell|
65
- # out << position_for(cell)
66
-
67
- out << cell.position.to_s
68
- out << colour_for(cell)
69
- out << style_for(cell)
70
- out << cell.value
71
- end
62
+ out = content.map do |cell|
63
+ [
64
+ # position_for(cell),
65
+ cell.position.to_s,
66
+ colour_for(cell),
67
+ style_for(cell),
68
+ cell.value,
69
+ ].join
70
+ end.join
72
71
 
73
72
  Vedeu.log(type: :output,
74
73
  message: "Compression: #{content.size} objects -> " \
@@ -80,11 +79,7 @@ module Vedeu
80
79
 
81
80
  # @return [String]
82
81
  def uncompress
83
- out = ''
84
-
85
- content.each do |cell|
86
- out << cell.to_s
87
- end
82
+ out = content.map(&:to_s).join
88
83
 
89
84
  Vedeu.log(type: :output,
90
85
  message: "No compression: #{content.size} objects -> " \
@@ -22,7 +22,7 @@ module Vedeu
22
22
  #
23
23
  # @return [Boolean]
24
24
  def position?
25
- self.respond_to?(:position) && position.is_a?(Vedeu::Geometry::Position)
25
+ self.respond_to?(:position) && position.is_a?(Vedeu::Geometries::Position)
26
26
  end
27
27
 
28
28
  # Renders the colour attributes of the receiver and yields (to
@@ -17,7 +17,7 @@ module Vedeu
17
17
  #
18
18
  # @return [Array<void>]
19
19
  def clear
20
- threads = storage.map do |renderer|
20
+ storage.map do |renderer|
21
21
  Vedeu.log(type: :output,
22
22
  message: "Clearing via #{renderer.class.name}".freeze)
23
23
 
@@ -26,8 +26,7 @@ module Vedeu
26
26
  toggle_cursor { renderer.clear }
27
27
  end
28
28
  end
29
- end
30
- threads.each(&:join)
29
+ end.each(&:join) if Vedeu.ready?
31
30
 
32
31
  ''
33
32
  end
@@ -51,7 +50,7 @@ module Vedeu
51
50
  # @param output [void]
52
51
  # @return [Array<void>]
53
52
  def render(output)
54
- threads = storage.map do |renderer|
53
+ storage.map do |renderer|
55
54
  Vedeu.log(type: :output,
56
55
  message: "Rendering via #{renderer.class.name}".freeze)
57
56
 
@@ -60,8 +59,7 @@ module Vedeu
60
59
  toggle_cursor { renderer.render(output) }
61
60
  end
62
61
  end
63
- end
64
- threads.each(&:join)
62
+ end.each(&:join) if Vedeu.ready?
65
63
 
66
64
  output
67
65
  end
@@ -83,12 +81,13 @@ module Vedeu
83
81
  end
84
82
 
85
83
  # @example
86
- # Vedeu.renderers.reset
84
+ # Vedeu.renderers.reset!
87
85
  #
88
86
  # @return [Set]
89
- def reset
87
+ def reset!
90
88
  @storage = in_memory
91
89
  end
90
+ alias_method :reset, :reset!
92
91
 
93
92
  private
94
93
 
@@ -149,7 +149,7 @@ module Vedeu
149
149
 
150
150
  # Returns the geometry for the interface.
151
151
  #
152
- # @return (see Vedeu::Geometry::Repository#by_name)
152
+ # @return (see Vedeu::Geometries::Repository#by_name)
153
153
  def geometry
154
154
  @geometry ||= Vedeu.geometries.by_name(name)
155
155
  end
@@ -51,13 +51,13 @@ module Vedeu
51
51
  # Remove all currently stored data.
52
52
  #
53
53
  # @return [Array|Hash|Set]
54
- def reset
54
+ def reset!
55
55
  Vedeu.log(type: :reset,
56
56
  message: "(#{self.class.name}) #{registered.inspect}".freeze)
57
57
 
58
58
  @storage = in_memory
59
59
  end
60
- alias_method :reset!, :reset
60
+ alias_method :reset, :reset!
61
61
  alias_method :clear, :reset
62
62
 
63
63
  # Return the number of entries stored.
@@ -15,146 +15,90 @@ module Vedeu
15
15
 
16
16
  extend self
17
17
 
18
- # Return a grid of {Vedeu::Models::Cell} objects defined by the
19
- # height and width of this virtual terminal.
20
- #
21
- # @return [Array<Array<Vedeu::Models::Cell>>]
22
- def buffer
23
- @output ||= Array.new(Vedeu.height + 1) do |y|
24
- Array.new(Vedeu.width + 1) do |x|
25
- Vedeu::Models::Cell.new(position: [y, x])
26
- end
27
- end
28
- end
29
- alias_method :cells, :buffer
30
-
31
- # Clear the output.
18
+ # Clears the whole terminal space.
32
19
  #
33
20
  # @example
34
21
  # Vedeu.clear
35
22
  #
23
+ # # or...
24
+ #
25
+ # Vedeu.trigger(:_clear_)
26
+ #
36
27
  # @return [String|void] Most likely to be a String.
37
28
  def clear
38
- reset
29
+ reset!
39
30
 
40
- Vedeu.renderers.clear if Vedeu.ready?
31
+ Vedeu.renderers.clear
41
32
  end
42
33
 
34
+ # Returns the buffer content.
35
+ #
36
+ # @example
37
+ # Vedeu.trigger(:_drb_retrieve_output_)
38
+ #
43
39
  # @return [Vedeu::Models::Page]
44
40
  def output
45
41
  Vedeu::Models::Page.coerce(buffer)
46
42
  end
47
43
 
48
- # Read a single cell from the virtual terminal.
49
- #
50
- # @note
51
- # Given two actual coordinates (y, x) e.g. (1, 1)
52
- # Convert to coordinate indices (cy, cx) e.g. (0, 0)
53
- # Fetch the row at cy and return the cell from cx
54
- #
55
- # @param y [Fixnum] The row/line coordinate.
56
- # @param x [Fixnum] The column/character coordinate.
57
- # @return [Vedeu::Views::Char]
58
- def read(y, x)
59
- cy, cx = Vedeu::Geometry::Position[y, x].as_indices
60
-
61
- row = fetch(cells, cy)
62
- cell = fetch(row, cx)
63
-
64
- cell
65
- end
66
-
67
44
  # Send the cells to the renderer and return the rendered result.
68
45
  #
46
+ # @example
47
+ # Vedeu.refresh
48
+ #
69
49
  # @return [String|void] Most likely to be a String.
70
- def render
71
- Vedeu.renderers.render(output) if Vedeu.ready?
50
+ def refresh
51
+ Vedeu.renderers.render(output)
72
52
  end
73
- alias_method :refresh, :render
74
53
 
75
54
  # Removes all content from the virtual terminal; effectively
76
55
  # clearing it.
77
56
  #
78
- # @return [Array<Array<Vedeu::Models::Cell>>]
79
- def reset
80
- @output = Array.new(Vedeu.height + 1) do |y|
81
- Array.new(Vedeu.width + 1) do |x|
82
- Vedeu::Models::Cell.new(position: [y, x])
83
- end
84
- end
85
- end
86
-
87
- # Write a collection of cells to the virtual terminal, will
88
- # then send written content to be rendered by a renderer.
89
- #
90
- # @param value [Array<Array<Vedeu::Views::Char>>]
91
- # @return [Array<Array<Vedeu::Views::Char>>]
92
- def write(value)
93
- update_buffer(value)
94
-
95
- render
96
-
97
- self
57
+ # @return [Vedeu::Buffers::View]
58
+ def reset!
59
+ @buffer = buffer.reset!
98
60
  end
99
61
 
100
62
  # Write a collection of cells to the virtual terminal, but do
101
63
  # not send to a renderer.
102
64
  #
103
- # @param value [Array<Array<Vedeu::Views::Char>>]
65
+ # @param value_or_values [Array<Array<Vedeu::Views::Char>>]
104
66
  # @return [Array<Array<Vedeu::Views::Char>>]
105
- def update(value)
106
- update_buffer(value)
67
+ def update(value_or_values)
68
+ buffer.update(value_or_values)
107
69
 
108
70
  self
109
71
  end
110
72
 
111
- private
112
-
113
- # @param from [Array] An Array of rows, or an Array of cells.
114
- # @param which [Fixnum] A Fixnum representing the index; the row
115
- # number or the cell number for a row.
116
- # @return [Array<Vedeu::Views::Char>|Array]
117
- def fetch(from, which)
118
- from[which] || []
119
- end
120
-
121
- # Returns a boolean indicating the value has a position
122
- # attribute.
73
+ # Write a collection of cells to the virtual terminal, will
74
+ # then send written content to be rendered by a renderer. This
75
+ # method is used internally by Vedeu, but can be triggered in
76
+ # DRb mode pushing the given data in to the virtual buffer of
77
+ # the running client application as per the example.
78
+ #
79
+ # @example
80
+ # Vedeu.trigger(:_drb_store_output_, value_or_values)
123
81
  #
124
- # @param value [void]
125
- # @return [Boolean]
126
- def position?(value)
127
- value.respond_to?(:position) &&
128
- value.position.is_a?(Vedeu::Geometry::Position)
129
- end
130
-
131
82
  # @param value [Array<Array<Vedeu::Views::Char>>]
132
83
  # @return [Array<Array<Vedeu::Views::Char>>]
133
- def update_buffer(value)
134
- values = Array(value).flatten
84
+ def write(value_or_values)
85
+ buffer.update(value_or_values)
135
86
 
136
- values.each do |v|
137
- buffer[v.position.y][v.position.x] = v if valid_position?(v)
138
- end
139
- end
87
+ refresh
140
88
 
141
- # Returns a boolean indicating the value has a position
142
- # attribute and is within the terminal boundary.
143
- #
144
- # @param value [void]
145
- # @return [Boolean]
146
- def valid_position?(value)
147
- position?(value) && within_terminal_boundary?(value)
89
+ self
148
90
  end
149
91
 
150
- # Returns a boolean indicating the position of the value object
151
- # is valid for this terminal.
92
+ private
93
+
94
+ # Return a grid of {Vedeu::Models::Cell} objects defined by the
95
+ # height and width of this virtual terminal.
152
96
  #
153
- # @param value [void]
154
- # @return [Boolean]
155
- def within_terminal_boundary?(value)
156
- buffer[value.position.y] && buffer[value.position.y][value.position.x]
97
+ # @return [Vedeu::Buffers::View]
98
+ def buffer
99
+ @buffer ||= Vedeu::Buffers::View.new(name: name)
157
100
  end
101
+ alias_method :cells, :buffer
158
102
 
159
103
  end # Buffer
160
104
 
@@ -168,13 +112,13 @@ module Vedeu
168
112
 
169
113
  # :nocov:
170
114
 
171
- # See {file:docs/events/visibility.md#\_clear_}
115
+ # @see Vedeu::Terminal::Buffer#clear
172
116
  Vedeu.bind(:_clear_) { Vedeu.clear }
173
117
 
174
- # See {file:docs/events/drb.md#\_drb_retrieve_output_}
118
+ # @see Vedeu::Terminal::Buffer#output
175
119
  Vedeu.bind(:_drb_retrieve_output_) { Vedeu::Terminal::Buffer.output }
176
120
 
177
- # See {file:docs/events/drb.md#\_drb_store_output_}
121
+ # @see Vedeu::Terminal::Buffer#write
178
122
  Vedeu.bind(:_drb_store_output_) { |data| Vedeu::Terminal::Buffer.write(data) }
179
123
 
180
124
  # :nocov: