vedeu 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/docs/dsl/by_method/focus_by_name.md +6 -1
  3. data/docs/dsl/by_method/focus_next.md +7 -0
  4. data/docs/dsl/by_method/focus_previous.md +7 -0
  5. data/docs/events/by_name/mouse_event.md +8 -0
  6. data/lib/vedeu.rb +12 -0
  7. data/lib/vedeu/all.rb +2 -0
  8. data/lib/vedeu/application/controller.rb +2 -6
  9. data/lib/vedeu/buffers/empty.rb +2 -1
  10. data/lib/vedeu/cells/borders/vertices/bottom_left.rb +1 -1
  11. data/lib/vedeu/cells/borders/vertices/bottom_right.rb +1 -1
  12. data/lib/vedeu/cells/borders/vertices/top_left.rb +1 -1
  13. data/lib/vedeu/cells/borders/vertices/top_right.rb +1 -1
  14. data/lib/vedeu/cells/char.rb +2 -6
  15. data/lib/vedeu/cells/cursor.rb +1 -1
  16. data/lib/vedeu/cells/support/html.rb +6 -18
  17. data/lib/vedeu/coercers/all.rb +18 -1
  18. data/lib/vedeu/coercers/chars.rb +29 -0
  19. data/lib/vedeu/coercers/coercer.rb +59 -0
  20. data/lib/vedeu/coercers/colour.rb +15 -33
  21. data/lib/vedeu/coercers/colour_attributes.rb +8 -3
  22. data/lib/vedeu/coercers/editor_line.rb +36 -0
  23. data/lib/vedeu/coercers/editor_lines.rb +36 -0
  24. data/lib/vedeu/coercers/lines.rb +36 -0
  25. data/lib/vedeu/coercers/page.rb +52 -0
  26. data/lib/vedeu/coercers/position.rb +69 -0
  27. data/lib/vedeu/coercers/row.rb +43 -0
  28. data/lib/vedeu/coercers/streams.rb +29 -0
  29. data/lib/vedeu/coercers/style.rb +54 -0
  30. data/lib/vedeu/configuration/api.rb +10 -0
  31. data/lib/vedeu/configuration/configuration.rb +11 -0
  32. data/lib/vedeu/cursors/coordinate.rb +41 -66
  33. data/lib/vedeu/cursors/cursor.rb +4 -4
  34. data/lib/vedeu/cursors/reposition.rb +3 -3
  35. data/lib/vedeu/dsl/border.rb +2 -39
  36. data/lib/vedeu/dsl/elements.rb +5 -6
  37. data/lib/vedeu/dsl/geometry.rb +3 -12
  38. data/lib/vedeu/editor/cropper.rb +2 -1
  39. data/lib/vedeu/error.rb +4 -0
  40. data/lib/vedeu/geometries/position.rb +14 -27
  41. data/lib/vedeu/input/mouse.rb +14 -5
  42. data/lib/vedeu/input/read.rb +1 -11
  43. data/lib/vedeu/interfaces/clear.rb +2 -1
  44. data/lib/vedeu/logging/log.rb +1 -1
  45. data/lib/vedeu/models/page.rb +5 -23
  46. data/lib/vedeu/models/row.rb +5 -14
  47. data/lib/vedeu/models/toggleable.rb +2 -7
  48. data/lib/vedeu/plugins/plugin.rb +1 -0
  49. data/lib/vedeu/presentation/style.rb +4 -20
  50. data/lib/vedeu/renderers/all.rb +24 -10
  51. data/lib/vedeu/repositories/model.rb +2 -8
  52. data/lib/vedeu/repositories/registerable.rb +4 -9
  53. data/lib/vedeu/runtime/application.rb +2 -0
  54. data/lib/vedeu/runtime/flags.rb +2 -0
  55. data/lib/vedeu/runtime/router.rb +2 -0
  56. data/lib/vedeu/support/point.rb +9 -7
  57. data/lib/vedeu/support/x_coordinate.rb +57 -0
  58. data/lib/vedeu/support/y_coordinate.rb +57 -0
  59. data/lib/vedeu/terminal/terminal.rb +2 -0
  60. data/lib/vedeu/version.rb +1 -1
  61. data/lib/vedeu/views/value.rb +3 -12
  62. data/test/lib/vedeu/coercers/chars_test.rb +33 -0
  63. data/test/lib/vedeu/coercers/coercer_test.rb +34 -0
  64. data/test/lib/vedeu/coercers/colour_test.rb +9 -7
  65. data/test/lib/vedeu/coercers/editor_line_test.rb +40 -0
  66. data/test/lib/vedeu/coercers/editor_lines_test.rb +40 -0
  67. data/test/lib/vedeu/coercers/lines_test.rb +40 -0
  68. data/test/lib/vedeu/coercers/page_test.rb +150 -0
  69. data/test/lib/vedeu/coercers/position_test.rb +76 -0
  70. data/test/lib/vedeu/coercers/row_test.rb +64 -0
  71. data/test/lib/vedeu/coercers/streams_test.rb +33 -0
  72. data/test/lib/vedeu/coercers/style_test.rb +62 -0
  73. data/test/lib/vedeu/cursors/coordinate_test.rb +11 -12
  74. data/test/lib/vedeu/geometries/position_test.rb +10 -54
  75. data/test/lib/vedeu/input/capture_test.rb +1 -1
  76. data/test/lib/vedeu/models/page_test.rb +4 -116
  77. data/test/lib/vedeu/models/row_test.rb +1 -31
  78. data/test/lib/vedeu/presentation/style_test.rb +4 -38
  79. data/test/lib/vedeu/renderers/all_test.rb +6 -0
  80. data/test/lib/vedeu/support/point_test.rb +13 -1
  81. data/test/lib/vedeu/support/x_coordinate_test.rb +64 -0
  82. data/test/lib/vedeu/support/y_coordinate_test.rb +64 -0
  83. data/test/support/examples/material_colours_app.rb +1 -0
  84. data/vedeu.gemspec +1 -1
  85. metadata +41 -4
