colorize 0.5.7 → 1.0.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 +7 -0
- data/CHANGELOG.md +76 -0
- data/LICENSE +339 -0
- data/README.md +152 -0
- data/Rakefile +12 -14
- data/colorize.gemspec +30 -42
- data/lib/colorize/class_methods.rb +203 -0
- data/lib/colorize/errors.rb +9 -0
- data/lib/colorize/instance_methods.rb +144 -0
- data/lib/colorize/version.rb +8 -0
- data/lib/colorize.rb +14 -185
- data/lib/colorized_string.rb +25 -0
- data/test/test_colorize.rb +209 -6
- data/test/test_colorized_string.rb +216 -0
- metadata +40 -47
- data/.gitignore +0 -6
- data/CHANGELOG.rdoc +0 -15
- data/README.rdoc +0 -55
- data/VERSION +0 -1
- data/test/test_helper.rb +0 -2
data/test/test_colorize.rb
CHANGED
|
@@ -1,11 +1,214 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require "#{File.dirname(__FILE__)}/../lib/colorize"
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
class TestColorize < Minitest::Test
|
|
7
|
+
def test_blue_symbol
|
|
8
|
+
assert_equal "\001\033[0;34;49m\002This is blue\001\033[0m\002", 'This is blue'.colorize(:blue)
|
|
6
9
|
end
|
|
7
|
-
|
|
8
|
-
def
|
|
9
|
-
|
|
10
|
+
|
|
11
|
+
def test_incorrect_symbol
|
|
12
|
+
assert_equal "\001\033[0;39;49m\002This is incorrect color\001\033[0m\002", 'This is incorrect color'.colorize(:bold)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_incorrect_hash
|
|
16
|
+
assert_equal "\001\033[0;39;49m\002This is incorrect color\001\033[0m\002", 'This is incorrect color'.colorize(:color => :bold)
|
|
17
|
+
|
|
18
|
+
assert_equal "\001\033[0;39;49m\002This is incorrect color\001\033[0m\002", 'This is incorrect color'.colorize(:mode => :green)
|
|
19
|
+
|
|
20
|
+
assert_equal "\001\033[0;39;49m\002This is incorrect color\001\033[0m\002", 'This is incorrect color'.colorize(:background => :bold)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_blue_hash
|
|
24
|
+
assert_equal "\001\033[0;34;49m\002This is also blue\001\033[0m\002", 'This is also blue'.colorize(:color => :blue)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_light_blue_symbol
|
|
28
|
+
assert_equal "\001\033[0;94;49m\002This is light blue\001\033[0m\002", 'This is light blue'.colorize(:light_blue)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_light_blue_with_red_background_hash
|
|
32
|
+
assert_equal "\001\033[0;94;41m\002This is light blue with red background\001\033[0m\002", 'This is light blue with red background'.colorize(:color => :light_blue, :background => :red)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_light_blue_with_red_background_symbol_and_hash
|
|
36
|
+
assert_equal "\001\033[0;94;41m\002This is light blue with red background\001\033[0m\002", 'This is light blue with red background'.colorize(:light_blue).colorize(:background => :red)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_blue_with_red_background_method
|
|
40
|
+
assert_equal "\001\033[0;34;41m\002This is blue text on red\001\033[0m\002", 'This is blue text on red'.blue.on_red
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_red_with_blue_background_symbol_and_method
|
|
44
|
+
assert_equal "\001\033[0;31;44m\002This is red on blue\001\033[0m\002", 'This is red on blue'.colorize(:red).on_blue
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_red_with_blue_background_and_underline_symbol_and_methods
|
|
48
|
+
assert_equal "\001\033[4;31;44m\002This is red on blue and underline\001\033[0m\002", 'This is red on blue and underline'.colorize(:red).on_blue.underline
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_blue_with_red_background_and_blink_methods
|
|
52
|
+
assert_equal "\001\033[5;34;41m\002This is blue text on red\001\033[0m\002", 'This is blue text on red'.blue.on_red.blink
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_uncolorize
|
|
56
|
+
assert_equal 'This is uncolorized', 'This is uncolorized'.blue.on_red.uncolorize
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_colorized?
|
|
60
|
+
assert_predicate 'Red'.red, :colorized?
|
|
61
|
+
refute_predicate 'Blue', :colorized?
|
|
62
|
+
refute_predicate 'Green'.blue.green.uncolorize, :colorized?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_concatenated__colorize?
|
|
66
|
+
assert_predicate "none #{'red'.red} none #{'blue'.blue} none", :colorized?
|
|
67
|
+
refute_predicate "none #{'red'.red} none #{'blue'.blue} none".uncolorize, :colorized?
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def test_concatenated_strings_on_green
|
|
71
|
+
assert_equal "\001\033[0;39;42m\002none \001\033[0m\002\001\033[0;31;42m\002red\001\033[0m\002\001\033[0;39;42m\002 none \001\033[0m\002\001\033[0;34;42m\002blue\001\033[0m\002\001\033[0;39;42m\002 none\001\033[0m\002", "none #{'red'.red} none #{'blue'.blue} none".on_green
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_concatenated_strings_uncolorize
|
|
75
|
+
assert_equal 'none red none blue none', "none #{'red'.red} none #{'blue'.blue} none".uncolorize
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_new_line
|
|
79
|
+
assert_equal "\001\033[5;34;41m\002This is blue\ntext on red\001\033[0m\002", "This is blue\ntext on red".blue.on_red.blink
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_disable_colorization_with_=
|
|
83
|
+
String.disable_colorization = true
|
|
84
|
+
|
|
85
|
+
assert String.disable_colorization
|
|
86
|
+
|
|
87
|
+
String.disable_colorization = false
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_disable_colorization_with_method
|
|
91
|
+
String.disable_colorization true
|
|
92
|
+
|
|
93
|
+
assert String.disable_colorization
|
|
94
|
+
|
|
95
|
+
String.disable_colorization false
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_string_disable_colorization_with_=
|
|
99
|
+
String.disable_colorization = true
|
|
100
|
+
|
|
101
|
+
assert String.disable_colorization
|
|
102
|
+
|
|
103
|
+
assert_equal 'This is blue after disabling', 'This is blue after disabling'.blue
|
|
104
|
+
|
|
105
|
+
String.disable_colorization = false
|
|
106
|
+
|
|
107
|
+
assert_equal "\001\033[0;34;49m\002This is blue after enabling\001\033[0m\002", 'This is blue after enabling'.colorize(:blue)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_string_disable_colorization_with_method
|
|
111
|
+
assert_equal "\001\033[0;34;49m\002This is blue before disabling\001\033[0m\002", 'This is blue before disabling'.colorize(:blue)
|
|
112
|
+
|
|
113
|
+
String.disable_colorization true
|
|
114
|
+
|
|
115
|
+
assert String.disable_colorization
|
|
116
|
+
|
|
117
|
+
assert_equal 'This is blue after disabling', 'This is blue after disabling'.blue
|
|
118
|
+
|
|
119
|
+
String.disable_colorization false
|
|
120
|
+
|
|
121
|
+
assert_equal "\001\033[0;34;49m\002This is blue after enabling\001\033[0m\002", 'This is blue after enabling'.colorize(:blue)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_already_colored_string_with_one_value
|
|
125
|
+
assert_equal 'This is red'.red, "\001\033[31m\002This is red\001\033[0m\002".red
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_color_matrix_method
|
|
129
|
+
assert_raises NoMethodError do
|
|
130
|
+
String.color_matrix
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_color_samples_method
|
|
135
|
+
assert_output do
|
|
136
|
+
String.color_samples
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_grey_alias
|
|
141
|
+
assert_equal 'This is grey'.grey, 'This is grey'.light_black
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def test_gray_alias
|
|
145
|
+
assert_equal 'This is gray'.gray, 'This is gray'.light_black
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def test_add_color_alias
|
|
149
|
+
String.add_color_alias(:extra_blue, :light_blue)
|
|
150
|
+
|
|
151
|
+
assert_equal 'blue'.light_blue, 'blue'.extra_blue
|
|
152
|
+
assert_equal 'blue'.on_light_blue, 'blue'.on_extra_blue
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def test_add_color_alias_errors
|
|
156
|
+
String.add_color_alias(:extra_red, :light_red)
|
|
157
|
+
|
|
158
|
+
assert_raises ::Colorize::ColorAlreadyExist, 'Colorize: color :extra_red already exist!' do
|
|
159
|
+
String.add_color_alias(:extra_red, :light_blue)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
assert_raises ::Colorize::ColorDontExist, 'Colorize: color :light_color don\'t exist!' do
|
|
163
|
+
String.add_color_alias(:extra_white, :light_color)
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def test_add_color_alias_with_single_hash
|
|
168
|
+
String.add_color_alias(extra_green: :light_green)
|
|
169
|
+
|
|
170
|
+
assert_equal 'example string'.light_green, 'example string'.extra_green
|
|
171
|
+
assert_equal 'example string'.on_light_green, 'example string'.on_extra_green
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def test_add_color_alias_with_single_hash_with_arrow
|
|
175
|
+
String.add_color_alias(:extra_color => :gray)
|
|
176
|
+
|
|
177
|
+
assert_equal 'example string'.gray, 'example string'.extra_color
|
|
178
|
+
assert_equal 'example string'.on_gray, 'example string'.on_extra_color
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def test_add_color_alias_with_multi_hash
|
|
182
|
+
String.add_color_alias(extra_color_a: :gray, extra_color_b: :blue)
|
|
183
|
+
|
|
184
|
+
assert_equal 'example string'.gray, 'example string'.extra_color_a
|
|
185
|
+
assert_equal 'example string'.blue, 'example string'.extra_color_b
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def test_add_color_alias_with_multi_hash_with_arrow
|
|
189
|
+
String.add_color_alias(:extra_color_c => :gray, :extra_color_d => :blue)
|
|
190
|
+
|
|
191
|
+
assert_equal 'example string'.gray, 'example string'.extra_color_c
|
|
192
|
+
assert_equal 'example string'.on_blue, 'example string'.on_extra_color_d
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def test_add_color_alias_with_multi_hash_mixed
|
|
196
|
+
String.add_color_alias(extra_color_e: :gray, :extra_color_f => :blue)
|
|
197
|
+
|
|
198
|
+
assert_equal 'example string'.gray, 'example string'.extra_color_e
|
|
199
|
+
assert_equal 'example string'.on_blue, 'example string'.on_extra_color_f
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def test_prevent_colors
|
|
203
|
+
String.prevent_colors true
|
|
204
|
+
|
|
205
|
+
assert String.prevent_colors
|
|
206
|
+
assert_equal "#{'blue'.blue}#{'red'.red}#{'green'.green}", "#{'blue'.blue}red#{'green'.green}".red
|
|
207
|
+
|
|
208
|
+
String.prevent_colors false
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_colorized_string_without_readline
|
|
212
|
+
assert_equal "\e[0;31;49mgreen\e[0m".green, 'green'.green
|
|
10
213
|
end
|
|
11
214
|
end
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
require "#{File.dirname(__FILE__)}/../lib/colorized_string"
|
|
5
|
+
|
|
6
|
+
class TestColorizedString < Minitest::Test
|
|
7
|
+
def test_colorize_not_required
|
|
8
|
+
refute_respond_to '', :colorize, 'Colorize should not be required. Only colorized_string'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_blue_symbol
|
|
12
|
+
assert_equal "\001\033[0;34;49m\002This is blue\001\033[0m\002", ColorizedString['This is blue'].colorize(:blue)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_incorrect_symbol
|
|
16
|
+
assert_equal "\001\033[0;39;49m\002This is incorrect color\001\033[0m\002", ColorizedString['This is incorrect color'].colorize(:bold)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_incorrect_hash
|
|
20
|
+
assert_equal "\001\033[0;39;49m\002This is incorrect color\001\033[0m\002", ColorizedString['This is incorrect color'].colorize(:color => :bold)
|
|
21
|
+
|
|
22
|
+
assert_equal "\001\033[0;39;49m\002This is incorrect color\001\033[0m\002", ColorizedString['This is incorrect color'].colorize(:mode => :green)
|
|
23
|
+
|
|
24
|
+
assert_equal "\001\033[0;39;49m\002This is incorrect color\001\033[0m\002", ColorizedString['This is incorrect color'].colorize(:background => :bold)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_blue_hash
|
|
28
|
+
assert_equal "\001\033[0;34;49m\002This is also blue\001\033[0m\002", ColorizedString['This is also blue'].colorize(:color => :blue)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_light_blue_symbol
|
|
32
|
+
assert_equal "\001\033[0;94;49m\002This is light blue\001\033[0m\002", ColorizedString['This is light blue'].colorize(:light_blue)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_light_blue_with_red_background_hash
|
|
36
|
+
assert_equal "\001\033[0;94;41m\002This is light blue with red background\001\033[0m\002", ColorizedString['This is light blue with red background'].colorize(:color => :light_blue, :background => :red)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_light_blue_with_red_background_symbol_and_hash
|
|
40
|
+
assert_equal "\001\033[0;94;41m\002This is light blue with red background\001\033[0m\002", ColorizedString['This is light blue with red background'].colorize(:light_blue).colorize(:background => :red)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_blue_with_red_background_method
|
|
44
|
+
assert_equal "\001\033[0;34;41m\002This is blue text on red\001\033[0m\002", ColorizedString['This is blue text on red'].blue.on_red
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_red_with_blue_background_symbol_and_method
|
|
48
|
+
assert_equal "\001\033[0;31;44m\002This is red on blue\001\033[0m\002", ColorizedString['This is red on blue'].colorize(:red).on_blue
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_red_with_blue_background_and_underline_sumbol_and_methods
|
|
52
|
+
assert_equal "\001\033[4;31;44m\002This is red on blue and underline\001\033[0m\002", ColorizedString['This is red on blue and underline'].colorize(:red).on_blue.underline
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_blue_with_red_background_and_blink_methods
|
|
56
|
+
assert_equal "\001\033[5;34;41m\002This is blue text on red\001\033[0m\002", ColorizedString['This is blue text on red'].blue.on_red.blink
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_uncolorize
|
|
60
|
+
assert_equal 'This is uncolorized', ColorizedString['This is uncolorized'].blue.on_red.uncolorize
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def test_colorized?
|
|
64
|
+
assert_predicate ColorizedString['Red'].red, :colorized?
|
|
65
|
+
refute_predicate ColorizedString['Blue'], :colorized?
|
|
66
|
+
refute_predicate ColorizedString['Green'].blue.green.uncolorize, :colorized?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def test_concatenated__colorize?
|
|
70
|
+
assert_predicate ColorizedString["none #{ColorizedString['red'].red} none #{ColorizedString['blue'].blue} none"], :colorized?
|
|
71
|
+
refute_predicate ColorizedString["none #{ColorizedString['red'].red} none #{ColorizedString['blue'].blue} none"].uncolorize, :colorized?
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_concatenated_strings_on_green
|
|
75
|
+
assert_equal "\001\033[0;39;42m\002none \001\033[0m\002\001\033[0;31;42m\002red\001\033[0m\002\001\033[0;39;42m\002 none \001\033[0m\002\001\033[0;34;42m\002blue\001\033[0m\002\001\033[0;39;42m\002 none\001\033[0m\002", ColorizedString["none #{ColorizedString['red'].red} none #{ColorizedString['blue'].blue} none"].on_green
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_concatenated_strings_uncolorize
|
|
79
|
+
assert_equal 'none red none blue none', ColorizedString["none #{ColorizedString['red'].red} none #{ColorizedString['blue'].blue} none"].uncolorize
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_frozen_strings
|
|
83
|
+
assert_equal "\001\033[5;34;41m\002This is blue text on red\001\033[0m\002", ColorizedString['This is blue text on red'].freeze.blue.on_red.blink
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def test_new_line
|
|
87
|
+
assert_equal "\001\033[5;34;41m\002This is blue\ntext on red\001\033[0m\002", ColorizedString["This is blue\ntext on red"].freeze.blue.on_red.blink
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_disable_colorization_with_=
|
|
91
|
+
ColorizedString.disable_colorization = true
|
|
92
|
+
|
|
93
|
+
assert ColorizedString.disable_colorization
|
|
94
|
+
|
|
95
|
+
ColorizedString.disable_colorization = false
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_disable_colorization_with_method
|
|
99
|
+
ColorizedString.disable_colorization true
|
|
100
|
+
|
|
101
|
+
assert ColorizedString.disable_colorization
|
|
102
|
+
|
|
103
|
+
ColorizedString.disable_colorization false
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_string_disable_colorization_with_=
|
|
107
|
+
ColorizedString.disable_colorization = true
|
|
108
|
+
|
|
109
|
+
assert ColorizedString.disable_colorization
|
|
110
|
+
|
|
111
|
+
assert_equal 'This is blue after disabling', ColorizedString['This is blue after disabling'].blue
|
|
112
|
+
|
|
113
|
+
ColorizedString.disable_colorization = false
|
|
114
|
+
|
|
115
|
+
assert_equal "\001\033[0;34;49m\002This is blue after enabling\001\033[0m\002", ColorizedString['This is blue after enabling'].colorize(:blue)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_string_disable_colorization_with_method
|
|
119
|
+
assert_equal "\001\033[0;34;49m\002This is blue before disabling\001\033[0m\002", ColorizedString['This is blue before disabling'].colorize(:blue)
|
|
120
|
+
|
|
121
|
+
ColorizedString.disable_colorization true
|
|
122
|
+
|
|
123
|
+
assert ColorizedString.disable_colorization
|
|
124
|
+
|
|
125
|
+
assert_equal 'This is blue after disabling', ColorizedString['This is blue after disabling'].blue
|
|
126
|
+
|
|
127
|
+
ColorizedString.disable_colorization false
|
|
128
|
+
|
|
129
|
+
assert_equal "\001\033[0;34;49m\002This is blue after enabling\001\033[0m\002", ColorizedString['This is blue after enabling'].colorize(:blue)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def test_already_colored_string_with_one_value
|
|
133
|
+
assert_equal ColorizedString['This is red'].red, ColorizedString["\001\033[31m\002This is red\001\033[0m\002"].red
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_color_matrix_method
|
|
137
|
+
assert_raises(NoMethodError) { ColorizedString.color_matrix }
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def test_color_samples_method
|
|
141
|
+
assert_output do
|
|
142
|
+
ColorizedString.color_samples
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def test_grey_alias
|
|
147
|
+
assert_equal ColorizedString['This is grey'].grey, ColorizedString['This is grey'].light_black
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def test_gray_alias
|
|
151
|
+
assert_equal ColorizedString['This is gray'].gray, ColorizedString['This is gray'].light_black
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def test_add_color_alias
|
|
155
|
+
ColorizedString.add_color_alias(:extra_blue, :light_blue)
|
|
156
|
+
|
|
157
|
+
assert_equal ColorizedString['blue'].light_blue, ColorizedString['blue'].extra_blue
|
|
158
|
+
assert_equal ColorizedString['blue'].on_light_blue, ColorizedString['blue'].on_extra_blue
|
|
159
|
+
|
|
160
|
+
assert_raises ::Colorize::ColorAlreadyExist, 'Colorize: color :extra_blue already exist!' do
|
|
161
|
+
ColorizedString.add_color_alias(:extra_blue, :light_color)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
assert_raises ::Colorize::ColorDontExist, 'Colorize: color :light_color don\'t exist!' do
|
|
165
|
+
ColorizedString.add_color_alias(:extra_white, :light_color)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def test_add_color_alias_with_single_hash
|
|
170
|
+
ColorizedString.add_color_alias(extra_green: :light_green)
|
|
171
|
+
|
|
172
|
+
assert_equal ColorizedString['example string'].light_green, ColorizedString['example string'].extra_green
|
|
173
|
+
assert_equal ColorizedString['example string'].on_light_green, ColorizedString['example string'].on_extra_green
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def test_add_color_alias_with_single_hash_with_arrow
|
|
177
|
+
ColorizedString.add_color_alias(:extra_color => :gray)
|
|
178
|
+
|
|
179
|
+
assert_equal ColorizedString['example string'].gray, ColorizedString['example string'].extra_color
|
|
180
|
+
assert_equal ColorizedString['example string'].on_gray, ColorizedString['example string'].on_extra_color
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_add_color_alias_with_multi_hash
|
|
184
|
+
ColorizedString.add_color_alias(extra_color_a: :gray, extra_color_b: :blue)
|
|
185
|
+
|
|
186
|
+
assert_equal ColorizedString['example string'].gray, ColorizedString['example string'].extra_color_a
|
|
187
|
+
assert_equal ColorizedString['example string'].blue, ColorizedString['example string'].extra_color_b
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
def test_add_color_alias_with_multi_hash_with_arrow
|
|
191
|
+
ColorizedString.add_color_alias(:extra_color_c => :gray, :extra_color_d => :blue)
|
|
192
|
+
|
|
193
|
+
assert_equal ColorizedString['example string'].gray, ColorizedString['example string'].extra_color_c
|
|
194
|
+
assert_equal ColorizedString['example string'].on_blue, ColorizedString['example string'].on_extra_color_d
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def test_add_color_alias_with_multi_hash_mixed
|
|
198
|
+
ColorizedString.add_color_alias(extra_color_e: :gray, :extra_color_f => :blue)
|
|
199
|
+
|
|
200
|
+
assert_equal ColorizedString['example string'].gray, ColorizedString['example string'].extra_color_e
|
|
201
|
+
assert_equal ColorizedString['example string'].on_blue, ColorizedString['example string'].on_extra_color_f
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def test_prevent_colors
|
|
205
|
+
ColorizedString.prevent_colors true
|
|
206
|
+
|
|
207
|
+
assert ColorizedString.prevent_colors
|
|
208
|
+
assert_equal "#{ColorizedString['blue'].blue}#{ColorizedString['red'].red}#{ColorizedString['green'].green}", ColorizedString["#{ColorizedString['blue'].blue}red#{ColorizedString['green'].green}"].red
|
|
209
|
+
|
|
210
|
+
ColorizedString.prevent_colors false
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def test_colorized_string_without_readline
|
|
214
|
+
assert_equal ColorizedString["\e[0;31;49mgreen\e[0m"].green, ColorizedString['green'].green
|
|
215
|
+
end
|
|
216
|
+
end
|
metadata
CHANGED
|
@@ -1,64 +1,57 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: colorize
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
5
|
platform: ruby
|
|
6
|
-
authors:
|
|
7
|
-
-
|
|
8
|
-
autorequire:
|
|
6
|
+
authors:
|
|
7
|
+
- Michał Kalbarczyk
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
|
|
12
|
-
date: 2009-11-24 00:00:00 +01:00
|
|
13
|
-
default_executable:
|
|
11
|
+
date: 2023-06-19 00:00:00.000000000 Z
|
|
14
12
|
dependencies: []
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
description: Extends String class or add a ColorizedString with methods to set text
|
|
14
|
+
color, background color and text effects.
|
|
17
15
|
email: fazibear@gmail.com
|
|
18
16
|
executables: []
|
|
19
|
-
|
|
20
17
|
extensions: []
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
- .
|
|
26
|
-
- CHANGELOG.rdoc
|
|
27
|
-
- README.rdoc
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- CHANGELOG.md
|
|
21
|
+
- LICENSE
|
|
22
|
+
- README.md
|
|
28
23
|
- Rakefile
|
|
29
|
-
- VERSION
|
|
30
24
|
- colorize.gemspec
|
|
31
25
|
- lib/colorize.rb
|
|
26
|
+
- lib/colorize/class_methods.rb
|
|
27
|
+
- lib/colorize/errors.rb
|
|
28
|
+
- lib/colorize/instance_methods.rb
|
|
29
|
+
- lib/colorize/version.rb
|
|
30
|
+
- lib/colorized_string.rb
|
|
32
31
|
- test/test_colorize.rb
|
|
33
|
-
- test/
|
|
34
|
-
has_rdoc: true
|
|
32
|
+
- test/test_colorized_string.rb
|
|
35
33
|
homepage: http://github.com/fazibear/colorize
|
|
36
|
-
licenses:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
licenses:
|
|
35
|
+
- GPL-2.0
|
|
36
|
+
metadata:
|
|
37
|
+
rubygems_mfa_required: 'true'
|
|
38
|
+
post_install_message:
|
|
39
|
+
rdoc_options: []
|
|
40
|
+
require_paths:
|
|
42
41
|
- lib
|
|
43
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
45
44
|
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
requirements:
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '2.6'
|
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
51
49
|
- - ">="
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version:
|
|
54
|
-
version:
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
55
52
|
requirements: []
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
summary: Add colors methods to string class
|
|
62
|
-
test_files:
|
|
63
|
-
- test/test_helper.rb
|
|
64
|
-
- test/test_colorize.rb
|
|
53
|
+
rubygems_version: 3.4.14
|
|
54
|
+
signing_key:
|
|
55
|
+
specification_version: 4
|
|
56
|
+
summary: Ruby gem for colorizing text using ANSI escape sequences.
|
|
57
|
+
test_files: []
|
data/.gitignore
DELETED
data/CHANGELOG.rdoc
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
== 0.5.7 / 2000-11-24
|
|
2
|
-
* moved to github/gemcutter
|
|
3
|
-
* 1.9 compatibile
|
|
4
|
-
|
|
5
|
-
== 0.5.6 / 2007-08-27
|
|
6
|
-
* rdocs Allison template
|
|
7
|
-
* cleanups
|
|
8
|
-
|
|
9
|
-
== 0.5.5 / 2007-08-11
|
|
10
|
-
* added effects methods
|
|
11
|
-
* readme files
|
|
12
|
-
* new rake file
|
|
13
|
-
|
|
14
|
-
== 0.5.0 / 2007-04-22
|
|
15
|
-
* initial rewrited version
|
data/README.rdoc
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
== colorize
|
|
2
|
-
http://colorize.rubyforge.org
|
|
3
|
-
http://fazibear.prv.pl
|
|
4
|
-
|
|
5
|
-
== DESCRIPTION:
|
|
6
|
-
|
|
7
|
-
Ruby string class extension. It add some methods to set color, background color and text effect on console easier. Uses ANSI escape sequences.
|
|
8
|
-
|
|
9
|
-
== FEATURES/PROBLEMS:
|
|
10
|
-
|
|
11
|
-
* change string color
|
|
12
|
-
* change string background
|
|
13
|
-
* change string effect
|
|
14
|
-
|
|
15
|
-
== SYNOPSIS:
|
|
16
|
-
|
|
17
|
-
Some usage samples:
|
|
18
|
-
|
|
19
|
-
puts "This is blue".colorize( :blue )
|
|
20
|
-
puts "This is light blue".colorize( :light_blue )
|
|
21
|
-
puts "This is also blue".colorize( :color => :blue )
|
|
22
|
-
puts "This is blue with red background".colorize( :color => :light_blue, :background => :red )
|
|
23
|
-
puts "This is blue with red background".colorize( :light_blue ).colorize( :background => :red )
|
|
24
|
-
puts "This is blue text on red".blue.on_red
|
|
25
|
-
puts "This is red on blue".colorize( :red ).on_blue
|
|
26
|
-
puts "This is uncolorized".blue.on_red.uncolorize
|
|
27
|
-
puts "This is red on blue and underline".colorize( :red ).on_blue.underline
|
|
28
|
-
puts "This is blue text on red".blue.on_red.blink
|
|
29
|
-
|
|
30
|
-
Class methods:
|
|
31
|
-
|
|
32
|
-
String.colors - return array of all possible colors names
|
|
33
|
-
String.modes - return array of all possible modes
|
|
34
|
-
String.color_matrix - displays color matrix with color names
|
|
35
|
-
String.color_matrix( "FOO" ) - display color matrix with "FOO" text
|
|
36
|
-
|
|
37
|
-
== REQUIREMENTS:
|
|
38
|
-
|
|
39
|
-
* Win32/Console/ANSI (for Windows)
|
|
40
|
-
|
|
41
|
-
== INSTALL:
|
|
42
|
-
|
|
43
|
-
* sudo gem install colorize
|
|
44
|
-
|
|
45
|
-
== LICENSE:
|
|
46
|
-
|
|
47
|
-
colorize - Ruby string class extension. It add some methods to set color, background color and text effect on console easier using ANSI escape sequences.
|
|
48
|
-
|
|
49
|
-
Copyright (C) 2007 Michal Kalbarczyk
|
|
50
|
-
|
|
51
|
-
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
|
|
52
|
-
|
|
53
|
-
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
54
|
-
|
|
55
|
-
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
data/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
0.5.7
|
data/test/test_helper.rb
DELETED