vedeu 0.6.32 → 0.6.33

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -2
  3. data/README.md +2 -2
  4. data/Rakefile +2 -2
  5. data/docs/borders.md +62 -0
  6. data/docs/{cursor.md → cursors.md} +7 -7
  7. data/docs/events/application.md +1 -1
  8. data/docs/events/document.md +9 -9
  9. data/docs/events/drb.md +7 -7
  10. data/docs/events/focus.md +3 -3
  11. data/docs/events/menu.md +10 -10
  12. data/docs/events/movement.md +3 -3
  13. data/docs/events/refresh.md +5 -10
  14. data/docs/events/system.md +8 -8
  15. data/docs/events/view.md +3 -3
  16. data/docs/events/visibility.md +13 -13
  17. data/docs/geometry.md +1 -1
  18. data/docs/interfaces.md +1 -1
  19. data/lib/vedeu/borders/border.rb +6 -2
  20. data/lib/vedeu/borders/refresh.rb +13 -18
  21. data/lib/vedeu/borders/repository.rb +23 -0
  22. data/lib/vedeu/buffers/refresh.rb +9 -5
  23. data/lib/vedeu/cursors/cursor.rb +2 -0
  24. data/lib/vedeu/cursors/refresh.rb +9 -4
  25. data/lib/vedeu/cursors/repository.rb +1 -1
  26. data/lib/vedeu/editor/cropper.rb +2 -1
  27. data/lib/vedeu/error.rb +6 -1
  28. data/lib/vedeu/groups/refresh.rb +7 -1
  29. data/lib/vedeu/interfaces/null.rb +3 -9
  30. data/lib/vedeu/models/focus.rb +5 -1
  31. data/lib/vedeu/null/generic.rb +3 -9
  32. data/lib/vedeu/output/clear/interface.rb +9 -3
  33. data/lib/vedeu/repositories/repository.rb +2 -2
  34. data/lib/vedeu/terminal/buffer.rb +2 -0
  35. data/lib/vedeu/version.rb +1 -1
  36. data/test/lib/vedeu/borders/refresh_test.rb +10 -2
  37. data/test/lib/vedeu/cursors/repository_test.rb +16 -7
  38. data/test/lib/vedeu/groups/refresh_test.rb +29 -1
  39. data/test/lib/vedeu/interfaces/null_test.rb +7 -14
  40. data/test/lib/vedeu/models/focus_test.rb +1 -1
  41. data/test/lib/vedeu/null/generic_test.rb +12 -7
  42. data/test/lib/vedeu/output/renderers/all_test.rb +20 -13
  43. data/test/support/examples/material_colours_app.rb +90 -23
  44. metadata +4 -4
  45. data/docs/border.md +0 -23
@@ -12,15 +12,9 @@ module Vedeu
12
12
  # @return [String]
13
13
  attr_reader :attributes
14
14
 
15
- # Returns a new instance of Vedeu::Interfaces::Null.
16
- #
17
- # @param attributes [Hash<Symbol => void>]
18
- # @option attributes name [String|Symbol]
19
- # @return [Vedeu::Interfaces::Null]
20
- def initialize(attributes = {})
21
- @attributes = attributes
22
- @name = @attributes[:name]
23
- @visible = false
15
+ # @return [String]
16
+ def group
17
+ ''
24
18
  end
25
19
 
26
20
  end # Null
@@ -82,7 +82,11 @@ module Vedeu
82
82
  #
83
83
  # @return [String]
84
84
  def current
85
- storage[0]
85
+ return storage[0] unless empty?
86
+
87
+ fail Vedeu::Error::Fatal,
88
+ 'No interfaces or views have been registered, therefore the ' \
89
+ 'focus table is empty.'.freeze
86
90
  end
87
91
  alias_method :focus, :current
88
92
 
@@ -21,7 +21,7 @@ module Vedeu
21
21
  # @return [Vedeu::Null::Generic]
22
22
  def initialize(attributes = {})
