vedeu 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +40 -0
  3. data/README.md +1 -0
  4. data/docs/dsl.md +24 -24
  5. data/lib/vedeu/all.rb +21 -44
  6. data/lib/vedeu/api.rb +13 -13
  7. data/lib/vedeu/application/application_controller.rb +2 -0
  8. data/lib/vedeu/bindings/movement.rb +53 -18
  9. data/lib/vedeu/bindings/refresh.rb +1 -1
  10. data/lib/vedeu/bindings/system.rb +2 -2
  11. data/lib/vedeu/bindings/visibility.rb +3 -3
  12. data/lib/vedeu/borders/all.rb +13 -0
  13. data/lib/vedeu/borders/border.rb +209 -202
  14. data/lib/vedeu/{dsl/border.rb → borders/dsl.rb} +15 -15
  15. data/lib/vedeu/{null/border.rb → borders/null.rb} +9 -9
  16. data/lib/vedeu/borders/render.rb +347 -0
  17. data/lib/vedeu/borders/repository.rb +19 -0
  18. data/lib/vedeu/buffers/all.rb +13 -0
  19. data/lib/vedeu/buffers/buffer.rb +182 -176
  20. data/lib/vedeu/{null/buffer.rb → buffers/null.rb} +8 -8
  21. data/lib/vedeu/buffers/repository.rb +24 -0
  22. data/lib/vedeu/buffers/virtual_buffer.rb +2 -2
  23. data/lib/vedeu/cursors/all.rb +11 -0
  24. data/lib/vedeu/cursors/cursor.rb +276 -0
  25. data/lib/vedeu/cursors/refresh.rb +84 -0
  26. data/lib/vedeu/cursors/repository.rb +34 -0
  27. data/lib/vedeu/dsl/interface.rb +9 -9
  28. data/lib/vedeu/dsl/shared.rb +11 -11
  29. data/lib/vedeu/{exceptions.rb → error.rb} +2 -2
  30. data/lib/vedeu/esc/esc.rb +1 -1
  31. data/lib/vedeu/geometry/all.rb +18 -0
  32. data/lib/vedeu/geometry/area.rb +170 -160
  33. data/lib/vedeu/geometry/coordinate.rb +61 -39
  34. data/lib/vedeu/geometry/dimension.rb +139 -132
  35. data/lib/vedeu/{dsl/geometry.rb → geometry/dsl.rb} +11 -11
  36. data/lib/vedeu/geometry/generic_coordinate.rb +159 -153
  37. data/lib/vedeu/geometry/geometry.rb +310 -212
  38. data/lib/vedeu/geometry/grid.rb +73 -69
  39. data/lib/vedeu/{null/geometry.rb → geometry/null.rb} +10 -10
  40. data/lib/vedeu/geometry/position.rb +124 -120
  41. data/lib/vedeu/geometry/repository.rb +19 -0
  42. data/lib/vedeu/input/editor/document.rb +2 -2
  43. data/lib/vedeu/internal_api.rb +8 -8
  44. data/lib/vedeu/models/escape.rb +2 -2
  45. data/lib/vedeu/models/interface.rb +1 -1
  46. data/lib/vedeu/models/page.rb +89 -0
  47. data/lib/vedeu/models/row.rb +66 -0
  48. data/lib/vedeu/models/toggleable.rb +1 -1
  49. data/lib/vedeu/models/views/char.rb +7 -6
  50. data/lib/vedeu/models/views/line.rb +1 -1
  51. data/lib/vedeu/models/views/view.rb +2 -2
  52. data/lib/vedeu/options.rb +19 -0
  53. data/lib/vedeu/output/clear/named_interface.rb +1 -1
  54. data/lib/vedeu/output/direct.rb +1 -1
  55. data/lib/vedeu/output/presentation.rb +2 -1
  56. data/lib/vedeu/output/viewport.rb +3 -3
  57. data/lib/vedeu/repositories/model.rb +9 -1
  58. data/lib/vedeu/repositories/repository.rb +5 -0
  59. data/lib/vedeu/terminal/terminal.rb +3 -3
  60. data/lib/vedeu/version.rb +1 -1
  61. data/test/lib/vedeu/borders/border_test.rb +299 -291
  62. data/test/lib/vedeu/{dsl/border_test.rb → borders/dsl_test.rb} +6 -6
  63. data/test/lib/vedeu/{null/border_test.rb → borders/null_test.rb} +6 -6
  64. data/test/lib/vedeu/borders/render_test.rb +125 -0
  65. data/test/lib/vedeu/borders/repository_test.rb +17 -0
  66. data/test/lib/vedeu/buffers/buffer_test.rb +116 -112
  67. data/test/lib/vedeu/{null/buffer_test.rb → buffers/null_test.rb} +5 -5
  68. data/test/lib/vedeu/buffers/repository_test.rb +18 -0
  69. data/test/lib/vedeu/cursors/cursor_test.rb +370 -0
  70. data/test/lib/vedeu/cursors/refresh_test.rb +69 -0
  71. data/test/lib/vedeu/cursors/repository_test.rb +41 -0
  72. data/test/lib/vedeu/dsl/interface_test.rb +5 -5
  73. data/test/lib/vedeu/{exceptions_test.rb → error_test.rb} +0 -0
  74. data/test/lib/vedeu/geometry/area_test.rb +141 -137
  75. data/test/lib/vedeu/geometry/coordinate_test.rb +93 -89
  76. data/test/lib/vedeu/geometry/dimension_test.rb +137 -133
  77. data/test/lib/vedeu/{dsl/geometry_test.rb → geometry/dsl_test.rb} +17 -17
  78. data/test/lib/vedeu/geometry/generic_coordinate_test.rb +32 -28
  79. data/test/lib/vedeu/geometry/geometry_test.rb +282 -157
  80. data/test/lib/vedeu/geometry/grid_test.rb +35 -31
  81. data/test/lib/vedeu/{null/geometry_test.rb → geometry/null_test.rb} +5 -5
  82. data/test/lib/vedeu/geometry/position_test.rb +146 -142
  83. data/test/lib/vedeu/geometry/repository_test.rb +19 -0
  84. data/test/lib/vedeu/input/editor/document_test.rb +1 -1
  85. data/test/lib/vedeu/models/escape_test.rb +1 -1
  86. data/test/lib/vedeu/models/interface_test.rb +2 -2
  87. data/test/lib/vedeu/models/page_test.rb +235 -0
  88. data/test/lib/vedeu/models/row_test.rb +111 -0
  89. data/test/lib/vedeu/models/views/char_test.rb +3 -3
  90. data/test/lib/vedeu/options_test.rb +57 -0
  91. data/test/lib/vedeu/output/clear/named_interface_test.rb +1 -1
  92. data/test/lib/vedeu/output/renderers/json_test.rb +1 -1
  93. data/test/lib/vedeu/output/viewport_test.rb +15 -9
  94. data/test/lib/vedeu/refresh/refresh_buffer_test.rb +12 -12
  95. data/test/lib/vedeu/repositories/repositories_test.rb +1 -1
  96. data/test/lib/vedeu/repositories/repository_test.rb +7 -0
  97. data/test/lib/vedeu/terminal/terminal_test.rb +1 -1
  98. data/test/test_helper.rb +1 -1
  99. data/vedeu.gemspec +2 -2
  100. metadata +57 -63
  101. data/lib/vedeu/borders/borders.rb +0 -15
  102. data/lib/vedeu/borders/render_border.rb +0 -331
  103. data/lib/vedeu/buffers/buffers.rb +0 -20
  104. data/lib/vedeu/cursor/cursor.rb +0 -174
  105. data/lib/vedeu/cursor/cursors.rb +0 -30
  106. data/lib/vedeu/cursor/move.rb +0 -239
  107. data/lib/vedeu/cursor/reposition.rb +0 -78
  108. data/lib/vedeu/geometry/geometries.rb +0 -15
  109. data/lib/vedeu/refresh/refresh_cursor.rb +0 -92
  110. data/test/lib/vedeu/borders/borders_test.rb +0 -13
  111. data/test/lib/vedeu/borders/render_border_test.rb +0 -121
  112. data/test/lib/vedeu/buffers/buffers_test.rb +0 -14
  113. data/test/lib/vedeu/cursor/cursor_test.rb +0 -246
  114. data/test/lib/vedeu/cursor/cursors_test.rb +0 -37
  115. data/test/lib/vedeu/cursor/move_test.rb +0 -301
  116. data/test/lib/vedeu/cursor/reposition_test.rb +0 -63
  117. data/test/lib/vedeu/geometry/geometries_test.rb +0 -15
  118. data/test/lib/vedeu/refresh/refresh_cursor_test.rb +0 -65
