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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8abebd20481d927ef3b7de1f4a21c566109fcb5a
4
- data.tar.gz: 3db48c0f3218d6d534cf731f256084e6a98efb91
3
+ metadata.gz: 83b3e4909563317ccf8df15a1f8e0106f27ca00a
4
+ data.tar.gz: fc3fce16bcc6f5648854b4897b493aaf6b04857e
5
5
  SHA512:
6
- metadata.gz: e6555ade9af405d42797525c9ce496d4e6f105babf54d6edbfe5cf2fcbc618b71823b9709544fca60c8c2a853918d4d259dc372ca56bf037061d351add0f5016
7
- data.tar.gz: 057a89420029e115a3a87bcdc56872d0e01b0149e08c4d29899870632a0e989377b09b295bf7be4f94f4e8ed8800c1fec1a59292cb635696bca7d2604edee9c5
6
+ metadata.gz: 32aa195136e7b3cbbfa16018dba9c6da366df448e2a4a432c232485808bbad8d0c5dd4f9154d5313ccb9a1867373b607142dad8859a90474c738deca068d2f94
7
+ data.tar.gz: efdbc099065362fd76ecc407f50915ebad6285b0f36707153fe7a2266f8603be7620aaefb87abb34871730db610527bddfda04783258c51b9bf9051273727019
@@ -1 +1,6 @@
1
- @todo Add more documentation.
1
+ Instruct Vedeu to focus the view with the given name.
2
+
3
+ @todo Add more documentation
4
+ - What would happen if the view was not currently visible?
5
+ - What would happen if the view was occupying the same space as
6
+ another view?
@@ -1 +1,8 @@
1
+ Instruct Vedeu to focus the next visible view.
2
+
3
+ Vedeu.focus_next
4
+
5
+ Vedeu.trigger(:_focus_next_)
6
+
1
7
  @todo Add more documentation.
8
+ - How does this work with groups?
@@ -1 +1,8 @@
1
+ Instruct Vedeu to focus the previous visible view.
2
+
3
+ Vedeu.focus_previous
4
+
5
+ Vedeu.trigger(:_focus_prev_)
6
+
1
7
  @todo Add more documentation.
8
+ - How does this work with groups?
@@ -0,0 +1,8 @@
1
+ Triggered when Vedeu receives input from a mouse.
2
+
3
+ Binding to this event in the client application will give access to
4
+ the escape sequence emitted by the terminal.
5
+
6
+ Vedeu.bind(:_mouse_event_) do |input|
7
+ # ... some code ...
8
+ end
@@ -44,4 +44,16 @@ module Vedeu
44
44
 
45
45
  end # Vedeu
46
46
 
47
+ # Define some Yard macros used throughout the project.
48
+ #
49
+ # @!macro [new] included_module
50
+ # Provide additional behaviour to a class or module.
51
+ #
52
+ # When a ClassMethods submodule and/or an InstanceMethods submodule
53
+ # is defined within this module, then provide these methods as
54
+ # class or instance methods to the including class or module.
55
+ #
56
+ # @param klass [Class]
57
+ # @return [void]
58
+
47
59
  require 'vedeu/all'
@@ -7,6 +7,8 @@ require 'vedeu/sentence'
7
7
  require 'vedeu/version'
8
8
 
9
9
  require 'vedeu/support/point'
10
+ require 'vedeu/support/x_coordinate'
11
+ require 'vedeu/support/y_coordinate'
10
12
 
11
13
  require 'vedeu/configuration/all'
12
14
  require 'vedeu/esc/all'
@@ -6,7 +6,7 @@ module Vedeu
6
6
  #
7
7
  module Controller
8
8
 
9
- # When included, provide these methods as class methods.
9
+ # Provide additional behaviour as class methods.
10
10
  #
11
11
  module ClassMethods
12
12
 
@@ -75,11 +75,7 @@ module Vedeu
75
75
 
