term-ansicolor 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/CHANGES +3 -0
- data/VERSION +1 -1
- data/bin/colortab +1 -3
- data/lib/term/ansicolor.rb +7 -11
- data/lib/term/ansicolor/attribute.rb +12 -0
- data/lib/term/ansicolor/rgb_triple.rb +1 -1
- data/lib/term/ansicolor/version.rb +1 -1
- data/term-ansicolor.gemspec +3 -3
- data/tests/ansicolor_test.rb +1 -10
- data/tests/attribute_test.rb +33 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NWQ4Yjg1MjdjMDU0NWRiYjAwZmNlOTZmMjRmMWY3NDhjZjA1ODI2MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGRkYzFmZGQzOTRkMDY0OGQwNjYwZTFhYjZkYWE3MjEyNDE2MTA0Mw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjU3MmI1YjhhN2NkZjRlNjJmOGY0MWU5NTJhYzZhNjJkYTQwNjdiYTY4NTVj
|
10
|
+
YzM4MzUzZmRmMjI0MjE0YTEzNWI3NjIwOGYwN2UxZTNiNTk3NGY1ODU3ODU0
|
11
|
+
MDllNTdjOWYyNjBjZmExNGYwNmU3ZmJjYWUwNDRmZGQ1OGI4NjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTc2NDEwODcxNmFiY2M3NTNjOThlMjZhMGFhZTNiMDc3NmNhZWJmMGQ3MmI4
|
14
|
+
MDRiNDI2MWE4MjdkMzU2MjczZTY3OTMwYzUxMGRlYmFiNWE1MjZjYzg1YmVh
|
15
|
+
NDNhMWU2ZTUxYzEwZjM2YmExMjJhNjhiMDhmNGNhMmQ1MWJjZGE=
|
data/CHANGES
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
2013-03-26 - 1.1.3 * Fix a bug where respond_to could overflow the stack.
|
2
|
+
* Easier access to color attributes via color(123) or
|
3
|
+
approximate html colors like color('#336caf').
|
1
4
|
2013-03-25 - 1.1.2 * Change the API: color0 - color255 to color(:color0) -
|
2
5
|
color(:color255), and on_color0 to on_color(:color0) -
|
3
6
|
on_color(:color255); the previous way caused some
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.3
|
data/bin/colortab
CHANGED
@@ -6,10 +6,8 @@ class String
|
|
6
6
|
include Term::ANSIColor
|
7
7
|
end
|
8
8
|
|
9
|
-
$colors = Term::ANSIColor::Attribute.rgb_colors.to_a
|
10
|
-
|
11
9
|
def print_color(c)
|
12
|
-
color =
|
10
|
+
color = Term::ANSIColor::Attribute[c]
|
13
11
|
text = [
|
14
12
|
Term::ANSIColor::Attribute.nearest_rgb_color('#000'),
|
15
13
|
Term::ANSIColor::Attribute.nearest_rgb_color('#fff'),
|
data/lib/term/ansicolor.rb
CHANGED
@@ -161,14 +161,6 @@ module Term
|
|
161
161
|
create_color_method(attribute.name, attribute.code)
|
162
162
|
end
|
163
163
|
|
164
|
-
module RespondTo
|
165
|
-
def respond_to?(symbol, include_all = false)
|
166
|
-
term_ansicolor_attributes.include?(symbol) or super
|
167
|
-
end
|
168
|
-
end
|
169
|
-
include RespondTo
|
170
|
-
extend RespondTo
|
171
|
-
|
172
164
|
# Regular expression that is used to scan for ANSI-Attributes while
|
173
165
|
# uncoloring strings.
|
174
166
|
COLORED_REGEXP = /\e\[(?:(?:[349]|10)[0-7]|[0-9]|[34]8;5;\d{1,3})?m/
|
@@ -193,8 +185,12 @@ module Term
|
|
193
185
|
# color +name+. If string isn't a string only the escape sequence to switch
|
194
186
|
# on the color +name+ is returned.
|
195
187
|
def color(name, string = nil, &block)
|
196
|
-
attribute = Attribute.get(name)
|
197
|
-
|
188
|
+
attribute = Attribute.get(name)
|
189
|
+
attribute ||=
|
190
|
+
name.to_s =~ /\Aon_/ ?
|
191
|
+
Attribute.nearest_rgb_on_color(name) :
|
192
|
+
Attribute.nearest_rgb_color(name)
|
193
|
+
attribute or raise ArgumentError, "unknown attribute #{name.inspect}"
|
198
194
|
result = ''
|
199
195
|
result << "\e[#{attribute.code}m" if Term::ANSIColor.coloring?
|
200
196
|
if block_given?
|
@@ -217,7 +213,7 @@ module Term
|
|
217
213
|
class << self
|
218
214
|
# Returns an array of all Term::ANSIColor attributes as symbols.
|
219
215
|
def term_ansicolor_attributes
|
220
|
-
|
216
|
+
::Term::ANSIColor::ATTRIBUTE_NAMES
|
221
217
|
end
|
222
218
|
|
223
219
|
alias attributes term_ansicolor_attributes
|
@@ -10,6 +10,16 @@ module Term
|
|
10
10
|
result
|
11
11
|
end
|
12
12
|
|
13
|
+
def self.[](name)
|
14
|
+
case
|
15
|
+
when self === name then name
|
16
|
+
when name.to_s =~ /\A(on_)?(\d+)\z/ then get "#$1color#$2"
|
17
|
+
when name.to_s =~ /\A#([0-9a-f]{3}){1,2}\z/i then nearest_rgb_color name
|
18
|
+
when name.to_s =~ /\Aon_#([0-9a-f]{3}){1,2}\z/i then nearest_rgb_on_color name
|
19
|
+
else get name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
def self.get(name)
|
14
24
|
@__store__[name.to_sym]
|
15
25
|
end
|
@@ -76,6 +86,8 @@ module Term
|
|
76
86
|
other_rgb = other.to_rgb_triple
|
77
87
|
then
|
78
88
|
our_rgb.distance_to other_rgb
|
89
|
+
else
|
90
|
+
1 / 0.0
|
79
91
|
end
|
80
92
|
end
|
81
93
|
end
|
@@ -36,7 +36,7 @@ module Term
|
|
36
36
|
case
|
37
37
|
when thing.respond_to?(:to_rgb_triple) then thing
|
38
38
|
when thing.respond_to?(:to_ary) then RGBTriple.from_array(thing.to_ary)
|
39
|
-
when thing.respond_to?(:to_str) then RGBTriple.from_html(thing.to_str)
|
39
|
+
when thing.respond_to?(:to_str) then RGBTriple.from_html(thing.to_str.sub(/\Aon_/, '')) # XXX somewhat hacky
|
40
40
|
when thing.respond_to?(:to_hash) then RGBTriple.from_hash(thing.to_hash)
|
41
41
|
else raise ArgumentError, "cannot convert #{thing.inspect} into #{self}"
|
42
42
|
end
|
data/term-ansicolor.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "term-ansicolor"
|
5
|
-
s.version = "1.1.
|
5
|
+
s.version = "1.1.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Florian Frank"]
|
@@ -11,14 +11,14 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.email = "flori@ping.de"
|
12
12
|
s.executables = ["cdiff", "decolor"]
|
13
13
|
s.extra_rdoc_files = ["README.rdoc", "lib/term/ansicolor.rb", "lib/term/ansicolor/attribute.rb", "lib/term/ansicolor/rgb_triple.rb", "lib/term/ansicolor/version.rb"]
|
14
|
-
s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "Gemfile", "README.rdoc", "Rakefile", "VERSION", "bin/cdiff", "bin/colortab", "bin/decolor", "examples/example.rb", "lib/term/ansicolor.rb", "lib/term/ansicolor/.keep", "lib/term/ansicolor/attribute.rb", "lib/term/ansicolor/rgb_triple.rb", "lib/term/ansicolor/version.rb", "term-ansicolor.gemspec", "tests/ansicolor_test.rb", "tests/rgb_triple_test.rb", "tests/test_helper.rb"]
|
14
|
+
s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "Gemfile", "README.rdoc", "Rakefile", "VERSION", "bin/cdiff", "bin/colortab", "bin/decolor", "examples/example.rb", "lib/term/ansicolor.rb", "lib/term/ansicolor/.keep", "lib/term/ansicolor/attribute.rb", "lib/term/ansicolor/rgb_triple.rb", "lib/term/ansicolor/version.rb", "term-ansicolor.gemspec", "tests/ansicolor_test.rb", "tests/attribute_test.rb", "tests/rgb_triple_test.rb", "tests/test_helper.rb"]
|
15
15
|
s.homepage = "http://flori.github.com/term-ansicolor"
|
16
16
|
s.licenses = ["GPL-2"]
|
17
17
|
s.rdoc_options = ["--title", "Term-ansicolor - Ruby library that colors strings using ANSI escape sequences", "--main", "README.rdoc"]
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
s.rubygems_version = "2.0.3"
|
20
20
|
s.summary = "Ruby library that colors strings using ANSI escape sequences"
|
21
|
-
s.test_files = ["tests/ansicolor_test.rb", "tests/rgb_triple_test.rb", "tests/test_helper.rb"]
|
21
|
+
s.test_files = ["tests/ansicolor_test.rb", "tests/attribute_test.rb", "tests/rgb_triple_test.rb", "tests/test_helper.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
s.specification_version = 4
|
data/tests/ansicolor_test.rb
CHANGED
@@ -102,6 +102,7 @@ class ANSIColorTest < Test::Unit::TestCase
|
|
102
102
|
assert_not_equal foo, foo_colored = __send__(a) { foo }
|
103
103
|
assert_equal foo, uncolor { foo_colored }
|
104
104
|
end
|
105
|
+
assert_equal Term::ANSIColor.attributes, 'foo'.attributes
|
105
106
|
end
|
106
107
|
|
107
108
|
def test_coloring_string_like
|
@@ -115,14 +116,4 @@ class ANSIColorTest < Test::Unit::TestCase
|
|
115
116
|
assert string.frozen?
|
116
117
|
assert_equal red, string.red
|
117
118
|
end
|
118
|
-
|
119
|
-
def test_nearest_rgb_color
|
120
|
-
assert_equal Term::ANSIColor::Attribute.get(:color0).rgb, Term::ANSIColor::Attribute.nearest_rgb_color('#000').rgb
|
121
|
-
assert_equal Term::ANSIColor::Attribute.get(:color15).rgb, Term::ANSIColor::Attribute.nearest_rgb_color('#ffffff').rgb
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_nearest_rgb_color
|
125
|
-
assert_equal Term::ANSIColor::Attribute.get(:on_color0).rgb, Term::ANSIColor::Attribute.nearest_rgb_on_color('#000').rgb
|
126
|
-
assert_equal Term::ANSIColor::Attribute.get(:on_color15).rgb, Term::ANSIColor::Attribute.nearest_rgb_on_color('#ffffff').rgb
|
127
|
-
end
|
128
119
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class AttributeTest < Test::Unit::TestCase
|
4
|
+
include Term::ANSIColor
|
5
|
+
|
6
|
+
def test_cast
|
7
|
+
color = Attribute.get(:color123)
|
8
|
+
on_color = Attribute.get(:on_color123)
|
9
|
+
assert_equal color, Attribute[color]
|
10
|
+
assert_equal color, Attribute[:color123]
|
11
|
+
assert_equal color, Attribute[123]
|
12
|
+
assert_equal color, Attribute['123']
|
13
|
+
assert_equal color, Attribute['#87ffff']
|
14
|
+
assert_equal on_color, Attribute['on_123']
|
15
|
+
assert_equal on_color, Attribute['on_#87ffff']
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_distance_to
|
19
|
+
assert_in_delta 149.685, Attribute.get(:color0).distance_to(Attribute.nearest_rgb_color('#0f0')), 1e-3
|
20
|
+
assert_equal 1 / 0.0, Attribute.get(:color0).distance_to(nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_nearest_rgb_color
|
24
|
+
assert_equal Attribute.get(:color0).rgb, Attribute.nearest_rgb_color('#000').rgb
|
25
|
+
assert_equal Attribute.get(:color15).rgb, Attribute.nearest_rgb_color('#ffffff').rgb
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_nearest_rgb_on_color
|
29
|
+
assert_equal Attribute.get(:on_color0).rgb, Attribute.nearest_rgb_on_color('#000').rgb
|
30
|
+
assert_equal Attribute.get(:on_color15).rgb, Attribute.nearest_rgb_on_color('#ffffff').rgb
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: term-ansicolor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: simplecov
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: This library uses ANSI escape sequences to control the attributes of
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/term/ansicolor/version.rb
|
72
72
|
- term-ansicolor.gemspec
|
73
73
|
- tests/ansicolor_test.rb
|
74
|
+
- tests/attribute_test.rb
|
74
75
|
- tests/rgb_triple_test.rb
|
75
76
|
- tests/test_helper.rb
|
76
77
|
homepage: http://flori.github.com/term-ansicolor
|
@@ -87,12 +88,12 @@ require_paths:
|
|
87
88
|
- lib
|
88
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
89
90
|
requirements:
|
90
|
-
- - '>='
|
91
|
+
- - ! '>='
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
95
|
requirements:
|
95
|
-
- - '>='
|
96
|
+
- - ! '>='
|
96
97
|
- !ruby/object:Gem::Version
|
97
98
|
version: '0'
|
98
99
|
requirements: []
|
@@ -103,5 +104,6 @@ specification_version: 4
|
|
103
104
|
summary: Ruby library that colors strings using ANSI escape sequences
|
104
105
|
test_files:
|
105
106
|
- tests/ansicolor_test.rb
|
107
|
+
- tests/attribute_test.rb
|
106
108
|
- tests/rgb_triple_test.rb
|
107
109
|
- tests/test_helper.rb
|