23
23
  @attributes = attributes
24
- @name = @attributes[:name]
24
+ @name = @attributes.fetch(:name, '')
25
25
  end
26
26
 
27
27
  # @return [FalseClass]
@@ -33,6 +33,8 @@ module Vedeu
33
33
  alias_method :maximise, :falsy
34
34
  alias_method :maximised?, :falsy
35
35
  alias_method :unmaximise, :falsy
36
+ alias_method :visible, :falsy
37
+ alias_method :visible?, :falsy
36
38
 
37
39
  # @return [NilClass]
38
40
  def null(*)
@@ -70,14 +72,6 @@ module Vedeu
70
72
  self
71
73
  end
72
74
 
73
- # The generic null should not be visible.
74
- #
75
- # @return [FalseClass]
76
- def visible?
77
- false
78
- end
79
- alias_method :visible, :visible?
80
-
81
75
  # @return [FalseClass]
82
76
  def visible=(*)
83
77
  false
@@ -6,6 +6,8 @@ module Vedeu
6
6
  #
7
7
  class Interface
8
8
 
9
+ include Vedeu::Common
10
+
9
11
  class << self
10
12
 
11
13
  # Clear the interface with the given name.
@@ -16,7 +18,9 @@ module Vedeu
16
18
  #
17
19
  # @return [Array<Array<Vedeu::Views::Char>>]
18
20
  # @see #initialize
19
- def render(name)
21
+ def render(name = Vedeu.focus)
22
+ name || Vedeu.focus
23
+
20
24
  new(name).render
21
25
  end
22
26
  alias_method :clear_by_name, :render
@@ -30,7 +34,9 @@ module Vedeu
30
34
  #
31
35
  # @return [Array<Array<Vedeu::Views::Char>>]
32
36
  # @see #initialize
33
- def clear_content_by_name(name)
37
+ def clear_content_by_name(name = Vedeu.focus)
38
+ name || Vedeu.focus
39
+
34
40
  new(name, content_only: true).render
35
41
  end
36
42
 
@@ -45,7 +51,7 @@ module Vedeu
45
51
  # not the border as well. Defaults to false.
46
52
  # @return [Vedeu::Clear::Interface]
47
53
  def initialize(name, options = {})
48
- @name = name
54
+ @name = present?(name) ? name : Vedeu.focus
49
55
  @options = options
50
56
  end
51
57
 
@@ -62,8 +62,8 @@ module Vedeu
62
62
  #
63
63
  # @param name [String|Symbol] The name of the stored model.
64
64
  # @return [void]
65
- def by_name(name)
66
- name ||= Vedeu.focus
65
+ def by_name(name = Vedeu.focus)
66
+ name = present?(name) ? name : Vedeu.focus
67
67
 
68
68
  return find(name) if registered?(name)
69
69
 
@@ -95,6 +95,8 @@ module Vedeu
95
95
  buffer[v.position.y][v.position.x] = v if valid_position?(v)
96
96
  end
97
97
 
98
+ render
99
+
98
100
  self
99
101
  end
100
102
 
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.32'.freeze
4
+ VERSION = '0.6.33'.freeze
5
5
 
6
6
  end
@@ -22,7 +22,7 @@ module Vedeu
22
22
  show_left: show_left,
23
23
  show_right: show_right)
24
24
  }
25
- let(:visible) { false }
25
+ let(:visible) { true }
26
26
  let(:enabled) { false }
27
27
  let(:_name) { 'Vedeu::Borders::Refresh' }
28
28
  let(:title) {}
@@ -46,7 +46,7 @@ module Vedeu
46
46
  Vedeu::Geometry::Geometry.new(name: _name, x: 1, xn: 7, y: 1, yn: 4)
47
47
  }
48
48
  let(:interface) {
49
- Vedeu::Interfaces::Interface.new(name: _name, visible: true)
49
+ Vedeu::Interfaces::Interface.new(name: _name, visible: visible)
50
50
  }
