vedeu 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/material_colours_app.rb +25 -0
- data/lib/vedeu/all.rb +0 -1
- data/lib/vedeu/colours/colour_translator.rb +6 -6
- data/lib/vedeu/cursor/cursor.rb +0 -12
- data/lib/vedeu/dsl.rb +23 -0
- data/lib/vedeu/dsl/border.rb +0 -10
- data/lib/vedeu/dsl/composition.rb +1 -19
- data/lib/vedeu/dsl/geometry.rb +0 -10
- data/lib/vedeu/dsl/group.rb +0 -10
- data/lib/vedeu/dsl/interface.rb +0 -20
- data/lib/vedeu/dsl/keymap.rb +0 -10
- data/lib/vedeu/dsl/line.rb +3 -21
- data/lib/vedeu/dsl/menu.rb +0 -10
- data/lib/vedeu/dsl/stream.rb +4 -10
- data/lib/vedeu/dsl/view.rb +0 -20
- data/lib/vedeu/geometry/geometry.rb +0 -13
- data/lib/vedeu/geometry/position.rb +11 -0
- data/lib/vedeu/models/escape.rb +0 -7
- data/lib/vedeu/models/interface.rb +4 -16
- data/lib/vedeu/models/views/all.rb +4 -5
- data/lib/vedeu/models/views/char.rb +21 -22
- data/lib/vedeu/models/views/{chars.rb → collections/chars.rb} +0 -0
- data/lib/vedeu/models/views/{lines.rb → collections/lines.rb} +0 -0
- data/lib/vedeu/models/views/{streams.rb → collections/streams.rb} +0 -0
- data/lib/vedeu/models/views/{view_collection.rb → collections/view_collection.rb} +0 -0
- data/lib/vedeu/models/views/composition.rb +17 -19
- data/lib/vedeu/models/views/line.rb +19 -31
- data/lib/vedeu/models/views/stream.rb +7 -20
- data/lib/vedeu/models/views/view.rb +22 -35
- data/lib/vedeu/output/html_char.rb +38 -28
- data/lib/vedeu/output/presentation/colour.rb +15 -44
- data/lib/vedeu/output/presentation/style.rb +7 -14
- data/lib/vedeu/output/viewport.rb +0 -3
- data/lib/vedeu/output/virtual_terminal.rb +2 -2
- data/lib/vedeu/repositories/repository.rb +0 -7
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/buffers/buffer_test.rb +4 -4
- data/test/lib/vedeu/colours/colour_translator_test.rb +14 -0
- data/test/lib/vedeu/cursor/cursor_test.rb +0 -9
- data/test/lib/vedeu/dsl/line_test.rb +15 -13
- data/test/lib/vedeu/geometry/geometry_test.rb +0 -13
- data/test/lib/vedeu/geometry/position_test.rb +18 -0
- data/test/lib/vedeu/models/escape_test.rb +0 -8
- data/test/lib/vedeu/models/interface_test.rb +0 -12
- data/test/lib/vedeu/models/views/char_test.rb +4 -23
- data/test/lib/vedeu/models/views/{chars_test.rb → collections/chars_test.rb} +0 -0
- data/test/lib/vedeu/models/views/{lines_test.rb → collections/lines_test.rb} +0 -0
- data/test/lib/vedeu/models/views/{streams_test.rb → collections/streams_test.rb} +0 -0
- data/test/lib/vedeu/models/views/collections/view_collection_test.rb +22 -0
- data/test/lib/vedeu/models/views/composition_test.rb +23 -17
- data/test/lib/vedeu/models/views/line_test.rb +13 -42
- data/test/lib/vedeu/models/views/stream_test.rb +4 -33
- data/test/lib/vedeu/output/html_char_test.rb +16 -39
- data/test/lib/vedeu/output/presentation/colour_test.rb +63 -60
- data/test/lib/vedeu/output/presentation/style_test.rb +30 -29
- data/test/lib/vedeu/output/presentation_test.rb +1 -1
- data/test/lib/vedeu/output/renderers/html_test.rb +4 -8
- data/test/lib/vedeu/output/renderers/json_test.rb +37 -3
- data/test/lib/vedeu/output/wordwrap_test.rb +4 -4
- data/test/lib/vedeu/repositories/repository_test.rb +0 -26
- data/test/lib/vedeu/templating/view_template_test.rb +8 -8
- metadata +13 -17
- data/lib/vedeu/geometry/position_index.rb +0 -68
- data/lib/vedeu/models/interface_collection.rb +0 -9
- data/test/lib/vedeu/geometry/position_index_test.rb +0 -82
- data/test/lib/vedeu/models/interface_collection_test.rb +0 -18
@@ -45,11 +45,19 @@ module Vedeu
|
|
45
45
|
def tag_style
|
46
46
|
return '' unless border || present?(value)
|
47
47
|
|
48
|
-
" style='"
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
out = " style='"
|
49
|
+
|
50
|
+
unless char.background.empty?
|
51
|
+
out << "border:1px #{char.background.to_html} solid;"
|
52
|
+
out << "background:#{char.background.to_html};"
|
53
|
+
end
|
54
|
+
|
55
|
+
unless char.foreground.empty?
|
56
|
+
out << "color:#{char.foreground.to_html};"
|
57
|
+
out << "#{border_style}"
|
58
|
+
end
|
59
|
+
|
60
|
+
out << "'"
|
53
61
|
end
|
54
62
|
|
55
63
|
# @return [String]
|
@@ -77,39 +85,41 @@ module Vedeu
|
|
77
85
|
|
78
86
|
# @return [String]
|
79
87
|
def css(direction = '')
|
80
|
-
"border-#{direction}:1px #{
|
88
|
+
"border-#{direction}:1px #{char.foreground.to_html} solid;"
|
81
89
|
end
|
82
90
|
|
83
|
-
# @return [String]
|
84
|
-
def fg
|
85
|
-
|
86
|
-
end
|
91
|
+
# # @return [String]
|
92
|
+
# def fg
|
93
|
+
# @fg ||= colour(char, 'foreground', '#222')
|
94
|
+
# end
|
87
95
|
|
88
|
-
# @return [String]
|
89
|
-
def bg
|
90
|
-
|
91
|
-
end
|
96
|
+
# # @return [String]
|
97
|
+
# def bg
|
98
|
+
# @bg ||= colour(char, 'background', '#000')
|
99
|
+
# end
|
92
100
|
|
93
101
|
# @param char [Vedeu::Views::Char]
|
94
|
-
# @param type [String]
|
95
|
-
# @param default [String]
|
102
|
+
# @param type [String] 'background' or 'foreground'
|
103
|
+
# @param default [String] A default colour (CSS style; e.g. '#b2adf2')
|
96
104
|
# @return [String]
|
97
|
-
def colour(char, type, default)
|
98
|
-
|
99
|
-
|
100
|
-
|
105
|
+
# def colour(char, type, default)
|
106
|
+
# parent_type = char.send(:parent).send(type).send(:to_html)
|
107
|
+
# #parent_type = ('parent_' + type).to_sym
|
108
|
+
# type_to_html = char.send(type).send(:to_html)
|
109
|
+
# #parent_type_to_html = char.send(parent_type).send(:to_html)
|
101
110
|
|
102
|
-
|
103
|
-
|
111
|
+
# if present?(type_to_html)
|
112
|
+
# type_to_html
|
104
113
|
|
105
|
-
|
106
|
-
|
114
|
+
# elsif char.parent
|
115
|
+
# parent_type
|
116
|
+
# #char.parent.send(type).send(:to_html)
|
107
117
|
|
108
|
-
|
109
|
-
|
118
|
+
# else
|
119
|
+
# default
|
110
120
|
|
111
|
-
|
112
|
-
end
|
121
|
+
# end
|
122
|
+
# end
|
113
123
|
|
114
124
|
# @return [Symbol|NilClass]
|
115
125
|
def border
|
@@ -14,8 +14,11 @@ module Vedeu
|
|
14
14
|
@background ||= if colour
|
15
15
|
colour.background
|
16
16
|
|
17
|
+
elsif parent
|
18
|
+
parent.background
|
19
|
+
|
17
20
|
else
|
18
|
-
|
21
|
+
Vedeu::Background.new
|
19
22
|
|
20
23
|
end
|
21
24
|
end
|
@@ -25,7 +28,7 @@ module Vedeu
|
|
25
28
|
#
|
26
29
|
# @return [Vedeu::Background]
|
27
30
|
def background=(value)
|
28
|
-
|
31
|
+
@colour = Vedeu::Colour.coerce(
|
29
32
|
background: Vedeu::Background.coerce(value),
|
30
33
|
foreground: colour.foreground)
|
31
34
|
end
|
@@ -35,8 +38,8 @@ module Vedeu
|
|
35
38
|
@colour ||= if attributes[:colour]
|
36
39
|
Vedeu::Colour.coerce(attributes[:colour])
|
37
40
|
|
38
|
-
elsif
|
39
|
-
Vedeu::Colour.coerce(
|
41
|
+
elsif parent
|
42
|
+
Vedeu::Colour.coerce(parent.colour)
|
40
43
|
|
41
44
|
else
|
42
45
|
Vedeu::Colour.new
|
@@ -49,7 +52,7 @@ module Vedeu
|
|
49
52
|
#
|
50
53
|
# @return [Vedeu::Colour]
|
51
54
|
def colour=(value)
|
52
|
-
@colour =
|
55
|
+
@colour = Vedeu::Colour.coerce(value)
|
53
56
|
end
|
54
57
|
|
55
58
|
# When the foreground colour for the model exists, return it, otherwise
|
@@ -60,8 +63,11 @@ module Vedeu
|
|
60
63
|
@foreground ||= if colour
|
61
64
|
colour.foreground
|
62
65
|
|
66
|
+
elsif parent
|
67
|
+
parent.foreground
|
68
|
+
|
63
69
|
else
|
64
|
-
|
70
|
+
Vedeu::Foreground.new
|
65
71
|
|
66
72
|
end
|
67
73
|
end
|
@@ -71,44 +77,9 @@ module Vedeu
|
|
71
77
|
#
|
72
78
|
# @return [Vedeu::Foreground]
|
73
79
|
def foreground=(value)
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
# When a parent colour is available, returns the parent background colour,
|
80
|
-
# otherwise an empty Vedeu::Background.
|
81
|
-
#
|
82
|
-
# @return [Vedeu::Background]
|
83
|
-
def parent_background
|
84
|
-
if parent_colour
|
85
|
-
parent_colour.background
|
86
|
-
|
87
|
-
else
|
88
|
-
Vedeu::Background.new
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Returns the parent colour when available or NilClass.
|
94
|
-
#
|
95
|
-
# @return [String|NilClass]
|
96
|
-
def parent_colour
|
97
|
-
parent.colour if parent
|
98
|
-
end
|
99
|
-
|
100
|
-
# When a parent colour is available, returns the parent foreground colour,
|
101
|
-
# otherwise an empty Vedeu::Foreground.
|
102
|
-
#
|
103
|
-
# @return [Vedeu::Foreground]
|
104
|
-
def parent_foreground
|
105
|
-
if parent_colour
|
106
|
-
parent_colour.foreground
|
107
|
-
|
108
|
-
else
|
109
|
-
Vedeu::Foreground.new
|
110
|
-
|
111
|
-
end
|
80
|
+
@colour = Vedeu::Colour.coerce(
|
81
|
+
background: colour.background,
|
82
|
+
foreground: Vedeu::Foreground.coerce(value))
|
112
83
|
end
|
113
84
|
|
114
85
|
end # Colour
|
@@ -6,26 +6,16 @@ module Vedeu
|
|
6
6
|
#
|
7
7
|
module Style
|
8
8
|
|
9
|
-
#
|
9
|
+
# When the style for the model exists, return it, otherwise returns the
|
10
|
+
# parent style, or an empty Vedeu::Style.
|
10
11
|
#
|
11
|
-
# @return [String|NilClass]
|
12
|
-
def parent_style
|
13
|
-
if parent
|
14
|
-
parent.style
|
15
|
-
|
16
|
-
else
|
17
|
-
Vedeu::Style.new
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
12
|
# @return [Vedeu::Style]
|
23
13
|
def style
|
24
14
|
@style ||= if attributes[:style]
|
25
15
|
Vedeu::Style.coerce(attributes[:style])
|
26
16
|
|
27
|
-
elsif
|
28
|
-
Vedeu::Style.coerce(
|
17
|
+
elsif parent
|
18
|
+
Vedeu::Style.coerce(parent.style)
|
29
19
|
|
30
20
|
else
|
31
21
|
Vedeu::Style.new
|
@@ -33,6 +23,9 @@ module Vedeu
|
|
33
23
|
end
|
34
24
|
end
|
35
25
|
|
26
|
+
# Allows the setting of the style by coercing the given value into a
|
27
|
+
# Vedeu::Style.
|
28
|
+
#
|
36
29
|
# @return [Vedeu::Style]
|
37
30
|
def style=(value)
|
38
31
|
@style = Vedeu::Style.coerce(value)
|
@@ -12,7 +12,6 @@ module Vedeu
|
|
12
12
|
|
13
13
|
def_delegators :view,
|
14
14
|
:lines,
|
15
|
-
:lines?,
|
16
15
|
:name,
|
17
16
|
:visible?
|
18
17
|
|
@@ -83,8 +82,6 @@ module Vedeu
|
|
83
82
|
#
|
84
83
|
# @return [Array]
|
85
84
|
def show
|
86
|
-
return [] unless lines?
|
87
|
-
|
88
85
|
(lines[rows] || []).map { |line| (line.chars[columns] || []) }
|
89
86
|
end
|
90
87
|
|
@@ -48,7 +48,7 @@ module Vedeu
|
|
48
48
|
# @param x [Fixnum] The column/character coordinate.
|
49
49
|
# @return [Vedeu::Views::Char]
|
50
50
|
def read(y, x)
|
51
|
-
cy, cx = Vedeu::
|
51
|
+
cy, cx = Vedeu::Position[y, x].as_indices
|
52
52
|
|
53
53
|
row = fetch(cells, cy)
|
54
54
|
cell = fetch(row, cx)
|
@@ -96,7 +96,7 @@ module Vedeu
|
|
96
96
|
def write(y, x, data)
|
97
97
|
return false unless read(y, x).is_a?(Vedeu::Cell)
|
98
98
|
|
99
|
-
cy, cx = Vedeu::
|
99
|
+
cy, cx = Vedeu::Position[y, x].as_indices
|
100
100
|
cells[cy][cx] = data
|
101
101
|
|
102
102
|
true
|
@@ -113,13 +113,6 @@ module Vedeu
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
|
116
|
-
# Override Ruby's Object#inspect method to provide a more helpful output.
|
117
|
-
#
|
118
|
-
# @return [String]
|
119
|
-
def inspect
|
120
|
-
"<#{self.class.name}: #{registered.inspect}>"
|
121
|
-
end
|
122
|
-
|
123
116
|
# Returns a boolean indicating whether the named model is registered.
|
124
117
|
#
|
125
118
|
# @param name [String]
|
data/lib/vedeu/version.rb
CHANGED
@@ -42,7 +42,7 @@ module Vedeu
|
|
42
42
|
end
|
43
43
|
|
44
44
|
describe '#add' do
|
45
|
-
let(:content) { Vedeu::Views::View.new(
|
45
|
+
let(:content) { Vedeu::Views::View.new(value: [Vedeu::Views::Line.new]) }
|
46
46
|
|
47
47
|
subject { instance.add(content) }
|
48
48
|
|
@@ -54,7 +54,7 @@ module Vedeu
|
|
54
54
|
|
55
55
|
context 'with content' do
|
56
56
|
let(:back) {
|
57
|
-
Vedeu::Views::View.new(
|
57
|
+
Vedeu::Views::View.new(value: [Vedeu::Views::Line.new])
|
58
58
|
}
|
59
59
|
|
60
60
|
it { subject.must_equal(true) }
|
@@ -70,7 +70,7 @@ module Vedeu
|
|
70
70
|
|
71
71
|
context 'with content' do
|
72
72
|
let(:front) {
|
73
|
-
Vedeu::Views::View.new(
|
73
|
+
Vedeu::Views::View.new(value: [Vedeu::Views::Line.new])
|
74
74
|
}
|
75
75
|
|
76
76
|
it { subject.must_equal(true) }
|
@@ -86,7 +86,7 @@ module Vedeu
|
|
86
86
|
|
87
87
|
context 'with content' do
|
88
88
|
let(:previous) {
|
89
|
-
Vedeu::Views::View.new(
|
89
|
+
Vedeu::Views::View.new(value: [Vedeu::Views::Line.new])
|
90
90
|
}
|
91
91
|
|
92
92
|
it { subject.must_equal(true) }
|
@@ -56,6 +56,20 @@ module Vedeu
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
describe '#empty?' do
|
60
|
+
subject { instance.empty? }
|
61
|
+
|
62
|
+
context 'when there is no colour' do
|
63
|
+
let(:colour) {}
|
64
|
+
|
65
|
+
it { subject.must_equal(true) }
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when there is a colour' do
|
69
|
+
it { subject.must_equal(false) }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
59
73
|
describe '#eql?' do
|
60
74
|
let(:other) { instance }
|
61
75
|
|
@@ -80,15 +80,6 @@ module Vedeu
|
|
80
80
|
it { subject.must_be_instance_of(Vedeu::Escape) }
|
81
81
|
end
|
82
82
|
|
83
|
-
describe '#inspect' do
|
84
|
-
subject { instance.inspect }
|
85
|
-
|
86
|
-
it { subject.must_be_instance_of(String) }
|
87
|
-
it { subject.must_equal(
|
88
|
-
'<Vedeu::Cursor (silver, true, x:19, y:8, ox:3, oy:2)>'
|
89
|
-
) }
|
90
|
-
end
|
91
|
-
|
92
83
|
describe '#position' do
|
93
84
|
subject { instance.position }
|
94
85
|
|
@@ -6,22 +6,24 @@ module Vedeu
|
|
6
6
|
|
7
7
|
describe Line do
|
8
8
|
|
9
|
-
let(:described)
|
10
|
-
let(:instance)
|
11
|
-
let(:model)
|
12
|
-
let(:
|
9
|
+
let(:described) { Vedeu::DSL::Line }
|
10
|
+
let(:instance) { described.new(model) }
|
11
|
+
let(:model) { Vedeu::Views::Line.new(attributes) }
|
12
|
+
let(:client) {}
|
13
|
+
let(:colour) { Vedeu::Colour.new }
|
14
|
+
let(:parent) { Vedeu::Views::View.new }
|
15
|
+
let(:style) { Vedeu::Style.new }
|
16
|
+
let(:_value) { [] }
|
17
|
+
let(:attributes) {
|
13
18
|
{
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
client: client,
|
20
|
+
value: _value,
|
21
|
+
parent: parent,
|
22
|
+
colour: colour,
|
23
|
+
style: style,
|
18
24
|
}
|
19
25
|
}
|
20
|
-
|
21
|
-
let(:streams) { [] }
|
22
|
-
let(:parent) { Vedeu::Views::View.new }
|
23
|
-
let(:colour) { Vedeu::Colour.new }
|
24
|
-
let(:style) { Vedeu::Style.new }
|
26
|
+
|
25
27
|
|
26
28
|
describe '#initialize' do
|
27
29
|
it { instance.must_be_instance_of(described) }
|
@@ -67,19 +67,6 @@ module Vedeu
|
|
67
67
|
it { instance.must_respond_to(:yn=) }
|
68
68
|
end
|
69
69
|
|
70
|
-
describe '#inspect' do
|
71
|
-
before { Terminal.stubs(:size).returns([12, 40]) }
|
72
|
-
|
73
|
-
subject { instance.inspect }
|
74
|
-
|
75
|
-
it { subject.must_be_instance_of(String) }
|
76
|
-
|
77
|
-
it { subject.must_equal(
|
78
|
-
'<Vedeu::Geometry x:1 xn:40 y:1 yn:12 centred:false maximise:false>'
|
79
|
-
)
|
80
|
-
}
|
81
|
-
end
|
82
|
-
|
83
70
|
describe '#maximise' do
|
84
71
|
let(:attributes) {
|
85
72
|
{
|
@@ -139,6 +139,24 @@ module Vedeu
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
+
describe '#as_indices' do
|
143
|
+
subject { instance.as_indices }
|
144
|
+
|
145
|
+
it { subject.must_equal([11, 18]) }
|
146
|
+
|
147
|
+
context 'when y is less than 1' do
|
148
|
+
let(:y) { -3 }
|
149
|
+
|
150
|
+
it { subject.must_equal([0, 18]) }
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'when x is less than 1' do
|
154
|
+
let(:x) { -9 }
|
155
|
+
|
156
|
+
it { subject.must_equal([11, 0]) }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
142
160
|
end # Position
|
143
161
|
|
144
162
|
end # Vedeu
|