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



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



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



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



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



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



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