@@ -0,0 +1,19 @@
1
+ module Vedeu
2
+
3
+ module Geometry
4
+
5
+ # Allows the storing of interface/view geometry independent of the interface
6
+ # instance.
7
+ #
8
+ class Repository < Vedeu::Repository
9
+
10
+ singleton_class.send(:alias_method, :geometries, :repository)
11
+
12
+ null Vedeu::Geometry::Null
13
+ real Vedeu::Geometry::Geometry
14
+
15
+ end # Repository
16
+
17
+ end # Geometry
18
+
19
+ end # Vedeu
@@ -212,7 +212,7 @@ module Vedeu
212
212
  # Retrieve the dimensions of the document from the interface of the same
213
213
  # name.
214
214
  #
215
- # @return [Vedeu::Border]
215
+ # @return [Vedeu::Borders::Border]
216
216
  def border
217
217
  @border ||= Vedeu.borders.by_name(name)
218
218
  end
@@ -249,7 +249,7 @@ module Vedeu
249
249
  output = ''
250
250
 
251
251
  visible.each_with_index do |line, y_index|
252
- output << Vedeu::Position.new((by + y_index), bx).to_s
252
+ output << Vedeu::Geometry::Position.new((by + y_index), bx).to_s
253
253
  output << line.to_s
254
254
  end
