From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.213.28.69 with SMTP id l5cs33571ebc; Sun, 24 Jan 2010 11:42:34 -0800 (PST) Received: by 10.224.121.213 with SMTP id i21mr3198390qar.8.1264362153599; Sun, 24 Jan 2010 11:42:33 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 4si14545225qwe.15.2010.01.24.11.42.33; Sun, 24 Jan 2010 11:42:33 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 0F34C18582FD; Sun, 24 Jan 2010 14:42:33 -0500 (EST) Received: from magnesium.club.cc.cmu.edu (MAGNESIUM.CLUB.CC.cmu.edu [128.237.157.15]) by rubyforge.org (Postfix) with ESMTP id 9278518582EC for ; Sun, 24 Jan 2010 14:38:17 -0500 (EST) Received: (qmail 10830 invoked from network); 24 Jan 2010 19:38:17 -0000 Received: from pion.club.cc.cmu.edu (HELO localhost.localdomain) (128.237.157.88) by magnesium.club.cc.cmu.edu with SMTP; 24 Jan 2010 19:38:17 -0000 From: Rich Lane To: sup-devel@rubyforge.org Date: Sun, 24 Jan 2010 11:37:00 -0800 Message-Id: <1264361820-4176-1-git-send-email-rlane@club.cc.cmu.edu> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1264204034-7088-1-git-send-email-rlane@club.cc.cmu.edu> References: <1264204034-7088-1-git-send-email-rlane@club.cc.cmu.edu> Subject: [sup-devel] [PATCH] dont restrict colors to those in Colormap::DEFAULT_COLORS X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org This is necessary for user-created highlight colors. A side effect is that invalid color names now default to ugly red/green instead of what was in DEFAULT_COLORS, which seems more useful for debugging colormap problems. Also remove the redundant warnings. --- lib/sup/colormap.rb | 58 ++++++++++++++++++-------------------------------- 1 files changed, 21 insertions(+), 37 deletions(-) diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb index aeb3818..7de48db 100644 --- a/lib/sup/colormap.rb +++ b/lib/sup/colormap.rb @@ -183,51 +183,35 @@ class Colormap 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.to_s.upcase}" - rescue NameError - error ||= "Warning: there is no color named \"#{ufg}\", using fallback." - warn "there is no color named \"#{ufg}\"" - end - end + Colormap::DEFAULT_COLORS.merge(user_colors||{}).each_pair do |k, v| + fg = begin + Curses.const_get "COLOR_#{v[:fg].to_s.upcase}" + rescue NameError + warn "there is no color named \"#{v[:fg]}\"" + Curses::COLOR_GREEN + end - if(ubg = ucolor[:bg]) - begin - bg = Curses.const_get "COLOR_#{ubg.to_s.upcase}" - rescue NameError - error ||= "Warning: there is no color named \"#{ubg}\", using fallback." - warn "there is no color named \"#{ubg}\"" - end - end + bg = begin + Curses.const_get "COLOR_#{v[:bg].to_s.upcase}" + rescue NameError + warn "there is no color named \"#{v[:bg]}\"" + Curses::COLOR_RED + 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 + attrs = (v[:attrs]||[]).map do |a| + begin + Curses.const_get "A_#{a.upcase}" + rescue NameError + warn "there is no attribute named \"#{a}\", using fallback." + nil end - end + end.compact - highlight = ucolor[:highlight] || v[:highlight] - highlight_symbol = highlight ? :"#{highlight}_color" : nil + highlight_symbol = v[:highlight] ? :"#{v[:highlight]}_color" : nil symbol = (k.to_s + "_color").to_sym add symbol, fg, bg, attrs, highlight_symbol end - - warn error if error end def self.instance; @@instance; end -- 1.6.3.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel