From 6b2222c4b3e464ed6b97d2fe23ddf591994f12ae Mon Sep 17 00:00:00 2001 From: wmorgan Date: Sat, 3 Nov 2007 21:58:27 +0000 Subject: [PATCH] add --search option to sup (thanks to Marcus Williams) git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@665 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- bin/sup | 9 ++++++++- lib/sup/modes/search-results-mode.rb | 9 ++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/bin/sup b/bin/sup index d9e542c..b695306 100644 --- 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 diff --git a/lib/sup/modes/search-results-mode.rb b/lib/sup/modes/search-results-mode.rb index 6f0da2f..8917d5e 100644 --- a/lib/sup/modes/search-results-mode.rb +++ b/lib/sup/modes/search-results-mode.rb @@ -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] + "..." -- 2.45.2