libncurses: Import https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz changes

Change-Id: I3433d30ca01359fd2e3623ede96b531f0b39cbfa
Signed-off-by: micky387 <mickaelsaibi@free.fr>
diff --git a/test/redraw.c b/test/redraw.c
index 9cb0de9..749f790 100644
--- a/test/redraw.c
+++ b/test/redraw.c
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 2006-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright 2020-2021,2022 Thomas E. Dickey                                *
+ * Copyright 2006-2012,2017 Free Software Foundation, Inc.                  *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -26,13 +27,14 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: redraw.c,v 1.8 2012/12/08 20:46:02 tom Exp $
+ * $Id: redraw.c,v 1.17 2022/12/10 22:28:50 tom Exp $
  *
  * Demonstrate the redrawwin() and wredrawln() functions.
  * Thomas Dickey - 2006/11/4
  */
 
 #include <test.priv.h>
+#include <popup_msg.h>
 
 static void
 trash(int beg_x, int max_x, int cur_x)
@@ -53,15 +55,33 @@
     for (x = max_x; x > cur_x; --x) {
 	putchar('\b');
     }
+    fflush(stdout);
 }
 
 static void
 test_redraw(WINDOW *win)
 {
+    static const char *help[] =
+    {
+	"Commands:",
+	"  ^Q/ESC/q   - quit",
+	"  w          - recur in a new window",
+	"  !          - overwrite current line using stdio outside curses.",
+#ifdef NCURSES_VERSION
+	"  @          - run \"date\" command, to put its output on screen.",
+#endif
+	"  ^L         - call redrawwin() for current window.",
+	"  ^W         - call wredrawln() for current line/current window.",
+	"  arrow-keys - move cursor on the screen",
+	"",
+	"Other control characters are added to the screen in printable form.",
+	"Other printable characters are added to the screen as is.",
+	0
+    };
+
     WINDOW *win1;
     WINDOW *win2;
     bool done = FALSE;
-    int ch, y, x;
     int max_y, max_x;
     int beg_y, beg_x;
 
@@ -71,12 +91,16 @@
     keypad(win, TRUE);
     getmaxyx(win, max_y, max_x);
     getbegyx(win, beg_y, beg_x);
+
     while (!done) {
-	ch = wgetch(win);
+	int ch = wgetch(win);
+	int y, x;
+
 	getyx(win, y, x);
 	switch (ch) {
 	case 'q':
 	    /* FALLTHRU */
+	case QUIT:
 	case ESCAPE:
 	    done = TRUE;
 	    break;
@@ -111,7 +135,7 @@
 	    /*
 	     * For a shell command, we can work around the problem noted above
 	     * using mvcur().  It is ifdef'd for NCURSES, since X/Open does
-	     * not define the case where the old location is unknown. 
+	     * not define the case where the old location is unknown.
 	     */
 	    IGNORE_RC(system("date"));
 	    mvcur(-1, -1, y, x);
@@ -146,9 +170,14 @@
 		wmove(win, y, x + 1);
 	    break;
 
+	case HELP_KEY_1:
+	    popup_msg(win, help);
+	    break;
+
 	default:
 	    if (ch > KEY_MIN) {
 		waddstr(win, keyname(ch));
+		waddch(win, '\n');
 	    } else {
 		waddstr(win, unctrl(UChar(ch)));
 	    }
@@ -159,10 +188,59 @@
     }
 }
 
-int
-main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
+static void
+usage(int ok)
 {
-    initscr();
+    static const char *tbl[] =
+    {
+	"Usage: redraw [options]"
+	,""
+	,USAGE_COMMON
+	,"Options:"
+	," -e       use stderr (default stdout)"
+	," -n       do not initialize terminal"
+    };
+    unsigned n;
+    for (n = 0; n < SIZEOF(tbl); ++n)
+	fprintf(stderr, "%s\n", tbl[n]);
+    ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+/* *INDENT-OFF* */
+VERSION_COMMON()
+/* *INDENT-ON* */
+
+int
+main(int argc, char *argv[])
+{
+    int ch;
+    bool no_init = FALSE;
+    FILE *my_fp = stdout;
+
+    while ((ch = getopt(argc, argv, OPTS_COMMON "en")) != -1) {
+	switch (ch) {
+	case 'e':
+	    my_fp = stderr;
+	    break;
+	case 'n':
+	    no_init = TRUE;
+	    break;
+	case OPTS_VERSION:
+	    show_version(argv);
+	    ExitProgram(EXIT_SUCCESS);
+	default:
+	    usage(ch == OPTS_USAGE);
+	    /* NOTREACHED */
+	}
+    }
+    if (optind < argc)
+	usage(FALSE);
+
+    if (no_init) {
+	START_TRACE();
+    } else {
+	newterm((char *) 0, my_fp, stdin);
+    }
+
     raw();
     noecho();
     test_redraw(stdscr);