]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/demo_new_pair.c
ncurses 6.0 - patch 20170930
[ncurses.git] / test / demo_new_pair.c
index a0d069c06011cd6349d934e7c2796bc507a6c072..a0beb85c40dbfc2cb7c7c3dff98a4a984fcdff40 100644 (file)
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: demo_new_pair.c,v 1.11 2017/04/08 21:48:53 tom Exp $
+ * $Id: demo_new_pair.c,v 1.17 2017/09/28 23:17:56 tom Exp $
  *
  * Demonstrate the alloc_pair() function.
  */
 
 #include <test.priv.h>
 #include <time.h>
+#include <popup_msg.h>
 
 #if HAVE_ALLOC_PAIR && USE_WIDEC_SUPPORT
 
@@ -62,19 +63,19 @@ next_attr(int now)
        attr_t bits[MAX_BITS];
 
        init = TRUE;
-       bits[limit++] = A_NORMAL;
+       bits[limit++] = WA_NORMAL;
        if (valid_cap("smso"))
-           bits[limit++] = A_STANDOUT;
+           bits[limit++] = WA_STANDOUT;
        if (valid_cap("smul"))
-           bits[limit++] = A_UNDERLINE;
+           bits[limit++] = WA_UNDERLINE;
        if (valid_cap("rev"))
-           bits[limit++] = A_REVERSE;
+           bits[limit++] = WA_REVERSE;
        if (valid_cap("blink"))
-           bits[limit++] = A_BLINK;
+           bits[limit++] = WA_BLINK;
        if (valid_cap("dim"))
-           bits[limit++] = A_DIM;
+           bits[limit++] = WA_DIM;
        if (valid_cap("bold"))
-           bits[limit++] = A_BOLD;
+           bits[limit++] = WA_BOLD;
        for (j = 0; j < limit; ++j) {
            for (k = 0; k < limit; ++k) {
                table[j * limit + k] = bits[j] | bits[k];
@@ -118,24 +119,6 @@ next_color(int now)
     return result;
 }
 
-static void
-show_help(const char **help)
-{
-    WINDOW *mywin = newwin(LINES, COLS, 0, 0);
-    int n;
-
-    wmove(mywin, 1, 1);
-    for (n = 0; help[n] != 0; ++n) {
-       wmove(mywin, 1 + n, 2);
-       wprintw(mywin, "%.*s\n", COLS - 4, help[n]);
-    }
-    box(mywin, 0, 0);
-    wgetch(mywin);
-    delwin(mywin);
-    touchwin(stdscr);
-    refresh();
-}
-
 static time_t
 now(void)
 {
@@ -246,8 +229,11 @@ main(int argc, char *argv[])
        fprintf(stderr, "cannot open terminal for output\n");
        ExitProgram(EXIT_FAILURE);
     }
-    if (newterm(NULL, output, stdin) == 0)
-       usage();
+    if (newterm(NULL, output, stdin) == 0) {
+       fprintf(stderr, "Cannot initialize terminal\n");
+       fclose(output);
+       ExitProgram(EXIT_FAILURE);
+    }
     (void) cbreak();           /* read chars without wait for \n */
     (void) noecho();           /* don't echo input */
     update_modes();
@@ -272,8 +258,8 @@ main(int argc, char *argv[])
        int my_pair;
 
        switch (getch()) {
-       case '?':
-           show_help(help);
+       case HELP_KEY_1:
+           popup_msg(stdscr, help);
            break;
        case 'p':
            /* step-by-page */
@@ -348,7 +334,8 @@ main(int argc, char *argv[])
        total_cells += 1 + (use_wide ? 1 : 0);
        ++current;
     }
-    endwin();
+    exit_curses();
+    fclose(output);
 
     printf("%.1f cells/second\n",
           (double) (total_cells) / (double) (now() - start));