Sha256: 437761cc39a0c34faeabad7a113d635ce154b5b70ce39d198c6a1bfc1508a5c3

Contents?: true

Size: 830 Bytes

Versions: 9

Compression:

Stored size: 830 Bytes

Contents

# frozen_string_literal: true

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

    # Format text with color
    #
    # @param [String] text
    #
    # @return [String]
    #
    # @api private
    #
    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
      #
      # @api private
      #
      def format(text)
        text
      end

    private

      # Initialize null color
      #
      # @return [undefined]
      #
      # @api private
      #
      def initialize; end

    end.new

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

  end # Color
end # Unparser

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
unparser-0.4.7 lib/unparser/cli/color.rb
unparser-0.4.6 lib/unparser/cli/color.rb
unparser-0.4.5 lib/unparser/cli/color.rb
unparser-0.4.4 lib/unparser/cli/color.rb
unparser-0.4.3 lib/unparser/cli/color.rb
unparser-0.4.2 lib/unparser/cli/color.rb
unparser-0.4.1 lib/unparser/cli/color.rb
unparser-0.4.0 lib/unparser/cli/color.rb
unparser-0.3.0 lib/unparser/cli/color.rb