[PATCH 13/16] test/ncurses.c: Fix use of Control+D in form test.

"G. Branden Robinson" <[email protected]>
Newsgroups gmane.comp.lib.ncurses.bugs
Message-ID <20260815122141.rv4kyifcnhoy22wn@illithid>
This test program's `wGetChar()` interprets a Control+D as a demand to
instantly EOF and exit the program.  However, the help screen for the
form test documents that keystroke as navigating the form fields.  It
appears to be the only test that gives Control+D another meaning.  Fix
this the dumbest possible way--with a global Boolean variable.

It seemed not worth the trouble to add an argument to `wGetChar()` that
would be `FALSE` in every case but one.

* test/ncurses.c: Add new Boolean `IsEditingForm`, default `FALSE`.
  (wGetChar): Test it before checking for an input `CTRL('D')`.
  (form_virtualize): Set it `TRUE` on the way in, and `FALSE` on the way
  out, bracketing `wGetChar()`.
---
 test/ncurses.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/test/ncurses.c b/test/ncurses.c
index 18995280f..7b6962bfc 100644
--- a/test/ncurses.c
+++ b/test/ncurses.c
@@ -151,6 +151,9 @@ static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
 static int MaxColors;		/* the actual number of colors we'll use */
 static int MinColors;		/* the minimum color code */
 static bool UseColors;		/* true if we use colors */
+/* The form test must override wGetchar()'s handling of Control+D. */
+static bool IsEditingForm = FALSE;
+
 
 #undef max_pairs
 static int max_pairs;		/* ...and the number of color pairs */
@@ -220,7 +223,7 @@ wGetchar(WINDOW *win)
 #else
     c = wgetch(win);
 #endif
-    if (c == CTRL('D')) {
+    if (!IsEditingForm && (c == CTRL('D'))) {
 	Trace(("FORCE EOF"));
 	close(0);		/* force an EOF-style error */
 	c = wgetch(win);
@@ -6556,6 +6559,7 @@ edit_secure(FIELD *me, int c)
 static int
 form_virtualize(NCURSES_CONST FORM *f, WINDOW *w)
 {
+    IsEditingForm = TRUE;
     /* *INDENT-OFF* */
     static const struct {
 	int code;
@@ -6657,6 +6661,7 @@ form_virtualize(NCURSES_CONST FORM *f, WINDOW *w)
 	c = edit_secure(me, c);
 	set_field_back(me, A_UNDERLINE);
     }
+    IsEditingForm = FALSE;
     return c;
 }
 
-- 
2.30.2
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEh3PWHWjjDgcrENwa0Z6cfXEmbc4FAmqAWdUACgkQ0Z6cfXEm
bc4/iRAAqAlVKdVf1UXuWiuJ9RbkFpyXbajCOMexFen0ViZsSnTDC4+6V15LYdsP
8suSmyvMdR1LKHbTObxV8eE1t91UM0LWf1mTkqudq5hN81iwzbX5WdAD42ukaT9S
0DbaJmznYlQ4OGv6C+tn+UPG7NoaOQKCgOntPJ+RgY4VnCLIXjMV+Gidy3n2VIGI
lcYS7N83eKgNMgebSLKOTVuLdi3hzWT3207hDM2iueCZYx4R1WUNKvfYz50ymfD0
ECfA/78Ay3Dy5inCuYrKIzgi1vrLvucTTdCJgJJBizQ7afy2KmgsVnHBJadvG4mV
LaLavJGCJ569dOT3pRp0QPtTJlzkGJbImZVxY3W5V4KNcHeA+FReshW5XVL4i03P
0ZWKwP7sC/UTgFtbZbEzCekq8qsMUO47/nAEqAsCMFcwkcWfq9KwPQNK4eBRwcrt
Enc5fJrn5dZDlQnvXgjSSib57MMvmrWb6gaFbx7zC7dBa1iFuVauFZsM1llAznb3
3YGwnEjXnzzJBrgQ/6JFU8OVBs8l/Qho7yPfaqdO61/1zOJLTbpUVOnGaILvHG05
hZTPo2LwrhT3q8KIvHGHM0ApoRFiVwLPRSFIDcdpHR5pz37iqpkJV9XsiCxoABq5
buTWayXQLsmXj8C6oGHL20X7Cg+2sBMoY6MXlt+EcKugnwT7ZUo=
=HOGV
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.