255
255
 
@@ -25,8 +25,8 @@ module Vedeu
25
25
  # Vedeu.borders
26
26
  #
27
27
  # @!method borders
28
- # @return [Vedeu::Borders]
29
- def_delegators Vedeu::Borders, :borders
28
+ # @return [Vedeu::Borders::Repository]
29
+ def_delegators Vedeu::Borders::Repository, :borders
30
30
 
31
31
  # Manipulate the repository of buffers.
32
32
  #
@@ -34,8 +34,8 @@ module Vedeu
34
34
  # Vedeu.buffers
35
35
  #
36
36
  # @!method buffers
37
- # @return [Vedeu::Buffers]
38
- def_delegators Vedeu::Buffers, :buffers
37
+ # @return [Vedeu::Buffers::Repository]
38
+ def_delegators Vedeu::Buffers::Repository, :buffers
39
39
 
40
40
  # Manipulate the repository of cursors.
41
41
  #
@@ -43,8 +43,8 @@ module Vedeu
43
43
  # Vedeu.cursors
44
44
  #
45
45
  # @!method cursors
46
- # @return [Vedeu::Cursors]
47
- def_delegators Vedeu::Cursors, :cursors
46
+ # @return [Vedeu::Cursors::Repository]
47
+ def_delegators Vedeu::Cursors::Repository, :cursors
48
48
 
49
49
  # Allow debugging via the creation of stack traces courtesy of ruby-prof.
50
50
  #
@@ -88,8 +88,8 @@ module Vedeu
88
88
  # Vedeu.geometries
89
89
  #
90
90
  # @!method geometries
91
- # @return [Vedeu::Geometries]
92
- def_delegators Vedeu::Geometries, :geometries
91
+ # @return [Vedeu::Geometry::Repository]
92
+ def_delegators Vedeu::Geometry::Repository, :geometries
93
93
 
94
94
  # Manipulate the repository of groups.
95
95
  #
@@ -11,7 +11,7 @@ module Vedeu
11
11
  # Returns a new instance of Vedeu::Escape.
12
12
  #
13
13
  # @param attributes [String]
14
- # @option attributes position [Vedeu::Position|Array<Fixnum>]
14
+ # @option attributes position [Vedeu::Geometry::Position|Array<Fixnum>]
15
15
  # @option attributes value [String]
16
16
  # @return [Vedeu::Escape]
17
17
  def initialize(attributes = {})
