vedeu 0.8.12 → 0.8.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/bin/vedeu +1 -1
  3. data/docs/dsl/by_method/profile.md +1 -1
  4. data/docs/dsl/by_method/view/repositories.md +4 -0
  5. data/integrations/342_streams.rb +1 -1
  6. data/integrations/dsl_app_001.rb +1 -0
  7. data/integrations/dsl_app_002.rb +1 -0
  8. data/integrations/dsl_app_003.rb +1 -0
  9. data/integrations/dsl_app_004.rb +1 -0
  10. data/integrations/dsl_app_005.rb +1 -0
  11. data/integrations/dsl_app_006.rb +1 -0
  12. data/integrations/dsl_app_007.rb +1 -0
  13. data/integrations/dsl_app_008.rb +1 -0
  14. data/integrations/dsl_app_009.rb +1 -0
  15. data/integrations/dsl_app_010.rb +1 -0
  16. data/integrations/dsl_app_011.rb +1 -0
  17. data/integrations/dsl_app_012.rb +1 -0
  18. data/integrations/dsl_app_013.rb +1 -0
  19. data/integrations/dsl_app_014.rb +1 -0
  20. data/integrations/dsl_app_015.rb +1 -0
  21. data/integrations/dsl_app_016.rb +1 -0
  22. data/integrations/dsl_app_017.rb +1 -0
  23. data/integrations/dsl_app_018.rb +1 -0
  24. data/integrations/dsl_app_019.rb +1 -0
  25. data/integrations/dsl_app_020.rb +1 -0
  26. data/integrations/dsl_app_021.rb +1 -0
  27. data/integrations/dsl_app_022.rb +1 -0
  28. data/integrations/dsl_app_border_001.rb +1 -0
  29. data/integrations/dsl_app_border_002.rb +1 -0
  30. data/integrations/dsl_app_border_003.rb +1 -0
  31. data/integrations/dsl_app_border_004.rb +1 -0
  32. data/integrations/dsl_app_border_005.rb +1 -0
  33. data/lib/vedeu/application/application_view.rb +3 -3
  34. data/lib/vedeu/borders/dsl.rb +2 -2
  35. data/lib/vedeu/borders/title.rb +1 -1
  36. data/lib/vedeu/buffers/view.rb +1 -11
  37. data/lib/vedeu/cells/empty.rb +2 -2
  38. data/lib/vedeu/coercers/alignment.rb +5 -5
  39. data/lib/vedeu/coercers/coercer.rb +4 -5
  40. data/lib/vedeu/coercers/colour_attributes.rb +1 -1
  41. data/lib/vedeu/coercers/horizontal_alignment.rb +3 -3
  42. data/lib/vedeu/coercers/position.rb +4 -9
  43. data/lib/vedeu/coercers/vertical_alignment.rb +3 -3
  44. data/lib/vedeu/colours/colour.rb +2 -1
  45. data/lib/vedeu/colours/translator.rb +2 -2
  46. data/lib/vedeu/common.rb +20 -1
  47. data/lib/vedeu/configuration/api.rb +8 -6
  48. data/lib/vedeu/configuration/configuration.rb +2 -2
  49. data/lib/vedeu/cursors/coordinate.rb +2 -2
  50. data/lib/vedeu/cursors/cursor.rb +3 -2
  51. data/lib/vedeu/dsl/border.rb +1 -1
  52. data/lib/vedeu/dsl/elements.rb +9 -9
  53. data/lib/vedeu/dsl/geometry.rb +3 -3
  54. data/lib/vedeu/dsl/helpers/wordwrap.rb +4 -4
  55. data/lib/vedeu/dsl/view.rb +9 -9
  56. data/lib/vedeu/dsl/views.rb +2 -2
  57. data/lib/vedeu/editor/document.rb +1 -1
  58. data/lib/vedeu/editor/item.rb +17 -15
  59. data/lib/vedeu/esc/colours.rb +21 -20
  60. data/lib/vedeu/geometries/area/area.rb +6 -2
  61. data/lib/vedeu/geometries/dsl/grid.rb +2 -2
  62. data/lib/vedeu/geometries/geometry.rb +34 -46
  63. data/lib/vedeu/geometries/move.rb +5 -4
  64. data/lib/vedeu/geometries/position.rb +1 -1
  65. data/lib/vedeu/groups/dsl.rb +2 -2
  66. data/lib/vedeu/groups/group.rb +1 -1
  67. data/lib/vedeu/groups/refresh.rb +2 -2
  68. data/lib/vedeu/input/capture.rb +2 -1
  69. data/lib/vedeu/input/dsl.rb +22 -16
  70. data/lib/vedeu/input/key.rb +1 -1
  71. data/lib/vedeu/input/mapper.rb +6 -6
  72. data/lib/vedeu/input/read.rb +2 -2
  73. data/lib/vedeu/interfaces/dsl.rb +2 -2
  74. data/lib/vedeu/logging/debug.rb +10 -10
  75. data/lib/vedeu/logging/timer.rb +7 -11
  76. data/lib/vedeu/menus/dsl.rb +2 -2
  77. data/lib/vedeu/models/focus.rb +3 -3
  78. data/lib/vedeu/models/page.rb +1 -1
  79. data/lib/vedeu/models/row.rb +1 -1
  80. data/lib/vedeu/presentation/style.rb +1 -1
  81. data/lib/vedeu/renderers/escape.rb +0 -6
  82. data/lib/vedeu/renderers/options.rb +3 -3
  83. data/lib/vedeu/renderers/text.rb +0 -6
  84. data/lib/vedeu/repositories/assemblage.rb +1 -1
  85. data/lib/vedeu/repositories/defaults.rb +2 -2
  86. data/lib/vedeu/repositories/repositories.rb +17 -1
  87. data/lib/vedeu/repositories/repository.rb +5 -5
  88. data/lib/vedeu/runtime/application.rb +3 -3
  89. data/lib/vedeu/runtime/main_loop.rb +2 -2
  90. data/lib/vedeu/runtime/router.rb +11 -11
  91. data/lib/vedeu/support/point.rb +18 -15
  92. data/lib/vedeu/templating/helpers.rb +1 -1
  93. data/lib/vedeu/templating/template.rb +4 -4
  94. data/lib/vedeu/terminal/terminal.rb +1 -1
  95. data/lib/vedeu/version.rb +1 -1
  96. data/lib/vedeu/views/chars.rb +3 -3
  97. data/lib/vedeu/views/line.rb +1 -1
  98. data/lib/vedeu/views/lines.rb +3 -3
  99. data/lib/vedeu/views/stream.rb +1 -1
  100. data/lib/vedeu/views/streams.rb +3 -3
  101. data/lib/vedeu/views/view.rb +2 -2
  102. data/test/lib/vedeu/common_test.rb +43 -0
  103. data/test/lib/vedeu/cursors/cursor_test.rb +1 -1
  104. data/test/lib/vedeu/esc/colours_test.rb +42 -0
  105. data/test/lib/vedeu/input/dsl_test.rb +8 -8
  106. data/test/lib/vedeu/logging/debug_test.rb +2 -2
  107. data/test/lib/vedeu/logging/timer_test.rb +4 -13
  108. data/test/lib/vedeu/renderers/escape_test.rb +24 -0
  109. data/test/lib/vedeu/repositories/repositories_test.rb +6 -0
  110. data/test/support/examples/material_colours_app.rb +30 -51
  111. data/vedeu.gemspec +2 -2
  112. metadata +9 -6