@@ -188,7 +188,7 @@ module Vedeu
188
188
  #
189
189
  # @return [Vedeu::Geometries::Position]
190
190
  def position
191
- @position = Vedeu::Geometries::Position.coerce([y, x])
191
+ @position = Vedeu::Geometries::Position.new(y, x)
192
192
  end
193
193
 
194
194
  # {include:file:docs/events/by_name/show_cursor.md}
@@ -224,9 +224,9 @@ module Vedeu
224
224
  #
225
225
  # @return [Vedeu::Cursors::Coordinate]
226
226
  def coordinate(offset, type)
227
- Vedeu::Cursors::Coordinate.new(name: name,
228
- offset: offset,
229
- type: type)
227
+ Vedeu::Cursors::Coordinate.new(geometry: geometry,
228
+ offset: offset,
229
+ type: type)
230
230
  end
231
231
 
232
232
  # The default values for a new instance of this class.
@@ -71,9 +71,9 @@ module Vedeu
71
71
  # @param type [Symbol]
72
72
  # @return [Vedeu::Cursors::Coordinate]
73
73
  def coordinate(offset, type)
74
- Vedeu::Cursors::Coordinate.new(name: name,
75
- offset: offset,
76
- type: type)
74
+ Vedeu::Cursors::Coordinate.new(geometry: geometry,
75
+ offset: offset,
76
+ type: type)
77
77
  end
78
78
 
79
79
  # @return [Vedeu::Cursors::Cursor]
@@ -10,39 +10,7 @@ module Vedeu
10
10
  #
11
11
  module Border
12
12
 
