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
@@ -0,0 +1,36 @@
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::Editor::Line}.
9
+ #
10
+ # @api private
11
+ #
12
+ class EditorLine < Vedeu::Coercers::Coercer
13
+
14
+ # @return [void]
15
+ def coerce
16
+ if coerced?
17
+ value
18
+
19
+ else
20
+
21
+
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # @return [Class]
28
+ def klass
29
+ Vedeu::Editor::Line
30
+ end
31
+
32
+ end # EditorLine
33
+
34
+ end # Coercers
35
+
36
+ end # Vedeu
@@ -0,0 +1,36 @@
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::Editor::Lines}.
9
+ #
10
+ # @api private
11
+ #
12
+ class EditorLines < Vedeu::Coercers::Coercer
13
+
14
+ # @return [void]
15
+ def coerce
16
+ if coerced?
17
+ value
18
+
19
+ else
20
+
21
+
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # @return [Class]
28
+ def klass
29
+ Vedeu::Editor::Lines
30
+ end
31
+
32
+ end # EditorLines
33
+
34
+ end # Coercers
35
+
36
+ end # Vedeu
@@ -0,0 +1,36 @@
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::Lines}.
9
+ #
10
+ # @api private
11
+ #
12
+ class Lines < Vedeu::Coercers::Coercer
13
+
14
+ # @return [void]
15
+ def coerce
16
+ if coerced?
17
+ value
18
+
19
+ else
20
+
21
+
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ # @return [Class]
28
+ def klass
29
+ Vedeu::Views::Lines
30
+ end
31
+
32
+ end # Lines
33
+
34
+ end # Coercers
35
+
36
+ end # Vedeu
@@ -0,0 +1,52 @@
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::Models::Page}.
9
+ #
10
+ # @api private
11
+ #
12
+ class Page < Vedeu::Coercers::Coercer
13
+
14
+ # @param value
15
+ # [Vedeu::Models::Page|Vedeu::Models::Row|Array<void>|void]
16
+ # @macro raise_invalid_syntax
17
+ # @return [Vedeu::Models::Page]
18
+ def coerce
19
+ if coerced?
20
+ value
21
+
22
+ elsif value.is_a?(Vedeu::Models::Row)
23
+ klass.new([value])
24
+
25
+ elsif value.is_a?(Array) && value.empty?
26
+ klass.new([Vedeu::Models::Row.coerce(value)])
27
+
28
+ elsif value.is_a?(Array) || value.is_a?(Vedeu::Buffers::View)
29
+ values = value.map { |v| Vedeu::Models::Row.coerce(v) }
30
+
31
+ klass.new(values)
32
+
33
+ else
34
+ fail Vedeu::Error::InvalidSyntax,
35
+ "Cannot coerce as value is not an Array, #{klass} " \
36
+ "or Vedeu::Models::Row. Is a '#{value.class.name}'."
37
+
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ # @return [Class]
44
+ def klass
45
+ Vedeu::Models::Page
46
+ end
47
+
48
+ end # Page
49
+
50
+ end # Coercers
51
+
52
+ end # Vedeu
@@ -0,0 +1,69 @@
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::Geometries::Position}.
9
+ #
10
+ # @api private
11
+ #
12
+ class Position < Vedeu::Coercers::Coercer
13
+
14
+ # @macro raise_fatal
15
+ # @return [NilClass|Vedeu::Geometries::Position]
16
+ def coerce
17
+ if value.nil? || coerced?
18
+ value
19
+
20
+ elsif tuple?
21
+ klass.new(*value)
22
+
23
+ elsif hash?
24
+ klass.new(value.fetch(:y, 1), value.fetch(:x, 1))
25
+
26
+ elsif fixnum?
27
+ klass.new(value, 1)
28
+
29
+ else
30
+ fail Vedeu::Error::Fatal,
31
+ "Vedeu cannot coerce a '#{value.class.name}' into a " \
32
+ "'#{klass}'."
33
+
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ # @return [Boolean]
40
+ def fixnum?
41
+ value.is_a?(Fixnum)
42
+ end
43
+
44
+ # @return [Boolean]
45
+ def hash?
46
+ value.is_a?(Hash)
47
+ end
48
+
49
+ # @return [Class]
50
+ def klass
51
+ Vedeu::Geometries::Position
52
+ end
53
+
54
+ # @macro raise_fatal
55
+ # @return [Boolean]
56
+ def tuple?
57
+ return false unless value.is_a?(Array)
58
+ return true if value.size == 2
59
+
60
+ fail Vedeu::Error::Fatal,
61
+ "A '#{klass}' is made up of two elements. (Provided " \
62
+ "#{value.size}.)"
63
+ end
64
+
65
+ end # Position
66
+
67
+ end # Coercers
68
+
69
+ end # Vedeu
@@ -0,0 +1,43 @@
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::Models::Row}.
9
+ #
10
+ # @api private
11
+ #
12
+ class Row < Vedeu::Coercers::Coercer
13
+
14
+ # @param value [Vedeu::Models::Row|Array<void>|void]
15
+ # @return [Vedeu::Models::Row]
16
+ def coerce
17
+ if coerced?
18
+ value
19
+
20
+ elsif value.is_a?(Array)
21
+ klass.new(value.compact)
22
+
23
+ elsif value.nil?
24
+ klass.new
25
+
26
+ else
27
+ klass.new([value])
28
+
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ # @return [Class]
35
+ def klass
36
+ Vedeu::Models::Row
37
+ end
38
+
39
+ end # Row
40
+
41
+ end # Coercers
42
+
43
+ end # Vedeu
@@ -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::Streams}.
9
+ #
10
+ # @api private
11
+ #
12
+ class Streams < 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::Streams
23
+ end
24
+
25
+ end # Streams
26
+
27
+ end # Coercers
28
+
29
+ end # Vedeu
@@ -0,0 +1,54 @@
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::Presentation::Style}.
9
+ #
10
+ # @api private
11
+ #
12
+ class Style < Vedeu::Coercers::Coercer
13
+
14
+ # Produces new objects of the correct class from the value,
15
+ # ignores objects that have already been coerced.
16
+ #
17
+ # @return [Vedeu::Presentation::Style]
18
+ def coerce
19
+ if coerced?
20
+ value
21
+
22
+ elsif value.is_a?(Hash)
23
+ if present?(value[:style])
24
+ if value[:style].is_a?(klass)
25
+ value[:style]
26
+
27
+ else
28
+ Vedeu::Coercers::Style.coerce(value[:style])
29
+
30
+ end
31
+
32
+ else
33
+ klass.new
34
+
35
+ end
36
+
37
+ else
38
+ klass.new(value)
39
+
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ # @return [Class]
46
+ def klass
47
+ Vedeu::Presentation::Style
48
+ end
49
+
50
+ end # Style
51
+
52
+ end # Coercers
53
+
54
+ end # Vedeu
@@ -525,6 +525,16 @@ module Vedeu
525
525
  end
