vedeu 0.6.1 → 0.6.2

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