@@ -83,13 +83,14 @@ module Vedeu
83
83
  # @param other [Vedeu::Cursors::Cursor]
84
84
  # @return [Boolean]
85
85
  def eql?(other)
86
- self.class == other.class && name == other.name
86
+ self.class.equal?(other.class) && name == other.name
87
87
  end
88
88
  alias == eql?
89
89
 
90
90
  # @return [String]
91
91
  def inspect
92
- "name:'#{name}' x:#{x} y:#{y} ox:#{ox} oy:#{oy} visible:#{visible}"
92
+ "name: #{name.inspect} x: #{x} y: #{y} ox: #{ox} oy: #{oy} " \
93
+ "visible: #{visible}"
93
94
  end
94
95
 
95
96
  # {include:file:docs/events/by_name/cursor_down.md}
@@ -42,7 +42,7 @@ module Vedeu
42
42
  # @return [Vedeu::Borders::Border]
43
43
  # @see Vedeu::Borders::DSL
44
44
  def border(name = nil, &block)
45
- fail Vedeu::Error::RequiresBlock unless block_given?
45
+ raise Vedeu::Error::RequiresBlock unless block_given?
46
46
 
47
47
  model_name = name ? name : model.name
48
48
 
@@ -137,8 +137,8 @@ module Vedeu
137
137
  model.add(l.value)
138
138
 
139
139
  else
140
- fail Vedeu::Error::Fatal,
141
- "Cannot add line to '#{model.class.name}' model."
140
+ raise Vedeu::Error::Fatal,
141
+ "Cannot add line to '#{model.class.name}' model."
142
142
 
143
143
  end
144
144
  end
@@ -178,8 +178,8 @@ module Vedeu
178
178
  model.add([l])
179
179
 
180
180
  else
181
- fail Vedeu::Error::Fatal,
182
- "Cannot add stream to '#{model.class.name}' model."
181
+ raise Vedeu::Error::Fatal,
182
+ "Cannot add stream to '#{model.class.name}' model."
183
183
 
184
184
  end
185
185
  end
@@ -262,8 +262,8 @@ module Vedeu
262
262
  model.add(stream.value)
263
263
 
264
264
  else
265
- fail Vedeu::Error::Fatal,
266
- "Cannot add text to '#{model.class.name}' model."
265
+ raise Vedeu::Error::Fatal,
266
+ "Cannot add text to '#{model.class.name}' model."
267
267
 
268
268
  end
269
269
  end
@@ -299,14 +299,14 @@ module Vedeu
299
299
  # @macro raise_requires_block
300
300
  # @return [NilClass]
301
301
  def requires_block!(&block)
302
- fail Vedeu::Error::RequiresBlock unless block_given?
302
+ raise Vedeu::Error::RequiresBlock unless block_given?
303
303
  end
304
304
 
305
305
  # @macro raise_fatal
306
306
  # @return [NilClass]
307
307
  def requires_model!
308
- fail Vedeu::Error::Fatal,
309
- 'No model, cannot continue.' unless present?(model)
308
+ raise Vedeu::Error::Fatal,
309
+ 'No model, cannot continue.' unless present?(model)
310
310
  end
311
311
 
312
312
  end # Elements
@@ -33,8 +33,8 @@ module Vedeu
33
33
  #
34
34
  # end
35
35
 
36
- fail Vedeu::Error::MissingRequired unless name
37
- fail Vedeu::Error::RequiresBlock unless block_given?
36
+ raise Vedeu::Error::MissingRequired unless name
37
+ raise Vedeu::Error::RequiresBlock unless block_given?
38
38
 
39
39
  Vedeu::Geometries::Geometry.build(name: name, &block).store
40
40
  end
@@ -56,7 +56,7 @@ module Vedeu
56
56
  # @return [Vedeu::Geometries::Geometry]
57
57
  # @see Vedeu::Geometries::DSL
58
58
  def geometry(name = nil, &block)
59
- fail Vedeu::Error::RequiresBlock unless block_given?
59
+ raise Vedeu::Error::RequiresBlock unless block_given?
60
60
 
61
61
  model_name = name ? name : model.name
62
62
 
@@ -187,10 +187,10 @@ module Vedeu
187
187
  return options[:width] if present?(options[:width])
188
188
  return geometry.width if registered?
189
189
 
190
- fail Vedeu::Error::MissingRequired,
191
- 'The text provided cannot be wrapped or pruned because a :width ' \
192
- 'option was not given, or a :name option was either not given ' \
193
- 'or there is no geometry registered with that name.'
190
+ raise Vedeu::Error::MissingRequired,
191
+ 'The text provided cannot be wrapped or pruned because a ' \
192
+ ':width option was not given, or a :name option was either not ' \
193
+ 'given or there is no geometry registered with that name.'
194
194
  end
195
195
 
196
196
  # @macro defaults_method
@@ -55,9 +55,9 @@ module Vedeu
55
55
  # @return [Vedeu::Views::Views<Vedeu::Views::View>]
56
56
  # @todo More documentation required.
57
57
  def view(name, &block)