51
51
  before do
52
52
  Vedeu.borders.stubs(:by_name).returns(border)
@@ -63,9 +63,17 @@ module Vedeu
63
63
  Vedeu.expects(:render_output)
64
64
  subject
65
65
  }
66
+
67
+ context 'but the interface/view is not visible' do
68
+ let(:visible) { false }
69
+
70
+ it { Vedeu.expects(:render_output).never }
71
+ it { subject.must_equal(nil) }
72
+ end
66
73
  end
67
74
 
68
75
  context 'when the border is not enabled' do
76
+ it { Vedeu.expects(:render_output).never }
69
77
  it { subject.must_equal(nil) }
70
78
  end
71
79
  end
@@ -11,26 +11,35 @@ module Vedeu
11
11
  it { described.must_respond_to(:cursors) }
12
12
 
13
13
  describe '.cursor' do
14
+ before { Vedeu::Models::Focus.reset }
15
+
14
16
  subject { Vedeu.cursor }
15
17
 
16
18
  context 'when there are cursors are defined' do
17
19
  before do
18
- Vedeu::Models::Focus.reset
19
20
  Vedeu.cursors.reset
20
- Vedeu::Models::Focus.add('Vedeu.cursor')
21
21
  Vedeu::Cursors::Cursor.store(name: 'Vedeu.cursor')
22
+ Vedeu::Models::Focus.add('Vedeu.cursor')
22
23
  end
23
24
 
24
- it { subject.must_be_instance_of(Vedeu::Cursors::Cursor) }
25
+ it 'returns the cursor of the interface/view currently in focus' do
26
+ subject.must_be_instance_of(Vedeu::Cursors::Cursor)
27
+ end
25
28
  end
26
29
 
27
30
  context 'when there are no cursors defined' do
28
- before do
29
- Vedeu::Models::Focus.reset
31
+ before {
32
+ Vedeu::Models::Focus.add('Vedeu.cursor')
30
33
  Vedeu.cursors.reset
31
- end
34
+ }
35
+
36
+ it {
37
+ subject.must_be_instance_of(Vedeu::Cursors::Cursor)
38
+ }
39
+ end
32
40
 
33
- it { subject.must_be_instance_of(NilClass) }
41
+ context 'when there are no interfaces or views defined' do
42
+ it { proc { subject }.must_raise(Vedeu::Error::Fatal) }
34
43
  end
35
44
  end
36
45
 
@@ -20,15 +20,43 @@ module Vedeu
20
20
  end
21
21
 
22
22
  describe '.by_name' do
23
+ let(:interface) {
24
+ Vedeu::Interfaces::Interface.new(name: _name, group: group)
25
+ }
26
+ let(:group) { :vedeu_groups_refresh_group }
27
+
23
28
  subject { described.by_name(_name) }
24
29
 
25
30
  context 'when the name is not present' do
26
31
  let(:_name) { '' }
27
32
 
28
- it { proc { subject }.must_raise(Vedeu::Error::MissingRequired) }
33
+ context 'when the currently focussed interface/view has a group' do
34
+ before { Vedeu.interfaces.stubs(:by_name).returns(interface) }
35
+
36
+ # @todo Add more tests.
37
+ # it { skip }
38
+ end
39
+
40
+ context 'when the currently focussed interface/view does not have ' \
41
+ 'a group' do
42
+ let(:group) { '' }
43
+
44
+ before { Vedeu.interfaces.stubs(:by_name).returns(interface) }
45
+
46
+ it { proc { subject }.must_raise(Vedeu::Error::MissingRequired) }
47
+ end
48
+
49
+ context 'when no interfaces/views have been registered' do
50
+ before { Vedeu::Models::Focus.reset }
51
+
52
+ it { proc { subject }.must_raise(Vedeu::Error::Fatal) }
53
+ end
29
54
  end
30
55
 
31
56
  context 'when the name is present' do
57
+ # @todo Add more tests.
58
+ # it { skip }
59
+
32
60
  # it {
