vedeu 0.6.15 → 0.6.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -60
  3. data/config/rubocop_enabled.yml +6 -1023
  4. data/docs/events/refresh.md +6 -2
  5. data/docs/events/visibility.md +8 -3
  6. data/lib/vedeu.rb +4 -3
  7. data/lib/vedeu/all.rb +3 -2
  8. data/lib/vedeu/api/external.rb +6 -6
  9. data/lib/vedeu/bindings/bindings.rb +3 -3
  10. data/lib/vedeu/bindings/movement.rb +4 -4
  11. data/lib/vedeu/bindings/refresh.rb +9 -9
  12. data/lib/vedeu/bindings/visibility.rb +10 -12
  13. data/lib/vedeu/buffers/buffer.rb +1 -1
  14. data/lib/vedeu/buffers/refresh.rb +1 -1
  15. data/lib/vedeu/colours/repository.rb +1 -0
  16. data/lib/vedeu/colours/translator.rb +2 -6
  17. data/lib/vedeu/common.rb +2 -1
  18. data/lib/vedeu/configuration/api.rb +16 -7
  19. data/lib/vedeu/cursors/cursor.rb +12 -21
  20. data/lib/vedeu/cursors/refresh.rb +1 -1
  21. data/lib/vedeu/dsl/text.rb +21 -18
  22. data/lib/vedeu/dsl/use.rb +13 -11
  23. data/lib/vedeu/dsl/view.rb +52 -46
  24. data/lib/vedeu/editor/cursor.rb +2 -2
  25. data/lib/vedeu/editor/insert.rb +2 -6
  26. data/lib/vedeu/editor/line.rb +3 -8
  27. data/lib/vedeu/editor/lines.rb +1 -12
  28. data/lib/vedeu/events/event.rb +52 -43
  29. data/lib/vedeu/events/trigger.rb +7 -15
  30. data/lib/vedeu/geometry/generic_coordinate.rb +4 -12
  31. data/lib/vedeu/geometry/geometry.rb +1 -1
  32. data/lib/vedeu/input/translator.rb +50 -31
  33. data/lib/vedeu/models/focus.rb +33 -22
  34. data/lib/vedeu/models/group.rb +8 -7
  35. data/lib/vedeu/models/interface.rb +6 -10
  36. data/lib/vedeu/models/toggleable.rb +6 -9
  37. data/lib/vedeu/models/views/char.rb +24 -30
  38. data/lib/vedeu/models/views/html_char.rb +0 -33
  39. data/lib/vedeu/models/views/stream.rb +8 -7
  40. data/lib/vedeu/models/views/view.rb +9 -9
  41. data/lib/vedeu/options.rb +1 -1
  42. data/lib/vedeu/output/clear/all.rb +13 -0
  43. data/lib/vedeu/output/clear/{named_group.rb → group.rb} +4 -7
  44. data/lib/vedeu/output/clear/{named_interface.rb → interface.rb} +4 -7
  45. data/lib/vedeu/output/direct.rb +2 -2
  46. data/lib/vedeu/output/presentation/presentation.rb +10 -7
  47. data/lib/vedeu/output/renderers/all.rb +9 -4
  48. data/lib/vedeu/output/renderers/escape_sequence.rb +1 -1
  49. data/lib/vedeu/output/renderers/file.rb +1 -1
  50. data/lib/vedeu/output/renderers/null.rb +1 -1
  51. data/lib/vedeu/output/renderers/{renderer_options.rb → options.rb} +2 -2
  52. data/lib/vedeu/output/renderers/terminal.rb +1 -1
  53. data/lib/vedeu/output/renderers/text.rb +1 -1
  54. data/lib/vedeu/output/text.rb +4 -8
  55. data/lib/vedeu/output/viewport.rb +2 -6
  56. data/lib/vedeu/output/wordwrap.rb +2 -6
  57. data/lib/vedeu/repositories/repository.rb +9 -22
  58. data/lib/vedeu/runtime/application.rb +2 -6
  59. data/lib/vedeu/templating/view_template.rb +7 -15
  60. data/lib/vedeu/version.rb +1 -1
  61. data/test/lib/vedeu/bindings/bindings_test.rb +32 -6
  62. data/test/lib/vedeu/bindings/refresh_test.rb +1 -0
  63. data/test/lib/vedeu/bindings/visibility_test.rb +1 -0
  64. data/test/lib/vedeu/buffers/buffer_test.rb +2 -2
  65. data/test/lib/vedeu/colours/background_test.rb +0 -18
  66. data/test/lib/vedeu/colours/foreground_test.rb +0 -18
  67. data/test/lib/vedeu/cursors/refresh_test.rb +5 -3
  68. data/test/lib/vedeu/events/aliases_test.rb +0 -6
  69. data/test/lib/vedeu/models/views/view_test.rb +1 -1
  70. data/test/lib/vedeu/output/clear/{named_group_test.rb → group_test.rb} +5 -5
  71. data/test/lib/vedeu/output/clear/{named_interface_test.rb → interface_test.rb} +4 -4
  72. data/test/lib/vedeu/output/renderers/{renderer_options_test.rb → options_test.rb} +2 -2
  73. data/vedeu.gemspec +1 -1
  74. metadata +14 -14
  75. data/config/rubocop_disabled.yml +0 -50
