vedeu 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/docs/borders.md +1 -5
  3. data/docs/cursors.md +23 -92
  4. data/docs/events/application.md +1 -8
  5. data/docs/events/by_name/cleanup.md +7 -0
  6. data/docs/events/by_name/clear.md +2 -0
  7. data/docs/events/by_name/clear_group.md +6 -0
  8. data/docs/events/by_name/clear_view.md +5 -0
  9. data/docs/events/by_name/clear_view_content.md +5 -0
  10. data/docs/events/by_name/command.md +19 -0
  11. data/docs/events/by_name/cursor_bottom.md +7 -0
  12. data/docs/events/by_name/cursor_down.md +4 -0
  13. data/docs/events/by_name/cursor_left.md +6 -0
  14. data/docs/events/by_name/cursor_origin.md +6 -0
  15. data/docs/events/by_name/cursor_position.md +10 -0
  16. data/docs/events/by_name/cursor_reposition.md +4 -0
  17. data/docs/events/by_name/cursor_right.md +4 -0
  18. data/docs/events/by_name/cursor_top.md +7 -0
  19. data/docs/events/by_name/cursor_up.md +6 -0
  20. data/docs/events/by_name/drb_input.md +7 -0
  21. data/docs/events/by_name/drb_restart.md +5 -0
  22. data/docs/events/by_name/drb_retrieve_output.md +2 -0
  23. data/docs/events/by_name/drb_start.md +5 -0
  24. data/docs/events/by_name/drb_status.md +5 -0
  25. data/docs/events/by_name/drb_stop.md +5 -0
  26. data/docs/events/by_name/drb_store_output.md +2 -0
  27. data/docs/events/by_name/editor.md +9 -0
  28. data/docs/events/by_name/editor_delete_character.md +5 -0
  29. data/docs/events/by_name/editor_delete_line.md +5 -0
  30. data/docs/events/by_name/editor_down.md +5 -0
  31. data/docs/events/by_name/editor_execute.md +3 -0
  32. data/docs/events/by_name/editor_insert_character.md +7 -0
  33. data/docs/events/by_name/editor_insert_line.md +5 -0
  34. data/docs/events/by_name/editor_left.md +5 -0
  35. data/docs/events/by_name/editor_right.md +5 -0
  36. data/docs/events/by_name/editor_up.md +5 -0
  37. data/docs/events/by_name/exit.md +6 -0
  38. data/docs/events/by_name/focus_by_name.md +6 -0
  39. data/docs/events/by_name/focus_next.md +6 -0
  40. data/docs/events/by_name/focus_prev.md +6 -0
  41. data/docs/events/by_name/goto.md +8 -0
  42. data/docs/events/by_name/hide_cursor.md +10 -0
  43. data/docs/events/by_name/hide_group.md +5 -0
  44. data/docs/events/by_name/hide_interface.md +5 -0
  45. data/docs/events/by_name/initialize.md +6 -0
  46. data/docs/events/by_name/keypress.md +40 -0
  47. data/docs/events/by_name/log.md +7 -0
  48. data/docs/events/by_name/maximise.md +6 -0
  49. data/docs/events/by_name/menu_bottom.md +4 -0
  50. data/docs/events/by_name/menu_current.md +4 -0
  51. data/docs/events/by_name/menu_deselect.md +4 -0
  52. data/docs/events/by_name/menu_items.md +5 -0
  53. data/docs/events/by_name/menu_next.md +5 -0
  54. data/docs/events/by_name/menu_prev.md +5 -0
  55. data/docs/events/by_name/menu_select.md +4 -0
  56. data/docs/events/by_name/menu_selected.md +4 -0
  57. data/docs/events/by_name/menu_top.md +4 -0
  58. data/docs/events/by_name/menu_view.md +5 -0
  59. data/docs/events/by_name/mode_switch.md +7 -0
  60. data/docs/events/by_name/movement_refresh.md +19 -0
  61. data/docs/events/by_name/refresh.md +9 -0
  62. data/docs/events/by_name/refresh_border.md +5 -0
  63. data/docs/events/by_name/refresh_cursor.md +5 -0
  64. data/docs/events/by_name/refresh_group.md +4 -0
  65. data/docs/events/by_name/refresh_view.md +4 -0
  66. data/docs/events/by_name/refresh_view_content.md +4 -0
  67. data/docs/events/by_name/resize.md +5 -0
  68. data/docs/events/by_name/show_cursor.md +10 -0
  69. data/docs/events/by_name/show_group.md +5 -0
  70. data/docs/events/by_name/show_interface.md +5 -0
  71. data/docs/events/by_name/toggle_cursor.md +9 -0
  72. data/docs/events/by_name/toggle_group.md +5 -0
  73. data/docs/events/by_name/toggle_interface.md +5 -0
  74. data/docs/events/by_name/unmaximise.md +6 -0
  75. data/docs/events/document.md +9 -45
  76. data/docs/events/drb.md +7 -31
  77. data/docs/events/focus.md +3 -18
  78. data/docs/events/menu.md +10 -44
  79. data/docs/events/refresh.md +6 -25
  80. data/docs/events/system.md +8 -101
  81. data/docs/events/view.md +4 -36
  82. data/docs/events/visibility.md +10 -48
  83. data/lib/vedeu/borders/border.rb +117 -37
  84. data/lib/vedeu/borders/refresh.rb +29 -113
  85. data/lib/vedeu/borders/repository.rb +0 -5
  86. data/lib/vedeu/buffers/buffer.rb +13 -17
  87. data/lib/vedeu/buffers/refresh.rb +4 -4
  88. data/lib/vedeu/cursors/refresh.rb +2 -7
  89. data/lib/vedeu/groups/clear.rb +3 -1
  90. data/lib/vedeu/groups/refresh.rb +2 -2
  91. data/lib/vedeu/interfaces/clear.rb +2 -2
  92. data/lib/vedeu/output/refresh.rb +2 -2
  93. data/lib/vedeu/repositories/model.rb +2 -6
  94. data/lib/vedeu/repositories/repository.rb +17 -6
  95. data/lib/vedeu/runtime/flags.rb +2 -0
  96. data/lib/vedeu/version.rb +1 -1
  97. data/test/lib/vedeu/borders/border_test.rb +128 -12
  98. data/test/lib/vedeu/cursors/dsl_test.rb +13 -0
  99. metadata +72 -2
