vedeu 0.4.16 → 0.4.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/api.rb +7 -21
  3. data/lib/vedeu/bindings.rb +2 -6
  4. data/lib/vedeu/buffers/buffer.rb +29 -34
  5. data/lib/vedeu/cursor/cursor.rb +5 -2
  6. data/lib/vedeu/distributed/all.rb +5 -5
  7. data/lib/vedeu/distributed/server.rb +1 -1
  8. data/lib/vedeu/dsl/components/border.rb +1 -2
  9. data/lib/vedeu/dsl/components/geometry.rb +0 -47
  10. data/lib/vedeu/dsl/interface.rb +4 -11
  11. data/lib/vedeu/dsl/line.rb +1 -2
  12. data/lib/vedeu/dsl/shared/all.rb +1 -2
  13. data/lib/vedeu/dsl/shared/{colour.rb → presentation.rb} +27 -4
  14. data/lib/vedeu/dsl/shared/use.rb +50 -29
  15. data/lib/vedeu/dsl/stream.rb +1 -2
  16. data/lib/vedeu/geometry/geometry.rb +22 -11
  17. data/lib/vedeu/geometry/index_position.rb +0 -19
  18. data/lib/vedeu/geometry/position_validator.rb +8 -8
  19. data/lib/vedeu/models/interface.rb +34 -76
  20. data/lib/vedeu/models/null_interface.rb +5 -0
  21. data/lib/vedeu/models/stream.rb +1 -1
  22. data/lib/vedeu/output/border.rb +25 -41
  23. data/lib/vedeu/output/clear.rb +1 -7
  24. data/lib/vedeu/output/esc.rb +10 -10
  25. data/lib/vedeu/output/presentation.rb +2 -0
  26. data/lib/vedeu/output/renderers/escape_sequence_renderer.rb +3 -0
  27. data/lib/vedeu/repositories/model.rb +6 -0
  28. data/lib/vedeu/repositories/repositories/groups.rb +12 -0
  29. data/lib/vedeu/repositories/repository.rb +11 -8
  30. data/lib/vedeu/storage/all.rb +4 -4
  31. data/lib/vedeu/support/visibility.rb +8 -0
  32. data/test/lib/vedeu/buffers/buffer_test.rb +0 -2
  33. data/test/lib/vedeu/cursor/cursor_test.rb +14 -0
  34. data/test/lib/vedeu/dsl/components/border_test.rb +2 -2
  35. data/test/lib/vedeu/dsl/components/geometry_test.rb +63 -82
  36. data/test/lib/vedeu/dsl/components/keymap_test.rb +3 -3
  37. data/test/lib/vedeu/dsl/components/menu_test.rb +8 -8
  38. data/test/lib/vedeu/dsl/interface_test.rb +14 -22
  39. data/test/lib/vedeu/dsl/line_test.rb +4 -4
  40. data/test/lib/vedeu/dsl/shared/{colour_test.rb → presentation_test.rb} +19 -11
  41. data/test/lib/vedeu/dsl/shared/text_test.rb +15 -15
  42. data/test/lib/vedeu/dsl/shared/use_test.rb +24 -7
  43. data/test/lib/vedeu/geometry/geometry_test.rb +22 -19
  44. data/test/lib/vedeu/geometry/grid_test.rb +3 -3
  45. data/test/lib/vedeu/geometry/index_position_test.rb +0 -45
  46. data/test/lib/vedeu/geometry/position_test.rb +5 -5
  47. data/test/lib/vedeu/models/cell_test.rb +3 -3
  48. data/test/lib/vedeu/models/char_test.rb +5 -5
  49. data/test/lib/vedeu/models/interface_test.rb +7 -53
  50. data/test/lib/vedeu/models/null_test.rb +2 -2
  51. data/test/lib/vedeu/models/stream_test.rb +5 -5
  52. data/test/lib/vedeu/output/border_test.rb +1 -0
  53. data/test/lib/vedeu/output/colour_test.rb +16 -16
  54. data/test/lib/vedeu/output/esc_test.rb +15 -1
  55. data/test/lib/vedeu/output/html_char_test.rb +4 -4
  56. data/test/lib/vedeu/output/style_test.rb +15 -13
  57. data/test/lib/vedeu/output/text_test.rb +3 -3
  58. data/test/lib/vedeu/repositories/collection_test.rb +2 -2
  59. data/test/lib/vedeu/repositories/model_test.rb +19 -0
  60. data/test/lib/vedeu/repositories/repositories/groups_test.rb +22 -0
  61. data/test/lib/vedeu/repositories/repository_test.rb +50 -16
  62. data/test/lib/vedeu/support/common_test.rb +5 -5
  63. data/test/lib/vedeu/support/terminal_test.rb +3 -3
  64. data/test/lib/vedeu/support/visibility_test.rb +8 -0
  65. data/test/support/helpers/model_test_class.rb +18 -0
  66. data/test/test_helper.rb +1 -1
  67. data/vedeu.gemspec +2 -2
  68. metadata +7 -20
  69. data/lib/vedeu/dsl/shared/style.rb +0 -39
  70. data/test/lib/vedeu/dsl/shared/style_test.rb +0 -25
  71. data/test/support/helpers/all.rb +0 -5
  72. data/test/support/helpers/dsl_model_test_class.rb +0 -25
  73. data/test/support/helpers/helpers.rb +0 -17
  74. data/test/support/helpers/repositories.rb +0 -26
  75. data/test/support/helpers/repository_test_module.rb +0 -21
