sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 8039b8594c5246338406b284ab9b2c4974b77937
parent 8903cdedc810b5570b5d2cfb35d60683782aa84a
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Wed,  9 Sep 2009 10:03:08 -0400

protect getch from ctrl-c's outside of the main event loop

The main event loop was interpreting ctrl-c's correctly, but other getch
callers (like asking for input) were not. This change will treat ctrl-c as
ctrl-g in those cases.

Diffstat:
M bin/sup | 2 +-
M lib/sup/buffer.rb | 15 +++++++++++----
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/bin/sup b/bin/sup
@@ -210,7 +210,7 @@ begin
   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
diff --git a/lib/sup/buffer.rb b/lib/sup/buffer.rb
@@ -35,7 +35,14 @@ module Ncurses
     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
@@ -383,7 +390,7 @@ EOS
     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
@@ -559,7 +566,7 @@ EOS
     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
 
@@ -612,7 +619,7 @@ EOS
     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)