Subject: [sup-devel] [PATCH] dont restrict colors to those in Colormap::DEFAULT_COLORS

From: Rich Lane <[email-masked]>
Date: Sun, 24 Jan 2010 11:37:00 -0800

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
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Rich Lane <[email-masked]>
Date: Fri, 22 Jan 2010 18:47:14 -0500

Adds a :highlight key to the color entries in colors.yaml that names another
color to be used for highlighting.
---
 lib/sup/colormap.rb |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
index 6f21f9a..aeb3818 100644
--- a/lib/sup/colormap.rb
+++ b/lib/sup/colormap.rb
@@ -77,19 +77,26 @@ class Colormap
 
   def reset
     @entries = {}
+    @highlights = { :none => highlight_sym(:none)}
     @entries[highlight_sym(:none)] = highlight_for(Curses::COLOR_WHITE,
                                                    Curses::COLOR_BLACK,
                                                    []) + [nil]
   end
 
-  def add sym, fg, bg, attr=nil, opts={}
+  def add sym, fg, bg, attr=nil, highlight=nil
     raise ArgumentError, "color for #{sym} already defined" if @entries.member? sym
     raise ArgumentError, "color '#{fg}' unknown" unless (-1...Curses::NUM_COLORS).include? fg
     raise ArgumentError, "color '#{bg}' unknown" unless (-1...Curses::NUM_COLORS).include? bg
     attrs = [attr].flatten.compact
 
     @entries[sym] = [fg, bg, attrs, nil]
-    @entries[highlight_sym(sym)] = opts[:highlight] ? @entries[opts[:highlight]] : highlight_for(fg, bg, attrs) + [nil]
+
+    if not highlight
+      highlight = highlight_sym(sym)
+      @entries[highlight] = highlight_for(fg, bg, attrs) + [nil]
+    end
+
+    @highlights[sym] = highlight
   end
 
   def highlight_sym sym
@@ -132,7 +139,7 @@ class Colormap
   end
 
   def color_for sym, highlight=false
-    sym = highlight_sym(sym) if highlight
+    sym = @highlights[sym] if highlight
     return Curses::COLOR_BLACK if sym == :none
     raise ArgumentError, "undefined color #{sym}" unless @entries.member? sym
 
@@ -213,8 +220,11 @@ class Colormap
         end
       end
 
+      highlight = ucolor[:highlight] || v[:highlight]
+      highlight_symbol = highlight ? :"#{highlight}_color" : nil
+
       symbol = (k.to_s + "_color").to_sym
-      add symbol, fg, bg, attrs
+      add symbol, fg, bg, attrs, highlight_symbol
     end
 
     warn error if error
-- 
1.5.6.5

---

From: Rich Lane <[email-masked]>
Date: Sat, 27 Feb 2010 02:56:31 -0500

Branch highlights, merged to next.
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel