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
@@ -21,9 +21,10 @@ module Vedeu
21
21
  # @return [Array<void>]
22
22
  def clear
23
23
  storage.map do |renderer|
24
- log('Clearing', renderer)
24
+ Vedeu.log(type: :render,
25
+ message: "Clearing via #{renderer.class.name}")
25
26
 
26
- threaded(renderer) { renderer.clear }
27
+ perform(renderer) { renderer.clear }
27
28
  end.each(&:join) if Vedeu.ready?
28
29
 
29
30
  ''
@@ -49,9 +50,10 @@ module Vedeu
49
50
  # @return [Array<void>]
50
51
  def render(output)
51
52
  storage.map do |renderer|
52
- log('Rendering', renderer)
53
+ Vedeu.log(type: :render,
54
+ message: "Rendering via #{renderer.class.name}")
53
55
 
54
- threaded(renderer) { renderer.render(output) }
56
+ perform(renderer) { renderer.render(output) }
55
57
  end.each(&:join) if Vedeu.ready?
56
58
 
57
59
  output
@@ -70,12 +72,16 @@ module Vedeu
70
72
  end
71
73
  end
72
74
 
73
- # @param message [String]
74
- # @param renderer [Class]
75
- # @return [void]
76
- def log(message, renderer)
77
- Vedeu.log(type: :render,
78
- message: "#{message} via #{renderer.class.name}")
75
+ # @param renderer [void]
76
+ # @param block [Proc]
77
+ def perform(renderer, &block)
78
+ if Vedeu.config.threaded?
79
+ threaded(renderer) { yield }
80
+
81
+ else
82
+ unthreaded { yield }
83
+
84
+ end
79
85
  end
80
86
 
81
87
  # @return [Mutex]
@@ -105,6 +111,14 @@ module Vedeu
105
111
  Vedeu.trigger(:_show_cursor_)
106
112
  end
107
113
 
114
+ # @param block [Proc]
115
+ # @return [void]
116
+ def unthreaded(&block)
117
+ toggle_cursor do
118
+ yield
119
+ end
120
+ end
121
+
108
122
  end # Renderers
109
123
 
110
124
  # @example
@@ -16,9 +16,7 @@ module Vedeu
16
16
  # @return [Vedeu::Repositories::Repository]
17
17
  attr_accessor :repository
18
18
 
19
- # When {Vedeu::Repositories::Model} is included in a class, the
20
- # methods within this module are included as class methods on
21
- # that class.
19
+ # Provide additional behaviour as class methods.
22
20
  #
23
21
  module ClassMethods
24
22
 
@@ -68,11 +66,7 @@ module Vedeu
68
66
 
69
67
  end # ClassMethods
70
68
 
71
- # When this module is included in a class, provide ClassMethods
72
- # as class methods for the class.
73
- #
74
- # @param klass [Class]
75
- # @return [void]
69
+ # @macro included_module
76
70
  def self.included(klass)
77
71
  klass.extend(Vedeu::Repositories::Model::ClassMethods)
78
72
  end
@@ -9,7 +9,8 @@ module Vedeu
9
9
  #
10
10
  module Registerable
11
11
 
12
- # These class methods are mixed into the repository.
12
+ # Provide additional behaviour as class methods.
13
+ #
13
14
  module ClassMethods
14
15
 
15
16
  # The null model is used when the repository cannot be found.
@@ -64,9 +65,7 @@ module Vedeu
64
65
 
65
66
  end # ClassMethods
66
67
 
67
- # When {Vedeu::Repositories::Registerable} is included in a
68
- # class, the methods within this module are included as instance
69
- # methods on that class.
68
+ # Provide additional behaviour as instance methods.
70
69
  #
71
70
  module InstanceMethods
72
71
 
@@ -77,11 +76,7 @@ module Vedeu
77
76
 
78
77
  end # InstanceMethods
79
78
 
80
- # When this module is included in a class, provide ClassMethods
81
- # as class methods for the class.
82
- #
83
- # @param klass [Class]
84
- # @return [void]
79
+ # @macro included_module
85
80
  def self.included(klass)
