### CLI Usage Source: https://github.com/piotrmurach/pastel/blob/master/README.md Provides an example of how to use the `pastel-cli` companion library to style text directly from the command line. ```bash $ pastel green "Unicorns & rainbows!" ``` -------------------------------- ### Pastel Command Line Usage Source: https://github.com/piotrmurach/pastel/blob/master/README.md Demonstrates how to use the pastel executable from the command line to style text. It shows an example of coloring text with 'green'. ```bash $ pastel green 'Unicorns & rainbows!' ``` -------------------------------- ### Pastel Environment Variable for Color Aliases Source: https://github.com/piotrmurach/pastel/blob/master/README.md Illustrates the format for the PASTEL_COLORS_ALIASES environment variable, which allows users to define custom color aliases. It shows examples of mapping new alias names to existing colors and styles. ```ruby PASTEL_COLORS_ALIASES="newcolor_1=red,newcolor_2=on_green,funky=red.bold" ``` -------------------------------- ### Basic Usage Source: https://github.com/piotrmurach/pastel/blob/master/README.md Demonstrates the fundamental way to use Pastel to color a string. It shows how to create a Pastel instance and apply a color to a string, returning the styled string. ```ruby pastel = Pastel.new puts pastel.red("Unicorns!") ``` -------------------------------- ### Variable Arguments Source: https://github.com/piotrmurach/pastel/blob/master/README.md Demonstrates that Pastel methods can accept a variable number of string arguments, applying the style to all of them. ```ruby pastel.red("Unicorns", "are", "running", "everywhere!") ``` -------------------------------- ### Nested Styles with Blocks Source: https://github.com/piotrmurach/pastel/blob/master/README.md Demonstrates a more advanced nesting technique using blocks, which can be useful for structuring complex styled output. ```ruby pastel.red.on_green("Unicorns") { green.on_red("will ", "dominate") { yellow("the world!") } } ``` -------------------------------- ### Nested Styles Source: https://github.com/piotrmurach/pastel/blob/master/README.md Explains and shows how to nest styles within each other, allowing for more intricate visual formatting of text. ```ruby pastel.red("Unicorns ", pastel.on_green("everywhere!")) ``` -------------------------------- ### Multiline Strings with `eachline` Source: https://github.com/piotrmurach/pastel/blob/master/README.md Shows how to configure Pastel to handle multiline strings by setting the `eachline` option, which affects how styles are applied across lines. ```ruby pastel = Pastel.new(eachline: "\n") ``` -------------------------------- ### Chained Styles Source: https://github.com/piotrmurach/pastel/blob/master/README.md Illustrates how to apply multiple styles to a single string by chaining color and decoration methods. This allows for complex styling combinations. ```ruby pastel.red.on_green.bold("Unicorns!") ``` -------------------------------- ### Composing Styled and Unstyled Strings Source: https://github.com/piotrmurach/pastel/blob/master/README.md Shows how to combine strings with different styles, including unstyled parts, into a single output. Pastel allows concatenation of styled strings. ```ruby pastel.red("Unicorns") + " will rule " + pastel.green("the World!") ``` -------------------------------- ### List Supported Styles Source: https://github.com/piotrmurach/pastel/blob/master/README.md Retrieves a comprehensive list of all supported styles along with their corresponding ANSI escape codes. ```ruby pastel.styles ``` -------------------------------- ### Decorate Method Source: https://github.com/piotrmurach/pastel/blob/master/README.md Explains the lower-level `decorate` method, which allows styling a string with a variable list of color attributes. This is useful for dynamically generated styles. ```ruby pastel.decorate("Unicorn", :green, :on_blue, :bold) ``` -------------------------------- ### Smart Nesting Source: https://github.com/piotrmurach/pastel/blob/master/README.md Highlights Pastel's ability to correctly handle nested styles, ensuring that color codes are properly managed even when styles are adjacent. ```ruby pastel.red("Unicorns " + pastel.green("everywhere") + pastel.on_yellow("!")) ``` -------------------------------- ### Color Styling Method Source: https://github.com/piotrmurach/pastel/blob/master/README.md Details the interface for applying color styles to strings. It explains that color methods accept strings as arguments and return the styled string, which needs to be printed manually. ```ruby pastel.red("Unicorns ", pastel.bold.underline("everywhere"), "!") ``` -------------------------------- ### Alias Color Definitions Source: https://github.com/piotrmurach/pastel/blob/master/README.md Creates an alias for a combination of standard colors and styles, allowing for more meaningful naming. Aliases are global. ```ruby pastel.alias_color(:funky, :red, :bold) pastel.funky.on_green("unicorn") # => uses :red, :bold color ``` -------------------------------- ### Detached Styles Source: https://github.com/piotrmurach/pastel/blob/master/README.md Explains and demonstrates the use of `.detach` to create reusable style objects. These detached styles can be called like methods to apply their predefined formatting. ```ruby error = pastel.red.bold.detach warning = pastel.yellow.detach puts error.("Error!") puts warning.("Warning") ``` -------------------------------- ### Undecorate String Source: https://github.com/piotrmurach/pastel/blob/master/README.md Converts color escape sequences in a string into a list of hash objects, each representing a color attribute (foreground, background, text, style). ```ruby pastel.undecorate("\e[32mfoo\e[0m \e[31mbar\e[0m") # => [{foreground: :green, text: "foo"}, {text: " "}, {foreground: :red, text: "bar"}] ``` -------------------------------- ### Coloring Lines with Delimiters Source: https://github.com/piotrmurach/pastel/blob/master/README.md Applies coloring to each line of a string separately when a line delimiter is specified. Useful for background colors spanning multiple lines. ```ruby pastel = Pastel.new(eachline: "\n") pastel.red("foo\nbar") # => "\e[31mfoo\e[0m\n\e[31mbar\e[0m" ``` -------------------------------- ### Check Terminal Color Support Source: https://github.com/piotrmurach/pastel/blob/master/README.md Detects whether the current terminal environment supports coloring. Can be explicitly enabled. ```ruby pastel.enabled? # => false pastel = Pastel.new(enabled: true) pastel.enabled? # => true # Dynamically set based on TTY status stdout_pastel = Pastel.new(enabled: $stdout.tty?) stderr_pastel = Pastel.new(enabled: $stderr.tty?) ``` -------------------------------- ### Detach Color Configuration Source: https://github.com/piotrmurach/pastel/blob/master/README.md Allows retaining associated colors with a detached instance for later reuse. The detached object can be invoked using `call`, `.()`, or array-like access `[]`. ```ruby notice = pastel.blue.bold.detach notice.call("Unicorns running") notice.("Unicorns running") notice["Unicorns running"] ``` -------------------------------- ### Validate Color Attributes Source: https://github.com/piotrmurach/pastel/blob/master/README.md Determines if one or more color attributes (strings or symbols) are recognized by Pastel. Returns true if all attributes are valid, false otherwise. ```ruby pastel.valid?(:red, :blue) # => true pastel.valid?(:unicorn) # => false ``` -------------------------------- ### Lookup Color Code Source: https://github.com/piotrmurach/pastel/blob/master/README.md Translates a color name (symbol or string) into its corresponding ANSI escape code. ```ruby pastel.lookup(:red) # => "\e[31m" pastel.lookup(:reset) # => "\e[0m" ``` -------------------------------- ### Strip Color Escape Sequences Source: https://github.com/piotrmurach/pastel/blob/master/README.md Removes only color escape sequence characters from strings, preserving other escape codes like movement codes. Returns a modified string or an array of strings. ```ruby pastel.strip("\e[1A\e[1m\e[34mbold blue text\e[0m") # => "\e[1Abold blue text" ``` -------------------------------- ### Check if String is Colored Source: https://github.com/piotrmurach/pastel/blob/master/README.md Checks if a given string contains any color escape codes. ```ruby pastel.colored?("\e[31mcolorful\e[0m") # => true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.