Module: DiffToString::Style

Included in:
DiffToString
Defined in:
lib/nandoc/support/diff-to-string.rb

Constant Summary collapse

Codes =
{:red=>'31', :green=>'32', :bold=>'1', :red_bg=>'41',
  :magenta => '35'
}

Instance Method Summary collapse

Instance Method Details

#stylize(str, *codes) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/nandoc/support/diff-to-string.rb', line 21

def stylize str, *codes
  if 1 == codes.size
    if codes.first.nil?
      return str
    elsif codes.first.kind_of?(Array)
      codes = codes.first
    end
  end
  codes = codes.map{|c| Codes[c]}
  "\033[#{codes * ';'}m#{str}\033[0m";
end