rainbow 2.2.1 → 3.1.1
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 +5 -5
- data/Changelog.md +60 -42
- data/README.markdown +64 -172
- data/lib/rainbow/color.rb +43 -32
- data/lib/rainbow/ext/string.rb +16 -4
- data/lib/rainbow/global.rb +5 -1
- data/lib/rainbow/null_presenter.rb +88 -26
- data/lib/rainbow/presenter.rb +35 -17
- data/lib/rainbow/refinement.rb +14 -0
- data/lib/rainbow/string_utils.rb +10 -8
- data/lib/rainbow/version.rb +3 -1
- data/lib/rainbow/wrapper.rb +2 -2
- data/lib/rainbow/x11_color_names.rb +5 -4
- data/lib/rainbow.rb +2 -13
- metadata +21 -46
- data/.gitignore +0 -17
- data/.rubocop.yml +0 -14
- data/.travis.yml +0 -22
- data/Gemfile +0 -23
- data/Guardfile +0 -9
- data/Rakefile +0 -6
- data/ext/mkrf_conf.rb +0 -22
- data/lib/rainbow/legacy.rb +0 -15
- data/rainbow.gemspec +0 -24
- data/spec/integration/instance_spec.rb +0 -35
- data/spec/integration/rainbow_spec.rb +0 -149
- data/spec/integration/string_spec.rb +0 -80
- data/spec/spec_helper.rb +0 -6
- data/spec/support/presenter_shared_examples.rb +0 -9
- data/spec/unit/color_spec.rb +0 -301
- data/spec/unit/namespace_spec.rb +0 -31
- data/spec/unit/null_presenter_spec.rb +0 -93
- data/spec/unit/presenter_spec.rb +0 -179
- data/spec/unit/string_utils_spec.rb +0 -62
- data/spec/unit/wrapper_spec.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7367f9386ef2460491f123bd207091956c6dcce6300dcf3957a48c126a1ec900
|
4
|
+
data.tar.gz: 1c123ecd4c6ee30422ff9df560df3ec4f5d4c8bcb6010e3a0c5be4435848894a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ddf54fa7edd4f0f05301270503025bfb63cbca6db7e940b4cf6c62cbd860b3cf939c885f5e69becd1f4faf39c9d2fe1e8a35597dd28fe1b30df26e52f334f0
|
7
|
+
data.tar.gz: 74550a67235dcca95dbd6404023576843e626e0ec00e557c0e38fbd145f778983b6c63136008d39da958a4fc83dc73e7a62758a40c8ead76c24066e968b66b6e
|
data/Changelog.md
CHANGED
@@ -1,47 +1,53 @@
|
|
1
1
|
# Rainbow changelog
|
2
2
|
|
3
|
-
## 1.0
|
3
|
+
## 3.1.0 (2020-08-26)
|
4
4
|
|
5
|
-
|
5
|
+
- added `cross_out` aka `strike`
|
6
|
+
- hexadecimal color names supported better, see #83
|
7
|
+
- gemspec: list files using a Ruby expression, avoiding git
|
6
8
|
|
7
|
-
##
|
9
|
+
## 3.0.0 (2017-11-29)
|
8
10
|
|
9
|
-
*
|
11
|
+
* added String refinement
|
12
|
+
* added new `Rainbow.uncolor` method
|
13
|
+
* dropped MRI 1.9.3 compatibility
|
14
|
+
* dropped MRI 2.0 compatibility
|
15
|
+
* removed Rake dependency
|
10
16
|
|
11
|
-
##
|
17
|
+
## 2.2.2 (2017-04-21)
|
12
18
|
|
13
|
-
*
|
19
|
+
* added explicit rake dependency to fix installation issue
|
14
20
|
|
15
|
-
##
|
16
|
-
|
17
|
-
* rainbow methods don't mutate the original string object anymore
|
18
|
-
|
19
|
-
## 1.0.4 (2009-11-27)
|
21
|
+
## 2.2.1 (2016-12-28)
|
20
22
|
|
21
|
-
*
|
23
|
+
* fixed gem installation (2.2.0 was a broken release)
|
22
24
|
|
23
|
-
##
|
25
|
+
## 2.2.0 (2016-12-27)
|
24
26
|
|
25
|
-
*
|
26
|
-
*
|
27
|
+
* improved Windows support
|
28
|
+
* added Ruby 2.4 support
|
29
|
+
* added `bold` alias method for `bright`
|
27
30
|
|
28
|
-
##
|
31
|
+
## 2.1.0 (2016-01-24)
|
29
32
|
|
33
|
+
* added X11 color support
|
34
|
+
* fixed `require` issue when rainbow is used as a dependency in another gem
|
30
35
|
* improved Windows support
|
31
36
|
|
32
|
-
##
|
37
|
+
## 2.0.0 (2014-01-24)
|
33
38
|
|
34
|
-
*
|
39
|
+
* disable string mixin by default
|
35
40
|
|
36
|
-
## 1.
|
41
|
+
## 1.99.2 (2014-01-24)
|
37
42
|
|
38
|
-
*
|
39
|
-
* fix for regression with regards to original string mutation
|
43
|
+
* bring back ruby 1.8 support
|
40
44
|
|
41
|
-
## 1.1
|
45
|
+
## 1.99.1 (2013-12-28)
|
42
46
|
|
43
|
-
*
|
44
|
-
*
|
47
|
+
* drop support for ruby 1.8
|
48
|
+
* `require "rainbow/string"` -> `require "rainbow/ext/string"`
|
49
|
+
* custom rainbow wrapper instances (with separate enabled/disabled state)
|
50
|
+
* shortcut methods for changing text color (`Rainbow("foo").red`)
|
45
51
|
|
46
52
|
## 1.99.0 (2013-12-26)
|
47
53
|
|
@@ -51,33 +57,45 @@
|
|
51
57
|
* support for MRI 1.8.7, 1.9.2, 1.9.3, 2.0 and 2.1, JRuby and Rubinius
|
52
58
|
* deprecation of Sickill::Rainbow namespace (use Rainbow.enabled = true instead)
|
53
59
|
|
54
|
-
## 1.
|
60
|
+
## 1.1.4 (2012-4-28)
|
55
61
|
|
56
|
-
*
|
57
|
-
*
|
58
|
-
* custom rainbow wrapper instances (with separate enabled/disabled state)
|
59
|
-
* shortcut methods for changing text color (`Rainbow("foo").red`)
|
62
|
+
* option for forcing coloring even when STDOUT is not a TTY (CLICOLOR_FORCE env var)
|
63
|
+
* fix for frozen strings
|
60
64
|
|
61
|
-
## 1.
|
65
|
+
## 1.1.3 (2011-12-6)
|
62
66
|
|
63
|
-
*
|
67
|
+
* improved compatibility with MRI 1.8.7
|
68
|
+
* fix for regression with regards to original string mutation
|
64
69
|
|
65
|
-
##
|
70
|
+
## 1.1.2 (2011-11-13)
|
66
71
|
|
67
|
-
*
|
72
|
+
* improved compatibility with MRI 1.9.3
|
68
73
|
|
69
|
-
##
|
74
|
+
## 1.1.1 (2011-2-7)
|
70
75
|
|
71
|
-
* added X11 color support
|
72
|
-
* fixed `require` issue when rainbow is used as a dependency in another gem
|
73
76
|
* improved Windows support
|
74
77
|
|
75
|
-
|
78
|
+
## 1.1 (2010-6-7)
|
76
79
|
|
77
|
-
*
|
78
|
-
*
|
79
|
-
|
80
|
+
* option for enabling/disabling of escape code wrapping
|
81
|
+
* auto-disabling when STDOUT is not a TTY
|
82
|
+
|
83
|
+
## 1.0.4 (2009-11-27)
|
80
84
|
|
81
|
-
|
85
|
+
* support for 256 colors
|
82
86
|
|
83
|
-
|
87
|
+
## 1.0.3 (2009-7-26)
|
88
|
+
|
89
|
+
* rainbow methods don't mutate the original string object anymore
|
90
|
+
|
91
|
+
## 1.0.2 (2009-5-15)
|
92
|
+
|
93
|
+
* improved support for ruby 1.8.6 and 1.9.1
|
94
|
+
|
95
|
+
## 1.0.1 (2009-3-19)
|
96
|
+
|
97
|
+
* Windows support
|
98
|
+
|
99
|
+
## 1.0.0 (2008-7-21)
|
100
|
+
|
101
|
+
* initial version
|
data/README.markdown
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Rainbow
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/rainbow)
|
3
4
|
[](https://travis-ci.org/sickill/rainbow)
|
5
|
+
[](https://ci.appveyor.com/project/sickill/rainbow)
|
4
6
|
[](https://codeclimate.com/github/sickill/rainbow)
|
5
7
|
[](https://coveralls.io/r/sickill/rainbow)
|
6
8
|
|
@@ -27,6 +29,10 @@ puts Rainbow("this is red").red + " and " + Rainbow("this on yellow bg").bg(:yel
|
|
27
29
|
# => "\e[31mthis is red\e[0m and \e[43mthis on yellow bg\e[0m and \e[4m\e[1meven bright underlined!\e[0m"
|
28
30
|
```
|
29
31
|
|
32
|
+

|
33
|
+
|
34
|
+
Or, [watch this video example](https://asciinema.org/a/J928KpHoUQ0sl54ulOSOLE71E?rows=20&speed=2.5)
|
35
|
+
|
30
36
|
### Rainbow presenter API
|
31
37
|
|
32
38
|
Rainbow presenter adds the following methods to presented string:
|
@@ -38,7 +44,9 @@ Rainbow presenter adds the following methods to presented string:
|
|
38
44
|
* `blink`
|
39
45
|
* `inverse`
|
40
46
|
* `hide`
|
41
|
-
* `
|
47
|
+
* `faint` (not well supported by terminal emulators)
|
48
|
+
* `italic` (not well supported by terminal emulators)
|
49
|
+
* `cross_out`, `strike`
|
42
50
|
|
43
51
|
Text color can also be changed by calling a method named by a color:
|
44
52
|
|
@@ -62,28 +70,27 @@ calls:
|
|
62
70
|
Rainbow("hola!").blue.bright.underline
|
63
71
|
```
|
64
72
|
|
65
|
-
###
|
73
|
+
### Refinement
|
66
74
|
|
67
|
-
If you
|
68
|
-
you can include all the rainbow presenter methods directly in a String class by
|
69
|
-
requiring `rainbow/ext/string`:
|
75
|
+
If you want to use the Refinements version, you can:
|
70
76
|
|
71
77
|
```ruby
|
72
|
-
require 'rainbow/
|
73
|
-
|
74
|
-
puts "
|
78
|
+
require 'rainbow/refinement'
|
79
|
+
using Rainbow
|
80
|
+
puts "Hi!".green
|
75
81
|
```
|
76
82
|
|
77
|
-
|
78
|
-
public interface with methods that are presentation specific.
|
79
|
-
|
80
|
-
NOTE: the mixin doesn't include shortcut methods for changing text color, you
|
81
|
-
should use "string".color(:blue) instead of "string".blue
|
83
|
+
Here's an IRB session example:
|
82
84
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
```
|
86
|
+
>> 'Hello, World!'.blue.bright.underline
|
87
|
+
NoMethodError: undefined method `blue' for "Hello, World!":String
|
88
|
+
(ripl):1:in `<main>'
|
89
|
+
>> using Rainbow
|
90
|
+
=> main
|
91
|
+
>> 'Hello, World!'.blue.bright.underline
|
92
|
+
=> "\e[34m\e[1m\e[4mHello, World!\e[0m"
|
93
|
+
```
|
87
94
|
|
88
95
|
### Color specification
|
89
96
|
|
@@ -111,6 +118,20 @@ When you specify a color with a RGB triplet rainbow finds the nearest match
|
|
111
118
|
from 256 colors palette. Note that it requires a 256-colors capable terminal to
|
112
119
|
display correctly.
|
113
120
|
|
121
|
+
#### Example: Choose a random color
|
122
|
+
|
123
|
+
You can pick a random color with Rainbow, it's a one-liner:
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
colors = Range.new(0,7).to_a
|
127
|
+
"whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
|
128
|
+
# => "\e[36mw\e[0m\e[37mh\e[0m\e[34mo\e[0m\e[34mo\e[0m\e[37mp\e[0m\e[34m \e[0m\e[36md\e[0m\e[33me\e[0m\e[34me\e[0m\e[37m \e[0m\e[32md\e[0m\e[35mo\e[0m\e[33mo\e[0m\e[36mp\e[0m"
|
129
|
+
|
130
|
+
colors = [:aliceblue, :antiquewhite, :aqua, :aquamarine, :azure, :beige, :bisque, :blanchedalmond, :blueviolet]
|
131
|
+
"whoop dee doop".chars.map { |char| Rainbow(char).color(colors.sample) }.join
|
132
|
+
# => "\e[38;5;135mw\e[0m\e[38;5;230mh\e[0m\e[38;5;231mo\e[0m\e[38;5;135mo\e[0m\e[38;5;231mp\e[0m\e[38;5;231m \e[0m\e[38;5;122md\e[0m\e[38;5;231me\e[0m\e[38;5;231me\e[0m\e[38;5;230m \e[0m\e[38;5;122md\e[0m\e[38;5;51mo\e[0m\e[38;5;51mo\e[0m\e[38;5;51mp\e[0m"
|
133
|
+
```
|
134
|
+
|
114
135
|
### Configuration
|
115
136
|
|
116
137
|
Rainbow can be enabled/disabled globally by setting:
|
@@ -153,16 +174,6 @@ colorize all the strings, even the ones that go through file writing
|
|
153
174
|
formatters. You can easily solve that by disabling coloring for the Rainbow
|
154
175
|
instances that are used by formatters with file output.
|
155
176
|
|
156
|
-
## Windows support
|
157
|
-
|
158
|
-
For Windows support on Ruby < 2.0, you should install the following gems:
|
159
|
-
|
160
|
-
```ruby
|
161
|
-
gem install windows-pr win32console
|
162
|
-
```
|
163
|
-
|
164
|
-
If the above gems aren't installed then all strings are returned unmodified.
|
165
|
-
|
166
177
|
## Installation
|
167
178
|
|
168
179
|
Add it to your Gemfile:
|
@@ -181,154 +192,35 @@ gem install rainbow
|
|
181
192
|
|
182
193
|
### ANSI colors
|
183
194
|
|
184
|
-
|
185
|
-
* `red`
|
186
|
-
* `green`
|
187
|
-
* `yellow`
|
188
|
-
* `blue`
|
189
|
-
* `magenta`
|
190
|
-
* `cyan`
|
191
|
-
* `white`
|
195
|
+
`black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`
|
192
196
|
|
193
197
|
### X11 colors
|
194
198
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
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`
|
199
|
+
`aliceblue`, `antiquewhite`, `aqua`, `aquamarine`, `azure`, `beige`, `bisque`,
|
200
|
+
`blanchedalmond`, `blueviolet`, `brown`, `burlywood`, `cadetblue`, `chartreuse`,
|
201
|
+
`chocolate`, `coral`, `cornflower`, `cornsilk`, `crimson`, `darkblue`,
|
202
|
+
`darkcyan`, `darkgoldenrod`, `darkgray`, `darkgreen`, `darkkhaki`,
|
203
|
+
`darkmagenta`, `darkolivegreen`, `darkorange`, `darkorchid`, `darkred`,
|
204
|
+
`darksalmon`, `darkseagreen`, `darkslateblue`, `darkslategray`, `darkturquoise`,
|
205
|
+
`darkviolet`, `deeppink`, `deepskyblue`, `dimgray`, `dodgerblue`, `firebrick`,
|
206
|
+
`floralwhite`, `forestgreen`, `fuchsia`, `gainsboro`, `ghostwhite`, `gold`,
|
207
|
+
`goldenrod`, `gray`, `greenyellow`, `honeydew`, `hotpink`, `indianred`,
|
208
|
+
`indigo`, `ivory`, `khaki`, `lavender`, `lavenderblush`, `lawngreen`,
|
209
|
+
`lemonchiffon`, `lightblue`, `lightcoral`, `lightcyan`, `lightgoldenrod`,
|
210
|
+
`lightgray`, `lightgreen`, `lightpink`, `lightsalmon`, `lightseagreen`,
|
211
|
+
`lightskyblue`, `lightslategray`, `lightsteelblue`, `lightyellow`, `lime`,
|
212
|
+
`limegreen`, `linen`, `maroon`, `mediumaquamarine`, `mediumblue`,
|
213
|
+
`mediumorchid`, `mediumpurple`, `mediumseagreen`, `mediumslateblue`,
|
214
|
+
`mediumspringgreen`, `mediumturquoise`, `mediumvioletred`, `midnightblue`,
|
215
|
+
`mintcream`, `mistyrose`, `moccasin`, `navajowhite`, `navyblue`, `oldlace`,
|
216
|
+
`olive`, `olivedrab`, `orange`, `orangered`, `orchid`, `palegoldenrod`,
|
217
|
+
`palegreen`, `paleturquoise`, `palevioletred`, `papayawhip`, `peachpuff`,
|
218
|
+
`peru`, `pink`, `plum`, `powderblue`, `purple`, `rebeccapurple`, `rosybrown`,
|
219
|
+
`royalblue`, `saddlebrown`, `salmon`, `sandybrown`, `seagreen`, `seashell`,
|
220
|
+
`sienna`, `silver`, `skyblue`, `slateblue`, `slategray`, `snow`, `springgreen`,
|
221
|
+
`steelblue`, `tan`, `teal`, `thistle`, `tomato`, `turquoise`, `violet`,
|
222
|
+
`webgray`, `webgreen`, `webmaroon`, `webpurple`, `wheat`, `whitesmoke`,
|
223
|
+
`yellowgreen`
|
332
224
|
|
333
225
|
## Authors
|
334
226
|
|
data/lib/rainbow/color.rb
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Rainbow
|
2
4
|
class Color
|
3
|
-
|
4
5
|
attr_reader :ground
|
5
6
|
|
6
7
|
def self.build(ground, values)
|
7
8
|
unless [1, 3].include?(values.size)
|
8
|
-
|
9
|
-
|
9
|
+
raise ArgumentError,
|
10
|
+
"Wrong number of arguments for color definition, should be 1 or 3"
|
10
11
|
end
|
11
12
|
|
12
13
|
color = values.size == 1 ? values.first : values
|
13
14
|
|
14
15
|
case color
|
15
|
-
|
16
|
+
# NOTE: Properly handle versions before/after Ruby 2.4.0.
|
17
|
+
# Ruby 2.4+ unifies Fixnum & Bignum into Integer.
|
18
|
+
# However previous versions would still use Fixnum.
|
19
|
+
# To avoid missing `Fixnum` input, call `0.class` which would
|
20
|
+
# return either `Integer` or `Fixnum`.
|
21
|
+
when 0.class
|
16
22
|
Indexed.new(ground, color)
|
17
23
|
when Symbol
|
18
24
|
if Named.color_names.include?(color)
|
@@ -20,9 +26,9 @@ module Rainbow
|
|
20
26
|
elsif X11Named.color_names.include?(color)
|
21
27
|
X11Named.new(ground, color)
|
22
28
|
else
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
raise ArgumentError,
|
30
|
+
"Unknown color name, valid names: " +
|
31
|
+
(Named.color_names + X11Named.color_names).join(', ')
|
26
32
|
end
|
27
33
|
when Array
|
28
34
|
RGB.new(ground, *color)
|
@@ -32,6 +38,11 @@ module Rainbow
|
|
32
38
|
end
|
33
39
|
|
34
40
|
def self.parse_hex_color(hex)
|
41
|
+
unless hex =~ /^#?[a-f0-9]{6}/i
|
42
|
+
raise ArgumentError,
|
43
|
+
"Invalid hexadecimal RGB triplet. Valid format: /^#?[a-f0-9]{6}/i"
|
44
|
+
end
|
45
|
+
|
35
46
|
hex = hex.sub(/^#/, '')
|
36
47
|
r = hex[0..1].to_i(16)
|
37
48
|
g = hex[2..3].to_i(16)
|
@@ -41,7 +52,6 @@ module Rainbow
|
|
41
52
|
end
|
42
53
|
|
43
54
|
class Indexed < Color
|
44
|
-
|
45
55
|
attr_reader :num
|
46
56
|
|
47
57
|
def initialize(ground, num)
|
@@ -54,40 +64,40 @@ module Rainbow
|
|
54
64
|
|
55
65
|
[code]
|
56
66
|
end
|
57
|
-
|
58
67
|
end
|
59
68
|
|
60
69
|
class Named < Indexed
|
61
|
-
|
62
70
|
NAMES = {
|
63
|
-
black:
|
64
|
-
red:
|
65
|
-
green:
|
66
|
-
yellow:
|
67
|
-
blue:
|
71
|
+
black: 0,
|
72
|
+
red: 1,
|
73
|
+
green: 2,
|
74
|
+
yellow: 3,
|
75
|
+
blue: 4,
|
68
76
|
magenta: 5,
|
69
|
-
cyan:
|
70
|
-
white:
|
71
|
-
default: 9
|
72
|
-
}
|
77
|
+
cyan: 6,
|
78
|
+
white: 7,
|
79
|
+
default: 9
|
80
|
+
}.freeze
|
73
81
|
|
74
82
|
def self.color_names
|
75
83
|
NAMES.keys
|
76
84
|
end
|
77
85
|
|
86
|
+
def self.valid_names
|
87
|
+
color_names.join(', ')
|
88
|
+
end
|
89
|
+
|
78
90
|
def initialize(ground, name)
|
79
91
|
unless Named.color_names.include?(name)
|
80
|
-
|
81
|
-
|
92
|
+
raise ArgumentError,
|
93
|
+
"Unknown color name, valid names: #{self.class.valid_names}"
|
82
94
|
end
|
83
95
|
|
84
96
|
super(ground, NAMES[name])
|
85
97
|
end
|
86
|
-
|
87
98
|
end
|
88
99
|
|
89
100
|
class RGB < Indexed
|
90
|
-
|
91
101
|
attr_reader :r, :g, :b
|
92
102
|
|
93
103
|
def self.to_ansi_domain(value)
|
@@ -95,8 +105,8 @@ module Rainbow
|
|
95
105
|
end
|
96
106
|
|
97
107
|
def initialize(ground, *values)
|
98
|
-
if values.min
|
99
|
-
|
108
|
+
if values.min.negative? || values.max > 255
|
109
|
+
raise ArgumentError, "RGB value outside 0-255 range"
|
100
110
|
end
|
101
111
|
|
102
112
|
super(ground, 8)
|
@@ -111,10 +121,9 @@ module Rainbow
|
|
111
121
|
|
112
122
|
def code_from_rgb
|
113
123
|
16 + self.class.to_ansi_domain(r) * 36 +
|
114
|
-
|
115
|
-
|
124
|
+
self.class.to_ansi_domain(g) * 6 +
|
125
|
+
self.class.to_ansi_domain(b)
|
116
126
|
end
|
117
|
-
|
118
127
|
end
|
119
128
|
|
120
129
|
class X11Named < RGB
|
@@ -124,16 +133,18 @@ module Rainbow
|
|
124
133
|
NAMES.keys
|
125
134
|
end
|
126
135
|
|
136
|
+
def self.valid_names
|
137
|
+
color_names.join(', ')
|
138
|
+
end
|
139
|
+
|
127
140
|
def initialize(ground, name)
|
128
141
|
unless X11Named.color_names.include?(name)
|
129
|
-
|
130
|
-
|
142
|
+
raise ArgumentError,
|
143
|
+
"Unknown color name, valid names: #{self.class.valid_names}"
|
131
144
|
end
|
132
145
|
|
133
146
|
super(ground, *NAMES[name])
|
134
147
|
end
|
135
|
-
|
136
148
|
end
|
137
|
-
|
138
149
|
end
|
139
150
|
end
|
data/lib/rainbow/ext/string.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rainbow'
|
2
4
|
|
3
5
|
module Rainbow
|
4
6
|
module Ext
|
5
7
|
module String
|
6
8
|
module InstanceMethods
|
7
|
-
|
8
9
|
def foreground(*color)
|
9
10
|
Rainbow(self).foreground(*color)
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
alias color foreground
|
14
|
+
alias colour foreground
|
14
15
|
|
15
16
|
def background(*color)
|
16
17
|
Rainbow(self).background(*color)
|
@@ -24,6 +25,10 @@ module Rainbow
|
|
24
25
|
Rainbow(self).bright
|
25
26
|
end
|
26
27
|
|
28
|
+
def faint
|
29
|
+
Rainbow(self).faint
|
30
|
+
end
|
31
|
+
|
27
32
|
def italic
|
28
33
|
Rainbow(self).italic
|
29
34
|
end
|
@@ -44,9 +49,16 @@ module Rainbow
|
|
44
49
|
Rainbow(self).hide
|
45
50
|
end
|
46
51
|
|
52
|
+
def cross_out
|
53
|
+
Rainbow(self).cross_out
|
54
|
+
end
|
55
|
+
|
56
|
+
alias strike cross_out
|
47
57
|
end
|
48
58
|
end
|
49
59
|
end
|
50
60
|
end
|
51
61
|
|
52
|
-
|
62
|
+
class String
|
63
|
+
include Rainbow::Ext::String::InstanceMethods
|
64
|
+
end
|
data/lib/rainbow/global.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'wrapper'
|
2
4
|
|
3
5
|
module Rainbow
|
4
|
-
|
5
6
|
def self.global
|
6
7
|
@global ||= Wrapper.new
|
7
8
|
end
|
@@ -14,6 +15,9 @@ module Rainbow
|
|
14
15
|
global.enabled = value
|
15
16
|
end
|
16
17
|
|
18
|
+
def self.uncolor(string)
|
19
|
+
StringUtils.uncolor(string)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def Rainbow(string)
|