vedeu 0.8.7 → 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/TODO.md +8 -0
  3. data/docs/dsl/by_method/buffer_update.md +3 -1
  4. data/docs/dsl/by_method/buffer_write.md +3 -1
  5. data/docs/dsl/by_method/cursor.md +3 -1
  6. data/docs/dsl/by_method/cursors.md +3 -1
  7. data/docs/dsl/by_method/direct_write.md +3 -1
  8. data/docs/dsl/by_method/log_stderr.md +4 -1
  9. data/docs/dsl/by_method/log_stdout.md +4 -1
  10. data/docs/dsl/by_method/log_timestamp.md +7 -1
  11. data/docs/dsl/by_method/render_output.md +3 -1
  12. data/docs/events/by_name/{geometry_down.md → aliases/geometry_down.md} +0 -0
  13. data/docs/events/by_name/{geometry_left.md → aliases/geometry_left.md} +0 -0
  14. data/docs/events/by_name/{geometry_right.md → aliases/geometry_right.md} +0 -0
  15. data/docs/events/by_name/{geometry_up.md → aliases/geometry_up.md} +0 -0
  16. data/docs/events/by_name/cursor_down.md +5 -0
  17. data/docs/events/by_name/cursor_left.md +3 -0
  18. data/docs/events/by_name/cursor_origin.md +3 -0
  19. data/docs/events/by_name/cursor_right.md +5 -0
  20. data/docs/events/by_name/cursor_top.md +3 -0
  21. data/docs/events/by_name/cursor_up.md +3 -0
  22. data/docs/events/by_name/hide_cursor.md +6 -1
  23. data/docs/events/by_name/maximise.md +2 -3
  24. data/docs/events/by_name/show_cursor.md +6 -1
  25. data/docs/events/by_name/unmaximise.md +5 -3
  26. data/docs/events/by_name/view_down.md +8 -0
  27. data/docs/events/by_name/view_left.md +8 -0
  28. data/docs/events/by_name/view_right.md +8 -0
  29. data/docs/events/by_name/view_up.md +8 -0
  30. data/docs/events/document.md +2 -1
  31. data/docs/events/focus.md +2 -1
  32. data/docs/events/menu.md +2 -1
  33. data/docs/events/movement.md +2 -1
  34. data/docs/events/refresh.md +2 -1
  35. data/docs/events/view.md +2 -1
  36. data/docs/events/visibility.md +2 -1
  37. data/examples/dsl_horizontal_alignment.rb +1 -1
  38. data/examples/dsl_vertical_alignment.rb +1 -1
  39. data/integrations/dsl_app_border_001.rb +63 -0
  40. data/integrations/dsl_app_border_002.rb +63 -0
  41. data/integrations/dsl_app_border_003.rb +63 -0
  42. data/integrations/dsl_app_border_004.rb +63 -0
  43. data/integrations/dsl_app_border_005.rb +63 -0
  44. data/integrations/expected/dsl_app_border_001.out +1 -0
  45. data/integrations/expected/dsl_app_border_002.out +1 -0
  46. data/integrations/expected/dsl_app_border_003.out +1 -0
  47. data/integrations/expected/dsl_app_border_004.out +1 -0
  48. data/integrations/expected/dsl_app_border_005.out +1 -0
  49. data/integrations/test_runner.sh +7 -0
  50. data/lib/vedeu.rb +2 -1
  51. data/lib/vedeu/borders/repository.rb +1 -5
  52. data/lib/vedeu/cursors/cursor.rb +29 -70
  53. data/lib/vedeu/cursors/move.rb +11 -4
  54. data/lib/vedeu/cursors/reposition.rb +2 -2
  55. data/lib/vedeu/cursors/repository.rb +7 -12
  56. data/lib/vedeu/dsl/elements.rb +0 -1
  57. data/lib/vedeu/error.rb +17 -5
  58. data/lib/vedeu/geometries/dsl/dsl.rb +2 -28
  59. data/lib/vedeu/geometries/dsl/grid.rb +2 -0
  60. data/lib/vedeu/geometries/geometry.rb +2 -22
  61. data/lib/vedeu/geometries/move.rb +45 -10
  62. data/lib/vedeu/geometries/repository.rb +0 -20
  63. data/lib/vedeu/input/capture.rb +2 -1
  64. data/lib/vedeu/logging/log.rb +25 -25
  65. data/lib/vedeu/renderers/file.rb +0 -5
  66. data/lib/vedeu/renderers/json.rb +1 -1
  67. data/lib/vedeu/renderers/options.rb +3 -1
  68. data/lib/vedeu/renderers/text.rb +0 -7
  69. data/lib/vedeu/runtime/bootstrap.rb +1 -1
  70. data/lib/vedeu/runtime/launcher.rb +8 -5
  71. data/lib/vedeu/version.rb +1 -1
  72. data/test/lib/vedeu/application/application_controller_test.rb +2 -4
  73. data/test/lib/vedeu/cursors/cursor_test.rb +9 -12
  74. data/test/lib/vedeu/cursors/move_test.rb +7 -3
  75. data/test/lib/vedeu/geometries/move_test.rb +22 -9
  76. data/test/lib/vedeu/interfaces/interface_test.rb +71 -73
  77. data/test/lib/vedeu/logging/log_test.rb +1 -1
  78. data/test/lib/vedeu/runtime/launcher_test.rb +5 -4
  79. data/test/support/examples/material_colours_app.rb +59 -8
  80. data/test/test_helper.rb +1 -0
  81. metadata +16 -6