@@ -102,50 +102,15 @@ module Vedeu
102
102
  # @return [Array<Array<Vedeu::Views::Char>>]
103
103
  def output
104
104
  Vedeu.timer("Drawing border: '#{name}'".freeze) do
105
- [top, left, right, bottom].flatten
105
+ [
106
+ (top if top?),
107
+ (left if left?),
108
+ (right if right?),
109
+ (bottom if bottom?),
110
+ ].flatten
106
111
  end
107
112
  end
108
113
 
109
- # Creates the bottom left border character.
110
- #
111
- # @return [NilClass|Vedeu::Cells::Border|Vedeu::Views::Char]
112
- def build_bottom_left
113
- return nil unless left?
114
- return bottom_left if bottom_left
115
-
116
- Vedeu::Cells::BottomLeft.new(attributes)
117
- end
118
-
119
- # Creates the bottom right border character.
120
- #
121
- # @return [NilClass|Vedeu::Cells::Border|Vedeu::Views::Char]
122
- def build_bottom_right
123
- return nil unless right?
124
- return bottom_right if bottom_right
125
-
126
- Vedeu::Cells::BottomRight.new(attributes)
127
- end
128
-
129
- # Creates the top left border character.
130
- #
131
- # @return [NilClass|Vedeu::Cells::Border|Vedeu::Views::Char]
132
- def build_top_left
133
- return nil unless left?
134
- return top_left if top_left
135
-
136
- Vedeu::Cells::TopLeft.new(attributes)
137
- end
138
-
139
- # Creates the top right border character.
140
- #
141
- # @return [NilClass|Vedeu::Cells::Border|Vedeu::Views::Char]
142
- def build_top_right
143
- return nil unless right?
144
- return top_right if top_right
145
-
146
- Vedeu::Cells::TopRight.new(attributes)
147
- end
148
-
149
114
  # Renders the bottom border for the interface.
150
115
  #
151
116
  # @note
@@ -155,9 +120,7 @@ module Vedeu
155
120
  #
156
121
  # @return [String]
157
122
  def bottom
158
- return [] unless bottom?
159
-
160
- [build_bottom_left, captionbar, build_bottom_right].compact
123
+ [(bottom_left if left?), captionbar, (bottom_right if right?)].compact
161
124
  end
162
125
 
163
126
  # Returns the geometry for the interface.
@@ -182,10 +145,8 @@ module Vedeu
182
145
  #
183
146
  # @return [Array<void>]
184
147
  def left
185
- return [] unless left?
186
-
187
148
  build_collection(bordered_height) do |iy|
188
- cell = left_vertical_cell.dup
149
+ cell = left_vertical.dup
189
150
  cell.position = [by + iy, x]
190
151
  cell
191
152
  end
@@ -195,10 +156,8 @@ module Vedeu
195
156
  #
196
157
  # @return [Array<void>]
197
158
  def right
198
- return [] unless right?
199
-
200
159
  build_collection(bordered_height) do |iy|
201
- cell = right_vertical_cell.dup
160
+ cell = right_vertical.dup
202
161
  cell.position = [by + iy, xn]
203
162
  cell
204
163
  end
@@ -213,9 +172,7 @@ module Vedeu
213
172
  #
214
173
  # @return [String]
215
174
  def top
216
- return [] unless top?
217
-
218
- [build_top_left, titlebar, build_top_right].compact
175
+ [(top_left if left?), titlebar, (top_right if right?)].compact
219
176
  end
220
177
 
221
178
  # An optional caption for when the bottom border is to be shown.
@@ -223,20 +180,15 @@ module Vedeu
223
180
  # @return [Array<Vedeu::Views::Char>]
224
181
  # @see [Vedeu::Borders::Caption#render]
225
182
  def captionbar
226
- return build_bottom unless present?(caption)
227
-
228
- Vedeu::Borders::Caption.render(name, caption, build_bottom)
229
- end
230
-
231
- # Creates a bottom border character.
232
- #
233
- # @return [Array<Vedeu::Views::Char>]
234
- def build_bottom
235
- build_collection(bordered_width) do |ix|
236
- cell = bottom_horizontal_cell.dup
183
+ characters = build_collection(bordered_width) do |ix|
184
+ cell = bottom_horizontal.dup
237
185
  cell.position = [yn, bx + ix]
238
186
  cell
239
187
  end
188
+
189
+ return characters unless present?(caption)
190
+
191
+ Vedeu::Borders::Caption.render(name, caption, characters)
240
192
  end
241
193
 
242
194
  # An optional title for when the top border is to be shown.
@@ -244,60 +196,15 @@ module Vedeu
244
196
  # @return [Array<Vedeu::Views::Char>]
245
197
  # @see [Vedeu::Borders::Title#render]
246
198
  def titlebar
247
- return build_top unless present?(title)
248
-
249
- Vedeu::Borders::Title.render(name, title, build_top)
250
- end
251
-
252
- # Creates a top border character.
253
- #
254
- # @return [Array<Vedeu::Views::Char>]
255
- def build_top
256
- build_collection(bordered_width) do |ix|
257
- cell = top_horizontal_cell.dup
199
+ characters = build_collection(bordered_width) do |ix|
200
+ cell = top_horizontal.dup
258
201
  cell.position = [y, bx + ix]
259
202
  cell
260
203
  end
261
- end
262
-
263
- # Return the client application configured left vertical cell
264
- # character, or the default if not set.
265
- #
266
- # @return [Vedeu::Cells::LeftVertical]
267
- def left_vertical_cell
268
- return left_vertical if left_vertical
269
-
270
- Vedeu::Cells::LeftVertical.new(attributes)
271
- end
272
204
 
273
- # Return the client application configured right vertical cell
274
- # character, or the default if not set.
275
- #
276
- # @return [Vedeu::Cells::RightVertical]
277
- def right_vertical_cell
278
- return right_vertical if right_vertical
279
-
280
- Vedeu::Cells::RightVertical.new(attributes)
281
- end
282
-
283
- # Return the client application configured top horizontal cell
284
- # character, or the default if not set.
285
- #
286
- # @return [Vedeu::Cells::TopHorizontal]
287
- def top_horizontal_cell
288
- return top_horizontal if top_horizontal
289
-
290
- Vedeu::Cells::TopHorizontal.new(attributes)
291
- end
292
-
293
- # Return the client application configured bottom horizontal
294
- # cell character, or the default if not set.
295
- #
296
- # @return [Vedeu::Cells::BottomHorizontal]
297
- def bottom_horizontal_cell
298
- return bottom_horizontal if bottom_horizontal
205
+ return characters unless present?(title)
299
206
 
300
- Vedeu::Cells::BottomHorizontal.new(attributes)
207
+ Vedeu::Borders::Title.render(name, title, characters)
301
208
  end
302
209
 
303
210
  # Build a collection with the given size of objects given within
@@ -313,4 +220,13 @@ module Vedeu
313
220
 
314
221
  end # Borders
315
222
 
223
+ # :nocov:
224
+
225
+ # See {file:docs/borders.md#label-3A_refresh_border_}
226
+ Vedeu.bind(:_refresh_border_) do |name|
227
+ Vedeu::Borders::Refresh.by_name(name) if Vedeu.ready?
228
+ end
229
+
230
+ # :nocov:
231
+
316
232
  end # Vedeu
@@ -28,11 +28,6 @@ module Vedeu
28
28
 
29
29
  # :nocov:
30
30
 
31
- # See {file:docs/borders.md#label-3A_refresh_border_}
32
- Vedeu.bind(:_refresh_border_) do |name|
33
- Vedeu::Borders::Refresh.by_name(name)
34
- end
35
-
36
31
  # See {file:docs/borders.md#label-3A_set_border_caption_}
37
32
  Vedeu.bind(:_set_border_caption_) do |name, caption|
38
33
  Vedeu::Borders::SetAttribute.update(name, :title, caption)
@@ -69,9 +69,7 @@ module Vedeu
69
69
  #
70
70
  # @return [Boolean] Whether the buffer targetted has content.
71
71
  def back?
72
- return false if back.nil? || back.lines.empty?
73
-
74
- true
72
+ (back.nil? || back.lines.empty?) ? false : true
75
73
  end
76
74
 
77
75
  # Return a boolean indicating whether the cursor should be
@@ -107,9 +105,7 @@ module Vedeu
107
105
  #
108
106
  # @return [Boolean] Whether the buffer targetted has content.
109
107
  def front?
110
- return false if front.nil? || front.lines.empty?
111
-
112
- true
108
+ (front.nil? || front.lines.empty?) ? false : true
113
109
  end
114
110
 
115
111
  # Return a boolean indicating content presence on the buffer
@@ -117,9 +113,7 @@ module Vedeu
117
113
  #
118
114
  # @return [Boolean] Whether the buffer targetted has content.
119
115
  def previous?
120
- return false if previous.nil? || previous.lines.empty?
121
-
122
- true
116
+ (previous.nil? || previous.lines.empty?) ? false : true
123
117
  end
124
118
 
125
119
  # Retrieve the latest content from the buffer.
