vedeu 0.8.24 → 0.8.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/integrations/dsl_app_030.rb +55 -0
  3. data/integrations/dsl_app_031.rb +55 -0
  4. data/integrations/dsl_app_border_012.rb +51 -0
  5. data/integrations/expected/dsl_app_030.out +1 -0
  6. data/integrations/expected/dsl_app_031.out +1 -0
  7. data/integrations/expected/dsl_app_border_012.out +1 -0
  8. data/integrations/test_runner.sh +3 -0
  9. data/lib/vedeu/boolean.rb +10 -0
  10. data/lib/vedeu/borders/dsl.rb +4 -12
  11. data/lib/vedeu/dsl/cursors.rb +3 -4
  12. data/lib/vedeu/dsl/elements.rb +4 -6
  13. data/lib/vedeu/dsl/presentation.rb +1 -3
  14. data/lib/vedeu/interfaces/all.rb +1 -0
  15. data/lib/vedeu/interfaces/clear.rb +19 -120
  16. data/lib/vedeu/interfaces/clear_content.rb +131 -0
  17. data/lib/vedeu/interfaces/dsl.rb +3 -7
  18. data/lib/vedeu/presentation/all.rb +3 -0
  19. data/lib/vedeu/presentation/colour.rb +2 -5
  20. data/lib/vedeu/presentation/parent.rb +21 -0
  21. data/lib/vedeu/presentation/styles.rb +3 -5
  22. data/lib/vedeu/version.rb +1 -1
  23. data/lib/vedeu/views/line.rb +1 -5
  24. data/lib/vedeu/views/stream.rb +1 -5
  25. data/lib/vedeu/views/view.rb +1 -5
  26. data/test/lib/vedeu/boolean_test.rb +18 -0
  27. data/test/lib/vedeu/interfaces/clear_content_test.rb +83 -0
  28. data/test/lib/vedeu/interfaces/clear_test.rb +1 -8
  29. data/test/lib/vedeu/presentation/colour_test.rb +1 -1
  30. data/test/lib/vedeu/presentation/parent_test.rb +39 -0
  31. data/test/lib/vedeu/presentation/styles_test.rb +7 -7
  32. data/test/lib/vedeu/views/line_test.rb +3 -7
  33. data/test/lib/vedeu/views/stream_test.rb +0 -4
  34. data/test/lib/vedeu/views/view_test.rb +0 -4
  35. data/vedeu.gemspec +1 -1
  36. metadata +16 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bba38d1b7b8c6befc6f778050e727f1afa5ec5aa
4
- data.tar.gz: 2f92824ce2e8faafd9cad5ccd7b69dcb528d2b42
3
+ metadata.gz: 977f6bdee8b7a54320de8ac868a677cdea943115
4
+ data.tar.gz: 1bb42f91d121a6331b8fd2ee779bd9d2f47a13da
5
5
  SHA512:
