def color_for sym, highlight=false
sym = highlight_sym(sym) if highlight
return Curses::COLOR_BLACK if sym == :none
raise ArgumentError, "undefined color #{sym}" unless @entries.member? sym
fg, bg, attrs, color = @entries[sym]
return color if color
if(cp = @color_pairs[[fg, bg]])
else
@next_id = (@next_id + 1) % NUM_COLORS
@next_id += 1 if @next_id == 0
id = @next_id
debug "colormap: for color #{sym}, using id #{id} -> #{fg}, #{bg}"
Curses.init_pair id, fg, bg or raise ArgumentError,
"couldn't initialize curses color pair #{fg}, #{bg} (key #{id})"
cp = @color_pairs[[fg, bg]] = Curses.color_pair(id)
if @users[cp]
@users[cp].each do |usym|
warn "dropping color #{usym} (#{id})"
@entries[usym][3] = nil
end
@users[cp] = []
end
end
color = attrs.inject(cp) { |color, attr| color | attr }
@entries[sym][3] = color
(@users[cp] ||= []) << sym
color
end