58
- fail Vedeu::Error::RequiresBlock unless block_given?
59
- fail Vedeu::Error::MissingRequired,
60
- 'Cannot add view without a name.' unless present?(name)
58
+ raise Vedeu::Error::RequiresBlock unless block_given?
59
+ raise Vedeu::Error::MissingRequired,
60
+ 'Cannot add view without a name.' unless present?(name)
61
61
 
62
62
  new_model = Vedeu::Views::View.build(new_attributes(name), &block)
63
63
 
@@ -87,12 +87,12 @@ module Vedeu
87
87
  # @macro raise_missing_required
88
88
  # @return [Vedeu::Views::Views<Vedeu::Views::View>]
89
89
  def template_for(name, filename, object = nil, options = {})
90
- fail Vedeu::Error::MissingRequired,
91
- 'Cannot render template without the name of the ' \
92
- 'view.' unless present?(name)
93
- fail Vedeu::Error::MissingRequired,
94
- 'Cannot render template without a ' \
95
- 'filename.' unless present?(filename)
90
+ raise Vedeu::Error::MissingRequired,
91
+ 'Cannot render template without the name of the ' \
92
+ 'view.' unless present?(name)
93
+ raise Vedeu::Error::MissingRequired,
94
+ 'Cannot render template without a ' \
95
+ 'filename.' unless present?(filename)
96
96
 
97
97
  options[:name] = name
98
98
 
@@ -100,7 +100,7 @@ module Vedeu
100
100
  # @macro raise_requires_block
101
101
  # @return [Vedeu::Views::Composition]
102
102
  def renders(&block)
103
- fail Vedeu::Error::RequiresBlock unless block_given?
103
+ raise Vedeu::Error::RequiresBlock unless block_given?
104
104
 
105
105
  composition(eval('self', block.binding), true, &block)
106
106
  end
@@ -113,7 +113,7 @@ module Vedeu
113
113
  # @macro raise_requires_block
114
114
  # @return [Vedeu::Views::Composition]
115
115
  def views(&block)
116
- fail Vedeu::Error::RequiresBlock unless block_given?
116
+ raise Vedeu::Error::RequiresBlock unless block_given?
117
117
 
118
118
  composition(eval('self', block.binding), false, &block)
119
119
  end
@@ -92,7 +92,7 @@ module Vedeu
92
92
  # @param character [String|Symbol]
93
93
  # @return [Vedeu::Editor::Document]
94
94
  def insert_character(character)
95
- return self if character.is_a?(Symbol)
95
+ return self if symbol?(character)
96
96
 
97
97
  @lines = lines.insert_character(character, y, x)
98
98
 
@@ -28,16 +28,16 @@ module Vedeu
28
28
 
29
29
  # @return [String|Vedeu::Editor::Line]
30
30
  def by_index
31
- return nil unless size > 0
31
+ return nil unless collection
32
32
 
33
- if index.nil? || index > size
34
- collection[-1]
33
+ if index.nil? || index > collection.size
34
+ last_item
35
35
 
36
- elsif index > 0 && index <= size
37
- collection[index]
36
+ elsif index > 0 && index <= collection.size
37
+ nth_item
38
38
 
39
39
  else
40
- collection[0]
40
+ first_item
41
41
 
42
42
  end
43
43
  end
@@ -54,17 +54,19 @@ module Vedeu
54
54
 
55
55
  private
56
56
 
57
- # Returns the size of the collection or 0.
58
- #
59
- # @return [Fixnum]
60
- def size
61
- if collection
62
- collection.size
57
+ # @return [String|Vedeu::Editor::Line]
58
+ def first_item
59
+ collection[0]
60
+ end
63
61
 
64
- else
65
- 0
62
+ # @return [String|Vedeu::Editor::Line]
63
+ def last_item
64
+ collection[-1]
65
+ end
66
66
 
67
- end
67
+ # @return [String|Vedeu::Editor::Line]
68
+ def nth_item
69
+ collection[index]
68
70
  end
69
71
 
70
72
  end # Item
@@ -8,6 +8,7 @@ module Vedeu
8
8
  #
9
9
  module Colours
10
10
 
11
+ include Vedeu::Common
11
12
  extend self
12
13
 
13
14
  # Produces the background named colour escape sequence hash from
@@ -21,6 +22,25 @@ module Vedeu
21
22
  end
22
23
  end
23
24
 
