sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit af7e9da6bdbadd14dc7bc78f4c1d404dd329fec9
parent 624298c1da52ee295e7468583385eac659ef6070
Author: Rich Lane <rlane@club.cc.cmu.edu>
Date:   Fri, 22 Jan 2010 18:47:14 -0500

configurable color highlights

Adds a :highlight key to the color entries in colors.yaml that names another
color to be used for highlighting.

Diffstat:
M lib/sup/colormap.rb | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git 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