easy-color 0.1.0 → 0.2.0
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/easy-color.rb +36 -26
- metadata +1 -1
data/lib/easy-color.rb
CHANGED
@@ -29,39 +29,49 @@
|
|
29
29
|
# POSSIBILITY OF SUCH DAMAGE.
|
30
30
|
################################################################################
|
31
31
|
|
32
|
-
|
32
|
+
$color = {
|
33
|
+
:black => 30, :red => 31, :green => 32,
|
34
|
+
:yellow => 33, :blue => 34, :purple => 35,
|
35
|
+
:cyan => 36, :white => 37
|
36
|
+
}
|
37
|
+
$attrs = {
|
38
|
+
:clean => 0, :bold => 1, :underline => 4,
|
39
|
+
:blink => 5, :reverse => 7, :conceal => 8
|
40
|
+
}
|
33
41
|
|
34
|
-
|
35
|
-
def black; colorize(self, "\e[0m\e[30"); end
|
36
|
-
def red; colorize(self, "\e[0m\e[31"); end
|
37
|
-
def green; colorize(self, "\e[0m\e[32"); end
|
38
|
-
def yellow; colorize(self, "\e[0m\e[33"); end
|
39
|
-
def blue; colorize(self, "\e[0m\e[34"); end
|
40
|
-
def purple; colorize(self, "\e[0m\e[35"); end
|
41
|
-
def cyan; colorize(self, "\e[0m\e[36"); end
|
42
|
-
def white; colorize(self, "\e[0m\e[37"); end
|
42
|
+
class String
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
def valid(args)
|
45
|
+
if args.keys.include? :color and $color.keys.include? args[:color]
|
46
|
+
true
|
47
|
+
elsif args.keys.include? :attr and $attrs.keys.include? args[:attr]
|
48
|
+
true
|
49
|
+
else
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
51
53
|
|
52
|
-
|
53
|
-
|
54
|
+
def fg(color)
|
55
|
+
"\033[#{$color[color]}m#{self}\033[0m" if valid(:color => color)
|
56
|
+
end
|
54
57
|
|
55
|
-
|
56
|
-
|
57
|
-
colorize(self, "\e[#{line};#{column}", mode='f')
|
58
|
+
def bg(color)
|
59
|
+
"\033[#{($color[color]+10)}m#{self}\033[0m" if valid(:color => color)
|
58
60
|
end
|
59
61
|
|
60
|
-
def
|
61
|
-
|
62
|
+
def attr(attr)
|
63
|
+
"\033[#{($attrs[attr])}m#{self}\033[0m" if valid(:attr => attr)
|
64
|
+
end
|
62
65
|
|
63
|
-
def
|
64
|
-
|
66
|
+
def method_missing(m, *args, &block)
|
67
|
+
if $color.keys.include?(m)
|
68
|
+
fg(m)
|
69
|
+
elsif $attrs.keys.include?(m)
|
70
|
+
attr(m)
|
71
|
+
else
|
72
|
+
raise NoMethodError, "Undefined method '#{m.inspect}'."
|
73
|
+
end
|
65
74
|
end
|
66
75
|
|
67
76
|
end
|
77
|
+
|