@@ -137,18 +131,20 @@ module Vedeu
137
131
  #
138
132
  # @return [Array<Array<Array<Vedeu::Views::Char>>>]
139
133
  def render
140
- if back?
141
- swap
134
+ current = if back?
135
+ swap
142
136
 
143
- Vedeu::Output::Viewport.render(front)
137
+ front
144
138
 
145
- elsif front?
146
- Vedeu::Output::Viewport.render(front)
139
+ elsif front?
140
+ front
147
141
 
148
- elsif previous?
149
- Vedeu::Output::Viewport.render(previous)
142
+ elsif previous?
143
+ previous
150
144
 
151
- end
145
+ end
146
+
147
+ Vedeu::Output::Viewport.render(current) unless current.nil?
152
148
  end
153
149
 
154
150
  # Returns the number of lines of content for the buffer or 0 if
@@ -85,14 +85,14 @@ module Vedeu
85
85
 
86
86
  # :nocov:
87
87
 
88
- # See {file:docs/events/refresh.md#\_refresh_view_}
88
+ # See {file:docs/events/refresh.md}
89
89
  Vedeu.bind(:_refresh_view_) do |name|
90
- Vedeu::Buffers::Refresh.by_name(name)
90
+ Vedeu::Buffers::Refresh.by_name(name) if Vedeu.ready?
91
91
  end
92
92
 
93
- # See {file:docs/events/refresh.md#\_refresh_view_content_}
93
+ # See {file:docs/events/refresh.md}
94
94
  Vedeu.bind(:_refresh_view_content_) do |name|
95
- Vedeu::Buffers::Refresh.refresh_content_by_name(name)
95
+ Vedeu::Buffers::Refresh.refresh_content_by_name(name) if Vedeu.ready?
96
96
  end
97
97
 
98
98
  # :nocov:
@@ -51,7 +51,7 @@ module Vedeu
51
51
  #
52
52
  # @return [Array]
53
53
  def by_name
54
- refresh_view if refresh_view?
54
+ Vedeu.trigger(:_refresh_view_content_, name) if refresh_view?
55
55
 