25
+ # @param named_colour [Symbol]
26
+ # @param block [Proc]
27
+ # @return [String]
28
+ def background_colour(named_colour, &block)
29
+ return '' unless valid_name?(named_colour)
30
+
31
+ colour(named_colour.to_s.prepend('on_').to_sym, &block)
32
+ end
33
+
34
+ # @param named_colour [Symbol]
35
+ # @param block [Proc]
36
+ # @return [String]
37
+ def colour(named_colour, &block)
38
+ return '' unless valid_name?(named_colour)
39
+
40
+ public_send(named_colour, &block)
41
+ end
42
+ alias foreground_colour colour
43
+
24
44
  # Produces the foreground named colour escape sequence hash. The
25
45
  # background escape sequences are also generated from this by
26
46
  # adding 10 to the values.
@@ -69,25 +89,6 @@ module Vedeu
69
89
  }
70
90
  end
71
91
 
72
- # @param named_colour [Symbol]
73
- # @param block [Proc]
74
- # @return [String]
75
- def background_colour(named_colour, &block)
76
- return '' unless valid_name?(named_colour)
77
-
78
- colour(named_colour.to_s.prepend('on_').to_sym, &block)
79
- end
80
-
81
- # @param named_colour [Symbol]
82
- # @param block [Proc]
83
- # @return [String]
84
- def colour(named_colour, &block)
85
- return '' unless valid_name?(named_colour)
86
-
87
- public_send(named_colour, &block)
88
- end
89
- alias foreground_colour colour
90
-
91
92
  # @return [Array<Symbol>]
92
93
  def valid_codes
93
94
  @_valid_codes ||= foreground_codes.keys.map do |name|
@@ -101,7 +102,7 @@ module Vedeu
101
102
  # @param named_colour [Symbol]
102
103
  # @return [Boolean]
103
104
  def valid_name?(named_colour)
104
- return false unless named_colour.is_a?(Symbol)
105
+ return false unless symbol?(named_colour)
105
106
 
106
107
  valid_codes.include?(named_colour)
107
108
  end
@@ -101,8 +101,12 @@ module Vedeu
101
101
  # @param other [Vedeu::Geometries::Area]
102
102
  # @return [Boolean]
103
103
  def eql?(other)
104
- self.class == other.class && y == other.y && yn == other.yn &&
105
- x == other.x && xn == other.xn
104
+ self.class.equal?(other.class) &&
105
+ name == other.name &&
106
+ y == other.y &&
107
+ yn == other.yn &&
108
+ x == other.x &&
109
+ xn == other.xn
106
110
  end
107
111
  alias == eql?
108
112
 
@@ -36,7 +36,7 @@ module Vedeu
36
36
  # @macro raise_out_of_range
37
37
  # @see Vedeu::Geometries::DSL#columns
38
38
  def columns
39
- fail Vedeu::Error::OutOfRange if out_of_range?
39
+ raise Vedeu::Error::OutOfRange if out_of_range?
40
40
 
41
41
  column * value
42
42
  end
@@ -44,7 +44,7 @@ module Vedeu
44
44
  # @macro raise_out_of_range
45
45
  # @see Vedeu::Geometries::DSL#rows
46
46
  def rows
47
- fail Vedeu::Error::OutOfRange if out_of_range?
47
+ raise Vedeu::Error::OutOfRange if out_of_range?
48
48
 
49
49
  row * value
50
50
  end
@@ -39,27 +39,31 @@ module Vedeu
39
39
  :y,
40
40
  :yn
41
41
 
42
- # @!attribute [rw] horizontal_alignment
43
- # @return [Symbol]
44
- attr_accessor :horizontal_alignment
45
-
46
- # @!attribute [rw] vertical_alignment
47
- # @return [Symbol]
48
- attr_accessor :vertical_alignment
49
-
50
- # @!attribute [rw] name
51
- # @return [String|Symbol]
52
- attr_accessor :name
42
+ # @!attribute [rw] client
43
+ # @return [Object]
44
+ attr_accessor :client
53
45
 
54
46
  # @!attribute [w] height
55
47
  # @return [Fixnum]
56
48
  attr_writer :height
57
49
 
50
+ # @!attribute [rw] horizontal_alignment
51
+ # @return [Symbol]
52
+ attr_accessor :horizontal_alignment
53
+
58
54
  # @!attribute [rw] maximised
