rainbow 1.1.4 → 1.99.0
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 +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +11 -0
- data/Gemfile +17 -0
- data/Guardfile +9 -0
- data/README.markdown +91 -48
- data/Rakefile +6 -0
- data/lib/rainbow.rb +14 -96
- data/lib/rainbow/color.rb +109 -0
- data/lib/rainbow/core.rb +16 -0
- data/lib/rainbow/legacy.rb +14 -0
- data/lib/rainbow/string.rb +50 -0
- data/lib/rainbow/string_utils.rb +23 -0
- data/lib/rainbow/version.rb +3 -0
- data/lib/rainbow/wrapper.rb +76 -0
- data/rainbow.gemspec +25 -0
- data/spec/integration/rainbow_spec.rb +132 -0
- data/spec/integration/string_spec.rb +50 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/color_spec.rb +244 -0
- data/spec/unit/namespace_spec.rb +31 -0
- data/spec/unit/string_utils_spec.rb +62 -0
- data/spec/unit/wrapper_spec.rb +149 -0
- metadata +86 -20
- data/lib/ansi_color.rb +0 -71
- data/lib/ansi_rgb.rb +0 -43
- data/test/rainbow_test.rb +0 -277
data/lib/ansi_rgb.rb
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
module Sickill
|
|
2
|
-
module Rainbow
|
|
3
|
-
|
|
4
|
-
# Retrieve ANSI color code from RGB color.
|
|
5
|
-
class AnsiRgb
|
|
6
|
-
|
|
7
|
-
# +ground+ is one of :foreground, :background
|
|
8
|
-
# +rgb+ is an array of 3 values between 0 and 255.
|
|
9
|
-
def initialize(ground, rgb)
|
|
10
|
-
if RGB.outside_range?(rgb)
|
|
11
|
-
raise ArgumentError.new("RGB value outside 0-255 range")
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
@ground_code = { :foreground => 38, :background => 48 }[ground]
|
|
15
|
-
@red, @green, @blue = rgb[0], rgb[1], rgb[2]
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Get the ANSI color code for this RGB color.
|
|
19
|
-
def code
|
|
20
|
-
index = 16 +
|
|
21
|
-
RGB.to_ansi_domain(@red) * 36 +
|
|
22
|
-
RGB.to_ansi_domain(@green) * 6 +
|
|
23
|
-
RGB.to_ansi_domain(@blue)
|
|
24
|
-
|
|
25
|
-
"#{@ground_code};5;#{index}"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Helper class for RGB color format.
|
|
31
|
-
class RGB
|
|
32
|
-
def self.outside_range?(rgb)
|
|
33
|
-
rgb.min < 0 or rgb.max > 255
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Change domain of color value from 0-255 to 0-5
|
|
37
|
-
def self.to_ansi_domain(value)
|
|
38
|
-
(6 * (value / 256.0)).to_i
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
end
|
data/test/rainbow_test.rb
DELETED
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
require 'test/unit'
|
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/../lib/rainbow')
|
|
3
|
-
|
|
4
|
-
class RainbowTest < Test::Unit::TestCase #:nodoc:
|
|
5
|
-
def test_color_by_name
|
|
6
|
-
assert_equal "\e[31mhello\e[0m", "hello".color(:red)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def test_color_by_rgb
|
|
10
|
-
assert_equal "\e[38;5;196mhello\e[0m", "hello".color(255, 0, 0)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def test_foreground_alias
|
|
14
|
-
assert_equal "hello".color(:red), "hello".foreground(:red)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def test_colour_alias
|
|
18
|
-
assert_equal "hello".color(:red), "hello".colour(:red)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def test_background_by_name
|
|
22
|
-
assert_equal "\e[42mhello\e[0m", "hello".background(:green)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def test_background_by_rgb
|
|
26
|
-
assert_equal "\e[48;5;46mhello\e[0m", "hello".background(0, 255, 0)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def test_color_and_background
|
|
30
|
-
assert_equal "\e[31m\e[42mhello\e[0m", "hello".color(:red).background(:green)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_hex_color
|
|
34
|
-
assert_equal "\e[48;5;46mhello\e[0m", "hello".background("#00FF00")
|
|
35
|
-
assert_equal "\e[48;5;46mhello\e[0m", "hello".background("00FF00")
|
|
36
|
-
assert_equal "\e[48;5;46mhello\e[0m", "hello".background("00ff00")
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def test_bad_color_name
|
|
40
|
-
assert_raises ArgumentError do
|
|
41
|
-
"hello".background(:baaaad)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def test_rgb_color_with_2_args
|
|
46
|
-
assert_raises ArgumentError do
|
|
47
|
-
"hello".background(1, 2)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def test_rgb_color_with_4_args
|
|
52
|
-
assert_raises ArgumentError do
|
|
53
|
-
"hello".background(1, 2, 3, 4)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def test_rgb_color_with_values_below_zero
|
|
58
|
-
assert_raises ArgumentError do
|
|
59
|
-
"hello".background(-3, 2, 3)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def test_rgb_color_with_values_above_255
|
|
64
|
-
assert_raises ArgumentError do
|
|
65
|
-
"hello".background(256, 2, 3)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def test_bright
|
|
70
|
-
assert_equal "\e[1mhello\e[0m", "hello".bright
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def test_bright_and_color
|
|
74
|
-
assert_equal "\e[1m\e[31mhello\e[0m", "hello".bright.color(:red)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def test_bright_and_background
|
|
78
|
-
assert_equal "\e[1m\e[44mhello\e[0m", "hello".bright.background(:blue)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def test_color_override
|
|
82
|
-
assert_equal "\e[31m\e[34m\e[33mhello\e[0m", "hello".color(:red).color(:blue).color(:yellow)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def test_reset
|
|
86
|
-
assert_equal "\e[0mhello\e[0m", "hello".reset
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def test_italic
|
|
90
|
-
assert_equal "\e[3mhello\e[0m", "hello".italic
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def test_underline
|
|
94
|
-
assert_equal "\e[4mhello\e[0m", "hello".underline
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def test_blink
|
|
98
|
-
assert_equal "\e[5mhello\e[0m", "hello".blink
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def test_inverse
|
|
102
|
-
assert_equal "\e[7mhello\e[0m", "hello".inverse
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def test_hide
|
|
106
|
-
assert_equal "\e[8mhello\e[0m", "hello".hide
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def test_immutability
|
|
110
|
-
string = "hello"
|
|
111
|
-
string.color(:red)
|
|
112
|
-
assert_equal string, "hello"
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
def test_frozen
|
|
116
|
-
string = "frozen"
|
|
117
|
-
string.freeze
|
|
118
|
-
string.color(:red)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
class MyString < String
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def test_inheritance
|
|
125
|
-
my_string = MyString.new "hello"
|
|
126
|
-
assert_equal "\e[31mhello\e[0m", my_string.color(:red)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def test_disabled
|
|
130
|
-
Sickill::Rainbow.enabled = false
|
|
131
|
-
assert_equal "hello", "hello".color(:red)
|
|
132
|
-
Sickill::Rainbow.enabled = true
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
class AnsiColorTest < Test::Unit::TestCase
|
|
138
|
-
include Sickill::Rainbow
|
|
139
|
-
|
|
140
|
-
### Foreground
|
|
141
|
-
|
|
142
|
-
def test_bad_foreground_name
|
|
143
|
-
assert_raises ArgumentError do
|
|
144
|
-
AnsiColor.new(:foreground, :azerty).code
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def test_by_name_black_foreground
|
|
149
|
-
assert_equal 30, AnsiColor.new(:foreground, :black).code
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def test_by_name_red_foreground
|
|
153
|
-
assert_equal 31, AnsiColor.new(:foreground, :red).code
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def test_by_name_green_foreground
|
|
157
|
-
assert_equal 32, AnsiColor.new(:foreground, :green).code
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def test_by_name_yellow_foreground
|
|
161
|
-
assert_equal 33, AnsiColor.new(:foreground, :yellow).code
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def test_by_name_blue_foreground
|
|
165
|
-
assert_equal 34, AnsiColor.new(:foreground, :blue).code
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def test_by_name_magenta_foreground
|
|
169
|
-
assert_equal 35, AnsiColor.new(:foreground, :magenta).code
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def test_by_name_cyan_foreground
|
|
173
|
-
assert_equal 36, AnsiColor.new(:foreground, :cyan).code
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def test_by_name_white_foreground
|
|
177
|
-
assert_equal 37, AnsiColor.new(:foreground, :white).code
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
### Background
|
|
181
|
-
|
|
182
|
-
def test_bad_background_name
|
|
183
|
-
assert_raises ArgumentError do
|
|
184
|
-
AnsiColor.new(:background, :azerty).code
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
def test_by_name_black_background
|
|
189
|
-
assert_equal 40, AnsiColor.new(:background, :black).code
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
def test_by_name_red_background
|
|
193
|
-
assert_equal 41, AnsiColor.new(:background, :red).code
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def test_by_name_green_background
|
|
197
|
-
assert_equal 42, AnsiColor.new(:background, :green).code
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def test_by_name_yellow_background
|
|
201
|
-
assert_equal 43, AnsiColor.new(:background, :yellow).code
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
def test_by_name_blue_background
|
|
205
|
-
assert_equal 44, AnsiColor.new(:background, :blue).code
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
def test_by_name_magenta_background
|
|
209
|
-
assert_equal 45, AnsiColor.new(:background, :magenta).code
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
def test_by_name_cyan_background
|
|
213
|
-
assert_equal 46, AnsiColor.new(:background, :cyan).code
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
def test_by_name_white_background
|
|
217
|
-
assert_equal 47, AnsiColor.new(:background, :white).code
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
### Hex color
|
|
221
|
-
|
|
222
|
-
def test_by_hex_maj
|
|
223
|
-
assert_equal "38;5;46", AnsiColor.new(:foreground, "00FF00").code
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
def test_by_hex_min
|
|
227
|
-
assert_equal "38;5;46", AnsiColor.new(:foreground, "00ff00").code
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
def test_by_hex_maj_with_sharp
|
|
231
|
-
assert_equal "38;5;46", AnsiColor.new(:foreground, "#00FF00").code
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
def test_by_hex_min_with_sharp
|
|
235
|
-
assert_equal "38;5;46", AnsiColor.new(:foreground, "#00ff00").code
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
### RGB color
|
|
239
|
-
|
|
240
|
-
def test_too_few_colors
|
|
241
|
-
assert_raises ArgumentError do
|
|
242
|
-
AnsiColor.new(:foreground, 255, 0).code
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
def test_too_much_colors
|
|
247
|
-
assert_raises ArgumentError do
|
|
248
|
-
AnsiColor.new(:foreground, 255, 0, 0, 0).code
|
|
249
|
-
end
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def test_by_rgb_red_foreground
|
|
253
|
-
assert_equal "38;5;196", AnsiColor.new(:foreground, 255, 0, 0).code
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
class AnsiRgbTest < Test::Unit::TestCase
|
|
259
|
-
include Sickill::Rainbow
|
|
260
|
-
|
|
261
|
-
def test_red
|
|
262
|
-
assert_equal "38;5;196", AnsiRgb.new(:foreground, [255, 0, 0]).code
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
def test_rgb_color_with_values_below_zero
|
|
266
|
-
assert_raises ArgumentError do
|
|
267
|
-
AnsiRgb.new(:foreground, [-1, 0, 0])
|
|
268
|
-
end
|
|
269
|
-
end
|
|
270
|
-
|
|
271
|
-
def test_rgb_color_with_values_above_255
|
|
272
|
-
assert_raises ArgumentError do
|
|
273
|
-
AnsiRgb.new(:foreground, [256, 0, 0])
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
end
|