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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6c9a92f957cb6c294806caa9b03a2c04445d76a9
4
- data.tar.gz: 5eac0662983ec23f174bd5d0af4687120fd49cb9
5
- SHA512:
6
- metadata.gz: e633cda3e9d3b749c7c3a5282012e0f9f0bda78c1674c8de081461b4df16719e7916191c4d7bb57eefa0817c13c7bafc6557a303fdcab8c635c7c786f8598663
7
- data.tar.gz: ec810aa236b5ff82b942de368b30f262b82189423afb3abcbc1ade2f6f3673794b29564799008fbf4b2d753f6fe02c20534dff3b530155240f9e52f7b9e55263
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.2
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 = $colors[c]
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'),
@@ -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) || Attribute.nearest_rgb(name) or
197
- raise ArgumentError, "unknown attribute #{name.inspect}"
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
- @term_ansicolor_attributes ||= Term::ANSIColor::ATTRIBUTE_NAMES
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
@@ -1,6 +1,6 @@
1
1
  module Term::ANSIColor
2
2
  # Term::ANSIColor version
3
- VERSION = '1.1.2'
3
+ VERSION = '1.1.3'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "term-ansicolor"
5
- s.version = "1.1.2"
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
@@ -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.2
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