]> git.cworth.org Git - sup/blobdiff - lib/sup/buffer.rb
Merge branch 'index-locking' into next
[sup] / lib / sup / buffer.rb
index 782695b7655c2f64beb0249a3671bc13afe2ff11..ebc3587bb44ea547ce2ef665fdf893b10296e23e 100644 (file)
@@ -63,7 +63,6 @@ class Buffer
     @title = opts[:title] || ""
     @force_to_top = opts[:force_to_top] || false
     @x, @y, @width, @height = 0, 0, width, height
-    @in_x = ENV["TERM"] =~ /(xterm|rxvt)/
   end
 
   def content_height; @height - 1; end
@@ -166,6 +165,15 @@ called at least once per keystroke, so excessive computation is discouraged.
 
 Variables: the same as status-bar-text hook.
 Return value: a string to be used as the terminal title.
+EOS
+
+  HookManager.register "extra-contact-addresses", <<EOS
+A list of extra addresses to propose for tab completion, etc. when the
+user is entering an email address. Can be plain email addresses or can
+be full "User Name <email@domain.tld>" entries.
+
+Variables: none
+Return value: an array of email address strings.
 EOS
 
   def initialize
@@ -178,6 +186,7 @@ EOS
     @textfields = {}
     @flash = nil
     @shelled = @asking = false
+    @in_x = ENV["TERM"] =~ /(xterm|rxvt|screen)/
 
     self.class.i_am_the_instance self
   end
@@ -263,7 +272,8 @@ EOS
         get_status_and_title @focus_buf # must be called outside of the ncurses lock
       end
 
-    print "\033]2;#{title}\07" if title && @in_x
+    ## http://rtfm.etla.org/xterm/ctlseq.html (see Operating System Controls)
+    print "\033]0;#{title}\07" if title && @in_x
 
     Ncurses.mutex.lock unless opts[:sync] == false
 
@@ -398,7 +408,7 @@ EOS
 
   def ask_with_completions domain, question, completions, default=nil
     ask domain, question, default do |s|
-      completions.select { |x| x =~ /^#{s}/i }.map { |x| [x, x] }
+      completions.select { |x| x =~ /^#{Regexp::escape s}/i }.map { |x| [x, x] }
     end
   end
 
@@ -414,7 +424,7 @@ EOS
           raise "william screwed up completion: #{partial.inspect}"
         end
 
-      completions.select { |x| x =~ /^#{target}/i }.map { |x| [prefix + x, x] }
+      completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] }
     end
   end
 
@@ -423,7 +433,7 @@ EOS
       prefix, target = partial.split_on_commas_with_remainder
       target ||= prefix.pop || ""
       prefix = prefix.join(", ") + (prefix.empty? ? "" : ", ")
-      completions.select { |x| x =~ /^#{target}/i }.map { |x| [prefix + x, x] }
+      completions.select { |x| x =~ /^#{Regexp::escape target}/i }.map { |x| [prefix + x, x] }
     end
   end
 
@@ -436,7 +446,7 @@ EOS
         if dir
           [[s.sub(full, dir), "~#{name}"]]
         else
-          users.select { |u| u =~ /^#{name}/ }.map do |u|
+          users.select { |u| u =~ /^#{Regexp::escape name}/ }.map do |u|
             [s.sub("~#{name}", "~#{u}"), "~#{u}"]
           end
         end
@@ -455,7 +465,7 @@ EOS
         elsif File.directory?(answer)
           spawn_modal "file browser", FileBrowserMode.new(answer)
         else
-          answer
+          File.expand_path answer
         end
     end
 
@@ -492,6 +502,7 @@ EOS
     contacts = ContactManager.contacts.map { |c| [ContactManager.alias_for(c), c.full_address, c.email] }
 
     completions = (recent + contacts).flatten.uniq.sort
+    completions += HookManager.run("extra-contact-addresses") || []
     answer = BufferManager.ask_many_emails_with_completions domain, question, completions, default
 
     if answer
@@ -557,7 +568,6 @@ EOS
 
   def ask_getch question, accept=nil
     raise "impossible!" if @asking
-    @asking = true
 
     accept = accept.split(//).map { |x| x[0] } if accept
 
@@ -570,6 +580,7 @@ EOS
       Ncurses.refresh
     end
 
+    @asking = true
     ret = nil
     done = false
     until done