33
61
  # Vedeu.expects(:trigger).with(:_refresh_view_)
34
62
  # subject
@@ -7,20 +7,13 @@ module Vedeu
7
7
  describe Null do
8
8
 
9
9
  let(:described) { Vedeu::Interfaces::Null }
10
- let(:instance) { described.new(attributes) }
11
- let(:_name) { 'null_interface' }
12
- let(:attributes) {
13
- {
14
- name: _name
15
- }
16
- }
17
-
18
- describe '#initialize' do
19
- it { instance.must_be_instance_of(described) }
20
- it {
21
- instance.instance_variable_get('@attributes').must_equal(attributes)
22
- }
23
- it { instance.instance_variable_get('@name').must_equal(_name) }
10
+ let(:instance) { described.new }
11
+
12
+ describe '#group' do
13
+ subject { instance.group }
14
+
15
+ it { subject.must_be_instance_of(String) }
16
+ it { subject.must_equal('') }
24
17
  end
25
18
 
26
19
  end # Null
@@ -113,7 +113,7 @@ module Vedeu
113
113
  end
114
114
 
115
115
  context 'when no interfaces are defined' do
116
- it { subject.must_equal(nil) }
116
+ it { proc { subject }.must_raise(Vedeu::Error::Fatal) }
117
117
  end
118
118
 
119
119
  context 'API methods' do
@@ -26,6 +26,16 @@ module Vedeu
26
26
  it {
27
27
  instance.instance_variable_get('@attributes').must_equal(attributes)
28
28
  }
29
+
30
+ context 'when a name is given' do
31
+ it { instance.instance_variable_get('@name').must_equal(_name) }
32
+ end
33
+
34
+ context 'when a name is not given' do
35
+ let(:attributes) { {} }
36
+
37
+ it { instance.instance_variable_get('@name').must_equal('') }
38
+ end
29
39
  end
30
40
 
31
41
  describe '#falsy' do
@@ -37,6 +47,8 @@ module Vedeu
37
47
  it { instance.must_respond_to(:maximise) }
38
48
  it { instance.must_respond_to(:maximised?) }
39
49
  it { instance.must_respond_to(:unmaximise) }
50
+ it { instance.must_respond_to(:visible) }
51
+ it { instance.must_respond_to(:visible?) }
40
52
  end
41
53
 
42
54
  describe '#null' do
@@ -78,13 +90,6 @@ module Vedeu
78
90
  it { subject.must_be_instance_of(described) }
79
91
  end
80
92
 
81
- describe '#visible' do
82
- subject { instance.visible }
83
-
84
- it { subject.must_be_instance_of(FalseClass) }
85
- it { instance.must_respond_to(:visible?) }
86
- end
87
-
88
93
  describe '#visible=' do
89
94
  let(:_value) { :ignored }
90
95
 
@@ -61,6 +61,7 @@ module Vedeu
61
61
  let(:output) {}
62
62
 
63
63
  before do
64
+ Vedeu.stubs(:focus).returns(:vedeu_renderers_render)
64
65
  Vedeu::Renderers.reset
65
66
  Vedeu::Renderers.renderer(DummyRenderer)
66
67
  Vedeu.stubs(:hide_cursor)
@@ -69,24 +70,30 @@ module Vedeu
69
70
 
70
71
  subject { described.render(output) }
71
72
 
72
- # it { subject.must_be_instance_of(Array) }
73
+ context 'when an interface/view has been defined' do
74
+ it {
75
+ DummyRenderer.expects(:render).with(output)
76
+ subject
77
+ }
73
78
 
74
- it {
75
- DummyRenderer.expects(:render).with(output)
76
- subject
77
- }
79
+ context 'when there is content' do
80
+ let(:output) {
81
+ Vedeu::Models::Escape
82
+ .new(value: Vedeu::EscapeSequences::Esc.hide_cursor)
83
+ }
78
84
 