526
526
  alias terminal_mode= terminal_mode
527
527
 
528
+ # Instructs Vedeu to use threads to perform certain actions.
529
+ # This can have a performance impact.
530
+ #
531
+ # @param boolean [Boolean]
532
+ # @return [Boolean]
533
+ def threaded(boolean)
534
+ options[:threaded] = boolean
535
+ end
536
+ alias threaded= threaded
537
+
528
538
  # Sets the width of the terminal.
529
539
  #
530
540
  # Vedeu.configure do
@@ -269,6 +269,16 @@ module Vedeu
269
269
  instance.options[:terminal_mode]
270
270
  end
271
271
 
272
+ # Returns a boolean indicating whether Vedeu should use threads
273
+ # to perform certain actions. This can have a performance
274
+ # impact.
275
+ #
276
+ # @return [Boolean]
277
+ def threaded?
278
+ instance.options[:threaded]
279
+ end
280
+ alias threaded threaded?
281
+
272
282
  # Returns the client defined width for the terminal.
273
283
  #
274
284
  # {include:file:docs/dsl/by_method/width.md}
@@ -371,6 +381,7 @@ module Vedeu
371
381
  stdout: nil,
372
382
  stderr: nil,
373
383
  terminal_mode: :raw,
384
+ threaded: true,
374
385
  width: nil,
375
386
  }
376
387
  end
@@ -10,10 +10,18 @@ module Vedeu
10
10
  #
11
11
  class Coordinate
12
12
 
13
+ extend Forwardable
14
+
15
+ def_delegators :coordinate,
16
+ :d,
17
+ :bd,
18
+ :bdn,
19
+ :d_dn
20
+
13
21
  # Return a new instance of Vedeu::Cursors::Coordinate.
