Class Pastel::Color
In: lib/pastel/color.rb
Parent: Object

A class responsible for coloring strings.

Methods

alias_color   apply_codes   clear   code   colored?   decorate   disable!   lookup   new   strip   style_names   styles   valid?  

Included Modules

Equatable ANSI

Constants

ALIASES = {}   All color aliases
ANSI_COLOR_REGEXP = /\x1b+(\[|\[\[)[0-9;:?]+m/mo.freeze   Match all color escape sequences

External Aliases

enabled -> enabled?

Attributes

eachline  [R] 
enabled  [R] 

Public Class methods

Initialize a Terminal Color

@api public

Public Instance methods

Define a new colors alias

@param [String] alias_name

  the colors alias to define

@param [Array[Symbol,String]] color

  the colors the alias will correspond to

@return [Array[String]]

  the standard color values of the alias

@api public

Apply escape codes to the string

@param [String] string

  the string to apply escapes to

@param [Strin] ansi_colors

  the ansi colors to apply

@return [String]

  return the string surrounded by escape codes

@api private

Reset sequence

@api public

Return raw color code without embeding it into a string.

@return [Array[String]]

  ANSI escape codes

@api public

Check if string has color escape codes

@param [String] string

  the string to check for color strings

@return [Boolean]

  true when string contains color codes, false otherwise

@api public

Apply ANSI color to the given string.

Wraps eachline with clear escape.

@param [String] string

  text to add ANSI strings

@param [Array[Symbol]] colors

  the color names

@example

  color.decorate "text", :yellow, :on_green, :underline

@return [String]

  the colored string

@api public

Disable coloring of this terminal session

@api public

Find the escape code for a given set of color attributes

@example

  color.lookup(:red, :on_green) # => "\e[31;42m"

@param [Array[Symbol]] colors

  the list of color name(s) to lookup

@return [String]

  the ANSI code(s)

@raise [InvalidAttributeNameError]

  exception raised for any invalid color name

@api private

Strip ANSI color codes from a string.

Only ANSI color codes are removed, not movement codes or other escapes sequences are stripped.

@param [Array[String]] strings

  a string or array of strings to sanitize

@example

  strip("foo\e[1mbar\e[0m")  # => "foobar"

@return [String]

@api public

List all available style names

@return [Array[Symbol]]

@api public

Expose all ANSI color names and their codes

@return [Hash[Symbol]]

@api public

Check if provided colors are known colors

@param [Array[Symbol,String]]

  the list of colors to check

@example

  valid?(:red)   # => true

@return [Boolean]

  true if all colors are valid, false otherwise

@api public

[Validate]