Module: CLAide::ANSI::Graphics

Included in:
CLAide::ANSI
Defined in:
lib/claide/ansi/graphics.rb

Overview

Provides support for generating escape sequences relative to the graphic mode.

Class Method Summary collapse

Class Method Details

.background_color(key) ⇒ String

Returns The escape sequence for a background color.

Parameters:

  • key (Symbol)

    The name of the color.

Returns:

  • (String)

    The escape sequence for a background color.


34
35
36
37
# File 'lib/claide/ansi/graphics.rb', line 34

def self.background_color(key)
  code = ANSI.code_for_key(key, COLORS) + 40
  graphics_mode(code)
end

.background_color_256(color) ⇒ String

Returns The escape sequence for a background color using the xterm-256 format.

Parameters:

  • color (Fixnum)

    The value of the color.

Returns:

  • (String)

    The escape sequence for a background color using the xterm-256 format.


56
57
58
59
# File 'lib/claide/ansi/graphics.rb', line 56

def self.background_color_256(color)
  code = [48, 5, color]
  graphics_mode(code)
end

.foreground_color(key) ⇒ String

Returns The escape sequence for a foreground color.

Parameters:

  • key (Symbol)

    The name of the color.

Returns:

  • (String)

    The escape sequence for a foreground color.


24
25
26
27
# File 'lib/claide/ansi/graphics.rb', line 24

def self.foreground_color(key)
  code = ANSI.code_for_key(key, COLORS) + 30
  graphics_mode(code)
end

.foreground_color_256(color) ⇒ String

Returns The escape sequence for a foreground color using the xterm-256 format.

Parameters:

  • color (Fixnum)

    The value of the color.

Returns:

  • (String)

    The escape sequence for a foreground color using the xterm-256 format.


45
46
47
48
# File 'lib/claide/ansi/graphics.rb', line 45

def self.foreground_color_256(color)
  code = [38, 5, color]
  graphics_mode(code)
end

.graphics_mode(codes) ⇒ String

Returns The escape sequence for a single or a list of codes.

Parameters:

  • codes (Fixnum, Array<Fixnum>)

    The code(s).

Returns:

  • (String)

    The escape sequence for a single or a list of codes.


66
67
68
69
# File 'lib/claide/ansi/graphics.rb', line 66

def self.graphics_mode(codes)
  codes = Array(codes)
  "\e[#{codes.join(';')}m"
end

.text_attribute(key) ⇒ String

Returns The escape sequence for a text attribute.

Parameters:

  • key (Symbol)

    The name of the text attribute.

Returns:

  • (String)

    The escape sequence for a text attribute.


14
15
16
17
# File 'lib/claide/ansi/graphics.rb', line 14

def self.text_attribute(key)
  code = ANSI.code_for_key(key, TEXT_ATTRIBUTES)
  graphics_mode(code)
end