data/lib/vedeu/dsl/use.rb CHANGED
@@ -8,10 +8,10 @@ module Vedeu
8
8
 
9
9
  # Use the attribute of stored model.
10
10
  #
11
- # This DSL method provides access to a stored model by name. You can
12
- # then request an attribute of that model for use within the current
13
- # model. The models which current support this are Border, Geometry and
14
- # Interface.
11
+ # This DSL method provides access to a stored model by name.
12
+ # You can then request an attribute of that model for use within
13
+ # the current model. The models which current support this are
14
+ # Border, Geometry and Interface.
15
15
  #
16
16
  # @example
17
17
  # # Here the character used for 'my_border' is used in
@@ -21,14 +21,16 @@ module Vedeu
21
21
  # end
22
22
  #
23
23
  # @note
24
- # - Only models of the same repository can be used in this way.
25
- # - If the stored model cannot be found, a ModelNotFound exception may
26
- # be raised, or the request for an attribute may raise a
27
- # NoMethodError exception.
24
+ # - Only models of the same repository can be used in this
25
+ # way.
26
+ # - If the stored model cannot be found, a ModelNotFound
27
+ # exception may be raised, or the request for an attribute
28
+ # may raise a NoMethodError exception.
28
29
  #
29
- # @param name [String] The name of the model with the value you wish to
30
- # use.
31
- # @raise [Vedeu::Error::ModelNotFound|Vedeu::Error::NoMethodError]
30
+ # @param name [String] The name of the model with the value you
31
+ # wish to use.
32
+ # @raise
33
+ # [Vedeu::Error::ModelNotFound|Vedeu::Error::NoMethodError]
32
34
  # The model or attribute cannot be found.
33
35
  # @return [void] The stored model.
34
36
  def use(name)
@@ -2,16 +2,18 @@ module Vedeu
2
2
 
3
3
  module DSL
4
4
 
5
- # There are two ways to construct views with Vedeu. You would like to draw
6
- # the view to the screen immediately (immediate render) or you want to save
7
- # a view to be drawn when you trigger a refresh event later (deferred view).
5
+ # There are two ways to construct views with Vedeu. You would like
6
+ # to draw the view to the screen immediately (immediate render) or
7
+ # you want to save a view to be drawn when you trigger a refresh
8
+ # event later (deferred view).
8
9
  #
9
- # Both of these approaches require that you have defined an interface (or
10
- # 'visible area') first. You can find out how to define an interface with
11
- # Vedeu below or in {Vedeu::DSL::Interface}. The examples in 'Immediate
12
- # Render' and 'Deferred View' use these interface definitions: (Note: should
13
- # you use these examples, ensure your terminal is at least 70 characters in
14
- # width and 5 lines in height.)
10
+ # Both of these approaches require that you have defined an
11
+ # interface (or 'visible area') first. You can find out how to
12
+ # define an interface with Vedeu below or in
13
+ # {Vedeu::DSL::Interface}. The examples in 'Immediate Render' and
14
+ # 'Deferred View' use these interface definitions: (Note: should
15
+ # you use these examples, ensure your terminal is at least 70
16
+ # characters in width and 5 lines in height.)
15
17
  #