@@ -12,6 +12,7 @@ module Vedeu
12
12
 
13
13
  else
14
14
  Vedeu::Background.new
15
+ # @todo: Should this be: parent_background
15
16
 
16
17
  end
17
18
  end
@@ -40,6 +41,7 @@ module Vedeu
40
41
 
41
42
  else
42
43
  Vedeu::Foreground.new
44
+ # @todo: Should this be: parent_foreground
43
45
 
44
46
  end
45
47
  end
@@ -29,6 +29,9 @@ module Vedeu
29
29
  # @return [Array<Array<Vedeu::Char>>]
30
30
  attr_reader :output
31
31
 
32
+ # Escapes the escape sequences.
33
+ #
34
+ # @return [String]
32
35
  def parsed
33
36
  @parsed ||= Array(output).flatten.map do |char|
34
37
  Esc.escape(char.to_s) + "\n"
@@ -40,6 +40,12 @@ module Vedeu
40
40
  alias_method :member, :child
41
41
  alias_method :collection, :child
42
42
 
43
+ # @note
44
+ # Not current used.
45
+ #
46
+ # @param klass [void]
47
+ # @param as [void]
48
+ # @return [void]
43
49
  def repository(klass, as:)
44
50
  self.repository = as
45
51
  klass.register(as, self)
@@ -19,6 +19,18 @@ module Vedeu
19
19
 
20
20
  end
21
21
 
22
+ # @param name [String] The name of the stored group.
23
+ # @return [Vedeu::Group]
24
+ def by_name(name)
25
+ if registered?(name)
26
+ find(name)
27
+
28
+ else
29
+ Vedeu::Group.new(name: name).store
30
+
31
+ end
32
+ end
33
+
22
34
  end # Groups
23
35
 
24
36
  end # Vedeu
@@ -24,6 +24,9 @@ module Vedeu
24
24
  # @return [void]
25
25
  attr_reader :storage
26
26
 
27
+ # @param model [Class]
28
+ # @param storage [Class|Hash]
29
+ # @return [Vedeu::Repository]
27
30
  def self.register_repository(model = nil, storage = {})
28
31
  new(model, storage).tap do |klass|
29
32
  Vedeu::Repositories.register(klass.repository)
@@ -40,6 +43,9 @@ module Vedeu
40
43
  @storage = storage
41
44
  end
42
45
 
46
+ # Returns the repository class.
47
+ #
48
+ # @return [Class]
43
49
  def repository
44
50
  self.class # .name
45
51
  end
@@ -86,6 +92,11 @@ module Vedeu
86
92
  end
87
93
  alias_method :by_name, :find_or_create
88
94
 
95
+ # @return [String]
96
+ def inspect
97
+ "<#{self.class.name}: #{registered.inspect}>"
98
+ end
99
+
89
100
  # Returns a collection of the names of all the registered entities.
