simplecolor 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +20 -0
- data/.travis.yml +7 -4
- data/ChangeLog.md +140 -2
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/TODO +2 -0
- data/bin/simplecolor.rb +50 -30
- data/lib/simplecolor.rb +17 -10
- data/lib/simplecolor/colorer.rb +3 -1
- data/lib/simplecolor/rgb_colors.rb +1 -1
- data/lib/simplecolor/version.rb +1 -1
- data/test/test_rgb.rb +36 -36
- data/test/test_simplecolor.rb +72 -72
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abed8ef92e28a61aee2c138607ec7e60b693130c2895257ed616dc0e3b2ab832
|
4
|
+
data.tar.gz: 2c06735714e16b94505e0d353261807d1183f6045bf38a1e0bd844da7ec7ecc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0de099a4abfca75531daeeb03a4a036383ae65f6838323ebd16a4dd7004aefc0072efaa8ee6344fea4b8461629595d029f4b344c33501f179a9232b2218d47a7
|
7
|
+
data.tar.gz: b7272f90678ed239b0d36a8e770057f6908bc62d572ae70c52198640f36d98ca3b07b73c1f6cfe1dbc09a34157291a6374e5f413d2fa2ae034e52d4f9cc5c867
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
strategy:
|
7
|
+
fail-fast: false
|
8
|
+
matrix:
|
9
|
+
os: [ ubuntu-latest, macos-latest ]
|
10
|
+
ruby: [ 2.4, 2.5, 2.6, 2.7, jruby, truffleruby ]
|
11
|
+
runs-on: ${{ matrix.os }}
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby }}
|
17
|
+
- run: |
|
18
|
+
gem install bundler
|
19
|
+
bundle install --jobs 4 --retry 3
|
20
|
+
bundle exec rake test
|
data/.travis.yml
CHANGED
data/ChangeLog.md
CHANGED
@@ -1,4 +1,142 @@
|
|
1
|
-
|
1
|
+
== Release v0.4.0 (2020-02-26) ==
|
2
2
|
|
3
|
-
*
|
3
|
+
* Fix ruby 2.3 bug
|
4
|
+
* Fix a truffleruby bug
|
5
|
+
* Fix minitest warnings
|
6
|
+
* Add rgb_colors.json.gz
|
7
|
+
* Support old ruby versions
|
8
|
+
* Update for ruby 2.7
|
9
|
+
* Add todo
|
10
|
+
* bin/simplecolor: showcase now show more about the base colors
|
11
|
+
|
12
|
+
== Release v0.3.0 (2019-05-02) ==
|
13
|
+
|
14
|
+
* Update Readme
|
15
|
+
* color schemes: move to data/
|
16
|
+
* Add tests for color names
|
17
|
+
* Add lots of color names
|
18
|
+
* More tests
|
19
|
+
* Add tests for local_color/global_color
|
20
|
+
* Replace colorer by colorer2
|
21
|
+
* colorer2: bug fixes
|
22
|
+
* colorer2: better global color detection
|
23
|
+
* colorer2
|
24
|
+
* Add test
|
25
|
+
* attributes_from_colors: support 256 and truecolors
|
26
|
+
* SimpleColor[]
|
27
|
+
* Add :color0 ... :color15
|
28
|
+
* RGB: fix color conversion
|
29
|
+
* Abstract 8/16 color palette
|
30
|
+
* Rgb color names can by symbols
|
31
|
+
* Effects
|
32
|
+
* RGB: can specify default @background
|
33
|
+
* RGB.to_hex
|
34
|
+
* Rename rgb_constants to rgb_colors
|
35
|
+
* SimpleColor.fill
|
36
|
+
* Color names: use a constant
|
37
|
+
* RGB: custom color names
|
38
|
+
* Color names
|
39
|
+
* Random: this is a rgb color rather than an abbreviation
|
40
|
+
* colorer: better recursive handling
|
41
|
+
* Change names of options
|
42
|
+
* Put Colorer in its own fle
|
43
|
+
* Rework the way we construct mixins
|
44
|
+
* Move constants around
|
45
|
+
* Color names: use a Proc
|
46
|
+
* Fixing all tests!
|
47
|
+
* Use constants
|
48
|
+
* More bug fixes
|
49
|
+
* Misc bug fixes
|
50
|
+
* Use new RGB class
|
51
|
+
* Class RGB
|
52
|
+
* Begin new RGB class
|
53
|
+
* New key: colornames
|
54
|
+
* Showcase + solarized shortcut
|
55
|
+
* Bug fixes + tests
|
56
|
+
* bin: --color=number
|
57
|
+
* Add binary
|
58
|
+
* Correctly dup arg
|
59
|
+
* proc in color: return multiple values
|
60
|
+
* Small tweak
|
61
|
+
* Test proc
|
62
|
+
* Add :random, :on_random shortcuts
|
63
|
+
* test: simplify resetting default options
|
64
|
+
* rgb color: support background mode with Array
|
65
|
+
* color_module: copy current options
|
66
|
+
* Shortcuts: be more general
|
67
|
+
* Fix test
|
68
|
+
* Shortcuts
|
69
|
+
* tests
|
70
|
+
* Color names: switch to json data
|
71
|
+
* Improve regexp
|
72
|
+
* Fixes for 256 colors
|
73
|
+
* Add Hex mode
|
74
|
+
* Raise when passed non supported parameters
|
75
|
+
* Add color_mode parameter
|
76
|
+
* 256 colors
|
77
|
+
* Continue rgb handling
|
78
|
+
* Update Rakefile
|
79
|
+
* Rakefile: add mapping
|
80
|
+
* Update Rakefile
|
81
|
+
* Add rgb.rb, from the paint gem
|
82
|
+
* Preliminary for truecolor support
|
83
|
+
* SimpleColor.color_strings
|
84
|
+
* color_module: shortcuts
|
85
|
+
* Add tests
|
86
|
+
* Generate new coloring module
|
87
|
+
* enabled should be a singleton method
|
88
|
+
* Add tests
|
89
|
+
* uncolor, color?: work in shell mode
|
90
|
+
* Add mixin.rb to help mix in String
|
91
|
+
* Copyright
|
92
|
+
* Whitespace
|
93
|
+
|
94
|
+
== Release v0.2.0 (2017-02-20) ==
|
95
|
+
|
96
|
+
* Add minitest dependency
|
97
|
+
* Fix binary strings
|
98
|
+
* Correct a bug on uncolor when there was no colors
|
99
|
+
* attribute_from_colors
|
100
|
+
* Bugfixes
|
101
|
+
* Better color regexps
|
102
|
+
* Bug fixes
|
103
|
+
* Mix attributes and ANSI strings
|
104
|
+
* Color entities and add tests
|
105
|
+
* Typos
|
106
|
+
* function to handle existing colors
|
107
|
+
* Concatenate ANSI escape sequences inside the \e
|
108
|
+
* Add possibility to copy colors
|
109
|
+
* Sometimes \e[m is abused for \e[0m
|
110
|
+
* More exceptions
|
111
|
+
* Merge some color regexp and raise exception on bogus colors
|
112
|
+
* Fix SimpleColor#uncolor!
|
113
|
+
* Change ANSI Regexps
|
114
|
+
* rake doc fails for now with Rake 11
|
115
|
+
* Add uncolor tests
|
116
|
+
* ColorWrapper: unify gestion of arg
|
117
|
+
* Correct a bug in uncolor
|
118
|
+
* Add more tests
|
119
|
+
* Add color! and uncolor!
|
120
|
+
* Specify mode even when nothing is passed
|
121
|
+
* Add color?
|
122
|
+
* Add more tests
|
123
|
+
* Split the module into small unit modules
|
124
|
+
* Add warning to use v0.1.0
|
125
|
+
* First step to add a Colorer class
|
126
|
+
* typo
|
127
|
+
* Put simplecolor.rb in lib/ rather than lib/simplecolor/
|
128
|
+
* Improve documentation
|
129
|
+
* Describe SimpleColor.enabled
|
130
|
+
* sh code block
|
131
|
+
* README: use code block
|
132
|
+
* Adding a simple test
|
133
|
+
* Shortcut for mixing in class
|
134
|
+
* Update homepage
|
135
|
+
|
136
|
+
== Release v0.1.0 (2013-08-23) ==
|
137
|
+
|
138
|
+
* Add more ANSI effects
|
139
|
+
* Update documentation
|
140
|
+
* First public version
|
141
|
+
* Initial commit.
|
4
142
|
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
data/TODO
ADDED
data/bin/simplecolor.rb
CHANGED
@@ -3,6 +3,30 @@
|
|
3
3
|
require 'simplecolor/mixin'
|
4
4
|
require 'optparse'
|
5
5
|
|
6
|
+
def solarized
|
7
|
+
puts
|
8
|
+
print "Solarized on light background: ".color("solarized_base00", "on_solarized_base3")
|
9
|
+
%w(yellow orange red magenta violet blue cyan green).each do |col|
|
10
|
+
print "#{col} ".color("solarized_#{col}", "on_solarized_base3")
|
11
|
+
end
|
12
|
+
puts
|
13
|
+
print "Solarized on dark background: ".color("solarized_base0", "on_solarized_base03")
|
14
|
+
%w(yellow orange red magenta violet blue cyan green).each do |col|
|
15
|
+
print "#{col} ".color("solarized_#{col}", "on_solarized_base03")
|
16
|
+
end
|
17
|
+
puts
|
18
|
+
[3, 2, 1, 0].each do |on|
|
19
|
+
(0..3).each do |cin|
|
20
|
+
puts SimpleColor.fill("Solarized color base0#{cin} on base#{on}").color("solarized_base0#{cin}", "on_solarized_base#{on}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
[3, 2, 1, 0].each do |on|
|
24
|
+
(0..3).each do |cin|
|
25
|
+
puts SimpleColor.fill("Solarized color base#{cin} on base0#{on}").color("solarized_base#{cin}", "on_solarized_base0#{on}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
6
30
|
def showcase
|
7
31
|
empty=" "
|
8
32
|
lorem="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
|
@@ -45,19 +69,20 @@ def showcase
|
|
45
69
|
puts
|
46
70
|
puts
|
47
71
|
|
48
|
-
|
49
|
-
(40..47).each do |color|
|
50
|
-
print SimpleColor.color(empty, color)
|
51
|
-
end
|
52
|
-
print " = "
|
72
|
+
print "Background system palette:"
|
53
73
|
%w(black red green yellow blue magenta cyan white).each do |s|
|
54
74
|
print SimpleColor.color(empty, "on_#{s}".to_sym);
|
55
75
|
end
|
56
|
-
|
76
|
+
## This is simply:
|
77
|
+
# (40..47).each do |color|
|
78
|
+
# print SimpleColor.color(empty, color)
|
79
|
+
# end
|
80
|
+
## (:bold does not change the background color)
|
57
81
|
# (40..47).each do |color|
|
58
82
|
# print SimpleColor.color(empty, color, :bold)
|
59
83
|
# end
|
60
|
-
puts
|
84
|
+
puts
|
85
|
+
print "High intensity background system palette:"
|
61
86
|
(90..97).each do |color|
|
62
87
|
print SimpleColor.color(empty, color)
|
63
88
|
end
|
@@ -72,6 +97,15 @@ def showcase
|
|
72
97
|
print "back to default background."
|
73
98
|
puts
|
74
99
|
puts
|
100
|
+
names=%w(black red green yellow blue magenta cyan white)
|
101
|
+
names+=names.map {|i| "intense_#{i}"}
|
102
|
+
columns=ENV['COLUMN']&.to_i || 80
|
103
|
+
(0..15).each do |i|
|
104
|
+
color=names[i]
|
105
|
+
rgb=SimpleColor::RGB.new(i, mode: 16)
|
106
|
+
printf "Color%02d = %s %-30s %s\n".color(color.to_sym), i, rgb.to_hex, color, (" "*(columns-49)).color("on_#{color}".to_sym)
|
107
|
+
end
|
108
|
+
puts
|
75
109
|
|
76
110
|
puts "* 256 colors:"
|
77
111
|
puts "System palette:";
|
@@ -131,28 +165,6 @@ def showcase
|
|
131
165
|
print SimpleColor.clear
|
132
166
|
puts
|
133
167
|
|
134
|
-
puts
|
135
|
-
print "Solarized on light background: ".color("solarized_base00", "on_solarized_base3")
|
136
|
-
%w(yellow orange red magenta violet blue cyan green).each do |col|
|
137
|
-
print "#{col} ".color("solarized_#{col}", "on_solarized_base3")
|
138
|
-
end
|
139
|
-
puts
|
140
|
-
print "Solarized on dark background: ".color("solarized_base0", "on_solarized_base03")
|
141
|
-
%w(yellow orange red magenta violet blue cyan green).each do |col|
|
142
|
-
print "#{col} ".color("solarized_#{col}", "on_solarized_base03")
|
143
|
-
end
|
144
|
-
puts
|
145
|
-
[3, 2, 1, 0].each do |on|
|
146
|
-
(0..3).each do |cin|
|
147
|
-
puts SimpleColor.fill("Solarized color base0#{cin} on base#{on}").color("solarized_base0#{cin}", "on_solarized_base#{on}")
|
148
|
-
end
|
149
|
-
end
|
150
|
-
[3, 2, 1, 0].each do |on|
|
151
|
-
(0..3).each do |cin|
|
152
|
-
puts SimpleColor.fill("Solarized color base#{cin} on base0#{on}").color("solarized_base#{cin}", "on_solarized_base0#{on}")
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
168
|
puts
|
157
169
|
cube= ->(start, to_end) do
|
158
170
|
direction=(0..2).map {|i| to_end[i]-start[i]}
|
@@ -185,6 +197,7 @@ def showcase
|
|
185
197
|
|
186
198
|
print_cube[[0,1,0],[0,1,1], [0,0,1]]
|
187
199
|
|
200
|
+
puts
|
188
201
|
puts "* Effects"
|
189
202
|
effects=SimpleColor::Colorer::ANSI_EFFECTS
|
190
203
|
effects.values.uniq.each do |v|
|
@@ -196,15 +209,22 @@ def showcase
|
|
196
209
|
puts "- #{eff.join('/')}: " + "lorem ipsum".color(v)
|
197
210
|
end
|
198
211
|
end
|
212
|
+
|
213
|
+
puts
|
214
|
+
puts "* Terminfo effects"
|
215
|
+
print "- Italic: "; system('tput sitm'); print "lorem ipsum"; system('tput ritm')
|
199
216
|
end
|
200
217
|
|
201
218
|
optparse = OptionParser.new do |opt|
|
202
219
|
opt.on("--color=number", "-c", "Set number of colors", Integer) do |v|
|
203
220
|
SimpleColor.color_mode=v
|
204
221
|
end
|
205
|
-
opt.on("--showcase", "Showcase color capabilities of terminal") do |_v|
|
222
|
+
opt.on("--showcase", "-s", "Showcase color capabilities of terminal") do |_v|
|
206
223
|
showcase
|
207
224
|
end
|
225
|
+
opt.on("--solarized", "Show solarized colors") do |_v|
|
226
|
+
solarized
|
227
|
+
end
|
208
228
|
end
|
209
229
|
optparse.parse!
|
210
230
|
|
data/lib/simplecolor.rb
CHANGED
@@ -30,7 +30,7 @@ module SimpleColor
|
|
30
30
|
# SimpleColor.color(:blue,:bold) { "blue" }
|
31
31
|
# SimpleColor.color(:blue,:bold) << "blue" << SimpleColor.color(:clear)
|
32
32
|
%i(color uncolor color! uncolor! color?).each do |m|
|
33
|
-
define_method m do |*args, &b|
|
33
|
+
define_method m do |*args, **kwds, &b|
|
34
34
|
arg=if b
|
35
35
|
b.call.to_s
|
36
36
|
elsif respond_to?(:to_str)
|
@@ -47,15 +47,19 @@ module SimpleColor
|
|
47
47
|
end
|
48
48
|
case m
|
49
49
|
when :color
|
50
|
-
|
50
|
+
# the rescue is here for ruby 2.3 which can't dup Nilclass.
|
51
|
+
# Newer versions of ruby don't need it
|
52
|
+
duped = arg.dup rescue arg
|
53
|
+
Colorer.colorer(duped,*args,**kwds)
|
51
54
|
when :uncolor
|
52
|
-
|
55
|
+
duped = arg.dup rescue arg
|
56
|
+
Colorer.uncolorer(duped,*args,**kwds)
|
53
57
|
when :color!
|
54
|
-
Colorer.colorer(arg,*args)
|
58
|
+
Colorer.colorer(arg,*args,**kwds)
|
55
59
|
when :uncolor!
|
56
|
-
Colorer.uncolorer(arg,*args)
|
60
|
+
Colorer.uncolorer(arg,*args,**kwds)
|
57
61
|
when :color?
|
58
|
-
Colorer.colored?(arg,*args)
|
62
|
+
Colorer.colored?(arg,*args,**kwds)
|
59
63
|
end
|
60
64
|
end
|
61
65
|
end
|
@@ -180,10 +184,13 @@ module SimpleColor
|
|
180
184
|
def self.define_color_methods(klass, *methods, opts_from: nil, color_module: ColorWrapper)
|
181
185
|
methods=color_module.instance_methods if methods.empty?
|
182
186
|
methods.each do |m|
|
183
|
-
klass.define_method m do |*args, **l_opts, &b|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
+
# klass.define_method m do |*args, **l_opts, &b|
|
188
|
+
klass.class_eval do
|
189
|
+
define_method m do |*args, **l_opts, &b|
|
190
|
+
opts= opts_from ? opts_from.opts : self.opts
|
191
|
+
opts=opts.merge(l_opts)
|
192
|
+
color_module.instance_method(m).bind(self).call(*args, **opts, &b)
|
193
|
+
end
|
187
194
|
end
|
188
195
|
end
|
189
196
|
end
|
data/lib/simplecolor/colorer.rb
CHANGED
@@ -39,7 +39,9 @@ module SimpleColor
|
|
39
39
|
symbol=s.is_a?(Symbol)
|
40
40
|
truecol=/(?<truecol>(?:truecolor|true|t):)?/
|
41
41
|
on=/(?<on>on_)?/
|
42
|
-
|
42
|
+
# the to_s is because of a bug in truffleruby where
|
43
|
+
# `s.match(...) do end` does not work with symbols
|
44
|
+
s.to_s.match(/\A#{truecol}#{on}(?<rest>.*)\z/) do |m|
|
43
45
|
tcol=m[:truecol]; on=m[:on]; string=m[:rest]
|
44
46
|
lcolormode = tcol ? :truecolor : color_mode
|
45
47
|
string=string.to_sym if symbol
|
data/lib/simplecolor/version.rb
CHANGED
data/test/test_rgb.rb
CHANGED
@@ -3,33 +3,33 @@ require 'simplecolor'
|
|
3
3
|
|
4
4
|
describe SimpleColor::RGB do
|
5
5
|
it "Should output truecolor code" do
|
6
|
-
SimpleColor::RGB.new(10,20,30).ansi.must_equal "38;2;10;20;30"
|
6
|
+
_(SimpleColor::RGB.new(10,20,30).ansi).must_equal "38;2;10;20;30"
|
7
7
|
end
|
8
8
|
it "Can degrade to 256 colors" do
|
9
|
-
SimpleColor::RGB.new(10,20,30).convert(256).ansi.must_equal "38;5;234"
|
9
|
+
_(SimpleColor::RGB.new(10,20,30).convert(256).ansi).must_equal "38;5;234"
|
10
10
|
end
|
11
11
|
it "Can degrade to 16 colors" do
|
12
|
-
SimpleColor::RGB.new(10,20,160).convert(16).ansi.must_equal "34"
|
12
|
+
_(SimpleColor::RGB.new(10,20,160).convert(16).ansi).must_equal "34"
|
13
13
|
end
|
14
14
|
it "Can degrade to 8 colors" do
|
15
|
-
SimpleColor::RGB.new(10,20,30).convert(8).ansi.must_equal "30"
|
15
|
+
_(SimpleColor::RGB.new(10,20,30).convert(8).ansi).must_equal "30"
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "List name" do
|
19
19
|
it "Can specify color names" do
|
20
|
-
SimpleColor::RGB.parse("lavender").to_hex.must_equal "#9F90D0"
|
20
|
+
_(SimpleColor::RGB.parse("lavender").to_hex).must_equal "#9F90D0"
|
21
21
|
end
|
22
22
|
it "Can specify the dict to use for color names" do
|
23
|
-
SimpleColor::RGB.parse("x11:lavender").to_hex.must_equal "#E6E6FA"
|
23
|
+
_(SimpleColor::RGB.parse("x11:lavender").to_hex).must_equal "#E6E6FA"
|
24
24
|
end
|
25
25
|
it "Can use custom names" do
|
26
|
-
SimpleColor::RGB.parse("solarized_base03").to_hex.must_equal "#002B36"
|
26
|
+
_(SimpleColor::RGB.parse("solarized_base03").to_hex).must_equal "#002B36"
|
27
27
|
end
|
28
28
|
it "Custom names have precedence" do
|
29
|
-
SimpleColor::RGB.parse("verydarkbluishgreen").to_hex.must_equal "#002A29"
|
29
|
+
_(SimpleColor::RGB.parse("verydarkbluishgreen").to_hex).must_equal "#002A29"
|
30
30
|
SimpleColor::RGB.color_names["verydarkbluishgreen"]="#002B30"
|
31
|
-
SimpleColor::RGB.parse("verydarkbluishgreen").to_hex.must_equal "#002B30"
|
32
|
-
SimpleColor::RGB.parse("nbs:verydarkbluishgreen").to_hex.must_equal "#002A29"
|
31
|
+
_(SimpleColor::RGB.parse("verydarkbluishgreen").to_hex).must_equal "#002B30"
|
32
|
+
_(SimpleColor::RGB.parse("nbs:verydarkbluishgreen").to_hex).must_equal "#002A29"
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -40,37 +40,37 @@ describe SimpleColor do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "Can parse a true color name" do
|
43
|
-
SimpleColor.color("foo", "rgb:10-20-30").must_equal "\e[38;2;10;20;30mfoo\e[0m"
|
44
|
-
SimpleColor.color("foo", "10-20-30").must_equal "\e[38;2;10;20;30mfoo\e[0m"
|
45
|
-
SimpleColor.color("foo", "10:20:30").must_equal "\e[38;2;10;20;30mfoo\e[0m"
|
46
|
-
SimpleColor.color("foo", [10, 20, 30]).must_equal "\e[38;2;10;20;30mfoo\e[0m"
|
43
|
+
_(SimpleColor.color("foo", "rgb:10-20-30")).must_equal "\e[38;2;10;20;30mfoo\e[0m"
|
44
|
+
_(SimpleColor.color("foo", "10-20-30")).must_equal "\e[38;2;10;20;30mfoo\e[0m"
|
45
|
+
_(SimpleColor.color("foo", "10:20:30")).must_equal "\e[38;2;10;20;30mfoo\e[0m"
|
46
|
+
_(SimpleColor.color("foo", [10, 20, 30])).must_equal "\e[38;2;10;20;30mfoo\e[0m"
|
47
47
|
end
|
48
48
|
|
49
49
|
it "Can specify 256 colors" do
|
50
|
-
SimpleColor.color("foo", "rgb256:1-2-3").must_equal "\e[38;5;67mfoo\e[0m"
|
51
|
-
SimpleColor.color("foo", "256:1-2-3").must_equal "\e[38;5;67mfoo\e[0m"
|
52
|
-
SimpleColor.color("foo", "256:grey1").must_equal "\e[38;5;233mfoo\e[0m"
|
53
|
-
SimpleColor.color("foo", "256:10").must_equal "\e[38;5;10mfoo\e[0m"
|
50
|
+
_(SimpleColor.color("foo", "rgb256:1-2-3")).must_equal "\e[38;5;67mfoo\e[0m"
|
51
|
+
_(SimpleColor.color("foo", "256:1-2-3")).must_equal "\e[38;5;67mfoo\e[0m"
|
52
|
+
_(SimpleColor.color("foo", "256:grey1")).must_equal "\e[38;5;233mfoo\e[0m"
|
53
|
+
_(SimpleColor.color("foo", "256:10")).must_equal "\e[38;5;10mfoo\e[0m"
|
54
54
|
end
|
55
55
|
|
56
56
|
it "Can specify hexa color name" do
|
57
|
-
SimpleColor.color("foo", "#10AABB").must_equal "\e[38;2;16;170;187mfoo\e[0m"
|
58
|
-
SimpleColor.color("foo", "#1AB").must_equal "\e[38;2;17;170;187mfoo\e[0m"
|
57
|
+
_(SimpleColor.color("foo", "#10AABB")).must_equal "\e[38;2;16;170;187mfoo\e[0m"
|
58
|
+
_(SimpleColor.color("foo", "#1AB")).must_equal "\e[38;2;17;170;187mfoo\e[0m"
|
59
59
|
end
|
60
60
|
|
61
61
|
it "Can specify x11 color name" do
|
62
|
-
SimpleColor.color("foo", "Lemon Chiffon").must_equal "\e[38;2;255;250;205mfoo\e[0m"
|
63
|
-
SimpleColor.color("foo", "lemonchiffon").must_equal "\e[38;2;255;250;205mfoo\e[0m"
|
62
|
+
_(SimpleColor.color("foo", "Lemon Chiffon")).must_equal "\e[38;2;255;250;205mfoo\e[0m"
|
63
|
+
_(SimpleColor.color("foo", "lemonchiffon")).must_equal "\e[38;2;255;250;205mfoo\e[0m"
|
64
64
|
end
|
65
65
|
|
66
66
|
it "Can specify background color name" do
|
67
|
-
SimpleColor.color("foo", "on_lemonchiffon").must_equal "\e[48;2;255;250;205mfoo\e[0m"
|
68
|
-
SimpleColor.color("foo", "on_rgb:255+250+205").must_equal "\e[48;2;255;250;205mfoo\e[0m"
|
69
|
-
SimpleColor.color("foo", "on_#CCBBAA").must_equal "\e[48;2;204;187;170mfoo\e[0m"
|
70
|
-
SimpleColor.color("foo", "on_rgb256:1+2+3").must_equal "\e[48;5;67mfoo\e[0m"
|
71
|
-
SimpleColor.color("foo", "on_rgb256:1").must_equal "\e[48;5;1mfoo\e[0m"
|
72
|
-
SimpleColor.color("foo", "on_rgb256:gray1").must_equal "\e[48;5;233mfoo\e[0m"
|
73
|
-
SimpleColor.color("foo", [:on, 10, 20, 30]).must_equal "\e[48;2;10;20;30mfoo\e[0m"
|
67
|
+
_(SimpleColor.color("foo", "on_lemonchiffon")).must_equal "\e[48;2;255;250;205mfoo\e[0m"
|
68
|
+
_(SimpleColor.color("foo", "on_rgb:255+250+205")).must_equal "\e[48;2;255;250;205mfoo\e[0m"
|
69
|
+
_(SimpleColor.color("foo", "on_#CCBBAA")).must_equal "\e[48;2;204;187;170mfoo\e[0m"
|
70
|
+
_(SimpleColor.color("foo", "on_rgb256:1+2+3")).must_equal "\e[48;5;67mfoo\e[0m"
|
71
|
+
_(SimpleColor.color("foo", "on_rgb256:1")).must_equal "\e[48;5;1mfoo\e[0m"
|
72
|
+
_(SimpleColor.color("foo", "on_rgb256:gray1")).must_equal "\e[48;5;233mfoo\e[0m"
|
73
|
+
_(SimpleColor.color("foo", [:on, 10, 20, 30])).must_equal "\e[48;2;10;20;30mfoo\e[0m"
|
74
74
|
end
|
75
75
|
|
76
76
|
describe "It can fallback to 256 colors" do
|
@@ -79,14 +79,14 @@ describe SimpleColor do
|
|
79
79
|
end
|
80
80
|
|
81
81
|
it "Can specify x11 color name" do
|
82
|
-
SimpleColor.color("foo", "Lemon Chiffon").must_equal "\e[38;5;230mfoo\e[0m"
|
83
|
-
SimpleColor.color("foo", "on_Lemon Chiffon").must_equal "\e[48;5;230mfoo\e[0m"
|
82
|
+
_(SimpleColor.color("foo", "Lemon Chiffon")).must_equal "\e[38;5;230mfoo\e[0m"
|
83
|
+
_(SimpleColor.color("foo", "on_Lemon Chiffon")).must_equal "\e[48;5;230mfoo\e[0m"
|
84
84
|
end
|
85
85
|
|
86
86
|
it "Can be forced to be truecolor" do
|
87
|
-
SimpleColor.color("foo", "t:Lemon Chiffon").must_equal "\e[38;2;255;250;205mfoo\e[0m"
|
88
|
-
SimpleColor.color("foo", "truecolor:Lemon Chiffon").must_equal "\e[38;2;255;250;205mfoo\e[0m"
|
89
|
-
SimpleColor.color("foo", "true:on_Lemon Chiffon").must_equal "\e[48;2;255;250;205mfoo\e[0m"
|
87
|
+
_(SimpleColor.color("foo", "t:Lemon Chiffon")).must_equal "\e[38;2;255;250;205mfoo\e[0m"
|
88
|
+
_(SimpleColor.color("foo", "truecolor:Lemon Chiffon")).must_equal "\e[38;2;255;250;205mfoo\e[0m"
|
89
|
+
_(SimpleColor.color("foo", "true:on_Lemon Chiffon")).must_equal "\e[48;2;255;250;205mfoo\e[0m"
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
@@ -96,8 +96,8 @@ describe SimpleColor do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it "Can specify x11 color name" do
|
99
|
-
SimpleColor.color("foo", "Lemon Chiffon").must_equal "\e[37mfoo\e[0m"
|
100
|
-
SimpleColor.color("foo", "on_Lemon Chiffon").must_equal "\e[47mfoo\e[0m"
|
99
|
+
_(SimpleColor.color("foo", "Lemon Chiffon")).must_equal "\e[37mfoo\e[0m"
|
100
|
+
_(SimpleColor.color("foo", "on_Lemon Chiffon")).must_equal "\e[47mfoo\e[0m"
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
data/test/test_simplecolor.rb
CHANGED
@@ -14,60 +14,60 @@ describe SimpleColor do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it "Can be used directly" do
|
17
|
-
SimpleColor.color("red",:red).must_equal "\e[31mred\e[0m"
|
17
|
+
_(SimpleColor.color("red",:red)).must_equal "\e[31mred\e[0m"
|
18
18
|
end
|
19
19
|
|
20
20
|
it "Can specify several colors" do
|
21
|
-
SimpleColor.color("red",:red,:bold).must_equal "\e[31;1mred\e[0m"
|
21
|
+
_(SimpleColor.color("red",:red,:bold)).must_equal "\e[31;1mred\e[0m"
|
22
22
|
end
|
23
23
|
|
24
24
|
it "Accepts ANSI sequences" do
|
25
|
-
SimpleColor.color("red","\e[31;1m").must_equal "\e[31;1mred\e[0m"
|
25
|
+
_(SimpleColor.color("red","\e[31;1m")).must_equal "\e[31;1mred\e[0m"
|
26
26
|
end
|
27
27
|
|
28
28
|
it "Can mix ANSI sequences and attributes" do
|
29
|
-
SimpleColor.color("red",:inverse,"\e[31m",:blue,:bold).must_equal "\e[7m\e[31m\e[34;1mred\e[0m"
|
29
|
+
_(SimpleColor.color("red",:inverse,"\e[31m",:blue,:bold)).must_equal "\e[7m\e[31m\e[34;1mred\e[0m"
|
30
30
|
end
|
31
31
|
|
32
32
|
it "Can take a block" do
|
33
|
-
SimpleColor.color(:red) { "red" }.must_equal "\e[31mred\e[0m"
|
33
|
+
_(SimpleColor.color(:red) { "red" }).must_equal "\e[31mred\e[0m"
|
34
34
|
end
|
35
35
|
|
36
36
|
it "Can provide only color values" do
|
37
|
-
SimpleColor.color(:red).must_equal "\e[31m"
|
37
|
+
_(SimpleColor.color(:red)).must_equal "\e[31m"
|
38
38
|
end
|
39
39
|
|
40
40
|
it "Does not change the string when there is no color attributes" do
|
41
|
-
SimpleColor.color("foo").must_equal "foo"
|
41
|
+
_(SimpleColor.color("foo")).must_equal "foo"
|
42
42
|
end
|
43
43
|
|
44
44
|
it "can uncolor" do
|
45
|
-
SimpleColor.uncolor(SimpleColor.color("red",:red)).must_equal "red"
|
45
|
+
_(SimpleColor.uncolor(SimpleColor.color("red",:red))).must_equal "red"
|
46
46
|
end
|
47
47
|
|
48
48
|
it "uncolor does not change uncolored strings" do
|
49
|
-
SimpleColor.uncolor("red").must_equal "red"
|
49
|
+
_(SimpleColor.uncolor("red")).must_equal "red"
|
50
50
|
end
|
51
51
|
|
52
52
|
it "Can detect colored strings" do
|
53
|
-
SimpleColor.color?("red").must_equal false
|
54
|
-
SimpleColor.color?(SimpleColor.color("red",:red)).must_equal true
|
53
|
+
_(SimpleColor.color?("red")).must_equal false
|
54
|
+
_(SimpleColor.color?(SimpleColor.color("red",:red))).must_equal true
|
55
55
|
end
|
56
56
|
|
57
57
|
it "Can only show color escape when passed nil" do
|
58
|
-
SimpleColor.color(nil, "x11:lavender").must_equal "\e[38;2;230;230;250m"
|
58
|
+
_(SimpleColor.color(nil, "x11:lavender")).must_equal "\e[38;2;230;230;250m"
|
59
59
|
end
|
60
60
|
|
61
61
|
it "Accepts a block as color parameter" do
|
62
|
-
SimpleColor.color("foo", proc { "x11:lavender" }).must_equal "\e[38;2;230;230;250mfoo\e[0m"
|
62
|
+
_(SimpleColor.color("foo", proc { "x11:lavender" })).must_equal "\e[38;2;230;230;250mfoo\e[0m"
|
63
63
|
end
|
64
64
|
|
65
65
|
it "Proc as color parameter can return multiple values" do
|
66
|
-
SimpleColor.color("foo", proc { ["x11:lavender", :bold] }).must_equal "\e[38;2;230;230;250;1mfoo\e[0m"
|
66
|
+
_(SimpleColor.color("foo", proc { ["x11:lavender", :bold] })).must_equal "\e[38;2;230;230;250;1mfoo\e[0m"
|
67
67
|
end
|
68
68
|
|
69
69
|
it "Has default options" do
|
70
|
-
SimpleColor.opts.must_equal(SimpleColor::Opts.default_opts)
|
70
|
+
_(SimpleColor.opts).must_equal(SimpleColor::Opts.default_opts)
|
71
71
|
end
|
72
72
|
|
73
73
|
describe "Abbreviations" do
|
@@ -76,26 +76,26 @@ describe SimpleColor do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
it "Can use the color1 abbreviations" do
|
79
|
-
SimpleColor.color("foo", :color1).must_equal "\e[38;2;230;230;250mfoo\e[0m"
|
79
|
+
_(SimpleColor.color("foo", :color1)).must_equal "\e[38;2;230;230;250mfoo\e[0m"
|
80
80
|
end
|
81
81
|
it "Abbrevations have precedence" do
|
82
|
-
SimpleColor.color("foo", :red).must_equal SimpleColor.color("foo", :green)
|
82
|
+
_(SimpleColor.color("foo", :red)).must_equal SimpleColor.color("foo", :green)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
describe "Random" do
|
87
87
|
it "Has a :random color" do
|
88
|
-
SimpleColor.color("foo", :random).must_match(/\e\[38;2;\d+;\d+;\d+mfoo\e\[0m/)
|
88
|
+
_(SimpleColor.color("foo", :random)).must_match(/\e\[38;2;\d+;\d+;\d+mfoo\e\[0m/)
|
89
89
|
end
|
90
90
|
it "Has a :on_random color" do
|
91
|
-
SimpleColor.color("foo", :on_random).must_match(/\e\[48;2;\d+;\d+;\d+mfoo\e\[0m/)
|
91
|
+
_(SimpleColor.color("foo", :on_random)).must_match(/\e\[48;2;\d+;\d+;\d+mfoo\e\[0m/)
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
describe "Abbreviations" do
|
96
96
|
it "Can specify abbreviations" do
|
97
97
|
SimpleColor.abbreviations[:important]=[:red, :bold]
|
98
|
-
SimpleColor.color("foo", :important).must_equal("\e[31;1mfoo\e[0m")
|
98
|
+
_(SimpleColor.color("foo", :important)).must_equal("\e[31;1mfoo\e[0m")
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -105,24 +105,24 @@ describe SimpleColor do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
it "Wraps color into shell escapes" do
|
108
|
-
SimpleColor.color("red",:red).must_equal "%{\e[31m%}red%{\e[0m%}"
|
108
|
+
_(SimpleColor.color("red",:red)).must_equal "%{\e[31m%}red%{\e[0m%}"
|
109
109
|
end
|
110
110
|
|
111
111
|
it "Can uncolor correctly" do
|
112
|
-
SimpleColor.uncolor(SimpleColor.color("red",:red)).must_equal "red"
|
112
|
+
_(SimpleColor.uncolor(SimpleColor.color("red",:red))).must_equal "red"
|
113
113
|
end
|
114
114
|
|
115
115
|
it "Only uncolor shell wrapped colors" do
|
116
116
|
red="\e[31mred\e[0m"
|
117
|
-
SimpleColor.uncolor(red).must_equal red
|
117
|
+
_(SimpleColor.uncolor(red)).must_equal red
|
118
118
|
end
|
119
119
|
|
120
120
|
it "Can detect colors correctly" do
|
121
|
-
SimpleColor.color?(SimpleColor.color("red",:red)).must_equal true
|
121
|
+
_(SimpleColor.color?(SimpleColor.color("red",:red))).must_equal true
|
122
122
|
end
|
123
123
|
|
124
124
|
it "Only detect shell wrapped colors" do
|
125
|
-
SimpleColor.color?("\e[31mred\e[0m").must_equal false
|
125
|
+
_(SimpleColor.color?("\e[31mred\e[0m")).must_equal false
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
@@ -132,35 +132,35 @@ describe SimpleColor do
|
|
132
132
|
end
|
133
133
|
|
134
134
|
it "Works on strings" do
|
135
|
-
"red".color(:red).must_equal "\e[31mred\e[0m"
|
135
|
+
_("red".color(:red)).must_equal "\e[31mred\e[0m"
|
136
136
|
end
|
137
137
|
|
138
138
|
it "Uncolor works on strings" do
|
139
|
-
"red".color(:red).uncolor.must_equal "red"
|
139
|
+
_("red".color(:red).uncolor).must_equal "red"
|
140
140
|
end
|
141
141
|
|
142
142
|
it "color does not affects the string" do
|
143
143
|
s="red"
|
144
144
|
s.color(:red)
|
145
|
-
s.must_equal "red"
|
145
|
+
_(s).must_equal "red"
|
146
146
|
end
|
147
147
|
|
148
148
|
it "color! does affects the string" do
|
149
149
|
s="red"
|
150
150
|
s.color!(:red)
|
151
|
-
s.must_equal "\e[31mred\e[0m"
|
151
|
+
_(s).must_equal "\e[31mred\e[0m"
|
152
152
|
end
|
153
153
|
|
154
154
|
it "uncolor does not affects the string" do
|
155
155
|
s="\e[31mred\e[0m"
|
156
156
|
s.uncolor
|
157
|
-
s.must_equal "\e[31mred\e[0m"
|
157
|
+
_(s).must_equal "\e[31mred\e[0m"
|
158
158
|
end
|
159
159
|
|
160
160
|
it "uncolor! does not affects the string" do
|
161
161
|
s="\e[31mred\e[0m"
|
162
162
|
s.uncolor!
|
163
|
-
s.must_equal "red"
|
163
|
+
_(s).must_equal "red"
|
164
164
|
end
|
165
165
|
end
|
166
166
|
|
@@ -171,41 +171,41 @@ describe SimpleColor do
|
|
171
171
|
|
172
172
|
it "When disabled color should be a noop" do
|
173
173
|
word="red"
|
174
|
-
SimpleColor.color(word,:red).must_equal word
|
174
|
+
_(SimpleColor.color(word,:red)).must_equal word
|
175
175
|
end
|
176
176
|
|
177
177
|
it "When disabled uncolor should still work" do
|
178
178
|
word="\e[31mred\e[0m"
|
179
|
-
SimpleColor.uncolor(word).must_equal "red"
|
179
|
+
_(SimpleColor.uncolor(word)).must_equal "red"
|
180
180
|
end
|
181
181
|
|
182
182
|
it "Can be disabled punctually" do
|
183
183
|
SimpleColor.enabled=true
|
184
184
|
word="red"
|
185
|
-
SimpleColor.color(word,:red, mode: false).must_equal word
|
186
|
-
SimpleColor.color(word,:red).must_equal "\e[31mred\e[0m"
|
185
|
+
_(SimpleColor.color(word,:red, mode: false)).must_equal word
|
186
|
+
_(SimpleColor.color(word,:red)).must_equal "\e[31mred\e[0m"
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
190
190
|
describe "It has colors helpers utilities" do
|
191
191
|
it "It can copy one color" do
|
192
|
-
SimpleColor.copy_colors(SimpleColor.color("red",:red),"blue").must_equal "\e[31mblue\e[0m"
|
192
|
+
_(SimpleColor.copy_colors(SimpleColor.color("red",:red),"blue")).must_equal "\e[31mblue\e[0m"
|
193
193
|
end
|
194
194
|
|
195
195
|
it "Copy several colors" do
|
196
|
-
SimpleColor.copy_colors(SimpleColor.color("red",:red,:bold),"blue").must_equal "\e[31;1mblue\e[0m"
|
196
|
+
_(SimpleColor.copy_colors(SimpleColor.color("red",:red,:bold),"blue")).must_equal "\e[31;1mblue\e[0m"
|
197
197
|
end
|
198
198
|
|
199
199
|
it "Can recover colors" do
|
200
200
|
b,e,l=SimpleColor.current_colors(SimpleColor.color("red",:red,:bold))
|
201
|
-
b.must_equal "\e[31;1m"
|
202
|
-
e.must_equal "\e[0m"
|
203
|
-
l.must_equal "red"
|
201
|
+
_(b).must_equal "\e[31;1m"
|
202
|
+
_(e).must_equal "\e[0m"
|
203
|
+
_(l).must_equal "red"
|
204
204
|
end
|
205
205
|
|
206
206
|
it "Can get colors attributes" do
|
207
207
|
b,e=SimpleColor.current_colors(SimpleColor.color("red",:red,:bold))
|
208
|
-
SimpleColor.attributes_from_colors("\e[m"+b+e).must_equal([:reset,:red,:bright,:reset])
|
208
|
+
_(SimpleColor.attributes_from_colors("\e[m"+b+e)).must_equal([:reset,:red,:bright,:reset])
|
209
209
|
end
|
210
210
|
|
211
211
|
it "Can detect 256 and truecolor attributes" do
|
@@ -213,17 +213,17 @@ describe SimpleColor do
|
|
213
213
|
expected=[SimpleColor::RGB.new(3, mode: 256),
|
214
214
|
SimpleColor::RGB.new([1,2,3], background: true),
|
215
215
|
:green, :bright, :conceal, :intense_white]
|
216
|
-
SimpleColor.attributes_from_colors(test).must_equal(expected)
|
216
|
+
_(SimpleColor.attributes_from_colors(test)).must_equal(expected)
|
217
217
|
end
|
218
218
|
|
219
219
|
it "Can split a string into color entities" do
|
220
|
-
SimpleColor.color_entities(SimpleColor.color("red",:red,:bold)+SimpleColor.color("blue",:blue)).must_equal(["\e[31;1m", "r", "e", "d", "\e[0m\e[34m", "b", "l", "u", "e", "\e[0m"])
|
221
|
-
SimpleColor.color_entities("blue "+SimpleColor.color("red",:red,:bold)+" green").must_equal(["b", "l", "u", "e", " ", "\e[31;1m", "r", "e", "d", "\e[0m", " ", "g", "r", "e", "e", "n"])
|
220
|
+
_(SimpleColor.color_entities(SimpleColor.color("red",:red,:bold)+SimpleColor.color("blue",:blue))).must_equal(["\e[31;1m", "r", "e", "d", "\e[0m\e[34m", "b", "l", "u", "e", "\e[0m"])
|
221
|
+
_(SimpleColor.color_entities("blue "+SimpleColor.color("red",:red,:bold)+" green")).must_equal(["b", "l", "u", "e", " ", "\e[31;1m", "r", "e", "d", "\e[0m", " ", "g", "r", "e", "e", "n"])
|
222
222
|
end
|
223
223
|
|
224
224
|
it "Can split a string into color strings" do
|
225
|
-
SimpleColor.color_strings(SimpleColor.color("red",:red,:bold)+SimpleColor.color("blue",:blue)).must_equal(["\e[31;1m", "red", "\e[0m\e[34m", "blue", "\e[0m"])
|
226
|
-
SimpleColor.color_strings("blue "+SimpleColor.color("red",:red,:bold)+" green").must_equal(["blue ", "\e[31;1m", "red", "\e[0m", " green"])
|
225
|
+
_(SimpleColor.color_strings(SimpleColor.color("red",:red,:bold)+SimpleColor.color("blue",:blue))).must_equal(["\e[31;1m", "red", "\e[0m\e[34m", "blue", "\e[0m"])
|
226
|
+
_(SimpleColor.color_strings("blue "+SimpleColor.color("red",:red,:bold)+" green")).must_equal(["blue ", "\e[31;1m", "red", "\e[0m", " green"])
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
@@ -233,30 +233,30 @@ describe SimpleColor do
|
|
233
233
|
end
|
234
234
|
|
235
235
|
it "Can color too" do
|
236
|
-
SimpleColor2.color("red", :red).must_equal "\e[31mred\e[0m"
|
236
|
+
_(SimpleColor2.color("red", :red)).must_equal "\e[31mred\e[0m"
|
237
237
|
end
|
238
238
|
|
239
239
|
it "Still works if SimpleColor is disabled" do
|
240
240
|
SimpleColor.enabled=false
|
241
|
-
SimpleColor2.color("red", :red).must_equal "\e[31mred\e[0m"
|
242
|
-
SimpleColor.color("red", :red).must_equal "red"
|
241
|
+
_(SimpleColor2.color("red", :red)).must_equal "\e[31mred\e[0m"
|
242
|
+
_(SimpleColor.color("red", :red)).must_equal "red"
|
243
243
|
end
|
244
244
|
|
245
245
|
it "Can be disabled without disabling SimpleColor" do
|
246
246
|
SimpleColor2.enabled=false
|
247
|
-
SimpleColor.color("red", :red).must_equal "\e[31mred\e[0m"
|
248
|
-
SimpleColor2.color("red", :red).must_equal "red"
|
247
|
+
_(SimpleColor.color("red", :red)).must_equal "\e[31mred\e[0m"
|
248
|
+
_(SimpleColor2.color("red", :red)).must_equal "red"
|
249
249
|
SimpleColor2.enabled=true
|
250
250
|
end
|
251
251
|
|
252
252
|
it "Can be mixed in a class" do
|
253
253
|
string_class=Class.new(String)
|
254
254
|
SimpleColor2.mix_in(string_class)
|
255
|
-
string_class.new("red").color(:red).must_equal "\e[31mred\e[0m"
|
255
|
+
_(string_class.new("red").color(:red)).must_equal "\e[31mred\e[0m"
|
256
256
|
SimpleColor.enabled=false
|
257
|
-
string_class.new("red").color(:red).must_equal "\e[31mred\e[0m"
|
257
|
+
_(string_class.new("red").color(:red)).must_equal "\e[31mred\e[0m"
|
258
258
|
SimpleColor2.enabled=false
|
259
|
-
string_class.new("red").color(:red).must_equal "red"
|
259
|
+
_(string_class.new("red").color(:red)).must_equal "red"
|
260
260
|
SimpleColor2.enabled=true
|
261
261
|
end
|
262
262
|
|
@@ -268,72 +268,72 @@ describe SimpleColor do
|
|
268
268
|
extend SimpleColor
|
269
269
|
end
|
270
270
|
SimpleColor.opts=default_opts
|
271
|
-
SimpleColor3.opts.must_equal default_opts
|
271
|
+
_(SimpleColor3.opts).must_equal default_opts
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
275
275
|
describe "It raises invalid parameters" do
|
276
276
|
it "Raises when we pass invalid parameter" do
|
277
|
-
proc { SimpleColor.color("foo", mode: :garbage)}.must_raise SimpleColor::WrongParameter
|
277
|
+
_(proc { SimpleColor.color("foo", mode: :garbage)}).must_raise SimpleColor::WrongParameter
|
278
278
|
end
|
279
279
|
|
280
280
|
it "Raises when we pass invalid rgb parameter" do
|
281
|
-
proc { SimpleColor.color("foo", "x11:lavender", color_mode:10)}.must_raise SimpleColor::WrongRGBParameter
|
281
|
+
_(proc { SimpleColor.color("foo", "x11:lavender", color_mode:10)}).must_raise SimpleColor::WrongRGBParameter
|
282
282
|
end
|
283
283
|
|
284
284
|
it "Raises when we pass an invalid color" do
|
285
|
-
proc { SimpleColor.color("foo", SimpleColor)}.must_raise SimpleColor::WrongColor
|
286
|
-
proc { SimpleColor.color("foo", "nonexistingcolorname")}.must_raise SimpleColor::WrongRGBColor
|
285
|
+
_(proc { SimpleColor.color("foo", SimpleColor)}).must_raise SimpleColor::WrongColor
|
286
|
+
_(proc { SimpleColor.color("foo", "nonexistingcolorname")}).must_raise SimpleColor::WrongRGBColor
|
287
287
|
end
|
288
288
|
end
|
289
289
|
|
290
290
|
describe "Chain colors" do
|
291
291
|
it "Can chain global colors" do
|
292
292
|
r=SimpleColor["red", :red]
|
293
|
-
SimpleColor.color(r, :blue).must_equal "\e[31m\e[34mred\e[0m"
|
293
|
+
_(SimpleColor.color(r, :blue)).must_equal "\e[31m\e[34mred\e[0m"
|
294
294
|
end
|
295
295
|
|
296
296
|
it "Can keep global colors" do
|
297
297
|
r=SimpleColor["red", :red]
|
298
|
-
SimpleColor.color(r, :blue, global_color: :keep).must_equal SimpleColor["red", :red]
|
298
|
+
_(SimpleColor.color(r, :blue, global_color: :keep)).must_equal SimpleColor["red", :red]
|
299
299
|
end
|
300
300
|
|
301
301
|
it "Can give precedence to existing global colors" do
|
302
302
|
r=SimpleColor["red", :red]
|
303
|
-
SimpleColor.color(r, :blue, global_color: :before).must_equal "\e[34m\e[31mred\e[0m"
|
303
|
+
_(SimpleColor.color(r, :blue, global_color: :before)).must_equal "\e[34m\e[31mred\e[0m"
|
304
304
|
end
|
305
305
|
|
306
306
|
it "Will give precedence to local colors" do
|
307
307
|
r="foo "+SimpleColor["red", :red]+" bar"
|
308
|
-
SimpleColor.color(r, :blue).must_equal "\e[34mfoo \e[31mred\e[0m\e[34m bar\e[0m"
|
308
|
+
_(SimpleColor.color(r, :blue)).must_equal "\e[34mfoo \e[31mred\e[0m\e[34m bar\e[0m"
|
309
309
|
r="foo "+SimpleColor["red", :red]
|
310
|
-
SimpleColor.color(r, :blue).must_equal "\e[34mfoo \e[31mred\e[0m"
|
310
|
+
_(SimpleColor.color(r, :blue)).must_equal "\e[34mfoo \e[31mred\e[0m"
|
311
311
|
r=+SimpleColor["red", :red]+" bar"
|
312
|
-
SimpleColor.color(r, :blue).must_equal "\e[34m\e[31mred\e[0m\e[34m bar\e[0m"
|
312
|
+
_(SimpleColor.color(r, :blue)).must_equal "\e[34m\e[31mred\e[0m\e[34m bar\e[0m"
|
313
313
|
end
|
314
314
|
|
315
315
|
it "Can get precedence over local colors" do
|
316
316
|
r="foo "+SimpleColor["red", :red]+" bar"
|
317
|
-
SimpleColor.color(r, :blue, local_color: :after).must_equal "\e[34mfoo \e[31m\e[34mred\e[0m\e[34m bar\e[0m"
|
317
|
+
_(SimpleColor.color(r, :blue, local_color: :after)).must_equal "\e[34mfoo \e[31m\e[34mred\e[0m\e[34m bar\e[0m"
|
318
318
|
r="foo "+SimpleColor["red", :red]
|
319
|
-
SimpleColor.color(r, :blue, local_color: :after).must_equal "\e[34mfoo \e[31m\e[34mred\e[0m"
|
319
|
+
_(SimpleColor.color(r, :blue, local_color: :after)).must_equal "\e[34mfoo \e[31m\e[34mred\e[0m"
|
320
320
|
r=+SimpleColor["red", :red]+" bar"
|
321
|
-
SimpleColor.color(r, :blue, local_color: :after).must_equal "\e[31m\e[34mred\e[0m\e[34m bar\e[0m"
|
321
|
+
_(SimpleColor.color(r, :blue, local_color: :after)).must_equal "\e[31m\e[34mred\e[0m\e[34m bar\e[0m"
|
322
322
|
end
|
323
323
|
|
324
324
|
it "Can keep local colors" do
|
325
325
|
r="foo "+SimpleColor["red", :red]+" bar"
|
326
|
-
SimpleColor.color(r, :blue, local_color: :keep).must_equal "\e[34mfoo \e[0m\e[31mred\e[0m\e[34m bar\e[0m"
|
326
|
+
_(SimpleColor.color(r, :blue, local_color: :keep)).must_equal "\e[34mfoo \e[0m\e[31mred\e[0m\e[34m bar\e[0m"
|
327
327
|
r="foo "+SimpleColor["red", :red]
|
328
|
-
SimpleColor.color(r, :blue, local_color: :keep).must_equal "\e[34mfoo \e[0m\e[31mred\e[0m"
|
328
|
+
_(SimpleColor.color(r, :blue, local_color: :keep)).must_equal "\e[34mfoo \e[0m\e[31mred\e[0m"
|
329
329
|
r=+SimpleColor["red", :red]+" bar"
|
330
|
-
SimpleColor.color(r, :blue, local_color: :keep).must_equal "\e[31mred\e[0m\e[34m bar\e[0m"
|
330
|
+
_(SimpleColor.color(r, :blue, local_color: :keep)).must_equal "\e[31mred\e[0m\e[34m bar\e[0m"
|
331
331
|
end
|
332
332
|
|
333
333
|
it "Can store precedence settings" do
|
334
334
|
SimpleColor.opts[:global_color]=:keep
|
335
335
|
r=SimpleColor["red", :red]
|
336
|
-
SimpleColor.color(r, :blue).must_equal(SimpleColor["red", :red])
|
336
|
+
_(SimpleColor.color(r, :blue)).must_equal(SimpleColor["red", :red])
|
337
337
|
end
|
338
338
|
end
|
339
339
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplecolor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Robert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -80,6 +80,7 @@ extra_rdoc_files:
|
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
82
82
|
files:
|
83
|
+
- ".github/workflows/ruby.yml"
|
83
84
|
- ".gitignore"
|
84
85
|
- ".travis.yml"
|
85
86
|
- ".yardopts"
|
@@ -88,6 +89,7 @@ files:
|
|
88
89
|
- LICENSE.txt
|
89
90
|
- README.md
|
90
91
|
- Rakefile
|
92
|
+
- TODO
|
91
93
|
- bin/simplecolor.rb
|
92
94
|
- data/NBS-ISCC_colors.json
|
93
95
|
- data/Resene2010_colors.json
|
@@ -128,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
130
|
- !ruby/object:Gem::Version
|
129
131
|
version: '0'
|
130
132
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.1.2
|
132
134
|
signing_key:
|
133
135
|
specification_version: 4
|
134
136
|
summary: Simple color library
|