Sha256: 37c9cdb32c339d6f92aa741bc6d81f03863fd5cb0336684eec13b56cba42d5f3

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'pork/stat'

module Pork
  module Color
    def case_skip    msg='s'; super(yellow {msg}); end
    def case_failed  msg='F'; super(magenta{msg}); end
    def case_errored msg='E'; super(red    {msg}); end

    private
    def command name
      gray{super}
    end

    def message msg
      blue{super}
    end

    def show_exception err
      magenta{super}
    end

    def time_spent
      cyan{super}
    end

    def numbers
      super.zip(%w[green green magenta red yellow]).map do |(num, col)|
        if num == 0
          num
        else
          send(col){ num }
        end
      end
    end

    def backtrace err
      super.map do |b|
        path, msgs = b.split(':', 2)
        dir , file = ::File.split(path)
        msg = msgs.sub(/(\d+):/){red{$1}+':'}.sub(/`.+?'/){green{$&}}

        "#{dir+'/'}#{yellow{file}}:#{msg}"
      end
    end

    def    gray █ color('1;30', &block); end
    def   black █ color(   30 , &block); end
    def     red █ color(   31 , &block); end
    def   green █ color(   32 , &block); end
    def  yellow █ color(   33 , &block); end
    def    blue █ color(   34 , &block); end
    def magenta █ color(   35 , &block); end
    def    cyan █ color(   36 , &block); end
    def   white █ color(   37 , &block); end

    def color rgb
      "\e[#{rgb}m#{yield}\e[0m"
    end
  end

  Pork::Stat.__send__(:include, Pork::Color)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pork-1.2.1 lib/pork/more/color.rb
pork-1.2.0 lib/pork/more/color.rb