Module: ConsoleGlitter::ANSI
Instance Method Summary collapse
-
#bg_hex_color(color) ⇒ Object
Public: Generate an escape sequence to set the bg color to an approximation of a 4 or 8 bit per channel hex RGB color a la CSS.
-
#hex_color(color) ⇒ Object
Public: Generate an escape sequence to set the foreground color to an approximation of a 4 or 8 bit per channel hex RGB color a la CSS.
Instance Method Details
#bg_hex_color(color) ⇒ Object
Public: Generate an escape sequence to set the bg color to an approximation of a 4 or 8 bit per channel hex RGB color a la CSS.
color - String containing hex digits describing the color to convert.
May be 4 or 8 bits per channel (3 or 6 characters long,
respectively).
Examples
ConsoleGlitter::ANSI.bg_hex_color("00FFFF")
# => "\033[38;5;51m"
ConsoleGlitter::ANSI.bg_hex_color("F0F")
# => "\033[38;5;201m"
Returns the appropriate escape code as a Fixnum.
39 40 41 |
# File 'lib/console-glitter/ansi.rb', line 39 def bg_hex_color(color) escape [48, 5, closest(color)].join(';') end |
#hex_color(color) ⇒ Object
Public: Generate an escape sequence to set the foreground color to an approximation of a 4 or 8 bit per channel hex RGB color a la CSS.
color - String containing hex digits describing the color to convert.
May be 4 or 8 bits per channel (3 or 6 characters long,
respectively).
Examples
ConsoleGlitter::ANSI.hex_color("00FFFF")
# => "\033[38;5;51m"
ConsoleGlitter::ANSI.hex_color("F0F")
# => "\033[38;5;201m"
Returns the appropriate escape code as a Fixnum.
20 21 22 |
# File 'lib/console-glitter/ansi.rb', line 20 def hex_color(color) escape [38, 5, closest(color)].join(';') end |