]> git.notmuchmail.org Git - sup/commitdiff
alternate colors in thread-view mode. not sure how much i like it.
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 18 Jan 2007 17:28:52 +0000 (17:28 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Thu, 18 Jan 2007 17:28:52 +0000 (17:28 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@265 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup
lib/sup/modes/thread-view-mode.rb

diff --git a/bin/sup b/bin/sup
index a83abe6871f5fac563589bf8826efd1ccdc4ed74..a45f2b59858dad41b22c74272753183ba4a1ec85 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -71,6 +71,8 @@ begin
     c.add :twiddle_color, Ncurses::COLOR_BLUE, Ncurses::COLOR_BLACK
     c.add :label_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
     c.add :message_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_GREEN
+    c.add :alternate_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_BLUE
+    c.add :missing_message_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_RED
     c.add :mime_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
     c.add :quote_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
     c.add :sig_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
index e187d7436c58f05243af6d21ff2ac93dfb6cfd88..be4079adafb76a0e6086a1e7e01771c5d435b1d1 100644 (file)
@@ -3,7 +3,7 @@ module Redwood
 class ThreadViewMode < LineCursorMode
   ## this holds all info we need to lay out a message
   class Layout
-    attr_accessor :top, :bot, :prev, :next, :depth, :width, :state
+    attr_accessor :top, :bot, :prev, :next, :depth, :width, :state, :color
   end
 
   DATE_FORMAT = "%B %e %Y %l:%M%P"
@@ -44,11 +44,14 @@ class ThreadViewMode < LineCursorMode
     @layout = {}
     earliest, latest = nil, nil
     latest_date = nil
+    altcolor = false
     @thread.each do |m, d, p|
       next unless m
       earliest ||= m
       @layout[m] = Layout.new
       @layout[m].state = initial_state_for m
+      @layout[m].color = altcolor ? :alternate_patina_color : :message_patina_color
+      altcolor = !altcolor
       if latest_date.nil? || m.date > latest_date
         latest_date = m.date
         latest = m
@@ -295,11 +298,15 @@ private
       ## that's just a nicety and hopefully this won't happen too
       ## often.
 
-      l = (@layout[m] ||= Layout.new)
-      l.state ||= initial_state_for m
+      unless @layout.member? m
+        l = @layout[m] = Layout.new
+        l.state = initial_state_for m
+        l.color = prevm && prevm.color == :message_patina_color ? :alternate_patina_color : :message_patina_color
+      end
+      l = @layout[m]
 
       ## build the patina
-      text = chunk_to_lines m, l.state, @text.length, depth, parent
+      text = chunk_to_lines m, l.state, @text.length, depth, parent, @layout[m].color
       
       l.top = @text.length
       l.bot = @text.length + text.length # updated below
@@ -336,38 +343,38 @@ private
     end
   end
 
-  def message_patina_lines m, state, start, parent, prefix
-    prefix_widget = [:message_patina_color, prefix]
+  def message_patina_lines m, state, start, parent, prefix, color
+    prefix_widget = [color, prefix]
     widget = 
       case state
       when :closed
-        [:message_patina_color, "+ "]
+        [color, "+ "]
       when :open, :detailed
-        [:message_patina_color, "- "]
+        [color, "- "]
       end
     imp_widget = 
       if m.has_label?(:starred)
         [:starred_patina_color, "* "]
       else
-        [:message_patina_color, "  "]
+        [color, "  "]
       end
 
     case state
     when :open
       @person_lines[start] = m.from
       [[prefix_widget, widget, imp_widget,
-        [:message_patina_color, 
+        [color, 
             "#{m.from ? m.from.mediumname : '?'} to #{m.recipients.map { |l| l.shortname }.join(', ')} #{m.date.to_nice_s} (#{m.date.to_nice_distance_s})"]]]
 
     when :closed
       @person_lines[start] = m.from
       [[prefix_widget, widget, imp_widget,
-        [:message_patina_color, 
+        [color, 
         "#{m.from ? m.from.mediumname : '?'}, #{m.date.to_nice_s} (#{m.date.to_nice_distance_s})  #{m.snippet}"]]]
 
     when :detailed
       @person_lines[start] = m.from
-      from = [[prefix_widget, widget, imp_widget, [:message_patina_color, "From: #{m.from ? format_person(m.from) : '?'}"]]]
+      from = [[prefix_widget, widget, imp_widget, [color, "From: #{m.from ? format_person(m.from) : '?'}"]]]
 
       rest = []
       unless m.to.empty?
@@ -390,7 +397,7 @@ private
         m.labels.empty? ? nil : "  Labels: #{m.labels.join(', ')}",
       ].compact
       
-      from + rest.map { |l| [[:message_patina_color, prefix + "  " + l]] }
+      from + rest.map { |l| [[color, prefix + "  " + l]] }
     end
   end
 
@@ -407,15 +414,15 @@ private
     p.longname + (ContactManager.is_contact?(p) ? " (#{ContactManager.alias_for p})" : "")
   end
 
-  def chunk_to_lines chunk, state, start, depth, parent=nil
+  def chunk_to_lines chunk, state, start, depth, parent=nil, color=nil
     prefix = " " * INDENT_SPACES * depth
     case chunk
     when :fake_root
-      [[[:message_patina_color, "#{prefix}<one or more unreceived messages>"]]]
+      [[[:missing_message_color, "#{prefix}<one or more unreceived messages>"]]]
     when nil
-      [[[:message_patina_color, "#{prefix}<an unreceived message>"]]]
+      [[[:missing_message_color, "#{prefix}<an unreceived message>"]]]
     when Message
-      message_patina_lines(chunk, state, start, parent, prefix) +
+      message_patina_lines(chunk, state, start, parent, prefix, color) +
         (chunk.is_draft? ? [[[:draft_notification_color, prefix + " >>> This message is a draft. To edit, hit 'e'. <<<"]]] : [])
     when Message::Attachment
       [[[:mime_color, "#{prefix}+ MIME attachment #{chunk.content_type}#{chunk.desc ? ' (' + chunk.desc + ')': ''}"]]]