13
- # When {Vedeu::DSL::Border} is included in a class, the
14
- # methods within this module are included as class methods on
15
- # that class.
16
- #
17
- module ClassMethods
18
-
19
- # Specify the border of an interface or view with a simple
20
- # DSL.
21
- #
22
- # # Standalone (preferred):
23
- # Vedeu.border :my_interface do
24
- # # ... see {Vedeu::Borders::DSL}
25
- # end
26
- #
27
- # @param name [String|Symbol] The name of the interface or
28
- # view to which this border belongs.
29
- # @param block [Proc]
30
- # @macro raise_requires_block
31
- # @macro raise_missing_required
32
- # @return [Vedeu::Borders::Border]
33
- # @see Vedeu::Borders::DSL
34
- def border(name, &block)
35
- fail Vedeu::Error::MissingRequired unless name
36
- fail Vedeu::Error::RequiresBlock unless block_given?
37
-
38
- Vedeu::Borders::Border.build(enabled: true, name: name, &block).store
39
- end
40
-
41
- end # ClassMethods
42
-
43
- # When {Vedeu::DSL::Border} is included in a class, the
44
- # methods within this module are included as instance methods on
45
- # that class.
13
+ # Provide additional behaviour as instance methods.
46
14
  #
47
15
  module InstanceMethods
48
16
 
@@ -110,13 +78,8 @@ module Vedeu
110
78
 
111
79
  end # InstanceMethods
112
80
 
113
- # When this module is included in a class, provide ClassMethods
114
- # as class methods for the class.
115
- #
116
- # @param klass [Class]
117
- # @return [void]
81
+ # @macro included_module
118
82
  def self.included(klass)
119
- klass.extend(Vedeu::DSL::Border::ClassMethods)
120
83
  klass.include(Vedeu::DSL::Border::InstanceMethods)
121
84
  end
122
85
 
@@ -61,7 +61,7 @@ module Vedeu
61
61
  #
62
62
  # @param block [Proc]
63
63
  # @macro raise_requires_block
64
- # @raise [Vedeu::Error::Fatal]
64
+ # @macro raise_fatal
65
65
  # @return [void]
66
66
  def lines(opts = {}, &block)
67
67
  requires_block!(&block)
@@ -113,7 +113,7 @@ module Vedeu
113
113
  # @param opts [Hash]
114
114
  # @option opts ... [void]
115
115
  # @param block [Proc]
116
- # @raise [Vedeu::Error::Fatal]
116
+ # @macro raise_fatal
117
117
  # @return [void]
118
118
  def line(value = '', opts = {}, &block)
119
119
  requires_model!
@@ -148,7 +148,7 @@ module Vedeu
148
148
  # @param opts [Hash]
149
149
  # @option opts ... [void]
150
150
  # @param block [Proc]
151
- # @raise [Vedeu::Error::Fatal]
151
+ # @macro raise_fatal
152
152
  # @return [void]
153
153
  def stream(value = '', opts = {}, &block)
154
154
  requires_model!
@@ -241,7 +241,7 @@ module Vedeu
241
241
  # @option opts :pad [String] The character to use to pad the
242
242
  # width, by default uses an empty space (0x20). Only when the
243
243
  # string is shorter than the specified width.
244
- # @raise [Vedeu::Error::Fatal]
244
+ # @macro raise_fatal
245
245
  # @return [void]
246
246
  def text(value = '', opts = {})
247
247
  requires_model!
@@ -302,8 +302,7 @@ module Vedeu
302
302
  fail Vedeu::Error::RequiresBlock unless block_given?
303
303
  end
304
304
 
305
- # @raise [Vedeu::Error::Fatal] When the model cannot be
306
- # determined.
305
+ # @macro raise_fatal
307
306
  # @return [NilClass]
308
307
  def requires_model!
309
308
  fail Vedeu::Error::Fatal,
@@ -10,9 +10,7 @@ module Vedeu
10
10
  #
11
11
  module Geometry
12
12
 