59
55
  # @return [Boolean]
60
56
  attr_accessor :maximised
61
57
  alias maximised? maximised
62
58
 
59
+ # @!attribute [rw] name
60
+ # @return [String|Symbol]
61
+ attr_accessor :name
62
+
63
+ # @!attribute [rw] vertical_alignment
64
+ # @return [Symbol]
65
+ attr_accessor :vertical_alignment
66
+
63
67
  # @!attribute [w] width
64
68
  # @return [Fixnum]
65
69
  attr_writer :width
@@ -80,20 +84,17 @@ module Vedeu
80
84
  # @return [Fixnum]
81
85
  attr_writer :yn
82
86
 
83
- # @!attribute [rw] client
84
- # @return [Object]
85
- attr_accessor :client
86
-
87
87
  # Returns a new instance of Vedeu::Geometries::Geometry.
88
88
  #
89
89
  # @param attributes [Hash<Symbol => Boolean|Fixnum|String|
90
90
  # Symbol|Vedeu::Geometries::Repository]
91
+ # @option attributes client [void]
92
+ # @option attributes height [Fixnum]
91
93
  # @option attributes horizontal_alignment [Symbol]
92
- # @option attributes vertical_alignment [Symbol]
93
94
  # @option attributes maximised [Boolean]
94
- # @option attributes height [Fixnum]
95
95
  # @option attributes name [String|Symbol]
96
96
  # @option attributes repository [Vedeu::Geometries::Repository]
97
+ # @option attributes vertical_alignment [Symbol]
97
98
  # @option attributes width [Fixnum]
98
99
  # @option attributes x [Fixnum]
99
100
  # @option attributes xn [Fixnum]
@@ -106,22 +107,20 @@ module Vedeu
106
107
  end
107
108
  end
108
109
 
109
- # @return [Hash<Symbol => Boolean|Fixnum|String|Symbol|
110
- # Vedeu::Geometries::Repository]
110
+ # @return [Hash<Symbol => Boolean|Fixnum|String|Symbol>]
111
111
  def attributes
112
112
  {
113
113
  client: client,
114
- height: height,
114
+ height: @height.is_a?(Proc) ? @height.call : @height,
115
115
  horizontal_alignment: horizontal_alignment,
116
116
  maximised: maximised,
117
117
  name: name,
118
- repository: repository,
119
118
  vertical_alignment: vertical_alignment,
120
- width: width,
121
- x: x,
122
- xn: xn,
123
- y: y,
124
- yn: yn,
119
+ width: @width.is_a?(Proc) ? @width.call : @width,
120
+ x: @x.is_a?(Proc) ? @x.call : @x,
121
+ xn: @xn.is_a?(Proc) ? @xn.call : @xn,
122
+ y: @y.is_a?(Proc) ? @y.call : @y,
123
+ yn: @yn.is_a?(Proc) ? @yn.call : @yn,
125
124
  }
126
125
  end
127
126
 
@@ -143,7 +142,7 @@ module Vedeu
143
142
  # @param other [Vedeu::Geometries::Geometry]
144
143
  # @return [Boolean]
145
144
  def eql?(other)
146
- self.class == other.class && name == other.name
145
+ self.class.equal?(other.class) && name == other.name
147
146
  end
148
147
  alias == eql?
149
148
 
@@ -153,9 +152,9 @@ module Vedeu
153
152
  return self if maximised?
154
153
 
155
154
  @maximised = true
155
+ @_area = nil
156
156
 
157
157
  store do
158
- Vedeu.trigger(:_clear_)
159
158
  Vedeu.trigger(:_refresh_view_, name)
160
159
  end
161
160
  end
@@ -166,6 +165,7 @@ module Vedeu
166
165
  return self unless maximised?
167
166
 
168
167
  @maximised = false
168
+ @_area = nil
169
169
 
170
170
  store do
171
171
  Vedeu.trigger(:_clear_)
@@ -173,27 +173,16 @@ module Vedeu
173
173
  end
174
174
  end
175
175
 
176
+ # @return [Vedeu::Geometries::Repository]
177
+ def repository
178
+ Vedeu.geometries
179
+ end
180
+
176
181
  private