16
18
  # Vedeu.interface 'main' do
17
19
  # geometry do
@@ -30,26 +32,27 @@ module Vedeu
30
32
  # end
31
33
  # end
32
34
  #
33
- # Both of these approaches use a concept of Buffers in Vedeu. There are
34
- # three buffers for any defined interface. These are imaginatively called:
35
- # 'back', 'front' and 'previous'.
35
+ # Both of these approaches use a concept of Buffers in Vedeu.
36
+ # There are three buffers for any defined interface. These are
37
+ # imaginatively called: 'back', 'front' and 'previous'.
36
38
  #
37
- # The 'back' buffer is the content for an interface which will be shown next
38
- # time a refresh event is fired globally or for that interface. So, 'back'
39
- # becomes 'front'.
39
+ # The 'back' buffer is the content for an interface which will be
40
+ # shown next time a refresh event is fired globally or for that
41
+ # interface. So, 'back' becomes 'front'.
40
42
  #
41
- # The 'front' buffer is the content for an interface which is currently
42
- # showing. When a refresh event is fired, again, globally or for that
43
- # interface specifically, the content of this 'front' buffer is first copied
44
- # to the 'previous' buffer, and then the current 'back' buffer overwrites
45
- # this 'front' buffer.
43
+ # The 'front' buffer is the content for an interface which is
44
+ # currently showing. When a refresh event is fired, again,
45
+ # globally or for that interface specifically, the content of this
46
+ # 'front' buffer is first copied to the 'previous' buffer, and
47
+ # then the current 'back' buffer overwrites this 'front' buffer.
46
48
  #
47
- # The 'previous' buffer contains what was shown on the 'front' before the
48
- # current 'front'.
49
+ # The 'previous' buffer contains what was shown on the 'front'
50
+ # before the current 'front'.
49
51
  #
50
- # You can only write to either the 'front' (you want the content to be drawn
51
- # immediately (immediate render)) or the 'back' (you would like the content
52
- # to be drawn on the next refresh (deferred view)).
52
+ # You can only write to either the 'front' (you want the content
53
+ # to be drawn immediately (immediate render)) or the 'back' (you
54
+ # would like the content to be drawn on the next refresh
55
+ # (deferred view)).
53
56
  #
54
57
  # The basic view DSL methods look like this:
55
58
  #
@@ -91,9 +94,10 @@ module Vedeu
91
94
 
92
95
  include Vedeu::Common
93
96
 
94
- # Directly write a view buffer to the terminal. Using this method means
95
- # that the refresh event does not need to be triggered after creating
96
- # the views, though can be later triggered when needed.
97
+ # Directly write a view buffer to the terminal. Using this
98
+ # method means that the refresh event does not need to be
99
+ # triggered after creating the views, though can be later
100
+ # triggered when needed.
97
101
  #
98
102
  # Vedeu.renders do
99
103
  # view 'some_interface' do
@@ -124,8 +128,9 @@ module Vedeu
124
128
  # end
125
129
  # end
126
130
  #
127
- # @param block [Proc] The directives you wish to send to render.
128
- # Typically includes `view` with associated sub-directives.
131
+ # @param block [Proc] The directives you wish to send to
132
+ # render. Typically includes `view` with associated
133
+ # sub-directives.
129
134
  # @raise [Vedeu::Error::RequiresBlock]
130
135
  # @return [Array<View>]
131
136
  def renders(&block)
@@ -137,15 +142,15 @@ module Vedeu
137
142
 
138
143
  # Define a view (content) for an interface.
139
144
  #
140
- # As you can see by comparing the examples above to these below, the
141
- # immediate render simply wraps what is already here in the deferred
142
- # view.
145
+ # As you can see by comparing the examples above to these
146
+ # below, the immediate render simply wraps what is already
147
+ # here in the deferred view.
143
148
  #