13
- # When {Vedeu::DSL::Geometry} is included in a class, the
14
- # methods within this module are included as class methods on
15
- # that class.
13
+ # Provide additional behaviour as class methods.
16
14
  #
17
15
  module ClassMethods
18
16
 
@@ -44,9 +42,7 @@ module Vedeu
44
42
 
45
43
  end # ClassMethods
46
44
 
47
- # When {Vedeu::DSL::Geometry} is included in a class, the
48
- # methods within this module are included as instance methods on
49
- # that class.
45
+ # Provide additional behaviour as instance methods.
50
46
  #
51
47
  module InstanceMethods
52
48
 
@@ -70,12 +66,7 @@ module Vedeu
70
66
 
71
67
  end # InstanceMethods
72
68
 
73
- # When this module is included in a class, provide ClassMethods
74
- # as class methods and InstanceMethods as instance methods for
75
- # the given class.
76
- #
77
- # @param klass [Class]
78
- # @return [void]
69
+ # @macro included_module
79
70
  def self.included(klass)
80
71
  klass.extend(Vedeu::DSL::Geometry::ClassMethods)
81
72
  klass.include(Vedeu::DSL::Geometry::InstanceMethods)
@@ -45,8 +45,9 @@ module Vedeu
45
45
 
46
46
  visible.each_with_index do |line, iy|
47
47
  line.chars.each_with_index do |char, ix|
48
+ position = Vedeu::Geometries::Position.new((by + iy), (bx + ix))
48
49
  out << Vedeu::Cells::Char.new(name: name,
49
- position: [(by + iy), (bx + ix)],
50
+ position: position,
50
51
  value: char)
51
52
  end
52
53
  end
@@ -37,6 +37,10 @@ module Vedeu
37
37
  # given or cannot be found is to use the name of the currently
38
38
  # focussed interface.
39
39
  #
40
+ # @!macro [new] raise_fatal
41
+ # @raise [Vedeu::Error::Fatal] When Vedeu does not understand
42
+ # that which the client application is attempting to achieve.
43
+ #
40
44
  class Fatal < StandardError
41
45
 
42
46
  end # Fatal
@@ -21,34 +21,21 @@ module Vedeu
21
21
  attr_reader :x
22
22
  alias last x
23
23
 
24
- # Convenience constructor for Vedeu::Geometries::Position.
25
- #
26
- # @param (see #initialize)
27
- def self.[](y = 1, x = 1)
28
- new(y, x)
29
- end
30
-
31
- # @param value [Array<Fixnum>|Fixnum|Hash|
32
- # Vedeu::Geometries::Position]
33
- # @return [Vedeu::Geometries::Position]
34
- def self.coerce(value)
35
- if value.is_a?(self)
36
- value
24
+ class << self
37
25
 
38
- elsif value.is_a?(Array)
39
- new(*value)
26
+ extend Forwardable
40
27
 
41
- elsif value.is_a?(Fixnum)
42
- new(value, 1)
43
-
44
- elsif value.is_a?(Hash)
45
- new(value.fetch(:y, 1), value.fetch(:x, 1))
46
-
47
- elsif value.is_a?(NilClass)
48
- nil
28
+ def_delegators Vedeu::Coercers::Position,
29
+ :coerce
49
30
 
31
+ # Convenience constructor for Vedeu::Geometries::Position.
32
+ #
33
+ # @param (see #initialize)
34
+ def [](y = 1, x = 1)
35
+ new(y, x)
50
36
  end
51
- end
37
+
38
+ end # Eigenclass
52
39
 
53
40
  # Initializes a new instance of Vedeu::Geometries::Position.
54
41
  #
@@ -67,10 +54,10 @@ module Vedeu
67
54
  #
68
55
  # @return [Array<Fixnum>]
69
56
  def as_indices
