]> git.cworth.org Git - sup/blobdiff - bin/sup
added SSL errors to the list of shit we have to catch
[sup] / bin / sup
diff --git a/bin/sup b/bin/sup
index 8c785e477584ad1f62202d7dfdb7c8e09e0f7559..c565a784de0714038f11c2e4f67ea27727fdf604 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -12,9 +12,9 @@ global_keymap = Keymap.new do |k|
   k.add :quit, "Quit Redwood", 'q'
   k.add :help, "Show help", 'H', '?'
   k.add :roll_buffers, "Switch to next buffer", 'b'
-  k.add :roll_buffers_backwards, "Switch to previous buffer", 'B'
+#  k.add :roll_buffers_backwards, "Switch to previous buffer", 'B'
   k.add :kill_buffer, "Kill the current buffer", 'x'
-  k.add :list_buffers, "List all buffers", 'A'
+  k.add :list_buffers, "List all buffers", 'B'
   k.add :list_contacts, "List contacts", 'C'
   k.add :redraw, "Redraw screen", :ctrl_l
   k.add :search, "Search messages", '/'
@@ -65,12 +65,16 @@ begin
     c.add :index_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
     c.add :index_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK, 
            Ncurses::A_BOLD
+    c.add :index_starred_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK, 
+           Ncurses::A_BOLD
     c.add :labellist_old_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
     c.add :labellist_new_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK, 
            Ncurses::A_BOLD
     c.add :twiddle_color, Ncurses::COLOR_BLUE, Ncurses::COLOR_BLACK
     c.add :label_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
     c.add :message_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_GREEN
+    c.add :alternate_patina_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_BLUE
+    c.add :missing_message_color, Ncurses::COLOR_BLACK, Ncurses::COLOR_RED
     c.add :mime_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
     c.add :quote_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
     c.add :sig_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK
@@ -81,6 +85,8 @@ begin
           Ncurses::A_BOLD
     c.add :starred_patina_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_GREEN,
           Ncurses::A_BOLD
+    c.add :alternate_starred_patina_color, Ncurses::COLOR_YELLOW,
+          Ncurses::COLOR_BLUE, Ncurses::A_BOLD
     c.add :snippet_color, Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK
     c.add :option_color, Ncurses::COLOR_WHITE, Ncurses::COLOR_BLACK
     c.add :tagged_color, Ncurses::COLOR_YELLOW, Ncurses::COLOR_BLACK,
@@ -96,11 +102,29 @@ begin
   imode = InboxMode.new
   ibuf = bm.spawn "inbox", imode
 
-  log "ready for (inter)action!"
+  log "ready for interaction!"
   Logger.make_buf
 
   bm.draw_screen
-  imode.load_threads :num => ibuf.content_height, :when_done => lambda {   reporting_thread { sleep 1; PollManager.poll } }
+
+  begin
+    Index.usual_sources.each { |s| s.check }
+  rescue SourceError
+    # do nothing! we'll report it at the next step
+  end
+  Redwood::report_broken_sources
+  
+  Index.usual_sources.each do |s|
+    reporting_thread do
+      begin
+        s.connect
+      rescue SourceError => e
+        Redwood::log "fatal error loading from #{s}: #{e.message}"
+      end
+    end if s.respond_to? :connect
+  end
+
+  imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread { sleep 1; PollManager.poll } }
 
   PollManager.start_thread
 
@@ -116,7 +140,7 @@ begin
         x = global_keymap.action_for c
         case x
         when :quit
-          break
+          break if bm.kill_all_buffers_safely
         when :help
           curmode = bm.focus_buf.mode
           bm.spawn_unless_exists("<help for #{curmode.name}>") { HelpMode.new curmode, global_keymap }
@@ -125,12 +149,12 @@ begin
         when :roll_buffers_backwards
           bm.roll_buffers_backwards
         when :kill_buffer
-          bm.kill_buffer bm.focus_buf if bm.focus_buf.mode.killable?
+          bm.kill_buffer_safely bm.focus_buf
         when :list_buffers
           bm.spawn_unless_exists("Buffer List") { BufferListMode.new }
         when :list_contacts
           b = bm.spawn_unless_exists("Contact List") { ContactListMode.new }
-          b.mode.load_more b.content_height
+          b.mode.load_in_background
         when :search
           text = bm.ask :search, "query: "
           next unless text && text !~ /^\s*$/
@@ -145,7 +169,6 @@ begin
           rescue Ferret::QueryParser::QueryParseException => e
             bm.flash "Couldn't parse query."
           end
-
         when :list_labels
           b = bm.spawn_unless_exists("Label List") { LabelListMode.new }
           b.mode.load_in_background
@@ -154,7 +177,7 @@ begin
           bm.spawn "New Message", mode
           mode.edit
         when :poll
-          bm.raise_to_front PollManager.buffer
+#          bm.raise_to_front PollManager.buffer
           reporting_thread { PollManager.poll }
         when :recall_draft
           case Index.num_results_for :label => :draft
@@ -181,18 +204,16 @@ begin
       end
     end
   end
-  bm.kill_all_buffers
 rescue Exception => e
   $exception ||= e
 ensure
   Redwood::finish
   stop_cursing
-  
-  # don't ask me why, but sometimes it's necessary to print something
-  # to stderr at this point or the exception doesn't get printed.
-  # doesn't get printed. WHY?
-
-  $stderr.puts " " 
+  if $exception
+    Redwood::log "oh crap, an exception"
+  else
+    Redwood::log "good night, sweet prince!"
+  end
 end
 
 Index.save unless $exception # TODO: think about this