Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Rich Lane <rlane@club.cc.cmu.edu>
To: sup-devel@rubyforge.org
Subject: [sup-devel] [PATCH] dont restrict colors to those in Colormap::DEFAULT_COLORS
Date: Sun, 24 Jan 2010 11:37:00 -0800	[thread overview]
Message-ID: <1264361820-4176-1-git-send-email-rlane@club.cc.cmu.edu> (raw)
In-Reply-To: <1264204034-7088-1-git-send-email-rlane@club.cc.cmu.edu>

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


  reply	other threads:[~2010-01-24 19:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-22 23:47 [sup-devel] [PATCH] configurable color highlights Rich Lane
2010-01-24 19:37 ` Rich Lane [this message]
2010-02-27  7:56   ` [sup-devel] [PATCH] dont restrict colors to those in Colormap::DEFAULT_COLORS Rich Lane

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1264361820-4176-1-git-send-email-rlane@club.cc.cmu.edu \
    --to=rlane@club.cc.cmu.edu \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox