term-ansicolor 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +4 -14
- data/VERSION +1 -1
- data/lib/term/ansicolor.rb +3 -0
- data/lib/term/ansicolor/attribute.rb +1 -0
- data/lib/term/ansicolor/hsl_triple.rb +169 -0
- data/lib/term/ansicolor/rgb_triple.rb +67 -9
- data/lib/term/ansicolor/version.rb +1 -1
- data/term-ansicolor.gemspec +9 -9
- data/tests/hsl_triple_test.rb +85 -0
- data/tests/rgb_triple_test.rb +29 -0
- data/tests/test_helper.rb +0 -1
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c967abdd454dffb2795cb482d7391d298b9fa4d1
|
4
|
+
data.tar.gz: 7bd2c0064585977b42f20f85ceb9c8a67ad7fe6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0909dbfe846bc63c6bd7ef9fe356d5dbd4cabfe37fd30870cb606b2a9f29f7ee231829cfcb4c0db36c958e238972e7a5c3b7bee1a6159a22a4594a9ddb051b1
|
7
|
+
data.tar.gz: 79322bfc43c0c19e863a8199f2c8c1f6878698b157c841277267a0d53cc9589cecb05bf459021e1ab7fe9fade46e7397a04818dde0b3da180bd28188fb70c786
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -13,25 +13,15 @@ GemHadar do
|
|
13
13
|
description 'This library uses ANSI escape sequences to control the attributes of terminal output'
|
14
14
|
licenses << 'GPL-2'
|
15
15
|
test_dir 'tests'
|
16
|
-
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage',
|
16
|
+
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage',
|
17
|
+
'tags', '.bundle', '.byebug_history'
|
18
|
+
|
17
19
|
readme 'README.rdoc'
|
18
20
|
executables.merge Dir['bin/*'].map { |x| File.basename(x) }
|
19
21
|
|
20
22
|
dependency 'tins', '~>1.0'
|
21
23
|
development_dependency 'simplecov'
|
22
|
-
development_dependency '
|
24
|
+
development_dependency 'test-unit'
|
23
25
|
|
24
26
|
required_ruby_version '>= 2.0'
|
25
|
-
|
26
|
-
install_library do
|
27
|
-
destdir = "#{ENV['DESTDIR']}"
|
28
|
-
libdir = CONFIG["sitelibdir"]
|
29
|
-
cd 'lib' do
|
30
|
-
for file in Dir['**/*.rb']
|
31
|
-
dest = destdir + File.join(libdir, File.dirname(file))
|
32
|
-
mkdir_p dest
|
33
|
-
install file, dest
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
27
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.5.0
|
data/lib/term/ansicolor.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'tins/xt/full'
|
2
|
+
|
1
3
|
module Term
|
2
4
|
|
3
5
|
# The ANSIColor module can be used for namespacing and mixed into your own
|
@@ -6,6 +8,7 @@ module Term
|
|
6
8
|
require 'term/ansicolor/version'
|
7
9
|
require 'term/ansicolor/attribute'
|
8
10
|
require 'term/ansicolor/rgb_triple'
|
11
|
+
require 'term/ansicolor/hsl_triple'
|
9
12
|
require 'term/ansicolor/ppm_reader'
|
10
13
|
require 'term/ansicolor/attribute/text'
|
11
14
|
require 'term/ansicolor/attribute/color8'
|
@@ -34,6 +34,7 @@ module Term
|
|
34
34
|
case
|
35
35
|
when self === name then name
|
36
36
|
when Array === name then nearest_rgb_color name
|
37
|
+
when name.respond_to?(:to_rgb_triple) then nearest_rgb_color(name.to_rgb_triple.to_a)
|
37
38
|
when name.to_s =~ /\A(on_)?(\d+)\z/ then get "#$1color#$2"
|
38
39
|
when name.to_s =~ /\A#([0-9a-f]{3}){1,2}\z/i then nearest_rgb_color name
|
39
40
|
when name.to_s =~ /\Aon_#([0-9a-f]{3}){1,2}\z/i then nearest_rgb_on_color name
|
@@ -0,0 +1,169 @@
|
|
1
|
+
module Term
|
2
|
+
module ANSIColor
|
3
|
+
class HSLTriple
|
4
|
+
def self.from_rgb_triple(rgb)
|
5
|
+
ps = rgb.to_a.map { |x| x / 255.0 }
|
6
|
+
p_min = ps.min
|
7
|
+
p_max = ps.max
|
8
|
+
p_red, p_green, p_blue = ps
|
9
|
+
|
10
|
+
diff = p_max - p_min
|
11
|
+
l = (p_max + p_min) / 2
|
12
|
+
|
13
|
+
if diff.zero?
|
14
|
+
h = s = 0.0
|
15
|
+
else
|
16
|
+
if l < 0.5
|
17
|
+
s = diff / (p_max + p_min)
|
18
|
+
else
|
19
|
+
s = diff / (2 - p_max - p_min)
|
20
|
+
end
|
21
|
+
|
22
|
+
diff_r = ( ( ( p_max - p_red ) / 6 ) + ( diff / 2 ) ) / diff
|
23
|
+
diff_g = ( ( ( p_max - p_green ) / 6 ) + ( diff / 2 ) ) / diff
|
24
|
+
diff_b = ( ( ( p_max - p_blue ) / 6 ) + ( diff / 2 ) ) / diff
|
25
|
+
|
26
|
+
h = case p_max
|
27
|
+
when p_red
|
28
|
+
diff_b - diff_g
|
29
|
+
when p_green
|
30
|
+
(1 / 3.0) + diff_r - diff_b
|
31
|
+
when p_blue
|
32
|
+
(2 / 3.0) + diff_g - diff_r
|
33
|
+
end
|
34
|
+
|
35
|
+
h < 0 and h += 1
|
36
|
+
h > 1 and h -= 1
|
37
|
+
end
|
38
|
+
from_hash(
|
39
|
+
hue: 360 * h,
|
40
|
+
saturation: 100 * s,
|
41
|
+
lightness: 100 * l
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.from_css(css)
|
46
|
+
case css
|
47
|
+
when /\A\s*hsl\(\s*([^,\s]+)\s*,\s*([^%\s]+)\s*%\s*,\s*([^%\s]+)\s*%\s*\)\z/
|
48
|
+
new(Float($1), Float($2), Float($3))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.from_hash(options)
|
53
|
+
new(
|
54
|
+
options[:hue].to_f,
|
55
|
+
options[:saturation].to_f,
|
56
|
+
options[:lightness].to_f
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.[](thing)
|
61
|
+
case
|
62
|
+
when thing.respond_to?(:to_hsl_triple) then thing.to_hsl_triple
|
63
|
+
when thing.respond_to?(:to_hash) then from_hash(thing.to_hash)
|
64
|
+
when thing.respond_to?(:to_str)
|
65
|
+
thing = thing.to_str
|
66
|
+
from_css(thing.to_str) ||
|
67
|
+
Term::ANSIColor::RGBTriple.from_html(thing).full?(:to_hsl_triple) ||
|
68
|
+
Term::ANSIColor::RGBTriple.from_css(thing).full?(:to_hsl_triple)
|
69
|
+
else raise ArgumentError, "cannot convert #{thing.inspect} into #{self}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def initialize(hue, saturation, lightness)
|
74
|
+
@hue = Float(hue) % 360
|
75
|
+
@saturation = [ [ Float(saturation), 0 ].max, 100 ].min
|
76
|
+
@lightness = [ [ Float(lightness), 0 ].max, 100 ].min
|
77
|
+
end
|
78
|
+
|
79
|
+
attr_reader :hue
|
80
|
+
|
81
|
+
attr_reader :saturation
|
82
|
+
|
83
|
+
attr_reader :lightness
|
84
|
+
|
85
|
+
def lighten(percentage)
|
86
|
+
self.class.new(@hue, @saturation, @lightness + percentage)
|
87
|
+
end
|
88
|
+
|
89
|
+
def darken(percentage)
|
90
|
+
self.class.new(@hue, @saturation, @lightness - percentage)
|
91
|
+
end
|
92
|
+
|
93
|
+
def saturate(percentage)
|
94
|
+
self.class.new(@hue, @saturation + percentage, @lightness)
|
95
|
+
end
|
96
|
+
|
97
|
+
def desaturate(percentage)
|
98
|
+
self.class.new(@hue, @saturation - percentage, @lightness)
|
99
|
+
end
|
100
|
+
|
101
|
+
def adjust_hue(degree)
|
102
|
+
self.class.new(@hue + degree, @saturation, @lightness)
|
103
|
+
end
|
104
|
+
|
105
|
+
def grayscale
|
106
|
+
self.class.new(@hue, 0, @lightness)
|
107
|
+
end
|
108
|
+
|
109
|
+
def complement
|
110
|
+
adjust_hue(180)
|
111
|
+
end
|
112
|
+
|
113
|
+
def hue2rgb(x, y, h)
|
114
|
+
h < 0 and h += 1
|
115
|
+
h > 1 and h -= 1
|
116
|
+
(6 * h) < 1 and return x + (y - x) * 6 * h
|
117
|
+
(2 * h) < 1 and return y
|
118
|
+
(3 * h) < 2 and return x + (y - x) * ( (2 / 3.0) - h ) * 6
|
119
|
+
x
|
120
|
+
end
|
121
|
+
private :hue2rgb
|
122
|
+
|
123
|
+
def to_rgb_triple
|
124
|
+
h = @hue / 360.0
|
125
|
+
s = @saturation / 100.0
|
126
|
+
l = @lightness / 100.0
|
127
|
+
|
128
|
+
if s.zero?
|
129
|
+
r = 255 * l
|
130
|
+
g = 255 * l
|
131
|
+
b = 255 * l
|
132
|
+
else
|
133
|
+
if l < 0.5
|
134
|
+
y = l * (1 + s)
|
135
|
+
else
|
136
|
+
y = (l + s) - (s * l)
|
137
|
+
end
|
138
|
+
|
139
|
+
x = 2 * l - y
|
140
|
+
|
141
|
+
r = 255 * hue2rgb(x, y, h + (1 / 3.0))
|
142
|
+
g = 255 * hue2rgb(x, y, h)
|
143
|
+
b = 255 * hue2rgb(x, y, h - (1 / 3.0))
|
144
|
+
end
|
145
|
+
Term::ANSIColor::RGBTriple.new(r.round, g.round, b.round)
|
146
|
+
end
|
147
|
+
|
148
|
+
def to_hsl_triple
|
149
|
+
self
|
150
|
+
end
|
151
|
+
|
152
|
+
def css
|
153
|
+
"hsl(%s,%s%%,%s%%)" % [ @hue, @saturation, @lightness ]
|
154
|
+
end
|
155
|
+
|
156
|
+
def ==(other)
|
157
|
+
to_rgb_triple == other.to_rgb_triple
|
158
|
+
end
|
159
|
+
|
160
|
+
def method_missing(name, *args, &block)
|
161
|
+
if Term::ANSIColor::RGBTriple.method_defined?(name)
|
162
|
+
to_rgb_triple.send(name, *args, &block)
|
163
|
+
else
|
164
|
+
super
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -5,11 +5,11 @@ module Term
|
|
5
5
|
class RGBTriple
|
6
6
|
include Term::ANSIColor::RGBColorMetricsHelpers::WeightedEuclideanDistance
|
7
7
|
|
8
|
-
def self.convert_value(color)
|
8
|
+
def self.convert_value(color, max: 255)
|
9
9
|
color.nil? and raise ArgumentError, "missing color value"
|
10
10
|
color = Integer(color)
|
11
|
-
(0..
|
12
|
-
"color value #{color.inspect} not between 0 and
|
11
|
+
(0..max) === color or raise ArgumentError,
|
12
|
+
"color value #{color.inspect} not between 0 and #{max}"
|
13
13
|
color
|
14
14
|
end
|
15
15
|
|
@@ -24,6 +24,15 @@ module Term
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.from_css(css)
|
28
|
+
case css
|
29
|
+
when /\A\s*rgb\(\s*([^%\s]+)\s*%\s*,\s*([^%\s]+)\s*%\s*,\s*([^%\s]+)\s*%\s*\)\z/
|
30
|
+
new(*$~.captures.map { |c| convert_value(((Float(c) / 100) * 0xff).round) })
|
31
|
+
when /\A\s*rgb\(\s*([^,\s]+)\s*,\s*([^,\s]+)\s*,\s*([^\)\s]+)\s*\)\z/
|
32
|
+
new(*$~.captures.map { |c| convert_value((Float(c)).round) })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
27
36
|
def self.from_hash(options)
|
28
37
|
new(
|
29
38
|
convert_value(options[:red]),
|
@@ -38,16 +47,21 @@ module Term
|
|
38
47
|
|
39
48
|
def self.[](thing)
|
40
49
|
case
|
41
|
-
when thing.respond_to?(:to_rgb_triple) then thing
|
42
|
-
when thing.respond_to?(:to_ary) then
|
43
|
-
when thing.respond_to?(:to_str)
|
44
|
-
|
50
|
+
when thing.respond_to?(:to_rgb_triple) then thing.to_rgb_triple
|
51
|
+
when thing.respond_to?(:to_ary) then from_array(thing.to_ary)
|
52
|
+
when thing.respond_to?(:to_str)
|
53
|
+
thing = thing.to_str
|
54
|
+
from_html(thing.sub(/\Aon_/, '')) || from_css(thing) ||
|
55
|
+
Term::ANSIColor::HSLTriple.from_css(thing).full?(:to_rgb_triple)
|
56
|
+
when thing.respond_to?(:to_hash) then from_hash(thing.to_hash)
|
45
57
|
else raise ArgumentError, "cannot convert #{thing.inspect} into #{self}"
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
49
61
|
def initialize(red, green, blue)
|
50
|
-
@values = [ red, green, blue ]
|
62
|
+
@values = [ red, green, blue ].map { |v|
|
63
|
+
[ [ Integer(v), 0 ].max, 0xff ].min
|
64
|
+
}
|
51
65
|
end
|
52
66
|
|
53
67
|
def red
|
@@ -62,6 +76,26 @@ module Term
|
|
62
76
|
@values[2]
|
63
77
|
end
|
64
78
|
|
79
|
+
def percentages
|
80
|
+
@percentages ||= @values.map { |v| 100 * v / 255.0 }
|
81
|
+
end
|
82
|
+
|
83
|
+
def red_p
|
84
|
+
percentages[0]
|
85
|
+
end
|
86
|
+
|
87
|
+
def green_p
|
88
|
+
percentages[1]
|
89
|
+
end
|
90
|
+
|
91
|
+
def blue_p
|
92
|
+
percentages[2]
|
93
|
+
end
|
94
|
+
|
95
|
+
def invert
|
96
|
+
self.class.new(255 - red, 255 - green, 255 - blue)
|
97
|
+
end
|
98
|
+
|
65
99
|
def gray?
|
66
100
|
red != 0 && red != 0xff && red == green && green == blue && blue == red
|
67
101
|
end
|
@@ -72,10 +106,22 @@ module Term
|
|
72
106
|
s
|
73
107
|
end
|
74
108
|
|
109
|
+
def css(percentage: false)
|
110
|
+
if percentage
|
111
|
+
"rgb(%s%%,%s%%,%s%%)" % @values.map { |v| 100.0 * v / 255 }
|
112
|
+
else
|
113
|
+
"rgb(%u,%u,%u)" % @values
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
75
117
|
def to_rgb_triple
|
76
118
|
self
|
77
119
|
end
|
78
120
|
|
121
|
+
def to_hsl_triple
|
122
|
+
Term::ANSIColor::HSLTriple.from_rgb_triple(self)
|
123
|
+
end
|
124
|
+
|
79
125
|
attr_reader :values
|
80
126
|
protected :values
|
81
127
|
|
@@ -84,7 +130,11 @@ module Term
|
|
84
130
|
end
|
85
131
|
|
86
132
|
def ==(other)
|
87
|
-
@values == other.values
|
133
|
+
@values == other.to_rgb_triple.values
|
134
|
+
end
|
135
|
+
|
136
|
+
def color(string)
|
137
|
+
Term::ANSIColor.color(self, string)
|
88
138
|
end
|
89
139
|
|
90
140
|
def distance_to(other, options = {})
|
@@ -116,6 +166,14 @@ module Term
|
|
116
166
|
end
|
117
167
|
gradient << other
|
118
168
|
end
|
169
|
+
|
170
|
+
def method_missing(name, *args, &block)
|
171
|
+
if Term::ANSIColor::HSLTriple.method_defined?(name)
|
172
|
+
to_hsl_triple.send(name, *args, &block)
|
173
|
+
else
|
174
|
+
super
|
175
|
+
end
|
176
|
+
end
|
119
177
|
end
|
120
178
|
end
|
121
179
|
end
|
data/term-ansicolor.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: term-ansicolor 1.
|
2
|
+
# stub: term-ansicolor 1.5.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "term-ansicolor".freeze
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.5.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2017-03-
|
11
|
+
s.date = "2017-03-28"
|
12
12
|
s.description = "This library uses ANSI escape sequences to control the attributes of terminal output".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.executables = ["term_cdiff".freeze, "term_colortab".freeze, "term_decolor".freeze, "term_display".freeze, "term_mandel".freeze]
|
15
|
-
s.extra_rdoc_files = ["README.rdoc".freeze, "lib/term/ansicolor.rb".freeze, "lib/term/ansicolor/attribute.rb".freeze, "lib/term/ansicolor/attribute/color256.rb".freeze, "lib/term/ansicolor/attribute/color8.rb".freeze, "lib/term/ansicolor/attribute/intense_color8.rb".freeze, "lib/term/ansicolor/attribute/text.rb".freeze, "lib/term/ansicolor/ppm_reader.rb".freeze, "lib/term/ansicolor/rgb_color_metrics.rb".freeze, "lib/term/ansicolor/rgb_triple.rb".freeze, "lib/term/ansicolor/version.rb".freeze]
|
16
|
-
s.files = [".gitignore".freeze, ".travis.yml".freeze, "CHANGES".freeze, "COPYING".freeze, "Gemfile".freeze, "README.rdoc".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/term_cdiff".freeze, "bin/term_colortab".freeze, "bin/term_decolor".freeze, "bin/term_display".freeze, "bin/term_mandel".freeze, "examples/ColorTest.gif".freeze, "examples/Mona_Lisa.jpg".freeze, "examples/Stilleben.jpg".freeze, "examples/example.rb".freeze, "examples/lambda-red-plain.ppm".freeze, "examples/lambda-red.png".freeze, "examples/lambda-red.ppm".freeze, "examples/pacman.jpg".freeze, "examples/smiley.png".freeze, "examples/wool.jpg".freeze, "lib/term/ansicolor.rb".freeze, "lib/term/ansicolor/.keep".freeze, "lib/term/ansicolor/attribute.rb".freeze, "lib/term/ansicolor/attribute/color256.rb".freeze, "lib/term/ansicolor/attribute/color8.rb".freeze, "lib/term/ansicolor/attribute/intense_color8.rb".freeze, "lib/term/ansicolor/attribute/text.rb".freeze, "lib/term/ansicolor/ppm_reader.rb".freeze, "lib/term/ansicolor/rgb_color_metrics.rb".freeze, "lib/term/ansicolor/rgb_triple.rb".freeze, "lib/term/ansicolor/version.rb".freeze, "term-ansicolor.gemspec".freeze, "tests/ansicolor_test.rb".freeze, "tests/attribute_test.rb".freeze, "tests/ppm_reader_test.rb".freeze, "tests/rgb_color_metrics_test.rb".freeze, "tests/rgb_triple_test.rb".freeze, "tests/test_helper.rb".freeze]
|
15
|
+
s.extra_rdoc_files = ["README.rdoc".freeze, "lib/term/ansicolor.rb".freeze, "lib/term/ansicolor/attribute.rb".freeze, "lib/term/ansicolor/attribute/color256.rb".freeze, "lib/term/ansicolor/attribute/color8.rb".freeze, "lib/term/ansicolor/attribute/intense_color8.rb".freeze, "lib/term/ansicolor/attribute/text.rb".freeze, "lib/term/ansicolor/hsl_triple.rb".freeze, "lib/term/ansicolor/ppm_reader.rb".freeze, "lib/term/ansicolor/rgb_color_metrics.rb".freeze, "lib/term/ansicolor/rgb_triple.rb".freeze, "lib/term/ansicolor/version.rb".freeze]
|
16
|
+
s.files = [".gitignore".freeze, ".travis.yml".freeze, "CHANGES".freeze, "COPYING".freeze, "Gemfile".freeze, "README.rdoc".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/term_cdiff".freeze, "bin/term_colortab".freeze, "bin/term_decolor".freeze, "bin/term_display".freeze, "bin/term_mandel".freeze, "examples/ColorTest.gif".freeze, "examples/Mona_Lisa.jpg".freeze, "examples/Stilleben.jpg".freeze, "examples/example.rb".freeze, "examples/lambda-red-plain.ppm".freeze, "examples/lambda-red.png".freeze, "examples/lambda-red.ppm".freeze, "examples/pacman.jpg".freeze, "examples/smiley.png".freeze, "examples/wool.jpg".freeze, "lib/term/ansicolor.rb".freeze, "lib/term/ansicolor/.keep".freeze, "lib/term/ansicolor/attribute.rb".freeze, "lib/term/ansicolor/attribute/color256.rb".freeze, "lib/term/ansicolor/attribute/color8.rb".freeze, "lib/term/ansicolor/attribute/intense_color8.rb".freeze, "lib/term/ansicolor/attribute/text.rb".freeze, "lib/term/ansicolor/hsl_triple.rb".freeze, "lib/term/ansicolor/ppm_reader.rb".freeze, "lib/term/ansicolor/rgb_color_metrics.rb".freeze, "lib/term/ansicolor/rgb_triple.rb".freeze, "lib/term/ansicolor/version.rb".freeze, "term-ansicolor.gemspec".freeze, "tests/ansicolor_test.rb".freeze, "tests/attribute_test.rb".freeze, "tests/hsl_triple_test.rb".freeze, "tests/ppm_reader_test.rb".freeze, "tests/rgb_color_metrics_test.rb".freeze, "tests/rgb_triple_test.rb".freeze, "tests/test_helper.rb".freeze]
|
17
17
|
s.homepage = "http://flori.github.com/term-ansicolor".freeze
|
18
18
|
s.licenses = ["GPL-2".freeze]
|
19
19
|
s.rdoc_options = ["--title".freeze, "Term-ansicolor - Ruby library that colors strings using ANSI escape sequences".freeze, "--main".freeze, "README.rdoc".freeze]
|
20
20
|
s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
|
21
21
|
s.rubygems_version = "2.6.11".freeze
|
22
22
|
s.summary = "Ruby library that colors strings using ANSI escape sequences".freeze
|
23
|
-
s.test_files = ["tests/ansicolor_test.rb".freeze, "tests/attribute_test.rb".freeze, "tests/ppm_reader_test.rb".freeze, "tests/rgb_color_metrics_test.rb".freeze, "tests/rgb_triple_test.rb".freeze, "tests/test_helper.rb".freeze]
|
23
|
+
s.test_files = ["tests/ansicolor_test.rb".freeze, "tests/attribute_test.rb".freeze, "tests/hsl_triple_test.rb".freeze, "tests/ppm_reader_test.rb".freeze, "tests/rgb_color_metrics_test.rb".freeze, "tests/rgb_triple_test.rb".freeze, "tests/test_helper.rb".freeze]
|
24
24
|
|
25
25
|
if s.respond_to? :specification_version then
|
26
26
|
s.specification_version = 4
|
@@ -28,18 +28,18 @@ Gem::Specification.new do |s|
|
|
28
28
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
29
29
|
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
30
30
|
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
31
|
-
s.add_development_dependency(%q<
|
31
|
+
s.add_development_dependency(%q<test-unit>.freeze, [">= 0"])
|
32
32
|
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.0"])
|
33
33
|
else
|
34
34
|
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
35
35
|
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
36
|
-
s.add_dependency(%q<
|
36
|
+
s.add_dependency(%q<test-unit>.freeze, [">= 0"])
|
37
37
|
s.add_dependency(%q<tins>.freeze, ["~> 1.0"])
|
38
38
|
end
|
39
39
|
else
|
40
40
|
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.9.1"])
|
41
41
|
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
42
|
-
s.add_dependency(%q<
|
42
|
+
s.add_dependency(%q<test-unit>.freeze, [">= 0"])
|
43
43
|
s.add_dependency(%q<tins>.freeze, ["~> 1.0"])
|
44
44
|
end
|
45
45
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class HSLTripleTest < Test::Unit::TestCase
|
4
|
+
include Term::ANSIColor
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@pastel_green_rgb = Term::ANSIColor::RGBTriple['#85e085']
|
8
|
+
@pastel_green_hsl = Term::ANSIColor::HSLTriple.new(120, 59.4, 70)
|
9
|
+
@soft_red_rgb = Term::ANSIColor::RGBTriple['#e08585']
|
10
|
+
@soft_blue_rgb = Term::ANSIColor::RGBTriple['#8585e0']
|
11
|
+
@gray_rgb = Term::ANSIColor::RGBTriple['#888']
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_hsl_cast
|
15
|
+
assert_equal '#85e085', HSLTriple[ @pastel_green_hsl ].html
|
16
|
+
assert_equal '#85e085', HSLTriple[ :hue => 120, :saturation => 59.4, :lightness => 70 ].html
|
17
|
+
assert_equal '#11ddff', HSLTriple[ '#1df' ].html
|
18
|
+
assert_equal '#8000ff', HSLTriple[ 'rgb(128,0,255)' ].html
|
19
|
+
assert_equal '#85e085', HSLTriple[ 'hsl(120.0,59.4%,70.0%)' ].html
|
20
|
+
assert_raises ArgumentError do
|
21
|
+
HSLTriple[ nil ]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_conversion_to_hsl
|
26
|
+
hsl = @pastel_green_rgb.to_hsl_triple
|
27
|
+
assert_in_delta @pastel_green_hsl.hue, hsl.hue, 1e-1
|
28
|
+
assert_in_delta @pastel_green_hsl.saturation, hsl.saturation, 1e-1
|
29
|
+
assert_in_delta @pastel_green_hsl.lightness, hsl.lightness, 1e-1
|
30
|
+
assert_match /hsl\(0\.0,0\.0%,53.3333.*?%\)/, @gray_rgb.to_hsl_triple.css
|
31
|
+
assert_match /hsl\(120\.0.*?,58\.82.*?%,20.0%\)/, RGBTriple[ '#155115' ].to_hsl_triple.css
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_conversion_to_rgb
|
35
|
+
rgb = @pastel_green_hsl.to_rgb_triple
|
36
|
+
assert_in_delta @pastel_green_rgb.red, rgb.red, 1e-1
|
37
|
+
assert_in_delta @pastel_green_rgb.green, rgb.green, 1e-1
|
38
|
+
assert_in_delta @pastel_green_rgb.blue, rgb.blue, 1e-1
|
39
|
+
assert_equal '#155115', HSLTriple[ '#155115' ].to_rgb_triple.html
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_lighten
|
43
|
+
assert_in_delta 80, @pastel_green_hsl.lighten(10).lightness, 1e-3
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_darken
|
47
|
+
assert_in_delta 60, @pastel_green_hsl.darken(10).lightness, 1e-3
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_saturate
|
51
|
+
assert_in_delta 69.4, @pastel_green_hsl.saturate(10).saturation, 1e-3
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_desaturate
|
55
|
+
assert_in_delta 49.4, @pastel_green_hsl.desaturate(10).saturation, 1e-3
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_adjust_hue
|
59
|
+
assert_in_delta 130, @pastel_green_hsl.adjust_hue(10).hue, 1e-3
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_grayscale
|
63
|
+
assert_equal '#b3b3b3', @pastel_green_hsl.grayscale.html
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_complement
|
67
|
+
assert_in_delta 300, @pastel_green_hsl.complement.hue, 1e-3
|
68
|
+
assert_in_delta 300 - 120, @soft_red_rgb.complement.hue, 1e-3
|
69
|
+
assert_in_delta 300 - 240, @soft_blue_rgb.complement.hue, 1e-3
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_css
|
73
|
+
assert_equal 'hsl(120.0,59.4%,70.0%)', @pastel_green_hsl.css
|
74
|
+
assert_equal '#85e085', HSLTriple.from_css('hsl(120.0,59.4%,70.0%)').html
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_equality
|
78
|
+
assert_equal @pastel_green_hsl, @pastel_green_rgb
|
79
|
+
assert_equal @pastel_green_rgb, @pastel_green_hsl
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_method_missing
|
83
|
+
assert_raise(NoMethodError) { @pastel_green_hsl.foo }
|
84
|
+
end
|
85
|
+
end
|
data/tests/rgb_triple_test.rb
CHANGED
@@ -9,6 +9,8 @@ class RgbTripleTest < Test::Unit::TestCase
|
|
9
9
|
assert_equal '#8000ff', RGBTriple[ [ 128, 0, 255 ] ].html
|
10
10
|
assert_equal '#8000ff', RGBTriple[ :red => 128, :green => 0, :blue => 255 ].html
|
11
11
|
assert_equal '#11ddff', RGBTriple[ '#1df' ].html
|
12
|
+
assert_equal '#8000ff', RGBTriple[ 'rgb(128,0,255)' ].html
|
13
|
+
assert_equal '#85e085', RGBTriple[ 'hsl(120.0,59.4%,70.0%)' ].html
|
12
14
|
assert_raises ArgumentError do
|
13
15
|
RGBTriple[ nil ]
|
14
16
|
end
|
@@ -19,6 +21,13 @@ class RgbTripleTest < Test::Unit::TestCase
|
|
19
21
|
assert_equal [ 128, 0, 255 ], rgb.to_a
|
20
22
|
end
|
21
23
|
|
24
|
+
def test_percentages
|
25
|
+
rgb = RGBTriple.new(128, 0, 255)
|
26
|
+
assert_in_delta 50.19, rgb.red_p, 1e-2
|
27
|
+
assert_in_delta 0.0, rgb.green_p, 1e-2
|
28
|
+
assert_in_delta 100.0, rgb.blue_p, 1e-2
|
29
|
+
end
|
30
|
+
|
22
31
|
def test_rgb_distance
|
23
32
|
rgb1 = RGBTriple.new(128, 0, 255)
|
24
33
|
rgb2 = RGBTriple.new(128, 200, 64)
|
@@ -69,4 +78,24 @@ class RgbTripleTest < Test::Unit::TestCase
|
|
69
78
|
assert_equal 204, g2[4].blue
|
70
79
|
assert_equal rgb2, g2[5]
|
71
80
|
end
|
81
|
+
|
82
|
+
def test_invert
|
83
|
+
assert_equal RGBTriple.new(127, 255, 0), RGBTriple.new(128, 0, 255).invert
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_css
|
87
|
+
rgb = RGBTriple.new(128, 0, 255)
|
88
|
+
assert_equal 'rgb(128,0,255)', rgb.css
|
89
|
+
assert_equal '#8000ff', RGBTriple.from_css('rgb(128,0,255)').html
|
90
|
+
assert_match /rgb\(50\.19.*?%,0\.0%,100.0%\)/, rgb.css(percentage: true)
|
91
|
+
assert_equal '#8000ff', RGBTriple.from_css('rgb(50.19607843137255%,0.0%,100.0%)').html
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_color
|
95
|
+
assert_equal "\e[38;5;93mfoo\e[0m", RGBTriple.new(128, 0, 255).color('foo')
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_method_missing
|
99
|
+
assert_raise(NoMethodError) { RGBTriple.new(0, 0, 0).foo }
|
100
|
+
end
|
72
101
|
end
|
data/tests/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: term-ansicolor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: test-unit
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -84,6 +84,7 @@ extra_rdoc_files:
|
|
84
84
|
- lib/term/ansicolor/attribute/color8.rb
|
85
85
|
- lib/term/ansicolor/attribute/intense_color8.rb
|
86
86
|
- lib/term/ansicolor/attribute/text.rb
|
87
|
+
- lib/term/ansicolor/hsl_triple.rb
|
87
88
|
- lib/term/ansicolor/ppm_reader.rb
|
88
89
|
- lib/term/ansicolor/rgb_color_metrics.rb
|
89
90
|
- lib/term/ansicolor/rgb_triple.rb
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- lib/term/ansicolor/attribute/color8.rb
|
120
121
|
- lib/term/ansicolor/attribute/intense_color8.rb
|
121
122
|
- lib/term/ansicolor/attribute/text.rb
|
123
|
+
- lib/term/ansicolor/hsl_triple.rb
|
122
124
|
- lib/term/ansicolor/ppm_reader.rb
|
123
125
|
- lib/term/ansicolor/rgb_color_metrics.rb
|
124
126
|
- lib/term/ansicolor/rgb_triple.rb
|
@@ -126,6 +128,7 @@ files:
|
|
126
128
|
- term-ansicolor.gemspec
|
127
129
|
- tests/ansicolor_test.rb
|
128
130
|
- tests/attribute_test.rb
|
131
|
+
- tests/hsl_triple_test.rb
|
129
132
|
- tests/ppm_reader_test.rb
|
130
133
|
- tests/rgb_color_metrics_test.rb
|
131
134
|
- tests/rgb_triple_test.rb
|
@@ -161,6 +164,7 @@ summary: Ruby library that colors strings using ANSI escape sequences
|
|
161
164
|
test_files:
|
162
165
|
- tests/ansicolor_test.rb
|
163
166
|
- tests/attribute_test.rb
|
167
|
+
- tests/hsl_triple_test.rb
|
164
168
|
- tests/ppm_reader_test.rb
|
165
169
|
- tests/rgb_color_metrics_test.rb
|
166
170
|
- tests/rgb_triple_test.rb
|