Sha256: cbd727a6423563a4b2869c3a4f2004e701e0f36ba2c0665b410c96c25344aea6

Contents?: true

Size: 552 Bytes

Versions: 5

Compression:

Stored size: 552 Bytes

Contents

module Enhanced
  class Colors
    COLORS = { red: 31, green: 32, yellow: 33, blue: 34, purple: 35, cyan: 36, white: 0 }

    class << self
      def enabled?
        @enabled
      end

      def enabled=(value)
        @enabled = value
      end

      def color(num, string)
        @enabled ? "#{code(num)}#{string}#{code(0)}" : string
      end

      def code(num)
        "\e[#{num}m"
      end

      COLORS.each do |color, code|
        define_method(color) do |str|
          color(COLORS[color], str)
        end
      end
    end
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
enhanced_errors-2.0.4 lib/enhanced/colors.rb
enhanced_errors-2.0.3 lib/enhanced/colors.rb
enhanced_errors-2.0.2 lib/enhanced/colors.rb
enhanced_errors-2.0.1 lib/enhanced/colors.rb
enhanced_errors-2.0.0 lib/enhanced/colors.rb