colorb 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/colorb.rb +35 -6
- metadata +3 -3
data/lib/colorb.rb
CHANGED
@@ -57,7 +57,7 @@ class String
|
|
57
57
|
if id.to_s.end_with?('?')
|
58
58
|
@foreground == name
|
59
59
|
else
|
60
|
-
if
|
60
|
+
if !@foreground
|
61
61
|
@foreground = name
|
62
62
|
else
|
63
63
|
@background = name
|
@@ -70,7 +70,28 @@ class String
|
|
70
70
|
@flags.member?(name)
|
71
71
|
else
|
72
72
|
@flags << name
|
73
|
-
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
@lazy ? self : self.colorify!
|
77
|
+
end
|
78
|
+
|
79
|
+
def color (code)
|
80
|
+
if code < 16
|
81
|
+
if code > 7
|
82
|
+
(@flags ||= []) << (!@foreground ? :bold : :blink)
|
83
|
+
end
|
84
|
+
|
85
|
+
if !@foreground
|
86
|
+
@foreground = code - (code > 7 ? 7 : 0)
|
87
|
+
else
|
88
|
+
@background = code - (code > 7 ? 7 : 0)
|
89
|
+
end
|
90
|
+
else
|
91
|
+
if !@foreground
|
92
|
+
@foreground = code
|
93
|
+
else
|
94
|
+
@background = code
|
74
95
|
end
|
75
96
|
end
|
76
97
|
|
@@ -102,11 +123,19 @@ class String
|
|
102
123
|
result
|
103
124
|
end
|
104
125
|
|
105
|
-
def self.color! (
|
106
|
-
|
126
|
+
def self.color! (what, bg=false)
|
127
|
+
if what.is_a?(Symbol) || what.is_a?(String)
|
128
|
+
"\e[#{Colors[what.to_sym] + (bg ? 40 : 30)}m" if Colors[what.to_sym]
|
129
|
+
elsif what.is_a?(Numeric)
|
130
|
+
if what < 8
|
131
|
+
"\e[#{what + (bg ? 40 : 30)}m"
|
132
|
+
else
|
133
|
+
"\e[#{bg ? 48 : 38};5;#{what}m"
|
134
|
+
end
|
135
|
+
end
|
107
136
|
end
|
108
137
|
|
109
|
-
def self.extra! (
|
110
|
-
"\e[#{Extra[
|
138
|
+
def self.extra! (what)
|
139
|
+
Extra[what] ? "\e[#{Extra[what]}m" : "\e[#{what}m"
|
111
140
|
end
|
112
141
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- meh.
|
@@ -59,6 +59,6 @@ rubyforge_project:
|
|
59
59
|
rubygems_version: 1.3.7
|
60
60
|
signing_key:
|
61
61
|
specification_version: 3
|
62
|
-
summary: Colorify strings
|
62
|
+
summary: Colorify strings in your terminal, 256 colors supported.
|
63
63
|
test_files: []
|
64
64
|
|