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 Borders
4
+
5
+ # Allows the storing of interface/view borders independent of the interface
6
+ # instance.
7
+ #
8
+ class Repository < Vedeu::Repository
9
+
10
+ singleton_class.send(:alias_method, :borders, :repository)
11
+
12
+ null Vedeu::Borders::Null
13
+ real Vedeu::Borders::Border
14
+
15
+ end # Repository
16
+
17
+ end # Borders
18
+
19
+ end # Vedeu
@@ -0,0 +1,13 @@
1
+ module Vedeu
2
+
3
+ module Buffers
4
+
5
+ end # Buffers
6
+
7
+ end # Vedeu
8
+
9
+ require 'vedeu/buffers/buffer'
10
+ require 'vedeu/buffers/null'
11
+ require 'vedeu/buffers/repository'
12
+ require 'vedeu/buffers/virtual_buffer'
13
+ require 'vedeu/buffers/virtual_buffers'
@@ -1,206 +1,212 @@
1
1
  module Vedeu
2
2
 
3
- # The Buffer object represents the states of display for an interface. The
4
- # states are 'front', 'back' and 'previous'.
5
- #
6
- # [Back] -> [Front] -> [Previous]
7
- #
8
- # The content on the screen, or last output will always be the 'Front' buffer.
9
- # Content due to be displayed on next refresh will come from the 'Back' buffer
10
- # when available, otherwise from the current 'Front' buffer. When new content
11
- # is copied to the 'Front' buffer, the current 'Front' buffer is also copied
12
- # to the 'Previous' buffer.
13
- #
14
- class Buffer
15
-
16
- include Vedeu::Model
17
-
18
- # The next buffer to be displayed; contains the content which will be shown
19
- # on next refresh.
20
- #
21
- # @!attribute [rw] back
22
- # @return [Vedeu::Views::View]
23
- attr_accessor :back
24
-
25
- # The currently displayed buffer, contains the content which was last
26
- # output.
27
- #
28
- # @!attribute [rw] front
29
- # @return [Vedeu::Views::View]
30
- attr_accessor :front
31
-
32
- # The previous buffer which was displayed; contains the content that was
33
- # shown before 'front'.
34
- #
35
- # @!attribute [rw] previous
36
- # @return [Vedeu::Views::View]
37
- attr_accessor :previous
3
+ module Buffers
4
+
5
+ # The Buffer object represents the states of display for an interface. The
6
+ # states are 'front', 'back' and 'previous'.
7
+ #
8
+ # [Back] -> [Front] -> [Previous]
9
+ #
10
+ # The content on the screen, or last output will always be the 'Front'
11
+ # buffer. Content due to be displayed on next refresh will come from the
12
+ # 'Back' buffer when available, otherwise from the current 'Front' buffer.
13
+ # When new content is copied to the 'Front' buffer, the current 'Front'
14
+ # buffer is also copied to the 'Previous' buffer.
15
+ #
16
+ class Buffer
17
+
18
+ include Vedeu::Model
19
+
20
+ # The next buffer to be displayed; contains the content which will be
21
+ # shown on next refresh.
22
+ #
23
+ # @!attribute [rw] back
24
+ # @return [Vedeu::Views::View]
25
+ attr_accessor :back
26
+
27
+ # The currently displayed buffer, contains the content which was last
28
+ # output.
29
+ #
30
+ # @!attribute [rw] front
31
+ # @return [Vedeu::Views::View]
32
+ attr_accessor :front
33
+
34
+ # The previous buffer which was displayed; contains the content that was
35
+ # shown before 'front'.
36
+ #
37
+ # @!attribute [rw] previous
38
+ # @return [Vedeu::Views::View]
39
+ attr_accessor :previous
40
+
41
+ # @!attribute [r] name
42
+ # @return [String]
43
+ attr_reader :name
44
+
45
+ # Return a new instance of Buffer. Generally a Buffer is initialized with
46
+ # only a 'name' and 'back' parameter.
47
+ #
48
+ # @option attributes name [String] The name of the interface for which the
49
+ # buffer belongs.
50
+ # @option attributes back [Vedeu::Views::View]
51
+ # @option attributes front [Vedeu::Views::View]
52
+ # @option attributes previous [Vedeu::Views::View]
53
+ # @option attributes repository [Vedeu::Buffers::Repository]
54
+ # @return [Vedeu::Buffers::Buffer]
55
+ def initialize(attributes = {})
56
+ @attributes = defaults.merge!(attributes)
57
+
58
+ @attributes.each do |key, value|
59
+ instance_variable_set("@#{key}", value)
60
+ end
61
+ end
38
62
 
39
- # @!attribute [r] name
40
- # @return [String]
41
- attr_reader :name
63
+ # Add the content to the back buffer, then update the repository.
64
+ # Returns boolean indicating that the repository was updated.
65
+ #
66
+ # @param content [Vedeu::Views::View]
67
+ # @return [Boolean]
68
+ def add(content)
69
+ @back = content
42
70
 
43
- # Return a new instance of Buffer. Generally a Buffer is initialized with
44
- # only a 'name' and 'back' parameter.
45
- #
46
- # @option attributes name [String] The name of the interface for which the
47
- # buffer belongs.
48
- # @option attributes back [Vedeu::Views::View]
49
- # @option attributes front [Vedeu::Views::View]
50
- # @option attributes previous [Vedeu::Views::View]
51
- # @option attributes repository [Vedeu::Buffers]
52
- # @return [Vedeu::Buffer]
53
- def initialize(attributes = {})
54
- @attributes = defaults.merge!(attributes)
55
-
56
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
57
- end
58
-
59
- # Add the content to the back buffer, then update the repository.
60
- # Returns boolean indicating that the repository was updated.
61
- #
62
- # @param content [Vedeu::Views::View]
63
- # @return [Boolean]
64
- def add(content)
65
- @back = content
71
+ store
66
72
 
67
- store
73
+ true
74
+ end
68
75
 
69
- true
70
- end
76
+ # Return a boolean indicating content presence on the buffer type.
77
+ #
78
+ # @return [Boolean] Whether the buffer targetted has content.
79
+ def back?
80
+ return false if back.nil? || back.lines.empty?
71
81
 
72
- # Return a boolean indicating content presence on the buffer type.
73
- #
74
- # @return [Boolean] Whether the buffer targetted has content.
75
- def back?
76
- return false if back.nil? || back.lines.empty?
82
+ true
83
+ end
77
84
 
78
- true
79
- end
85
+ # Clear the buffer.
86
+ #
87
+ # @return [Array<Array<Vedeu::Views::Char>>]
88
+ def clear
89
+ Vedeu::Output.render(Vedeu::Clear::NamedInterface.render(name))
90
+ end
80
91
 
81
- # Clear the buffer.
82
- #
83
- # @return [Array<Array<Vedeu::Views::Char>>]
84
- def clear
85
- Vedeu::Output.render(Vedeu::Clear::NamedInterface.render(name))
86
- end
92
+ # Return a boolean indicating content presence on the buffer type.
93
+ #
94
+ # @return [Boolean] Whether the buffer targetted has content.
95
+ def front?
96
+ return false if front.nil? || front.lines.empty?
87
97
 
88
- # Return a boolean indicating content presence on the buffer type.
89
- #
90
- # @return [Boolean] Whether the buffer targetted has content.
91
- def front?
92
- return false if front.nil? || front.lines.empty?
98
+ true
99
+ end
93
100
 
94
- true
95
- end
101
+ # Return a boolean indicating content presence on the buffer type.
102
+ #
103
+ # @return [Boolean] Whether the buffer targetted has content.
104
+ def previous?
105
+ return false if previous.nil? || previous.lines.empty?
96
106
 
