def populate_colormap
user_colors = if File.exists? Redwood::COLOR_FN
debug "loading user colors from #{Redwood::COLOR_FN}"
Redwood::load_yaml_obj Redwood::COLOR_FN
end
error = nil
Colormap::DEFAULT_COLORS.each_pair do |k, v|
fg = Curses.const_get "COLOR_#{v[:fg].upcase}"
bg = Curses.const_get "COLOR_#{v[:bg].upcase}"
attrs = v[:attrs] ? v[:attrs].map { |a| Curses.const_get "A_#{a.upcase}" } : []
if user_colors && (ucolor = user_colors[k])
if(ufg = ucolor[:fg])
begin
fg = Curses.const_get "COLOR_#{ufg.upcase}"
rescue NameError
error ||= "Warning: there is no color named \"#{ufg}\", using fallback."
warn "there is no color named \"#{ufg}\""
end
end
if(ubg = ucolor[:bg])
begin
bg = Curses.const_get "COLOR_#{ubg.upcase}"
rescue NameError
error ||= "Warning: there is no color named \"#{ubg}\", using fallback."
warn "there is no color named \"#{ubg}\""
end
end
if(uattrs = ucolor[:attrs])
attrs = [*uattrs].flatten.map do |a|
begin
Curses.const_get "A_#{a.upcase}"
rescue NameError
error ||= "Warning: there is no attribute named \"#{a}\", using fallback."
warn "there is no attribute named \"#{a}\", using fallback."
end
end
end
end
symbol = (k.to_s + "_color").to_sym
add symbol, fg, bg, attrs
end
BufferManager.flash error if error
end