Module: Ackr::Colorizer

Defined in:
lib/ackr/colorizer.rb

Overview

Methods to add terminal color commands into strings.

Class Method Summary collapse

Class Method Details

.for_file(string) ⇒ Object

Public: Highlight a filename.

string - The filename.

Returns the String filename highlighted.



15
16
17
# File 'lib/ackr/colorizer.rb', line 15

def self.for_file string
  string.foreground(:blue).bright.underline
end

.for_line(string, search) ⇒ Object

Public: Highlight a matched file line.

string - The line. search - The String search term.

Returns the String line highlighted.



25
26
27
28
29
30
31
32
# File 'lib/ackr/colorizer.rb', line 25

def self.for_line string, search
  search = Regexp.new(search, Regexp::IGNORECASE) if search.is_a?(String)
  begin
    string.gsub(search) {|exp| exp.bright }
  rescue Exception => ex
    puts "Error ".background(:red) + ex.message
  end
end