Class: RubyText::Color

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

Constant Summary collapse

Colors =
[Black, Blue, Cyan, Green, Magenta, Red, White, Yellow]

Class Method Summary collapse

Class Method Details

.index(color) ⇒ Object



15
16
17
# File 'lib/color.rb', line 15

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

.pair(fg, bg) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/color.rb', line 19

def self.pair(fg, bg)
  nf = index(fg)
  nb = index(bg)
  File.open("/tmp/pair.out", "w") do |f| 
    f.puts "fg, bg = #{[fg, bg].inspect}" 
    f.puts "Colors = #{Colors.inspect}"
    f.puts "index fg = #{nf.inspect}"
    f.puts "index bg = #{nb.inspect}"
  end
  num = 8*nf + nb
  X.init_pair(num, sym2const(fg), sym2const(bg))
  num
end

.sym2const(color) ⇒ Object

to curses constant



11
12
13
# File 'lib/color.rb', line 11

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