Sha256: afa9be8e61b599ebe1d6c532d791355fea6759fcd5d28e9145ee5d59ff5e4e1d

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 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 velocity
      super.zip(%w[cyan blue blue]).map do |(str, col)|
        send(col, str)
      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 text; color('1;30', text); end
    def   black text; color(   30 , text); end
    def     red text; color(   31 , text); end
    def   green text; color(   32 , text); end
    def  yellow text; color(   33 , text); end
    def    blue text; color(   34 , text); end
    def magenta text; color(   35 , text); end
    def    cyan text; color(   36 , text); end
    def   white text; color(   37 , text); end

    def color rgb, text
      "\e[#{rgb}m#{text}\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.3 lib/pork/more/color.rb
pork-1.2.2 lib/pork/more/color.rb