vedeu 0.8.29 → 0.8.30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/docs/dsl/by_method/centre_x.md +6 -0
  3. data/docs/dsl/by_method/centre_y.md +6 -0
  4. data/examples/dsl_horizontal_alignment.rb +1 -1
  5. data/examples/dsl_vertical_alignment.rb +1 -1
  6. data/integrations/dsl_app_geometry_005.rb +177 -0
  7. data/integrations/expected/342_streams.out +1 -1
  8. data/integrations/expected/dsl_app_001.out +1 -1
  9. data/integrations/expected/dsl_app_002.out +1 -1
  10. data/integrations/expected/dsl_app_003.out +1 -1
  11. data/integrations/expected/dsl_app_004.out +1 -1
  12. data/integrations/expected/dsl_app_005.out +1 -1
  13. data/integrations/expected/dsl_app_006.out +1 -1
  14. data/integrations/expected/dsl_app_007.out +1 -1
  15. data/integrations/expected/dsl_app_008.out +1 -1
  16. data/integrations/expected/dsl_app_009.out +1 -1
  17. data/integrations/expected/dsl_app_010.out +1 -1
  18. data/integrations/expected/dsl_app_013.out +1 -1
  19. data/integrations/expected/dsl_app_014.out +1 -1
  20. data/integrations/expected/dsl_app_015.out +1 -1
  21. data/integrations/expected/dsl_app_016.out +1 -1
  22. data/integrations/expected/dsl_app_021.out +1 -1
  23. data/integrations/expected/dsl_app_022.out +1 -1
  24. data/integrations/expected/dsl_app_030.out +1 -1
  25. data/integrations/expected/dsl_app_031.out +1 -1
  26. data/integrations/expected/dsl_app_border_001.out +1 -1
  27. data/integrations/expected/dsl_app_border_002.out +1 -1
  28. data/integrations/expected/dsl_app_border_003.out +1 -1
  29. data/integrations/expected/dsl_app_border_004.out +1 -1
  30. data/integrations/expected/dsl_app_border_005.out +1 -1
  31. data/integrations/expected/dsl_app_border_006.out +1 -1
  32. data/integrations/expected/dsl_app_border_007.out +1 -1
  33. data/integrations/expected/dsl_app_border_008.out +1 -1
  34. data/integrations/expected/dsl_app_border_009.out +1 -1
  35. data/integrations/expected/dsl_app_border_010.out +1 -1
  36. data/integrations/expected/dsl_app_border_011.out +1 -1
  37. data/integrations/expected/dsl_app_border_012.out +1 -1
  38. data/integrations/expected/dsl_app_geometry_001.out +1 -1
  39. data/integrations/expected/dsl_app_geometry_002.out +1 -1
  40. data/integrations/expected/dsl_app_geometry_003.out +1 -1
  41. data/integrations/expected/dsl_app_geometry_004.out +1 -1
  42. data/integrations/expected/dsl_app_geometry_005.out +1 -0
  43. data/integrations/test_runner.sh +1 -0
  44. data/lib/vedeu/geometries/dsl/dsl.rb +34 -6
  45. data/lib/vedeu/interfaces/clear.rb +12 -45
  46. data/lib/vedeu/interfaces/clear_content.rb +20 -40
  47. data/lib/vedeu/output/output.rb +10 -3
  48. data/lib/vedeu/terminal/terminal.rb +6 -0
  49. data/lib/vedeu/version.rb +1 -1
  50. data/test/lib/vedeu/interfaces/clear_content_test.rb +19 -8
  51. data/test/lib/vedeu/interfaces/clear_test.rb +26 -17
  52. data/test/lib/vedeu/output/output_test.rb +8 -0
  53. data/test/lib/vedeu_test.rb +2 -0
  54. metadata +6 -2
@@ -11,6 +11,14 @@ module Vedeu
11
11
  class Clear
12
12
 
13
13
  include Vedeu::Common
14
+ extend Forwardable
15
+
16
+ def_delegators :geometry,
17
+ :height,
18
+ :width
19
+
20
+ def_delegators :interface,
21
+ :colour
14
22
 
15
23
  class << self
16
24
 
@@ -48,29 +56,14 @@ module Vedeu
48
56
 
49
57
  private
50
58
 
51
- # @return [String] A string of blank characters.
52
- def chars
53
- @_chars ||= (' ' * width)
54
- end
55
-
56
- # @return [Vedeu::Colours::Colour]
57
- def colour
58
- @_colour ||= interface.colour
59
- end
60
-
61
59
  # @macro geometry_by_name
62
60
  def geometry
63
61
  @_geometry ||= Vedeu.geometries.by_name(name)
