term-ansicolor 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  .*.sw[pon]
2
+ .rvmrc
2
3
  Gemfile.lock
4
+ coverage
3
5
  pkg
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ruby-head
6
+ - ree
7
+ - rbx
8
+ - jruby
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ GemHadar do
12
12
  summary 'Ruby library that colors strings using ANSI escape sequences'
13
13
  description ''
14
14
  test_dir 'tests'
15
- ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock'
15
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage'
16
16
  readme 'README.rdoc'
17
17
  executables << 'cdiff' << 'decolor'
18
18
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.6
1
+ 1.0.7
data/examples/example.rb CHANGED
@@ -79,7 +79,7 @@ print red { bold { "All supported attributes = " } },
79
79
  blue { symbols.inspect }, "\n\n"
80
80
 
81
81
  print "Send symbols to strings:".send(:red).send(:bold), "\n"
82
- print symbols[12, 8].map { |c| c.to_s.send(c) }, "\n\n"
82
+ print symbols[12, 8].map { |c| c.to_s.send(c) } * '', "\n\n"
83
83
 
84
84
  print red { bold { "Make strings monochromatic again:" } }, "\n"
85
85
  print [
@@ -87,4 +87,4 @@ print [
87
87
  "not red anymore".red.uncolored,
88
88
  uncolored { "not red anymore".red },
89
89
  uncolored("not red anymore".red)
90
- ].map { |x| x + "\n" }
90
+ ].map { |x| x + "\n" } * ''
@@ -1,44 +1,73 @@
1
1
  module Term
2
- require 'term/ansicolor/version'
3
2
 
4
3
  # The ANSIColor module can be used for namespacing and mixed into your own
5
4
  # classes.
6
5
  module ANSIColor
6
+ require 'term/ansicolor/version'
7
+
7
8
  # :stopdoc:
8
9
  ATTRIBUTES = [
9
- [ :clear , 0 ],
10
- [ :reset , 0 ], # synonym for :clear
11
- [ :bold , 1 ],
12
- [ :dark , 2 ],
13
- [ :italic , 3 ], # not widely implemented
14
- [ :underline , 4 ],
15
- [ :underscore , 4 ], # synonym for :underline
16
- [ :blink , 5 ],
17
- [ :rapid_blink , 6 ], # not widely implemented
18
- [ :negative , 7 ], # no reverse because of String#reverse
19
- [ :concealed , 8 ],
20
- [ :strikethrough, 9 ], # not widely implemented
21
- [ :black , 30 ],
22
- [ :red , 31 ],
23
- [ :green , 32 ],
24
- [ :yellow , 33 ],
25
- [ :blue , 34 ],
26
- [ :magenta , 35 ],
27
- [ :cyan , 36 ],
28
- [ :white , 37 ],
29
- [ :on_black , 40 ],
30
- [ :on_red , 41 ],
31
- [ :on_green , 42 ],
32
- [ :on_yellow , 43 ],
33
- [ :on_blue , 44 ],
34
- [ :on_magenta , 45 ],
35
- [ :on_cyan , 46 ],
36
- [ :on_white , 47 ],
10
+ [ :clear , 0 ], # String#clear is already used to empty string in Ruby 1.9
11
+ [ :reset , 0 ], # synonym for :clear
12
+ [ :bold , 1 ],
13
+ [ :dark , 2 ],
14
+ [ :italic , 3 ], # not widely implemented
15
+ [ :underline , 4 ],
16
+ [ :underscore , 4 ], # synonym for :underline
17
+ [ :blink , 5 ],
18
+ [ :rapid_blink , 6 ], # not widely implemented
19
+ [ :negative , 7 ], # no reverse because of String#reverse
20
+ [ :concealed , 8 ],
21
+ [ :strikethrough , 9 ], # not widely implemented
22
+ [ :black , 30 ],
23
+ [ :red , 31 ],
24
+ [ :green , 32 ],
25
+ [ :yellow , 33 ],
26
+ [ :blue , 34 ],
27
+ [ :magenta , 35 ],
28
+ [ :cyan , 36 ],
29
+ [ :white , 37 ],
30
+ [ :on_black , 40 ],
31
+ [ :on_red , 41 ],
32
+ [ :on_green , 42 ],
33
+ [ :on_yellow , 43 ],
34
+ [ :on_blue , 44 ],
35
+ [ :on_magenta , 45 ],
36
+ [ :on_cyan , 46 ],
37
+ [ :on_white , 47 ],
38
+ [ :intense_black , 90 ], # High intensity, aixterm (works in OS X)
39
+ [ :intense_red , 91 ],
40
+ [ :intense_green , 92 ],
41
+ [ :intense_yellow , 93 ],
42
+ [ :intense_blue , 94 ],
43
+ [ :intense_magenta , 95 ],
44
+ [ :intense_cyan , 96 ],
45
+ [ :intense_white , 97 ],
46
+ [ :on_intense_black , 100 ], # High intensity background, aixterm (works in OS X)
47
+ [ :on_intense_red , 101 ],
48
+ [ :on_intense_green , 102 ],
49
+ [ :on_intense_yellow , 103 ],
50
+ [ :on_intense_blue , 104 ],
51
+ [ :on_intense_magenta , 105 ],
52
+ [ :on_intense_cyan , 106 ],
53
+ [ :on_intense_white , 107 ]
37
54
  ]
