X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdemo_new_pair.c;h=5f8e8e66a63ae8db4dfbac327b729f7d805666fe;hp=a0d069c06011cd6349d934e7c2796bc507a6c072;hb=5d8dbcdd9423bf9821db414fd9ec792ccf1f1027;hpb=a924c24b2535cccdc0f5f991cd8ddcadcfa1f0d2 diff --git a/test/demo_new_pair.c b/test/demo_new_pair.c index a0d069c0..5f8e8e66 100644 --- a/test/demo_new_pair.c +++ b/test/demo_new_pair.c @@ -26,13 +26,14 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_new_pair.c,v 1.11 2017/04/08 21:48:53 tom Exp $ + * $Id: demo_new_pair.c,v 1.16 2017/09/04 11:47:44 tom Exp $ * * Demonstrate the alloc_pair() function. */ #include #include +#include #if HAVE_ALLOC_PAIR && USE_WIDEC_SUPPORT @@ -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));