177
182
 
178
183
  # @return [Vedeu::Geometries::Area]
179
184
  def area
180
- Vedeu::Geometries::Area.from_attributes(area_attributes)
181
- end
182
-
183
- # @return [Hash<Symbol => Boolean|Fixnum>]
184
- def area_attributes
185
- {
186
- horizontal_alignment: horizontal_alignment,
187
- maximised: maximised,
188
- name: name,
189
- vertical_alignment: vertical_alignment,
190
- x: @x.is_a?(Proc) ? @x.call : @x,
191
- xn: @xn.is_a?(Proc) ? @xn.call : @xn,
192
- width: @width.is_a?(Proc) ? @width.call : @width,
193
- y: @y.is_a?(Proc) ? @y.call : @y,
194
- yn: @yn.is_a?(Proc) ? @yn.call : @yn,
195
- height: @height.is_a?(Proc) ? @height.call : @height,
196
- }
185
+ @_area ||= Vedeu::Geometries::Area.from_attributes(attributes)
197
186
  end
198
187
 
199
188
  # @macro defaults_method
@@ -204,7 +193,6 @@ module Vedeu
204
193
  horizontal_alignment: :none,
205
194
  maximised: false,
206
195
  name: nil,
207
- repository: Vedeu.geometries,
208
196
  vertical_alignment: :none,
209
197
  width: nil,
210
198
  x: nil,
@@ -177,6 +177,7 @@ module Vedeu
177
177
  down: valid_down?,
178
178
  left: valid_left?,
179
179
  origin: true,
180
+ none: false,
180
181
  right: valid_right?,
181
182
  up: valid_up?,
182
183
  }.fetch(direction, false)
@@ -184,22 +185,22 @@ module Vedeu
184
185
 
185
186
  # @return [Boolean]
186
187
  def valid_down?
187
- yn + offset <= Vedeu.height
188
+ Vedeu::Point.valid?(value: yn + offset, max: Vedeu.height)
188
189
  end
189
190
 
190
191
  # @return [Boolean]
191
192
  def valid_left?
192
- x - offset >= 1
193
+ Vedeu::Point.valid?(value: x - offset, min: 1)
193
194
  end
194
195
 
195
196
  # @return [Boolean]
196
197
  def valid_right?
197
- xn + offset <= Vedeu.width
198
+ Vedeu::Point.valid?(value: xn + offset, max: Vedeu.width)
198
199
  end
199
200
 
200
201
  # @return [Boolean]
201
202
  def valid_up?
202
- y - offset >= 1
203
+ Vedeu::Point.valid?(value: y - offset, min: 1)
203
204
  end
204
205
 
205
206
  end # Move
@@ -77,7 +77,7 @@ module Vedeu
77
77
  # @param other [Vedeu::Geometries::Position]
78
78
  # @return [Boolean]
79
79
  def eql?(other)
80
- self.class == other.class && x == other.x && y == other.y
80
+ self.class.equal?(other.class) && x == other.x && y == other.y
81
81
  end
82
82
  alias == eql?
83
83
 
@@ -59,8 +59,8 @@ module Vedeu
59
59
  # @macro raise_requires_block
60
60
  # @return [Vedeu::Groups::Group]
61
61
  def self.group(name, &block)
62
- fail Vedeu::Error::MissingRequired unless name
63
- fail Vedeu::Error::RequiresBlock unless block_given?
62
+ raise Vedeu::Error::MissingRequired unless name
63
+ raise Vedeu::Error::RequiresBlock unless block_given?
64
64
 
65
65
  Vedeu::Groups::Group.build(name: name, &block).store
66
66
  end
@@ -86,7 +86,7 @@ module Vedeu
86
86
  # @param other [Vedeu::Groups::Group]
87
87
  # @return [Boolean]
88
88
  def eql?(other)
89
- self.class == other.class && name == other.name &&
89
+ self.class.equal?(other.class) && name == other.name &&
90
90
  members == other.members
91
91
  end
92
92
  alias == eql?
@@ -58,8 +58,8 @@ module Vedeu
58
58
  return name if present?(name)
59
59
  return group_from_interface if present?(group_from_interface)
60
60
 