38
55
 
39
56
  ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
40
57
  # :startdoc:
41
58
 
59
+ # Returns true if Term::ANSIColor supports the +feature+.
60
+ #
61
+ # The feature :clear, that is mixing the clear color attribute into String,
62
+ # is only supported on ruby implementations, that do *not* already
63
+ # implement the String#clear method. It's better to use the reset color
64
+ # attribute instead.
65
+ def support?(feature)
66
+ case feature
67
+ when :clear
68
+ !String.instance_methods(false).map(&:to_sym).include?(:clear)
69
+ end
70
+ end
42
71
  # Returns true, if the coloring function of this module
43
72
  # is switched on, false otherwise.
44
73
  def self.coloring?
@@ -54,36 +83,36 @@ module Term
54
83
  self.coloring = true
55
84
 
56
85
  ATTRIBUTES.each do |c, v|
57
- eval %Q{
58
- def #{c}(string = nil)
59
- result = ''
60
- result << "\e[#{v}m" if Term::ANSIColor.coloring?
61
- if block_given?
62
- result << yield
63
- elsif string
64
- result << string
65
- elsif respond_to?(:to_str)
66
- result << to_str
67
- else
68
- return result #only switch on
69
- end
70
- result << "\e[0m" if Term::ANSIColor.coloring?
71
- result
86
+ eval <<-EOT
87
+ def #{c}(string = nil)
88
+ result = ''
89
+ result << "\e[#{v}m" if Term::ANSIColor.coloring?
90
+ if block_given?
91
+ result << yield
92
+ elsif string.respond_to?(:to_str)
93
+ result << string.to_str
94
+ elsif respond_to?(:to_str)
95
+ result << to_str
96
+ else
97
+ return result #only switch on
72
98
  end
73
- }
99
+ result << "\e[0m" if Term::ANSIColor.coloring?
100
+ result
101
+ end
102
+ EOT
74
103
  end
75
104
 
76
105
  # Regular expression that is used to scan for ANSI-sequences while
77
106
  # uncoloring strings.