@@ -40,7 +40,7 @@ module Vedeu
40
40
 
41
41
  # @return [String]
42
42
  def position
43
- Vedeu::Position.coerce(@position)
43
+ Vedeu::Geometry::Position.coerce(@position)
44
44
  end
45
45
 
46
46
  # @return [String]
@@ -1,7 +1,7 @@
1
1
  module Vedeu
2
2
 
3
3
  # An Interface represents a portion of the terminal defined by
4
- # {Vedeu::Geometry}.
4
+ # {Vedeu::Geometry::Geometry}.
5
5
  #
6
6
  class Interface
7
7
 
@@ -0,0 +1,89 @@
1
+ module Vedeu
2
+
3
+ # A Page represents an array of Vedeu::Row objects.
4
+ #
5
+ class Page
6
+
7
+ include Enumerable
8
+
9
+ # @!attribute [r] rows
10
+ # @return [Array<NilClass|Vedeu::Row>]
11
+ attr_reader :rows
12
+
13
+ # @param value [Vedeu::Page|Vedeu::Row|Array<void>|void]
14
+ # @return [Vedeu::Page]
15
+ def self.coerce(value)
16
+ if value.is_a?(Vedeu::Page)
17
+ value
18
+
19
+ elsif value.is_a?(Vedeu::Row)
20
+ Vedeu::Page.new([value])
21
+
22
+ elsif value.is_a?(Array) && value.empty?
23
+ Vedeu::Page.new([Vedeu::Row.coerce(value)])
24
+
25
+ elsif value.is_a?(Array)
26
+ values = value.map do |v|
27
+ if v.is_a?(Vedeu::Row)
28
+ v
29
+
30
+ else
31
+ Vedeu::Row.coerce(v)
32
+
33
+ end
34
+ end
35
+ Vedeu::Page.new(values)
36
+
37
+ else
38
+ fail Vedeu::Error::InvalidSyntax,
39
+ 'Cannot coerce as value is not an Array.'
40
+
41
+ end
42
+ end
43
+
44
+ # Returns an instance of Vedeu::Page.
45
+ #
46
+ # @param rows [Array<NilClass|Vedeu::Row>]
47
+ # @return [Vedeu::Page]
48
+ def initialize(rows = [])
49
+ @rows = rows || []
50
+ end
51
+
52
+ # Provides iteration over the collection.
53
+ #
54
+ # @param block [Proc]
55
+ # @return [Enumerator]
56
+ def each(&block)
57
+ rows.each(&block)
58
+ end
59
+
60
+ # An object is equal when its values are the same.
61
+ #
62
+ # @param other [Vedeu::Page]
63
+ # @return [Boolean]
64
+ def eql?(other)
65
+ self.class == other.class && rows == other.rows
66
+ end
67
+ alias_method :==, :eql?
68
+
69
+ # @param index [Fixnum]
70
+ # @return [NilClass|Vedeu::Row]
71
+ def row(index = nil)
72
+ return nil if index.nil?
73
+
74
+ rows[index]
75
+ end
76
+
77
+ # @param row_index [Fixnum]
78
+ # @param cell_index [Fixnum]
79
+ # @return [NilClass|void]
80
+ def cell(row_index = nil, cell_index = nil)
81
+ return nil if row_index.nil? || cell_index.nil?
82
+ return nil unless row(row_index)
83
+
84
+ row(row_index)[cell_index]
85
+ end
86
+
87
+ end # Page
88
+
89
+ end # Vedeu
@@ -0,0 +1,66 @@
1
+ module Vedeu
2
+
3
+ # A Row represents an array of Vedeu::Cell objects.
4
+ #
5
+ class Row
6
+
7
+ include Enumerable
8
+
9
+ # @!attribute [r] cells
10
+ # @return [Array<NilClass|void>]
11
+ attr_reader :cells
12
+
13
+ # @param value [Vedeu::Row|Array<void>|void]
14
+ # @return [Vedeu::Row]
15
+ def self.coerce(value)
16
+ if value.is_a?(self)
17
+ value
18
+
19
+ elsif value.is_a?(Array)
20
+ new(value.compact)
21
+
22
+ elsif value.nil?
23
+ new
24
+
25
+ else
26
+ new([value])
27
+
28
+ end
29
+ end
30
+
31
+ # Returns an instance of Vedeu::Row.
32
+ #
33
+ # @param cells [Array<NilClass|void>]
34
+ # @return [Vedeu::Row]
35
+ def initialize(cells = [])
36
+ @cells = cells || []
37
+ end
38
+
39
+ # Provides iteration over the collection.
40
+ #
41
+ # @param block [Proc]
42
+ # @return [Enumerator]
43
+ def each(&block)
44
+ cells.each(&block)
45
+ end
46
+
47
+ # An object is equal when its values are the same.
48
+ #
49
+ # @param other [Vedeu::Row]
50
+ # @return [Boolean]
51
+ def eql?(other)
52
+ self.class == other.class && cells == other.cells
53
+ end
54
+ alias_method :==, :eql?
55
+
56
+ # @param index [Fixnum]
57
+ # @return [NilClass|void]
58
+ def cell(index)
59
+ return nil if index.nil?
60
+
61
+ cells[index]
62
+ end
63
+
64
+ end # Row
65
+
66
+ end # Vedeu
@@ -3,7 +3,7 @@ module Vedeu
3
3
  # This module provides behaviour for certain classes which can be toggled