144
- # The views declared within this block are stored in their respective
145
- # interface back buffers until a refresh event occurs. When the refresh
146
- # event is triggered, the back buffers are swapped into the front
147
- # buffers and the content here will be rendered to
148
- # {Vedeu::Terminal#output}.
149
+ # The views declared within this block are stored in their
150
+ # respective interface back buffers until a refresh event
151
+ # occurs. When the refresh event is triggered, the back
152
+ # buffers are swapped into the front buffers and the content
153
+ # here will be rendered to {Vedeu::Terminal#output}.
149
154
  #
150
155
  # Vedeu.views do
151
156
  # view 'some_interface' do
@@ -168,8 +173,9 @@ module Vedeu
168
173
  # # ... some code
169
174
  # end
170
175
  #
171
- # @param block [Proc] The directives you wish to send to render.
172
- # Typically includes `view` with associated sub-directives.
176
+ # @param block [Proc] The directives you wish to send to
177
+ # render. Typically includes `view` with associated
178
+ # sub-directives.
173
179
  # @raise [Vedeu::Error::RequiresBlock]
174
180
  # @return [Array<View>]
175
181
  def views(&block)
@@ -188,8 +194,8 @@ module Vedeu
188
194
  eval('self', block.binding)
189
195
  end
190
196
 
191
- # Creates a new Vedeu::Views::Composition which may contain one or more
192
- # views (Vedeu::Views::View objects).
197
+ # Creates a new Vedeu::Views::Composition which may contain
198
+ # one or more views (Vedeu::Views::View objects).
193
199
  #
194
200
  # @param client [Object]
195
201
  # @param block [Proc]
@@ -198,12 +204,12 @@ module Vedeu
198
204
  Vedeu::Views::Composition.build(client: client, &block)
199
205
  end
200
206
 
201
- # Stores each of the views defined in their respective buffers ready to
202
- # be rendered on next refresh.
207
+ # Stores each of the views defined in their respective buffers
208
+ # ready to be rendered on next refresh.
203
209
  #
204
210
  # @param method [Symbol] An instruction; `:store_immediate` or
205
- # `:store_deferred` which determines whether the view will be shown
206
- # immediately or later respectively.
211
+ # `:store_deferred` which determines whether the view will
212
+ # be shown immediately or later respectively.
207
213
  # @param block [Proc]
208
214
  # @return [Array]
209
215
  def store(method, &block)
@@ -82,7 +82,7 @@ module Vedeu
82
82
  # @return [Vedeu::Editor::Cursor]
83
83
  def left
84
84
  @ox -= 1 unless @ox == 0
85
- @x -= 1
85
+ @x -= 1
86
86
 
87
87
  self
88
88
  end
@@ -121,7 +121,7 @@ module Vedeu
121
121
  # @return [Vedeu::Editor::Cursor]
122
122
  def up
123
123
  @oy -= 1 unless @oy == 0
124
- @y -= 1
124
+ @y -= 1
125
125
 
126
126
  self
127
127
  end
@@ -28,13 +28,9 @@ module Vedeu
28
28
 
29
29
  # @return [Vedeu::Editor::Line|Vedeu::Editor::Lines]
30
30
  def insert
31
- if index
32
- collection.insert(index, entity)
31
+ return collection.insert(index, entity) if index
33
32
 
34
- else
35
- collection << entity
36
-
37
- end
33
+ collection << entity
38
34
  end
39
35
 
40
36
  protected
@@ -16,15 +16,10 @@ module Vedeu
16
16
  # @param line [String|Vedeu::Editor::Line]
17
17
  # @return [Vedeu::Editor::Line]
18
18
  def self.coerce(line)
19
- return line if line.is_a?(self)
19
+ return line if line.is_a?(self)
20
+ return new(line) if line.is_a?(String)
20
21
 
21
- if line.is_a?(String)
22
- new(line)
23
-
24
- else
25
- new
26
-
27
- end
22
+ new
28
23
  end
29
24
 
30
25
  # Returns a new instance of Vedeu::Editor::Line.
@@ -21,18 +21,7 @@ module Vedeu
21
21
  new(document.lines)
22
22
 
23
23
  elsif document.is_a?(Array)
