From: wmorgan Date: Tue, 30 Oct 2007 15:55:48 +0000 (+0000) Subject: fancy resizing author list in thread-index-mode X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=f29ff54dc14c0dfda0481c4190a589c3fdfe9a6d;p=sup fancy resizing author list in thread-index-mode git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@651 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index ffd4182..aba33df 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -5,7 +5,7 @@ module Redwood class ThreadIndexMode < LineCursorMode DATE_WIDTH = Time::TO_NICE_S_MAX_LEN - FROM_WIDTH = 15 + MIN_FROM_WIDTH = 15 LOAD_MORE_THREAD_NUM = 20 register_keymap do |k| @@ -34,7 +34,6 @@ class ThreadIndexMode < LineCursorMode @load_thread_opts = load_thread_opts @hidden_labels = hidden_labels + LabelManager::HIDDEN_RESERVED_LABELS @date_width = DATE_WIDTH - @from_width = FROM_WIDTH @size_width = nil @tags = Tagger.new self @@ -425,6 +424,11 @@ class ThreadIndexMode < LineCursorMode end end + def resize rows, cols + regen_text + super + end + protected def cursor_thread; @threads[curpos]; end @@ -463,29 +467,65 @@ protected buffer.mark_dirty if buffer end - def author_text_for_thread t - t.authors.map do |p| - if AccountManager.is_account?(p) - "me" - elsif t.authors.size == 1 - p.mediumname - else - p.shortname - end - end.uniq.join "," + def authors; map { |m, *o| m.from if m }.compact.uniq; end + + def author_names_and_newness_for_thread t + new = {} + authors = t.map do |m, *o| + next unless m + + name = + if AccountManager.is_account?(m.from) + "me" + elsif t.authors.size == 1 + m.from.mediumname + else + m.from.shortname + end + + new[name] ||= m.has_label?(:unread) + name + end + + authors.compact.uniq.map { |a| [a, new[a]] } end def text_for_thread t date = t.date.to_nice_s - from = author_text_for_thread t - if from.length > @from_width - from = from[0 ... (@from_width - 1)] - from += "." unless from[-1] == ?\s - end new = t.has_label?(:unread) starred = t.has_label?(:starred) + ## format the from column + cur_width = 0 + ann = author_names_and_newness_for_thread t + from = [] + ann.each_with_index do |(name, newness), i| + break if cur_width >= from_width + last = i == ann.length - 1 + + abbrev = + if cur_width + name.length > from_width + name[0 ... (from_width - cur_width - 1)] + "." + elsif cur_width + name.length == from_width + name[0 ... (from_width - cur_width)] + else + if last + name[0 ... (from_width - cur_width)] + else + name[0 ... (from_width - cur_width - 1)] + "," + end + end + + cur_width += abbrev.length + + if last && from_width > cur_width + abbrev += " " * (from_width - cur_width) + end + + from << [(newness ? :index_new_color : (starred ? :index_starred_color : :index_old_color)), abbrev] + end + dp = t.direct_participants.any? { |p| AccountManager.is_account? p } p = dp || t.participants.any? { |p| AccountManager.is_account? p } @@ -502,7 +542,9 @@ protected [:tagged_color, @tags.tagged?(t) ? ">" : " "], [:none, sprintf("%#{@date_width}s", date)], (starred ? [:starred_color, "*"] : [:none, " "]), - [base_color, sprintf("%-#{@from_width}s", from)], + ] + + from + + [ [:none, t.size == 1 ? " " * (@size_width + 2) : sprintf("(%#{@size_width}d)", t.size)], [:to_me_color, dp ? " >" : (p ? ' +' : " ")], [base_color, t.subj + (t.subj.empty? ? "" : " ")], @@ -510,12 +552,17 @@ protected (t.labels - @hidden_labels).map { |label| [:label_color, "+#{label} "] } + [[:snippet_color, t.snippet] ] + end def dirty?; (@hidden_threads.keys + @threads).any? { |t| t.dirty? }; end private + def from_width + [(buffer.content_width.to_f * 0.2).to_i, MIN_FROM_WIDTH].max + end + def initialize_threads @ts = ThreadSet.new Index.instance, $config[:thread_by_subject] @ts_mutex = Mutex.new