Sha256: 1e242e81020f60fe61dbcc8cb7426987bc04087920fdb09d83e1472f42e3ba98

Contents?: true

Size: 923 Bytes

Versions: 8

Compression:

Stored size: 923 Bytes

Contents

def fb2cp(fg, bg)
  fg ||= Blue
  bg ||= White
  f2 = X.const_get("COLOR_#{fg.upcase}")
  b2 = X.const_get("COLOR_#{bg.upcase}")
  cp = $ColorPairs[[fg, bg]]
  [f2, b2, cp]
end

module RubyText
  Colors = [Black, Blue, Cyan, Green, Magenta, Red, White, Yellow]
  $ColorPairs = {}
  num = 0
  Colors.each do |fsym|
    Colors.each do |bsym|
      fg = X.const_get("COLOR_#{fsym.upcase}")
      bg = X.const_get("COLOR_#{bsym.upcase}")
      X.init_pair(num+=1, fg, bg)  # FIXME backwards?
      $ColorPairs[[fsym, bsym]] = num
    end
  end
end

class RubyText::Window
  def self.colors(win, fg, bg)
    cfg, cbg, cp = fb2cp(fg, bg)
    X.init_pair(cp, cfg, cbg)
    win.color_set(cp)
  end

  def self.colors!(win, fg, bg)
    colors(win, fg, bg)
    num = win.maxx * win.maxy
    win.setpos(0, 0)
    win.addstr(' '*num)
    win.setpos(0, 0)
    win.refresh
  end

  def fg=(sym)
    self.colors(@win, fg, @bg)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubytext-0.0.60 lib/color.rb
rubytext-0.0.59 lib/color.rb
rubytext-0.0.58 lib/color.rb
rubytext-0.0.57 lib/color.rb
rubytext-0.0.56 lib/color.rb
rubytext-0.0.55 lib/color.rb
rubytext-0.0.54 lib/color.rb
rubytext-0.0.53 lib/color.rb