97
- # Return a boolean indicating content presence on the buffer type.
98
- #
99
- # @return [Boolean] Whether the buffer targetted has content.
100
- def previous?
101
- return false if previous.nil? || previous.lines.empty?
107
+ true
108
+ end
102
109
 
103
- true
104
- end
110
+ # Hide this buffer.
111
+ #
112
+ # @example
113
+ # Vedeu.trigger(:_hide_interface_, name)
114
+ # Vedeu.hide_interface(name)
115
+ #
116
+ # Will hide the named interface. If the interface is currently visible, it
117
+ # will be cleared- rendered blank. To show the interface, the
118
+ # ':_show_interface_' event should be triggered. Triggering the
119
+ # ':_hide_group_' event to which this named interface belongs will also
120
+ # hide the interface.
121
+ #
122
+ # @return [Array<Array<Array<Vedeu::Views::Char>>>]
123
+ def hide
124
+ Vedeu::Output.render(clear)
125
+ end
105
126
 
106
- # Hide this buffer.
107
- #
108
- # @example
109
- # Vedeu.trigger(:_hide_interface_, name)
110
- # Vedeu.hide_interface(name)
111
- #
112
- # Will hide the named interface. If the interface is currently visible, it
113
- # will be cleared- rendered blank. To show the interface, the
114
- # ':_show_interface_' event should be triggered. Triggering the
115
- # ':_hide_group_' event to which this named interface belongs will also hide
116
- # the interface.
117
- #
118
- # @return [Array<Array<Array<Vedeu::Views::Char>>>]
119
- def hide
120
- Vedeu::Output.render(clear)
121
- end
127
+ # Return the content for this buffer.
128
+ #
129
+ # - If we have new content (i.e. content on 'back') to be shown, we first
130
+ # clear the area occupied by the previous content, then clear the area
131
+ # for the new content, and then finally render the new content.
132
+ # - If there is no new content (i.e. 'back' is empty), check the 'front'
133
+ # buffer and display that.
134
+ # - If there is no new content, and the front buffer is empty, display the
135
+ # 'previous' buffer.
136
+ # - If the 'previous' buffer is empty, return an empty collection.
137
+ #
138
+ # @return [Array<Array<Array<Vedeu::Views::Char>>>]
139
+ def render
140
+ Vedeu::Output.render(buffer)
141
+ end
122
142
 
123
- # Return the content for this buffer.
124
- #
125
- # - If we have new content (i.e. content on 'back') to be shown, we first
126
- # clear the area occupied by the previous content, then clear the area for
127
- # the new content, and then finally render the new content.
128
- # - If there is no new content (i.e. 'back' is empty), check the 'front'
129
- # buffer and display that.
130
- # - If there is no new content, and the front buffer is empty, display the
131
- # 'previous' buffer.
132
- # - If the 'previous' buffer is empty, return an empty collection.
133
- #
134
- # @return [Array<Array<Array<Vedeu::Views::Char>>>]
135
- def render
136
- Vedeu::Output.render(buffer)
137
- end
143
+ # Show this buffer.
144
+ #
145
+ # @example
146
+ # Vedeu.trigger(:_show_interface_, name)
147
+ # Vedeu.show_interface(name)
148
+ #
149
+ # Will show the named interface. If the interface is currently invisible,
150
+ # it will be shown- rendered with its latest content. To hide the
151
+ # interface, the ':_hide_interface_' event should be triggered. Triggering
152
+ # the ':_show_group_' event to which this named interface belongs will
153
+ # also show the interface.
154
+ #
155
+ # @return [Array<Array<Array<Vedeu::Views::Char>>>]
156
+ def show
157
+ Vedeu::Output.render(buffer)
158
+ end
138
159
 
139
- # Show this buffer.
140
- #
141
- # @example
142
- # Vedeu.trigger(:_show_interface_, name)
143
- # Vedeu.show_interface(name)
144
- #
145
- # Will show the named interface. If the interface is currently invisible, it
146
- # will be shown- rendered with its latest content. To hide the interface,
147
- # the ':_hide_interface_' event should be triggered. Triggering the
148
- # ':_show_group_' event to which this named interface belongs will also show
149
- # the interface.
150
- #
151
- # @return [Array<Array<Array<Vedeu::Views::Char>>>]
152
- def show
153
- Vedeu::Output.render(buffer)
154
- end
160
+ private
155
161
 
