Class: Termpic::AnsiRgb

Inherits:
Object
  • Object
show all
Defined in:
lib/termpic/ansi_rgb.rb

Class Method Summary collapse

Class Method Details

.code(red, green, blue) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/termpic/ansi_rgb.rb', line 8

def self.code(red, green, blue)
  index = 16 +
    to_ansi_domain(red) * 36 +
    to_ansi_domain(green) * 6 +
    to_ansi_domain(blue)
  "48;5;#{index}"
end

.to_ansi_domain(value) ⇒ Object



16
17
18
# File 'lib/termpic/ansi_rgb.rb', line 16

def self.to_ansi_domain(value)
  (6 * (value / 256.0)).to_i
end

.wrap_with_code(string, rgb) ⇒ Object



3
4
5
6
# File 'lib/termpic/ansi_rgb.rb', line 3

def self.wrap_with_code(string, rgb)
  red, green, blue = rgb[0], rgb[1], rgb[2]
  "\e[#{code(red, green, blue)}m" + string + "\e[0m"
end