4
4
  # between being shown and hidden.
5
5
  #
6
- # Currently using this are: {Vedeu::Cursor}, {Vedeu::Group} and
6
+ # Currently using this are: {Vedeu::Cursors::Cursor}, {Vedeu::Group} and
7
7
  # {Vedeu::Interface}.
8
8
  #
9
9
  module Toggleable
@@ -36,7 +36,7 @@ module Vedeu
36
36
  # border 'piece' this Vedeu::Views::Char represents.
37
37
  # @option attributes colour [Vedeu::Colours::Colour]
38
38
  # @option attributes parent [Vedeu::Views::Line]
39
- # @option attributes position [Vedeu::Position]
39
+ # @option attributes position [Vedeu::Geometry::Position]
40
40
  # @option attributes style [Vedeu::Style]
41
41
  # @option attributes value [String]
42
42
  # @return [Vedeu::Views::Char]
@@ -68,17 +68,18 @@ module Vedeu
68
68
  end
69
69
  alias_method :==, :eql?
70
70
 
71
- # @return [Vedeu::Position]
71
+ # @return [Vedeu::Geometry::Position]
72
72
  def position
73
- @position = Vedeu::Position.coerce(@attributes[:position])
73
+ @position = Vedeu::Geometry::Position.coerce(@attributes[:position])
74
74
  end
75
75
 
76
76
  # Sets the position of the Vedeu::Views::Char.
77
77
  #
78
- # @param value [Vedeu::Position]
79
- # @return [Vedeu::Position]
78
+ # @param value [Vedeu::Geometry::Position]
79
+ # @return [Vedeu::Geometry::Position]
80
80
  def position=(value)
81
- @position = @attributes[:position] = Vedeu::Position.coerce(value)
81
+ @position = @attributes[:position] = Vedeu::Geometry::Position
82
+ .coerce(value)
82
83
  end
83
84
 
84
85
  # @return [String]
@@ -4,7 +4,7 @@ module Vedeu
4
4
 
5
5
  # Represents a single row of the terminal. It is a container for
6
6
  # {Vedeu::Views::Stream} objects. A line's width is determined by the
7
- # {Vedeu::Geometry} it belongs to.
7
+ # {Vedeu::Geometry::Geometry} it belongs to.
8
8
  #
9
9
  class Line
10
10
 
@@ -74,11 +74,11 @@ module Vedeu
74
74
  return [] unless visible?
75
75
 
76
76
  output = [
77
- Vedeu::Cursor.hide_cursor(name),
77
+ Vedeu::Cursors::Cursor.hide_cursor(name),
78
78
  Vedeu::Clear::NamedInterface.render(name),
79
79
  Vedeu::Viewport.render(self),
80
80
  Vedeu.borders.by_name(name).render,
81
- Vedeu::Cursor.show_cursor(name),
81
+ Vedeu::Cursors::Cursor.show_cursor(name),
82
82
  ]
83
83
 
84
84
  output