64
62
  end
65
63
 
66
- # @return [Fixnum]
67
- def height
68
- @_height ||= geometry.height
69
- end
70
-
71
64
  # @macro interface_by_name
72
65
  def interface
73
- Vedeu.interfaces.by_name(name)
66
+ @_interface ||= Vedeu.interfaces.by_name(name)
74
67
  end
75
68
 
76
69
  # For each visible line of the interface, set the foreground and
@@ -81,40 +74,14 @@ module Vedeu
81
74
  # @return [Array<Array<Vedeu::Cells::Char>>]
82
75
  def output
83
76
  Vedeu.timer("Clearing interface: '#{name}'") do
84
- @_clear ||= Array.new(height) do |iy|
85
- Array.new(width) do |ix|
86
- Vedeu::Cells::Clear.new(output_attributes(iy, ix))
77
+ @_clear ||= Array.new(height) do
78
+ Array.new(width) do
79
+ Vedeu::Cells::Clear.new(colour: colour, name: name)
87
80
  end
88
81
  end
89
82
  end
90
83
  end
91
84
 
92
- # @param iy [Fixnum]
93
- # @param ix [Fixnum]
94
- # @return [Hash<Symbol => ]
95
- def output_attributes(iy, ix)
96
- {
97
- colour: colour,
98
- name: name,
99
- position: Vedeu::Geometries::Position.new((y + iy), (x + ix)),
100
- }
101
- end
102
-
103
- # @return [Fixnum]
104
- def width
105
- @_width ||= geometry.width
106
- end
107
-
108
- # @return [Fixnum]
109
- def y
110
- @_y ||= geometry.y
111
- end
112
-
113
- # @return [Fixnum]
114
- def x
115
- @_x ||= geometry.x
116
- end
117
-
118
85
  end # Clear
119
86
 
120
87
  end # Interfaces
@@ -11,6 +11,16 @@ module Vedeu
11
11
  class ClearContent
12
12
 
13
13
  include Vedeu::Common
14
+ extend Forwardable
15
+
16
+ def_delegators :geometry,
17
+ :bordered_height,
18
+ :bordered_width,
19
+ :bx,
20
+ :by
21
+
22
+ def_delegators :interface,
23
+ :colour
14
24
 
15
25
  class << self
16
26
 
@@ -50,12 +60,7 @@ module Vedeu
50
60
 
51
61
  # @return [String] A string of blank characters.
52
62
  def chars
53
- @_chars ||= (' ' * width)
54
- end
55
-
56
- # @return [Vedeu::Colours::Colour]
57
- def colour
58
- @_colour ||= interface.colour
63
+ @_chars ||= (' ' * bordered_width)
59
64
  end
60
65
 
61
66
  # @macro geometry_by_name
@@ -63,26 +68,19 @@ module Vedeu
63
68
  @_geometry ||= Vedeu.geometries.by_name(name)
64
69
  end
65
70
 
66
- # @return [Fixnum]
67
- def height
68
- @_height ||= geometry.bordered_height
69
- end
70
-
71
71
  # @macro interface_by_name
72
72
  def interface
73
- Vedeu.interfaces.by_name(name)
73
+ @_interface ||= Vedeu.interfaces.by_name(name)
74
74
  end
75
75
 
76
76
  # @return [String]
77
77
  def optimised_output
78
78
  Vedeu.timer("Optimised clearing content: '#{name}'") do
79
- Array.new(height) do |iy|
80
- [
81
- Vedeu::Geometries::Position.new(y + iy, x).to_s,
82
- colour.to_s,
83
- chars,
84
- ].join
85
- end.join + Vedeu::Geometries::Position.new(y, x).to_s
79
+ Array.new(bordered_height) do |iy|
80
+ Vedeu::Geometries::Position.new(by + iy, bx).to_s +
81
+ colour.to_s +
82
+ chars
83
+ end.join + Vedeu::Geometries::Position.new(by, bx)
86
84
  end
87
85
  end
88
86
 
@@ -94,32 +92,14 @@ module Vedeu
94
92
  # @return [Array<Array<Vedeu::Cells::Char>>]
95
93
  def output
96
94
  Vedeu.timer("Clearing content: '#{name}'") do
97
- @_clear ||= Array.new(height) do |iy|
98
- Array.new(width) do |ix|
99
- position = Vedeu::Geometries::Position.new((y + iy), (x + ix))
100
- Vedeu::Cells::Clear.new(colour: colour,
101
- name: name,
102
- position: position)
95
+ @_clear ||= Array.new(bordered_height) do
96
+ Array.new(bordered_width) do
97
+ Vedeu::Cells::Clear.new(colour: colour, name: name)
103
98
  end
