Sha256: 1ce12985bbc14c2d0b27f1913a002536ffcbf7bdb2a9a4f0c4eea045881805f3

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require "tty-color"

require_relative "pastel/alias_importer"
require_relative "pastel/color"
require_relative "pastel/color_resolver"
require_relative "pastel/delegator"
require_relative "pastel/version"

module Pastel
  # Raised when the style attribute is not supported
  InvalidAttributeNameError = Class.new(::ArgumentError)

  # Raised when the color alias is not supported
  InvalidAliasNameError = Class.new(::ArgumentError)

  # Create Pastel chainable API
  #
  # @example
  #   pastel = Pastel.new enabled: true
  #
  # @param [Boolean] :enabled
  #   whether or not to disable coloring
  # @param [Boolean] :eachline
  #   whether or not to wrap eachline with separate coloring
  #
  # @return [Delegator]
  #
  # @api public
  def new(enabled: nil, eachline: false)
    if enabled.nil?
      enabled = (TTY::Color.windows? || TTY::Color.color?)
    end
    color    = Color.new(enabled: enabled, eachline: eachline)
    importer = AliasImporter.new(color, ENV)
    importer.import
    resolver = ColorResolver.new(color)
    Delegator.wrap(resolver)
  end
  module_function :new
end # Pastel

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
lotrd-0.1.9 vendor/cache/ruby/2.6.0/gems/pastel-0.8.0/lib/pastel.rb
lotrd-0.1.8 vendor/cache/ruby/2.6.0/gems/pastel-0.8.0/lib/pastel.rb
lotrd-0.1.6 vendor/cache/ruby/2.6.0/gems/pastel-0.8.0/lib/pastel.rb
lotrd-0.1.5 vendor/cache/ruby/2.6.0/gems/pastel-0.8.0/lib/pastel.rb
pastel-0.8.0 lib/pastel.rb