79
- context 'when there is content' do
80
- let(:output) {
81
- Vedeu::Models::Escape
82
- .new(value: Vedeu::EscapeSequences::Esc.hide_cursor)
83
- }
85
+ it { subject.must_be_instance_of(Vedeu::Models::Escape) }
86
+ end
84
87
 
85
- it { subject.must_be_instance_of(Vedeu::Models::Escape) }
88
+ context 'when there is no content' do
89
+ it { subject.must_be_instance_of(NilClass) }
90
+ end
86
91
  end
87
92
 
88
- context 'when there is no content' do
89
- it { subject.must_be_instance_of(NilClass) }
93
+ context 'when no interfaces/view have been defined' do
94
+ before { Vedeu.stubs(:focus).raises(Vedeu::Error::Fatal) }
95
+
96
+ it { proc { subject }.must_raise(Vedeu::Error::Fatal) }
90
97
  end
91
98
  end
92
99
 
@@ -97,7 +97,7 @@ class VedeuMaterialColoursApp
97
97
  x(3)
98
98
  xn(64)
99
99
  y(15)
100
- yn(28)
100
+ yn(32)
101
101
  end
102
102
  zindex(1)
103
103
  end
@@ -113,6 +113,11 @@ class VedeuMaterialColoursApp
113
113
  key(:shift_tab) { Vedeu.trigger(:_focus_prev_) }
114
114
  key(:tab) { Vedeu.trigger(:_focus_next_) }
115
115
 
116
+ key('1') { Vedeu.trigger(:_hide_interface_, 'main_interface') }
117
+ key('2') { Vedeu.trigger(:_show_interface_, 'main_interface') }
118
+ key('3') { Vedeu.trigger(:_hide_interface_, 'other_interface') }
119
+ key('4') { Vedeu.trigger(:_show_interface_, 'other_interface') }
120
+
116
121
  key('a') { Vedeu.trigger(:_view_left_, 'main_interface') }
117
122
  key('s') { Vedeu.trigger(:_view_down_, 'main_interface') }
118
123
  key('d') { Vedeu.trigger(:_view_up_, 'main_interface') }
@@ -121,24 +126,23 @@ class VedeuMaterialColoursApp
121
126
  key('w') { Vedeu.trigger(:_toggle_group_, :my_group) }
122
127
  key('e') { Vedeu.trigger(:_hide_group_, :my_group) }
123
128
  key('r') { Vedeu.trigger(:_show_group_, :my_group) }
129
+ key('t') do
130
+ Vedeu.trigger(:_toggle_interface_, 'main_interface')
131
+ Vedeu.trigger(:_toggle_interface_, 'other_interface')
132
+ end
124
133
 
125
134
  key('h') { Vedeu.trigger(:_view_left_, 'other_interface') }
126
135
  key('j') { Vedeu.trigger(:_view_down_, 'other_interface') }
127
136
  key('k') { Vedeu.trigger(:_view_up_, 'other_interface') }
128
137
  key('l') { Vedeu.trigger(:_view_right_, 'other_interface') }
129
138
 
130
- key('t') do
131
- Vedeu.trigger(:_toggle_interface_, 'main_interface')
132
- Vedeu.trigger(:_toggle_interface_, 'other_interface')
133
- end
134
- key('1') { Vedeu.trigger(:_hide_interface_, 'main_interface') }
135
- key('2') { Vedeu.trigger(:_show_interface_, 'main_interface') }
136
- key('3') { Vedeu.trigger(:_hide_interface_, 'other_interface') }
137
- key('4') { Vedeu.trigger(:_show_interface_, 'other_interface') }
138
139
  key('m') { Vedeu.trigger(:_maximise_, 'main_interface') }
139
140
  key('n') { Vedeu.trigger(:_unmaximise_, 'main_interface') }
140
141
  key('b') { Vedeu.trigger(:_maximise_, 'other_interface') }
141
142
  key('v') { Vedeu.trigger(:_unmaximise_, 'other_interface') }