86
81
  klass.extend(Vedeu::Repositories::Registerable::ClassMethods)
87
82
  klass.include(Vedeu::Repositories::Registerable::InstanceMethods)
@@ -6,6 +6,8 @@ module Vedeu
6
6
 
7
7
  # Orchestrates the running of the main application loop.
8
8
  #
9
+ # @api private
10
+ #
9
11
  class Application
10
12
 
11
13
  class << self
@@ -6,6 +6,8 @@ module Vedeu
6
6
 
7
7
  # Home of various runtime flags which Vedeu uses.
8
8
  #
9
+ # @api public
10
+ #
9
11
  class Flags
10
12
 
11
13
  include Singleton
@@ -7,6 +7,8 @@ module Vedeu
7
7
  # Stores all client application controllers with their respective
8
8
  # actions.
9
9
  #
10
+ # @api public
11
+ #
10
12
  module Router
11
13
 
12
14
  include Vedeu::Common
@@ -12,21 +12,21 @@ module Vedeu
12
12
  # @param (see #initialize)
13
13
  # @macro raise_invalid_syntax
14
14
  # @return (see #initialize)
15
- def self.coerce(value: nil, min: 1, max: nil)
15
+ def self.coerce(value: nil, min: 1, max: Float::INFINITY)
16
16
  new(value: value, min: min, max: max).coerce
17
17
  end
18
18
 
19
19
  # @param (see #initialize)
20
20
  # @return (see #initialize)
21
- def self.valid?(value: nil, min: 1, max: nil)
21
+ def self.valid?(value: nil, min: 1, max: Float::INFINITY)
22
22
  new(value: value, min: min, max: max).valid?
23
23
  end
24
24
 
25
25
  # @param value [Fixnum|NilClass]
26
26
  # @param min [Fixnum]
27
- # @param max [Fixnum]
27
+ # @param max [Fixnum|Float::INFINITY]
28
28
  # @return [Vedeu::Point]
29
- def initialize(value: nil, min: 1, max: nil)
29
+ def initialize(value: nil, min: 1, max: Float::INFINITY)
30
30
  @min = min
31
31
  @max = max
32
32
  @value = value
@@ -67,15 +67,17 @@ module Vedeu
67
67
  def min
68
68
  return @min if @min.is_a?(Fixnum)
69
69
 
70
- fail Vedeu::Error::InvalidSyntax, "Expecting 'min' to be a Fixnum."
70
+ fail Vedeu::Error::InvalidSyntax,
71
+ "Expecting 'min' to be a Fixnum."
71
72
  end
72
73
 
73
74
  # @macro raise_invalid_syntax
74
75
  # @return [Fixnum]
75
76
  def max
76
- return @max if @max.is_a?(Fixnum)
77
+ return @max if @max.is_a?(Fixnum) || @max == Float::INFINITY
77
78
 
78
- fail Vedeu::Error::InvalidSyntax, "Expecting 'max' to be a Fixnum."
79
+ fail Vedeu::Error::InvalidSyntax,
80
+ "Expecting 'max' to be a Fixnum or Float::INFINITY."
79
81
  end
80
82
 
