sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 47caeb4c13f9d948f317ad8fc6884027ded3bff0
parent 8869d7f45399511379de84fedecbf4ed2104295f
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Thu,  9 Apr 2009 13:11:15 -0400

improve buffer-list-mode to sort by atime and more

Sort buffers by atime, color by whether they're system buffers
or not, and show a '*' for buffers with unsaved content.

Diffstat:
M lib/sup/colormap.rb | 5 ++++-
M lib/sup/modes/buffer-list-mode.rb | 8 ++++++--
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/lib/sup/colormap.rb b/lib/sup/colormap.rb
@@ -46,7 +46,10 @@ class Colormap
     :completion_character => { :fg => "white", :bg => "default", :attrs => ["bold"] },
     :horizontal_selector_selected => { :fg => "yellow", :bg => "default", :attrs => ["bold"] },
     :horizontal_selector_unselected => { :fg => "cyan", :bg => "default" },
-    :search_highlight => { :fg => "black", :bg => "yellow", :attrs => ["bold"] }
+    :search_highlight => { :fg => "black", :bg => "yellow", :attrs => ["bold"] },
+    :system_buf => { :fg => "blue", :bg => "default" },
+    :regular_buf => { :fg => "white", :bg => "default" },
+    :modified_buffer => { :fg => "yellow", :bg => "default", :attrs => ["bold"] },
   }
   
   def initialize
diff --git a/lib/sup/modes/buffer-list-mode.rb b/lib/sup/modes/buffer-list-mode.rb
@@ -16,6 +16,7 @@ class BufferListMode < LineCursorMode
 
   def focus
     reload # buffers may have been killed or created since last view
+    set_cursor_pos 0
   end
 
 protected
@@ -26,10 +27,13 @@ protected
   end
 
   def regen_text
-    @bufs = BufferManager.buffers.sort_by { |name, buf| name }
+    @bufs = BufferManager.buffers.reject { |name, buf| buf.mode == self }.sort_by { |name, buf| buf.atime }.reverse
     width = @bufs.max_of { |name, buf| buf.mode.name.length }
     @text = @bufs.map do |name, buf|
-      sprintf "%#{width}s  %s", buf.mode.name, name
+      base_color = buf.system? ? :system_buf_color : :regular_buf_color
+      [[base_color, sprintf("%#{width}s ", buf.mode.name)],
+       [:modified_buffer_color, (buf.mode.unsaved? ? '*' : ' ')],
+       [base_color, " " + name]]
     end
   end