Sha256: f31491b1ff2a8614fdb8d3c7948ed46d42b969157d967d7c06c4ff046e04ac32

Contents?: true

Size: 1.32 KB

Versions: 50

Compression:

Stored size: 1.32 KB

Contents

# Just some methods for outputting colorized text to a terminal
# with ansi codes, cribbed from rails. 

module TermColor
  mattr_accessor :colorize_logging
  # is nil in dev in rails 3.2, but supposed to default to true. okay. 
  self.colorize_logging = if Rails.application.config.colorize_logging.nil?
    # In Rails 3.2, somehow we can't count on config.colorize_logging being
    # set, okay, as a default colorize in development only. 
    Rails.env == "development"
  else
    Rails.application.config.colorize_logging
  end

    # Embed in a String to clear all previous ANSI sequences.
    CLEAR   = "\e[0m"
    BOLD    = "\e[1m"

    # Colors
    BLACK   = "\e[30m"
    RED     = "\e[31m"
    GREEN   = "\e[32m"
    YELLOW  = "\e[33m"
    BLUE    = "\e[34m"
    MAGENTA = "\e[35m"
    CYAN    = "\e[36m"
    WHITE   = "\e[37m"
  
    # Set color by using a string or one of the defined constants. If a third
    # option is set to true, it also adds bold to the string. This is based
    # on the Highline implementation and will automatically append CLEAR to the
    # end of the returned String.
    #
    def self.color(text, color, bold=false)
      return text unless colorize_logging
      color = self.const_get(color.to_s.upcase) if color.is_a?(Symbol)
      bold  = bold ? BOLD : ""
      "#{bold}#{color}#{text}#{CLEAR}"
    end
  
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
umlaut-4.1.7 lib/term_color.rb
umlaut-4.1.6 lib/term_color.rb
umlaut-4.1.5 lib/term_color.rb
umlaut-4.1.4 lib/term_color.rb
umlaut-4.1.3 lib/term_color.rb
umlaut-4.1.2 lib/term_color.rb
umlaut-4.1.1 lib/term_color.rb
umlaut-4.1.0 lib/term_color.rb
umlaut-4.1.0.pre3 lib/term_color.rb
umlaut-4.1.0.pre.2 lib/term_color.rb
umlaut-4.1.0.pre.alpha.1 lib/term_color.rb
umlaut-4.0.3 lib/term_color.rb
umlaut-4.0.2 lib/term_color.rb
umlaut-4.0.1 lib/term_color.rb
umlaut-4.0.0 lib/term_color.rb
umlaut-4.0.0.beta5 lib/term_color.rb
umlaut-4.0.0.beta4 lib/term_color.rb
umlaut-4.0.0.beta3 lib/term_color.rb
umlaut-4.0.0.beta2 lib/term_color.rb
umlaut-4.0.0.beta1 lib/term_color.rb