70
- xi = ((x - 1) <= 1) ? 0 : (x - 1)
71
- yi = ((y - 1) <= 1) ? 0 : (y - 1)
57
+ ix = Vedeu::Point.coerce(value: (x - 1), min: 0).value
58
+ iy = Vedeu::Point.coerce(value: (y - 1), min: 0).value
72
59
 
73
- [yi, xi]
60
+ [iy, ix]
74
61
  end
75
62
 
76
63
  # @param other [Vedeu::Geometries::Position]
@@ -65,21 +65,30 @@ module Vedeu
65
65
  mouse[0]
66
66
  end
67
67
 
68
- # @return [Array<Fixnum>]
69
- def mouse
70
- @_input ||= input.chars[3..-1].map { |character| character.ord - 32 }
71
- end
72
-
68
+ # Returns a boolean indicating the mouse interaction was
69
+ # recognised as a left click.
70
+ #
73
71
  # @return [Boolean]
74
72
  def left_click?
75
73
  button == 0
76
74
  end
77
75
 
76
+ # @return [Array<Fixnum>]
77
+ def mouse
78
+ @_input ||= input.chars[3..-1].map { |character| character.ord - 32 }
79
+ end
80
+
81
+ # Returns a boolean indicating the mouse interaction was
82
+ # recognised as the scroll wheel moving up.
83
+ #
78
84
  # @return [Boolean]
79
85
  def wheel_up?
80
86
  button == 64
81
87
  end
82
88
 
89
+ # Returns a boolean indicating the mouse interaction was
90
+ # recognised as the scroll wheel moving down.
91
+ #
83
92
  # @return [Boolean]
84
93
  def wheel_down?
85
94
  button == 65
@@ -25,7 +25,7 @@ module Vedeu
25
25
  #
26
26
  # @param input [NilClass|String]
27
27
  # @param options [Hash<Symbol => Symbol]
28
- # @option mode [Symbol] Either :cooked (default) or :raw
28
+ # @option mode [Symbol] Either :cooked (default), :raw or :fake.
29
29
  # @return [Vedeu::Input::Read]
30
30
  def initialize(input = nil, options = {})
31
31
  @input = input
@@ -78,16 +78,6 @@ module Vedeu
78
78
  mode == :fake
79
79
  end
80
80
 
81
- # @return [String]
82
- def mouse_off
83
- Vedeu.esc.mouse_x10_off
84
- end
85
-
86
- # @return [String]
87
- def show_cursor
88
- Vedeu.esc.show_cursor
89
- end
90
-
91
81
  # @return [String]
92
82
  def input
93
83
  @_input ||= if input?
@@ -162,9 +162,10 @@ module Vedeu
162
162
  Vedeu.timer("Clearing #{clearing}: '#{name}'") do
163
163
  @clear ||= Array.new(height) do |iy|
164
164
  Array.new(width) do |ix|
165
+ position = Vedeu::Geometries::Position.new((y + iy), (x + ix))
165
166
  Vedeu::Cells::Clear.new(colour: colour,
166
167
  name: name,
167
- position: [y + iy, x + ix])
168
+ position: position)
168
169
  end
169
170
  end
170
171
  end
@@ -87,7 +87,7 @@ module Vedeu
87
87
  end
88
88
  end
89
89
 
90
- # {include:file:docs/api/by_method/log_timestamp.md}
90
+ # {include:file:docs/dsl/by_method/log_timestamp.md}
91
91
  # @macro vedeu_logging_log_param_message
92
92
  # @return [String]
93
93
  def formatted_message(message)
@@ -14,32 +14,14 @@ module Vedeu
14
14
  # @return [Array<NilClass|Vedeu::Models::Row>]
15
15
  attr_reader :rows
16
16
 
