William Morgan
2008-Feb-16 20:04 UTC
[sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
[forgot to send to list] Reformatted excerpts from brabuhr''s message of 2008-02-08:> I was also thinking that it would be better to display the discovered > URIs in a list instead of the prompting, but I wasn''t sure how to > implement that. Another problem I see is that the extractor is > too-greedy and will pull in the punctuation following the URL; so, > perhaps the list should allow line editing before calling the view-url > hook?If you want to display them as a list, I would add a mode called UrlListMode or something like that which was a subclass of LineCursorMode. You can look to BufferListMode as an example, though it will be even simpler than that because the content won''t ever change. Spawn an instance of that mode when the user presses ''L'', and have enter in UrlListMode trigger the URL viewing hook, possibly first running it through BufferManager#ask for editing. We can also trim trailing punctuation from whatever URI.extract pulls out, since that sounds like the common case. -- William <wmorgan-sup at masanjin.net>
William Morgan
2008-Feb-16 20:06 UTC
[sup-talk] [PATCH] add URL extraction, listing, and viewing capabilities to ThreadViewMode
---
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 <wmorgan-sup at masanjin.net>
Nicolas Pouillard
2008-Feb-18 23:24 UTC
[sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
Excerpts from William Morgan''s message of Sat Feb 16 21:04:32 +0100 2008:> [forgot to send to list] > > Reformatted excerpts from brabuhr''s message of 2008-02-08: > > I was also thinking that it would be better to display the discovered > > URIs in a list instead of the prompting, but I wasn''t sure how to > > implement that. Another problem I see is that the extractor is > > too-greedy and will pull in the punctuation following the URL; so, > > perhaps the list should allow line editing before calling the view-url > > hook? > > If you want to display them as a list, I would add a mode called > UrlListMode or something like that which was a subclass of > LineCursorMode. You can look to BufferListMode as an example, though it > will be even simpler than that because the content won''t ever change. > > Spawn an instance of that mode when the user presses ''L'', and have > enter in UrlListMode trigger the URL viewing hook, possibly first > running it through BufferManager#ask for editing. We can also trim > trailing punctuation from whatever URI.extract pulls out, since that > sounds like the common case.You should look the rxvt-unicode terminal, there is an extension to deal with URLs [1]. That''s pretty handy in fact and applies not only to sup. [1]: http://www.jukie.net/~bart/blog/20070503013555 Regards, -- Nicolas Pouillard aka Ertai -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 194 bytes Desc: not available Url : http://rubyforge.org/pipermail/sup-talk/attachments/20080219/cb877745/attachment.bin
Daniel Wagner
2008-Feb-19 03:12 UTC
[sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
Excerpts from Nicolas Pouillard''s message of Mon Feb 18 15:24:54 -0800 2008:> You should look the rxvt-unicode terminal, there is an extension to deal with > URLs [1]. That''s pretty handy in fact and applies not only to sup. > > [1]: http://www.jukie.net/~bart/blog/20070503013555Sounds nice, does it handle multi-line URLs gracefully? In particular, in sup a multi-line URL could have a line-break in it... care to report how it handles this? http://www.yahoo.com/?this-is-a-really-long-url-for-you-to-test-with-if-you-would-be-so-kind-that-contains-no-newline-in-the-actual-message-as-sent http://www.yahoo.com/?this-is-a-really-long-url-for-you-to-test-with-if-you-woul d-be-so-kind-that-contains-a-newline-in-the-eightieth-column Either way, thanks for the tip! ~d
Nicolas Pouillard
2008-Feb-19 10:17 UTC
[sup-talk] [PATCH] first pass at a simple interface to extract URIs from a message
Excerpts from Daniel Wagner''s message of Tue Feb 19 04:12:15 +0100 2008:> Excerpts from Nicolas Pouillard''s message of Mon Feb 18 15:24:54 -0800 2008: > > You should look the rxvt-unicode terminal, there is an extension to deal with > > URLs [1]. That''s pretty handy in fact and applies not only to sup. > > > > [1]: http://www.jukie.net/~bart/blog/20070503013555 > > Sounds nice, does it handle multi-line URLs gracefully? In particular, > in sup a multi-line URL could have a line-break in it... care to report > how it handles this? > > http://www.yahoo.com/?this-is-a-really-long-url-for-you-to-test-with-if-you-would-be-so-kind-that-contains-no-newline-in-the-actual-message-as-sent > http://www.yahoo.com/?this-is-a-really-long-url-for-you-to-test-with-if-you-would-be-so-kind-that-contains-a-newline-in-the-eightieth-columnIt doesn''t handle br0ken URLs, however here that''s perhaps sup jobs to fix them. I send a patch to the list to fix this. Regards, -- Nicolas Pouillard aka Ertai -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 240 bytes Desc: not available Url : http://rubyforge.org/pipermail/sup-talk/attachments/20080219/61653c81/attachment-0001.bin