76
76
  end # ClassMethods
77
77
 
78
- # When this module is included in a class, provide ClassMethods as
79
- # class methods for the class.
80
- #
81
- # @param klass [Class]
82
- # @return [void]
78
+ # @macro included_module
83
79
  def self.included(klass)
84
80
  klass.extend(Vedeu::Controller::ClassMethods)
85
81
  end
@@ -58,7 +58,8 @@ module Vedeu
58
58
  def empty
59
59
  Array.new(height) do |h|
60
60
  Array.new(width) do |w|
61
- Vedeu::Cells::Empty.new(name: name, position: [y + h, x + w])
61
+ position = Vedeu::Geometries::Position.new((y + h), (x + w))
62
+ Vedeu::Cells::Empty.new(name: name, position: position)
62
63
  end
63
64
  end
64
65
  end
@@ -25,7 +25,7 @@ module Vedeu
25
25
 
26
26
  # @return [Hash<Symbol => String>]
27
27
  def defaults
28
- super.merge!(position: Vedeu::Geometries::Position.coerce([yn, x]),
28
+ super.merge!(position: Vedeu::Geometries::Position.new(yn, x),
29
29
  value: Vedeu.esc.bottom_left)
30
30
  end
31
31
 
@@ -25,7 +25,7 @@ module Vedeu
25
25
 
26
26
  # @return [Hash<Symbol => String>]
27
27
  def defaults
28
- super.merge!(position: Vedeu::Geometries::Position.coerce([yn, xn]),
28
+ super.merge!(position: Vedeu::Geometries::Position.new(yn, xn),
29
29
  value: Vedeu.esc.bottom_right)
30
30
  end
31
31
 
@@ -25,7 +25,7 @@ module Vedeu
25
25
 
26
26
  # @return [Hash<Symbol => String>]
27
27
  def defaults
28
- super.merge!(position: Vedeu::Geometries::Position.coerce([y, x]),
28
+ super.merge!(position: Vedeu::Geometries::Position.new(y, x),
29
29
  value: Vedeu.esc.top_left)
30
30
  end
31
31
 
@@ -25,7 +25,7 @@ module Vedeu
25
25
 
26
26
  # @return [Hash<Symbol => String>]
27
27
  def defaults
28
- super.merge!(position: Vedeu::Geometries::Position.coerce([y, xn]),
28
+ super.merge!(position: Vedeu::Geometries::Position.new(y, xn),
29
29
  value: Vedeu.esc.top_right)
30
30
  end
31
31
 
@@ -16,13 +16,9 @@ module Vedeu
16
16
 
17
17
  # @return [String]
18
18
  def as_html
19
- if present?(value)
20
- value
19
+ return value if present?(value)
21
20
 
22
- else
23
- super
24
-
25
- end
21
+ super
26
22
  end
27
23
 
28
24
  # @return [Boolean]
@@ -58,7 +58,7 @@ module Vedeu
58
58
 
59
59
  # @return [Hash]
60
60
  def defaults
61
- super.merge!(position: [1, 1])
61
+ super.merge!(position: Vedeu::Geometries::Position.new(1, 1))
62
62
  end
63
63
 
64
64
  end # Cursor
@@ -39,13 +39,9 @@ module Vedeu
39
39
 
40
40
  # @return [String]
41
41
  def background
42
- if cell.respond_to?(:background)
43
- cell.background.to_html
42
+ return '' unless cell.respond_to?(:background)
44
43
 
45
- else
46
- ''
47
-
48
- end
44
+ cell.background.to_html
49
45
  end
50
46
 
51
47
  # @return [String]
@@ -55,13 +51,9 @@ module Vedeu
55
51
 
56
52
  # @return [String]
57
53
  def foreground
58
- if cell.respond_to?(:foreground)
59
- cell.foreground.to_html
60
-
61
- else
62
- ''
54
+ return '' unless cell.respond_to?(:foreground)
63
55
 
64
- end
56
+ cell.foreground.to_html
65
57
  end
66
58
 
67
59
  # @return [String]
@@ -71,13 +63,9 @@ module Vedeu
71
63
 
72
64
  # @return [String]
73
65
  def style_attribute
74
- if absent?(background) && absent?(foreground)
75
- ''
76
-
77
- else
78
- " style='#{background}#{foreground}'"
66
+ return '' if absent?(background) && absent?(foreground)
79
67
 
80
- end
68
+ " style='#{background}#{foreground}'"
81
69
  end
82
70
 
83
71
  # @return [String]
@@ -2,7 +2,10 @@
2
2
 
3
3
  module Vedeu
4
4
 
5
- # Provides a mechanism to coerce values within Vedeu.
5
+ # Provides a mechanism to coerce values within Vedeu in to expected
6
+ # objects.
7
+ #
8
+ # @api private
6
9
  #
7
10
  module Coercers
8
11
 
@@ -10,9 +13,23 @@ module Vedeu
10
13
 
11
14
  end # Vedeu
12
15
 
16
+ require 'vedeu/coercers/coercer'
17
+
13
18
  require 'vedeu/coercers/alignment'
14
19
  require 'vedeu/coercers/horizontal_alignment'
15
20
  require 'vedeu/coercers/vertical_alignment'
16
21
 
22
+ require 'vedeu/coercers/chars'
23
+
17
24
  require 'vedeu/coercers/colour'
18
25
  require 'vedeu/coercers/colour_attributes'
26
+
27
+ require 'vedeu/coercers/editor_line'
28
+ require 'vedeu/coercers/editor_lines'
29
+
30
+ require 'vedeu/coercers/lines'
31
+ require 'vedeu/coercers/page'
32
+ require 'vedeu/coercers/position'
33
+ require 'vedeu/coercers/row'
34
+ require 'vedeu/coercers/streams'
35
+ require 'vedeu/coercers/style'
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vedeu
4
+
5
+ module Coercers
6
+
7
+ # Provides the mechanism to convert a value into a
8
+ # {Vedeu::Views::Chars}.
9
+ #
10
+ # @api private
11
+ #
12
+ class Chars < Vedeu::Coercers::Coercer
13
+
14
+ # @return [void]
15
+ def coerce
16
+ end
17
+
18
+ private
19
+
20
+ # @return [Class]
21
+ def klass
22
+ Vedeu::Views::Chars
23
+ end
24
+
25
+ end # Chars
26
+
27
+ end # Coercers
28
+
29
+ end # Vedeu
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vedeu
4
+
5
+ module Coercers
6
+
7
+ # Provides the mechanism to convert a value into another value.
8
+ #
9
+ # @api private
10
+ #
11
+ class Coercer
12
+
13
+ include Vedeu::Common
14
+
15
+ # @param (see #initialize)
16
+ # @return (see #coerce)
17
+ def self.coerce(value)
18
+ new(value).coerce
19
+ end
20
+
21
+ # Returns a new instance of the Vedeu::Coercers::Coercer
22
+ # subclass.
23
+ #
24
+ # @param value [void]
25
+ # @return [Vedeu::Coercers::Coercer]
26
+ def initialize(value)
27
+ @value = value
28
+ end
29
+
30
+ # @macro raise_not_implemented
31
+ # @return [void]
32
+ def coerce
33
+ fail Vedeu::Error::NotImplemented, 'Subclasses implement this.'
34
+ end
35
+
36
+ protected
37
+
38
+ # @!attribute [r] value
39
+ # @return [void]
40
+ attr_reader :value
41
+
42
+ private
43
+
44
+ # @return [Boolean]
45
+ def coerced?
46
+ value.is_a?(klass)
47
+ end
48
+
49
+ # @macro raise_not_implemented
50
+ # @return [Class]
51
+ def klass
52
+ fail Vedeu::Error::NotImplemented, 'Subclasses implement this.'
53
+ end
54
+
55
+ end # Coercer
56
+
57
+ end # Coercers
58
+
59
+ end # Vedeu
@@ -9,40 +9,28 @@ module Vedeu
9
9
  #
10
10
  # @api private
11
11
  #
12
- class Colour
12
+ class Colour < Vedeu::Coercers::Coercer
13
13
 
14
14
  include Vedeu::Common
15
15
 
16
- # @param (see #initialize)
17
- # @return (see #coerce)
18
- def self.coerce(value)
19
- new(value).coerce
20
- end
21
-
22
- # @param value [void]
23
- # @return [Vedeu::Coercers::Colour]
24
- def initialize(value)
25
- @value = value
26
- end
27
-
28
- # @raise [Vedeu::Error::Fatal] When the value cannot be coerced.
16
+ # @macro raise_fatal
29
17
  # @return [void]
30
18
  def coerce
31
- if absent?(value)
32
- Vedeu::Colours::Colour.new
19
+ if coerced?
20
+ value
33
21
 
34
- elsif background?
35
- Vedeu::Colours::Colour.new(background: value)
22
+ elsif absent?(value)
23
+ klass.new
36
24
 
37
- elsif colour?
38
- value
25
+ elsif background?
26
+ klass.new(background: value)
39
27
 
40
28
  elsif foreground?
41
- Vedeu::Colours::Colour.new(foreground: value)
29
+ klass.new(foreground: value)
42
30
 
43
31
  elsif hash?(value)
44
32
  attributes = Vedeu::Coercers::ColourAttributes.coerce(value)
45
- Vedeu::Colours::Colour.new(attributes)
33
+ klass.new(attributes)
46
34
 
47
35
  else
48
36
  fail Vedeu::Error::Fatal, 'Vedeu cannot coerce this colour.'
@@ -50,12 +38,6 @@ module Vedeu
50
38
  end
51
39
  end
52
40
 
53
- protected
54
-
55
- # @!attribute [r] value
56
- # @return [void]
57
- attr_reader :value
58
-
59
41
  private
60
42
 
61
43
  # @return [Boolean]
@@ -63,16 +45,16 @@ module Vedeu
63
45
  value.is_a?(Vedeu::Colours::Background)
64
46
  end
65
47
 
66
- # @return [Boolean]
67
- def colour?
68
- value.is_a?(Vedeu::Colours::Colour)
69
- end
70
-
71
48
  # @return [Boolean]
72
49
  def foreground?
73
50
  value.is_a?(Vedeu::Colours::Foreground)
74
51
  end
75
52
 
53
+ # @return [Class]
54
+ def klass
55
+ Vedeu::Colours::Colour
56
+ end
57
+
76
58
  end # Colour
77
59
 
78
60
  end # Coercers
@@ -33,7 +33,7 @@ module Vedeu
33
33
  if colour? && hash?(colour)
34
34
  Vedeu::Coercers::ColourAttributes.coerce(colour)
35
35
 
36
- elsif colour? && already_coerced?(colour)
36
+ elsif colour? && coerced?(colour)
37
37
  colour.attributes
38
38
 
39
39
  else
@@ -52,8 +52,8 @@ module Vedeu
52
52
 
53
53
  # @param colour [void]
54
54
  # @return [Boolean]
55
- def already_coerced?(colour)
56
- colour.is_a?(Vedeu::Colours::Colour)
55
+ def coerced?(colour)
56
+ colour.is_a?(klass)
57
57
  end
58
58
 
59
59
  # @return [Hash]
@@ -104,6 +104,11 @@ module Vedeu
104
104
  valid?(foreground)
105
105
  end
106
106
 
107
+ # @return [Class]
108
+ def klass
109
+ Vedeu::Colours::Colour
110
+ end
111
+
107
112
  # @param colour [void]
108
113
  # @return [Boolean]
109
114
  def valid?(colour)