* authorization. *
****************************************************************************/
/*
- * $Id: demo_new_pair.c,v 1.10 2017/03/10 09:47:15 tom Exp $
+ * $Id: demo_new_pair.c,v 1.16 2017/09/04 11:47:44 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
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#define MAX_BITS 8 /* all but A_ALTCHARSET */
#define MAX_ATTR ((1<<MAX_BITS)-1)
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)
{
wchar_t wch[2];
time_t start = now();
long total_cells = 0;
+ FILE *output = 0;
setlocale(LC_ALL, "");
}
}
- if (newterm(NULL, stderr, stdin) == 0)
- usage();
+ if (isatty(fileno(stderr))) {
+ output = stderr;
+ } else if ((ch = open("/dev/tty", O_WRONLY)) != 0) {
+ output = fdopen(ch, "w");
+ } else {
+ fprintf(stderr, "cannot open terminal for output\n");
+ ExitProgram(EXIT_FAILURE);
+ }
+ 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();
int my_pair;
switch (getch()) {
- case '?':
- show_help(help);
+ case HELP_KEY_1:
+ popup_msg(stdscr, help);
break;
case 'p':
/* step-by-page */
total_cells += 1 + (use_wide ? 1 : 0);
++current;
}
- endwin();
+ exit_curses();
+ fclose(output);
printf("%.1f cells/second\n",
(double) (total_cells) / (double) (now() - start));