[PATCH 15/16] test/dup_field.c: Add help text.

"G. Branden Robinson" <[email protected]>
Newsgroups gmane.comp.lib.ncurses.bugs
Message-ID <20260815122203.y66o5wec5cf4kxfs@illithid>
* test/dup_field.c: Add new global WINDOW pointer `win_help`.
  (rip_help): New function stores the WINDOW pointer for the help window
  created by initscr(3).
  (configure_help): New function populates the help window.
  (main): Call ripoffline(3) to reserve a help window.  Once curses and
  color pairs are set up, call `configure_help()`.

All of these changes are preprocessor-conditionalized on
`HAVE_RIPOFFLINE`.
---
 test/dup_field.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/test/dup_field.c b/test/dup_field.c
index 2672339db..35dd2d476 100644
--- a/test/dup_field.c
+++ b/test/dup_field.c
@@ -48,6 +48,9 @@ static FIELD *all_fields[MAX_FIELDS];
 static bool is_editing[MAX_FIELDS];
 static bool was_copied[MAX_FIELDS];
 static unsigned num_fields;
+#if HAVE_RIPOFFLINE
+WINDOW *win_help = NULL;
+#endif
 static FIELD **last_list;
 /* *INDENT-OFF* */
 static struct {
@@ -447,6 +450,38 @@ usage(int ok)
 VERSION_COMMON()
 /* *INDENT-ON* */
 
+#if HAVE_RIPOFFLINE
+static int
+rip_help(WINDOW *win, int cols)
+{
+    win_help = win;
+    return OK;
+}
+
+/*
+ * We can't do this stuff in rip_help() because colors aren't yet set up
+ * when initscr() calls it.
+ */
+static void
+configure_help(WINDOW *win)
+{
+    const size_t bufsz = 512; /* maximum # columns ncurses supports */
+    char buf[bufsz];
+
+    memset(buf, 0, bufsz);
+    (void) snprintf(buf, bufsz,
+		    "Press F1 for help, %s to duplicate field,"
+		    " or ^Q to quit.",
+		    keyname(DO_DEMO));
+    wbkgd(win, (chtype) COLOR_PAIR(1));
+    werase(win);
+    wmove(win, 0, 0);
+    wprintw(win, buf);
+    wnoutrefresh(win);
+    return;
+}
+#endif
+
 int
 main(int argc, char *argv[])
 {
@@ -464,6 +499,9 @@ main(int argc, char *argv[])
 
     setlocale(LC_ALL, "");
 
+#if HAVE_RIPOFFLINE
+    ripoffline(-1, rip_help);
+#endif
     initscr();
     cbreak();
     noecho();
@@ -481,6 +519,9 @@ main(int argc, char *argv[])
 	refresh();
     }
 
+#if HAVE_RIPOFFLINE
+    configure_help(win_help);
+#endif
     demo_forms();
 
     endwin();
-- 
2.30.2
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEh3PWHWjjDgcrENwa0Z6cfXEmbc4FAmqAWesACgkQ0Z6cfXEm
bc46OA/9HuaLD0p2nD5uGjL7LVUCokj4zLEbkurcEij5XsEln9FjxrJtiCLQ+lrY
44y9HhMI96TjRqz4ORRZsYkxXgecETlaEDc3OieJV9obijGNmK3iJrszasCaXSC9
TXzJY0yQbeILFRUqqQXvAcZOtG2fwqV/U7pYRkyuMfkPIbMgoXPvlbT2ff42C/JQ
7YASo+u8hTWeCAovFdMm0bBDmLiOsqq/npk7/RPwbbA+Y9hjsO/kEaVxD8udLniA
Qny4CdQqabJfyhGFskIXQvCYcCZFEZudA0A4SCU6ovv8Z6waELT/jIlu/suwDQiR
d2Vt7JqYh8rCZmJwEl91y1Aax0rmgSSjrDncaoKS0iEdF7L5ADLIzZRdc5+OlZCr
UM7yYitg6ymrSSrnyG8UDUraJwiAGh4TDGQp0rYEK7lnU+9XLvZcQWQEkvNAOjKO
5dON4SpqFMU++PYGw12CVioHb2IX7BHP7x1r6tcfWnwPckE5PVdx7/xJpmnay6+R
s7PzS8DUZylHMRbFlNHKATo2J4eLFMm/I8ps49ROOZu2d1dbrd5LzyhN0Sx0IM3P
iKkD8ZVLZfu0lBoPLRiCTxhmHzHgB473/X3F/aEFLotVJKxEsdshSqoo6wG857NH
BBL51CEkYnhoBOtuzBEj2gCDhIjJcOi5G9KAw/pFQtsa1tblOuE=
=C6Mp
-----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.