78
- COLORED_REGEXP = /\e\[(?:[34][0-7]|[0-9])?m/
107
+ COLORED_REGEXP = /\e\[(?:(?:[349]|10)[0-7]|[0-9])?m/
79
108
 
80
109
  # Returns an uncolored version of the string, that is all
81
110
  # ANSI-sequences are stripped from the string.
82
111
  def uncolored(string = nil) # :yields:
83
112
  if block_given?
84
- yield.gsub(COLORED_REGEXP, '')
85
- elsif string
86
- string.gsub(COLORED_REGEXP, '')
113
+ yield.to_str.gsub(COLORED_REGEXP, '')
114
+ elsif string.respond_to?(:to_str)
115
+ string.to_str.gsub(COLORED_REGEXP, '')
87
116
  elsif respond_to?(:to_str)
88
117
  to_str.gsub(COLORED_REGEXP, '')
89
118
  else
@@ -1,6 +1,6 @@
1
1
  module Term::ANSIColor
2
2
  # Term::ANSIColor version
3
- VERSION = '1.0.6'
3
+ VERSION = '1.0.7'
4
4
  VERSION_ARRAY = VERSION.split(/\./).map { |x| x.to_i } # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -1,33 +1,33 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.name = %q{term-ansicolor}
5
- s.version = "1.0.6"
4
+ s.name = "term-ansicolor"
5
+ s.version = "1.0.7"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = [%q{Florian Frank}]
9
- s.date = %q{2011-07-21}
10
- s.description = %q{}
11
- s.email = %q{flori@ping.de}
12
- s.executables = [%q{decolor}, %q{cdiff}]
13
- s.extra_rdoc_files = [%q{README.rdoc}, %q{lib/term/ansicolor/version.rb}, %q{lib/term/ansicolor.rb}]
14
- s.files = [%q{.gitignore}, %q{CHANGES}, %q{COPYING}, %q{Gemfile}, %q{README.rdoc}, %q{Rakefile}, %q{VERSION}, %q{bin/cdiff}, %q{bin/decolor}, %q{doc-main.txt}, %q{examples/example.rb}, %q{install.rb}, %q{lib/term/ansicolor.rb}, %q{lib/term/ansicolor/.keep}, %q{lib/term/ansicolor/version.rb}, %q{term-ansicolor.gemspec}, %q{tests/ansicolor_test.rb}]
15
- s.homepage = %q{http://flori.github.com/term-ansicolor}
16
- s.rdoc_options = [%q{--title}, %q{Term-ansicolor - Ruby library that colors strings using ANSI escape sequences}, %q{--main}, %q{README.rdoc}]
17
- s.require_paths = [%q{lib}]
18
- s.rubygems_version = %q{1.8.5}
19
- s.summary = %q{Ruby library that colors strings using ANSI escape sequences}
20
- s.test_files = [%q{tests/ansicolor_test.rb}]
8
+ s.authors = ["Florian Frank"]
9
+ s.date = "2011-10-13"
10
+ s.description = ""
11
+ s.email = "flori@ping.de"
12
+ s.executables = ["cdiff", "decolor"]
13
+ s.extra_rdoc_files = ["README.rdoc", "lib/term/ansicolor/version.rb", "lib/term/ansicolor.rb"]
14
+ s.files = [".gitignore", ".travis.yml", "CHANGES", "COPYING", "Gemfile", "README.rdoc", "Rakefile", "VERSION", "bin/cdiff", "bin/decolor", "doc-main.txt", "examples/example.rb", "install.rb", "lib/term/ansicolor.rb", "lib/term/ansicolor/.keep", "lib/term/ansicolor/version.rb", "term-ansicolor.gemspec", "tests/ansicolor_test.rb"]
15
+ s.homepage = "http://flori.github.com/term-ansicolor"
16
+ s.rdoc_options = ["--title", "Term-ansicolor - Ruby library that colors strings using ANSI escape sequences", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubygems_version = "1.8.11"
19
+ s.summary = "Ruby library that colors strings using ANSI escape sequences"
20
+ s.test_files = ["tests/ansicolor_test.rb"]
21
21
 
22
22
  if s.respond_to? :specification_version then
23
23
  s.specification_version = 3
24
24
 
25
25
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_development_dependency(%q<gem_hadar>, ["~> 0.0.8"])
26
+ s.add_development_dependency(%q<gem_hadar>, ["~> 0.1.1"])
27
27
  else
28
- s.add_dependency(%q<gem_hadar>, ["~> 0.0.8"])
28
+ s.add_dependency(%q<gem_hadar>, ["~> 0.1.1"])
29
29
  end
30
30
  else
31
- s.add_dependency(%q<gem_hadar>, ["~> 0.0.8"])
31
+ s.add_dependency(%q<gem_hadar>, ["~> 0.1.1"])
32
32
  end
33
33
  end
@@ -11,6 +11,16 @@ class Color
11
11
  extend Term::ANSIColor
12
12
  end
13
13
 
14
+ class StringLike
15
+ def initialize(string)
16
+ @string = string
17
+ end
18
+
19
+ def to_str
20
+ @string
21
+ end
22
+ end
23
+
14
24
  class ANSIColorTest < Test::Unit::TestCase
15
25
  include Term::ANSIColor
16
26
 
@@ -18,9 +28,11 @@ class ANSIColorTest < Test::Unit::TestCase
18
28
  @string = "red"
19
29
  @string_red = "\e[31mred\e[0m"
20
30
  @string_red_on_green = "\e[42m\e[31mred\e[0m\e[0m"
31
+ @string_like = StringLike.new(@string)
32
+ @string_like_red = StringLike.new(@string_red)
21
33
  end
22
34
 
23
- attr_reader :string, :string_red, :string_red_on_green
35
+ attr_reader :string, :string_red, :string_red_on_green, :string_like, :string_like_red
24
36
 
25
37
  def test_red
26
38
  assert_equal string_red, string.red
@@ -43,16 +55,24 @@ class ANSIColorTest < Test::Unit::TestCase
43
55
  def test_uncolored
44
56
  assert_equal string, string_red.uncolored
45
57
  assert_equal string, Color.uncolored(string_red)
58
+ assert_equal string, Color.uncolored(string_like_red)
46
59
  assert_equal string, Color.uncolored { string_red }
60
+ assert_equal string, Color.uncolored { string_like_red }
47
61
  assert_equal string, Term::ANSIColor.uncolored { string_red }
62
+ assert_equal string, Term::ANSIColor.uncolored { string_like_red }
48
63
  assert_equal string, uncolored { string }
64
+ assert_equal string, uncolored { string_like_red }
65
+ assert_equal "", uncolored(Object.new)
49
66
  end
50
67
 
51
68
  def test_attributes
52
69
  foo = 'foo'
53
70
  for (a, _) in Term::ANSIColor.attributes
54
- assert_not_equal foo, foo_colored = foo.__send__(a)
55
- assert_equal foo, foo_colored.uncolored
71
+ # skip clear for Ruby 1.9 which implements String#clear to empty the string
72
+ if a != :clear || Term::ANSIColor.support?(:clear)
73
+ assert_not_equal foo, foo_colored = foo.__send__(a)
74
+ assert_equal foo, foo_colored.uncolored
75
+ end
56
76
  assert_not_equal foo, foo_colored = Color.__send__(a, foo)
57
77
  assert_equal foo, Color.uncolored(foo_colored)
58
78
  assert_not_equal foo, foo_colored = Color.__send__(a) { foo }
@@ -63,4 +83,8 @@ class ANSIColorTest < Test::Unit::TestCase
63
83
  assert_equal foo, uncolored { foo_colored }
64
84
  end
65
85
  end
86
+
87
+ def test_coloring_string_like
88
+ assert_equal "\e[31mred\e[0m", red(string_like)
89
+ end
66
90
  end
metadata CHANGED
@@ -1,51 +1,40 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: term-ansicolor
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.7
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 6
10
- version: 1.0.6
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Florian Frank
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-21 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: gem_hadar
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &74228550 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 15
29
- segments:
30
- - 0
31
- - 0
32
- - 8
33
- version: 0.0.8
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.1
34
22
  type: :development
35
- version_requirements: *id001
36
- description: ""
23
+ prerelease: false
24
+ version_requirements: *74228550
25
+ description: ''
37
26
  email: flori@ping.de
38
- executables:
39
- - decolor
27
+ executables:
40
28
  - cdiff
29
+ - decolor
41
30
  extensions: []
42
-
43
- extra_rdoc_files:
31
+ extra_rdoc_files:
44
32
  - README.rdoc
45
33
  - lib/term/ansicolor/version.rb
46
34
  - lib/term/ansicolor.rb
47
- files:
35
+ files:
48
36
  - .gitignore
37
+ - .travis.yml
49
38
  - CHANGES
50
39
  - COPYING
51
40
  - Gemfile
@@ -64,39 +53,31 @@ files:
64
53
  - tests/ansicolor_test.rb
65
54
  homepage: http://flori.github.com/term-ansicolor
66
55
  licenses: []
67
-
68
56
  post_install_message:
69
- rdoc_options:
57
+ rdoc_options:
70
58
  - --title
71
59
  - Term-ansicolor - Ruby library that colors strings using ANSI escape sequences
72
60
  - --main
73
61
  - README.rdoc
74
- require_paths:
62
+ require_paths:
75
63
  - lib
76
- required_ruby_version: !ruby/object:Gem::Requirement
64
+ required_ruby_version: !ruby/object:Gem::Requirement
77
65
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
85
- required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
71
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
94
76
  requirements: []
95
-
96
77
  rubyforge_project:
97
- rubygems_version: 1.8.5
78
+ rubygems_version: 1.8.11
98
79
  signing_key:
99
80
  specification_version: 3
100
81
  summary: Ruby library that colors strings using ANSI escape sequences
101
- test_files:
82
+ test_files:
102
83
  - tests/ansicolor_test.rb