cloudhead-mutter 0.1.0 → 0.1.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
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: value['match'], style: value['style'] }
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
- self.class.stream.write stylize(parse(str), @active + styles).gsub(/\e(\d+)/, "\e[\\1m") + "\n"
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
- open, close = ANSI[style.to_sym]
78
- "#{esc(open)}#{str}#{esc(close || 0)}"
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{mutter}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["cloudhead"]
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
- :styles => ['bold', 'red']
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudhead-mutter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - cloudhead