From mboxrd@z Thu Jan 1 00:00:00 1970 From: marcus-sup@bar-coded.net (Marcus Williams) Date: Tue, 16 Jun 2009 13:42:08 +0100 Subject: [sup-talk] [PATCH] Alternative View Message-ID: <1245156068-sup-7360@tomsk> Adds a keypress to toggle to an alternative view in thread index mode. By default this removes the date, authors and number of threads from the view leaving more room for labels/snippets This view is extendable via the alternative-view-widget hook. An example hook is included in the contrib/hooks directory that implements the standard sup view as an example. If you use this example your alternative view will not look any different to the standard sup view. It is meant to give you a base point for your edits. --- contrib/hooks/alternate-view-widget.rb | 39 ++++++++++++++++++++++ lib/sup/modes/thread-index-mode.rb | 56 ++++++++++++++++++------------- 2 files changed, 71 insertions(+), 24 deletions(-) create mode 100644 contrib/hooks/alternate-view-widget.rb diff --git a/contrib/hooks/alternate-view-widget.rb b/contrib/hooks/alternate-view-widget.rb new file mode 100644 index 0000000..cf936fd --- /dev/null +++ b/contrib/hooks/alternate-view-widget.rb @@ -0,0 +1,39 @@ +# This hook recreates the standard sup view as the alternate view +# Note that this will mean there is no difference when toggling +# between the standard and alternate views in sup. This is meant to +# serve as a starting point for your own view + +date_width = Time::TO_NICE_S_MAX_LEN +date = thread.date.to_nice_s +starred = thread.has_label? :starred + +dp = thread.direct_participants.any? { |p| AccountManager.is_account? p } +p = dp || thread.participants.any? { |p| AccountManager.is_account? p } + +snippet = thread.snippet + (thread.snippet.empty? ? "" : "...") + +subj_color = + if thread.has_label?(:draft) + :index_draft_color + elsif thread.has_label?(:unread) + :index_new_color + elsif starred + :index_starred_color + else + :index_old_color + end + +[ + [:tagged_color, tagged ? ">" : " "], + [:none, sprintf("%#{date_width}s", date)], + (starred ? [:starred_color, "*"] : [:none, " "]), +] + from + +[ + [subj_color, size_widget_text], + [:to_me_color, thread.labels.member?(:attachment) ? "@" : " "], + [:to_me_color, dp ? ">" : (p ? '+' : " ")], +] + (thread.labels - hidden_labels).map { |label| [:label_color, "#{label} "] } + +[ + [subj_color, thread.subj + (thread.subj.empty? ? "" : " ")], + [:snippet_color, snippet], +] diff --git a/lib/sup/modes/thread-index-mode.rb b/lib/sup/modes/thread-index-mode.rb index 5fa4f4c..9124dbd 100644 --- a/lib/sup/modes/thread-index-mode.rb +++ b/lib/sup/modes/thread-index-mode.rb @@ -8,6 +8,15 @@ class ThreadIndexMode < LineCursorMode MIN_FROM_WIDTH = 15 LOAD_MORE_THREAD_NUM = 20 + HookManager.register "alternate-view-widget", <