Class: ColorTail::Colorize
- Inherits:
-
Object
- Object
- ColorTail::Colorize
- Defined in:
- lib/colortail.rb
Constant Summary collapse
- COLORS =
{ :none => "0", :black => "30", :red => "31", :green => "32", :yellow => "33", :blue => "34", :magenta => "35", :cyan => "36", :white => "37" }
- ATTRIBUTES =
{ :bright => 1, :dim => 2, :underscore => 4, :blink => 5, :reverse => 7, :hidden => 8 }
- @@color_matchers =
[]
Instance Method Summary collapse
- #add_color_matcher(options) ⇒ Object
- #colorit(message, color, attribute, nl = "\n") ⇒ Object
- #log(filename, message, line_prefix = nil) ⇒ Object
- #show(message, prefix) ⇒ Object
Instance Method Details
#add_color_matcher(options) ⇒ Object
69 70 71 |
# File 'lib/colortail.rb', line 69 def add_color_matcher( ) @@color_matchers.push( ) end |
#colorit(message, color, attribute, nl = "\n") ⇒ Object
64 65 66 67 |
# File 'lib/colortail.rb', line 64 def colorit(, color, attribute, nl = "\n") attribute = "#{attribute};" if attribute "\e[#{attribute}#{color}m" + .strip + "\e[0m#{nl}" end |
#log(filename, message, line_prefix = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/colortail.rb', line 35 def log(filename, , line_prefix=nil) # Add the filename to the message = "#{}" color = :none attribute = nil @@color_matchers.each do |filter| if =~ filter[:match] color = filter[:color] attribute = filter[:attribute] = filter[:prepend] + unless filter[:prepend].nil? break end end if color != :hide current_color = COLORS[color] current_attribute = ATTRIBUTES[attribute] line_prefix = colorit(line_prefix.to_s, current_color, current_attribute, nil) unless line_prefix.nil? show(colorit(, current_color, current_attribute), line_prefix) end end |
#show(message, prefix) ⇒ Object
60 61 62 |
# File 'lib/colortail.rb', line 60 def show(,prefix) puts "#{prefix}#{}" end |