90
101
  #
91
102
  # @return [Array]
@@ -145,14 +156,6 @@ module Vedeu
145
156
  end
146
157
  alias_method :register, :store
147
158
 
148
- # Access a model by name.
149
- #
150
- # @param name [String]
151
- # @return [|NilClass]
152
- def use(name)
153
- find(name) if registered?(name)
154
- end
155
-
156
159
  private
157
160
 
158
161
  # @return [Hash]
@@ -1,6 +1,6 @@
1
- require 'vedeu/storage/store'
1
+ require_relative 'store'
2
2
 
3
- require 'vedeu/storage/associative_store'
4
- require 'vedeu/storage/conveyor_store'
5
- require 'vedeu/storage/fifo_store'
3
+ require_relative 'associative_store'
4
+ require_relative 'conveyor_store'
5
+ require_relative 'fifo_store'
6
6
 
@@ -4,6 +4,14 @@ module Vedeu
4
4
  #
5
5
  class Visibility
6
6
 
7
+ # @param name [String]
8
+ # @return [Vedeu::Visibility]
9
+ def self.for_cursor(name = nil)
10
+ named = name ? Vedeu.cursors.by_name(name) : Vedeu.cursor
11
+
12
+ new(named)
13
+ end
14
+
7
15
  # @param model [void]
8
16
  # @return [void]
9
17
  def self.show(model)
@@ -12,14 +12,12 @@ module Vedeu
12
12
  back: back,
13
13
  front: front,
14
14
  previous: previous,
15
- repository: repository,
16
15
  }
17
16
  }
18
17
  let(:_name) { 'krypton' }
19
18
  let(:back) {}
20
19
  let(:front) {}
21
20
  let(:previous) {}
22
- let(:repository) {}
23
21
 
24
22
  before { Vedeu.stubs(:trigger) }
25
23
 
@@ -39,6 +39,13 @@ module Vedeu
39
39
  it { subject.instance_variable_get('@y').must_equal(8) }
40
40
  end
41
41
 
42
+ describe '#hide_cursor' do
43
+ subject { instance.hide_cursor }
44
+
45
+ it { subject.must_be_instance_of(String) }
46
+ it { subject.must_equal("\e[?25l") }
47
+ end
48
+
42
49
  describe '#inspect' do
43
50
  subject { instance.inspect }
44
51
 
@@ -48,6 +55,13 @@ module Vedeu
48
55
  ) }
49
56
  end
50
57
 
58
+ describe '#show_cursor' do
59
+ subject { instance.show_cursor }
60
+
61
+ it { subject.must_be_instance_of(String) }
62
+ it { subject.must_equal("\e[?25h") }
63
+ end
64
+
51
65
  describe '#to_s' do
52
66
  let(:visible) { true }
53
67
 
@@ -173,9 +173,9 @@ module Vedeu
173
173
  end
174
174
 
175
175
  describe '#title' do
176
- let(:value) { 'Some title'}
176
+ let(:_value) { 'Some title'}
177
177
 
178
- subject { instance.title(value) }
178
+ subject { instance.title(_value) }
179
179
 
180
180
  it { subject.must_be_instance_of(String) }
181
181
  it { subject.must_equal('Some title') }
@@ -10,6 +10,8 @@ module Vedeu
10
10
  let(:instance) { described.new(model) }
11
11
  let(:model) { Vedeu::Geometry.new }
12
12
 
13
+ before { Terminal.stubs(:size).returns([25, 80]) }
14
+
13
15
  describe 'alias methods' do
14
16
  it { instance.must_respond_to(:centred!) }
15
17
  end
@@ -20,113 +22,86 @@ module Vedeu
20
22
  end
21
23
 
22
24
  describe '#centred' do
23
- subject { Vedeu::Geometry.build({}) { centred true } }
25
+ subject { instance.centred(true) }
24
26
 
25
27
  it 'sets the attribute to the value' do
26
- subject.centred.must_equal(true)
28
+ subject.must_equal(true)
27
29
  end
28
30
 
29
31
  context 'DSL #centred' do
