Module: Pastel

Defined in:
lib/pastel.rb,
lib/pastel/ansi.rb,
lib/pastel/color.rb,
lib/pastel/version.rb,
lib/pastel/detached.rb,
lib/pastel/delegator.rb,
lib/pastel/color_parser.rb,
lib/pastel/alias_importer.rb,
lib/pastel/color_resolver.rb,
lib/pastel/decorator_chain.rb

Defined Under Namespace

Modules: ANSI Classes: AliasImporter, Color, ColorParser, ColorResolver, DecoratorChain, Delegator, Detached

Constant Summary collapse

InvalidAttributeNameError =

Raised when the style attribute is not supported

Class.new(::ArgumentError)
InvalidAliasNameError =

Raised when the color alias is not supported

Class.new(::ArgumentError)
VERSION =
"0.8.0"

Class Method Summary collapse

Class Method Details

.new(enabled: nil, eachline: false) ⇒ Delegator

Create Pastel chainable API

Examples:

pastel = Pastel.new enabled: true

Parameters:

  • :enabled (Boolean)

    whether or not to disable coloring

  • :eachline (Boolean)

    whether or not to wrap eachline with separate coloring

Returns:



31
32
33
34
35
36
37
38
39
40
# File 'lib/pastel.rb', line 31

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