24
- lines = document.map do |line|
25
- if line.is_a?(Vedeu::Editor::Line)
26
- line
27
-
28
- elsif line.is_a?(String)
29
- Vedeu::Editor::Line.coerce(line)
30
-
31
- else
32
- Vedeu::Editor::Line.new
33
-
34
- end
35
- end
24
+ lines = document.map { |line| Vedeu::Editor::Line.coerce(line) }
36
25
 
37
26
  new(lines)
38
27
 
@@ -2,31 +2,30 @@ module Vedeu
2
2
 
3
3
  module Events
4
4
 
5
- # Contains all the logic of an event. Handles debouncing and throttling.
5
+ # Contains all the logic of an event. Handles debouncing and
6
+ # throttling.
6
7
  #
7
- # Vedeu provides an event mechanism to facilitate the functionality of your
8
- # application. The events are either Vedeu defined, ie. system events or
9
- # user defined, ie. user events. User events allow you to orchestrate
10
- # behaviour within your application, ie. the user presses a specific key,
11
- # you trigger an event to make something happen. Eg. pressing 'p' instructs
12
- # the player to play.
8
+ # Vedeu provides an event mechanism to facilitate the
9
+ # functionality of your application. The events are either Vedeu
10
+ # defined, ie. system events or user defined, ie. user events.
11
+ # User events allow you to orchestrate behaviour within your
12
+ # application, ie. the user presses a specific key,
13
+ # you trigger an event to make something happen. Eg. pressing 'p'
14
+ # instructs the player to play.
13
15
  #
14
- # Events described here assume that you have either included Vedeu in your
15
- # class:
16
+ # Events described here assume that you have bound the events
17
+ # within your classes:
16
18
  #
17
19
  # class SomeClassInYourApplication
18
- # include Vedeu
19
- #
20
- # bind :event_name do |arg1, arg2|
21
- # # Things that should happen when the event is triggered; these can
22
- # # be method calls or the triggering of another event or events.
20
+ # Vedeu.bind(:event_name) do |arg1, arg2|
21
+ # # Things that should happen when the event is triggered;
22
+ # # these can be method calls or the triggering of another
23
+ # # event or events.
23
24
  # end
24
25
  #
25
- # or, you are prepared to use the `Vedeu` prefix:
26
- #
27
- # class SomeClassInYourApplication
28
26
  # Vedeu.bind(:event_name) do
29
- # # Not all events you define will have arguments; like methods.
27
+ # # Not all events you define will have arguments; like
28
+ # # methods.
30
29
  # :do_stuff
31
30
  # end
32
31
  #
@@ -36,20 +35,25 @@ module Vedeu
36
35
 
37
36
  class << self
38
37
 
39
- # Register an event by name with optional delay (throttling) which when
40
- # triggered will execute the code contained within the passed block.
38
+ # Register an event by name with optional delay (throttling)
39
+ # which when triggered will execute the code contained within
40
+ # the passed block.
41
41
  #
42
- # @param name [Symbol] The name of the event to be triggered later.
43
- # @param options [Hash] The options to register the event with.
44
- # @option options :delay [Fixnum|Float] Limits the execution of the
45
- # triggered event to only execute when first triggered, with
46
- # subsequent triggering being ignored until the delay has expired.
47
- # @option options :debounce [Fixnum|Float] Limits the execution of the
48
- # triggered event to only execute once the debounce has expired.
49
- # Subsequent triggers before debounce expiry are ignored.
50
- # @param block [Proc] The event to be executed when triggered. This
51
- # block could be a method call, or the triggering of another event, or
52
- # sequence of either/both.
42
+ # @param name [Symbol] The name of the event to be triggered
43
+ # later.
44
+ # @param options [Hash] The options to register the event
45
+ # with.
46
+ # @option options :delay [Fixnum|Float] Limits the execution
47
+ # of the triggered event to only execute when first
48
+ # triggered, with subsequent triggering being ignored until
49
+ # the delay has expired.
50
+ # @option options :debounce [Fixnum|Float] Limits the
51
+ # execution of the triggered event to only execute once the
52
+ # debounce has expired. Subsequent triggers before debounce
53
+ # expiry are ignored.
54
+ # @param block [Proc] The event to be executed when triggered.
55
+ # This block could be a method call, or the triggering of
56
+ # another event, or sequence of either/both.
53
57
  #