14
22
  #
15
23
  # @param attributes [Hash<Symbol => Fixnum|String|Symbol>]
16
- # @option attributes name [String|Symbol]
24
+ # @option attributes geometry [Vedeu::Geometries::Geometry]
17
25
  # @option attributes type [Symbol]
18
26
  # @option attributes offset [Fixnum]
19
27
  # @return [Vedeu::Cursors::Coordinate]
@@ -50,27 +58,16 @@ module Vedeu
50
58
  #
51
59
  # @return [Fixnum]
52
60
  def d_position
53
- pos = if offset <= 0
54
- d
55
-
56
- elsif offset > dn_index
57
- dn_position
58
-
59
- else
60
- d_range[offset]
61
-
62
- end
63
-
64
- Vedeu::Point.coerce(value: pos, min: bd, max: bdn).value
61
+ Vedeu::Point.coerce(value: position, min: bd, max: bdn).value
65
62
  end
66
63
  alias x d_position
67
64
  alias y d_position
68
65
 
69
66
  protected
70
67
 
71
- # @!attribute [r] name
72
- # @return [String|Symbol]
73
- attr_reader :name
68
+ # @!attribute [r] geometry
69
+ # @return [Vedeu::Geometries::Geometry]
70
+ attr_reader :geometry
74
71
 
75
72
  # @!attribute [r] offset
76
73
  # @return [Fixnum]
@@ -82,54 +79,16 @@ module Vedeu
82
79
 
83
80
  private
84
81
 
85
- # Returns the geometry for the interface.
86
- #
87
- # @return (see Vedeu::Geometries::Repository#by_name)
88
- def geometry
89
- @geometry ||= Vedeu.geometries.by_name(name)
90
- end
91
-
92
- # Return the :x or :y value from the geometry.
93
- #
94
- # @return [Fixnum]
95
- def d
96
- geometry.send(coordinate_type[0])
97
- end
98
-
99
- # Return the :bx or :by value from the geometry.
100
- #
101
- # @return [Fixnum]
102
- def bd
103
- geometry.send(coordinate_type[1])
104
- end
105
-
106
- # Return the :bxn or :byn value from the geometry.
107
- #
108
- # @return [Fixnum]
109
- def bdn
110
- geometry.send(coordinate_type[2])
111
- end
112
-
113
- # Return the :width or :height value from the geometry.
114
- #
115
- # @return [Fixnum]
116
- def d_dn
117
- geometry.send(coordinate_type[3])
118
- end
119
-
120
- # Ascertain the correct methods to use for determining the
121
- # coordinates.
122
- #
123
82
  # @macro raise_invalid_syntax
124
- # @return [Fixnum]
125
- def coordinate_type
126
- @_type ||= case type
127
- when :x then [:x, :bx, :bxn, :bordered_width]
128
- when :y then [:y, :by, :byn, :bordered_height]
129
- else
130
- fail Vedeu::Error::InvalidSyntax,
131
- 'Coordinate type not given, cannot continue.'
132
- end
83
+ # @return [Vedeu::XCoordinate|Vedeu::YCoordinate]
84
+ def coordinate
85
+ @_coordinate ||= case type
86
+ when :x then Vedeu::XCoordinate.new(geometry)
87
+ when :y then Vedeu::YCoordinate.new(geometry)
88
+ else
89
+ fail Vedeu::Error::InvalidSyntax,
90
+ 'Coordinate type not given, cannot continue.'
91
+ end
133
92
  end
134
93
 
135
94
  # Returns the maximum index for an area.
@@ -163,12 +122,28 @@ module Vedeu
163
122
  # @return [Hash<Symbol => Fixnum|String|Symbol>]
164
123
  def defaults
165
124
  {
166
- name: '',
167
- offset: nil,
168
- type: :x,
125
+ geometry: nil,
126
+ offset: nil,
127
+ type: :x,
169
128
  }
170
129
  end
171
130
 
131
+ # Return the position respective of the offset.
132
+ #
133
+ # @return [Fixnum]
134
+ def position
135
+ if offset <= 0
136
+ d
137
+
138
+ elsif offset > dn_index
139
+ dn_position
140
+
141
+ else
142
+ d_range[offset]
143
+
144
+ end
145
+ end
146
+
172
147
  end # Coordinate
173
148
 
174
149
  end # Cursors