@@ -67,8 +67,8 @@ module Vedeu
67
67
 
68
68
  # Determine correct x and y related coordinates.
69
69
  #
70
- # @param offset []
71
- # @param type []
70
+ # @param offset [Fixnum]
71
+ # @param type [Symbol]
72
72
  # @return [Vedeu::Cursors::Coordinate]
73
73
  def coordinate(offset, type)
74
74
  Vedeu::Cursors::Coordinate.new(name: name,
@@ -12,11 +12,7 @@ module Vedeu
12
12
 
13
13
  class << self
14
14
 
15
- # Fetch the cursor of the currently focussed interface/view.
16
- #
17
- # @example
18
- # Vedeu.cursor
19
- #
15
+ # {include:file:docs/dsl/by_method/cursor.md}
20
16
  # @return [NilClass|Vedeu::Cursors::Cursor]
21
17
  def cursor
22
18
  cursors.by_name
@@ -37,17 +33,16 @@ module Vedeu
37
33
 
38
34
  end # Cursors
39
35
 
40
- # Manipulate the repository of cursors.
41
- #
42
- # @example
43
- # Vedeu.cursors
44
- #
36
+ # {include:file:docs/dsl/by_method/cursors.md}
45
37
  # @!method cursors
46
38
  # @return [Vedeu::Cursors::Repository]
39
+ def_delegators Vedeu::Cursors::Repository,
40
+ :cursors
41
+
42
+ # {include:file:docs/dsl/by_method/cursor.md}
47
43
  # @!method cursor
48
44
  # @see Vedeu::Cursors::Repository.cursor
49
45
  def_delegators Vedeu::Cursors::Repository,
50
- :cursor,
51
- :cursors
46
+ :cursor
52
47
 
53
48
  end # Vedeu
@@ -167,7 +167,6 @@ module Vedeu
167
167
  else
168
168
  s = Vedeu::Views::Stream.new(attrs)
169
169
  ss = Vedeu::Views::Streams.coerce([s])
170
-
171
170
  Vedeu::Views::Line.new(attrs.merge!(value: ss))
172
171
 
173
172
  end
@@ -24,11 +24,18 @@ module Vedeu
24
24
  end # ControllerNotFound
25
25
 
26
26
  # Raised when Vedeu encounters an error it cannot recover from.
27
- # This would happen if there was not interfaces, or specifically
28
- # if there were no entries in {Vedeu::Models::Focus}, since the
29
- # fallback for most of the system when a name is not given or
30
- # cannot be found is to use the name of the currently focussed
31
- # interface.
27
+ # Generally, all Vedeu exceptions are fatal- however, fatal here
28
+ # means that it is not known how to recover from an error.
29
+ #
30
+ # If you encounter a `Vedeu::Error::Fatal` error and the error
31
+ # message is insufficient to help you, please raise an issue so
32
+ # that we can attempt to accommodate your intentions.
33
+ #
34
+ # An example of this would happen if there was no interfaces, or
35
+ # specifically if there were no entries in {Vedeu::Models::Focus},
36
+ # since the fallback for most of the system when a name is not
37
+ # given or cannot be found is to use the name of the currently
38
+ # focussed interface.
32
39
  #
33
40
  class Fatal < StandardError
34
41
 
@@ -105,6 +112,11 @@ module Vedeu
105
112
  #
106
113
  # @see Vedeu::Geometries::Grid
107
114
  #
115
+ # @!macro [new] raise_out_of_range
116
+ # @raise [Vedeu::Error::OutOfRange] When the value given for
117
+ # an argument or parameter cannot be used because it is
118
+ # outside the allowed range.
119
+ #
108
120
  class OutOfRange < StandardError
109
121
 
110
122
  # Returns an error message.
@@ -139,10 +139,6 @@ module Vedeu
139
139
  # # ... some code
140
140
  # end
141
141
  #
142
- # @note
143
- # Vedeu.width in the example above will set the width to the
144
- # default width of the terminal, this can be substituted for
145
- # your own positive integer.
146
142
  # @param height [Fixnum] The number of lines/rows.
147
143
  # @return [Vedeu::Geometries::Geometry]
148
144
  def align_bottom(height = nil)
@@ -166,10 +162,6 @@ module Vedeu
166
162
  #
167
163
  # # Also allows `align_center` if preferred.
168
164
  #
169
- # @note
170
- # Vedeu.height in the example above will set the height to the
171
- # default height of the terminal, this can be substituted for
172
- # your own positive integer.
173
165
  # @param width [Fixnum] The number of characters/columns.
174
166
  # @return [Vedeu::Geometries::Geometry]
175
167
  def align_centre(width = nil)
@@ -192,10 +184,6 @@ module Vedeu
192
184
  # # ... some code
193
185
  # end
194
186
  #
195
- # @note
196
- # Vedeu.height in the example above will set the height to the
197
- # default height of the terminal, this can be substituted for
198
- # your own positive integer.
199
187
  # @param width [Fixnum] The number of characters/columns.
200
188
  # @return [Vedeu::Geometries::Geometry]
201
189
  def align_left(width = nil)
@@ -218,10 +206,6 @@ module Vedeu
218
206
  # # ... some code
219
207
  # end
220
208
  #
221
- # @note
222
- # Vedeu.width in the example above will set the width to the
223
- # default width of the terminal, this can be substituted for
224
- # your own positive integer.
225
209
  # @param height [Fixnum] The number of lines/rows.
226
210
  # @return [Vedeu::Geometries::Geometry]
227
211
  def align_middle(height = nil)
@@ -243,10 +227,6 @@ module Vedeu
243
227
  # # ... some code
244
228
  # end
245
229
  #
246
- # @note
247
- # Vedeu.height in the example above will set the height to the
248
- # default height of the terminal, this can be substituted for
249
- # your own positive integer.
250
230
  # @param width [Fixnum] The number of characters/columns.
251
231
  # @return [Vedeu::Geometries::Geometry]
252
232
  def align_right(width = nil)
@@ -269,10 +249,6 @@ module Vedeu
269
249
  # # ... some code
270
250
  # end
271
251
  #
272
- # @note
273
- # Vedeu.width in the example above will set the width to the
274
- # default width of the terminal, this can be substituted for
275
- # your own positive integer.
276
252
  # @param height [Fixnum] The number of lines/rows.
277
253
  # @return [Vedeu::Geometries::Geometry]
278
254
  def align_top(height = nil)
@@ -291,8 +267,7 @@ module Vedeu
291
267
  # end
292
268
  #
293
269
  # @param value [Fixnum]
294
- # @raise [Vedeu::Error::OutOfRange] When the value parameter is
295
- # not between 1 and 12 inclusive.
270
+ # @macro raise_out_of_range
296
271
  # @return [Fixnum|Vedeu::Error::OutOfRange]
297
272
  def columns(value)
298
273
  Vedeu::Geometries::Grid.columns(value)
@@ -325,8 +300,7 @@ module Vedeu
325
300
  # end
326
301
  #
327
302
  # @param value [Fixnum]
328
- # @raise [Vedeu::Error::OutOfRange] When the value parameter is
329
- # not between 1 and 12 inclusive.
303
+ # @macro raise_out_of_range
330
304
  # @return [Fixnum]
331
305
  def rows(value)
332
306
  Vedeu::Geometries::Grid.rows(value)
@@ -33,6 +33,7 @@ module Vedeu
33
33
  @value = value
34
34
  end
35
35
 
36
+ # @macro raise_out_of_range
36
37
  # @see Vedeu::Geometries::DSL#columns
37
38
  def columns
38
39
  fail Vedeu::Error::OutOfRange if out_of_range?
@@ -40,6 +41,7 @@ module Vedeu
40
41
  column * value
41
42
  end
42
43
 
44
+ # @macro raise_out_of_range
43
45
  # @see Vedeu::Geometries::DSL#rows
44
46
  def rows
45
47
  fail Vedeu::Error::OutOfRange if out_of_range?
@@ -147,12 +147,7 @@ module Vedeu
147
147
  end
148
148
  alias == eql?
149
149
 
150
- # Will maximise the named interface geometry. This means it will
151
- # occupy all of the available space on the terminal window.
152
- #
153
- # @example
154
- # Vedeu.trigger(:_maximise_, name)
155
- #
150
+ # {include:file:docs/events/by_name/maximise.md}
156
151
  # @return [Vedeu::Geometries::Geometry|NilClass]
157
152
  def maximise
158
153
  return self if maximised?
@@ -165,15 +160,7 @@ module Vedeu
165
160
  end
166
161
  end
167
162
 
168
- # Will unmaximise the named interface geometry. Previously, when
169
- # a geometry was maximised, then triggering the unmaximise event
170
- # will return it to its usual defined size (terminal size
171
- # permitting: when the terminal has been resized, then the new
172
- # geometry size should adapt).
173
- #
174
- # @example
175
- # Vedeu.trigger(:_unmaximise_, name)
176
- #
163
+ # {include:file:docs/events/by_name/unmaximise.md}
177
164
  # @return [Vedeu::Geometries::Geometry|NilClass]
178
165
  def unmaximise
179
166
  return self unless maximised?
@@ -183,18 +170,11 @@ module Vedeu
183
170
  store do
184
171
  Vedeu.trigger(:_clear_)
185
172
  Vedeu.trigger(:_refresh_)
186
- Vedeu.trigger(:_refresh_view_, name)
187
173
  end
188
174
  end
189
175
 
190
176
  private
191
177
 
192
- # @todo Investigate the differences between memoizing this and
193
- # not memoizing. Memoizing saves ~80ms on running test suite
194
- # and considerably impacts app responsiveness, however changes
195
- # to the geometry (such as movement or maximising) are not
196
- # reflected. (GL: 2016-01-11)
197
- #
198
178
  # @return [Vedeu::Geometries::Area]
199
179
  def area
200
180
  Vedeu::Geometries::Area.from_attributes(area_attributes)
@@ -41,7 +41,7 @@ module Vedeu
41
41
 
42
42
  Vedeu::Geometries::Geometry.store(new_attributes) do
43
43
  update_cursor!
44
- refresh!
44
+ Vedeu.trigger(:_movement_refresh_, name)
45
45
  end
46
46
  end
47
47
 
@@ -87,7 +87,7 @@ module Vedeu
87
87
  end
88
88
 
89
89
  # @return [Hash<Symbol => Symbol>]
90
- def event
90
+ def cursor_event
91
91
  {
92
92
  down: :_cursor_down_,
93
93
  left: :_cursor_left_,
@@ -129,13 +129,6 @@ module Vedeu
129
129
  }
130
130
  end
131
131
 
132
- # Refresh the screen after moving.
133
- #
134
- # @return [void]
135
- def refresh!
136
- Vedeu.trigger(:_movement_refresh_, name)
137
- end
138
-
139
132
  # Moves the geometry right by the offset.
140
133
  #
141
134
  # @return [Hash<Symbol => Fixnum]
@@ -169,7 +162,13 @@ module Vedeu
169
162
  #
170
163
  # @return [void]
171
164
  def update_cursor!
172
- Vedeu.trigger(event, name)
165
+ if direction == :origin
166
+ Vedeu.trigger(cursor_event, name)
167
+
168
+ else
169
+ Vedeu.trigger(cursor_event, name, 0)
170
+
171
+ end
173
172
  end
174
173
 
175
174
  # @return [Boolean]
@@ -207,4 +206,40 @@ module Vedeu
207
206
 
208
207
  end # Geometries
209
208
 
209
+ # :nocov:
210
+
211
+ # {include:file:docs/events/by_name/movement_refresh.md}
212
+ Vedeu.bind(:_movement_refresh_) do |name|
213
+ Vedeu.trigger(:_clear_)
214
+ Vedeu.trigger(:_refresh_)
215
+ Vedeu.trigger(:_clear_view_, name)
216
+ Vedeu.trigger(:_refresh_view_, name)
217
+ end
218
+
219
+ # {include:file:docs/events/by_name/view_down.md}
220
+ Vedeu.bind(:_view_down_) do |name, offset|
221
+ Vedeu::Geometries::Move.move(name: name, offset: offset, direction: :down)
222
+ end
223
+
224
+ # {include:file:docs/events/by_name/view_left.md}
225
+ Vedeu.bind(:_view_left_) do |name, offset|
226
+ Vedeu::Geometries::Move.move(name: name, offset: offset, direction: :left)
227
+ end
228
+
229
+ # {include:file:docs/events/by_name/view_right.md}
230
+ Vedeu.bind(:_view_right_) do |name, offset|
231
+ Vedeu::Geometries::Move.move(name: name, offset: offset, direction: :right)
232
+ end
233
+
234
+ # {include:file:docs/events/by_name/view_up.md}
235
+ Vedeu.bind(:_view_up_) do |name, offset|
236
+ Vedeu::Geometries::Move.move(name: name, offset: offset, direction: :up)
237
+ end
238
+
239
+ [:down, :left, :right, :up].each do |direction|
240
+ Vedeu.bind_alias(:"_geometry_#{direction}_", :"_view_#{direction}_")
241
+ end
242
+
243
+ # :nocov:
244
+
210
245
  end # Vedeu
@@ -35,31 +35,11 @@ module Vedeu
35
35
  Vedeu.geometries.by_name(name).maximise
36
36
  end
37
37
 
38
- # See {file:docs/events/view.md#\_movement_refresh_}
39
- Vedeu.bind(:_movement_refresh_) do |name|
40
- Vedeu.trigger(:_clear_)
41
- Vedeu.trigger(:_refresh_)
42
- Vedeu.trigger(:_clear_view_, name)
43
- Vedeu.trigger(:_refresh_view_, name)
44
- end
45
-
46
38
  # See {file:docs/events/view.md#\_unmaximise_}
47
39
  Vedeu.bind(:_unmaximise_) do |name|
48
40
  Vedeu.geometries.by_name(name).unmaximise
49
41
  end
50
42
 
51
- [:down, :left, :right, :up].each do |direction|
52
- Vedeu.bind(:"_view_#{direction}_") do |name, offset|
53
- Vedeu::Geometries::Move.move(direction: direction,
54
- name: name,
55
- offset: offset)
56
- end
57
- end
58
-
59
- [:down, :left, :right, :up].each do |direction|
60
- Vedeu.bind_alias(:"_geometry_#{direction}_", :"_view_#{direction}_")
61
- end
62
-
63
43
  # :nocov:
64
44
 
65
45
  end # Vedeu
@@ -2,7 +2,8 @@
2
2
 
3
3
  module Vedeu
4
4
 
5
- ESCAPE_KEY_CODE = 27 # \e
5
+ # \e
6
+ ESCAPE_KEY_CODE = 27
6
7
 
7
8
  module Input
8
9
 
@@ -6,6 +6,12 @@ module Vedeu
6
6
 
7
7
  # Provides the ability to log anything to the Vedeu log file.
8
8
  #
9
+ # @!macro [new] vedeu_logging_log_param_message
10
+ # @param message [String] The message you wish to emit, useful
11
+ # for debugging.
12
+ #
13
+ # @api public
14
+ #
9
15
  class Log
10
16
 
11
17
  class << self
@@ -16,8 +22,7 @@ module Vedeu
16
22
  # Vedeu.log(type: :debug,
17
23
  # message: 'A useful debugging message: Error!')
18
24
  #
19
- # @param message [String] The message you wish to emit to the
20
- # log file, useful for debugging.
25
+ # @macro vedeu_logging_log_param_message
21
26
  # @param force [Boolean] When evaluates to true will attempt
22
27
  # to write to the log file regardless of the Configuration
23
28
  # setting.
@@ -33,29 +38,29 @@ module Vedeu
33
38
  end
34
39
  end
35
40
 
36
- # Write a message to STDOUT.
37
- #
38
- # @example
39
- # Vedeu.log_stdout
40
- #
41
+ # {include:file:docs/dsl/by_method/log_stdout.md}
42
+ # @macro vedeu_logging_log_param_message
43
+ # @param type [Symbol] See {Vedeu::Logging::Log.message_types}
44
+ # for valid values.
41
45
  # @return [String]
42
- def log_stdout(type: :info, message:)
46
+ def log_stdout(message:, type: :info)
47
+ log(message: message, type: type)
48
+
43
49
  $stdout.puts log_entry(type, message)
44
50
  end
45
51
 
46
- # Write a message to STDERR.
47
- #
48
- # @example
49
- # Vedeu.log_stderr
50
- #
52
+ # {include:file:docs/dsl/by_method/log_stderr.md}
53
+ # @macro vedeu_logging_log_param_message
54
+ # @param type [Symbol] See {Vedeu::Logging::Log.message_types}
55
+ # for valid values.
51
56
  # @return [String]
52
- def log_stderr(type: :info, message:)
57
+ def log_stderr(message:, type: :error)
58
+ log(message: message, type: type)
59
+
53
60
  $stderr.puts log_entry(type, message)
54
61
  end
55
62
 
56
- # Returns a formatted timestamp.
57
- # eg. [137.7824]
58
- #
63
+ # {include:file:docs/dsl/by_method/log_timestamp.md}
59
64
  # @return [String]
60
65
  def timestamp
61
66
  @now = Vedeu.clock_time
@@ -82,12 +87,8 @@ module Vedeu
82
87
  end
83
88
  end
84
89
 
85
- # Returns the message with timestamp.
86
- #
87
- # [ 0.0987] [debug] Something happened.
88
- #
89
- # @param message [String] The message type and message
90
- # coloured and combined.
90
+ # {include:file:docs/api/by_method/log_timestamp.md}
91
+ # @macro vedeu_logging_log_param_message
91
92
  # @return [String]
92
93
  def formatted_message(message)
93
94
  "#{timestamp}#{message}\n" if message
@@ -98,8 +99,7 @@ module Vedeu
98
99
  # [type] message
99
100
  #
100
101
  # @param type [Symbol] The type of log message.
101
- # @param message [String] The message you wish to emit to the
102
- # log file, useful for debugging.
102
+ # @macro vedeu_logging_log_param_message
103
103
  # @return [String]
104
104
  def log_entry(type, message)
105
105
  colours = message_types.fetch(type, [:default, :default])