Class: Twterm::ColorManager

Inherits:
Object
  • Object
show all
Includes:
Curses, Singleton
Defined in:
lib/twterm/color_manager.rb

Constant Summary collapse

COLORS =
[:black, :white, :red, :green, :blue, :yellow, :cyan, :magenta]
CURSES_COLORS =
{
  black: COLOR_BLACK,
  white: COLOR_WHITE,
  red: COLOR_RED,
  green: COLOR_GREEN,
  blue: COLOR_BLUE,
  yellow: COLOR_YELLOW,
  cyan: COLOR_CYAN,
  magenta: COLOR_MAGENTA
}

Instance Method Summary collapse

Constructor Details

#initializeColorManager

Returns a new instance of ColorManager.



18
19
20
21
22
23
24
# File 'lib/twterm/color_manager.rb', line 18

def initialize
  @colors = {
    black: {}, white: {}, red: {}, green: {},
    blue: {}, yellow: {}, cyan: {}, magenta: {}
  }
  @count = 0
end

Instance Method Details

#get_color_pair_index(fg, bg) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/twterm/color_manager.rb', line 26

def get_color_pair_index(fg, bg)
  fail ArgumentError, 'invalid color name' unless COLORS.include? fg
  fail ArgumentError, 'invalid color name' unless COLORS.include? bg

  return @colors[bg][fg] unless @colors[bg][fg].nil?

  add_color(fg, bg)
end