Sha256: 74b6a26d31384928fcc692f94c2901240c793d06a146058d4edbed592676d56f

Contents?: true

Size: 820 Bytes

Versions: 2

Compression:

Stored size: 820 Bytes

Contents

# -*- encoding: utf-8 -*-

gem 'rainbow', '= 1.99.2'
require 'rainbow'

module Ackr

  # Methods to add terminal color commands into strings.
  module Colorizer

    # Public: Highlight a filename.
    #
    # string - The filename.
    #
    # Returns the String filename highlighted.
    def self.for_file string
      string.foreground(:blue).bright.underline
    end

    # Public: Highlight a matched file line.
    #
    # string - The line.
    # search - The String search term.
    #
    # Returns the String line highlighted.
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ackr-0.2.4 lib/ackr/colorizer.rb
ackr-0.2.3 lib/ackr/colorizer.rb