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 +2 -0
- data/.travis.yml +8 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/examples/example.rb +2 -2
- data/lib/term/ansicolor.rb +78 -49
- data/lib/term/ansicolor/version.rb +1 -1
- data/term-ansicolor.gemspec +18 -18
- data/tests/ansicolor_test.rb +27 -3
- metadata +33 -52
data/.gitignore
CHANGED
data/.travis.yml
ADDED
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.
|
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" } * ''
|
data/lib/term/ansicolor.rb
CHANGED
@@ -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
|
10
|
-
[ :reset
|
11
|
-
[ :bold
|
12
|
-
[ :dark
|
13
|
-
[ :italic
|
14
|
-
[ :underline
|
15
|
-
[ :underscore
|
16
|
-
[ :blink
|
17
|
-
[ :rapid_blink
|
18
|
-
[ :negative
|
19
|
-
[ :concealed
|
20
|
-
[ :strikethrough, 9 ], # not widely implemented
|
21
|
-
[ :black
|
22
|
-
[ :red
|
23
|
-
[ :green
|
24
|
-
[ :yellow
|
25
|
-
[ :blue
|
26
|
-
[ :magenta
|
27
|
-
[ :cyan
|
28
|
-
[ :white
|
29
|
-
[ :on_black
|
30
|
-
[ :on_red
|
31
|
-
[ :on_green
|
32
|
-
[ :on_yellow
|
33
|
-
[ :on_blue
|
34
|
-
[ :on_magenta
|
35
|
-
[ :on_cyan
|
36
|
-
[ :on_white
|
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
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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\[(?:[
|
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
|
data/term-ansicolor.gemspec
CHANGED
@@ -1,33 +1,33 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.name =
|
5
|
-
s.version = "1.0.
|
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 = [
|
9
|
-
s.date =
|
10
|
-
s.description =
|
11
|
-
s.email =
|
12
|
-
s.executables = [
|
13
|
-
s.extra_rdoc_files = [
|
14
|
-
s.files = [
|
15
|
-
s.homepage =
|
16
|
-
s.rdoc_options = [
|
17
|
-
s.require_paths = [
|
18
|
-
s.rubygems_version =
|
19
|
-
s.summary =
|
20
|
-
s.test_files = [
|
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.
|
26
|
+
s.add_development_dependency(%q<gem_hadar>, ["~> 0.1.1"])
|
27
27
|
else
|
28
|
-
s.add_dependency(%q<gem_hadar>, ["~> 0.
|
28
|
+
s.add_dependency(%q<gem_hadar>, ["~> 0.1.1"])
|
29
29
|
end
|
30
30
|
else
|
31
|
-
s.add_dependency(%q<gem_hadar>, ["~> 0.
|
31
|
+
s.add_dependency(%q<gem_hadar>, ["~> 0.1.1"])
|
32
32
|
end
|
33
33
|
end
|
data/tests/ansicolor_test.rb
CHANGED
@@ -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
|
-
|
55
|
-
|
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
|
-
|
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
|
-
|
19
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
36
|
-
|
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
|
-
|
82
|
-
|
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
|
-
|
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.
|
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
|