143
+
144
+ key('x') { Vedeu.trigger(:_set_border_caption_, Vedeu.focus, 'Amazing!') }
145
+ key('z') { Vedeu.trigger(:_set_border_title_, Vedeu.focus, 'Surprise!') }
142
146
  end
143
147
 
144
148
  Vedeu.renders do
@@ -193,30 +197,93 @@ class VedeuMaterialColoursApp
193
197
  view 'keys_interface' do
194
198
  line {
195
199
  stream {
196
- left "\u2190, \u2193, \u2191, \u2192", width: 20
200
+ left "\u2190 \u2193 \u2191 \u2192",
201
+ foreground: '#ffff00', width: 20
202
+ }
203
+ stream { left "Move cursor" }
204
+ }
205
+ line {}
206
+ line {
207
+ stream {
208
+ left 'a, s, d, f',
209
+ foreground: '#ffff00', width: 20
210
+ }
211
+ stream { left 'Move Rainbow! left, down, up, right' }
212
+ }
213
+ line {
214
+ stream {
215
+ left 'h, j, k, l',
216
+ foreground: '#ffff00', width: 20
217
+ }
218
+ stream { left 'Move Wow! left, down, up, right' }
219
+ }
220
+ line {}
221
+ line {
222
+ stream {
223
+ left 't',
224
+ foreground: '#ffff00', width: 20
225
+ }
226
+ stream { left 'Toggle Rainbow!/Wow!' }
227
+ }
228
+ line {
229
+ stream {
230
+ left '1, 2',
231
+ foreground: '#ffff00', width: 20
197
232
  }
233
+ stream { left 'Hide/Show Rainbow!' }
234
+ }
235
+ line {
198
236
  stream {
199
- left "Move cursor"
237
+ left '3, 4',
238
+ foreground: '#ffff00', width: 20
200
239
  }
240
+ stream { left 'Hide/Show Wow!' }
201
241
  }
242
+ line {}
202
243
  line {
203
244
  stream {
204
- left "q", width: 20
245
+ left 'm, n',
246
+ foreground: '#ffff00', width: 20
205
247
  }
248
+ stream { left 'Maximise/Unmaximise Rainbow!' }
249
+ }
250
+ line {
251
+ stream {
252
+ left 'b, v',
253
+ foreground: '#ffff00', width: 20
254
+ }
255
+ stream { left 'Maximise/Unmaximise Wow!' }
256
+ }
257
+ line {}
258
+ line {
259
+ stream {
260
+ left 'escape',
261
+ foreground: '#ffff00', width: 20
262
+ }
263
+ stream { left 'Mode Switch' }
264
+ }
265
+ line {
266
+ stream {
267
+ left 'shift+tab',
268
+ foreground: '#ffff00', width: 20
269
+ }
270
+ stream { left 'Focus previous view' }
271
+ }
272
+ line {
273
+ stream {
274
+ left 'tab',
275
+ foreground: '#ffff00', width: 20
276
+ }
277
+ stream { left 'Focus next view' }
278
+ }
279
+ line {}
280
+ line {
206
281
  stream {
207
- left "Exit"
282
+ left 'q',
283
+ foreground: '#ffff00', width: 20
208
284
  }
285
+ stream { left 'Exit' }
209
286
  }
210
- line { left 'escape - mode switch'}
211
- line { left 'shift+tab - focus previous'}
212
- line { left 'tab - focus next'}
213
- line { left 'a, s, d, f - Move Rainbow! left, down, up, right' }
214
- line { left 'h, j, k, l - Move Wow! left, down, up, right' }
215
- line { left 't - Toggle Rainbow!/Wow!' }
216
- line { left '1,2 - Hide/Show Rainbow!'}
217
- line { left '3,4 - Hide/Show Wow!'}
218
- line { left 'm,n - Maximise/Unmaximise Rainbow!' }
219
- line { left 'b,v - Maximise/Unmaximise Wow!' }
220
287
  end
221
288
  end
222
289