Class: Twterm::ColorManager

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initializeColorManager

Returns a new instance of ColorManager.



29
30
31
32
33
34
35
36
# File 'lib/twterm/color_manager.rb', line 29

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

Instance Method Details

#get_color_pair_index(fg, bg) ⇒ Object



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

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

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

  add_color(fg, bg)
end