]> git.cworth.org Git - sup/commitdiff
Merge branch 'master' into next
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 9 Sep 2009 14:08:33 +0000 (10:08 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Wed, 9 Sep 2009 14:11:20 +0000 (10:11 -0400)
Conflicts:
lib/sup/ferret_index.rb

1  2 
bin/sup
lib/sup/buffer.rb
lib/sup/ferret_index.rb
lib/sup/modes/console-mode.rb
lib/sup/xapian_index.rb

diff --combined bin/sup
index 5049879cd16432661bb46fb8176b008f89c1eab2,6a35cfdaa95d6da360c400e47086ccc2868d2b53..e53a8e8bfafa2fcffa00cf89d1e75fa26eb62bec
+++ b/bin/sup
@@@ -58,7 -58,6 +58,7 @@@ if $opts[:list_hooks
  end
  
  Thread.abort_on_exception = true # make debugging possible
 +Thread.current.priority = 1 # keep ui responsive
  
  module Redwood
  
@@@ -211,7 -210,7 +211,7 @@@ begi
    until Redwood::exceptions.nonempty? || $die
      c = begin
        Ncurses.nonblocking_getch
-     rescue Interrupt => e
+     rescue Interrupt
        raise if BufferManager.ask_yes_or_no "Die ungracefully now?"
        BufferManager.draw_screen
        nil
  
      bm.erase_flash
  
 -    action = begin
 -      if bm.handle_input c
 +    action =
 +      begin
 +        if bm.handle_input c
 +          :nothing
 +        else
 +          bm.resolve_input_with_keymap c, global_keymap
 +        end
 +      rescue InputSequenceAborted
          :nothing
 -      else
 -        bm.resolve_input_with_keymap c, global_keymap
        end
 -    rescue InputSequenceAborted
 -      :nothing
 -    end
      case action
      when :quit_now
        break if bm.kill_all_buffers_safely
diff --combined lib/sup/buffer.rb
index 67ccd86ea533f15e0706233314ebcdd21188af7e,df5d23c455fbaeb9fa53a5d9d66305249d9d6f17..19f8ec2c0c37644ddf640c663281463d395dc1cb
@@@ -25,8 -25,6 +25,8 @@@ module Ncurse
    def mutex; @mutex ||= Mutex.new; end
    def sync &b; mutex.synchronize(&b); end
  
 +  ## magically, this stuff seems to work now. i could swear it didn't
 +  ## before. hm.
    def nonblocking_getch
      ## INSANTIY
      ## it is NECESSARY to wrap Ncurses.getch in a select() otherwise all
      end
    end
  
-   module_function :rows, :cols, :curx, :nonblocking_getch, :mutex, :sync
+   ## pretends ctrl-c's are ctrl-g's
+   def safe_nonblocking_getch
+     nonblocking_getch
+   rescue Interrupt
+     KEY_CANCEL
+   end
+   module_function :rows, :cols, :curx, :nonblocking_getch, :safe_nonblocking_getch, :mutex, :sync
  
    remove_const :KEY_ENTER
    remove_const :KEY_CANCEL
@@@ -72,7 -77,7 +79,7 @@@ class Buffe
    def content_height; @height - 1; end
    def content_width; @width; end
  
 -  def resize rows, cols
 +  def resize rows, cols 
      return if cols == @width && rows == @height
      @width = cols
      @height = rows
@@@ -385,7 -390,7 +392,7 @@@ EO
      draw_screen
  
      until mode.done?
-       c = Ncurses.nonblocking_getch
+       c = Ncurses.safe_nonblocking_getch
        next unless c # getch timeout
        break if c == Ncurses::KEY_CANCEL
        begin
      end
  
      while true
-       c = Ncurses.nonblocking_getch
+       c = Ncurses.safe_nonblocking_getch
        next unless c # getch timeout
        break unless tf.handle_input c # process keystroke
  
      ret = nil
      done = false
      until done
-       key = Ncurses.nonblocking_getch or next
+       key = Ncurses.safe_nonblocking_getch or next
        if key == Ncurses::KEY_CANCEL
          done = true
        elsif accept.nil? || accept.empty? || accept.member?(key)
diff --combined lib/sup/ferret_index.rb
index 2de8727f2e2652577d0ed4e8634caae8030003ae,d605e8d389f7e61c0cb2eb5a1ba168d077ae6d19..789a688d22b03630afdae22cb4dc5ae4e8600ba4
@@@ -8,10 -8,7 +8,7 @@@ class FerretIndex < BaseInde
  Executes before a string search is applied to the index,
  returning a new search string.
  Variables:
-   subs: The string being searched. Be careful about shadowing:
-     this variable is actually a method, so use a temporary variable
-     or explicitly call self.subs; the substitutions in index.rb
-     don't actually work.
+   subs: The string being searched.
  EOS
  
    def initialize dir=BASE_DIR
      query = {}
  
      subs = HookManager.run("custom-search", :subs => s) || s
 -    subs = s.gsub(/\b(to|from):(\S+)\b/) do
 +
 +    subs = subs.gsub(/\b(to|from):(\S+)\b/) do
        field, name = $1, $2
        if(p = ContactManager.contact_for(name))
          [field, p.email]
index af3d66d00d1c8fdd85521fecdf8edeef23c6c36b,f0c626e60e1024cdeee957e1dc5d0309f7f3973b..e9bf47cc914a978c0278d319c37654b2a6c8f97d
@@@ -21,6 -21,7 +21,7 @@@ class Consol
  
    def xapian; Index.instance.instance_variable_get :@xapian; end
    def ferret; Index.instance.instance_variable_get :@index; end
+   def special_methods; methods - Object.methods end
  
    ## files that won't cause problems when reloaded
    ## TODO expand this list / convert to blacklist
@@@ -64,15 -65,9 +65,9 @@@ class ConsoleMode < LogMod
    end
  
    def initialize
 -    super
 +    super "console"
      @console = Console.new self
      @binding = @console.instance_eval { binding }
-     self << <<EOS
- Sup #{VERSION} console.
- Available commands: #{(@console.methods - Object.methods) * ", "}
- Ctrl-g stops evaluation; 'e' restarts it.
- EOS
    end
  
    def execute cmd
    end
  
    def prompt
-     BufferManager.ask :console, "eval: "
+     BufferManager.ask :console, ">> "
    end
  
    def run
+     self << <<EOS
+ Sup v#{VERSION} console session started.
+ Available extra commands: #{(@console.special_methods) * ", "}
+ Ctrl-G stops evaluation; 'e' restarts it.
+ EOS
      while true
-       cmd = prompt or return
-       execute cmd
+       if(cmd = prompt)
+         execute cmd
+       else
+         self << "Console session ended."
+         break
+       end
      end
    end
  end
diff --combined lib/sup/xapian_index.rb
index 1395601367ef49fdebb9ef5019a82a07a0c83ca3,ab25ea04125eb9f8b1ee204a02bdb015d19604aa..e1cfe65a0c1266d6280d79d5e5fda8c310bd0508
@@@ -16,6 -16,13 +16,13 @@@ class XapianIndex < BaseInde
    MIN_DATE = Time.at 0
    MAX_DATE = Time.at(2**31-1)
  
+   HookManager.register "custom-search", <<EOS
+ Executes before a string search is applied to the index,
+ returning a new search string.
+ Variables:
+   subs: The string being searched.
+ EOS
    def initialize dir=BASE_DIR
      super
  
    def parse_query s
      query = {}
  
-     subs = s.gsub(/\b(to|from):(\S+)\b/) do
+     subs = HookManager.run("custom-search", :subs => s) || s
 -    subs = s.gsub(/\b(to|from):(\S+)\b/) do
++    subs = subs.gsub(/\b(to|from):(\S+)\b/) do
        field, name = $1, $2
        if(p = ContactManager.contact_for(name))
          [field, p.email]