module Crayon::StringBuilder

Public Instance Methods

background_string() click to toggle source
# File lib/crayon/string_builder.rb, line 20
def background_string
  handle_color(4, @background)
end
foreground_string() click to toggle source
# File lib/crayon/string_builder.rb, line 16
def foreground_string
  handle_color(3, @foreground)
end
formatting_string() click to toggle source
# File lib/crayon/string_builder.rb, line 24
def formatting_string
  return "" if @formatting.empty?
  @formatting.map{|format| "\e[#{FORMATS[format]}m"}.join("")
end
handle_color(lead, color) click to toggle source
# File lib/crayon/string_builder.rb, line 29
def handle_color(lead, color)
  return "" unless color
  "\e[#{lead}#{COLORS[color]}m"
end
has_color?() click to toggle source
# File lib/crayon/string_builder.rb, line 12
def has_color?
  @foreground || @background || @formatting.any?
end
prepare_string(string) click to toggle source
# File lib/crayon/string_builder.rb, line 3
def prepare_string(string)
  [ foreground_string,
    background_string,
    formatting_string,
    string,
    (TERMINATION_STRING if has_color?)
  ].compact.join("")
end