]> git.cworth.org Git - sup/blobdiff - bin/sup
Merge branch 'ncurses-fixes'
[sup] / bin / sup
diff --git a/bin/sup b/bin/sup
index 7a51800a461c2c82a6a6f35e2b075451f05991bb..8a377f78149f5a4b17a56e06036fcae96e2b3fb6 100755 (executable)
--- a/bin/sup
+++ b/bin/sup
@@ -161,6 +161,9 @@ begin
   Redwood::start
   Index.load
 
+  trap("TERM") { |x| SuicideManager.please_die! }
+  trap("WINCH") { |x| BufferManager.sigwinch_happened! }
+
   if(s = Redwood::SourceManager.source_for DraftManager.source_name)
     DraftManager.source = s
   else
@@ -225,29 +228,39 @@ begin
   end
 
   until Redwood::exceptions.nonempty? || SuicideManager.die?
-    c = 
-       begin
-         Ncurses.nonblocking_getch
-       rescue Exception => e
-         if e.is_a?(Interrupt)
-           raise if BufferManager.ask_yes_or_no("Die ungracefully now?")
-           bm.draw_screen
-           nil
-         end
-       end
-    next unless c
+    c = begin
+      Ncurses.nonblocking_getch
+    rescue Interrupt => e
+      raise if BufferManager.ask_yes_or_no "Die ungracefully now?"
+      BufferManager.draw_screen
+      nil
+    end
+
+    if c.nil?
+      if BufferManager.sigwinch_happened?
+        debug "redrawing screen on sigwinch"
+        BufferManager.completely_redraw_screen
+      end
+      next
+    end
+
+    if c == 410
+      ## this is ncurses's way of telling us it's detected a refresh.
+      ## since we have our own sigwinch handler, we don't do anything.
+      next
+    end
+
     bm.erase_flash
 
-    action =
-      begin
-        if bm.handle_input c
-          :nothing
-        else
-          bm.resolve_input_with_keymap c, global_keymap
-        end
-      rescue InputSequenceAborted
+    action = begin
+      if bm.handle_input c
         :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