Sha256: a458a9bc6ed6b49569dbf9312b81456c5c44c0253e02ef544448582cb2986b7c

Contents?: true

Size: 619 Bytes

Versions: 15

Compression:

Stored size: 619 Bytes

Contents

module Enhanced
  class Colors
    COLORS = { red: 31, green: 32, yellow: 33, blue: 34, purple: 35, cyan: 36, white: 0 }.freeze
    RESET_CODE = "\e[0m".freeze

    class << self
      def enabled?
        @enabled
      end

      def enabled=(value)
        @enabled = value
      end

      def color(num, string)
        return string unless @enabled
        "#{code(num)}#{string}#{RESET_CODE}"
      end

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

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

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
enhanced_errors-3.0.7 lib/enhanced/colors.rb
enhanced_errors-3.0.6 lib/enhanced/colors.rb
enhanced_errors-3.0.5 lib/enhanced/colors.rb
enhanced_errors-3.0.4 lib/enhanced/colors.rb
enhanced_errors-3.0.3 lib/enhanced/colors.rb
enhanced_errors-3.0.2 lib/enhanced/colors.rb
enhanced_errors-3.0.1 lib/enhanced/colors.rb
enhanced_errors-3.0.0 lib/enhanced/colors.rb
enhanced_errors-2.2.0 lib/enhanced/colors.rb
enhanced_errors-2.1.3 lib/enhanced/colors.rb
enhanced_errors-2.1.2 lib/enhanced/colors.rb
enhanced_errors-2.1.1 lib/enhanced/colors.rb
enhanced_errors-2.1.0 lib/enhanced/colors.rb
enhanced_errors-2.0.6 lib/enhanced/colors.rb
enhanced_errors-2.0.5 lib/enhanced/colors.rb