From 58f6d836d93450a293436030ef150435bd676b67 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 27 Jan 2004 07:12:47 +0000
Subject: [PATCH] set keypad() to FALSE while reading in verbatim input, to
 deal with a bit of xterm weirdness, and update a few keypad-related comments

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1637 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog   |  8 ++++++++
 src/nano.c  |  4 +++-
 src/winio.c | 17 +++++++++++++----
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a0c95e69..6ab68ca9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -33,6 +33,14 @@ CVS code -
 	  matches inside a line (e.g. replace the "b" in "abc" with
 	  anything). (David Benbennick)
 - winio.c:
+  get_verbatim_kbinput()
+	- Set keypad() to FALSE while reading input, and set it back to
+	  TRUE afterwards.  This ensures that we don't end up reading in
+	  extended keypad values that are outside the ASCII range.
+	  (Also, with keypad() set to TRUE, xterm generates
+	  KEY_BACKSPACE when the user hits Ctrl-H, which, when cut down
+	  to ASCII range, ends up being Ctrl-G, which can be confusing.)
+	  (DLR)
   get_accepted_kbinput()
 	- Don't use "kbinput = wgetch(win)" as a switch value. (DLR)
   get_escape_seq_kbinput()
diff --git a/src/nano.c b/src/nano.c
index f602f3b5..bad05acb 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -240,7 +240,8 @@ void window_init(void)
     topwin = newwin(2, COLS, 0, 0);
     bottomwin = newwin(3 - no_help(), COLS, LINES - 3 + no_help(), 0);
 
-    /* This is so the keypad still works after a Meta-X, for example. */
+    /* Turn the keypad on, so that it still works after a Meta-X, for
+     * example. */
     keypad(edit, TRUE);
     keypad(bottomwin, TRUE);
 }
@@ -3468,6 +3469,7 @@ int main(int argc, char *argv[])
     mouse_init();
 #endif
 
+    /* Turn the keypad on */
     keypad(edit, TRUE);
     keypad(bottomwin, TRUE);
 
diff --git a/src/winio.c b/src/winio.c
index 639acf66..fd717078 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -58,8 +58,13 @@ char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len,
 	int allow_ascii)
 {
     char *verbatim_kbinput;
-    int kbinput = wgetch(win);
+    int kbinput;
+
+    /* Turn the keypad off so that we don't get extended keypad values,
+     * all of which are outside the ASCII range. */
+    keypad(win, FALSE);
 
+    kbinput = wgetch(win);
     verbatim_kbinput = charalloc(1);
     verbatim_kbinput[0] = kbinput;
     *kbinput_len = 1;
@@ -79,6 +84,9 @@ char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len,
 	nodelay(win, FALSE);
     }
 
+    /* Turn the keypad back on now that we're done. */
+    keypad(win, TRUE);
+
 #ifdef DEBUG
     fprintf(stderr, "get_verbatim_kbinput(): verbatim_kbinput = %s\n", verbatim_kbinput);
 #endif
@@ -308,9 +316,10 @@ int get_ascii_kbinput(WINDOW *win, int kbinput)
     return retval;
 }
 
-/* Translate escape sequences for extended keypad values.  These are
- * generated when the terminal doesn't support the needed keys.  Assume
- * that Escape has already been read in, and that nodelay(win) is TRUE.
+/* Translate escape sequences, most of which correspond to extended
+ * keypad values.  These sequences are generated when the terminal
+ * doesn't support the needed keys.  Assume that Escape has already been
+ * read in, and that nodelay(win) is TRUE.
  *
  * The supported terminals are the Linux console, the FreeBSD console,
  * the Hurd console (a.k.a. the Mach console), xterm, rxvt, and Eterm.
-- 
GitLab