Module: IronTermAnsiColor

Includes:
System
Included in:
IO
Defined in:
lib/iron-term-ansicolor.rb

Constant Summary collapse

ANSI_REGEXP =
/\e\[([1349][0-7][0-7]?|[01])m/
FGCOLORS =
{
  30 => ConsoleColor.black,
  31 => ConsoleColor.dark_red,
  32 => ConsoleColor.dark_green,
  33 => ConsoleColor.dark_yellow,
  34 => ConsoleColor.dark_blue,
  35 => ConsoleColor.dark_magenta,
  36 => ConsoleColor.dark_cyan,
  37 => ConsoleColor.gray,
  90 => ConsoleColor.dark_gray,
  91 => ConsoleColor.red,
  92 => ConsoleColor.green,
  93 => ConsoleColor.yellow,
  94 => ConsoleColor.blue,
  95 => ConsoleColor.magenta,
  96 => ConsoleColor.cyan,
  97 => ConsoleColor.white
}
BGCOLORS =
{
  40 => ConsoleColor.black,
  41 => ConsoleColor.dark_red,
  42 => ConsoleColor.dark_green,
  43 => ConsoleColor.dark_yellow,
  44 => ConsoleColor.dark_blue,
  45 => ConsoleColor.dark_magenta,
  46 => ConsoleColor.dark_cyan,
  47 => ConsoleColor.gray,
  100 => ConsoleColor.dark_gray,
  101 => ConsoleColor.red,
  102 => ConsoleColor.green,
  103 => ConsoleColor.yellow,
  104 => ConsoleColor.blue,
  105 => ConsoleColor.magenta,
  106 => ConsoleColor.cyan,
  107 => ConsoleColor.white
}

Instance Method Summary collapse

Instance Method Details

#set_color(num) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/iron-term-ansicolor.rb', line 51

def set_color(num)
  if num == 0
    Console.reset_color
  elsif num == 1
    #since we can't do bold, invert the colors
    bg = Console.background_color
    Console.background_color = Console.foreground_color
    Console.foreground_color = bg       
  else
    Console.foreground_color = FGCOLORS[num] || Console.foreground_color
    Console.background_color = BGCOLORS[num] || Console.background_color
  end
end