colorer 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/colorer.rb +9 -10
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/colorer.rb
CHANGED
@@ -46,22 +46,21 @@ module Colorer
|
|
46
46
|
@color = true
|
47
47
|
attr_accessor :color
|
48
48
|
|
49
|
-
def add_sgr(string, sgr)
|
50
|
-
return string unless (Colorer.color && STDOUT.tty? && ENV['TERM'] && ENV['TERM'] != 'dumb')
|
51
|
-
code = sgr.is_a?(Symbol) ? Colorer::BASIC_SGR[sgr] : sgr
|
52
|
-
raise UnknownSgrCode.new(sgr) unless code.is_a? Integer
|
53
|
-
string = sprintf("\e[0m%s\e[0m", string) unless string =~ /^\e\[[\d;]+m.*\e\[0m$/
|
54
|
-
string.sub /^(\e\[[\d;]+)/, '\1;' + code.to_s
|
55
|
-
end
|
56
|
-
|
57
49
|
def define_styles(styles, force=false)
|
58
|
-
styles =
|
50
|
+
styles = BASIC_SGR.merge(styles) if styles.delete(:basic)
|
59
51
|
styles.each_pair do |meth, style|
|
60
52
|
style = [style] unless style.is_a?(Array)
|
53
|
+
codes = style.map do |s|
|
54
|
+
code = s.is_a?(Symbol) ? BASIC_SGR[s] : s
|
55
|
+
raise UnknownSgrCode.new(s) unless code.is_a?(Integer) && (0..109).include?(code)
|
56
|
+
code
|
57
|
+
end
|
61
58
|
String.class_eval do
|
62
59
|
raise AlreadyDefinedMethod.new(meth, self) if !force && method_defined?(meth)
|
63
60
|
define_method(meth) do
|
64
|
-
|
61
|
+
return self unless (Colorer.color && STDOUT.tty? && ENV['TERM'] && ENV['TERM'] != 'dumb')
|
62
|
+
string = self =~ /^\e\[[\d;]+m.*\e\[0m$/ ? self : sprintf("\e[0m%s\e[0m", self)
|
63
|
+
string.sub /^(\e\[[\d;]+)/, '\1;' + codes.join(';')
|
65
64
|
end
|
66
65
|
end
|
67
66
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 2
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Domizio Demichelis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-20 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|