vedeu 0.4.8 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/docs/object_graph.md +14 -0
- data/examples/borders_app.rb +19 -19
- data/lib/vedeu/api.rb +134 -22
- data/lib/vedeu/buffers/buffer.rb +11 -8
- data/lib/vedeu/cursor/cursor.rb +2 -1
- data/lib/vedeu/dsl/shared/colour.rb +1 -1
- data/lib/vedeu/geometry/area.rb +25 -20
- data/lib/vedeu/geometry/canvas.rb +12 -2
- data/lib/vedeu/geometry/dimension.rb +68 -21
- data/lib/vedeu/geometry/geometry.rb +70 -224
- data/lib/vedeu/geometry/position.rb +1 -6
- data/lib/vedeu/models/cell.rb +1 -6
- data/lib/vedeu/models/char.rb +1 -6
- data/lib/vedeu/output/compositor.rb +3 -3
- data/lib/vedeu/output/viewport.rb +6 -0
- data/test/lib/vedeu/distributed/server_test.rb +4 -0
- data/test/lib/vedeu/dsl/components/geometry_test.rb +4 -0
- data/test/lib/vedeu/geometry/area_test.rb +95 -7
- data/test/lib/vedeu/geometry/canvas_test.rb +10 -2
- data/test/lib/vedeu/geometry/dimension_test.rb +112 -33
- data/test/lib/vedeu/geometry/geometry_test.rb +71 -240
- data/test/lib/vedeu/geometry/position_test.rb +5 -9
- data/test/lib/vedeu/models/cell_test.rb +1 -15
- data/test/lib/vedeu/models/char_test.rb +14 -0
- data/test/lib/vedeu/output/colour_test.rb +16 -0
- data/test/lib/vedeu/output/compositor_test.rb +3 -1
- data/vedeu.gemspec +1 -1
- metadata +4 -3
@@ -48,17 +48,12 @@ module Vedeu
|
|
48
48
|
@x = (x.nil? || x < 1) ? 1 : x
|
49
49
|
end
|
50
50
|
|
51
|
-
# @param other [Vedeu::Position]
|
52
|
-
# @return [Boolean]
|
53
|
-
def ==(other)
|
54
|
-
eql?(other)
|
55
|
-
end
|
56
|
-
|
57
51
|
# @param other [Vedeu::Position]
|
58
52
|
# @return [Boolean]
|
59
53
|
def eql?(other)
|
60
54
|
self.class == other.class && (x == other.x && y == other.y)
|
61
55
|
end
|
56
|
+
alias_method :==, :eql?
|
62
57
|
|
63
58
|
# Return the escape sequence required to position the cursor at a particular
|
64
59
|
# point on the screen. When passed a block, will do the aforementioned,
|
data/lib/vedeu/models/cell.rb
CHANGED
@@ -45,12 +45,6 @@ module Vedeu
|
|
45
45
|
@y = attributes[:y]
|
46
46
|
end
|
47
47
|
|
48
|
-
# @param other [Vedeu::Cell]
|
49
|
-
# @return [Boolean]
|
50
|
-
def ==(other)
|
51
|
-
eql?(other)
|
52
|
-
end
|
53
|
-
|
54
48
|
# @param other [Vedeu::Cell]
|
55
49
|
# @return [Boolean]
|
56
50
|
def eql?(other)
|
@@ -62,6 +56,7 @@ module Vedeu
|
|
62
56
|
x == other.x &&
|
63
57
|
y == other.y
|
64
58
|
end
|
59
|
+
alias_method :==, :eql?
|
65
60
|
|
66
61
|
end # Cell
|
67
62
|
|
data/lib/vedeu/models/char.rb
CHANGED
@@ -48,12 +48,6 @@ module Vedeu
|
|
48
48
|
@value = @attributes[:value]
|
49
49
|
end
|
50
50
|
|
51
|
-
# @param other [Vedeu::Char]
|
52
|
-
# @return [Boolean]
|
53
|
-
def ==(other)
|
54
|
-
eql?(other)
|
55
|
-
end
|
56
|
-
|
57
51
|
# When {Vedeu::Viewport#padded_lines} has less lines that required to fill
|
58
52
|
# the visible area of the interface, it creates a line that contains a
|
59
53
|
# single {Vedeu::Char} containing a space (0x20); later,
|
@@ -70,6 +64,7 @@ module Vedeu
|
|
70
64
|
def eql?(other)
|
71
65
|
self.class == other.class && value == other.value
|
72
66
|
end
|
67
|
+
alias_method :==, :eql?
|
73
68
|
|
74
69
|
# @return [String]
|
75
70
|
def inspect
|
@@ -30,9 +30,9 @@ module Vedeu
|
|
30
30
|
|
31
31
|
# @return [Array<Interface>]
|
32
32
|
def compose
|
33
|
-
buffer.
|
34
|
-
view.colour
|
35
|
-
view.style
|
33
|
+
buffer.each do |view|
|
34
|
+
view.colour = interface.colour unless view.colour
|
35
|
+
view.style = interface.style unless view.style
|
36
36
|
|
37
37
|
Vedeu::Output.render(view)
|
38
38
|
end
|
@@ -122,6 +122,9 @@ module Vedeu
|
|
122
122
|
# Scrolls the content vertically when the stored cursor's y position for the
|
123
123
|
# interface is outside of the visible area.
|
124
124
|
#
|
125
|
+
# @note
|
126
|
+
# The height is reduced by one as #rows is a range of Array elements.
|
127
|
+
#
|
125
128
|
# @return [Range]
|
126
129
|
def rows
|
127
130
|
top..(top + (height - 1))
|
@@ -132,6 +135,9 @@ module Vedeu
|
|
132
135
|
# Scrolls the content horizontally when the stored cursor's x position for
|
133
136
|
# the interface is outside of the visible area.
|
134
137
|
#
|
138
|
+
# @note
|
139
|
+
# The width is reduced by one as #columns is a range of Array elements.
|
140
|
+
#
|
135
141
|
# @return [Range]
|
136
142
|
def columns
|
137
143
|
left..(left + (width - 1))
|
@@ -19,10 +19,14 @@ module Vedeu
|
|
19
19
|
let(:data) {}
|
20
20
|
|
21
21
|
subject { described.input(data) }
|
22
|
+
|
23
|
+
it { Vedeu.expects(:trigger); subject }
|
22
24
|
end
|
23
25
|
|
24
26
|
describe '.output' do
|
25
27
|
subject { described.output }
|
28
|
+
|
29
|
+
it { Vedeu.expects(:trigger); subject }
|
26
30
|
end
|
27
31
|
|
28
32
|
describe '#pid' do
|
@@ -206,12 +206,16 @@ module Vedeu
|
|
206
206
|
end
|
207
207
|
|
208
208
|
describe '#xn' do
|
209
|
+
before { Terminal.stubs(:size).returns([25, 80]) }
|
210
|
+
|
209
211
|
subject { Vedeu::Geometry.build({}) { xn 15 } }
|
210
212
|
|
211
213
|
it { subject.xn.must_equal(15) }
|
212
214
|
end
|
213
215
|
|
214
216
|
describe '#yn' do
|
217
|
+
before { Terminal.stubs(:size).returns([25, 80]) }
|
218
|
+
|
215
219
|
subject { Vedeu::Geometry.build({}) { yn 8 } }
|
216
220
|
|
217
221
|
it { subject.yn.must_equal(8) }
|
@@ -10,6 +10,7 @@ module Vedeu
|
|
10
10
|
let(:yn) { 9 }
|
11
11
|
let(:x) { 6 }
|
12
12
|
let(:xn) { 21 }
|
13
|
+
let(:offset) { 1 }
|
13
14
|
|
14
15
|
describe 'accessors and aliases' do
|
15
16
|
it { instance.must_respond_to(:y) }
|
@@ -66,32 +67,119 @@ module Vedeu
|
|
66
67
|
it { subject.instance_variable_get('@xn').must_equal(xn) }
|
67
68
|
end
|
68
69
|
|
69
|
-
describe '#
|
70
|
-
|
70
|
+
describe '#eql?' do
|
71
|
+
let(:other) { described.new(y: 4, yn: 9, x: 6, xn: 21) }
|
71
72
|
|
72
|
-
|
73
|
-
|
73
|
+
subject { instance.eql?(other) }
|
74
|
+
|
75
|
+
it { subject.must_equal(true) }
|
76
|
+
|
77
|
+
context 'when different to other' do
|
78
|
+
let(:other) { described.new(y: 1, yn: 25, x: 1, xn: 40) }
|
79
|
+
|
80
|
+
it { subject.must_equal(false) }
|
81
|
+
end
|
74
82
|
end
|
75
83
|
|
76
84
|
describe '#centre' do
|
77
85
|
subject { instance.centre }
|
78
86
|
|
79
87
|
it { subject.must_be_instance_of(Array) }
|
80
|
-
it { subject.must_equal([
|
88
|
+
it { subject.must_equal([7, 14]) }
|
81
89
|
end
|
82
90
|
|
83
91
|
describe '#centre_y' do
|
84
92
|
subject { instance.centre_y }
|
85
93
|
|
86
94
|
it { subject.must_be_instance_of(Fixnum) }
|
87
|
-
it { subject.must_equal(
|
95
|
+
it { subject.must_equal(7) }
|
88
96
|
end
|
89
97
|
|
90
98
|
describe '#centre_x' do
|
91
99
|
subject { instance.centre_x }
|
92
100
|
|
93
101
|
it { subject.must_be_instance_of(Fixnum) }
|
94
|
-
it { subject.must_equal(
|
102
|
+
it { subject.must_equal(14) }
|
103
|
+
end
|
104
|
+
|
105
|
+
describe '#north' do
|
106
|
+
subject { instance.north(offset) }
|
107
|
+
|
108
|
+
context 'with the default offset' do
|
109
|
+
it { subject.must_equal(3) }
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'with a negative offset' do
|
113
|
+
let(:offset) { -2 }
|
114
|
+
|
115
|
+
it { subject.must_equal(6) }
|
116
|
+
end
|
117
|
+
|
118
|
+
context 'with a positive offset' do
|
119
|
+
let(:offset) { 2 }
|
120
|
+
|
121
|
+
it { subject.must_equal(2) }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#east' do
|
126
|
+
subject { instance.east(offset) }
|
127
|
+
|
128
|
+
context 'with the default offset' do
|
129
|
+
it { subject.must_equal(22) }
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'with a negative offset' do
|
133
|
+
let(:offset) { -2 }
|
134
|
+
|
135
|
+
it { subject.must_equal(19) }
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'with a positive offset' do
|
139
|
+
let(:offset) { 2 }
|
140
|
+
|
141
|
+
it { subject.must_equal(23) }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#south' do
|
146
|
+
subject { instance.south(offset) }
|
147
|
+
|
148
|
+
context 'with the default offset' do
|
149
|
+
it { subject.must_equal(10) }
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'with a negative offset' do
|
153
|
+
let(:offset) { -2 }
|
154
|
+
|
155
|
+
it { subject.must_equal(7) }
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'with a positive offset' do
|
159
|
+
let(:offset) { 2 }
|
160
|
+
|
161
|
+
it { subject.must_equal(11) }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
describe '#west' do
|
166
|
+
subject { instance.west(offset) }
|
167
|
+
|
168
|
+
context 'with the default offset' do
|
169
|
+
it { subject.must_equal(5) }
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'with a negative offset' do
|
173
|
+
let(:offset) { -2 }
|
174
|
+
|
175
|
+
it { subject.must_equal(8) }
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'with a positive offset' do
|
179
|
+
let(:offset) { 2 }
|
180
|
+
|
181
|
+
it { subject.must_equal(4) }
|
182
|
+
end
|
95
183
|
end
|
96
184
|
|
97
185
|
end # Area
|
@@ -20,7 +20,7 @@ module Vedeu
|
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '#c' do
|
23
|
-
it { instance.c.must_equal([13,
|
23
|
+
it { instance.c.must_equal([13, 41]) }
|
24
24
|
it { instance.must_respond_to(:centre) }
|
25
25
|
end
|
26
26
|
|
@@ -30,7 +30,7 @@ module Vedeu
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe '#cx' do
|
33
|
-
it { instance.cx.must_equal(
|
33
|
+
it { instance.cx.must_equal(41) }
|
34
34
|
it { instance.must_respond_to(:centre_x) }
|
35
35
|
end
|
36
36
|
|
@@ -39,6 +39,14 @@ module Vedeu
|
|
39
39
|
it { instance.must_respond_to(:origin) }
|
40
40
|
end
|
41
41
|
|
42
|
+
describe '#height' do
|
43
|
+
it { instance.height.must_equal(25) }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#width' do
|
47
|
+
it { instance.width.must_equal(80) }
|
48
|
+
end
|
49
|
+
|
42
50
|
describe '#y' do
|
43
51
|
it { instance.y.must_equal(1) }
|
44
52
|
it { instance.must_respond_to(:top) }
|
@@ -11,13 +11,15 @@ module Vedeu
|
|
11
11
|
d: d,
|
12
12
|
dn: dn,
|
13
13
|
d_dn: d_dn,
|
14
|
-
default: default
|
14
|
+
default: default,
|
15
|
+
options: options,
|
15
16
|
}
|
16
17
|
}
|
17
18
|
let(:d) {}
|
18
19
|
let(:dn) {}
|
19
20
|
let(:d_dn) {}
|
20
21
|
let(:default) {}
|
22
|
+
let(:options) { {} }
|
21
23
|
|
22
24
|
describe '#initialize' do
|
23
25
|
it { instance.must_be_instance_of(Vedeu::Dimension) }
|
@@ -25,16 +27,39 @@ module Vedeu
|
|
25
27
|
it { instance.instance_variable_get('@dn').must_equal(dn) }
|
26
28
|
it { instance.instance_variable_get('@d_dn').must_equal(d_dn) }
|
27
29
|
it { instance.instance_variable_get('@default').must_equal(default) }
|
30
|
+
it { instance.instance_variable_get('@options').must_equal(options) }
|
28
31
|
end
|
29
32
|
|
30
33
|
describe '.pair' do
|
31
|
-
let(:d) {
|
32
|
-
let(:dn) {
|
34
|
+
let(:d) { 15 }
|
35
|
+
let(:dn) { 38 }
|
33
36
|
|
34
37
|
subject { described.pair(attributes) }
|
35
38
|
|
36
39
|
it { subject.must_be_instance_of(Array) }
|
37
|
-
it { subject.must_equal([
|
40
|
+
it { subject.must_equal([15, 38]) }
|
41
|
+
|
42
|
+
context 'when centred and a length can be determined' do
|
43
|
+
let(:options) { { centred: true } }
|
44
|
+
let(:default) { 80 }
|
45
|
+
|
46
|
+
context 'when d and dn are given' do
|
47
|
+
let(:d) { 7 }
|
48
|
+
let(:dn) { 47 }
|
49
|
+
|
50
|
+
it { subject.must_equal([20, 60]) }
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when only a d_dn is given' do
|
54
|
+
let(:d_dn) { 30 }
|
55
|
+
|
56
|
+
it { subject.must_equal([28, 52]) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when only a default is given' do
|
60
|
+
it { subject.must_equal([28, 52]) }
|
61
|
+
end
|
62
|
+
end
|
38
63
|
end
|
39
64
|
|
40
65
|
describe '#d1' do
|
@@ -42,55 +67,109 @@ module Vedeu
|
|
42
67
|
|
43
68
|
it { subject.must_be_instance_of(Fixnum) }
|
44
69
|
|
45
|
-
context 'when
|
46
|
-
|
70
|
+
context 'when not centred and/or a length cannot be determined' do
|
71
|
+
context 'when d is given' do
|
72
|
+
let(:d) { 5 }
|
47
73
|
|
48
|
-
|
74
|
+
it { subject.must_equal(5) }
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when d is not given' do
|
78
|
+
it { subject.must_equal(1) }
|
79
|
+
end
|
49
80
|
end
|
50
81
|
|
51
|
-
context 'when
|
52
|
-
|
82
|
+
context 'when centred and a length can be determined' do
|
83
|
+
let(:options) { { centred: true } }
|
84
|
+
let(:default) { 80 }
|
85
|
+
|
86
|
+
context 'when d and dn are given' do
|
87
|
+
let(:d) { 7 }
|
88
|
+
let(:dn) { 47 }
|
89
|
+
|
90
|
+
it { subject.must_equal(20) }
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when only a d_dn is given' do
|
94
|
+
let(:d_dn) { 30 }
|
95
|
+
|
96
|
+
it { subject.must_equal(25) }
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when only a default is given' do
|
100
|
+
it { subject.must_equal(1) }
|
101
|
+
end
|
53
102
|
end
|
54
103
|
end
|
55
104
|
|
56
105
|
describe '#d2' do
|
57
106
|
subject { instance.d2 }
|
58
107
|
|
59
|
-
context 'when
|
60
|
-
|
61
|
-
|
108
|
+
context 'when not centred and/or a length cannot be determined' do
|
109
|
+
context 'when d and dn are given' do
|
110
|
+
let(:d) { 5 }
|
111
|
+
let(:dn) { 8 }
|
62
112
|
|
63
|
-
|
64
|
-
|
113
|
+
it { subject.must_equal(8) }
|
114
|
+
end
|
65
115
|
|
66
|
-
|
67
|
-
|
68
|
-
|
116
|
+
context 'when d and d_dn are given' do
|
117
|
+
let(:d) { 5 }
|
118
|
+
let(:d_dn) { 2 }
|
69
119
|
|
70
|
-
|
71
|
-
|
120
|
+
it { subject.must_equal(7) }
|
121
|
+
end
|
72
122
|
|
73
|
-
|
74
|
-
|
123
|
+
context 'when only d_dn is given' do
|
124
|
+
let(:d_dn) { 6 }
|
75
125
|
|
76
|
-
|
77
|
-
|
126
|
+
it { subject.must_equal(6) }
|
127
|
+
end
|
78
128
|
|
79
|
-
|
80
|
-
|
81
|
-
let(:default) { 40 }
|
129
|
+
context 'when only dn is given' do
|
130
|
+
let(:dn) { 8 }
|
82
131
|
|
83
|
-
|
84
|
-
|
132
|
+
it { subject.must_equal(8) }
|
133
|
+
end
|
134
|
+
|
135
|
+
context 'when d and a default is given' do
|
136
|
+
let(:d) { 1 }
|
137
|
+
let(:default) { 40 }
|
138
|
+
|
139
|
+
it { subject.must_equal(40) }
|
140
|
+
end
|
85
141
|
|
86
|
-
|
87
|
-
|
142
|
+
context 'when only a default is given' do
|
143
|
+
let(:default) { 25 }
|
88
144
|
|
89
|
-
|
145
|
+
it { subject.must_equal(25) }
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when no default is given' do
|
149
|
+
it { subject.must_equal(nil) }
|
150
|
+
end
|
90
151
|
end
|
91
152
|
|
92
|
-
context 'when
|
93
|
-
|
153
|
+
context 'when centred and a length can be determined' do
|
154
|
+
let(:options) { { centred: true } }
|
155
|
+
let(:default) { 80 }
|
156
|
+
|
157
|
+
context 'when d and dn are given' do
|
158
|
+
let(:d) { 7 }
|
159
|
+
let(:dn) { 47 }
|
160
|
+
|
161
|
+
it { subject.must_equal(60) }
|
162
|
+
end
|
163
|
+
|
164
|
+
context 'when only a d_dn is given' do
|
165
|
+
let(:d_dn) { 30 }
|
166
|
+
|
167
|
+
it { subject.must_equal(55) }
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when only a default is given' do
|
171
|
+
it { subject.must_equal(80) }
|
172
|
+
end
|
94
173
|
end
|
95
174
|
end
|
96
175
|
|