6
- metadata.gz: 8f685282146b350cbdff354b6990054d022812c9cf9dba3b068efc8ed28313d318a3ea23418fb2ed943f593658017f7a6588e3e46fb564b06d2b57f10235defe
7
- data.tar.gz: 0253772378f8d3de47153617970963329548b5ed5021326454d4ba21e078fb51a5df3e3f0380a0760b3c12af780cbfd7ff24af04a7afcb1729b68e6d21cad4af
6
+ metadata.gz: f8e18b503177a2d2478a057639c480186cd82e6c3bb766d7c918e41c0129a2e0f4f143937650e3b06c567a2fcaaa8179db07215e05f0645909bb563d13ed7624
7
+ data.tar.gz: 661116fd7b9a6c3209698c4ffd11248d374d63741560a793ece435c0bdda8d505cb2be806f68adacf5c36e17e0e7077d06d4831993da3e6a51c0840f50bc3d7f
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'vedeu'
7
+
8
+ TESTCASE = 'dsl_app_030'
9
+
10
+ class DSLApp
11
+
12
+ Vedeu.bind(:_initialize_) do
13
+ Vedeu.trigger(:_refresh_)
14
+ sleep 0.25
15
+ Vedeu.trigger(:_clear_view_)
16
+ end
17
+
18
+ Vedeu.configure do
19
+ debug!
20
+ height 10
21
+ log Dir.tmpdir + '/vedeu_views_dsl.log'
22
+ renderers [
23
+ Vedeu::Renderers::Terminal.new(
24
+ filename: Dir.tmpdir + "/#{TESTCASE}.out",
25
+ write_file: true),
26
+ # Vedeu::Renderers::JSON.new(filename: Dir.tmpdir + "/#{TESTCASE}.json"),
27
+ # Vedeu::Renderers::HTML.new(filename: Dir.tmpdir + "/#{TESTCASE}.html"),
28
+ # Vedeu::Renderers::Text.new(filename: Dir.tmpdir + "/#{TESTCASE}.txt"),
29
+ ]
30
+ run_once!
31
+ standalone!
32
+ end
33
+
34
+ load File.dirname(__FILE__) + '/support/test_interface.rb'
35
+
36
+ Vedeu.render do
37
+ view(:test_interface) do
38
+ lines do
39
+ line 'some content'
40
+ end
41
+ end
42
+ end
43
+
44
+ def self.start(argv = ARGV)
45
+ Vedeu::Launcher.execute!(argv)
46
+ end
47
+
48
+ end # DSLApp
49
+
50
+ Vedeu.timer('Test') do
51
+ DSLApp.start
52
+ end
53
+
54
+ load File.dirname(__FILE__) + '/test_runner.rb'
55
+ TestRunner.result(TESTCASE, __FILE__)
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'vedeu'
7
+
8
+ TESTCASE = 'dsl_app_031'
9
+
10
+ class DSLApp
11
+
12
+ Vedeu.bind(:_initialize_) do
13
+ Vedeu.trigger(:_refresh_)
14
+ sleep 0.25
15
+ Vedeu.trigger(:_clear_view_content_)
16
+ end
17
+
18
+ Vedeu.configure do
19
+ debug!
20
+ height 10
21
+ log Dir.tmpdir + '/vedeu_views_dsl.log'
22
+ renderers [
23
+ Vedeu::Renderers::Terminal.new(
24
+ filename: Dir.tmpdir + "/#{TESTCASE}.out",
25
+ write_file: true),
26
+ # Vedeu::Renderers::JSON.new(filename: Dir.tmpdir + "/#{TESTCASE}.json"),
27
+ # Vedeu::Renderers::HTML.new(filename: Dir.tmpdir + "/#{TESTCASE}.html"),
28
+ # Vedeu::Renderers::Text.new(filename: Dir.tmpdir + "/#{TESTCASE}.txt"),
29
+ ]
30
+ run_once!
31
+ standalone!
32
+ end
33
+
34
+ load File.dirname(__FILE__) + '/support/test_interface.rb'
35
+
36
+ Vedeu.render do
37
+ view(:test_interface) do
38
+ lines do
39
+ line 'some content'
40
+ end
41
+ end
42
+ end
43
+
44
+ def self.start(argv = ARGV)
45
+ Vedeu::Launcher.execute!(argv)
46
+ end
47
+
48
+ end # DSLApp
49
+
50
+ Vedeu.timer('Test') do
51
+ DSLApp.start
52
+ end
53
+
54
+ load File.dirname(__FILE__) + '/test_runner.rb'
55
+ TestRunner.result(TESTCASE, __FILE__)
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'vedeu'
7
+
8
+ TESTCASE = 'dsl_app_border_012'
9
+
10
+ class DSLApp
11
+
12
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
13
+
14
+ Vedeu.configure do
15
+ debug!
16
+ height 10
17
+ log Dir.tmpdir + '/vedeu_views_dsl.log'
18
+ renderers [
19
+ Vedeu::Renderers::Terminal.new(
20
+ filename: Dir.tmpdir + "/#{TESTCASE}.out",
21
+ write_file: true),
22
+ # Vedeu::Renderers::JSON.new(filename: Dir.tmpdir + "/#{TESTCASE}.json"),
23
+ # Vedeu::Renderers::HTML.new(filename: Dir.tmpdir + "/#{TESTCASE}.html"),
24
+ # Vedeu::Renderers::Text.new(filename: Dir.tmpdir + "/#{TESTCASE}.txt"),
25
+ ]
26
+ run_once!
27
+ standalone!
28
+ end
29
+
30
+ load File.dirname(__FILE__) + '/support/test_interface.rb'
31
+
32
+ Vedeu.render do
33
+ view(:test_interface) do
34
+ lines do
35
+ line 'border on'
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.start(argv = ARGV)
41
+ Vedeu::Launcher.execute!(argv)
42
+ end
43
+
44
+ end # DSLApp
45
+
46
+ Vedeu.timer('Test') do
47
+ DSLApp.start
48
+ end
49
+
50
+ load File.dirname(__FILE__) + '/test_runner.rb'
51
+ TestRunner.result(TESTCASE, __FILE__)
@@ -0,0 +1 @@
1
+                                                                                                                                                            
@@ -0,0 +1 @@
1
+ (0l(B(0q(B Test (0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0k(B(0x(B                             (0x(B(0x(B                             (0x(B(0x(B                             (0x(B(0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B
@@ -0,0 +1 @@
1
+ (0l(B(0q(B Test (0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0k(B(0x(Bborder on                    (0x(B(0x(B                             (0x(B(0x(B                             (0x(B(0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B
@@ -31,6 +31,8 @@ cd "$(dirname "$0")"
31
31
  ./dsl_app_016.rb
32
32
  ./dsl_app_021.rb
33
33
  ./dsl_app_022.rb
34
+ ./dsl_app_030.rb
35
+ ./dsl_app_031.rb
34
36
 
35
37
  # Test some border functionality
36
38
  ./dsl_app_border_001.rb # border off
@@ -44,6 +46,7 @@ cd "$(dirname "$0")"
44
46
  ./dsl_app_border_009.rb # only right
45
47
  ./dsl_app_border_010.rb # only bottom
46
48
  ./dsl_app_border_011.rb # only left
49
+ ./dsl_app_border_012.rb # border on
47
50
 
48
51
  # Failing
49
52
  # ./dsl_app_017.rb
@@ -8,12 +8,22 @@ module Vedeu
8
8
  #
9
9
  class Boolean
10
10
 
11
+ # @return [Boolean]
12
+ def self.coerce(value = nil)
13
+ new(value).coerce
14
+ end
15
+
11
16
  # @param value [void]
12
17
  # @return [Vedeu::Boolean]
13
18
  def initialize(value = nil)
14
19
  @value = value
15
20
  end
16
21
 
22
+ # @return [Boolean]
23
+ def coerce
24
+ value ? true : false
25
+ end
26
+
17
27
  # @return [Boolean]
18
28
  def false?
19
29
  value.nil? || value == false
@@ -128,9 +128,7 @@ module Vedeu
128
128
  # and false.
129
129
  # @return [Boolean]
130
130
  def bottom(value)
131
- boolean = value ? true : false
132
-
133
- model.show_bottom = boolean
131
+ model.show_bottom = Vedeu::Boolean.coerce(value)
134
132
  end
135
133
  alias show_bottom bottom
136
134
  alias bottom= bottom
@@ -154,9 +152,7 @@ module Vedeu
154
152
  # and false.
155
153
  # @return [Boolean]
156
154
  def left(value)
157
- boolean = value ? true : false
158
-
159
- model.show_left = boolean
155
+ model.show_left = Vedeu::Boolean.coerce(value)
160
156
  end
161
157
  alias show_left left
162
158
  alias left= left
@@ -180,9 +176,7 @@ module Vedeu
180
176
  # and false.
181
177
  # @return [Boolean]
182
178
  def right(value)
183
- boolean = value ? true : false
184
-
185
- model.show_right = boolean
179
+ model.show_right = Vedeu::Boolean.coerce(value)
186
180
  end
187
181
  alias show_right right
188
182
  alias right= right
@@ -224,9 +218,7 @@ module Vedeu
224
218
  # and false.
225
219
  # @return [Boolean]
226
220
  def top(value)
227
- boolean = value ? true : false
228
-
229
- model.show_top = boolean
221
+ model.show_top = Vedeu::Boolean.coerce(value)
230
222
  end
231
223
  alias show_top top
232
224
  alias top= top
@@ -16,11 +16,10 @@ module Vedeu
16
16
  # evaluate to true.
17
17
  # @return [Vedeu::Cursors::Cursor]
18
18
  def cursor(value = true)
19
- boolean = value ? true : false
19
+ model.cursor_visible = Vedeu::Boolean.coerce(value)
20
20
 
21
- model.cursor_visible = boolean
22
-
23
- Vedeu::Cursors::Cursor.store(name: name, visible: boolean)
21
+ Vedeu::Cursors::Cursor.store(name: name,
22
+ visible: Vedeu::Boolean.coerce(value))
24
23
  end
25
24
 
26
25
  # Set the cursor to visible for the interface or view.
@@ -68,25 +68,23 @@ module Vedeu
68
68
  requires_model!
69
69
 
70
70
  attrs = Vedeu::DSL::Attributes.build(self, model, nil, opts, &block)
71
+ l = Vedeu::Views::Line.build(attrs, &block)
72
+ v = Vedeu::Views::View.build(attrs, &block)
71
73
 
72
74
  if view_model?
73
75
  if model.lines?
74
- l = Vedeu::Views::Line.build(attrs, &block)
75
76
  model.add(l)
76
77
 
77
78
  else
78
- l = Vedeu::Views::View.build(attrs, &block)
79
- model.value = l.value
79
+ model.value = v.value
80
80
 
81
81
  end
82
82
 
83
83
  elsif line_model?
84
- l = Vedeu::Views::Line.build(attrs, &block)
85
84
  model.value = l.value
86
85
 
87
86
  else
88
- l = Vedeu::Views::View.build(attrs, &block)
89
- model.value = l.value
87
+ model.value = v.value
90
88
 
91
89
  end
92
90
  end
@@ -134,9 +134,7 @@ module Vedeu
134
134
  # @param value [Boolean]
135
135
  # @return [Boolean]
136
136
  def wordwrap(value = true)
137
- boolean = value ? true : false
138
-
139
- model.wordwrap = boolean
137
+ model.wordwrap = Vedeu::Boolean.coerce(value)
140
138
  end
141
139
  alias wordwrap! wordwrap
142
140
 
@@ -35,6 +35,7 @@ end # Vedeu
35
35
 
36
36
  require 'vedeu/interfaces/interface'
37
37
  require 'vedeu/interfaces/clear'
38
+ require 'vedeu/interfaces/clear_content'
38
39
  require 'vedeu/interfaces/dsl'
39
40
  require 'vedeu/interfaces/null'
40
41
  require 'vedeu/interfaces/repository'
@@ -25,45 +25,19 @@ module Vedeu
25
25
  alias clear_by_name render
26
26
  alias by_name render
27
27
 
28
- # {include:file:docs/dsl/by_method/clear_content_by_name.md}
29
- # @return [Array<Array<Vedeu::Cells::Char>>]
30
- # @see #initialize
31
- def clear_content_by_name(name = Vedeu.focus)
32
- name || Vedeu.focus
33
-
34
- new(name, content_only: true, direct: true).render
35
- end
36
-
37
28
  end # Eigenclass
38
29
 
39
30
  # Return a new instance of Vedeu::Interfaces::Clear.
40
31
  #
41
32
  # @macro param_name
42
- # @param options [Hash]
43
- # @option options content_only [Boolean] Only clear the content
44
- # not the border as well. Defaults to false.
45
- # @option options direct [Boolean] Write the content directly
46
- # to the terminal using a faster mechanism. The virtual buffer
47
- # will still be updated. This improves the refresh time for
48
- # Vedeu as we will not be building a grid of
49
- # {Vedeu::Cells::Char} objects.
50
33
  # @return [Vedeu::Interfaces::Clear]
51
- def initialize(name, options = {})
52
- @name = present?(name) ? name : Vedeu.focus
53
- @options = options
34
+ def initialize(name = Vedeu.focus)
35
+ @name = present?(name) ? name : Vedeu.focus
54
36
  end
55
37
 
56
38
  # @return [Array<Array<Vedeu::Cells::Char>>]
57
39
  def render
58
- if direct?
59
- Vedeu.direct_write(optimised_output)
60
-
61
- Vedeu.buffer_update(output)
62
-
63
- else
64
- Vedeu.render_output(output)
65
-
66
- end
40
+ Vedeu.render_output(output)
67
41
  end
68
42
 
69
43
  protected
@@ -84,24 +58,6 @@ module Vedeu
84
58
  @_colour ||= interface.colour
85
59
  end
86
60
 
87
- # @return [Boolean]
88
- def content_only?
89
- options[:content_only]
90
- end
91
-
92
- # @macro defaults_method
93
- def defaults
94
- {
95
- content_only: false,
96
- direct: false,
97
- }
98
- end
99
-
100
- # @return [Boolean]
101
- def direct?
102
- options[:direct]
103
- end
104
-
105
61
  # @macro geometry_by_name
106
62
  def geometry
107
63
  @_geometry ||= Vedeu.geometries.by_name(name)
@@ -109,13 +65,7 @@ module Vedeu
109
65
 
110
66
  # @return [Fixnum]
111
67
  def height
112
- @_height ||= if content_only?
113
- geometry.bordered_height
114
-
115
- else
116
- geometry.height
117
-
118
- end
68
+ @_height ||= geometry.height
119
69
  end
120
70
 
121
71
  # @macro interface_by_name
@@ -123,24 +73,6 @@ module Vedeu
123
73
  Vedeu.interfaces.by_name(name)
124
74
  end
125
75
 
126
- # @return [Hash<Symbol => Boolean>]
127
- def options
128
- defaults.merge!(@options)
129
- end
130
-
131
- # @return [String]
132
- def optimised_output
133
- Vedeu.timer("Optimised clearing #{clearing}: '#{name}'") do
134
- Array.new(height) do |iy|
135
- [
136
- build_position(y + iy, x),
137
- colour.to_s,
138
- chars,
139
- ].join
140
- end.join + build_position(y, x)
141
- end
142
- end
143
-
144
76
  # For each visible line of the interface, set the foreground and
145
77
  # background colours to those specified when the interface was
146
78
  # defined, then starting write space characters over the area
@@ -148,68 +80,39 @@ module Vedeu
148
80
  #
149
81
  # @return [Array<Array<Vedeu::Cells::Char>>]
150
82
  def output
151
- Vedeu.timer("Clearing #{clearing}: '#{name}'") do
83
+ Vedeu.timer("Clearing interface: '#{name}'") do
152
84
  @_clear ||= Array.new(height) do |iy|
153
85
  Array.new(width) do |ix|
154
- position = Vedeu::Geometries::Position.new((y + iy), (x + ix))
155
- Vedeu::Cells::Clear.new(colour: colour,
156
- name: name,
157
- position: position)
86
+ Vedeu::Cells::Clear.new(output_attributes(iy, ix))
158
87
  end
159
88
  end
160
89
  end
161
90
  end
162
91
 
163
- # @return [String]
164
- def clearing
165
- @_clearing ||= if content_only?
166
- 'content'
167
-
168
- else
169
- 'interface'
170
-
171
- end
172
- end
173
-
174
- # @param pos_y [Fixnum]
175
- # @param pos_x [Fixnum]
176
- # @return [Vedeu::Geometries::Position]
177
- # @todo Not sure if #to_s is required here. (GL: 2015-11-30)
178
- def build_position(pos_y, pos_x)
179
- Vedeu::Geometries::Position.new(pos_y, pos_x).to_s
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
+ }
180
101
  end
181
102
 
182
103
  # @return [Fixnum]
183
104
  def width
184
- @_width ||= if content_only?
185
- geometry.bordered_width
186
-
187
- else
188
- geometry.width
189
-
190
- end
105
+ @_width ||= geometry.width
191
106
  end
192
107
 
193
108
  # @return [Fixnum]
194
109
  def y
195
- @_y ||= if content_only?
196
- geometry.by
197
-
198
- else
199
- geometry.y
200
-
201
- end
110
+ @_y ||= geometry.y
202
111
  end
203
112
 
204
113
  # @return [Fixnum]
205
114
  def x
206
- @_x ||= if content_only?
207
- geometry.bx
208
-
209
- else
210
- geometry.x
211
-
212
- end
115
+ @_x ||= geometry.x
213
116
  end
214
117
 
215
118
  end # Clear
@@ -219,11 +122,7 @@ module Vedeu
219
122
  # @api public
220
123
  # @!method clear_by_name
221
124
  # @see Vedeu::Interfaces::Clear.clear_by_name
222
- # @api public
223
- # @!method clear_content_by_name
224
- # @see Vedeu::Interfaces.Clear.clear_content_by_name
225
125
  def_delegators Vedeu::Interfaces::Clear,
226
- :clear_by_name,
227
- :clear_content_by_name
126
+ :clear_by_name
228
127
 
229
128
  end # Vedeu
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vedeu
4
+
5
+ module Interfaces
6
+
7
+ # Clear the content of the named interface.
8
+ #
9
+ # @api private
10
+ #
11
+ class ClearContent
12
+
13
+ include Vedeu::Common
14
+
15
+ class << self
16
+
17
+ # {include:file:docs/dsl/by_method/clear_content_by_name.md}
18
+ # @return [Vedeu::Buffers::View]
19
+ # @see #initialize
20
+ def clear_content_by_name(name = Vedeu.focus)
21
+ new(name).render
22
+ end
23
+
24
+ end # Eigenclass
25
+
26
+ # Return a new instance of Vedeu::Interfaces::ClearContent.
27
+ #
28
+ # @macro param_name
29
+ # @return [Vedeu::Interfaces::ClearContent]
30
+ def initialize(name = Vedeu.focus)
31
+ @name = present?(name) ? name : Vedeu.focus
32
+ end
33
+
34
+ # @return [Vedeu::Buffers::View]
35
+ def render
36
+ Vedeu.direct_write(optimised_output)
37
+
38
+ Vedeu.buffer_update(output)
39
+ end
40
+
41
+ protected
42
+
43
+ # @!attribute [r] name
44
+ # @macro return_name
45
+ attr_reader :name
46
+
47
+ private
48
+
49
+ # @return [String] A string of blank characters.
50
+ def chars
51
+ @_chars ||= (' ' * width)
52
+ end
53
+
54
+ # @return [Vedeu::Colours::Colour]
55
+ def colour
56
+ @_colour ||= interface.colour
57
+ end
58
+
59
+ # @macro geometry_by_name
60
+ def geometry
61
+ @_geometry ||= Vedeu.geometries.by_name(name)
62
+ end
63
+
64
+ # @return [Fixnum]
65
+ def height
66
+ @_height ||= geometry.bordered_height
67
+ end
68
+
69
+ # @macro interface_by_name
70
+ def interface
71
+ Vedeu.interfaces.by_name(name)
72
+ end
73
+
74
+ # @return [String]
75
+ def optimised_output
76
+ Vedeu.timer("Optimised clearing content: '#{name}'") do
77
+ Array.new(height) do |iy|
78
+ [
79
+ Vedeu::Geometries::Position.new(y + iy, x).to_s,
80
+ colour.to_s,
81
+ chars,
82
+ ].join
83
+ end.join + Vedeu::Geometries::Position.new(y, x).to_s
84
+ end
85
+ end
86
+
87
+ # For each visible line of the interface, set the foreground and
88
+ # background colours to those specified when the interface was
89
+ # defined, then starting write space characters over the area
90
+ # which the interface occupies.
91
+ #
92
+ # @return [Array<Array<Vedeu::Cells::Char>>]
93
+ def output
94
+ Vedeu.timer("Clearing content: '#{name}'") do
95
+ @_clear ||= Array.new(height) do |iy|
96
+ Array.new(width) do |ix|
97
+ position = Vedeu::Geometries::Position.new((y + iy), (x + ix))
98
+ Vedeu::Cells::Clear.new(colour: colour,
99
+ name: name,
100
+ position: position)
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ # @return [Fixnum]
107
+ def width
108
+ @_width ||= geometry.bordered_width
109
+ end
110
+
111
+ # @return [Fixnum]
112
+ def y
113
+ @_y ||= geometry.by
114
+ end
115
+
116
+ # @return [Fixnum]
117
+ def x
118
+ @_x ||= geometry.bx
119
+ end
120
+
121
+ end # ClearContent
122
+
123
+ end # Interfaces
124
+
125
+ # @api public
126
+ # @!method clear_content_by_name
127
+ # @see Vedeu::Interfaces.ClearContent.clear_content_by_name
128
+ def_delegators Vedeu::Interfaces::ClearContent,
129
+ :clear_content_by_name
130
+
131
+ end # Vedeu
@@ -170,11 +170,9 @@ module Vedeu
170
170
  #
171
171
  # @return [Boolean]
172
172
  def editable(value = true)
173
- boolean = value ? true : false
173
+ cursor(true) if Vedeu::Boolean.coerce(value)
174
174
 
175
- cursor(true) if boolean
176
-
177
- model.editable = boolean
175
+ model.editable = Vedeu::Boolean.coerce(value)
178
176
  end
179
177
 
180
178
  # Set the interface to be editable.
@@ -292,9 +290,7 @@ module Vedeu
292
290
  #
293
291
  # @return [Boolean]
294
292
  def visible(value = true)
295
- boolean = value ? true : false
296
-
297
- model.visible = boolean
293
+ model.visible = Vedeu::Boolean.coerce(value)
298
294
  end
299
295
 
300
296
  # Set the zindex of the interface. This controls the render
@@ -5,12 +5,15 @@ module Vedeu
5
5
  # This module allows the sharing of presentation concerns between
6
6
  # the models: Interface, View, Line and Stream.
7
7
  #
8
+ # @api private
9
+ #
8
10
  module Presentation
9
11
 
10
12
  end # Presentation
11
13
 
12
14
  end # Vedeu
13
15
 
16
+ require 'vedeu/presentation/parent'
14
17
  require 'vedeu/presentation/colour'
15
18
  require 'vedeu/presentation/position'
16
19
  require 'vedeu/presentation/styles'
@@ -10,6 +10,8 @@ module Vedeu
10
10
  #
11
11
  module Colour
12
12
 
13
+ include Vedeu::Presentation::Parent
14
+
13
15
  # When the background colour for the model exists, return it,
14
16
  # otherwise returns the parent background colour, or an empty
15
17
  # Vedeu::Colours::Background.
@@ -100,11 +102,6 @@ module Vedeu
100
102
  @_colour = @colour = colour
101
103
  end
102
104
 
103
- # @return [NilClass|void]
104
- def parent
105
- present?(@parent) ? @parent : nil
106
- end
107
-
108
105
  # @return [NilClass|String|Symbol]
109
106
  def name
110
107
  if present?(@name)
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vedeu
4
+
5
+ module Presentation
6
+
7
+ #
8
+ # @api private
9
+ #
10
+ module Parent
11
+
12
+ # @return [NilClass|void]
13
+ def parent
14
+ present?(@parent) ? @parent : nil
15
+ end
16
+
17
+ end # Parent
18
+
19
+ end # Presentation
20
+
21
+ end # Vedeu
@@ -6,9 +6,12 @@ module Vedeu
6
6
 
7
7
  # Provides style related presentation behaviour.
8
8
  #
9
+ # @api private
10
+ #
9
11
  module Styles
10
12
 
11
13
  include Vedeu::Common
14
+ include Vedeu::Presentation::Parent
12
15
 
13
16
  # @return [NilClass|String|Symbol]
14
17
  def name
@@ -21,11 +24,6 @@ module Vedeu
21
24
  end
22
25
  end
23
26
 
24
- # @return [NilClass|void]
25
- def parent
26
- present?(@parent) ? @parent : nil
27
- end
28
-
29
27
  # When the style for the model exists, return it, otherwise
30
28
  # returns the parent style, or an empty
31
29
  # {Vedeu::Presentation::Style}.
@@ -3,6 +3,6 @@
3
3
  module Vedeu
4
4
 
5
5
  # The current version of Vedeu.
6
- VERSION = '0.8.24'
6
+ VERSION = '0.8.25'
7
7
 
8
8
  end # Vedeu
@@ -29,6 +29,7 @@ module Vedeu
29
29
  include Vedeu::Views::DefaultAttributes
30
30
  include Vedeu::Repositories::Model
31
31
  include Vedeu::Presentation
32
+ include Vedeu::Presentation::Parent
32
33
  include Vedeu::Presentation::Colour
33
34
  include Vedeu::Presentation::Position
34
35
  include Vedeu::Presentation::Styles
@@ -101,11 +102,6 @@ module Vedeu
101
102
  end
102
103
  end
103
104
 
104
- # @return [NilClass|void]
105
- def parent
106
- present?(@parent) ? @parent : nil
107
- end
108
-
109
105
  # Returns the size of the content in characters without
110
106
  # formatting.
111
107
  #
@@ -30,6 +30,7 @@ module Vedeu
30
30
  include Vedeu::Views::DefaultAttributes
31
31
  include Vedeu::Repositories::Model
32
32
  include Vedeu::Presentation
33
+ include Vedeu::Presentation::Parent
33
34
  include Vedeu::Presentation::Colour
34
35
  include Vedeu::Presentation::Position
35
36
  include Vedeu::Presentation::Styles
@@ -105,11 +106,6 @@ module Vedeu
105
106
  end
106
107
  end
107
108
 
108
- # @return [NilClass|void]
109
- def parent
110
- present?(@parent) ? @parent : nil
111
- end
112
-
113
109
  end # Stream
114
110
 
115
111
  end # Views
@@ -31,6 +31,7 @@ module Vedeu
31
31
  extend Forwardable
32
32
  include Vedeu::Repositories::Model
33
33
  include Vedeu::Presentation
34
+ include Vedeu::Presentation::Parent
34
35
  include Vedeu::Presentation::Colour
35
36
  include Vedeu::Presentation::Position
36
37
  include Vedeu::Presentation::Styles
@@ -118,11 +119,6 @@ module Vedeu
118
119
  end
119
120
  end
120
121
 
121
- # @return [NilClass|void]
122
- def parent
123
- present?(@parent) ? @parent : nil
124
- end
125
-
126
122
  # Store the view in its respective buffer.
127
123
  #
128
124
  # @param refresh [Boolean] Should the buffer of the view be
@@ -14,6 +14,24 @@ module Vedeu
14
14
  it { instance.must_be_instance_of(Vedeu::Boolean) }
15
15
  end
16
16
 
17
+ describe '.coerce' do
18
+ subject { described.coerce(_value) }
19
+
20
+ context 'when the value is falsy' do
21
+ it { subject.must_equal(false) }
22
+ end
23
+
24
+ context 'when the value is truthy' do
25
+ let(:_value) { 0 }
26
+
27
+ it { subject.must_equal(true) }
28
+ end
29
+ end
30
+
31
+ describe '#coerce' do
32
+ it { instance.must_respond_to(:coerce) }
33
+ end
34
+
17
35
  describe '#false?' do
18
36
  subject { instance.false? }
19
37
 
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Vedeu
6
+
7
+ describe 'Bindings' do
8
+ it { Vedeu.bound?(:_clear_view_).must_equal(true) }
9
+ it { Vedeu.bound?(:_clear_view_content_).must_equal(true) }
10
+ end
11
+
12
+ module Interfaces
13
+
14
+ describe ClearContent do
15
+
16
+ let(:described) { Vedeu::Interfaces::ClearContent }
17
+ let(:instance) { described.new(_name) }
18
+ let(:_name) { :vedeu_interfaces_clear }
19
+
20
+ describe '#initialize' do
21
+ it { instance.must_be_instance_of(described) }
22
+ it { instance.instance_variable_get('@name').must_equal(_name) }
23
+ end
24
+
25
+ describe '.clear_content_by_name' do
26
+ it { described.must_respond_to(:clear_content_by_name) }
27
+ end
28
+
29
+ describe '#render' do
30
+ let(:interface) {
31
+ Vedeu::Interfaces::Interface.new(name: _name, visible: visible)
32
+ }
33
+ let(:colour) { interface.colour }
34
+ let(:visible) { true }
35
+ let(:geometry) {
36
+ Vedeu::Geometries::Geometry.new(name: _name, x: 1, y: 1, xn: 2, yn: 2)
37
+ }
38
+ let(:output) {
39
+ [
40
+ [
41
+ Vedeu::Cells::Clear.new(colour: colour,
42
+ name: _name,
43
+ position: [1, 1]),
44
+ Vedeu::Cells::Clear.new(colour: colour,
45
+ name: _name,
46
+ position: [1, 2]),
47
+ ], [
48
+ Vedeu::Cells::Clear.new(colour: colour,
49
+ name: _name,
50
+ position: [2, 1]),
51
+ Vedeu::Cells::Clear.new(colour: colour,
52
+ name: _name,
53
+ position: [2, 2]),
54
+ ]
55
+ ]
56
+ }
57
+
58
+ before do
59
+ Vedeu.interfaces.stubs(:by_name).returns(interface)
60
+ Vedeu.geometries.stubs(:by_name).returns(geometry)
61
+ Vedeu.stubs(:direct_write)
62
+ Vedeu.stubs(:buffer_update)
63
+ end
64
+
65
+ subject { instance.render }
66
+
67
+ # it { subject.must_be_instance_of(Vedeu::Buffers::View) }
68
+ it do
69
+ Vedeu.expects(:direct_write)
70
+ subject
71
+ end
72
+ it do
73
+ Vedeu.expects(:buffer_update)
74
+ subject
75
+ end
76
+ # it { subject.must_equal(output) }
77
+ end
78
+
79
+ end # ClearContent
80
+
81
+ end # Interfaces
82
+
83
+ end # Vedeu
@@ -14,19 +14,12 @@ module Vedeu
14
14
  describe Clear do
15
15
 
16
16
  let(:described) { Vedeu::Interfaces::Clear }
17
- let(:instance) { described.new(_name, options) }
18
- let(:options) {
19
- {
20
- content_only: false,
21
- direct: false,
22
- }
23
- }
17
+ let(:instance) { described.new(_name) }
24
18
  let(:_name) { :vedeu_interfaces_clear }
25
19
 
26
20
  describe '#initialize' do
27
21
  it { instance.must_be_instance_of(described) }
28
22
  it { instance.instance_variable_get('@name').must_equal(_name) }
29
- it { instance.instance_variable_get('@options').must_equal(options) }
30
23
  end
31
24
 
32
25
  describe '.render' do
@@ -34,7 +34,7 @@ module Vedeu
34
34
  @parent = attributes[:parent]
35
35
  end
36
36
 
37
- end # PresentationTestClass
37
+ end # PresentationColourTestClass
38
38
 
39
39
  module Presentation
40
40
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Vedeu
6
+
7
+ class PresentationParentTestClass
8
+
9
+ include Vedeu::Presentation::Parent
10
+
11
+ def initialize(attributes = {})
12
+ @colour = attributes[:colour]
13
+ @parent = attributes[:parent]
14
+ end
15
+
16
+ end # PresentationParentTestClass
17
+
18
+ module Presentation
19
+
20
+ describe Parent do
21
+
22
+ let(:described) { Vedeu::Presentation::Parent }
23
+ let(:included_described) { Vedeu::PresentationParentTestClass }
24
+ let(:included_instance) { included_described.new(attributes) }
25
+ let(:attributes) {
26
+ {
27
+ parent: Vedeu::PresentationParentTestClass.new
28
+ }
29
+ }
30
+
31
+ describe '#parent' do
32
+ it { included_instance.must_respond_to(:parent) }
33
+ end
34
+
35
+ end # Parent
36
+
37
+ end # Presentation
38
+
39
+ end # Vedeu
@@ -4,7 +4,7 @@ require 'test_helper'
4
4
 
5
5
  module Vedeu
6
6
 
7
- class ParentPresentationStyleTestClass
7
+ class ParentPresentationStylesTestClass
8
8
 
9
9
  include Vedeu::Presentation
10
10
  include Vedeu::Presentation::Colour
@@ -18,9 +18,9 @@ module Vedeu
18
18
  @parent = nil
19
19
  end
20
20
 
21
- end # ParentPresentationStyleTestClass
21
+ end # ParentPresentationStylesTestClass
22
22
 
23
- class PresentationStyleTestClass
23
+ class PresentationStylesTestClass
24
24
 
25
25
  include Vedeu::Presentation
26
26
  include Vedeu::Presentation::Colour
@@ -34,14 +34,14 @@ module Vedeu
34
34
  @parent = attributes[:parent]
35
35
  end
36
36
 
37
- end # PresentationTestClass
37
+ end # PresentationStylesTestClass
38
38
 
39
39
  module Presentation
40
40
 
41
41
  describe Styles do
42
42
 
43
43
  let(:described) { Vedeu::Presentation::Styles }
44
- let(:included_described) { Vedeu::PresentationStyleTestClass }
44
+ let(:included_described) { Vedeu::PresentationStylesTestClass }
45
45
  let(:included_instance) { included_described.new(attributes) }
46
46
  let(:attributes) {
47
47
  {
@@ -49,7 +49,7 @@ module Vedeu
49
49
  style: style,
50
50
  }
51
51
  }
52
- let(:parent) { Vedeu::ParentPresentationStyleTestClass.new }
52
+ let(:parent) { Vedeu::ParentPresentationStylesTestClass.new }
53
53
  let(:style) { ['bold'] }
54
54
 
55
55
  describe '#style' do
@@ -84,7 +84,7 @@ module Vedeu
84
84
  it { subject.must_be_instance_of(Vedeu::Presentation::Style) }
85
85
  end
86
86
 
87
- end # Style
87
+ end # Styles
88
88
 
89
89
  end # Presentation
90
90
 
@@ -59,19 +59,15 @@ module Vedeu
59
59
  end
60
60
 
61
61
  describe '#client' do
62
- it { instance.must_respond_to(:client) }
62
+ it { instance.must_respond_to(:client) }
63
63
  end
64
64
 
65
65
  describe '#client=' do
66
- it { instance.must_respond_to(:client=) }
67
- end
68
-
69
- describe '#parent' do
70
- it { instance.must_respond_to(:parent) }
66
+ it { instance.must_respond_to(:client=) }
71
67
  end
72
68
 
73
69
  describe '#parent=' do
74
- it { instance.must_respond_to(:parent=) }
70
+ it { instance.must_respond_to(:parent=) }
75
71
  end
76
72
 
77
73
  describe '#add' do
@@ -45,10 +45,6 @@ module Vedeu
45
45
  it { instance.instance_variable_get('@value').must_equal(_value) }
46
46
  end
47
47
 
48
- describe '#parent' do
49
- it { instance.must_respond_to(:parent) }
50
- end
51
-
52
48
  describe '#parent=' do
53
49
  it { instance.must_respond_to(:parent=) }
54
50
  end
@@ -70,10 +70,6 @@ module Vedeu
70
70
  it { instance.must_respond_to(:name=) }
71
71
  end
72
72
 
73
- describe '#parent' do
74
- it { instance.must_respond_to(:parent) }
75
- end
76
-
77
73
  describe '#parent=' do
78
74
  it { instance.must_respond_to(:parent=) }
79
75
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'simplecov-console', '0.3.0'
33
33
  spec.add_development_dependency 'yard', '0.8.7.6'
34
34
 
35
- spec.add_dependency 'bundler', '~> 1.10'
35
+ spec.add_dependency 'bundler', '~> 1.11'
36
36
  spec.add_dependency 'rake', '~> 10.5'
37
37
  spec.add_dependency 'thor', '0.19.1'
38
38
  spec.add_dependency 'vedeu_cli', '0.0.10'
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.24
4
+ version: 0.8.25
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-04-10 00:00:00.000000000 Z
11
+ date: 2016-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '1.10'
159
+ version: '1.11'
160
160
  type: :runtime
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '1.10'
166
+ version: '1.11'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rake
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -559,6 +559,8 @@ files:
559
559
  - integrations/dsl_app_020.rb
560
560
  - integrations/dsl_app_021.rb
561
561
  - integrations/dsl_app_022.rb
562
+ - integrations/dsl_app_030.rb
563
+ - integrations/dsl_app_031.rb
562
564
  - integrations/dsl_app_border_001.rb
563
565
  - integrations/dsl_app_border_002.rb
564
566
  - integrations/dsl_app_border_003.rb
@@ -570,6 +572,7 @@ files:
570
572
  - integrations/dsl_app_border_009.rb
571
573
  - integrations/dsl_app_border_010.rb
572
574
  - integrations/dsl_app_border_011.rb
575
+ - integrations/dsl_app_border_012.rb
573
576
  - integrations/expected/342_streams.out
574
577
  - integrations/expected/dsl_app_001.out
575
578
  - integrations/expected/dsl_app_002.out
@@ -590,6 +593,8 @@ files:
590
593
  - integrations/expected/dsl_app_017.out
591
594
  - integrations/expected/dsl_app_021.out
592
595
  - integrations/expected/dsl_app_022.out
596
+ - integrations/expected/dsl_app_030.out
597
+ - integrations/expected/dsl_app_031.out
593
598
  - integrations/expected/dsl_app_border_001.out
594
599
  - integrations/expected/dsl_app_border_002.out
595
600
  - integrations/expected/dsl_app_border_003.out
@@ -601,6 +606,7 @@ files:
601
606
  - integrations/expected/dsl_app_border_009.out
602
607
  - integrations/expected/dsl_app_border_010.out
603
608
  - integrations/expected/dsl_app_border_011.out
609
+ - integrations/expected/dsl_app_border_012.out
604
610
  - integrations/support/test_interface.rb
605
611
  - integrations/support/test_interface_021.rb
606
612
  - integrations/support/test_interface_022.rb
@@ -782,6 +788,7 @@ files:
782
788
  - lib/vedeu/input/translator.rb
783
789
  - lib/vedeu/interfaces/all.rb
784
790
  - lib/vedeu/interfaces/clear.rb
791
+ - lib/vedeu/interfaces/clear_content.rb
785
792
  - lib/vedeu/interfaces/dsl.rb
786
793
  - lib/vedeu/interfaces/interface.rb
787
794
  - lib/vedeu/interfaces/null.rb
@@ -819,6 +826,7 @@ files:
819
826
  - lib/vedeu/plugins/plugins.rb
820
827
  - lib/vedeu/presentation/all.rb
821
828
  - lib/vedeu/presentation/colour.rb
829
+ - lib/vedeu/presentation/parent.rb
822
830
  - lib/vedeu/presentation/position.rb
823
831
  - lib/vedeu/presentation/presentation.rb
824
832
  - lib/vedeu/presentation/style.rb
@@ -1015,6 +1023,7 @@ files:
1015
1023
  - test/lib/vedeu/input/repository_test.rb
1016
1024
  - test/lib/vedeu/input/store_test.rb
1017
1025
  - test/lib/vedeu/input/translator_test.rb
1026
+ - test/lib/vedeu/interfaces/clear_content_test.rb
1018
1027
  - test/lib/vedeu/interfaces/clear_test.rb
1019
1028
  - test/lib/vedeu/interfaces/dsl_test.rb
1020
1029
  - test/lib/vedeu/interfaces/interface_test.rb
@@ -1045,6 +1054,7 @@ files:
1045
1054
  - test/lib/vedeu/plugins/plugin_test.rb
1046
1055
  - test/lib/vedeu/plugins/plugins_test.rb
1047
1056
  - test/lib/vedeu/presentation/colour_test.rb
1057
+ - test/lib/vedeu/presentation/parent_test.rb
1048
1058
  - test/lib/vedeu/presentation/position_test.rb
1049
1059
  - test/lib/vedeu/presentation/presentation_test.rb
1050
1060
  - test/lib/vedeu/presentation/style_test.rb
@@ -1277,6 +1287,7 @@ test_files:
1277
1287
  - test/lib/vedeu/input/repository_test.rb
1278
1288
  - test/lib/vedeu/input/store_test.rb
1279
1289
  - test/lib/vedeu/input/translator_test.rb
1290
+ - test/lib/vedeu/interfaces/clear_content_test.rb
1280
1291
  - test/lib/vedeu/interfaces/clear_test.rb
1281
1292
  - test/lib/vedeu/interfaces/dsl_test.rb
1282
1293
  - test/lib/vedeu/interfaces/interface_test.rb
@@ -1307,6 +1318,7 @@ test_files:
1307
1318
  - test/lib/vedeu/plugins/plugin_test.rb
1308
1319
  - test/lib/vedeu/plugins/plugins_test.rb
1309
1320
  - test/lib/vedeu/presentation/colour_test.rb
1321
+ - test/lib/vedeu/presentation/parent_test.rb
1310
1322
  - test/lib/vedeu/presentation/position_test.rb
1311
1323
  - test/lib/vedeu/presentation/presentation_test.rb
1312
1324
  - test/lib/vedeu/presentation/style_test.rb