104
99
  end
105
100
  end
106
101
  end
107
102
 
108
- # @return [Fixnum]
109
- def width
110
- @_width ||= geometry.bordered_width
111
- end
112
-
113
- # @return [Fixnum]
114
- def y
115
- @_y ||= geometry.by
116
- end
117
-
118
- # @return [Fixnum]
119
- def x
120
- @_x ||= geometry.bx
121
- end
122
-
123
103
  end # ClearContent
124
104
 
125
105
  end # Interfaces
@@ -52,17 +52,17 @@ module Vedeu
52
52
 
53
53
  # @return (see #render_output)
54
54
  def buffer_update
55
- Vedeu::Buffers::Terminal.update(output) if present?(output)
55
+ Vedeu::Buffers::Terminal.update(output) if output?
56
56
  end
57
57
 
58
58
  # @return (see #render_output)
59
59
  def buffer_write
60
- Vedeu::Buffers::Terminal.write(output) if present?(output)
60
+ Vedeu::Buffers::Terminal.write(output) if output?
61
61
  end
62
62
 
63
63
  # @return (see #render_output)
64
64
  def direct_write
65
- Vedeu::Terminal.output(output.to_s) if present?(output)
65
+ Vedeu::Terminal.output(output.to_s) if output?
66
66
  end
67
67
 
68
68
  # Send the view to the renderers. If the output is a
@@ -92,6 +92,13 @@ module Vedeu
92
92
  # NilClass|Vedeu::Cells::Escape|Vedeu::Cells::Cursor]
93
93
  attr_reader :output
94
94
 
95
+ private
96
+
97
+ # @return [Boolean]
98
+ def output?
99
+ present?(output)
100
+ end
101
+
95
102
  end # Output
96
103
 
97
104
  end # Output
@@ -166,7 +166,13 @@ module Vedeu
166
166
  # @api public
167
167
  # @!method resize
168
168
  # @see Vedeu::Terminal#resize
169
+ # @!method centre_x
170
+ # @see Vedeu::Terminal#centre_x
171
+ # @!method centre_y
172
+ # @see Vedeu::Terminal#centre_y
169
173
  def_delegators Vedeu::Terminal,
174
+ :centre_x,
175
+ :centre_y,
170
176
  :resize
171
177
 
172
178
  end # Vedeu
@@ -3,6 +3,6 @@
3
3
  module Vedeu
4
4
 
5
5
  # The current version of Vedeu.
6
- VERSION = '0.8.29'
6
+ VERSION = '0.8.30'
7
7
 
8
8
  end # Vedeu
@@ -60,20 +60,31 @@ module Vedeu
60
60
  Vedeu.geometries.stubs(:by_name).returns(geometry)
61
61
  Vedeu.stubs(:direct_write)
62
62
  Vedeu.stubs(:buffer_update)
63
+ Vedeu.stubs(:ready?).returns(ready)
63
64
  end
64
65
 
65
66
  subject { instance.render }
66
67
 
67
- # it { subject.must_be_instance_of(Vedeu::Buffers::View) }
68
- it do
69
- Vedeu.expects(:direct_write)
70
- subject
68
+ context 'when Vedeu is ready' do
69
+ let(:ready) { true }
70
+
71
+ # it { subject.must_be_instance_of(Vedeu::Buffers::View) }
72
+ it do
73
+ Vedeu.expects(:direct_write)
74
+ subject
75
+ end
76
+ it do
77
+ Vedeu.expects(:buffer_update)
78
+ subject
79
+ end
80
+ # it { subject.must_equal(output) }
71
81
  end
72
- it do
73
- Vedeu.expects(:buffer_update)
74
- subject
82
+
83
+ context 'when Vedeu is not ready' do
84
+ let(:ready) { false }
85
+
86
+ it { subject.must_be_instance_of(NilClass) }
75
87
  end
76
- # it { subject.must_equal(output) }
77
88
  end
78
89
 
79
90
  end # ClearContent
@@ -40,19 +40,15 @@ module Vedeu
40
40
  let(:output) {
41
41
  [
42
42
  [
43
- Vedeu::Cells::Clear.new(colour: colour,
44
- name: _name,
45
- position: [1, 1]),
46
- Vedeu::Cells::Clear.new(colour: colour,
47
- name: _name,
48
- position: [1, 2]),
43
+ Vedeu::Cells::Clear.new(colour: colour,
44
+ name: _name),
45
+ Vedeu::Cells::Clear.new(colour: colour,
46
+ name: _name),
49
47
  ], [
50
- Vedeu::Cells::Clear.new(colour: colour,
51
- name: _name,
52
- position: [2, 1]),
53
- Vedeu::Cells::Clear.new(colour: colour,
54
- name: _name,
55
- position: [2, 2]),
48
+ Vedeu::Cells::Clear.new(colour: colour,
49
+ name: _name),
50
+ Vedeu::Cells::Clear.new(colour: colour,
51
+ name: _name),
56
52
  ]
57
53
  ]
58
54
  }