17
- # @param value
18
- # [Vedeu::Models::Page|Vedeu::Models::Row|Array<void>|void]
19
- # @macro raise_invalid_syntax
20
- # @return [Vedeu::Models::Page]
21
- def self.coerce(value)
22
- if value.is_a?(Vedeu::Models::Page)
23
- value
24
-
25
- elsif value.is_a?(Vedeu::Models::Row)
26
- Vedeu::Models::Page.new([value])
27
-
28
- elsif value.is_a?(Array) && value.empty?
29
- Vedeu::Models::Page.new([Vedeu::Models::Row.coerce(value)])
17
+ class << self
30
18
 
31
- elsif value.is_a?(Array) || value.is_a?(Vedeu::Buffers::View)
32
- values = value.map { |v| Vedeu::Models::Row.coerce(v) }
19
+ extend Forwardable
33
20
 
34
- Vedeu::Models::Page.new(values)
21
+ def_delegators Vedeu::Coercers::Page,
22
+ :coerce
35
23
 
36
- else
37
- fail Vedeu::Error::InvalidSyntax,
38
- 'Cannot coerce as value is not an Array, Vedeu::Models::Page ' \
39
- "or Vedeu::Models::Row. Is a '#{value.class.name}'."
40
-
41
- end
42
- end
24
+ end # Eigenclass
43
25
 
44
26
  # Returns a new instance of Vedeu::Models::Page.
45
27
  #
@@ -15,23 +15,14 @@ module Vedeu
15
15
  # @return [Array<NilClass|void>]
16
16
  attr_reader :cells
17
17
 
18
- # @param value [Vedeu::Models::Row|Array<void>|void]
19
- # @return [Vedeu::Models::Row]
20
- def self.coerce(value)
21
- if value.is_a?(self)
22
- value
23
-
24
- elsif value.is_a?(Array)
25
- new(value.compact)
18
+ class << self
26
19
 
27
- elsif value.nil?
28
- new
20
+ extend Forwardable
29
21
 
30
- else
31
- new([value])
22
+ def_delegators Vedeu::Coercers::Row,
23
+ :coerce
32
24
 
33
- end
34
- end
25
+ end # Eigenclass
35
26
 
36
27
  # Returns a new instance of Vedeu::Models::Row.
37
28
  #
@@ -43,8 +43,7 @@ module Vedeu
43
43
  show
44
44
  end
45
45
 
46
- # Provide class methods to models to allow the visibility to be
47
- # changed.
46
+ # Provide additional behaviour as class methods.
48
47
  #
49
48
  module ClassMethods
50
49
 
@@ -146,11 +145,7 @@ module Vedeu
146
145
 
147
146
  end # ClassMethods
148
147
 
149
- # When this module is included in a class, provide ClassMethods as
150
- # class methods for the class.
151
- #
152
- # @param klass [Class]
153
- # @return [void]
148
+ # @macro included_module
154
149
  def self.included(klass)
155
150
  klass.extend(Vedeu::Toggleable::ClassMethods)
156
151
  end
@@ -37,6 +37,7 @@ module Vedeu
37
37
 
38
38
  # Load the plugin (require the gem).
39
39
  #
40
+ # @macro raise_fatal
40
41
  # @return [void]
41
42
  def load!
42
43
  begin
@@ -19,26 +19,10 @@ module Vedeu
19
19
 
20
20
  class << self
21
21
 
22
- include Vedeu::Common
23
-
24
- # Produces new objects of the correct class from the value,
25
- # ignores objects that have already been coerced.
26
- #
27
- # @param value [Object|NilClass]
28
- # @return [Object]
29
- def coerce(value)
30
- return value if value.is_a?(Vedeu::Presentation::Style)
31
- return new(value) unless value.is_a?(Hash)
32
- return new unless present?(value[:style])
33
-
34
- if value[:style].is_a?(Vedeu::Presentation::Style)
35
- value[:style]
36
-
37
- else
38
- new(value[:style])
39
-
40
- end
41
- end
22
+ extend Forwardable
23
+
24
+ def_delegators Vedeu::Coercers::Style,
25
+ :coerce
42
26
 
43
27
  end # Eigenclass
44
28