]> git.cworth.org Git - sup/commitdiff
improve buffer-list-mode to sort by atime and more
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 9 Apr 2009 17:11:15 +0000 (13:11 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 9 Apr 2009 17:20:14 +0000 (13:20 -0400)
Sort buffers by atime, color by whether they're system buffers
or not, and show a '*' for buffers with unsaved content.

lib/sup/colormap.rb
lib/sup/modes/buffer-list-mode.rb

index 469ed0b91874342a8fde6787008aa625b9d4e576..fe60f61362a5d65cd3abe22d4fcfbf8bc21d26c2 100644 (file)
@@ -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
index 91b2fac7fa4d50e974368486ca17a1ddc44f462e..1554caedfe77e2bfeb8a99efbfd65f63f479c074 100644 (file)
@@ -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