@@ -0,0 +1,19 @@
1
+ module Vedeu
2
+
3
+ class Options
4
+
5
+ # @param options [Hash]
6
+ # @param defaults [Hash]
7
+ def initialize(options = {}, defaults = {})
8
+ @options = options || {}
9
+ @defaults = defaults || {}
10
+
11
+ @defaults.merge!(@options).each do |key, value|
12
+ instance_variable_set("@#{key}", value)
13
+ self.class.send(:define_method, key) { value }
14
+ end
15
+ end
16
+
17
+ end # Options
18
+
19
+ end # Vedeu
@@ -41,7 +41,7 @@ module Vedeu
41
41
 
42
42
  private
43
43
 
44
- # @see Vedeu::Geometries#by_name
44
+ # @see Vedeu::Geometry::Repository#by_name
45
45
  def geometry
46
46
  @geometry ||= Vedeu.geometries.by_name(name)
47
47
  end
@@ -54,7 +54,7 @@ module Vedeu
54
54
 
55
55
  # @return [String]
56
56
  def position
57
- Vedeu::Position.new(y, x).to_s
57
+ Vedeu::Geometry::Position.new(y, x).to_s
58
58
  end
59
59
 
60
60
  end # Direct
@@ -33,7 +33,8 @@ module Vedeu
33
33
 
34
34
  # @return [String]
35
35
  def render_position
36
- if self.respond_to?(:position) && position.is_a?(Vedeu::Position)
36
+ if self.respond_to?(:position) &&
37
+ position.is_a?(Vedeu::Geometry::Position)
37
38
  position.to_s { yield }
38
39
 
39
40
  else
@@ -140,7 +140,7 @@ module Vedeu
140
140
 
141
141
  # Return the border associated with the interface/view we are drawing.
142
142
  #
143
- # @return (see Vedeu::Borders#by_name)
143
+ # @return (see Vedeu::Borders::Repository#by_name)
144
144
  def border
145
145
  @border ||= Vedeu.borders.by_name(name)
146
146
  end
@@ -155,8 +155,8 @@ module Vedeu
155
155
  @by ||= border.by
156
156
  end
157
157
 
158
- # @return [Vedeu::Cursor]
159
- # @see Vedeu::Cursors#by_name
158
+ # @return [Vedeu::Cursors::Cursor]
159
+ # @see Vedeu::Cursors::Repository#by_name
160
160
  def cursor
161
161
  @cursor ||= Vedeu.cursors.by_name(name)
162
162
  end
@@ -109,7 +109,15 @@ module Vedeu
109
109
  #
110
110
  # @return [String]
111
111
  def dsl_class
112
- 'Vedeu::DSL::' + demodulize(self.class.name)
112
+ if demodulize(self.class.name) == 'Border'
113
+ 'Vedeu::Borders::DSL'
114
+ elsif demodulize(self.class.name) == 'Buffer'
115
+ 'Vedeu::Buffers::DSL'
116
+ elsif demodulize(self.class.name) == 'Geometry'
117
+ 'Vedeu::Geometry::DSL'
118
+ else
119
+ 'Vedeu::DSL::' + demodulize(self.class.name)
120
+ end
113
121
  end
114
122
 
115
123
  end # Model
@@ -113,6 +113,11 @@ module Vedeu
113
113
  end
114
114
  end
115
115
 
116
+ # @return [String]
117
+ def inspect
118
+ "<#{self.class.name}>"
119
+ end
120
+
116
121
  # Returns a boolean indicating whether the named model is registered.
117
122
  #
118
123
  # @param name [String]
@@ -183,9 +183,9 @@ module Vedeu
183
183
  # terminal space up when defining interfaces or views, leading to more
184
184
  # consistent rendering.
185
185
  #
186
- # If the client application is using the {Vedeu::Grid#rows} or
187
- # {Vedeu::Grid#columns} helpers, the dimensions are made more consistent
188
- # using this approach.
186
+ # If the client application is using the {Vedeu::Geometry::Grid#rows} or
187
+ # {Vedeu::Geometry::Grid#columns} helpers, the dimensions are made more
188
+ # consistent using this approach.
189
189
  #
190
190
  # @return [Array]
191
191
  def size