30
32
  subject {
31
- Vedeu.interface 'geometry' do
32
- geometry do
33
- centred false
34
- end
33
+ Vedeu.geometry 'geometry' do
34
+ centred false
35
35
  end
36
36
  }
37
37
 
38
- it { subject.must_be_instance_of(Vedeu::Interface) }
38
+ it { subject.must_be_instance_of(Vedeu::Geometry) }
39
39
 
40
40
  it 'allows the use of centred within geometry' do
41
- subject.geometry.centred.must_equal(false)
41
+ subject.centred.must_equal(false)
42
42
  end
43
43
 
44
44
  context 'when no value is given' do
45
45
  subject {
46
- Vedeu.interface 'geometry' do
47
- geometry do
48
- centred
49
- end
46
+ Vedeu.geometry 'geometry' do
47
+ centred
50
48
  end
51
49
  }
52
50
 
53
- it { subject.geometry.centred.must_equal(true) }
51
+ it { subject.centred.must_equal(true) }
54
52
  end
55
53
  end
56
54
  end
57
55
 
58
56
  describe '#height' do
59
- subject { Vedeu::Geometry.build({}) { height 6 } }
57
+ subject { instance.height(6) }
60
58
 
61
59
  it 'sets the attribute to the value' do
62
- subject.height.must_equal(6)
60
+ subject.must_equal(6)
63
61
  end
64
62
 
65
63
  context 'DSL #height' do
66
64
  subject {
67
- Vedeu.interface 'geometry' do
68
- geometry do
69
- height 17
70
- end
65
+ Vedeu.geometry 'geometry' do
66
+ height 17
71
67
  end
72
68
  }
73
69
 
74
- it { subject.must_be_instance_of(Vedeu::Interface) }
70
+ it { subject.must_be_instance_of(Vedeu::Geometry) }
75
71
 
76
72
  it 'allows the use of height within geometry' do
77
- subject.geometry.height.must_equal(17)
73
+ subject.height.must_equal(17)
78
74
  end
79
75
  end
80
76
  end
81
77
 
82
- # describe '#use' do
83
- # subject {
84
- # Vedeu::Geometry.build({ name: 'hydrogen' }) { use 'helium' }
85
- # }
86
-
87
- # context 'when the named geometry does not exist' do
88
- # end
89
-
90
- # context 'when the named geometry exists' do
91
- # before do
92
- # Vedeu::Geometry.build({ name: 'helium', x: 5 }).store
93
- # end
94
-
95
- # it { subject.must_be_instance_of(Vedeu::Geometry) }
96
- # it { subject.name.must_equal('hydrogen') }
97
- # it { subject.x.must_equal(5) }
98
- # end
99
- # end
100
-
101
78
  describe '#width' do
102
- subject { Vedeu::Geometry.build({}) { width 25 } }
79
+ subject { instance.width(25) }
103
80
 
104
81
  it 'sets the attribute to the value' do
105
- subject.width.must_equal(25)
82
+ subject.must_equal(25)
106
83
  end
107
84
 
108
85
  context 'DSL #width' do
109
86
  subject {
110
- Vedeu.interface 'geometry' do
111
- geometry do
112
- width 29
113
- end
87
+ Vedeu.geometry 'geometry' do
88
+ width 29
114
89
  end
115
90
  }
116
91
 
117
- it { subject.must_be_instance_of(Vedeu::Interface) }
92
+ it { subject.must_be_instance_of(Vedeu::Geometry) }
118
93
 
119
94
  it 'allows the use of width within geometry' do
120
- subject.geometry.width.must_equal(29)
95
+ subject.width.must_equal(29)
121
96
  end
122
97
  end
123
98
  end
124
99
 
125
100
  describe '#x' do
126
- subject { Vedeu::Geometry.build({}) { x 2 } }
101
+ subject { instance.x(2) }
127
102
 
128
103
  it 'sets the attribute to the value' do
129
- subject.x.must_equal(2)
104
+ subject.must_equal(2)
130
105
  end
131
106
 
132
107
  context 'when a block is given' do
@@ -143,41 +118,46 @@ module Vedeu
143
118
 