@@ -61,16 +57,29 @@ module Vedeu
61
57
  Vedeu.interfaces.stubs(:by_name).returns(interface)
62
58
  Vedeu.geometries.stubs(:by_name).returns(geometry)
63
59
  Vedeu.stubs(:render_output).returns(output)
60
+ Vedeu.stubs(:ready?).returns(ready)
64
61
  end
65
62
 
66
63
  subject { instance.render }
67
64
 
68
- it { subject.must_be_instance_of(Array) }
69
- it do
70
- Vedeu.expects(:render_output).with(output)
71
- subject
65
+ context 'when Vedeu is ready' do
66
+ let(:ready) { true }
67
+
68
+ it { subject.must_be_instance_of(Array) }
69
+
70
+ it do
71
+ Vedeu.expects(:render_output).with(output)
72
+ subject
73
+ end
74
+
75
+ it { subject.must_equal(output) }
76
+ end
77
+
78
+ context 'when Vedeu is not ready' do
79
+ let(:ready) { false }
80
+
81
+ it { subject.must_be_instance_of(NilClass) }
72
82
  end
73
- it { subject.must_equal(output) }
74
83
  end
75
84
 
76
85
  end # Clear
@@ -18,6 +18,10 @@ module Vedeu
18
18
  it { instance.instance_variable_get('@output').must_equal(output) }
19
19
  end
20
20
 
21
+ describe '.buffer_update' do
22
+ it { described.must_respond_to(:buffer_update) }
23
+ end
24
+
21
25
  describe '.buffer_write' do
22
26
  subject { described.buffer_write(output) }
23
27
 
@@ -84,6 +88,10 @@ module Vedeu
84
88
  end
85
89
  end
86
90
 
91
+ describe '#buffer_update' do
92
+ it { instance.must_respond_to(:buffer_update) }
93
+ end
94
+
87
95
  describe '#buffer_write' do
88
96
  it { instance.must_respond_to(:buffer_write) }
89
97
  end
@@ -17,6 +17,8 @@ describe Vedeu do
17
17
  it { Vedeu.must_respond_to(:buffers) }
18
18
  it { Vedeu.must_respond_to(:buffer_update) }
19
19
  it { Vedeu.must_respond_to(:buffer_write) }
20
+ it { Vedeu.must_respond_to(:centre_x) }
21
+ it { Vedeu.must_respond_to(:centre_y) }
20
22
  it { Vedeu.must_respond_to(:clear) }
21
23
  it { Vedeu.must_respond_to(:clear_by_group) }
22
24
  it { Vedeu.must_respond_to(:clear_by_name) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.29
4
+ version: 0.8.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-20 00:00:00.000000000 Z
11
+ date: 2016-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -301,6 +301,8 @@ files:
301
301
  - docs/dsl/by_method/buffer_write.md
302
302
  - docs/dsl/by_method/buffers.md
303
303
  - docs/dsl/by_method/caption.md
304
+ - docs/dsl/by_method/centre_x.md
305
+ - docs/dsl/by_method/centre_y.md
304
306
  - docs/dsl/by_method/clear.md
305
307
  - docs/dsl/by_method/clear_by_group.md
306
308
  - docs/dsl/by_method/clear_by_name.md
@@ -582,6 +584,7 @@ files:
582
584
  - integrations/dsl_app_geometry_002.rb
583
585
  - integrations/dsl_app_geometry_003.rb
584
586
  - integrations/dsl_app_geometry_004.rb
587
+ - integrations/dsl_app_geometry_005.rb
585
588
  - integrations/expected/342_streams.out
586
589
  - integrations/expected/dsl_app_001.out
587
590
  - integrations/expected/dsl_app_002.out
@@ -620,6 +623,7 @@ files:
620
623
  - integrations/expected/dsl_app_geometry_002.out
621
624
  - integrations/expected/dsl_app_geometry_003.out
622
625
  - integrations/expected/dsl_app_geometry_004.out
626
+ - integrations/expected/dsl_app_geometry_005.out
623
627
  - integrations/support/test_interface.rb
624
628
  - integrations/support/test_interface_021.rb
625
629
  - integrations/support/test_interface_022.rb