cloudhead-mutter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mutter.rb +12 -6
- data/mutter.gemspec +1 -1
- data/spec/mutter_spec.rb +3 -2
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/mutter.rb
CHANGED
@@ -39,14 +39,15 @@ module Mutter
|
|
39
39
|
def load styles
|
40
40
|
styles += '.yml' unless styles =~ /\.ya?ml/
|
41
41
|
styles = YAML.load_file(styles).inject({}) do |h, (key, value)|
|
42
|
-
value = { match
|
42
|
+
value = { :match => value['match'], :style => value['style'] }
|
43
43
|
h.merge key.to_sym => value
|
44
44
|
end
|
45
45
|
@styles.merge! styles
|
46
46
|
end
|
47
47
|
|
48
48
|
def say str, *styles
|
49
|
-
|
49
|
+
out = stylize(parse(str), @active + styles)
|
50
|
+
self.class.stream.write out.gsub(/\e(\d+)\e/, "\e[\\1m") + "\n"
|
50
51
|
self.class.stream.flush
|
51
52
|
end
|
52
53
|
alias :print say
|
@@ -72,15 +73,20 @@ module Mutter
|
|
72
73
|
end
|
73
74
|
end
|
74
75
|
|
75
|
-
def stylize string, styles = []
|
76
|
+
def stylize string, styles = []
|
76
77
|
[styles].flatten.inject(string) do |str, style|
|
77
|
-
|
78
|
-
|
78
|
+
style = style.to_sym
|
79
|
+
if ANSI.include? style
|
80
|
+
open, close = ANSI[style]
|
81
|
+
"#{esc(open)}#{str}#{esc(close || 0)}"
|
82
|
+
else
|
83
|
+
stylize(str, @styles[style][:style])
|
84
|
+
end
|
79
85
|
end
|
80
86
|
end
|
81
87
|
|
82
88
|
def esc style
|
83
|
-
"\e#{style}"
|
89
|
+
"\e#{style}\e"
|
84
90
|
end
|
85
91
|
|
86
92
|
def self.stream
|
data/mutter.gemspec
CHANGED
data/spec/mutter_spec.rb
CHANGED
@@ -57,11 +57,12 @@ describe Mutter do
|
|
57
57
|
it "should work with custom styles" do
|
58
58
|
style = {
|
59
59
|
:alert => {
|
60
|
-
:match => '
|
61
|
-
:
|
60
|
+
:match => '!!',
|
61
|
+
:style => ['bold', 'red']
|
62
62
|
}
|
63
63
|
}
|
64
64
|
Mutter.new(style).say "alert!", :alert
|
65
|
+
out.should == "\e[31m\e[1malert!\e[22m\e[0m\n"
|
65
66
|
end
|
66
67
|
|
67
68
|
it "should work with shorthand custom styles" do
|