144
119
  context 'DSL #x' do
145
120
  subject {
146
- Vedeu.interface 'geometry' do
147
- geometry do
148
- x 7
149
- end
121
+ Vedeu.geometry 'geometry' do
122
+ x 7
150
123
  end
151
124
  }
152
125
 
153
- it { subject.must_be_instance_of(Vedeu::Interface) }
126
+ it { subject.must_be_instance_of(Vedeu::Geometry) }
154
127
 
155
128
  it 'allows the use of x within geometry' do
156
- subject.geometry.x.must_equal(7)
129
+ subject.x.must_equal(7)
157
130
  end
158
131
 
159
132
  context 'when no value is given' do
160
133
  subject {
161
- Vedeu.interface 'geometry' do
162
- geometry do
163
- x
164
- end
134
+ Vedeu.geometry 'geometry' do
135
+ x
165
136
  end
166
137
  }
167
138
 
168
- it { subject.geometry.x.must_equal(1) }
139
+ it { subject.x.must_equal(1) }
169
140
  end
170
141
 
171
142
  context 'when a block is given' do
143
+ subject {
144
+ Vedeu::Geometry.build({}) do
145
+ x do
146
+ 8 + 8
147
+ end
148
+ end
149
+ }
150
+
151
+ it { subject.x.must_equal(16) }
172
152
  end
173
153
  end
174
154
  end
175
155
 
176
156
  describe '#y' do
177
- subject { Vedeu::Geometry.build({}) { y 5 } }
157
+ subject { instance.y(5) }
178
158
 
179
159
  it 'sets the attribute to the value' do
180
- subject.y.must_equal(5)
160
+ subject.must_equal(5)
181
161
  end
182
162
 
183
163
  context 'when a block is given' do
@@ -194,42 +174,45 @@ module Vedeu
194
174
 
195
175
  context 'DSL #y' do
196
176
  subject {
197
- Vedeu.interface 'geometry' do
198
- geometry do
199
- y 4
200
- end
177
+ Vedeu.geometry 'geometry' do
178
+ y 4
201
179
  end
202
180
  }
203
181
 
204
- it { subject.must_be_instance_of(Vedeu::Interface) }
182
+ it { subject.must_be_instance_of(Vedeu::Geometry) }
205
183
 
206
184
  it 'allows the use of y within geometry' do
207
- subject.geometry.y.must_equal(4)
185
+ subject.y.must_equal(4)
208
186
  end
209
187
 
210
188
  context 'when no value is given' do
211
189
  subject {
212
- Vedeu.interface 'geometry' do
213
- geometry do
214
- y
215
- end
190
+ Vedeu.geometry 'geometry' do
191
+ y
216
192
  end
217
193
  }
218
194
 
219
- it { subject.geometry.y.must_equal(1) }
195
+ it { subject.y.must_equal(1) }
220
196
  end
221
197
 
222
198
  context 'when a block is given' do
199
+ subject {
200
+ Vedeu::Geometry.build({}) do
201
+ y do
202
+ 8 + 8
203
+ end
204
+ end
205
+ }
206
+
207
+ it { subject.y.must_equal(16) }
223
208
  end
224
209
  end
225
210
  end
226
211
 
227
212
  describe '#xn' do
228
- before { Terminal.stubs(:size).returns([25, 80]) }
229
-
230
- subject { Vedeu::Geometry.build({}) { xn 15 } }
213
+ subject { instance.xn(15) }
231
214
 
232
- it { subject.xn.must_equal(15) }
215
+ it { subject.must_equal(15) }
233
216
 
234
217
  context 'when a block is given' do
235
218
  subject {
@@ -245,11 +228,9 @@ module Vedeu
245
228
  end
246
229
 
247
230
  describe '#yn' do
248
- before { Terminal.stubs(:size).returns([25, 80]) }
249
-
250
- subject { Vedeu::Geometry.build({}) { yn 8 } }
231
+ subject { instance.yn(8) }
251
232
 
252
- it { subject.yn.must_equal(8) }
233
+ it { subject.must_equal(8) }
253
234
 
254
235
  context 'when a block is given' do
255
236
  subject {