From mboxrd@z Thu Jan 1 00:00:00 1970 From: wmorgan-sup@masanjin.net (William Morgan) Date: Sat, 16 Feb 2008 12:06:32 -0800 Subject: [sup-talk] [PATCH] add URL extraction, listing, and viewing capabilities to ThreadViewMode In-Reply-To: <1203192249-sup-6640@south> References: <21aa9f0801291923w2df946dbga7832a7345c09a95@mail.gmail.com> <1203192249-sup-6640@south> Message-ID: <1203192317-sup-4404@south> --- Here's a "starter patch". Still needs HookManager integration to actually view the URLs, and probably some touching up of the extraction to trim out punctuation and the like. I found that URI.extract is very general unless you restrict it to particular schemata, so this limits it to http and ftp only. Feel free to expand/tweak any of it. lib/sup.rb | 1 + lib/sup/modes/thread-view-mode.rb | 13 +++++++++++++ lib/sup/modes/url-list-mode.rb | 23 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 0 deletions(-) create mode 100644 lib/sup/modes/url-list-mode.rb diff --git a/lib/sup.rb b/lib/sup.rb index cec36b6..3c591e6 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -276,6 +276,7 @@ require "sup/modes/buffer-list-mode" require "sup/modes/poll-mode" require "sup/modes/file-browser-mode" require "sup/modes/completion-mode" +require "sup/modes/url-list-mode" require "sup/sent" $:.each do |base| diff --git a/lib/sup/modes/thread-view-mode.rb b/lib/sup/modes/thread-view-mode.rb index fb324c1..99b7908 100644 --- a/lib/sup/modes/thread-view-mode.rb +++ b/lib/sup/modes/thread-view-mode.rb @@ -48,6 +48,7 @@ EOS k.add :subscribe_to_list, "Subscribe to/unsubscribe from mailing list", "(" k.add :unsubscribe_from_list, "Subscribe to/unsubscribe from mailing list", ")" k.add :pipe_message, "Pipe message or attachment to a shell command", '|' + k.add :view_urls, "View URLs in message", 'L' k.add_multi "(a)rchive/(d)elete/mark as (s)pam/mark as u(N)read:", '.' do |kk| kk.add :archive_and_kill, "Archive this thread and kill buffer", 'a' @@ -118,6 +119,18 @@ EOS def lines; @text.length; end def [] i; @text[i]; end + def view_urls + m = @message_lines[curpos] or return + chunks = m.chunks.select { |c| c.is_a? Chunk::Text } + return if chunks.empty? + + lines = chunks.map { |c| c.lines }.flatten.join(" ") + urls = URI.extract(lines, %w(http ftp)).uniq.sort + return if urls.empty? + + BufferManager.spawn "URLs for #{m.subj}", UrlListMode.new(urls) + end + def show_header m = @message_lines[curpos] or return BufferManager.spawn_unless_exists("Full header for #{m.id}") do diff --git a/lib/sup/modes/url-list-mode.rb b/lib/sup/modes/url-list-mode.rb new file mode 100644 index 0000000..f51cd52 --- /dev/null +++ b/lib/sup/modes/url-list-mode.rb @@ -0,0 +1,23 @@ +module Redwood +class UrlListMode < LineCursorMode + register_keymap do |k| + k.add :view_url, "View selected URL", :enter + end + + def initialize urls + @urls = urls + @text = urls.map { |u| u.to_s } + super() + end + + def lines; @text.length end + def [] i; @text[i] end + + def view_url + url = BufferManager.ask :url, "URL: ", @urls[curpos].to_s + return unless url + BufferManager.flash "viewing #{url.inspect}" + end +end + +end -- 1.5.4.rc2.69.g10f0 -- William