vedeu 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vedeu/all.rb +2 -13
- data/lib/vedeu/api.rb +9 -9
- data/lib/vedeu/application/application_view.rb +3 -5
- data/lib/vedeu/bindings/bindings.rb +5 -1
- data/lib/vedeu/bindings/focus.rb +0 -5
- data/lib/vedeu/bindings/refresh.rb +0 -5
- data/lib/vedeu/bindings/system.rb +1 -6
- data/lib/vedeu/colours/all.rb +17 -0
- data/lib/vedeu/colours/background.rb +32 -28
- data/lib/vedeu/colours/backgrounds.rb +13 -9
- data/lib/vedeu/colours/colour.rb +106 -102
- data/lib/vedeu/colours/foreground.rb +32 -28
- data/lib/vedeu/colours/foregrounds.rb +13 -9
- data/lib/vedeu/colours/repository.rb +70 -0
- data/lib/vedeu/colours/translator.rb +267 -0
- data/lib/vedeu/configuration/api.rb +10 -7
- data/lib/vedeu/configuration/configuration.rb +2 -1
- data/lib/vedeu/dsl/border.rb +15 -2
- data/lib/vedeu/dsl/composition.rb +6 -4
- data/lib/vedeu/dsl/geometry.rb +14 -7
- data/lib/vedeu/dsl/group.rb +2 -2
- data/lib/vedeu/dsl/interface.rb +5 -3
- data/lib/vedeu/dsl/keymap.rb +9 -7
- data/lib/vedeu/dsl/line.rb +7 -4
- data/lib/vedeu/dsl/menu.rb +3 -0
- data/lib/vedeu/dsl/presentation.rb +20 -10
- data/lib/vedeu/dsl/shared.rb +4 -4
- data/lib/vedeu/dsl/stream.rb +2 -2
- data/lib/vedeu/dsl/text.rb +11 -5
- data/lib/vedeu/dsl/use.rb +2 -2
- data/lib/vedeu/dsl/view.rb +8 -6
- data/lib/vedeu/events/aliases.rb +91 -0
- data/lib/vedeu/events/all.rb +15 -0
- data/lib/vedeu/events/collection.rb +13 -0
- data/lib/vedeu/events/event.rb +244 -239
- data/lib/vedeu/events/repository.rb +30 -0
- data/lib/vedeu/events/trigger.rb +68 -64
- data/lib/vedeu/exceptions.rb +65 -54
- data/lib/vedeu/geometry/coordinate.rb +3 -1
- data/lib/vedeu/geometry/grid.rb +2 -4
- data/lib/vedeu/input/editor/all.rb +2 -1
- data/lib/vedeu/input/editor/{virtual_cursor.rb → cursor.rb} +10 -10
- data/lib/vedeu/input/editor/document.rb +7 -7
- data/lib/vedeu/input/editor/insert.rb +70 -0
- data/lib/vedeu/input/editor/line.rb +4 -16
- data/lib/vedeu/input/editor/lines.rb +2 -16
- data/lib/vedeu/input/input_translator.rb +2 -2
- data/lib/vedeu/input/key.rb +2 -2
- data/lib/vedeu/internal_api.rb +6 -6
- data/lib/vedeu/log/lockless_log_device.rb +0 -74
- data/lib/vedeu/models/focus.rb +3 -3
- data/lib/vedeu/models/interface.rb +3 -3
- data/lib/vedeu/models/menu.rb +2 -2
- data/lib/vedeu/models/views/char.rb +1 -1
- data/lib/vedeu/models/views/composition.rb +1 -1
- data/lib/vedeu/models/views/line.rb +1 -1
- data/lib/vedeu/models/views/stream.rb +1 -1
- data/lib/vedeu/models/views/view.rb +6 -7
- data/lib/vedeu/output/presentation/colour.rb +23 -21
- data/lib/vedeu/output/renderers/renderer_options.rb +2 -4
- data/lib/vedeu/output/text.rb +1 -1
- data/lib/vedeu/output/wordwrap.rb +18 -7
- data/lib/vedeu/plugins/plugin.rb +2 -2
- data/lib/vedeu/refresh/refresh_buffer.rb +3 -3
- data/lib/vedeu/refresh/refresh_group.rb +3 -3
- data/lib/vedeu/repositories/repository.rb +7 -6
- data/lib/vedeu/runtime/application.rb +1 -1
- data/lib/vedeu/runtime/main_loop.rb +3 -3
- data/lib/vedeu/runtime/router.rb +14 -11
- data/lib/vedeu/templating/helpers.rb +5 -5
- data/lib/vedeu/templating/template.rb +4 -4
- data/lib/vedeu/templating/view_template.rb +1 -1
- data/lib/vedeu/terminal/terminal.rb +2 -2
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/application/application_view_test.rb +1 -1
- data/test/lib/vedeu/colours/background_test.rb +93 -89
- data/test/lib/vedeu/colours/backgrounds_test.rb +11 -7
- data/test/lib/vedeu/colours/colour_test.rb +155 -151
- data/test/lib/vedeu/colours/foreground_test.rb +93 -89
- data/test/lib/vedeu/colours/foregrounds_test.rb +11 -7
- data/test/lib/vedeu/colours/repository_test.rb +97 -0
- data/test/lib/vedeu/colours/translator_test.rb +173 -0
- data/test/lib/vedeu/configuration/api_test.rb +4 -4
- data/test/lib/vedeu/dsl/border_test.rb +12 -0
- data/test/lib/vedeu/dsl/composition_test.rb +3 -3
- data/test/lib/vedeu/dsl/geometry_test.rb +11 -0
- data/test/lib/vedeu/dsl/group_test.rb +2 -2
- data/test/lib/vedeu/dsl/interface_test.rb +4 -4
- data/test/lib/vedeu/dsl/keymap_test.rb +8 -4
- data/test/lib/vedeu/dsl/line_test.rb +6 -3
- data/test/lib/vedeu/dsl/menu_test.rb +6 -0
- data/test/lib/vedeu/dsl/presentation_test.rb +16 -3
- data/test/lib/vedeu/dsl/stream_test.rb +1 -1
- data/test/lib/vedeu/dsl/text_test.rb +7 -0
- data/test/lib/vedeu/dsl/view_test.rb +3 -3
- data/test/lib/vedeu/events/aliases_test.rb +144 -0
- data/test/lib/vedeu/events/collection_test.rb +22 -0
- data/test/lib/vedeu/events/event_test.rb +84 -80
- data/test/lib/vedeu/events/repository_test.rb +28 -0
- data/test/lib/vedeu/events/trigger_test.rb +41 -37
- data/test/lib/vedeu/geometry/grid_test.rb +4 -4
- data/test/lib/vedeu/input/editor/{virtual_cursor_test.rb → cursor_test.rb} +3 -3
- data/test/lib/vedeu/input/editor/insert_test.rb +36 -0
- data/test/lib/vedeu/input/key_test.rb +1 -1
- data/test/lib/vedeu/models/cell_test.rb +1 -1
- data/test/lib/vedeu/models/focus_test.rb +4 -2
- data/test/lib/vedeu/models/menu_test.rb +1 -1
- data/test/lib/vedeu/models/views/char_test.rb +8 -4
- data/test/lib/vedeu/models/views/line_test.rb +4 -4
- data/test/lib/vedeu/models/views/stream_test.rb +3 -3
- data/test/lib/vedeu/models/views/view_test.rb +1 -1
- data/test/lib/vedeu/output/html_char_test.rb +4 -2
- data/test/lib/vedeu/output/presentation/colour_test.rb +5 -5
- data/test/lib/vedeu/output/presentation_test.rb +4 -4
- data/test/lib/vedeu/output/renderers/json_test.rb +4 -2
- data/test/lib/vedeu/plugins/plugin_test.rb +1 -1
- data/test/lib/vedeu/refresh/refresh_buffer_test.rb +1 -1
- data/test/lib/vedeu/refresh/refresh_group_test.rb +1 -1
- data/test/lib/vedeu/repositories/repository_test.rb +2 -2
- data/test/lib/vedeu/runtime/router_test.rb +6 -6
- data/test/lib/vedeu/templating/decoder_test.rb +2 -3
- data/test/lib/vedeu/templating/encoder_test.rb +2 -3
- data/test/lib/vedeu/templating/helpers_test.rb +6 -6
- data/test/lib/vedeu/templating/template_test.rb +2 -2
- data/test/lib/vedeu/templating/view_template_test.rb +13 -7
- data/test/lib/vedeu/terminal/terminal_test.rb +3 -3
- metadata +24 -19
- data/lib/vedeu/colours/colour_translator.rb +0 -260
- data/lib/vedeu/colours/colours.rb +0 -66
- data/lib/vedeu/events/event_aliases.rb +0 -87
- data/lib/vedeu/events/event_collection.rb +0 -9
- data/lib/vedeu/events/events.rb +0 -26
- data/test/lib/vedeu/colours/colour_translator_test.rb +0 -169
- data/test/lib/vedeu/colours/colours_test.rb +0 -93
- data/test/lib/vedeu/events/event_aliases_test.rb +0 -140
- data/test/lib/vedeu/events/event_collection_test.rb +0 -18
- data/test/lib/vedeu/events/events_test.rb +0 -24
@@ -2,16 +2,20 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
|
5
|
+
module Colours
|
6
6
|
|
7
|
-
|
7
|
+
describe Backgrounds do
|
8
8
|
|
9
|
-
|
10
|
-
subject { described.background_colours }
|
9
|
+
let(:described) { Vedeu::Colours::Backgrounds }
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
describe '.background_colours' do
|
12
|
+
subject { described.background_colours }
|
14
13
|
|
15
|
-
|
14
|
+
it { subject.must_be_instance_of(described) }
|
15
|
+
end
|
16
|
+
|
17
|
+
end # Backgrounds
|
18
|
+
|
19
|
+
end # Colours
|
16
20
|
|
17
21
|
end # Vedeu
|
@@ -2,37 +2,12 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
let(:described) { Vedeu::Colour }
|
8
|
-
let(:instance) { described.new(attributes) }
|
9
|
-
let(:attributes) {
|
10
|
-
{
|
11
|
-
background: background,
|
12
|
-
foreground: foreground,
|
13
|
-
}
|
14
|
-
}
|
15
|
-
let(:background) {}
|
16
|
-
let(:foreground) {}
|
17
|
-
|
18
|
-
describe '#initialize' do
|
19
|
-
it { instance.must_be_instance_of(described) }
|
20
|
-
it {
|
21
|
-
instance.instance_variable_get('@background').
|
22
|
-
must_be_instance_of(Vedeu::Background)
|
23
|
-
}
|
24
|
-
it {
|
25
|
-
instance.instance_variable_get('@foreground').
|
26
|
-
must_be_instance_of(Vedeu::Foreground)
|
27
|
-
}
|
28
|
-
end
|
5
|
+
module Colours
|
29
6
|
|
30
|
-
describe
|
31
|
-
it { instance.must_respond_to(:background) }
|
32
|
-
it { instance.must_respond_to(:foreground) }
|
33
|
-
end
|
7
|
+
describe Colour do
|
34
8
|
|
35
|
-
|
9
|
+
let(:described) { Vedeu::Colours::Colour }
|
10
|
+
let(:instance) { described.new(attributes) }
|
36
11
|
let(:attributes) {
|
37
12
|
{
|
38
13
|
background: background,
|
@@ -41,80 +16,146 @@ module Vedeu
|
|
41
16
|
}
|
42
17
|
let(:background) {}
|
43
18
|
let(:foreground) {}
|
44
|
-
let(:_value) {}
|
45
|
-
|
46
|
-
subject { described.coerce(_value) }
|
47
19
|
|
48
|
-
|
20
|
+
describe '#initialize' do
|
21
|
+
it { instance.must_be_instance_of(described) }
|
22
|
+
it {
|
23
|
+
instance.instance_variable_get('@background').
|
24
|
+
must_be_instance_of(Vedeu::Colours::Background)
|
25
|
+
}
|
26
|
+
it {
|
27
|
+
instance.instance_variable_get('@foreground').
|
28
|
+
must_be_instance_of(Vedeu::Colours::Foreground)
|
29
|
+
}
|
30
|
+
end
|
49
31
|
|
50
|
-
|
51
|
-
it {
|
52
|
-
it {
|
32
|
+
describe 'accessors' do
|
33
|
+
it { instance.must_respond_to(:background) }
|
34
|
+
it { instance.must_respond_to(:foreground) }
|
53
35
|
end
|
54
36
|
|
55
|
-
|
56
|
-
let(:
|
57
|
-
|
58
|
-
|
37
|
+
describe '.coerce' do
|
38
|
+
let(:attributes) {
|
39
|
+
{
|
40
|
+
background: background,
|
41
|
+
foreground: foreground,
|
42
|
+
}
|
43
|
+
}
|
44
|
+
let(:background) {}
|
45
|
+
let(:foreground) {}
|
46
|
+
let(:_value) {}
|
59
47
|
|
60
|
-
|
61
|
-
|
62
|
-
it { subject.
|
63
|
-
|
48
|
+
subject { described.coerce(_value) }
|
49
|
+
|
50
|
+
it { subject.must_be_instance_of(described) }
|
51
|
+
|
52
|
+
context 'when the value is nil' do
|
53
|
+
it { subject.foreground.colour.must_equal('') }
|
54
|
+
it { subject.background.colour.must_equal('') }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the value is a Vedeu::Colour' do
|
58
|
+
let(:background) { '#ff00ff' }
|
59
|
+
let(:foreground) { '#220022' }
|
60
|
+
let(:_value) { Vedeu::Colours::Colour.new(attributes) }
|
61
|
+
|
62
|
+
it { subject.foreground.colour.must_equal('#220022') }
|
63
|
+
it { subject.background.colour.must_equal('#ff00ff') }
|
64
|
+
it { subject.to_s.must_equal("\e[38;2;34;0;34m\e[48;2;255;0;255m") }
|
65
|
+
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
context 'when the value is a Hash' do
|
68
|
+
context 'when the hash has a :colour defined' do
|
69
|
+
context 'when the value of :colour is a Vedeu::Colours::Colour' do
|
70
|
+
let(:background) { '#002200' }
|
71
|
+
let(:foreground) { '#00ff00' }
|
72
|
+
let(:_value) {
|
73
|
+
{
|
74
|
+
colour: Vedeu::Colours::Colour.new(attributes),
|
75
|
+
}
|
73
76
|
}
|
74
|
-
}
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
78
|
+
it { subject.foreground.colour.must_equal('#00ff00') }
|
79
|
+
it { subject.background.colour.must_equal('#002200') }
|
80
|
+
it { subject.to_s.must_equal("\e[38;2;0;255;0m\e[48;2;0;34;0m") }
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'when the value of :colour is a Hash' do
|
84
|
+
context 'and a :background is defined' do
|
85
|
+
let(:_value) {
|
86
|
+
{
|
87
|
+
colour: {
|
88
|
+
background: '#7700ff'
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
it { subject.foreground.colour.must_equal('') }
|
94
|
+
it { subject.background.colour.must_equal('#7700ff') }
|
95
|
+
it {
|
96
|
+
subject.to_s.must_equal("\e[48;2;119;0;255m")
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'and a :foreground is defined' do
|
101
|
+
let(:_value) {
|
102
|
+
{
|
103
|
+
colour: {
|
104
|
+
foreground: '#220077'
|
105
|
+
}
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
it { subject.foreground.colour.must_equal('#220077') }
|
110
|
+
it { subject.background.colour.must_equal('') }
|
111
|
+
it {
|
112
|
+
subject.to_s.must_equal("\e[38;2;34;0;119m")
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'and neither a :background or :foreground is defined' do
|
117
|
+
let(:_value) {
|
118
|
+
{
|
119
|
+
colour: 'wrong'
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
it { subject.foreground.colour.must_equal('') }
|
124
|
+
it { subject.background.colour.must_equal('') }
|
125
|
+
it { subject.to_s.must_equal('') }
|
126
|
+
end
|
127
|
+
end
|
79
128
|
end
|
80
129
|
|
81
|
-
context 'when the
|
82
|
-
context '
|
130
|
+
context 'when the hash does not have a :colour defined' do
|
131
|
+
context 'when the hash has a :background defined' do
|
83
132
|
let(:_value) {
|
84
133
|
{
|
85
|
-
|
86
|
-
background: '#7700ff'
|
87
|
-
}
|
134
|
+
background: '#000022'
|
88
135
|
}
|
89
136
|
}
|
90
137
|
|
91
138
|
it { subject.foreground.colour.must_equal('') }
|
92
|
-
it { subject.background.colour.must_equal('#
|
93
|
-
it {
|
94
|
-
subject.to_s.must_equal("\e[48;2;119;0;255m")
|
95
|
-
}
|
139
|
+
it { subject.background.colour.must_equal('#000022') }
|
140
|
+
it { subject.to_s.must_equal("\e[48;2;0;0;34m") }
|
96
141
|
end
|
97
142
|
|
98
|
-
context '
|
143
|
+
context 'when the hash has a :foreground defined' do
|
99
144
|
let(:_value) {
|
100
145
|
{
|
101
|
-
|
102
|
-
foreground: '#220077'
|
103
|
-
}
|
146
|
+
foreground: '#aadd00'
|
104
147
|
}
|
105
148
|
}
|
106
149
|
|
107
|
-
it { subject.foreground.colour.must_equal('#
|
150
|
+
it { subject.foreground.colour.must_equal('#aadd00') }
|
108
151
|
it { subject.background.colour.must_equal('') }
|
109
|
-
it {
|
110
|
-
subject.to_s.must_equal("\e[38;2;34;0;119m")
|
111
|
-
}
|
152
|
+
it { subject.to_s.must_equal("\e[38;2;170;221;0m") }
|
112
153
|
end
|
113
154
|
|
114
|
-
context '
|
155
|
+
context 'when neither a :background or :foreground is defined' do
|
115
156
|
let(:_value) {
|
116
157
|
{
|
117
|
-
|
158
|
+
irrelevant: true
|
118
159
|
}
|
119
160
|
}
|
120
161
|
|
@@ -124,106 +165,69 @@ module Vedeu
|
|
124
165
|
end
|
125
166
|
end
|
126
167
|
end
|
168
|
+
end
|
127
169
|
|
128
|
-
|
129
|
-
|
130
|
-
let(:_value) {
|
131
|
-
{
|
132
|
-
background: '#000022'
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
it { subject.foreground.colour.must_equal('') }
|
137
|
-
it { subject.background.colour.must_equal('#000022') }
|
138
|
-
it { subject.to_s.must_equal("\e[48;2;0;0;34m") }
|
139
|
-
end
|
170
|
+
describe '#background=' do
|
171
|
+
let(:_value) { '#000000' }
|
140
172
|
|
141
|
-
|
142
|
-
let(:_value) {
|
143
|
-
{
|
144
|
-
foreground: '#aadd00'
|
145
|
-
}
|
146
|
-
}
|
173
|
+
subject { instance.background = (_value) }
|
147
174
|
|
148
|
-
|
149
|
-
it { subject.background.colour.must_equal('') }
|
150
|
-
it { subject.to_s.must_equal("\e[38;2;170;221;0m") }
|
151
|
-
end
|
152
|
-
|
153
|
-
context 'when neither a :background or :foreground is defined' do
|
154
|
-
let(:_value) {
|
155
|
-
{
|
156
|
-
irrelevant: true
|
157
|
-
}
|
158
|
-
}
|
159
|
-
|
160
|
-
it { subject.foreground.colour.must_equal('') }
|
161
|
-
it { subject.background.colour.must_equal('') }
|
162
|
-
it { subject.to_s.must_equal('') }
|
163
|
-
end
|
164
|
-
end
|
175
|
+
it { subject.must_equal(_value) }
|
165
176
|
end
|
166
|
-
end
|
167
177
|
|
168
|
-
|
169
|
-
|
178
|
+
describe '#eql?' do
|
179
|
+
let(:other) { instance }
|
170
180
|
|
171
|
-
|
181
|
+
subject { instance.eql?(other) }
|
172
182
|
|
173
|
-
|
174
|
-
end
|
183
|
+
it { subject.must_equal(true) }
|
175
184
|
|
176
|
-
|
177
|
-
|
185
|
+
context 'when different to other' do
|
186
|
+
let(:other) { described.new(background: '#ff0000') }
|
178
187
|
|
179
|
-
|
188
|
+
it { subject.must_equal(false) }
|
189
|
+
end
|
190
|
+
end
|
180
191
|
|
181
|
-
|
192
|
+
describe '#foreground=' do
|
193
|
+
let(:_value) { '#ff0000' }
|
182
194
|
|
183
|
-
|
184
|
-
let(:other) { described.new(background: '#ff0000') }
|
195
|
+
subject { instance.foreground = (_value) }
|
185
196
|
|
186
|
-
it { subject.must_equal(
|
197
|
+
it { subject.must_equal(_value) }
|
187
198
|
end
|
188
|
-
end
|
189
|
-
|
190
|
-
describe '#foreground=' do
|
191
|
-
let(:_value) { '#ff0000' }
|
192
|
-
|
193
|
-
subject { instance.foreground = (_value) }
|
194
199
|
|
195
|
-
|
196
|
-
|
200
|
+
describe '#to_s' do
|
201
|
+
subject { instance.to_s }
|
197
202
|
|
198
|
-
|
199
|
-
subject { instance.to_s }
|
203
|
+
it { subject.must_be_instance_of(String) }
|
200
204
|
|
201
|
-
|
205
|
+
context 'with both background and foreground' do
|
206
|
+
let(:background) { '#000000' }
|
207
|
+
let(:foreground) { '#ff0000' }
|
202
208
|
|
203
|
-
|
204
|
-
|
205
|
-
let(:foreground) { '#ff0000' }
|
209
|
+
it { subject.must_equal("\e[38;2;255;0;0m\e[48;2;0;0;0m") }
|
210
|
+
end
|
206
211
|
|
207
|
-
|
208
|
-
|
212
|
+
context 'when the foreground is missing' do
|
213
|
+
let(:background) { '#000000' }
|
209
214
|
|
210
|
-
|
211
|
-
|
215
|
+
it { subject.must_equal("\e[48;2;0;0;0m") }
|
216
|
+
end
|
212
217
|
|
213
|
-
|
214
|
-
|
218
|
+
context 'when the background is missing' do
|
219
|
+
let(:foreground) { '#ff0000' }
|
215
220
|
|
216
|
-
|
217
|
-
|
221
|
+
it { subject.must_equal("\e[38;2;255;0;0m") }
|
222
|
+
end
|
218
223
|
|
219
|
-
|
224
|
+
context 'when both are missing' do
|
225
|
+
it { subject.must_equal('') }
|
226
|
+
end
|
220
227
|
end
|
221
228
|
|
222
|
-
|
223
|
-
it { subject.must_equal('') }
|
224
|
-
end
|
225
|
-
end
|
229
|
+
end # Colour
|
226
230
|
|
227
|
-
end #
|
231
|
+
end # Colours
|
228
232
|
|
229
233
|
end # Vedeu
|
@@ -2,124 +2,128 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
|
5
|
-
|
5
|
+
module Colours
|
6
6
|
|
7
|
-
|
8
|
-
let(:instance) { described.new(colour) }
|
9
|
-
let(:colour) {}
|
7
|
+
describe Foreground do
|
10
8
|
|
11
|
-
|
9
|
+
let(:described) { Vedeu::Colours::Foreground }
|
10
|
+
let(:instance) { described.new(colour) }
|
11
|
+
let(:colour) {}
|
12
12
|
|
13
|
-
|
14
|
-
subject { instance.escape_sequence }
|
13
|
+
before { Vedeu.foreground_colours.reset! }
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
describe '#escape_sequence' do
|
16
|
+
subject { instance.escape_sequence }
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
context 'when the colour is empty' do
|
19
|
+
let(:colour) { '' }
|
20
|
+
|
21
|
+
it { subject.must_equal('') }
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
24
|
+
context 'when the colour is named (3-bit / 8 colours)' do
|
25
|
+
{
|
26
|
+
red: "\e[31m",
|
27
|
+
yellow: "\e[33m",
|
28
|
+
magenta: "\e[35m",
|
29
|
+
white: "\e[97m",
|
30
|
+
default: "\e[39m",
|
31
|
+
unknown: '',
|
32
|
+
}.map do |colour, result|
|
33
|
+
it "returns the correct escape sequence for #{colour}" do
|
34
|
+
described.new(colour).escape_sequence.must_equal(result)
|
35
|
+
end
|
33
36
|
end
|
34
37
|
end
|
35
|
-
end
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
context 'when the colour is numbered (8-bit / 256 colours)' do
|
40
|
+
{
|
41
|
+
24 => "\e[38;5;24m",
|
42
|
+
56 => "\e[38;5;56m",
|
43
|
+
82 => "\e[38;5;82m",
|
44
|
+
118 => "\e[38;5;118m",
|
45
|
+
143 => "\e[38;5;143m",
|
46
|
+
219 => "\e[38;5;219m",
|
47
|
+
-2 => '',
|
48
|
+
442 => ''
|
49
|
+
}.map do |colour, result|
|
50
|
+
it "returns the correct escape sequence for #{colour}" do
|
51
|
+
described.new(colour).escape_sequence.must_equal(result)
|
52
|
+
end
|
50
53
|
end
|
51
54
|
end
|
52
|
-
end
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
56
|
+
context 'when the colour is a CSS value (8-bit / 256 colours)' do
|
57
|
+
before { Configuration.stubs(:colour_mode).returns(8) }
|
58
|
+
|
59
|
+
{
|
60
|
+
'#5f0000' => "\e[38;5;52m",
|
61
|
+
'#008700' => "\e[38;5;28m",
|
62
|
+
'#0000d7' => "\e[38;5;20m",
|
63
|
+
'#afafaf' => "\e[38;5;145m",
|
64
|
+
'#afd700' => "\e[38;5;148m",
|
65
|
+
'#af005f' => "\e[38;5;125m",
|
66
|
+
'999999' => '',
|
67
|
+
'#12121' => '',
|
68
|
+
'#h11111' => '',
|
69
|
+
}.map do |colour, result|
|
70
|
+
it "returns the correct escape sequence for #{colour}" do
|
71
|
+
described.new(colour).escape_sequence.must_equal(result)
|
72
|
+
end
|
70
73
|
end
|
71
74
|
end
|
72
|
-
end
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
76
|
+
context 'when the colour is a CSS value (24-bit / 16.8mil colours)' do
|
77
|
+
{
|
78
|
+
'#5f0000' => "\e[38;2;95;0;0m",
|
79
|
+
'#008700' => "\e[38;2;0;135;0m",
|
80
|
+
'#0000d7' => "\e[38;2;0;0;215m",
|
81
|
+
'#afafaf' => "\e[38;2;175;175;175m",
|
82
|
+
'#afd700' => "\e[38;2;175;215;0m",
|
83
|
+
'#af005f' => "\e[38;2;175;0;95m",
|
84
|
+
'999999' => '',
|
85
|
+
'#12121' => '',
|
86
|
+
'#h11111' => '',
|
87
|
+
}.map do |colour, result|
|
88
|
+
it "returns the correct escape sequence for #{colour}" do
|
89
|
+
described.new(colour).escape_sequence.must_equal(result)
|
90
|
+
end
|
88
91
|
end
|
89
92
|
end
|
90
93
|
end
|
91
|
-
end
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
+
describe '.to_html' do
|
96
|
+
subject { instance.to_html }
|
95
97
|
|
96
|
-
|
97
|
-
|
98
|
+
context 'when the colour is empty' do
|
99
|
+
let(:colour) {}
|
98
100
|
|
99
|
-
|
100
|
-
|
101
|
+
it { subject.must_equal('') }
|
102
|
+
end
|
101
103
|
|
102
|
-
|
103
|
-
|
104
|
+
context 'when the colour is named (3-bit / 8 colours)' do
|
105
|
+
let(:colour) { :red }
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
+
it { subject.must_equal('') }
|
108
|
+
end
|
107
109
|
|
108
|
-
|
109
|
-
|
110
|
+
context 'when the colour is numbered (8-bit / 256 colours)' do
|
111
|
+
let(:colour) { 118 }
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
+
it { subject.must_equal('') }
|
114
|
+
end
|
113
115
|
|
114
|
-
|
115
|
-
|
116
|
+
context 'when the colour is a CSS value' do
|
117
|
+
let(:colour) { '#afd700' }
|
116
118
|
|
117
|
-
|
118
|
-
|
119
|
+
it 'returns the colour as a CSS value' do
|
120
|
+
subject.must_equal('#afd700')
|
121
|
+
end
|
119
122
|
end
|
120
123
|
end
|
121
|
-
end
|
122
124
|
|
123
|
-
|
125
|
+
end # Foreground
|
126
|
+
|
127
|
+
end # Colours
|
124
128
|
|
125
129
|
end # Vedeu
|