Module: Acclaim::ANSI

Defined in:
lib/acclaim/ansi.rb

Overview

ANSI escape codes for colors and effects.

See Also:

Author:

  • Matheus Afonso Martins Moreira

Since:

  • 0.5.0

Class Method Summary collapse

Class Method Details

.background_color(string, color) ⇒ String

Applies background color to the given string.

Parameters:

  • string (String, #to_s)

    the string the color will be applied to

  • color (Symbol)

    the name of the color that will be applied

Returns:

  • (String)

    new string with the color applied

See Also:

Since:

  • 0.5.0



64
65
66
# File 'lib/acclaim/ansi.rb', line 64

def background_color(string, color)
  apply_color_to string, color, background_offset
end

.effects(string, *effects) ⇒ String

Applies text effects to the given string.

Parameters:

  • string (String, #to_s)

    the string the effects will be applied to

  • effects (Array<Symbol>)

    the text effects to apply

Returns:

  • (String)

    new string with the text effects applied

See Also:

Since:

  • 0.5.0



74
75
76
77
78
79
80
81
82
# File 'lib/acclaim/ansi.rb', line 74

def effects(string, *effects)
  apply_escape_codes_to string do
    effects.select do |effect|
      text_effects.has_key? effect
    end.map do |effect|
      text_effects[effect]
    end
  end
end

.extend_string!Object

Extends the String class with an object-oriented ANSI escape code API.

See Also:

Since:

  • 0.5.0



19
20
21
# File 'lib/acclaim/ansi.rb', line 19

def extend_string!
  require 'acclaim/core_extensions/string/ansi'
end

.foreground_color(string, color) ⇒ String

Applies foreground color to the given string.

Parameters:

  • string (String, #to_s)

    the string the color will be applied to

  • color (Symbol)

    the name of the color that will be applied

Returns:

  • (String)

    new string with the color applied

See Also:

Since:

  • 0.5.0



53
54
55
# File 'lib/acclaim/ansi.rb', line 53

def foreground_color(string, color)
  apply_color_to string, color, foreground_offset
end

.supported_colorsArray<Symbol> Also known as: available_colors

Colors from the standard color pallete.

Returns:

  • (Array<Symbol>)

    available colors

See Also:

Since:

  • 0.5.0



29
30
31
# File 'lib/acclaim/ansi.rb', line 29

def supported_colors
  colors.keys
end

.supported_effectsArray<Symbol> Also known as: available_effects

Text effects that can be applied.

Returns:

  • (Array<Symbol>)

    available text effects

See Also:

Since:

  • 0.5.0



40
41
42
# File 'lib/acclaim/ansi.rb', line 40

def supported_effects
  text_effects.keys
end