rainbow 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/Changelog.md +6 -0
- data/Gemfile +6 -0
- data/README.markdown +166 -6
- data/lib/rainbow.rb +5 -4
- data/lib/rainbow/color.rb +34 -14
- data/lib/rainbow/global.rb +1 -1
- data/lib/rainbow/presenter.rb +13 -2
- data/lib/rainbow/string_utils.rb +4 -7
- data/lib/rainbow/version.rb +1 -1
- data/lib/rainbow/wrapper.rb +4 -4
- data/lib/rainbow/x11_color_names.rb +152 -0
- data/rainbow.gemspec +3 -5
- data/spec/integration/rainbow_spec.rb +18 -8
- data/spec/integration/string_spec.rb +4 -0
- data/spec/unit/color_spec.rb +63 -6
- data/spec/unit/wrapper_spec.rb +9 -3
- metadata +11 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e50d4d60cddebd63162aa542384109c229e019b4
|
4
|
+
data.tar.gz: 5240ea5388eb6b8df8715227cd2830dc9cba19db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4953dabd646d05ea36be2d0e4d4d8b4f1eb070a3bf0576413ab31335e8513302deb8399e8fc111de20948e049f8e3b17a8fd081bafca36455c5bc1721dec05b7
|
7
|
+
data.tar.gz: 7fdee7a80bd1ee2292e274d7e0694a79a03d6f7f99d004d79b21eb88e3f3e1d5d22f9bfb81f478cbbd5505c8c7b10ba95bcdb6aa952a9275c684930abde1ab42
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
data/Gemfile
CHANGED
@@ -3,8 +3,14 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies in rainbow.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
+
gem 'rake'
|
6
7
|
gem 'coveralls', require: false
|
7
8
|
gem 'mime-types', '< 2.0.0', platforms: [:ruby_18]
|
9
|
+
gem 'rspec', '3.0.0beta2'
|
10
|
+
|
11
|
+
group :development do
|
12
|
+
gem 'mutant-rspec'
|
13
|
+
end
|
8
14
|
|
9
15
|
group :guard do
|
10
16
|
gem 'guard'
|
data/README.markdown
CHANGED
@@ -22,7 +22,7 @@ To make your string colored wrap it with `Rainbow()` presenter and call
|
|
22
22
|
```ruby
|
23
23
|
require 'rainbow'
|
24
24
|
|
25
|
-
|
25
|
+
puts Rainbow("this is red").red + " and " + Rainbow("this on yellow bg").bg(:yellow) + " and " + Rainbow("even bright underlined!").underline.bright
|
26
26
|
|
27
27
|
# => "\e[31mthis is red\e[0m and \e[43mthis on yellow bg\e[0m and \e[4m\e[1meven bright underlined!\e[0m"
|
28
28
|
```
|
@@ -50,6 +50,10 @@ Text color can also be changed by calling a method named by a color:
|
|
50
50
|
* `magenta`
|
51
51
|
* `cyan`
|
52
52
|
* `white`
|
53
|
+
* `aqua`
|
54
|
+
* `silver`
|
55
|
+
* `aliceblue`
|
56
|
+
* `indianred`
|
53
57
|
|
54
58
|
All of the methods return `self` (the presenter object) so you can chain method
|
55
59
|
calls:
|
@@ -73,7 +77,7 @@ puts "this is red".color(:red) + " and " + "this on yellow bg".background(:yello
|
|
73
77
|
This way of using Rainbow is not recommended though as it pollutes String's
|
74
78
|
public interface with methods that are presentation specific.
|
75
79
|
|
76
|
-
NOTE: the
|
80
|
+
NOTE: the mixin doesn't include shortcut methods for changing text color, you
|
77
81
|
should use "string".color(:blue) instead of "string".blue
|
78
82
|
|
79
83
|
NOTE: the mixin is included in String by default in rainbow 1.x versions.
|
@@ -86,13 +90,16 @@ extension as shown above or update your code to use the new presenter API.
|
|
86
90
|
Both `color` and `background` accept color specified in any
|
87
91
|
of the following ways:
|
88
92
|
|
89
|
-
* color number (where 0 is black, 1 is red, 2 is green and so on):
|
93
|
+
* ANSI color number (where 0 is black, 1 is red, 2 is green and so on):
|
90
94
|
`Rainbow("hello").color(1)`
|
91
95
|
|
92
|
-
* color name
|
93
|
-
:magenta, :cyan, :white):
|
96
|
+
* [ANSI color](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) name or [X11 color](https://en.wikipedia.org/wiki/X11_color_names) name as a symbol:
|
94
97
|
`Rainbow("hello").color(:yellow)`.
|
95
|
-
This can be simplified to `Rainbow("hello").yellow`
|
98
|
+
This can be simplified to `Rainbow("hello").yellow`
|
99
|
+
|
100
|
+
See [Color list](#user-content-color-list) for all available color names.
|
101
|
+
Note that ANSI colors can be changed in accordance with terminal setting.
|
102
|
+
But X11 color is just a syntax sugar for RGB triplet. So you always see what you specified.
|
96
103
|
|
97
104
|
* RGB triplet as separate values in the range 0-255:
|
98
105
|
`Rainbow("hello").color(115, 23, 98)`
|
@@ -170,6 +177,159 @@ Or just install it via rubygems:
|
|
170
177
|
gem install rainbow
|
171
178
|
```
|
172
179
|
|
180
|
+
## Color list
|
181
|
+
|
182
|
+
### ANSI colors
|
183
|
+
|
184
|
+
* `black`
|
185
|
+
* `red`
|
186
|
+
* `green`
|
187
|
+
* `yellow`
|
188
|
+
* `blue`
|
189
|
+
* `magenta`
|
190
|
+
* `cyan`
|
191
|
+
* `white`
|
192
|
+
|
193
|
+
### X11 colors
|
194
|
+
|
195
|
+
* `aqua`
|
196
|
+
* `aquamarine`
|
197
|
+
* `mediumaquamarine`
|
198
|
+
* `azure`
|
199
|
+
* `beige`
|
200
|
+
* `bisque`
|
201
|
+
* `blanchedalmond`
|
202
|
+
* `darkblue`
|
203
|
+
* `lightblue`
|
204
|
+
* `mediumblue`
|
205
|
+
* `aliceblue`
|
206
|
+
* `cadetblue`
|
207
|
+
* `dodgerblue`
|
208
|
+
* `midnightblue`
|
209
|
+
* `navyblue`
|
210
|
+
* `powderblue`
|
211
|
+
* `royalblue`
|
212
|
+
* `skyblue`
|
213
|
+
* `deepskyblue`
|
214
|
+
* `lightskyblue`
|
215
|
+
* `slateblue`
|
216
|
+
* `darkslateblue`
|
217
|
+
* `mediumslateblue`
|
218
|
+
* `steelblue`
|
219
|
+
* `lightsteelblue`
|
220
|
+
* `brown`
|
221
|
+
* `rosybrown`
|
222
|
+
* `saddlebrown`
|
223
|
+
* `sandybrown`
|
224
|
+
* `burlywood`
|
225
|
+
* `chartreuse`
|
226
|
+
* `chocolate`
|
227
|
+
* `coral`
|
228
|
+
* `lightcoral`
|
229
|
+
* `cornflower`
|
230
|
+
* `cornsilk`
|
231
|
+
* `crimson`
|
232
|
+
* `darkcyan`
|
233
|
+
* `lightcyan`
|
234
|
+
* `firebrick`
|
235
|
+
* `fuchsia`
|
236
|
+
* `gainsboro`
|
237
|
+
* `gold`
|
238
|
+
* `goldenrod`
|
239
|
+
* `darkgoldenrod`
|
240
|
+
* `lightgoldenrod`
|
241
|
+
* `palegoldenrod`
|
242
|
+
* `gray`
|
243
|
+
* `darkgray`
|
244
|
+
* `dimgray`
|
245
|
+
* `lightgray`
|
246
|
+
* `slategray`
|
247
|
+
* `lightslategray`
|
248
|
+
* `webgray`
|
249
|
+
* `darkgreen`
|
250
|
+
* `lightgreen`
|
251
|
+
* `palegreen`
|
252
|
+
* `darkolivegreen`
|
253
|
+
* `yellowgreen`
|
254
|
+
* `forestgreen`
|
255
|
+
* `lawngreen`
|
256
|
+
* `limegreen`
|
257
|
+
* `seagreen`
|
258
|
+
* `darkseagreen`
|
259
|
+
* `lightseagreen`
|
260
|
+
* `mediumseagreen`
|
261
|
+
* `springgreen`
|
262
|
+
* `mediumspringgreen`
|
263
|
+
* `webgreen`
|
264
|
+
* `honeydew`
|
265
|
+
* `indianred`
|
266
|
+
* `indigo`
|
267
|
+
* `ivory`
|
268
|
+
* `khaki`
|
269
|
+
* `darkkhaki`
|
270
|
+
* `lavender`
|
271
|
+
* `lavenderblush`
|
272
|
+
* `lemonchiffon`
|
273
|
+
* `lime`
|
274
|
+
* `linen`
|
275
|
+
* `darkmagenta`
|
276
|
+
* `maroon`
|
277
|
+
* `webmaroon`
|
278
|
+
* `mintcream`
|
279
|
+
* `mistyrose`
|
280
|
+
* `moccasin`
|
281
|
+
* `oldlace`
|
282
|
+
* `olive`
|
283
|
+
* `olivedrab`
|
284
|
+
* `orange`
|
285
|
+
* `darkorange`
|
286
|
+
* `orchid`
|
287
|
+
* `darkorchid`
|
288
|
+
* `mediumorchid`
|
289
|
+
* `papayawhip`
|
290
|
+
* `peachpuff`
|
291
|
+
* `peru`
|
292
|
+
* `pink`
|
293
|
+
* `deeppink`
|
294
|
+
* `lightpink`
|
295
|
+
* `hotpink`
|
296
|
+
* `plum`
|
297
|
+
* `purple`
|
298
|
+
* `mediumpurple`
|
299
|
+
* `rebeccapurple`
|
300
|
+
* `webpurple`
|
301
|
+
* `darkred`
|
302
|
+
* `orangered`
|
303
|
+
* `mediumvioletred`
|
304
|
+
* `palevioletred`
|
305
|
+
* `salmon`
|
306
|
+
* `darksalmon`
|
307
|
+
* `lightsalmon`
|
308
|
+
* `seashell`
|
309
|
+
* `sienna`
|
310
|
+
* `silver`
|
311
|
+
* `darkslategray`
|
312
|
+
* `snow`
|
313
|
+
* `tan`
|
314
|
+
* `teal`
|
315
|
+
* `thistle`
|
316
|
+
* `tomato`
|
317
|
+
* `turquoise`
|
318
|
+
* `darkturquoise`
|
319
|
+
* `mediumturquoise`
|
320
|
+
* `paleturquoise`
|
321
|
+
* `violet`
|
322
|
+
* `darkviolet`
|
323
|
+
* `blueviolet`
|
324
|
+
* `wheat`
|
325
|
+
* `antiquewhite`
|
326
|
+
* `floralwhite`
|
327
|
+
* `ghostwhite`
|
328
|
+
* `navajowhite`
|
329
|
+
* `whitesmoke`
|
330
|
+
* `lightyellow`
|
331
|
+
* `greenyellow`
|
332
|
+
|
173
333
|
## Authors
|
174
334
|
|
175
335
|
[Marcin Kulik](http://ku1ik.com/) and [great open-source contributors](https://github.com/sickill/rainbow/graphs/contributors).
|
data/lib/rainbow.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'rainbow/global'
|
2
|
+
require_relative 'rainbow/legacy'
|
3
3
|
|
4
4
|
module Rainbow
|
5
5
|
|
@@ -11,9 +11,10 @@ module Rainbow
|
|
11
11
|
self.enabled = false if ENV['TERM'] == 'dumb'
|
12
12
|
self.enabled = true if ENV['CLICOLOR_FORCE'] == '1'
|
13
13
|
|
14
|
-
# On Windows systems, try to load the local ANSI support library
|
14
|
+
# On Windows systems, try to load the local ANSI support library if Ruby version < 2
|
15
|
+
# Ruby 2.x on Windows includes ANSI support.
|
15
16
|
require 'rbconfig'
|
16
|
-
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
|
17
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ && RUBY_VERSION.to_i < 2
|
17
18
|
begin
|
18
19
|
require 'Win32/Console/ANSI'
|
19
20
|
rescue LoadError
|
data/lib/rainbow/color.rb
CHANGED
@@ -12,19 +12,23 @@ module Rainbow
|
|
12
12
|
color = values.size == 1 ? values.first : values
|
13
13
|
|
14
14
|
case color
|
15
|
-
when
|
15
|
+
when Fixnum
|
16
16
|
Indexed.new(ground, color)
|
17
|
-
when
|
18
|
-
Named.
|
19
|
-
|
17
|
+
when Symbol
|
18
|
+
if Named.color_names.include?(color)
|
19
|
+
Named.new(ground, color)
|
20
|
+
else X11Named.color_names.include?(color)
|
21
|
+
X11Named.new(ground, color)
|
22
|
+
end
|
23
|
+
when Array
|
20
24
|
RGB.new(ground, *color)
|
21
|
-
when
|
25
|
+
when String
|
22
26
|
RGB.new(ground, *parse_hex_color(color))
|
23
27
|
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def self.parse_hex_color(hex)
|
27
|
-
hex = hex.
|
31
|
+
hex = hex.sub(/^#/, '')
|
28
32
|
r = hex[0..1].to_i(16)
|
29
33
|
g = hex[2..3].to_i(16)
|
30
34
|
b = hex[4..5].to_i(16)
|
@@ -63,21 +67,19 @@ module Rainbow
|
|
63
67
|
default: 9,
|
64
68
|
}
|
65
69
|
|
70
|
+
def self.color_names
|
71
|
+
NAMES.keys
|
72
|
+
end
|
73
|
+
|
66
74
|
def initialize(ground, name)
|
67
|
-
unless color_names.include?(name)
|
75
|
+
unless Named.color_names.include?(name)
|
68
76
|
fail ArgumentError,
|
69
|
-
"Unknown color name, valid names: #{color_names.join(', ')}"
|
77
|
+
"Unknown color name, valid names: #{Named.color_names.join(', ')}"
|
70
78
|
end
|
71
79
|
|
72
80
|
super(ground, NAMES[name])
|
73
81
|
end
|
74
82
|
|
75
|
-
private
|
76
|
-
|
77
|
-
def color_names
|
78
|
-
NAMES.keys
|
79
|
-
end
|
80
|
-
|
81
83
|
end
|
82
84
|
|
83
85
|
class RGB < Indexed
|
@@ -111,5 +113,23 @@ module Rainbow
|
|
111
113
|
|
112
114
|
end
|
113
115
|
|
116
|
+
class X11Named < RGB
|
117
|
+
include X11ColorNames
|
118
|
+
|
119
|
+
def self.color_names
|
120
|
+
NAMES.keys
|
121
|
+
end
|
122
|
+
|
123
|
+
def initialize(ground, name)
|
124
|
+
unless X11Named.color_names.include?(name)
|
125
|
+
fail ArgumentError,
|
126
|
+
"Unknown color name, valid names: #{X11Named.color_names.join(', ')}"
|
127
|
+
end
|
128
|
+
|
129
|
+
super(ground, *NAMES[name])
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
114
134
|
end
|
115
135
|
end
|
data/lib/rainbow/global.rb
CHANGED
data/lib/rainbow/presenter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'string_utils'
|
2
|
+
require_relative 'x11_color_names'
|
3
|
+
require_relative 'color'
|
3
4
|
|
4
5
|
module Rainbow
|
5
6
|
|
@@ -102,6 +103,16 @@ module Rainbow
|
|
102
103
|
color(:white)
|
103
104
|
end
|
104
105
|
|
106
|
+
# We take care of X11 color method call here.
|
107
|
+
# Such as #aqua, #ghostwhite.
|
108
|
+
def method_missing(method_name,*args)
|
109
|
+
if Color::X11Named.color_names.include? method_name and args.empty? then
|
110
|
+
color(method_name)
|
111
|
+
else
|
112
|
+
super
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
105
116
|
private
|
106
117
|
|
107
118
|
def wrap_with_sgr(codes) #:nodoc:
|
data/lib/rainbow/string_utils.rb
CHANGED
@@ -6,16 +6,13 @@ module Rainbow
|
|
6
6
|
|
7
7
|
seq = "\e[" + codes.join(";") + "m"
|
8
8
|
match = string.match(/^(\e\[([\d;]+)m)*/)
|
9
|
+
seq_pos = match.end(0)
|
10
|
+
string = string[0...seq_pos] + seq + string[seq_pos..-1]
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
string = string[0...seq_pos] + seq + string[seq_pos..-1]
|
13
|
-
else
|
14
|
-
string = seq + string
|
12
|
+
unless string =~ /\e\[0m$/
|
13
|
+
string = string + "\e[0m"
|
15
14
|
end
|
16
15
|
|
17
|
-
string = string + "\e[0m" unless string =~ /\e\[0m$/
|
18
|
-
|
19
16
|
string
|
20
17
|
end
|
21
18
|
|
data/lib/rainbow/version.rb
CHANGED
data/lib/rainbow/wrapper.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'presenter'
|
2
|
+
require_relative 'null_presenter'
|
3
3
|
|
4
4
|
module Rainbow
|
5
5
|
|
@@ -12,9 +12,9 @@ module Rainbow
|
|
12
12
|
|
13
13
|
def wrap(string)
|
14
14
|
if enabled
|
15
|
-
|
15
|
+
Presenter.new(string.to_s)
|
16
16
|
else
|
17
|
-
|
17
|
+
NullPresenter.new(string.to_s)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
module Rainbow
|
2
|
+
|
3
|
+
module X11ColorNames
|
4
|
+
NAMES= {
|
5
|
+
aqua: [0, 255, 255],
|
6
|
+
aquamarine: [127, 255, 212],
|
7
|
+
mediumaquamarine: [102, 205, 170],
|
8
|
+
azure: [240, 255, 255],
|
9
|
+
beige: [245, 245, 220],
|
10
|
+
bisque: [255, 228, 196],
|
11
|
+
black: [0, 0, 0],
|
12
|
+
blanchedalmond: [255, 235, 205],
|
13
|
+
blue: [0, 0, 255],
|
14
|
+
darkblue: [0, 0, 139],
|
15
|
+
lightblue: [173, 216, 230],
|
16
|
+
mediumblue: [0, 0, 205],
|
17
|
+
aliceblue: [240, 248, 255],
|
18
|
+
cadetblue: [95, 158, 160],
|
19
|
+
dodgerblue: [30, 144, 255],
|
20
|
+
midnightblue: [25, 25, 112],
|
21
|
+
navyblue: [0, 0, 128],
|
22
|
+
powderblue: [176, 224, 230],
|
23
|
+
royalblue: [65, 105, 225],
|
24
|
+
skyblue: [135, 206, 235],
|
25
|
+
deepskyblue: [0, 191, 255],
|
26
|
+
lightskyblue: [135, 206, 250],
|
27
|
+
slateblue: [106, 90, 205],
|
28
|
+
darkslateblue: [72, 61, 139],
|
29
|
+
mediumslateblue: [123, 104, 238],
|
30
|
+
steelblue: [70, 130, 180],
|
31
|
+
lightsteelblue: [176, 196, 222],
|
32
|
+
brown: [165, 42, 42],
|
33
|
+
rosybrown: [188, 143, 143],
|
34
|
+
saddlebrown: [139, 69, 19],
|
35
|
+
sandybrown: [244, 164, 96],
|
36
|
+
burlywood: [222, 184, 135],
|
37
|
+
chartreuse: [127, 255, 0],
|
38
|
+
chocolate: [210, 105, 30],
|
39
|
+
coral: [255, 127, 80],
|
40
|
+
lightcoral: [240, 128, 128],
|
41
|
+
cornflower: [100, 149, 237],
|
42
|
+
cornsilk: [255, 248, 220],
|
43
|
+
crimson: [220, 20, 60],
|
44
|
+
cyan: [0, 255, 255],
|
45
|
+
darkcyan: [0, 139, 139],
|
46
|
+
lightcyan: [224, 255, 255],
|
47
|
+
firebrick: [178, 34, 34],
|
48
|
+
fuchsia: [255, 0, 255],
|
49
|
+
gainsboro: [220, 220, 220],
|
50
|
+
gold: [255, 215, 0],
|
51
|
+
goldenrod: [218, 165, 32],
|
52
|
+
darkgoldenrod: [184, 134, 11],
|
53
|
+
lightgoldenrod: [250, 250, 210],
|
54
|
+
palegoldenrod: [238, 232, 170],
|
55
|
+
gray: [190, 190, 190],
|
56
|
+
darkgray: [169, 169, 169],
|
57
|
+
dimgray: [105, 105, 105],
|
58
|
+
lightgray: [211, 211, 211],
|
59
|
+
slategray: [112, 128, 144],
|
60
|
+
lightslategray: [119, 136, 153],
|
61
|
+
webgray: [128, 128, 128],
|
62
|
+
green: [0, 255, 0],
|
63
|
+
darkgreen: [0, 100, 0],
|
64
|
+
lightgreen: [144, 238, 144],
|
65
|
+
palegreen: [152, 251, 152],
|
66
|
+
darkolivegreen: [85, 107, 47],
|
67
|
+
yellowgreen: [154, 205, 50],
|
68
|
+
forestgreen: [34, 139, 34],
|
69
|
+
lawngreen: [124, 252, 0],
|
70
|
+
limegreen: [50, 205, 50],
|
71
|
+
seagreen: [46, 139, 87],
|
72
|
+
darkseagreen: [143, 188, 143],
|
73
|
+
lightseagreen: [32, 178, 170],
|
74
|
+
mediumseagreen: [60, 179, 113],
|
75
|
+
springgreen: [0, 255, 127],
|
76
|
+
mediumspringgreen: [0, 250, 154],
|
77
|
+
webgreen: [0, 128, 0],
|
78
|
+
honeydew: [240, 255, 240],
|
79
|
+
indianred: [205, 92, 92],
|
80
|
+
indigo: [75, 0, 130],
|
81
|
+
ivory: [255, 255, 240],
|
82
|
+
khaki: [240, 230, 140],
|
83
|
+
darkkhaki: [189, 183, 107],
|
84
|
+
lavender: [230, 230, 250],
|
85
|
+
lavenderblush: [255, 240, 245],
|
86
|
+
lemonchiffon: [255, 250, 205],
|
87
|
+
lime: [0, 255, 0],
|
88
|
+
linen: [250, 240, 230],
|
89
|
+
magenta: [255, 0, 255],
|
90
|
+
darkmagenta: [139, 0, 139],
|
91
|
+
maroon: [176, 48, 96],
|
92
|
+
webmaroon: [127, 0, 0],
|
93
|
+
mintcream: [245, 255, 250],
|
94
|
+
mistyrose: [255, 228, 225],
|
95
|
+
moccasin: [255, 228, 181],
|
96
|
+
oldlace: [253, 245, 230],
|
97
|
+
olive: [128, 128, 0],
|
98
|
+
olivedrab: [107, 142, 35],
|
99
|
+
orange: [255, 165, 0],
|
100
|
+
darkorange: [255, 140, 0],
|
101
|
+
orchid: [218, 112, 214],
|
102
|
+
darkorchid: [153, 50, 204],
|
103
|
+
mediumorchid: [186, 85, 211],
|
104
|
+
papayawhip: [255, 239, 213],
|
105
|
+
peachpuff: [255, 218, 185],
|
106
|
+
peru: [205, 133, 63],
|
107
|
+
pink: [255, 192, 203],
|
108
|
+
deeppink: [255, 20, 147],
|
109
|
+
lightpink: [255, 182, 193],
|
110
|
+
hotpink: [255, 105, 180],
|
111
|
+
plum: [221, 160, 221],
|
112
|
+
purple: [160, 32, 240],
|
113
|
+
mediumpurple: [147, 112, 219],
|
114
|
+
rebeccapurple: [102, 51, 153],
|
115
|
+
webpurple: [127, 0, 127],
|
116
|
+
red: [255, 0, 0],
|
117
|
+
darkred: [139, 0, 0],
|
118
|
+
orangered: [255, 69, 0],
|
119
|
+
mediumvioletred: [199, 21, 133],
|
120
|
+
palevioletred: [219, 112, 147],
|
121
|
+
salmon: [250, 128, 114],
|
122
|
+
darksalmon: [233, 150, 122],
|
123
|
+
lightsalmon: [255, 160, 122],
|
124
|
+
seashell: [255, 245, 238],
|
125
|
+
sienna: [160, 82, 45],
|
126
|
+
silver: [192, 192, 192],
|
127
|
+
darkslategray: [47, 79, 79],
|
128
|
+
snow: [255, 250, 250],
|
129
|
+
tan: [210, 180, 140],
|
130
|
+
teal: [0, 128, 128],
|
131
|
+
thistle: [216, 191, 216],
|
132
|
+
tomato: [255, 99, 71],
|
133
|
+
turquoise: [64, 224, 208],
|
134
|
+
darkturquoise: [0, 206, 209],
|
135
|
+
mediumturquoise: [72, 209, 204],
|
136
|
+
paleturquoise: [175, 238, 238],
|
137
|
+
violet: [238, 130, 238],
|
138
|
+
darkviolet: [148, 0, 211],
|
139
|
+
blueviolet: [138, 43, 226],
|
140
|
+
wheat: [245, 222, 179],
|
141
|
+
white: [255, 255, 255],
|
142
|
+
antiquewhite: [250, 235, 215],
|
143
|
+
floralwhite: [255, 250, 240],
|
144
|
+
ghostwhite: [248, 248, 255],
|
145
|
+
navajowhite: [255, 222, 173],
|
146
|
+
whitesmoke: [245, 245, 245],
|
147
|
+
yellow: [255, 255, 0],
|
148
|
+
lightyellow: [255, 255, 224],
|
149
|
+
greenyellow: [173, 255, 47]
|
150
|
+
}
|
151
|
+
end
|
152
|
+
end
|
data/rainbow.gemspec
CHANGED
@@ -8,18 +8,16 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Rainbow::VERSION
|
9
9
|
spec.authors = ["Marcin Kulik"]
|
10
10
|
spec.email = ["m@ku1ik.com"]
|
11
|
-
spec.description = %q
|
12
|
-
spec.summary = %q
|
11
|
+
spec.description = %q(Colorize printed text on ANSI terminals)
|
12
|
+
spec.summary = %q(Colorize printed text on ANSI terminals)
|
13
13
|
spec.homepage = "https://github.com/sickill/rainbow"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = '>= 1.9.2'
|
16
16
|
|
17
|
-
spec.files = `git ls-files`.split(
|
17
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
-
spec.add_development_dependency "rake"
|
24
|
-
spec.add_development_dependency "rspec"
|
25
23
|
end
|
@@ -17,12 +17,17 @@ describe 'Rainbow() wrapper' do
|
|
17
17
|
expect(result).to eq("\e[31mhello\e[0m")
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'allows foreground coloring directly by method name' do
|
20
|
+
it 'allows foreground coloring directly by ANSI method name' do
|
21
21
|
result = Rainbow('hello').red
|
22
22
|
expect(result).to eq("\e[31mhello\e[0m")
|
23
23
|
end
|
24
24
|
|
25
|
-
it 'allows foreground coloring by
|
25
|
+
it 'allows foreground coloring directly by X11 method name' do
|
26
|
+
result = Rainbow('hello').midnightblue
|
27
|
+
expect(result).to eq("\e[38;5;18mhello\e[0m")
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'allows foreground coloring by ANSI color name (color alias)' do
|
26
31
|
result = Rainbow('hello').color(:red)
|
27
32
|
expect(result).to eq("\e[31mhello\e[0m")
|
28
33
|
end
|
@@ -32,6 +37,11 @@ describe 'Rainbow() wrapper' do
|
|
32
37
|
expect(result).to eq("\e[31mhello\e[0m")
|
33
38
|
end
|
34
39
|
|
40
|
+
it 'allows foreground coloring by X11 color name' do
|
41
|
+
result = Rainbow('hello').foreground(:midnightblue)
|
42
|
+
expect(result).to eq("\e[38;5;18mhello\e[0m")
|
43
|
+
end
|
44
|
+
|
35
45
|
it 'allows foreground coloring by color rgb' do
|
36
46
|
result = Rainbow('hello').foreground(255, 128, 64)
|
37
47
|
expect(result).to eq("\e[38;5;215mhello\e[0m")
|
@@ -47,18 +57,18 @@ describe 'Rainbow() wrapper' do
|
|
47
57
|
expect(result).to eq("\e[43mhello\e[0m")
|
48
58
|
end
|
49
59
|
|
50
|
-
it 'allows background coloring by color name' do
|
60
|
+
it 'allows background coloring by ANSI color name' do
|
51
61
|
result = Rainbow('hello').background(:green)
|
52
62
|
expect(result).to eq("\e[42mhello\e[0m")
|
53
63
|
end
|
54
64
|
|
55
|
-
it 'allows background coloring by color
|
56
|
-
result = Rainbow('hello').background(
|
57
|
-
expect(result).to eq("\e[48;5;
|
65
|
+
it 'allows background coloring by X11 color name' do
|
66
|
+
result = Rainbow('hello').background(:midnightblue)
|
67
|
+
expect(result).to eq("\e[48;5;18mhello\e[0m")
|
58
68
|
end
|
59
69
|
|
60
|
-
it 'allows background coloring by color rgb
|
61
|
-
result = Rainbow('hello').background(
|
70
|
+
it 'allows background coloring by color rgb' do
|
71
|
+
result = Rainbow('hello').background(255, 128, 64)
|
62
72
|
expect(result).to eq("\e[48;5;215mhello\e[0m")
|
63
73
|
end
|
64
74
|
|
@@ -15,6 +15,10 @@ describe 'String mixin' do
|
|
15
15
|
expect('hello'.color(:red)).to eq(Rainbow('hello').color(:red))
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'proxies x11 color to Rainbow().color' do
|
19
|
+
expect('hello'.color(:midnightblue)).to eq(Rainbow('hello').color(:midnightblue))
|
20
|
+
end
|
21
|
+
|
18
22
|
it 'proxies colour to Rainbow().colour' do
|
19
23
|
expect('hello'.colour(:red)).to eq(Rainbow('hello').colour(:red))
|
20
24
|
end
|
data/spec/unit/color_spec.rb
CHANGED
@@ -12,19 +12,41 @@ module Rainbow
|
|
12
12
|
context "when single fixnum given" do
|
13
13
|
let(:values) { [1] }
|
14
14
|
|
15
|
-
it { should
|
15
|
+
it { should be_instance_of(Color::Indexed) }
|
16
|
+
|
17
|
+
specify { expect(subject.ground).to eq(ground) }
|
18
|
+
specify { expect(subject.num).to eq(1) }
|
16
19
|
end
|
17
20
|
|
18
|
-
context "when single symbol given" do
|
21
|
+
context "when single ansi symbol given" do
|
19
22
|
let(:values) { [:red] }
|
20
23
|
|
21
|
-
it { should
|
24
|
+
it { should be_instance_of(Color::Named) }
|
25
|
+
|
26
|
+
specify { expect(subject.ground).to eq(ground) }
|
27
|
+
specify { expect(subject.num).to eq(1) }
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when single x11 symbol given" do
|
31
|
+
let(:values) { [:midnightblue] }
|
32
|
+
|
33
|
+
it { should be_instance_of(Color::X11Named) }
|
34
|
+
|
35
|
+
specify { expect(subject.ground).to eq(ground) }
|
36
|
+
specify { expect(subject.r).to eq(25) }
|
37
|
+
specify { expect(subject.g).to eq(25) }
|
38
|
+
specify { expect(subject.b).to eq(112) }
|
22
39
|
end
|
23
40
|
|
24
41
|
context "when single string given" do
|
25
|
-
let(:values) { ['#
|
42
|
+
let(:values) { ['#deadcc'] }
|
26
43
|
|
27
|
-
it { should
|
44
|
+
it { should be_instance_of(Color::RGB) }
|
45
|
+
|
46
|
+
specify { expect(subject.ground).to eq(ground) }
|
47
|
+
specify { expect(subject.r).to eq(222) }
|
48
|
+
specify { expect(subject.g).to eq(173) }
|
49
|
+
specify { expect(subject.b).to eq(204) }
|
28
50
|
end
|
29
51
|
|
30
52
|
context "when 2 elements" do
|
@@ -38,7 +60,12 @@ module Rainbow
|
|
38
60
|
context "when 3 elements given" do
|
39
61
|
let(:values) { [1, 2, 3] }
|
40
62
|
|
41
|
-
it { should
|
63
|
+
it { should be_instance_of(Color::RGB) }
|
64
|
+
|
65
|
+
specify { expect(subject.ground).to eq(ground) }
|
66
|
+
specify { expect(subject.r).to eq(1) }
|
67
|
+
specify { expect(subject.g).to eq(2) }
|
68
|
+
specify { expect(subject.b).to eq(3) }
|
42
69
|
end
|
43
70
|
|
44
71
|
context "when 4 elements" do
|
@@ -241,4 +268,34 @@ module Rainbow
|
|
241
268
|
|
242
269
|
end
|
243
270
|
end
|
271
|
+
|
272
|
+
describe Color::X11Named do
|
273
|
+
let(:color) { described_class.new(ground, name) }
|
274
|
+
|
275
|
+
describe '#codes' do
|
276
|
+
subject { color.codes }
|
277
|
+
|
278
|
+
context "when ground is :foreground" do
|
279
|
+
let(:name) { :midnightblue }
|
280
|
+
let(:ground) { :foreground }
|
281
|
+
it { should eq([38, 5, 18]) }
|
282
|
+
end
|
283
|
+
|
284
|
+
context "when ground is :background" do
|
285
|
+
let(:name) { :midnightblue }
|
286
|
+
let(:ground) { :background }
|
287
|
+
it { should eq([48, 5, 18]) }
|
288
|
+
end
|
289
|
+
|
290
|
+
context "when name is invalid" do
|
291
|
+
let(:name) { :foo }
|
292
|
+
let(:ground) { :background }
|
293
|
+
it 'raises ArgumentError' do
|
294
|
+
expect { subject }.to raise_error(ArgumentError)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
244
301
|
end
|
data/spec/unit/wrapper_spec.rb
CHANGED
@@ -6,20 +6,26 @@ module Rainbow
|
|
6
6
|
|
7
7
|
let(:wrapper) { described_class.new(enabled) }
|
8
8
|
|
9
|
+
it "is enabled by default" do
|
10
|
+
expect(described_class.new.enabled).to be(true)
|
11
|
+
end
|
12
|
+
|
9
13
|
describe '#wrap' do
|
10
|
-
subject { wrapper.wrap(
|
14
|
+
subject { wrapper.wrap(object) }
|
15
|
+
|
16
|
+
let(:object) { Object.new }
|
11
17
|
|
12
18
|
context "when wrapping is enabled" do
|
13
19
|
let(:enabled) { true }
|
14
20
|
|
15
|
-
it { should eq(
|
21
|
+
it { should eq(object.to_s) }
|
16
22
|
it { should be_kind_of(Rainbow::Presenter) }
|
17
23
|
end
|
18
24
|
|
19
25
|
context "when wrapping is disabled" do
|
20
26
|
let(:enabled) { false }
|
21
27
|
|
22
|
-
it { should eq(
|
28
|
+
it { should eq(object.to_s) }
|
23
29
|
it { should be_kind_of(Rainbow::NullPresenter) }
|
24
30
|
end
|
25
31
|
end
|
metadata
CHANGED
@@ -1,57 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rainbow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Kulik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
27
|
description: Colorize printed text on ANSI terminals
|
56
28
|
email:
|
57
29
|
- m@ku1ik.com
|
@@ -59,9 +31,9 @@ executables: []
|
|
59
31
|
extensions: []
|
60
32
|
extra_rdoc_files: []
|
61
33
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .rubocop.yml
|
64
|
-
- .travis.yml
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- ".travis.yml"
|
65
37
|
- Changelog.md
|
66
38
|
- Gemfile
|
67
39
|
- Guardfile
|
@@ -78,6 +50,7 @@ files:
|
|
78
50
|
- lib/rainbow/string_utils.rb
|
79
51
|
- lib/rainbow/version.rb
|
80
52
|
- lib/rainbow/wrapper.rb
|
53
|
+
- lib/rainbow/x11_color_names.rb
|
81
54
|
- rainbow.gemspec
|
82
55
|
- spec/integration/instance_spec.rb
|
83
56
|
- spec/integration/rainbow_spec.rb
|
@@ -100,17 +73,17 @@ require_paths:
|
|
100
73
|
- lib
|
101
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
75
|
requirements:
|
103
|
-
- -
|
76
|
+
- - ">="
|
104
77
|
- !ruby/object:Gem::Version
|
105
78
|
version: 1.9.2
|
106
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
80
|
requirements:
|
108
|
-
- -
|
81
|
+
- - ">="
|
109
82
|
- !ruby/object:Gem::Version
|
110
83
|
version: '0'
|
111
84
|
requirements: []
|
112
85
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.2.2
|
114
87
|
signing_key:
|
115
88
|
specification_version: 4
|
116
89
|
summary: Colorize printed text on ANSI terminals
|