56
56
  Vedeu.log(type: :cursor,
57
57
  message: "Refreshing cursor: '#{name}' (x:#{x}, y:#{y}, " \
@@ -67,11 +67,6 @@ module Vedeu
67
67
  present?(@name) ? @name : Vedeu.focus
68
68
  end
69
69
 
70
- # @return [void]
71
- def refresh_view
72
- Vedeu.trigger(:_refresh_view_content_, name)
73
- end
74
-
75
70
  # Returns true when the view should be refreshed. This is
76
71
  # determined by checking that the offsets for x and y are
77
72
  # outside the (bordered) width and (bordered) height of the
@@ -103,7 +98,7 @@ module Vedeu
103
98
 
104
99
  # See {file:docs/events/refresh.md#\_refresh_cursor_}
105
100
  Vedeu.bind(:_refresh_cursor_) do |name|
106
- Vedeu::Cursors::Refresh.by_name(name)
101
+ Vedeu::Cursors::Refresh.by_name(name) if Vedeu.ready?
107
102
  end
108
103
 
109
104
  # :nocov:
@@ -67,7 +67,9 @@ module Vedeu
67
67
  # :nocov:
68
68
 
69
69
  # See {file:docs/events/visibility.md#\_clear_group_}
70
- Vedeu.bind(:_clear_group_) { |name| Vedeu.clear_by_group(name) }
70
+ Vedeu.bind(:_clear_group_) do |name|
71
+ Vedeu.clear_by_group(name) if Vedeu.ready?
72
+ end
71
73
 
72
74
  # :nocov:
73
75
 
@@ -77,9 +77,9 @@ module Vedeu
77
77
 
78
78
  # :nocov:
79
79
 
80
- # See {file:docs/events/refresh.md#\_refresh_group_}
80
+ # See {file:docs/events/refresh.md}
81
81
  Vedeu.bind(:_refresh_group_) do |name|
82
- Vedeu::Groups::Refresh.by_name(name)
82
+ Vedeu::Groups::Refresh.by_name(name) if Vedeu.ready?
83
83
  end
84
84
 
85
85
  # :nocov:
@@ -235,11 +235,11 @@ module Vedeu
235
235
  # :nocov:
236
236
 
237
237
  # See {file:docs/events/visibility.md#\_clear_view_}
238
- Vedeu.bind(:_clear_view_) { |name| Vedeu.clear_by_name(name) }
238
+ Vedeu.bind(:_clear_view_) { |name| Vedeu.clear_by_name(name) if Vedeu.ready? }
239
239
 
240
240
  # See {file:docs/events/visibility.md#\_clear_view_content_}
241
241
  Vedeu.bind(:_clear_view_content_) do |name|
242
- Vedeu.clear_content_by_name(name)
242
+ Vedeu.clear_content_by_name(name) if Vedeu.ready?
243
243
  end
244
244
 
245
245
  # :nocov:
@@ -32,8 +32,8 @@ module Vedeu
32
32
 
33
33
  # :nocov:
34
34
 
35
- # See {file:docs/events/refresh.md#\_refresh_}
36
- Vedeu.bind(:_refresh_) { Vedeu::Output::Refresh.all }
35
+ # See {file:docs/events/refresh.md}
36
+ Vedeu.bind(:_refresh_) { Vedeu::Output::Refresh.all if Vedeu.ready? }
37
37
 
38
38
  # :nocov:
39
39
 
@@ -108,12 +108,8 @@ module Vedeu
108
108
  # after yielding.
109
109
  # @todo Perhaps some validation could be added here?
110
110
  # @return [void] The model instance stored in the repository.
111
- def store
112
- new_model = repository.store(self)
113
-
114
- yield if block_given?
115
-
116
- new_model
111
+ def store(&block)
112
+ repository.store(self, &block)
117
113
  end
118
114
 
119
115
  end # Model
@@ -156,20 +156,22 @@ module Vedeu
156
156
  # Stores the model instance by name in the repository of the
157
157
  # model.
158
158
  #
159
+ # @note If a block is given, store the model, return the model
160
+ # after yielding.
159
161
  # @param model [void] A model instance.
160
162
  # @raise [Vedeu::Error::MissingRequired] When the name attribute
161
163
  # is not defined.
162
164
  # @return [void] The model instance which was stored.
163
- def store(model)
164
- unless present?(model.name)
165
- fail Vedeu::Error::MissingRequired,
166
- "Cannot store model '#{model.class}' " \
167
- 'without a name attribute.'.freeze
168
- end
165
+ def store(model, &block)
166
+ valid_model?(model)
169
167
 
170
168
  log_store(model)
171
169
 
172
170
  storage[model.name] = model
171
+
172
+ yield if block_given?
173
+
174
+ model
173
175
  end
174
176
  alias_method :register, :store
175
177
  alias_method :add, :store
@@ -185,6 +187,15 @@ module Vedeu
185
187
  message: "#{model.class.name}: '#{model.name}'".freeze)
186
188
  end
187
189
 
190
+ #
191
+ # @param model [void] A model instance.
192
+ # @return [Boolean]
193
+ def valid_model?(model)
194
+ fail Vedeu::Error::MissingRequired,
195
+ "Cannot store model '#{model.class}' without a name " \
196
+ 'attribute.'.freeze unless present?(model.name)
197
+ end
198
+
188
199
  end # Repository
189
200
 
190
201
  end # Repositories
@@ -12,6 +12,8 @@ module Vedeu
12
12
 
13
13
  # @return [Boolean]
14
14
  def ready!
15
+ Vedeu.log(type: :info, message: 'Vedeu ready!')
16
+
15
17
  instance.options[:ready] = true
16
18
  end
17
19