Class: RubyText::Color

Inherits:
Object
  • Object
show all
Defined in:
color.rb

Overview

Handles color constants and fg/bg pairs

Constant Summary collapse

Colors =
::Colors

Class Method Summary collapse

Class Method Details

.index(color) ⇒ Object

Find “our” color number



25
26
27
# File 'color.rb', line 25

def self.index(color)
  Colors.find_index(color)  # "our" number
end

.pair(fg, bg) ⇒ Object

Define a fg/bg color pair



31
32
33
34
35
36
# File 'color.rb', line 31

def self.pair(fg, bg)
  nf, nb = index(fg), index(bg)
  num = 8*nf + nb
  Curses.init_pair(num, sym2const(fg), sym2const(bg))
  num
end

.sym2const(color) ⇒ Object

Convert Ruby symbol to curses color constant name



19
20
21
# File 'color.rb', line 19

def self.sym2const(color)   # to curses constant
  Curses.const_get("COLOR_#{color.to_s.upcase}")
end