156
- private
162
+ # Retrieve the latest content from the buffer.
163
+ #
164
+ # @return [Array<Array<Array<Vedeu::Views::Char>>>]
165
+ def buffer
166
+ swap if back?
157
167
 
158
- # Retrieve the latest content from the buffer.
159
- #
160
- # @return [Array<Array<Array<Vedeu::Views::Char>>>]
161
- def buffer
162
- swap if back?
168
+ if front?
169
+ [front.render]
163
170
 
164
- if front?
165
- [front.render]
171
+ elsif previous?
172
+ [previous.render]
166
173
 
167
- elsif previous?
168
- [previous.render]
174
+ else
175
+ []
169
176
 
170
- else
171
- []
177
+ end
178
+ end
172
179
 
180
+ # Returns the default options/attributes for this class.
181
+ #
182
+ # @return [Hash<Symbol => NilClass, String>]
183
+ def defaults
184
+ {
185
+ back: nil,
186
+ front: nil,
187
+ name: '',
188
+ previous: nil,
189
+ repository: Vedeu.buffers,
190
+ }
173
191
  end
174
- end
175
192
 
176
- # Returns the default options/attributes for this class.
177
- #
178
- # @return [Hash<Symbol => NilClass, String>]
179
- def defaults
180
- {
181
- back: nil,
182
- front: nil,
183
- name: '',
184
- previous: nil,
185
- repository: Vedeu.buffers,
186
- }
187
- end
188
-
189
- # Return a boolean indicating content was swapped between buffers.
190
- #
191
- # @return [Boolean]
192
- def swap
193
- Vedeu.log(type: :output, message: "Buffer swapping: '#{name}'")
193
+ # Return a boolean indicating content was swapped between buffers.
194
+ #
195
+ # @return [Boolean]
196
+ def swap
197
+ Vedeu.log(type: :output, message: "Buffer swapping: '#{name}'")
194
198
 
195
- @previous = front
196
- @front = back
197
- @back = nil
199
+ @previous = front
200
+ @front = back
201
+ @back = nil
198
202
 
199
- store
203
+ store
204
+
205
+ true
206
+ end
200
207
 
201
- true
202
- end
208
+ end # Buffer
203
209
 
204
- end # Buffer
210
+ end # Buffers
205
211
 
206
212
  end # Vedeu
@@ -1,21 +1,21 @@
1
1
  module Vedeu
2
2
 
3
- module Null
3
+ module Buffers
4
4
 
5
- # Provides a non-existent Vedeu::Buffer that acts like the real thing, but
6
- # does nothing.
5
+ # Provides a non-existent Vedeu::Buffers::Buffer that acts like the real
6
+ # thing, but does nothing.
7
7
  #
8
- class Buffer
8
+ class Null
9
9
 
10
10
  # @!attribute [r] name
11
11
  # @return [String]
12
12
  attr_reader :name
13
13
 
14
- # Returns a new instance of Vedeu::Null::Buffer.
14
+ # Returns a new instance of Vedeu::Buffers::Null.
15
15
  #
16
16
  # @param attributes [Hash<Symbol => void>]
17
17
  # @option attributes name [String|NilClass]
18
- # @return [Vedeu::Null::Buffer]
18
+ # @return [Vedeu::Buffers::Null]
19
19
  def initialize(attributes = {})
20
20
  @attributes = attributes
21
21
  @name = @attributes[:name]
@@ -37,8 +37,8 @@ module Vedeu
37
37
  true
38
38
  end
39
39
 
40
- end # Buffer
40
+ end # Null
41
41
 
42
- end # Null
42
+ end # Buffers
43
43
 
44
44
  end # Vedeu