]> git.cworth.org Git - sup/commitdiff
add --search option to sup (thanks to Marcus Williams)
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 3 Nov 2007 21:58:27 +0000 (21:58 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Sat, 3 Nov 2007 21:58:27 +0000 (21:58 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@665 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup
lib/sup/modes/search-results-mode.rb

diff --git a/bin/sup b/bin/sup
index d9e542c43ccd26001f96e239ed69b352ca330b40..b69530658f146b4e9eb4d8a88d0ce2d4112b6f49 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -19,6 +19,7 @@ Options are:
 EOS
   opt :list_hooks, "List all hooks and descriptions thereof, and quit."
   opt :no_threads, "Turn of threading. Helps with debugging. (Necessarily disables background polling for new messages.)"
+  opt :search, "Search for threads ", :type => String
 end
 
 if $opts[:list_hooks]
@@ -195,6 +196,10 @@ begin
     Index.start_lock_update_thread
   end
 
+  if $opts[:search]
+    SearchResultsMode.spawn_from_query $opts[:search]
+  end
+
   until $exception || SuicideManager.die?
     c = Ncurses.nonblocking_getch
     next unless c
@@ -220,7 +225,9 @@ begin
         b = bm.spawn_unless_exists("Contact List") { ContactListMode.new }
         b.mode.load_in_background
       when :search
-        SearchResultsMode.spawn_by_query
+        query = BufferManager.ask :search, "query: "
+        next unless query && query !~ /^\s*$/
+        SearchResultsMode.spawn_from_query query
       when :list_labels
         labels = LabelManager.listable_labels.map { |l| LabelManager.string_for l }
         user_label = bm.ask_with_completions :label, "Show threads with label (enter for listing): ", labels
index 6f0da2f101fa3f9a14a0ca0aa2cff698ec95ab9b..8917d5e2028f0f56448d2cec6c52eeb409ee4461 100644 (file)
@@ -11,7 +11,9 @@ class SearchResultsMode < ThreadIndexMode
   end
 
   def refine_search
-    SearchResultsMode.spawn_by_query(@qobj.to_s + " ")
+    query = BufferManager.ask :search, "query: ", (@qobj.to_s + " ")
+    return unless query && query !~ /^\s*$/
+    SearchResultsMode.spawn_from_query query
   end
 
   ## a proper is_relevant? method requires some way of asking ferret
@@ -20,10 +22,7 @@ class SearchResultsMode < ThreadIndexMode
   ## the message, and search against it to see if i have > 0 results,
   ## but that seems pretty insane.
 
-  def self.spawn_by_query default=""
-    text = BufferManager.ask :search, "query: ", default
-    return unless text && text !~ /^\s*$/
-
+  def self.spawn_from_query text
     begin
       qobj = Index.parse_user_query_string text
       short_text = text.length < 20 ? text : text[0 ... 20] + "..."