61
- fail Vedeu::Error::MissingRequired,
62
- 'Cannot refresh group with an empty group name.'
61
+ raise Vedeu::Error::MissingRequired,
62
+ 'Cannot refresh group with an empty group name.'
63
63
  end
64
64
 
65
65
  # @return [String|Symbol]
@@ -12,6 +12,7 @@ module Vedeu
12
12
  #
13
13
  class Capture
14
14
 
15
+ include Vedeu::Common
15
16
  extend Forwardable
16
17
 
17
18
  def_delegators Vedeu::Terminal::Mode,
@@ -116,7 +117,7 @@ module Vedeu
116
117
  # @param keys [NilClass|String|Symbol|Vedeu::Cursors::Cursor]
117
118
  # @return [Boolean]
118
119
  def click?(keys)
119
- return false if keys.nil? || keys.is_a?(Symbol)
120
+ return false if keys.nil? || symbol?(keys)
120
121
 
121
122
  keys.is_a?(Vedeu::Cursors::Cursor) || keys.start_with?("\e[M")
122
123
  end
@@ -64,8 +64,8 @@ module Vedeu
64
64
  # @macro raise_missing_required
65
65
  # @return [Vedeu::Input::Keymap]
66
66
  def self.keymap(name, &block)
67
- fail Vedeu::Error::MissingRequired unless name
68
- fail Vedeu::Error::RequiresBlock unless block_given?
67
+ raise Vedeu::Error::MissingRequired unless name
68
+ raise Vedeu::Error::RequiresBlock unless block_given?
69
69
 
70
70
  unless Vedeu.keymaps.registered?(name)
71
71
  Vedeu::Input::Keymap.new(name: name).store
@@ -76,32 +76,38 @@ module Vedeu
76
76
 
77
77
  # Define keypress(es) to perform an action.
78
78
  #
79
- # @param values [Array<String>|Array<Symbol>|String|Symbol]
79
+ # @param keys [Array<String>|Array<Symbol>|String|Symbol]
80
80
  # The key(s) pressed. Special keys can be found in
81
81
  # {Vedeu::Input::Input#specials}. When more than one key is
82
82
  # defined, then the extras are treated as aliases.
83
83
  # @param block [Proc] The action to perform when this key is
84
84
  # pressed. Can be a method call or event triggered.
85
85
  # @macro raise_invalid_syntax
86
- # @return [Array] A collection containing the keypress(es).
87
- def key(*values, &block)
88
- fail Vedeu::Error::InvalidSyntax,
89
- 'No action defined for `key`.' unless block_given?
86
+ # @return [Array] A collection containing the keys minus any
87
+ # invalid or nil keys.
88
+ def key(*keys, &block)
89
+ raise Vedeu::Error::InvalidSyntax,
90
+ 'No action defined for `key`.' unless block_given?
90
91
 
91
- fail Vedeu::Error::InvalidSyntax,
92
- 'No keypress(es) defined for `key`.' unless present?(values)
92
+ raise Vedeu::Error::InvalidSyntax,
93
+ 'No keypresses defined for `key`.' unless present?(keys)
93
94
 
94
- values.each do |value|
95
- unless present?(value)
96
- fail Vedeu::Error::InvalidSyntax,
97
- 'An invalid value for `key` was encountered.'
98
- end
99
-
100
- model.add(Vedeu::Input::Key.new(value, &block))
95
+ valid_keys(keys).each do |key|
96
+ model.add(Vedeu::Input::Key.new(key, &block))
101
97
  end
102
98
  end
103
99
  alias key= key
104
100
 
101
+ private
102
+
103
+ # @param keys [Array<void>]
104
+ # @return [Array<String|Symbol>]
105
+ def valid_keys(keys)
106
+ keys.compact.keep_if do |key|
107
+ symbol?(key) || (string?(key) && present?(key))
108
+ end
109
+ end
110
+
105
111
  end # DSL
106
112
 
107
113
  end # Input
@@ -21,7 +21,7 @@ module Vedeu
21
21
  # @macro raise_requires_block
22
22
  # @return [Vedeu::Input::Key]
23
23
  def initialize(input = nil, &block)
24
- fail Vedeu::Error::RequiresBlock unless block_given?
24
+ raise Vedeu::Error::RequiresBlock unless block_given?
25
25
 
26
26
  @input = input
27
27
  @output = block