Sha256: 523bb2e0487aa098006216e8283f29c53d5aa552651a967156337c9965c468c0

Contents?: true

Size: 627 Bytes

Versions: 6

Compression:

Stored size: 627 Bytes

Contents

# frozen_string_literal: true

module Unparser
  # Class to colorize strings
  class Color
    include Adamantium, Concord.new(:code)

    # Format text with color
    #
    # @param [String] text
    #
    # @return [String]
    def format(text)
      "\e[#{code}m#{text}\e[0m"
    end

    NONE = Class.new(self) do

      # Format null color
      #
      # @param [String] text
      #
      # @return [String]
      #   the argument string
      def format(text)
        text
      end

    private

      def initialize; end

    end.new

    RED   = Color.new(31)
    GREEN = Color.new(32)

  end # Color
end # Unparser

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unparser-0.6.5 lib/unparser/color.rb
unparser-0.6.4 lib/unparser/color.rb
unparser-0.6.3 lib/unparser/color.rb
unparser-0.6.2 lib/unparser/color.rb
unparser-0.6.1 lib/unparser/color.rb
unparser-0.6.0 lib/unparser/color.rb