81
83
  end # Point
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vedeu
4
+
5
+ # Provide delegation methods for Vedeu::Geometries::Geometry.
6
+ #
7
+ # @api private
8
+ #
9
+ class XCoordinate
10
+
11
+ # @param geometry [Vedeu::Geometries::Geometry]
12
+ # @return [Vedeu::XCoordinate]
13
+ def initialize(geometry)
14
+ @geometry = geometry
15
+ end
16
+
17
+ # Return the :x value from the geometry.
18
+ #
19
+ # @return [Fixnum]
20
+ def d
21
+ geometry.x
22
+ end
23
+ alias x d
24
+
25
+ # Return the :bx value from the geometry.
26
+ #
27
+ # @return [Fixnum]
28
+ def bd
29
+ geometry.bx
30
+ end
31
+ alias bx bd
32
+
33
+ # Return the :bxn value from the geometry.
34
+ #
35
+ # @return [Fixnum]
36
+ def bdn
37
+ geometry.bxn
38
+ end
39
+ alias bxn bdn
40
+
41
+ # Return the :bordered_width value from the geometry.
42
+ #
43
+ # @return [Fixnum]
44
+ def d_dn
45
+ geometry.bordered_width
46
+ end
47
+ alias bordered_width d_dn
48
+
49
+ protected
50
+
51
+ # @!attribute [r] geometry
52
+ # @return [Vedeu::Geometries::Geometry]
53
+ attr_reader :geometry
54
+
55
+ end # XCoordinate
56
+
57
+ end # Vedeu
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vedeu
4
+
5
+ # Provide delegation methods for Vedeu::Geometries::Geometry.
6
+ #
7
+ # @api private
8
+ #
9
+ class YCoordinate
10
+
11
+ # @param geometry [Vedeu::Geometries::Geometry]
12
+ # @return [Vedeu::XCoordinate]
13
+ def initialize(geometry)
14
+ @geometry = geometry
15
+ end
16
+
17
+ # Return the :y value from the geometry.
18
+ #
19
+ # @return [Fixnum]
20
+ def d
21
+ geometry.y
22
+ end
23
+ alias y d
24
+
25
+ # Return the :by value from the geometry.
26
+ #
27
+ # @return [Fixnum]
28
+ def bd
29
+ geometry.by
30
+ end
31
+ alias by bd
32
+
33
+ # Return the :byn value from the geometry.
34
+ #
35
+ # @return [Fixnum]
36
+ def bdn
37
+ geometry.byn
38
+ end
39
+ alias byn bdn
40
+
41
+ # Return the :bordered_height value from the geometry.
42
+ #
43
+ # @return [Fixnum]
44
+ def d_dn
45
+ geometry.bordered_height
46
+ end
47
+ alias bordered_height d_dn
48
+
49
+ protected
50
+
51
+ # @!attribute [r] geometry
52
+ # @return [Vedeu::Geometries::Geometry]
53
+ attr_reader :geometry
54
+
55
+ end # YCoordinate
56
+
57
+ end # Vedeu
@@ -5,6 +5,8 @@ module Vedeu
5
5
  # This module is the direct interface between Vedeu and your
6
6
  # terminal/ console, via Ruby's IO core library.
7
7
  #
8
+ # @api private
9
+ #
8
10
  module Terminal
9
11
 
10
12
  include Vedeu::Terminal::Mode
@@ -3,6 +3,6 @@
3
3
  module Vedeu
4
4
 
5
5
  # The current version of Vedeu.
6
- VERSION = '0.8.8'.freeze
6
+ VERSION = '0.8.9'.freeze
7
7
 
8
8
  end
@@ -10,9 +10,7 @@ module Vedeu
10
10
  #
11
11
  module Value
12
12
 
13
- # Provides view model class methods for Vedeu::Views.
14
- #
15
- # @api private
13
+ # Provide additional behaviour as class methods.
16
14
  #
17
15
  module ClassMethods
18
16
 
@@ -58,9 +56,7 @@ module Vedeu
58
56
 
59
57
  end # ClassMethods
60
58
 
61
- # Provides view model instance methods for Vedeu::Views.
62
- #
63
- # @api private
59
+ # Provide additional behaviour as instance methods.
64
60
  #
65
61
  module InstanceMethods
66
62
 
@@ -128,12 +124,7 @@ module Vedeu
128
124
 
129
125
  end # InstanceMethods
130
126
 
131
- # When this module is included in a class, provide ClassMethods
132
- # as class methods and InstanceMethods as instance methods for
133
- # the given class.
134
- #
135
- # @param klass [Class]
136
- # @return [void]
127
+ # @macro included_module
137
128
  def self.included(klass)
138
129
  klass.extend(Vedeu::Views::Value::ClassMethods)
