Module ANSI::Code
In: lib/ansi/code.rb

ANSI Codes

Ansi::Code module makes it very easy to use ANSI codes. These are esspecially nice for beautifying shell output.

  Ansi::Code.red + "Hello" + Ansi::Code.blue + "World"
  => "\e[31mHello\e[34mWorld"

  Ansi::Code.red{ "Hello" } + Ansi::Code.blue{ "World" }
  => "\e[31mHello\e[0m\e[34mWorld\e[0m"

IMPORTANT! Do not mixin Ansi::Code, instead use {ANSI::Mixin}.

See {ANSI::Code::CHART} for list of all supported codes.

Methods

[]   ansi   code   color   colors   display   down   hex   left   method_missing   move   random   rgb   right   style   styles   unansi   uncolor   unstyle   up  

Included Modules

Constants

Constants

PATTERN = /\e\[(\d+)m/   Regexp for matching most ANSI codes.
ENDCODE = "\e[0m"   ANSI clear code.

Public Class methods

List of primary colors.

List of primary styles.

Public Instance methods

Return ANSI code given a list of symbolic names.

Apply ANSI codes to a first argument or block value.

@example

  ansi("Valentine", :red, :on_white)

@example

  ansi(:red, :on_white){ "Valentine" }

@return [String]

  String wrapped ANSI code.

Look-up code from chart, or if Integer simply pass through. Also resolves :random and :on_random.

@param codes [Array<Symbol,Integer]

  Symbols or integers to covnert to ANSI code.

@return [String] ANSI code

color(*codes)

Alias for ansi

Like move but returns to original positon after yielding the block.

Move cursor down a specificed number of spaces.

Creates an xterm-256 color from a CSS-style color string.

Move cursor left a specificed number of spaces.

Use method missing to dispatch ANSI code methods.

Move cursor to line and column.

Provides a random primary ANSI color.

@param background [Boolean]

  Use `true` for background color, otherwise foreground color.

@return [Integer] ANSI color number

Creates an xterm-256 color from rgb value.

@param background [Boolean]

  Use `true` for background color, otherwise foreground color.

Move cursor right a specificed number of spaces.

style(*codes)

Alias for ansi

Remove ANSI codes from string or block value.

@param [String] string

  String from which to remove ANSI codes.

@return [String]

  String wrapped ANSI code.
uncolor(string=nil)

Alias for unansi

unstyle(string=nil)

Alias for unansi

Move cursor up a specificed number of spaces.

[Validate]