54
58
  # @example
55
59
  # Vedeu.bind :my_event do |some, args|
@@ -87,7 +91,8 @@ module Vedeu
87
91
  alias_method :event, :bind
88
92
  alias_method :register, :bind
89
93
 
90
- # Return a boolean indicating whether the named event is registered.
94
+ # Return a boolean indicating whether the named event is
95
+ # registered.
91
96
  #
92
97
  # @example
93
98
  # Vedeu.bound?(:some_event)
@@ -153,7 +158,8 @@ module Vedeu
153
158
  true
154
159
  end
155
160
 
156
- # Triggers the event based on debouncing and throttling conditions.
161
+ # Triggers the event based on debouncing and throttling
162
+ # conditions.
157
163
  #
158
164
  # @param args [Array]
159
165
  # @return [void]
@@ -194,9 +200,9 @@ module Vedeu
194
200
  closure.call(*args)
195
201
  end
196
202
 
197
- # Returns a boolean indicating whether throttling is required for this
198
- # event. Setting the delay option to any value greater than 0 will enable
199
- # throttling.
203
+ # Returns a boolean indicating whether throttling is required
204
+ # for this event. Setting the delay option to any value greater
205
+ # than 0 will enable throttling.
200
206
  #
201
207
  # @return [Boolean]
202
208
  def throttling?
@@ -216,11 +222,12 @@ module Vedeu
216
222
  false
217
223
  end
218
224
 
219
- # Returns a boolean indicating whether debouncing is required for this
220
- # event. Setting the debounce option to any value greater than 0 will
221
- # enable debouncing.
222
- # Sets the deadline for when this event can be executed to a point in the
223
- # future determined by the amount of debounce time left.
225
+ # Returns a boolean indicating whether debouncing is required
226
+ # for this event. Setting the debounce option to any value
227
+ # greater than 0 will enable debouncing.
228
+ # Sets the deadline for when this event can be executed to a
229
+ # point in the future determined by the amount of debounce time
230
+ # left.
224
231
  #
225
232
  # @return [Boolean]
226
233
  def debouncing?
@@ -242,7 +249,8 @@ module Vedeu
242
249
  false
243
250
  end
244
251
 
245
- # Returns a boolean indicating whether this event has a deadline.
252
+ # Returns a boolean indicating whether this event has a
253
+ # deadline.
246
254
  #
247
255
  # @return [Boolean]
248
256
  def deadline?
@@ -263,7 +271,8 @@ module Vedeu
263
271
  options[:delay] || defaults[:delay]
264
272
  end
265
273
 
266
- # Combines the options provided at instantiation with the default values.
274
+ # Combines the options provided at instantiation with the
275
+ # default values.
267
276
  #
268
277
  # @return [Hash]
269
278
  def options
@@ -38,13 +38,9 @@ module Vedeu
38
38
  #
39
39
  # @return [Array]
40
40
  def trigger
41
- if results.one?
42
- results[0]
41
+ return results[0] if results.one?
43
42
 
44
- else
45
- results
46
-
47
- end
43
+ results
48
44
  end
49
45
 
50
46
  protected
@@ -72,17 +68,13 @@ module Vedeu
72
68
  #
73
69
  # @return [Array|Array<Vedeu::Events::Event>]
74
70
  def registered_events
75
- if repository.registered?(name)
76
- repository.find(name)
77
-
78
- else
79
- Vedeu::Events::Aliases.find(name).map do |event_name|
80
- Vedeu::Events::Trigger.trigger(event_name, *args)
81
- end
82
-
83
- []
71
+ return repository.find(name) if repository.registered?(name)
84
72
 
73
+ Vedeu::Events::Aliases.find(name).map do |event_name|
74
+ Vedeu::Events::Trigger.trigger(event_name, *args)
85
75
  end
76
+
77
+ []
86
78
  end
87
79
 
88
80
  end # Trigger