class Thor::Shell::Color


Thor::Shell::Basic to see all available methods.
Inherit from Thor::Shell::Basic and add set_color behavior. Check

def diff_lcs_loaded? #:nodoc:

:nodoc:

for diff.
Check if Diff::LCS is loaded. If it is, use it to create pretty output
def diff_lcs_loaded? #:nodoc:
  return true  if defined?(Diff::LCS)
  return @diff_lcs_loaded unless @diff_lcs_loaded.nil?
  @diff_lcs_loaded = begin
    require 'diff/lcs'
    true
  rescue LoadError
    false
  end
end

def output_diff_line(diff) #:nodoc:

:nodoc:
def output_diff_line(diff) #:nodoc:
  case diff.action
    when '-'
      say "- #{diff.old_element.chomp}", :red, true
    when '+'
      say "+ #{diff.new_element.chomp}", :green, true
    when '!'
      say "- #{diff.old_element.chomp}", :red, true
      say "+ #{diff.new_element.chomp}", :green, true
    else
      say "  #{diff.old_element.chomp}", nil, true
  end
end

def set_color(string, color, bold=false)


of the returned String.
on Highline implementation and it automatically appends CLEAR to the end
option is set to true, it also adds bold to the string. This is based
Set color by using a string or one of the defined constants. If a third
def set_color(string, color, bold=false)
  color = self.class.const_get(color.to_s.upcase) if color.is_a?(Symbol)
  bold  = bold ? BOLD : ""
  "#{bold}#{color}#{string}#{CLEAR}"
end

def show_diff(destination, content) #:nodoc:

:nodoc:

available.
Overwrite show_diff to show diff with colors if Diff::LCS is
def show_diff(destination, content) #:nodoc:
  if diff_lcs_loaded? && ENV['THOR_DIFF'].nil? && ENV['RAILS_DIFF'].nil?
    actual  = File.binread(destination).to_s.split("\n")
    content = content.to_s.split("\n")
    Diff::LCS.sdiff(actual, content).each do |diff|
      output_diff_line(diff)
    end
  else
    super
  end
end