vedeu 0.6.30 → 0.6.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +0 -3
  3. data/lib/vedeu/all.rb +0 -3
  4. data/lib/vedeu/borders/border.rb +3 -7
  5. data/lib/vedeu/borders/refresh.rb +4 -0
  6. data/lib/vedeu/buffers/refresh.rb +4 -0
  7. data/lib/vedeu/cursors/cursor.rb +46 -36
  8. data/lib/vedeu/cursors/refresh.rb +4 -0
  9. data/lib/vedeu/distributed/server.rb +4 -0
  10. data/lib/vedeu/editor/editor.rb +4 -0
  11. data/lib/vedeu/editor/repository.rb +4 -0
  12. data/lib/vedeu/events/event.rb +6 -1
  13. data/lib/vedeu/geometry/all.rb +1 -1
  14. data/lib/vedeu/geometry/coordinate.rb +138 -36
  15. data/lib/vedeu/geometry/dimension.rb +7 -0
  16. data/lib/vedeu/geometry/repository.rb +4 -0
  17. data/lib/vedeu/groups/clear.rb +4 -0
  18. data/lib/vedeu/groups/group.rb +4 -0
  19. data/lib/vedeu/groups/refresh.rb +4 -0
  20. data/lib/vedeu/input/mapper.rb +18 -0
  21. data/lib/vedeu/interfaces/interface.rb +4 -0
  22. data/lib/vedeu/logging/log.rb +6 -2
  23. data/lib/vedeu/menus/repository.rb +4 -0
  24. data/lib/vedeu/models/focus.rb +4 -0
  25. data/lib/vedeu/output/clear/interface.rb +4 -0
  26. data/lib/vedeu/output/refresh/refresh.rb +4 -0
  27. data/lib/vedeu/runtime/application.rb +10 -0
  28. data/lib/vedeu/runtime/flags.rb +4 -0
  29. data/lib/vedeu/runtime/launcher.rb +0 -2
  30. data/lib/vedeu/runtime/router.rb +4 -0
  31. data/lib/vedeu/terminal/buffer.rb +4 -0
  32. data/lib/vedeu/terminal/terminal.rb +4 -0
  33. data/lib/vedeu/version.rb +1 -1
  34. data/test/lib/vedeu/borders/border_test.rb +0 -1
  35. data/test/lib/vedeu/geometry/coordinate.rb +167 -0
  36. data/test/lib/vedeu/input/mapper_test.rb +2 -0
  37. data/test/lib/vedeu/output/presentation/styles_test.rb +0 -1
  38. data/test/lib/vedeu/runtime/application_test.rb +1 -0
  39. data/test/test_helper.rb +1 -1
  40. data/vedeu.gemspec +1 -1
  41. metadata +6 -15
  42. data/lib/vedeu/bindings/all.rb +0 -64
  43. data/lib/vedeu/geometry/generic_coordinate.rb +0 -169
  44. data/lib/vedeu/options.rb +0 -22
  45. data/test/lib/vedeu/bindings/all_test.rb +0 -19
  46. data/test/lib/vedeu/geometry/coordinate_test.rb +0 -135
  47. data/test/lib/vedeu/geometry/generic_coordinate_test.rb +0 -45
  48. data/test/lib/vedeu/options_test.rb +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea4a90f4f35a50a9277083e0f25eb794c4bde66f
4
- data.tar.gz: f88025c5b2d624ff2cd1f66ec06e52465157ea22
3
+ metadata.gz: e129ccc6fe63f7b1f7b48ab9030683d79fe8544c
4
+ data.tar.gz: fab4cf9d158706ff5670b11c59bfaf1f03710683
5
5
  SHA512:
6
- metadata.gz: 346ade00d603a72378c0da55b48650c87335ededb334f576ebee3fb0c1249c66af74574aa90bd4ebe21e38eb651b7862b523ebe2e536a7734c057fa09c500718
7
- data.tar.gz: cba34e4d351846db0e2d08de4f125a25674d8430badf95e4820db70ed8fa66b502476ad8e1499f758f19d50029bb9907253024ea15172b66d918784fe4d80a16
6
+ metadata.gz: f76de0943d7be6e18efc10e248acac5232be21608228f45766a4815dd9e6bda0488dc7d304793fa6dea38aceadbf8bbcbba2694fe9763aff645db8d7b8f37b58
7
+ data.tar.gz: 8e9ef60497f7132a022a87d8223dddb9b3e486f3887ada7ffc276143dab0dc4c35341a141104eb2c8e5b4621ced3d1de2d00517bfa1aa315b75da4ae9b355f42
data/.codeclimate.yml CHANGED
@@ -1,6 +1,3 @@
1
- engines:
2
- rubocop:
3
- enabled: true
4
1
  ratings:
5
2
  paths:
6
3
  - lib/**
data/lib/vedeu/all.rb CHANGED
@@ -7,7 +7,6 @@ require 'vedeu/repositories/all'
7
7
  require 'vedeu/events/all'
8
8
  require 'vedeu/esc/all'
9
9
  require 'vedeu/logging/all'
10
- require 'vedeu/options'
11
10
  require 'vedeu/error'
12
11
  require 'vedeu/runtime/all'
13
12
  require 'vedeu/terminal/all'
@@ -42,6 +41,4 @@ require 'vedeu/input/all'
42
41
  require 'vedeu/interfaces/all'
43
42
  require 'vedeu/menus/all'
44
43
  require 'vedeu/templating/all'
45
-
46
- require 'vedeu/bindings/all'
47
44
  require 'vedeu/plugins/all'
@@ -25,10 +25,6 @@ module Vedeu
25
25
  :y,
26
26
  :yn
27
27
 
28
- # @!attribute [rw] attributes
29
- # @return [Hash]
30
- attr_accessor :attributes
31
-
32
28
  # @!attribute [rw] bottom_left
33
29
  # @return [String]
34
30
  attr_accessor :bottom_left
@@ -148,9 +144,9 @@ module Vedeu
148
144
  parent: @parent,
149
145
  repository: @repository,
150
146
  show_bottom: @show_bottom,
151
- show_left: @show_,
152
- show_right: @show_,
153
- show_top: @show_,
147
+ show_left: @show_left,
148
+ show_right: @show_right,
149
+ show_top: @show_top,
154
150
  style: @style,
155
151
  title: @title,
156
152
  top_left: @top_left,
@@ -362,9 +362,13 @@ module Vedeu
362
362
 
363
363
  end # Borders
364
364
 
365
+ # :nocov:
366
+
365
367
  # See {file:docs/events/refresh.md#\_refresh_border_}
366
368
  Vedeu.bind(:_refresh_border_) do |name|
367
369
  Vedeu::Borders::Refresh.by_name(name)
368
370
  end
369
371
 
372
+ # :nocov:
373
+
370
374
  end # Vedeu
@@ -74,6 +74,8 @@ module Vedeu
74
74
 
75
75
  end # Buffers
76
76
 
77
+ # :nocov:
78
+
77
79
  # See {file:docs/events/refresh.md#\_refresh_view_}
78
80
  Vedeu.bind(:_refresh_view_) do |name|
79
81
  Vedeu::Buffers::Refresh.by_name(name)
@@ -84,4 +86,6 @@ module Vedeu
84
86
  Vedeu::Buffers::Refresh.refresh_content_by_name(name)
85
87
  end
86
88
 
89
+ # :nocov:
90
+
87
91
  end # Vedeu
@@ -17,10 +17,6 @@ module Vedeu
17
17
  :by,
18
18
  :byn
19
19
 
20
- # @!attribute [r] attributes
21
- # @return [Hash]
22
- attr_reader :attributes
23
-
24
20
  # @!attribute [r] name
25
21
  # @return [String|Symbol]
26
22
  attr_reader :name
@@ -43,7 +39,7 @@ module Vedeu
43
39
 
44
40
  # @param (see #initialize)
45
41
  # @return [Vedeu::Cursors::Cursor]
46
- def self.store(attributes)
42
+ def self.store(attributes = {})
47
43
  new(attributes).store
48
44
  end
49
45
 
@@ -64,13 +60,24 @@ module Vedeu
64
60
  # the cursor.
65
61
  # @return [Vedeu::Cursors::Cursor]
66
62
  def initialize(attributes = {})
67
- @attributes = defaults.merge!(attributes)
68
-
69
- @attributes.each do |key, value|
63
+ defaults.merge!(attributes).each do |key, value|
70
64
  instance_variable_set("@#{key}", value)
71
65
  end
72
66
  end
73
67
 
68
+ # @return [Hash]
69
+ def attributes
70
+ {
71
+ name: @name,
72
+ ox: ox,
73
+ oy: oy,
74
+ repository: @repository,
75
+ visible: @visible,
76
+ x: x,
77
+ y: y,
78
+ }
79
+ end
80
+
74
81
  # An object is equal when its values are the same.
75
82
  #
76
83
  # @param other [Vedeu::Cursors::Cursor]
@@ -88,9 +95,9 @@ module Vedeu
88
95
  # @return [Vedeu::Cursors::Cursor]
89
96
  def move_down
90
97
  @oy += 1
98
+ @y = coordinate(oy, :y).y
91
99
 
92
- Vedeu::Cursors::Cursor.store(
93
- new_attributes(coordinate.y_position, x, oy, ox))
100
+ store
94
101
  end
95
102
 
96
103
  # Moves the cursor left by one column.
@@ -101,9 +108,9 @@ module Vedeu
101
108
  # @return [Vedeu::Cursors::Cursor]
102
109
  def move_left
103
110
  @ox -= 1
111
+ @x = coordinate(ox, :x).x
104
112
 
105
- Vedeu::Cursors::Cursor.store(
106
- new_attributes(y, coordinate.x_position, oy, ox))
113
+ store
107
114
  end
108
115
 
109
116
  # Moves the cursor to the top left of the named interface.
@@ -113,8 +120,12 @@ module Vedeu
113
120
  #
114
121
  # @return [Vedeu::Cursors::Cursor]
115
122
  def move_origin
116
- Vedeu::Cursors::Cursor.store(
117
- attributes.merge!(x: bx, y: by, ox: 0, oy: 0))
123
+ @x = bx
124
+ @y = by
125
+ @ox = 0
126
+ @oy = 0
127
+
128
+ store
118
129
  end
119
130
 
120
131
  # Moves the cursor right by one column.
@@ -125,9 +136,9 @@ module Vedeu
125
136
  # @return [Vedeu::Cursors::Cursor]
126
137
  def move_right
127
138
  @ox += 1
139
+ @x = coordinate(ox, :x).x
128
140
 
129
- Vedeu::Cursors::Cursor.store(
130
- new_attributes(y, coordinate.x_position, oy, ox))
141
+ store
131
142
  end
132
143
 
133
144
  # Moves the cursor up by one row.
@@ -138,9 +149,9 @@ module Vedeu
138
149
  # @return [Vedeu::Cursors::Cursor]
139
150
  def move_up
140
151
  @oy -= 1
152
+ @y = coordinate(oy, :y).y
141
153
 
142
- Vedeu::Cursors::Cursor.store(
143
- new_attributes(coordinate.y_position, x, oy, ox))
154
+ store
144
155
  end
145
156
 
146
157
  # Renders the cursor.
@@ -160,9 +171,10 @@ module Vedeu
160
171
  def reposition(new_oy, new_ox)
161
172
  @oy = new_oy
162
173
  @ox = new_ox
174
+ @y = coordinate(oy, :y).y
175
+ @x = coordinate(ox, :x).x
163
176
 
164
- Vedeu::Cursors::Cursor.store(
165
- new_attributes(coordinate.y_position, coordinate.x_position, oy, ox))
177
+ store
166
178
  end
167
179
 
168
180
  # @return [Array<Fixnum>]
@@ -200,14 +212,12 @@ module Vedeu
200
212
 
201
213
  # @return [Fixnum]
202
214
  def ox
203
- @ox = 0 if @ox < 0
204
- @ox
215
+ @ox < 0 ? 0 : @ox
205
216
  end
206
217
 
207
218
  # @return [Fixnum]
208
219
  def oy
209
- @oy = 0 if @oy < 0
210
- @oy
220
+ @oy < 0 ? 0 : @oy
211
221
  end
212
222
 
213
223
  # Return the position of this cursor.
@@ -235,21 +245,15 @@ module Vedeu
235
245
 
236
246
  # @return [Fixnum] The column/character coordinate.
237
247
  def x
238
- @x = bx if @x < bx
239
- @x = bxn if @x > bxn
240
-
241
- @attributes[:x] = @x
242
-
248
+ @x = (@x < bx) ? bx : @x
249
+ @x = (@x > bxn) ? bxn : @x
243
250
  @x
244
251
  end
245
252
 
246
253
  # @return [Fixnum] The row/line coordinate.
247
254
  def y
248
- @y = by if @y < by
249
- @y = byn if @y > byn
250
-
251
- @attributes[:y] = @y
252
-
255
+ @y = (@y < by) ? by : @y
256
+ @y = (@y > byn) ? byn : @y
253
257
  @y
254
258
  end
255
259
 
@@ -260,9 +264,11 @@ module Vedeu
260
264
  @border ||= Vedeu.borders.by_name(name)
261
265
  end
262
266
 
267
+ # Determine correct x and y related coordinates.
268
+ #
263
269
  # @return [Vedeu::Geometry::Coordinate]
264
- def coordinate
265
- @coordinate ||= Vedeu::Geometry::Coordinate.new(name, oy, ox)
270
+ def coordinate(offset, type)
271
+ Vedeu::Geometry::Coordinate.new(name: name, offset: offset, type: type)
266
272
  end
267
273
 
268
274
  # The default values for a new instance of this class.
@@ -313,6 +319,8 @@ module Vedeu
313
319
  def_delegators Vedeu::Cursors::Cursor, :hide_cursor, :show_cursor,
314
320
  :toggle_cursor
315
321
 
322
+ # :nocov:
323
+
316
324
  # See {file:docs/events/visibility.md#\_hide_cursor_}
317
325
  Vedeu.bind(:_hide_cursor_) { |name| Vedeu.hide_cursor(name) }
318
326
  # Vedeu.bind_alias(:_cursor_hide_, :_hide_cursor_)
@@ -372,4 +380,6 @@ module Vedeu
372
380
  Vedeu.trigger(:_refresh_cursor_, name)
373
381
  end
374
382
 
383
+ # :nocov:
384
+
375
385
  end # Vedeu
@@ -86,9 +86,13 @@ module Vedeu
86
86
 
87
87
  end # Cursors
88
88
 
89
+ # :nocov:
90
+
89
91
  # See {file:docs/events/refresh.md#\_refresh_cursor_}
90
92
  Vedeu.bind(:_refresh_cursor_) do |name|
91
93
  Vedeu::Cursors::Refresh.by_name(name)
92
94
  end
93
95
 
96
+ # :nocov:
97
+
94
98
  end # Vedeu
@@ -249,6 +249,8 @@ module Vedeu
249
249
  def_delegators Vedeu::Distributed::Server, :drb_restart, :drb_start,
250
250
  :drb_status, :drb_stop
251
251
 
252
+ # :nocov:
253
+
252
254
  # See {file:docs/events/drb.md#\_drb_restart_}
253
255
  Vedeu.bind(:_drb_restart_) { Vedeu::Distributed::Server.restart }
254
256
 
@@ -261,4 +263,6 @@ module Vedeu
261
263
  # See {file:docs/events/drb.md#\_drb_stop_}
262
264
  Vedeu.bind(:_drb_stop_) { Vedeu::Distributed::Server.stop }
263
265
 
266
+ # :nocov:
267
+
264
268
  end # Vedeu
@@ -87,9 +87,13 @@ module Vedeu
87
87
 
88
88
  end # Editor
89
89
 
90
+ # :nocov:
91
+
90
92
  # See {file:docs/events/system.md#\_editor_}
91
93
  Vedeu.bind(:_editor_) do |key|
92
94
  Vedeu::Editor::Editor.keypress(name: Vedeu.focus, input: key)
93
95
  end
94
96
 
97
+ # :nocov:
98
+
95
99
  end # Vedeu
@@ -24,6 +24,8 @@ module Vedeu
24
24
  # @return [Vedeu::Editor::Repository]
25
25
  def_delegators Vedeu::Editor::Repository, :documents
26
26
 
27
+ # :nocov:
28
+
27
29
  # See {file:docs/events/document.md#\_editor_execute_}
28
30
  Vedeu.bind(:_editor_execute_) do |name|
29
31
  Vedeu.documents.by_name(name).execute
@@ -65,4 +67,6 @@ module Vedeu
65
67
  # See {file:docs/events/document.md#\_editor_up_}
66
68
  Vedeu.bind(:_editor_up_) { |name| Vedeu.documents.by_name(name).up }
67
69
 
70
+ # :nocov:
71
+
68
72
  end # Vedeu
@@ -194,7 +194,12 @@ module Vedeu
194
194
  @now = 0 # reset now
195
195
 
196
196
  message = "Triggering: '#{name.inspect}'"
197
- message << " with '#{args.inspect}'" if args.any?
197
+
198
+ if args.size > 1
199
+ message << " with #{args.inspect}"
200
+ elsif args.one?
201
+ message << " for #{args.first.inspect}"
202
+ end
198
203
 
199
204
  Vedeu.log(type: :event, message: message)
200
205
 
@@ -17,7 +17,7 @@ require 'vedeu/geometry/area'
17
17
  require 'vedeu/geometry/coordinate'
18
18
  require 'vedeu/geometry/dimension'
19
19
  require 'vedeu/geometry/dsl'
20
- require 'vedeu/geometry/generic_coordinate'
20
+ require 'vedeu/geometry/coordinate'
21
21
  require 'vedeu/geometry/geometry'
22
22
  require 'vedeu/geometry/grid'
23
23
  require 'vedeu/geometry/null'
@@ -6,62 +6,164 @@ module Vedeu
6
6
  #
7
7
  class Coordinate
8
8
 
9
- extend Forwardable
9
+ # Return a new instance of Vedeu::Geometry::Coordinate.
10
+ #
11
+ # @param attributes [Hash]
12
+ # @option attributes name [String|Symbol]
13
+ # @option attributes type [Symbol]
14
+ # @option attributes offset [Fixnum]
15
+ # @return [Vedeu::Geometry::Coordinate]
16
+ def initialize(attributes = {})
17
+ defaults.merge!(attributes).each do |key, value|
18
+ instance_variable_set("@#{key}", value)
19
+ end
20
+ end
10
21
 
11
- def_delegators :x,
12
- :x_position,
13
- :xn
22
+ # Returns the maximum coordinate for an area.
23
+ #
24
+ # @example
25
+ # # d = 2
26
+ # # d_dn = 4 # represents width or height
27
+ # dn # => 6
28
+ #
29
+ # @return [Fixnum]
30
+ def dn_position
31
+ return 0 if d_dn <= 0
14
32
 
15
- def_delegators :y,
16
- :y_position,
17
- :yn
33
+ d + d_dn
34
+ end
35
+ alias_method :xn, :dn_position
36
+ alias_method :yn, :dn_position
18
37
 
19
- # Returns a new instance of Vedeu::Geometry::Coordinate.
38
+ # Returns the coordinate for a given index.
20
39
  #
21
- # @param name [String|Symbol]
22
- # @param oy [Fixnum]
23
- # @param ox [Fixnum]
24
- # @return [Vedeu::Geometry::Coordinate]
25
- def initialize(name, oy, ox)
26
- @name = name
27
- @ox = ox
28
- @oy = oy
40
+ # @example
41
+ # # d_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
42
+ # position # => 4
43
+ # position(-2) # => 4
44
+ # position(2) # => 6
45
+ # position(15) # => 13
46
+ #
47
+ # @return [Fixnum]
48
+ def d_position
49
+ pos = if offset <= 0
50
+ d
51
+
52
+ elsif offset > dn_index
53
+ dn_position
54
+
55
+ else
56
+ d_range[offset]
57
+
58
+ end
59
+
60
+ pos = pos < bd ? bd : pos
61
+ pos = pos > bdn ? bdn : pos
62
+ pos
29
63
  end
64
+ alias_method :x, :d_position
65
+ alias_method :y, :d_position
30
66
 
31
67
  protected
32
68
 
33
69
  # @!attribute [r] name
34
- # @return [String|Symbol]
70
+ # @return [String]
35
71
  attr_reader :name
36
72
 
37
- # @!attribute [rw] ox
73
+ # @!attribute [r] offset
38
74
  # @return [Fixnum]
39
- attr_accessor :ox
75
+ attr_reader :offset
40
76
 
41
- # @!attribute [rw] oy
42
- # @return [Fixnum]
43
- attr_accessor :oy
77
+ # @!attribute [r] type
78
+ # @return [Symbol]
79
+ attr_reader :type
44
80
 
45
81
  private
46
82
 
47
- # Provide an instance of {Vedeu::Geometry::GenericCoordinate} to
48
- # determine correct x related coordinates.
83
+ # @see Vedeu::Borders::Repository#by_name
84
+ def border
85
+ @border ||= Vedeu.borders.by_name(name)
86
+ end
87
+
88
+ # Return the :x or :y value from the border.
89
+ #
90
+ # @return [Fixnum]
91
+ def d
92
+ border.send(coordinate_type[0])
93
+ end
94
+
95
+ # Return the :bx or :by value from the border.
96
+ #
97
+ # @return [Fixnum]
98
+ def bd
99
+ border.send(coordinate_type[1])
100
+ end
101
+
102
+ # Return the :bxn or :byn value from the border.
103
+ #
104
+ # @return [Fixnum]
105
+ def bdn
106
+ border.send(coordinate_type[2])
107
+ end
108
+
109
+ # Return the :width or :height value from the border.
110
+ #
111
+ # @return [Fixnum]
112
+ def d_dn
113
+ border.send(coordinate_type[3])
114
+ end
115
+
116
+ # Ascertain the correct methods to use for determining the
117
+ # coordinates.
118
+ #
119
+ # @raise [Vedeu::Error::InvalidSyntax] When the coordinate type
120
+ # is not given.
121
+ # @return [Fixnum]
122
+ def coordinate_type
123
+ @_type ||= case type
124
+ when :x then [:x, :bx, :bxn, :width]
125
+ when :y then [:y, :by, :byn, :height]
126
+ else
127
+ fail Vedeu::Error::InvalidSyntax,
128
+ 'Coordinate type not given, cannot continue.'.freeze
129
+ end
130
+ end
131
+
132
+ # Returns the maximum index for an area.
133
+ #
134
+ # @example
135
+ # # d_dn = 3
136
+ # dn_index # => 2
137
+ #
138
+ # @return [Fixnum]
139
+ def dn_index
140
+ return 0 if d_dn < 1
141
+
142
+ d_dn - 1
143
+ end
144
+
145
+ # Returns an array with all coordinates from d to dn.
146
+ #
147
+ # @example
148
+ # # d_dn = 10
149
+ # # d = 4
150
+ # # dn = 14
151
+ # d_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
49
152
  #
50
- # @return [Vedeu::Geometry::GenericCoordinate]
51
- def x
52
- @x ||= Vedeu::Geometry::GenericCoordinate.new(name: name,
53
- offset: ox,
54
- type: :x)
153
+ # @return [Array]
154
+ def d_range
155
+ (d...dn_position).to_a
55
156
  end
56
157
 
57
- # Provide an instance of {Vedeu::Geometry::GenericCoordinate} to
58
- # determine correct y related coordinates.
158
+ # The default values for a new instance of this class.
59
159
  #
60
- # @return [Vedeu::Geometry::GenericCoordinate]
61
- def y
62
- @y ||= Vedeu::Geometry::GenericCoordinate.new(name: name,
63
- offset: oy,
64
- type: :y)
160
+ # @return [Hash]
161
+ def defaults
162
+ {
163
+ name: '',
164
+ offset: nil,
165
+ type: :x,
166
+ }
65
167
  end
66
168
 
67
169
  end # Coordinate