class CLAide::ANSI

Provides support for ANSI Escape sequences

For more information see:

This functionality has been inspired and derived from the following gems:

Constants

COLORS

@return [Hash{Symbol => Fixnum}] The colors codes by their English name.

DEFAULT_BACKGROUND_COLOR

Return [String] The escape sequence for the default background color.

DEFAULT_FOREGROUND_COLOR

Return [String] The escape sequence for the default foreground color.

RESET_SEQUENCE

Return [String] The escape sequence to reset the graphics.

TEXT_ATTRIBUTES

@return [Hash{Symbol => Fixnum}] The text attributes codes by their

English name.
TEXT_DISABLE_ATTRIBUTES

@return [Hash{Symbol => Fixnum}] The codes to disable a text attribute by

their name.

Attributes

disabled[RW]

@return [Bool] Wether the string mixin should be disabled to return the original string. This method is intended to offer a central location where to disable ANSI logic without needed to implement conditionals across the code base of clients.

@example

"example".ansi.yellow #=> "\e[33mexample\e[39m"
ANSI.disabled = true
"example".ansi.yellow #=> "example"

Public Class Methods

code_for_key(key, map) click to toggle source

@return [Fixnum] The code of a key given the map.

@param [Symbol] key

The key for which the code is needed.

@param [Hash{Symbol => Fixnum}] map

A hash which associates each code to each key.

@raise If the key is not provided. @raise If the key is not present in the map.

# File lib/claide/ansi.rb, line 96
def self.code_for_key(key, map)
  unless key
    raise ArgumentError, 'A key must be provided'
  end
  code = map[key]
  unless code
    raise ArgumentError, "Unsupported key: `#{key}`"
  end
  code
end