Sha256: 5c515eb64e287f940adb9c5e919f3227ae6fedc95e4c560c0d5a3b782826878c

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

begin
  require 'ansi/code'
rescue LoadError
  begin
    require 'rubygems'
    require 'ansi/code'
  rescue LoadError
  end
end

module Turn

  module Colorize

    COLORLESS_TERMINALS = ['dumb']

    def colorize?
      defined?(::ANSI::Code) &&
        ENV.has_key?('TERM') &&
        !COLORLESS_TERMINALS.include?(ENV['TERM']) &&
        $stdout.tty?
    end
    module_function :colorize?

    def self.red(string)
      colorize? ? ::ANSI::Code.red{ string } : string
    end

    def self.green(string)
      colorize? ? ::ANSI::Code.green{ string } : string
    end

    def self.blue(string)
      colorize? ? ::ANSI::Code.blue{ string } : string
    end

    def self.magenta(string)
      colorize? ? ::ANSI::Code.magenta{ string } : string
    end

    def self.bold(string)
      colorize? ? ::ANSI::Code.bold{ string } : string
    end

    def self.pass(string)
      colorize? ? ::ANSI::Code.green{ string } : string
    end

    def self.fail(string)
      colorize? ? ::ANSI::Code.red{ string } : string
    end

    #def self.error(string)
    #  colorize? ? ::ANSI::Code.white{ ::ANSI::Code.on_red{ string } } : string
    #end

    def self.error(string)
      colorize? ? ::ANSI::Code.yellow{ string } : string
    end

    def self.skip(string)
      colorize? ? ::ANSI::Code.cyan{ string } : string
    end

    PASS  = pass('PASS')
    FAIL  = fail('FAIL')
    ERROR = error('ERROR')
    SKIP  = skip('SKIP')

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
turn-0.8.3 lib/turn/colorize.rb