colorb 0.0.4 → 0.0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/colorb.rb +26 -18
- metadata +3 -2
data/lib/colorb.rb
CHANGED
@@ -44,58 +44,66 @@ class String
|
|
44
44
|
remove_method name rescue nil
|
45
45
|
}
|
46
46
|
|
47
|
-
|
47
|
+
attr_accessor :foreground, :background, :flags
|
48
48
|
|
49
49
|
alias __old_method_missing method_missing
|
50
50
|
|
51
51
|
def method_missing (id, *args, &block)
|
52
52
|
name = id.to_s.match(/^(.+?)[!?]?$/)[1].to_sym
|
53
53
|
|
54
|
+
result = self.frozen? ? "#{self}" : self
|
55
|
+
|
54
56
|
return __old_method_missing(id, *args, &block) unless Colors[name] || Extra[name]
|
55
57
|
|
56
58
|
if Colors[name]
|
57
59
|
if id.to_s.end_with?('?')
|
58
|
-
|
60
|
+
result.foreground == name
|
59
61
|
else
|
60
|
-
if
|
61
|
-
|
62
|
+
if !result.foreground
|
63
|
+
result.foreground = name
|
62
64
|
else
|
63
|
-
|
65
|
+
result.background = name
|
64
66
|
end
|
65
67
|
end
|
66
68
|
elsif Extra[name]
|
67
|
-
|
69
|
+
result.flags ||= []
|
68
70
|
|
69
71
|
if id.to_s.end_with?('?')
|
70
|
-
|
72
|
+
result.flags.member?(name)
|
71
73
|
else
|
72
|
-
|
74
|
+
result.flags << name
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
|
-
|
78
|
+
result.lazy? ? result : result.colorify!
|
77
79
|
end
|
78
80
|
|
79
|
-
def color (code)
|
81
|
+
def color (code, second=nil)
|
82
|
+
return method_missing(code.to_sym) if code.is_a?(Symbol) || code.is_a?(String)
|
83
|
+
|
84
|
+
result = self.frozen? ? "#{self}" : self
|
85
|
+
|
80
86
|
if code < 16
|
81
87
|
if code > 7
|
82
|
-
(
|
88
|
+
(result.flags ||= []) << (!result.foreground ? :bold : :blink)
|
83
89
|
end
|
84
90
|
|
85
|
-
if
|
86
|
-
|
91
|
+
if !result.foreground
|
92
|
+
result.foreground = code - (code > 7 ? 7 : 0)
|
87
93
|
else
|
88
|
-
|
94
|
+
result.background = code - (code > 7 ? 7 : 0)
|
89
95
|
end
|
90
96
|
else
|
91
|
-
if
|
92
|
-
|
97
|
+
if !result.foreground
|
98
|
+
result.foreground = code
|
93
99
|
else
|
94
|
-
|
100
|
+
result.background = code
|
95
101
|
end
|
96
102
|
end
|
97
103
|
|
98
|
-
|
104
|
+
result.color(second) if second
|
105
|
+
|
106
|
+
result.lazy? ? result : result.colorify!
|
99
107
|
end
|
100
108
|
|
101
109
|
def lazy; @lazy = true; self end
|
metadata
CHANGED
@@ -6,7 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.0.4.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- meh.
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-13 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|