139
130
  klass.include(Vedeu::Views::Value::InstanceMethods)
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Vedeu
6
+
7
+ module Coercers
8
+
9
+ describe Chars do
10
+
11
+ let(:described) { Vedeu::Coercers::Chars }
12
+ let(:instance) { described.new(_value) }
13
+ let(:_value) {}
14
+ let(:klass) { Vedeu::Views::Chars }
15
+
16
+ describe '#initialize' do
17
+ it { instance.must_be_instance_of(described) }
18
+ it { instance.instance_variable_get('@value').must_equal(_value) }
19
+ end
20
+
21
+ describe '.coerce' do
22
+ it { described.must_respond_to(:coerce) }
23
+ end
24
+
25
+ describe '#coerce' do
26
+ subject { instance.coerce }
27
+ end
28
+
29
+ end # Chars
30
+
31
+ end # Coercers
32
+
33
+ end # Vedeu
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Vedeu
6
+
7
+ module Coercers
8
+
9
+ describe Coercer do
10
+
11
+ let(:described) { Vedeu::Coercers::Coercer }
12
+ let(:instance) { described.new(_value) }
13
+ let(:_value) {}
14
+
15
+ describe '#initialize' do
16
+ it { instance.must_be_instance_of(described) }
17
+ it { instance.instance_variable_get('@value').must_equal(_value) }
18
+ end
19
+
20
+ describe '.coerce' do
21
+ it { described.must_respond_to(:coerce) }
22
+ end
23
+
24
+ describe '#coerce' do
25
+ subject { instance.coerce }
26
+
27
+ it { proc { subject }.must_raise(Vedeu::Error::NotImplemented) }
28
+ end
29
+
30
+ end # Coercer
31
+
32
+ end # Coercers
33
+
34
+ end # Vedeu
@@ -11,6 +11,7 @@ module Vedeu
11
11
  let(:described) { Vedeu::Coercers::Colour }
12
12
  let(:instance) { described.new(_value) }
13
13
  let(:_value) {}
14
+ let(:klass) { Vedeu::Colours::Colour }
14
15
 
15
16
  describe '#initialize' do
16
17
  it { instance.must_be_instance_of(described) }
@@ -21,7 +22,7 @@ module Vedeu
21
22
  subject { described.coerce(_value) }
22
23
 
23
24
  context 'when the value is nil' do
24
- it { subject.must_be_instance_of(Vedeu::Colours::Colour) }
25
+ it { subject.must_be_instance_of(klass) }
25
26
  end
26
27
 
27
28
  context 'when the value is a Hash' do
@@ -32,7 +33,7 @@ module Vedeu
32
33
  }
33
34
  }
34
35
 
35
- it { subject.must_be_instance_of(Vedeu::Colours::Colour) }
36
+ it { subject.must_be_instance_of(klass) }
36
37
  it do
37
38
  subject.background.must_be_instance_of(Vedeu::Colours::Background)
38
39
  end
@@ -44,19 +45,20 @@ module Vedeu
44
45
  context 'when the value is a Vedeu::Colours::Background' do
45
46
  let(:_value) { Vedeu::Colours::Background.new('#aadd00') }
46
47
 
47
- it { subject.must_be_instance_of(Vedeu::Colours::Colour) }
48
+ it { subject.must_be_instance_of(klass) }
48
49
  end
49
50
 
50
- context 'when the value is a Vedeu::Colours::Colour' do
51
- let(:_value) { Vedeu::Colours::Colour.new }
51
+ context 'when the value is already the target class' do
52
+ let(:_value) { klass.new }
52
53
 
53
- it { subject.must_be_instance_of(Vedeu::Colours::Colour) }
54
+ it { subject.must_be_instance_of(klass) }
55
+ it { subject.must_equal(_value) }
54
56
  end
55
57
 
56
58
  context 'when the value is a Vedeu::Colours::Foreground' do
57
59
  let(:_value) { Vedeu::Colours::Foreground.new('#448822') }
58
60
 
59
- it { subject.must_be_instance_of(Vedeu::Colours::Colour) }
61
+ it { subject.must_be_instance_of(klass) }
60
62
  end
61
63
 
62
64
  context 'when the value is invalid or unsupported' do