module CLAide::ANSI::Graphics
Provides support for generating escape sequences relative to the graphic mode.
Public Class Methods
background_color(key)
click to toggle source
@return [String] The escape sequence for a background color.
@param [Symbol] key
The name of the color.
# 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)
click to toggle source
@return [String] The escape sequence for a background color using the
xterm-256 format.
@param [Fixnum] color
The value of the color.
# 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)
click to toggle source
@return [String] The escape sequence for a foreground color.
@param [Symbol] key
The name of the color.
# 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)
click to toggle source
@return [String] The escape sequence for a foreground color using the
xterm-256 format.
@param [Fixnum] color
The value of the color.
# 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)
click to toggle source
@return [String] The escape sequence for a single or a list of codes.
@param [Fixnum, Array<Fixnum>] codes
The code(s).
# File lib/claide/ansi/graphics.rb, line 66 def self.graphics_mode(codes) codes = Array(codes) "\e[#{codes.join(';')}m" end
text_attribute(key)
click to toggle source
@return [String] The escape sequence for a text attribute.
@param [Symbol] key
The name of the text attribute.
# 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