1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
28 /****************************************************************************
31 ncurses.c --- ncurses library exerciser
37 An interactive test module for the ncurses library.
40 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
41 Thomas E. Dickey (beginning revision 1.27 in 1996).
43 $Id: ncurses.c,v 1.296 2007/12/29 21:05:43 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_CALLS;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
109 #ifdef CURSES_WACS_ARRAY
110 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
111 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
112 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
113 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
114 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
115 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
116 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
121 #define P(string) printw("%s\n", string)
123 #define BLANK ' ' /* this is the background character */
126 static int max_colors; /* the actual number of colors we'll use */
127 static int min_colors; /* the minimum color code */
128 static bool use_colors; /* true if we use colors */
131 static int max_pairs; /* ...and the number of color pairs */
139 static RGB_DATA *all_colors;
141 static void main_menu(bool);
143 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
144 * though we can rely on negative x/y values to stop the macro.
147 do_h_line(int y, int x, chtype c, int to)
150 mvhline(y, x, c, (to) - (x));
154 do_v_line(int y, int x, chtype c, int to)
157 mvvline(y, x, c, (to) - (y));
171 return ((c) == QUIT || (c) == ESCAPE);
173 #define case_QUIT case QUIT: case ESCAPE
175 /* Common function to allow ^T to toggle trace-mode in the middle of a test
176 * so that trace-files can be made smaller.
179 wGetchar(WINDOW *win)
183 while ((c = wgetch(win)) == CTRL('T')) {
185 save_trace = _nc_tracing;
186 _tracef("TOGGLE-TRACING OFF");
189 _nc_tracing = save_trace;
193 _tracef("TOGGLE-TRACING ON");
200 #define Getchar() wGetchar(stdscr)
202 /* replaces wgetnstr(), since we want to be able to edit values */
204 wGetstring(WINDOW *win, char *buffer, int limit)
211 wattrset(win, A_REVERSE);
215 if (x > (int) strlen(buffer))
216 x = (int) strlen(buffer);
218 wprintw(win, "%-*s", limit, buffer);
219 wmove(win, y0, x0 + x);
220 switch (ch = wGetchar(win)) {
233 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
251 if (!isprint(ch) || ch >= KEY_MIN) {
253 } else if ((int) strlen(buffer) < limit) {
255 for (j = strlen(buffer) + 1; j > x; --j) {
256 buffer[j] = buffer[j - 1];
265 wattroff(win, A_REVERSE);
270 #if USE_WIDEC_SUPPORT
272 wGet_wchar(WINDOW *win, wint_t *result)
276 while ((c = wget_wch(win, result)) == CTRL('T')) {
278 save_trace = _nc_tracing;
279 _tracef("TOGGLE-TRACING OFF");
282 _nc_tracing = save_trace;
286 _tracef("TOGGLE-TRACING ON");
289 c = wget_wch(win, result);
293 #define Get_wchar(result) wGet_wchar(stdscr, result)
295 /* replaces wgetn_wstr(), since we want to be able to edit values */
297 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
306 wattrset(win, A_REVERSE);
310 if (x > (int) wcslen(buffer))
311 x = (int) wcslen(buffer);
313 /* clear the "window' */
315 wprintw(win, "%*s", limit, " ");
317 /* write the existing buffer contents */
319 waddnwstr(win, buffer, limit);
321 /* positions the cursor past character 'x' */
323 waddnwstr(win, buffer, x);
325 switch (wGet_wchar(win, &ch)) {
365 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
385 } else if ((int) wcslen(buffer) < limit) {
387 for (j = wcslen(buffer) + 1; j > x; --j) {
388 buffer[j] = buffer[j - 1];
397 wattroff(win, A_REVERSE);
408 addstr("Press any key to continue... ");
413 Cannot(const char *what)
415 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
420 ShellOut(bool message)
423 addstr("Shelling out...");
428 addstr("returned from shellout.\n");
432 #ifdef NCURSES_MOUSE_VERSION
434 * This function is the same as _tracemouse(), but we cannot count on that
435 * being available in the non-debug library.
438 mouse_decode(MEVENT const *ep)
440 static char buf[80 + (5 * 10) + (32 * 15)];
442 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
443 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
445 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
447 SHOW(BUTTON1_RELEASED, "release-1");
448 SHOW(BUTTON1_PRESSED, "press-1");
449 SHOW(BUTTON1_CLICKED, "click-1");
450 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
451 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
452 #if NCURSES_MOUSE_VERSION == 1
453 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
456 SHOW(BUTTON2_RELEASED, "release-2");
457 SHOW(BUTTON2_PRESSED, "press-2");
458 SHOW(BUTTON2_CLICKED, "click-2");
459 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
460 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
461 #if NCURSES_MOUSE_VERSION == 1
462 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
465 SHOW(BUTTON3_RELEASED, "release-3");
466 SHOW(BUTTON3_PRESSED, "press-3");
467 SHOW(BUTTON3_CLICKED, "click-3");
468 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
469 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
470 #if NCURSES_MOUSE_VERSION == 1
471 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
474 SHOW(BUTTON4_RELEASED, "release-4");
475 SHOW(BUTTON4_PRESSED, "press-4");
476 SHOW(BUTTON4_CLICKED, "click-4");
477 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
478 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
479 #if NCURSES_MOUSE_VERSION == 1
480 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
483 #if NCURSES_MOUSE_VERSION == 2
484 SHOW(BUTTON5_RELEASED, "release-5");
485 SHOW(BUTTON5_PRESSED, "press-5");
486 SHOW(BUTTON5_CLICKED, "click-5");
487 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
488 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
491 SHOW(BUTTON_CTRL, "ctrl");
492 SHOW(BUTTON_SHIFT, "shift");
493 SHOW(BUTTON_ALT, "alt");
494 SHOW(ALL_MOUSE_EVENTS, "all-events");
495 SHOW(REPORT_MOUSE_POSITION, "position");
499 if (buf[strlen(buf) - 1] == ' ')
500 buf[strlen(buf) - 2] = '\0';
501 (void) strcat(buf, "}");
504 #endif /* NCURSES_MOUSE_VERSION */
506 /****************************************************************************
508 * Character input test
510 ****************************************************************************/
513 setup_getch(WINDOW *win, bool flags[])
515 keypad(win, flags['k']); /* should be redundant, but for testing */
516 meta(win, flags['m']); /* force this to a known state */
524 wgetch_help(WINDOW *win, bool flags[])
526 static const char *help[] =
528 "e -- toggle echo mode"
529 ,"g -- triggers a getstr test"
530 ,"k -- toggle keypad/literal mode"
531 ,"m -- toggle meta (7-bit/8-bit) mode"
534 ,"w -- create a new window"
536 ,"z -- suspend this process"
540 unsigned chk = ((SIZEOF(help) + 1) / 2);
545 printw("Type any key to see its %s value. Also:\n",
546 flags['k'] ? "keypad" : "literal");
547 for (n = 0; n < SIZEOF(help); ++n) {
548 int row = 1 + (n % chk);
549 int col = (n >= chk) ? COLS / 2 : 0;
550 int flg = ((strstr(help[n], "toggle") != 0)
551 && (flags[UChar(*help[n])] != FALSE));
554 mvprintw(row, col, "%s", help[n]);
565 wgetch_wrap(WINDOW *win, int first_y)
567 int last_y = getmaxy(win) - 1;
568 int y = getcury(win) + 1;
576 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
582 static WINSTACK *winstack = 0;
583 static unsigned len_winstack = 0;
596 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
598 unsigned need = (level + 1) * 2;
602 winstack = (WINSTACK *) malloc(len_winstack * sizeof(WINSTACK));
603 } else if (need >= len_winstack) {
605 winstack = (WINSTACK *) realloc(winstack, len_winstack * sizeof(WINSTACK));
607 winstack[level].text = txt_win;
608 winstack[level].frame = box_win;
611 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229)
615 /* this chunk is now done in resize_term() */
622 #define slk_repaint() /* nothing */
626 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
627 * Resize both and paint the box in the parent.
630 resize_boxes(unsigned level, WINDOW *win)
634 int high = LINES - base;
638 wnoutrefresh(stdscr);
642 for (n = 0; n < level; ++n) {
643 wresize(winstack[n].frame, high, wide);
644 wresize(winstack[n].text, high - 2, wide - 2);
647 werase(winstack[n].text);
648 box(winstack[n].frame, 0, 0);
649 wnoutrefresh(winstack[n].frame);
650 wprintw(winstack[n].text,
652 getmaxy(winstack[n].text),
653 getmaxx(winstack[n].text));
654 wnoutrefresh(winstack[n].text);
655 if (winstack[n].text == win)
661 #define forget_boxes() /* nothing */
662 #define remember_boxes(level,text,frame) /* nothing */
666 wgetch_test(unsigned level, WINDOW *win, int delay)
669 int first_y, first_x;
673 bool blocking = (delay < 0);
675 memset(flags, FALSE, sizeof(flags));
676 flags[UChar('k')] = (win == stdscr);
678 setup_getch(win, flags);
679 wtimeout(win, delay);
680 getyx(win, first_y, first_x);
682 wgetch_help(win, flags);
683 wsetscrreg(win, first_y, getmaxy(win) - 1);
687 while ((c = wGetchar(win)) == ERR) {
690 (void) wprintw(win, "%05d: input error", incount);
693 (void) wprintw(win, "%05d: input timed out", incount);
695 wgetch_wrap(win, first_y);
697 if (c == ERR && blocking) {
699 wgetch_wrap(win, first_y);
700 } else if (isQuit(c)) {
702 } else if (c == 'e') {
703 flags[UChar('e')] = !flags[UChar('e')];
704 setup_getch(win, flags);
705 wgetch_help(win, flags);
706 } else if (c == 'g') {
707 waddstr(win, "getstr test: ");
709 wgetnstr(win, buf, sizeof(buf) - 1);
711 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
713 wgetch_wrap(win, first_y);
714 } else if (c == 'k') {
715 flags[UChar('k')] = !flags[UChar('k')];
716 setup_getch(win, flags);
717 wgetch_help(win, flags);
718 } else if (c == 'm') {
719 flags[UChar('m')] = !flags[UChar('m')];
720 setup_getch(win, flags);
721 wgetch_help(win, flags);
722 } else if (c == 's') {
724 } else if (c == 'w') {
725 int high = getmaxy(win) - 1 - first_y + 1;
726 int wide = getmaxx(win) - first_x;
728 int new_y = first_y + getbegy(win);
729 int new_x = first_x + getbegx(win);
731 getyx(win, old_y, old_x);
732 if (high > 2 && wide > 2) {
733 WINDOW *wb = newwin(high, wide, new_y, new_x);
734 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
739 remember_boxes(level, wi, wb);
740 wgetch_test(level + 1, wi, delay);
744 wgetch_help(win, flags);
745 wmove(win, old_y, old_x);
751 } else if (c == 'z') {
752 kill(getpid(), SIGTSTP);
755 wprintw(win, "Key pressed: %04o ", c);
756 #ifdef NCURSES_MOUSE_VERSION
757 if (c == KEY_MOUSE) {
762 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
764 move(event.y, event.x);
768 #endif /* NCURSES_MOUSE_VERSION */
770 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
771 if (c == KEY_RESIZE) {
772 resize_boxes(level, win);
775 (void) waddstr(win, keyname(c));
776 } else if (c > 0x80) {
777 unsigned c2 = (c & 0x7f);
779 (void) wprintw(win, "M-%c", UChar(c2));
781 (void) wprintw(win, "M-%s", unctrl(c2));
782 waddstr(win, " (high-half character)");
785 (void) wprintw(win, "%c (ASCII printable character)", c);
787 (void) wprintw(win, "%s (ASCII control character)",
790 wgetch_wrap(win, first_y);
798 begin_getch_test(void)
805 #ifdef NCURSES_MOUSE_VERSION
806 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
809 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
811 getnstr(buf, sizeof(buf) - 1);
815 if (isdigit(UChar(buf[0]))) {
816 delay = atoi(buf) * 100;
826 finish_getch_test(void)
828 #ifdef NCURSES_MOUSE_VERSION
829 mousemask(0, (mmask_t *) 0);
840 int delay = begin_getch_test();
843 wgetch_test(0, stdscr, delay);
848 #if USE_WIDEC_SUPPORT
850 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
851 * Resize both and paint the box in the parent.
855 resize_wide_boxes(unsigned level, WINDOW *win)
859 int high = LINES - base;
863 wnoutrefresh(stdscr);
867 for (n = 0; n < level; ++n) {
868 wresize(winstack[n].frame, high, wide);
869 wresize(winstack[n].text, high - 2, wide - 2);
872 werase(winstack[n].text);
873 box_set(winstack[n].frame, 0, 0);
874 wnoutrefresh(winstack[n].frame);
875 wprintw(winstack[n].text,
877 getmaxy(winstack[n].text),
878 getmaxx(winstack[n].text));
879 wnoutrefresh(winstack[n].text);
880 if (winstack[n].text == win)
885 #endif /* KEY_RESIZE */
888 wcstos(const wchar_t *src)
893 const wchar_t *tmp = src;
895 memset(&state, 0, sizeof(state));
896 if ((need = wcsrtombs(0, &tmp, 0, &state)) > 0) {
897 unsigned have = need;
898 result = (char *) calloc(have + 1, 1);
900 if (wcsrtombs(result, &tmp, have, &state) != have) {
909 wget_wch_test(unsigned level, WINDOW *win, int delay)
911 wchar_t wchar_buf[BUFSIZ];
912 wint_t wint_buf[BUFSIZ];
913 int first_y, first_x;
917 bool blocking = (delay < 0);
921 memset(flags, FALSE, sizeof(flags));
922 flags[UChar('k')] = (win == stdscr);
924 setup_getch(win, flags);
925 wtimeout(win, delay);
926 getyx(win, first_y, first_x);
928 wgetch_help(win, flags);
929 wsetscrreg(win, first_y, getmaxy(win) - 1);
933 while ((code = wGet_wchar(win, &c)) == ERR) {
936 (void) wprintw(win, "%05d: input error", incount);
939 (void) wprintw(win, "%05d: input timed out", incount);
941 wgetch_wrap(win, first_y);
943 if (code == ERR && blocking) {
945 wgetch_wrap(win, first_y);
946 } else if (isQuit((int) c)) {
948 } else if (c == 'e') {
949 flags[UChar('e')] = !flags[UChar('e')];
950 setup_getch(win, flags);
951 wgetch_help(win, flags);
952 } else if (c == 'g') {
953 waddstr(win, "getstr test: ");
955 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
958 wprintw(win, "wgetn_wstr returns an error.");
961 for (n = 0; (wchar_buf[n] = wint_buf[n]) != 0; ++n) ;
962 if ((temp = wcstos(wchar_buf)) != 0) {
963 wprintw(win, "I saw %d characters:\n\t`%s'.",
964 (int) wcslen(wchar_buf), temp);
967 wprintw(win, "I saw %d characters (cannot convert).",
968 (int) wcslen(wchar_buf));
972 wgetch_wrap(win, first_y);
973 } else if (c == 'k') {
974 flags[UChar('k')] = !flags[UChar('k')];
975 setup_getch(win, flags);
976 wgetch_help(win, flags);
977 } else if (c == 'm') {
978 flags[UChar('m')] = !flags[UChar('m')];
979 setup_getch(win, flags);
980 wgetch_help(win, flags);
981 } else if (c == 's') {
983 } else if (c == 'w') {
984 int high = getmaxy(win) - 1 - first_y + 1;
985 int wide = getmaxx(win) - first_x;
987 int new_y = first_y + getbegy(win);
988 int new_x = first_x + getbegx(win);
990 getyx(win, old_y, old_x);
991 if (high > 2 && wide > 2) {
992 WINDOW *wb = newwin(high, wide, new_y, new_x);
993 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
998 remember_boxes(level, wi, wb);
999 wget_wch_test(level + 1, wi, delay);
1003 wgetch_help(win, flags);
1004 wmove(win, old_y, old_x);
1009 } else if (c == 'z') {
1010 kill(getpid(), SIGTSTP);
1013 wprintw(win, "Key pressed: %04o ", c);
1014 #ifdef NCURSES_MOUSE_VERSION
1015 if (c == KEY_MOUSE) {
1019 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1021 move(event.y, event.x);
1025 #endif /* NCURSES_MOUSE_VERSION */
1026 if (code == KEY_CODE_YES) {
1028 if (c == KEY_RESIZE) {
1029 resize_wide_boxes(level, win);
1032 (void) waddstr(win, key_name((wchar_t) c));
1034 if (c < 256 && iscntrl(c)) {
1035 (void) wprintw(win, "%s (control character)", unctrl(c));
1038 waddnwstr(win, &c2, 1);
1039 (void) wprintw(win, " = %#x (printable character)", c);
1042 wgetch_wrap(win, first_y);
1052 int delay = begin_getch_test();
1055 wget_wch_test(0, stdscr, delay);
1057 finish_getch_test();
1061 /****************************************************************************
1063 * Character attributes test
1065 ****************************************************************************/
1067 #if HAVE_SETUPTERM || HAVE_TGETENT
1068 #define get_ncv() TIGETNUM("ncv","NC")
1069 #define get_xmc() TIGETNUM("xmc","sg")
1071 #define get_ncv() -1
1072 #define get_xmc() -1
1079 static int first = TRUE;
1080 static chtype result = 0;
1086 char *area_pointer = parsed;
1088 tgetent(buffer, getenv("TERM"));
1091 if (TIGETSTR("smso", "so"))
1092 result |= A_STANDOUT;
1093 if (TIGETSTR("smul", "us"))
1094 result |= A_UNDERLINE;
1095 if (TIGETSTR("rev", "mr"))
1096 result |= A_REVERSE;
1097 if (TIGETSTR("blink", "mb"))
1099 if (TIGETSTR("dim", "mh"))
1101 if (TIGETSTR("bold", "md"))
1103 if (TIGETSTR("smacs", "ac"))
1104 result |= A_ALTCHARSET;
1110 #define termattrs() my_termattrs()
1113 #define MAX_ATTRSTRING 31
1114 #define LEN_ATTRSTRING 26
1116 static char attr_test_string[MAX_ATTRSTRING + 1];
1119 attr_legend(WINDOW *helpwin)
1124 mvwprintw(helpwin, row++, col,
1126 mvwprintw(helpwin, row++, col,
1129 mvwprintw(helpwin, row++, col,
1130 "Modify the test strings:");
1131 mvwprintw(helpwin, row++, col,
1132 " A digit sets gaps on each side of displayed attributes");
1133 mvwprintw(helpwin, row++, col,
1134 " </> shifts the text left/right. ");
1136 mvwprintw(helpwin, row++, col,
1139 mvwprintw(helpwin, row++, col,
1140 " f/F/b/F toggle foreground/background background color");
1141 mvwprintw(helpwin, row++, col,
1142 " t/T toggle text/background color attribute");
1144 mvwprintw(helpwin, row++, col,
1145 " a/A toggle ACS (alternate character set) mapping");
1146 mvwprintw(helpwin, row++, col,
1147 " v/V toggle video attribute to combine with each line");
1151 show_color_attr(int fg, int bg, int tx)
1154 printw(" Colors (fg %d, bg %d", fg, bg);
1156 printw(", text %d", tx);
1162 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1193 if (*fg < min_colors)
1197 if (*bg < min_colors)
1211 adjust_attr_string(int adjust)
1213 int first = ((int) UChar(attr_test_string[0])) + adjust;
1214 int last = first + LEN_ATTRSTRING;
1216 if (first >= ' ' && last <= '~') { /* 32..126 */
1218 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1219 attr_test_string[j] = k;
1220 if (((k + 1 - first) % 5) == 0) {
1222 if (j < MAX_ATTRSTRING)
1223 attr_test_string[j] = ' ';
1226 while (j < MAX_ATTRSTRING)
1227 attr_test_string[j++] = ' ';
1228 attr_test_string[j] = '\0';
1235 init_attr_string(void)
1237 attr_test_string[0] = 'a';
1238 adjust_attr_string(0);
1242 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1244 int ncv = get_ncv();
1245 chtype test = attr & (chtype) (~A_ALTCHARSET);
1248 mvprintw(row, 5, "-->");
1249 mvprintw(row, 8, "%s mode:", name);
1250 mvprintw(row, 24, "|");
1252 printw("%*s", skip, " ");
1254 * Just for testing, write text using the alternate character set one
1255 * character at a time (to pass its rendition directly), and use the
1256 * string operation for the other attributes.
1258 if (attr & A_ALTCHARSET) {
1262 for (s = attr_test_string; *s != '\0'; ++s) {
1268 addstr(attr_test_string);
1272 printw("%*s", skip, " ");
1274 if (test != A_NORMAL) {
1275 if (!(termattrs() & test)) {
1278 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1279 static const chtype table[] =
1295 for (n = 0; n < SIZEOF(table); n++) {
1296 if ((table[n] & attr) != 0
1297 && ((1 << n) & ncv) != 0) {
1305 if ((termattrs() & test) != test)
1312 static const struct {
1314 NCURSES_CONST char * name;
1315 } attrs_to_test[] = {
1316 { A_STANDOUT, "STANDOUT" },
1317 { A_REVERSE, "REVERSE" },
1319 { A_UNDERLINE, "UNDERLINE" },
1321 { A_BLINK, "BLINK" },
1322 { A_PROTECT, "PROTECT" },
1324 { A_INVIS, "INVISIBLE" },
1326 { A_NORMAL, "NORMAL" },
1331 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1341 if (ch < 256 && isdigit(ch)) {
1349 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1351 attr_legend(helpwin);
1364 *kc = SIZEOF(attrs_to_test) - 1;
1370 if (*kc >= SIZEOF(attrs_to_test))
1374 adjust_attr_string(-1);
1377 adjust_attr_string(1);
1383 error = cycle_color_attr(ch, fg, bg, tx);
1393 /* test text attributes */
1396 int skip = get_xmc();
1397 short fg = COLOR_BLACK; /* color pair 0 is special */
1398 short bg = COLOR_BLACK;
1406 n = skip; /* make it easy */
1407 k = SIZEOF(attrs_to_test) - 1;
1412 chtype normal = A_NORMAL | BLANK;
1416 short pair = (fg != COLOR_BLACK || bg != COLOR_BLACK);
1419 if (init_pair(pair, fg, bg) == ERR) {
1422 normal |= COLOR_PAIR(pair);
1427 if (init_pair(pair, tx, bg) == ERR) {
1430 extras |= COLOR_PAIR(pair);
1439 mvaddstr(0, 20, "Character attribute test display");
1441 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1442 bool arrow = (j == k);
1443 row = show_attr(row, n, arrow,
1445 attrs_to_test[j].attr |
1446 attrs_to_test[k].attr,
1447 attrs_to_test[j].name);
1451 "This terminal does %shave the magic-cookie glitch",
1452 get_xmc() > -1 ? "" : "not ");
1453 mvprintw(row + 1, 8, "Enter '?' for help.");
1454 show_color_attr(fg, bg, tx);
1455 printw(" ACS (%d)", ac != 0);
1458 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1460 bkgdset(A_NORMAL | BLANK);
1465 #if USE_WIDEC_SUPPORT
1466 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1469 wide_adjust_attr_string(int adjust)
1471 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1472 int last = first + LEN_ATTRSTRING;
1474 if (first >= ' ' && last <= '~') { /* 32..126 */
1476 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1477 wide_attr_test_string[j] = k;
1478 if (((k + 1 - first) % 5) == 0) {
1480 if (j < MAX_ATTRSTRING)
1481 wide_attr_test_string[j] = ' ';
1484 while (j < MAX_ATTRSTRING)
1485 wide_attr_test_string[j++] = ' ';
1486 wide_attr_test_string[j] = '\0';
1493 wide_init_attr_string(void)
1495 wide_attr_test_string[0] = 'a';
1496 wide_adjust_attr_string(0);
1500 set_wide_background(short pair)
1507 setcchar(&normal, blank, A_NORMAL, pair, 0);
1513 get_wide_background(void)
1515 attr_t result = A_NORMAL;
1521 if (getbkgrnd(&ch) != ERR) {
1522 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1530 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1532 int ncv = get_ncv();
1533 chtype test = attr & ~WA_ALTCHARSET;
1536 mvprintw(row, 5, "-->");
1537 mvprintw(row, 8, "%s mode:", name);
1538 mvprintw(row, 24, "|");
1540 printw("%*s", skip, " ");
1543 * Just for testing, write text using the alternate character set one
1544 * character at a time (to pass its rendition directly), and use the
1545 * string operation for the other attributes.
1547 if (attr & WA_ALTCHARSET) {
1551 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1555 setcchar(&ch, fill, attr, pair, 0);
1562 attr_get(&old_attr, &old_pair, 0);
1563 attr_set(attr, pair, 0);
1564 addwstr(wide_attr_test_string);
1565 attr_set(old_attr, old_pair, 0);
1568 printw("%*s", skip, " ");
1570 if (test != A_NORMAL) {
1571 if (!(term_attrs() & test)) {
1574 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1575 static const attr_t table[] =
1589 for (n = 0; n < SIZEOF(table); n++) {
1590 if ((table[n] & attr) != 0
1591 && ((1 << n) & ncv) != 0) {
1599 if ((term_attrs() & test) != test)
1607 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1617 if (ch < 256 && isdigit(ch)) {
1625 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1626 box_set(helpwin, 0, 0);
1627 attr_legend(helpwin);
1640 *kc = SIZEOF(attrs_to_test) - 1;
1646 if (*kc >= SIZEOF(attrs_to_test))
1650 wide_adjust_attr_string(-1);
1653 wide_adjust_attr_string(1);
1659 error = cycle_color_attr(ch, fg, bg, tx);
1668 wide_attr_test(void)
1669 /* test text attributes using wide-character calls */
1672 int skip = get_xmc();
1673 short fg = COLOR_BLACK; /* color pair 0 is special */
1674 short bg = COLOR_BLACK;
1682 n = skip; /* make it easy */
1683 k = SIZEOF(attrs_to_test) - 1;
1684 wide_init_attr_string();
1692 pair = (fg != COLOR_BLACK || bg != COLOR_BLACK);
1695 if (init_pair(pair, fg, bg) == ERR) {
1702 if (init_pair(extras, tx, bg) == ERR) {
1707 set_wide_background(pair);
1710 box_set(stdscr, 0, 0);
1711 mvaddstr(0, 20, "Character attribute test display");
1713 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1714 row = wide_show_attr(row, n, j == k,
1716 attrs_to_test[j].attr |
1717 attrs_to_test[k].attr,
1719 attrs_to_test[j].name);
1723 "This terminal does %shave the magic-cookie glitch",
1724 get_xmc() > -1 ? "" : "not ");
1725 mvprintw(row + 1, 8, "Enter '?' for help.");
1726 show_color_attr(fg, bg, tx);
1727 printw(" ACS (%d)", ac != 0);
1730 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1732 set_wide_background(0);
1738 /****************************************************************************
1740 * Color support tests
1742 ****************************************************************************/
1744 static NCURSES_CONST char *the_color_names[] =
1765 show_color_name(int y, int x, int color, bool wide)
1767 if (move(y, x) != ERR) {
1772 sprintf(temp, "%02d", color);
1774 } else if (color >= 8) {
1775 sprintf(temp, "[%02d]", color);
1777 strcpy(temp, the_color_names[color]);
1779 printw("%-*.*s", width, width, temp);
1784 color_legend(WINDOW *helpwin)
1789 mvwprintw(helpwin, row++, col,
1792 mvwprintw(helpwin, row++, col,
1793 "Use up/down arrow to scroll through the display if it is");
1794 mvwprintw(helpwin, row++, col,
1795 "longer than one screen. Control/N and Control/P can be used");
1796 mvwprintw(helpwin, row++, col,
1797 "in place up up/down arrow. Use pageup/pagedown to scroll a");
1798 mvwprintw(helpwin, row++, col,
1799 "full screen; control/B and control/F can be used here.");
1801 mvwprintw(helpwin, row++, col,
1803 mvwprintw(helpwin, row++, col,
1804 " b/B toggle bold off/on");
1805 mvwprintw(helpwin, row++, col,
1806 " n/N toggle text/number on/off");
1807 mvwprintw(helpwin, row++, col,
1808 " w/W toggle width between 8/16 colors");
1811 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1813 /* generate a color test pattern */
1820 int grid_top = top + 3;
1821 int page_size = (LINES - grid_top);
1822 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1828 bool opt_bold = FALSE;
1829 bool opt_wide = FALSE;
1830 bool opt_nums = FALSE;
1833 if (pairs_max > COLOR_PAIRS)
1834 pairs_max = COLOR_PAIRS;
1839 /* this assumes an 80-column line */
1843 per_row = (COLORS > 8) ? 16 : 8;
1850 row_limit = (pairs_max + per_row - 1) / per_row;
1853 (void) printw("There are %d color pairs and %d colors\n",
1857 (void) mvprintw(top + 1, 0,
1858 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1861 opt_bold ? "on" : "off");
1863 /* show color names/numbers across the top */
1864 for (i = 0; i < per_row; i++)
1865 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
1867 /* show a grid of colors, with color names/ numbers on the left */
1868 for (i = (base_row * per_row); i < pairs_max; i++) {
1869 int row = grid_top + (i / per_row) - base_row;
1870 int col = (i % per_row + 1) * width;
1873 if (row >= 0 && move(row, col) != ERR) {
1874 short fg = i % COLORS;
1875 short bg = i / COLORS;
1877 init_pair(pair, fg, bg);
1878 attron((attr_t) COLOR_PAIR(pair));
1880 attron((attr_t) A_BOLD);
1883 sprintf(numbered, "{%02X}", i);
1886 printw("%-*.*s", width, width, hello);
1889 if ((i % per_row) == 0 && (i % COLORS) == 0) {
1890 show_color_name(row, 0, i / COLORS, opt_wide);
1898 switch (wGetchar(stdscr)) {
1915 set_color_test(opt_wide, FALSE);
1918 set_color_test(opt_wide, TRUE);
1922 if (base_row <= 0) {
1930 if (base_row + page_size >= row_limit) {
1939 if (base_row <= 0) {
1942 base_row -= (page_size - 1);
1950 if (base_row + page_size >= row_limit) {
1953 base_row += page_size - 1;
1954 if (base_row + page_size >= row_limit) {
1955 base_row = row_limit - page_size - 1;
1960 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1962 color_legend(helpwin);
1977 #if USE_WIDEC_SUPPORT
1978 /* generate a color test pattern */
1980 wide_color_test(void)
1986 int grid_top = top + 3;
1987 int page_size = (LINES - grid_top);
1988 int pairs_max = COLOR_PAIRS;
1994 bool opt_bold = FALSE;
1995 bool opt_wide = FALSE;
1996 bool opt_nums = FALSE;
2002 /* this assumes an 80-column line */
2006 per_row = (COLORS > 8) ? 16 : 8;
2013 row_limit = (pairs_max + per_row - 1) / per_row;
2016 (void) printw("There are %d color pairs and %d colors\n",
2020 (void) mvprintw(top + 1, 0,
2021 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2024 opt_bold ? "on" : "off");
2026 /* show color names/numbers across the top */
2027 for (i = 0; i < per_row; i++)
2028 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
2030 /* show a grid of colors, with color names/ numbers on the left */
2031 for (i = (base_row * per_row); i < pairs_max; i++) {
2032 int row = grid_top + (i / per_row) - base_row;
2033 int col = (i % per_row + 1) * width;
2036 if (row >= 0 && move(row, col) != ERR) {
2037 init_pair(pair, i % COLORS, i / COLORS);
2038 color_set(pair, NULL);
2040 attr_on((attr_t) A_BOLD, NULL);
2043 sprintf(numbered, "{%02X}", i);
2046 printw("%-*.*s", width, width, hello);
2047 attr_set(A_NORMAL, 0, NULL);
2049 if ((i % per_row) == 0 && (i % COLORS) == 0) {
2050 show_color_name(row, 0, i / COLORS, opt_wide);
2058 switch (c = wGetchar(stdscr)) {
2075 set_color_test(opt_wide, FALSE);
2078 set_color_test(opt_wide, TRUE);
2082 if (base_row <= 0) {
2090 if (base_row + page_size >= row_limit) {
2099 if (base_row <= 0) {
2102 base_row -= (page_size - 1);
2110 if (base_row + page_size >= row_limit) {
2113 base_row += page_size - 1;
2114 if (base_row + page_size >= row_limit) {
2115 base_row = row_limit - page_size - 1;
2120 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2122 color_legend(helpwin);
2136 #endif /* USE_WIDEC_SUPPORT */
2139 change_color(short current, int field, int value, int usebase)
2141 short red, green, blue;
2143 color_content(current, &red, &green, &blue);
2147 red = usebase ? red + value : value;
2150 green = usebase ? green + value : value;
2153 blue = usebase ? blue + value : value;
2157 if (init_color(current, red, green, blue) == ERR)
2162 init_all_colors(void)
2166 for (c = 0; c < COLORS; ++c)
2169 all_colors[c].green,
2170 all_colors[c].blue);
2173 #define scaled_rgb(n) ((255 * (n)) / 1000)
2177 /* display the color test pattern, without trying to edit colors */
2181 int this_c = 0, value = 0, field = 0;
2184 int page_size = (LINES - 6);
2189 for (i = 0; i < max_colors; i++)
2190 init_pair(i, COLOR_WHITE, i);
2192 mvprintw(LINES - 2, 0, "Number: %d", value);
2195 short red, green, blue;
2198 mvaddstr(0, 20, "Color RGB Value Editing");
2202 (i - top_color < page_size)
2203 && (i < max_colors); i++) {
2206 sprintf(numeric, "[%d]", i);
2207 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2208 (i == current ? '>' : ' '),
2209 (i < (int) SIZEOF(the_color_names)
2210 ? the_color_names[i] : numeric));
2211 attrset(COLOR_PAIR(i));
2215 color_content(i, &red, &green, &blue);
2217 if (current == i && field == 0)
2219 printw("%04d", red);
2220 if (current == i && field == 0)
2223 if (current == i && field == 1)
2225 printw("%04d", green);
2226 if (current == i && field == 1)
2229 if (current == i && field == 2)
2231 printw("%04d", blue);
2232 if (current == i && field == 2)
2235 printw(" ( %3d %3d %3d )",
2241 mvaddstr(LINES - 3, 0,
2242 "Use up/down to select a color, left/right to change fields.");
2243 mvaddstr(LINES - 2, 0,
2244 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2246 move(2 + current - top_color, 0);
2250 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2257 current -= (page_size - 1);
2264 if (current < (max_colors - 1))
2265 current += (page_size - 1);
2272 current = (current == 0 ? (max_colors - 1) : current - 1);
2277 current = (current == (max_colors - 1) ? 0 : current + 1);
2281 field = (field == 2 ? 0 : field + 1);
2285 field = (field == 0 ? 2 : field - 1);
2298 value = value * 10 + (this_c - '0');
2302 change_color(current, field, value, 1);
2306 change_color(current, field, -value, 1);
2310 change_color(current, field, value, 0);
2315 P(" RGB Value Editing Help");
2317 P("You are in the RGB value editor. Use the arrow keys to select one of");
2318 P("the fields in one of the RGB triples of the current colors; the one");
2319 P("currently selected will be reverse-video highlighted.");
2321 P("To change a field, enter the digits of the new value; they are echoed");
2322 P("as entered. Finish by typing `='. The change will take effect instantly.");
2323 P("To increment or decrement a value, use the same procedure, but finish");
2324 P("with a `+' or `-'.");
2326 P("Press 'm' to invoke the top-level menu with the current color settings.");
2327 P("To quit, do ESC");
2349 if (current >= max_colors)
2350 current = max_colors - 1;
2351 if (current < top_color)
2352 top_color = current;
2353 if (current - top_color >= page_size)
2354 top_color = current - (page_size - 1);
2356 mvprintw(LINES - 1, 0, "Number: %d", value);
2364 * ncurses does not reset each color individually when calling endwin().
2371 /****************************************************************************
2373 * Soft-key label test
2375 ****************************************************************************/
2380 #define SLK_WORK (SLK_HELP + 3)
2385 static const char *table[] =
2387 "Available commands are:"
2389 ,"^L -- repaint this message and activate soft keys"
2390 ,"a/d -- activate/disable soft keys"
2391 ,"c -- set centered format for labels"
2392 ,"l -- set left-justified format for labels"
2393 ,"r -- set right-justified format for labels"
2394 ,"[12345678] -- set label; labels are numbered 1 through 8"
2395 ,"e -- erase stdscr (should not erase labels)"
2396 ,"s -- test scrolling of shortened screen"
2398 ,"F/B -- cycle through foreground/background colors"
2400 ,"ESC -- return to main menu"
2402 ,"Note: if activating the soft keys causes your terminal to scroll up"
2403 ,"one line, your terminal auto-scrolls when anything is written to the"
2404 ,"last screen position. The ncurses code does not yet handle this"
2410 for (j = 0; j < SIZEOF(table); ++j) {
2418 call_slk_color(short fg, short bg)
2420 init_pair(1, bg, fg);
2422 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2430 /* exercise the soft keys */
2436 short fg = COLOR_BLACK;
2437 short bg = COLOR_WHITE;
2443 call_slk_color(fg, bg);
2453 mvaddstr(0, 20, "Soft Key Exerciser");
2468 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2469 while ((c = Getchar()) != 'Q' && (c != ERR))
2497 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2499 if ((s = slk_label(c - '0')) != 0) {
2502 wGetstring(stdscr, buf, 8);
2503 slk_set((c - '0'), buf, fmt);
2515 fg = (fg + 1) % COLORS;
2516 call_slk_color(fg, bg);
2521 bg = (bg + 1) % COLORS;
2522 call_slk_color(fg, bg);
2526 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2534 } while (!isQuit(c = Getchar()));
2542 #if USE_WIDEC_SUPPORT
2546 /* exercise the soft keys */
2549 wchar_t buf[SLKLEN + 1];
2551 short fg = COLOR_BLACK;
2552 short bg = COLOR_WHITE;
2556 call_slk_color(fg, bg);
2563 attr_on(WA_BOLD, NULL);
2564 mvaddstr(0, 20, "Soft Key Exerciser");
2565 attr_off(WA_BOLD, NULL);
2579 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2580 while ((c = Getchar()) != 'Q' && (c != ERR))
2608 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2610 if ((s = slk_label(c - '0')) != 0) {
2611 char *temp = strdup(s);
2612 size_t used = strlen(temp);
2613 size_t want = SLKLEN;
2618 while (want > 0 && used != 0) {
2619 const char *base = s;
2620 memset(&state, 0, sizeof(state));
2621 test = mbsrtowcs(0, &base, 0, &state);
2622 if (test == (size_t) -1) {
2624 } else if (test > want) {
2627 memset(&state, 0, sizeof(state));
2628 mbsrtowcs(buf, &base, want, &state);
2634 wGet_wstring(stdscr, buf, SLKLEN);
2635 slk_wset((c - '0'), buf, fmt);
2646 fg = (fg + 1) % COLORS;
2647 call_slk_color(fg, bg);
2652 bg = (bg + 1) % COLORS;
2653 call_slk_color(fg, bg);
2656 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2663 } while (!isQuit(c = Getchar()));
2671 #endif /* SLK_INIT */
2673 /****************************************************************************
2675 * Alternate character-set stuff
2677 ****************************************************************************/
2679 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2680 * terminal to perform functions. The remaining codes can be graphic.
2683 show_upper_chars(unsigned first)
2685 bool C1 = (first == 128);
2687 unsigned last = first + 31;
2692 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2693 C1 ? "C1" : "GR", first, last);
2697 for (code = first; code <= last; code++) {
2698 int row = 2 + ((code - first) % 16);
2699 int col = ((code - first) / 16) * COLS / 2;
2701 sprintf(tmp, "%3u (0x%x)", code, code);
2702 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2704 nodelay(stdscr, TRUE);
2707 /* (yes, this _is_ crude) */
2708 while ((reply = Getchar()) != ERR) {
2709 addch(UChar(reply));
2712 nodelay(stdscr, FALSE);
2724 mvprintw(0, 20, "Display of PC Character Codes");
2728 for (code = 0; code < 16; ++code) {
2729 mvprintw(2, (int) code * 3 + 8, "%X", code);
2731 for (code = 0; code < 256; code++) {
2732 int row = 3 + (code / 16) + (code >= 128);
2733 int col = 8 + (code % 16) * 3;
2734 if ((code % 16) == 0)
2735 mvprintw(row, 0, "0x%02x:", code);
2745 * Skip the ones that do not work.
2749 addch(code | A_ALTCHARSET);
2756 show_box_chars(void)
2760 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
2765 mvhline(LINES / 2, 0, ACS_HLINE, COLS);
2766 mvvline(0, COLS / 2, ACS_VLINE, LINES);
2767 mvaddch(0, COLS / 2, ACS_TTEE);
2768 mvaddch(LINES / 2, COLS / 2, ACS_PLUS);
2769 mvaddch(LINES - 1, COLS / 2, ACS_BTEE);
2770 mvaddch(LINES / 2, 0, ACS_LTEE);
2771 mvaddch(LINES / 2, COLS - 1, ACS_RTEE);
2777 show_1_acs(int n, const char *name, chtype code)
2779 const int height = 16;
2780 int row = 2 + (n % height);
2781 int col = (n / height) * COLS / 2;
2782 mvprintw(row, col, "%*s : ", COLS / 4, name);
2788 show_acs_chars(void)
2789 /* display the ACS character set */
2793 #define BOTH(name) #name, name
2797 mvaddstr(0, 20, "Display of the ACS Character Set");
2801 n = show_1_acs(0, BOTH(ACS_ULCORNER));
2802 n = show_1_acs(n, BOTH(ACS_URCORNER));
2803 n = show_1_acs(n, BOTH(ACS_LLCORNER));
2804 n = show_1_acs(n, BOTH(ACS_LRCORNER));
2806 n = show_1_acs(n, BOTH(ACS_LTEE));
2807 n = show_1_acs(n, BOTH(ACS_RTEE));
2808 n = show_1_acs(n, BOTH(ACS_TTEE));
2809 n = show_1_acs(n, BOTH(ACS_BTEE));
2811 n = show_1_acs(n, BOTH(ACS_HLINE));
2812 n = show_1_acs(n, BOTH(ACS_VLINE));
2815 * HPUX's ACS definitions are broken here. Just give up.
2817 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
2818 n = show_1_acs(n, BOTH(ACS_LARROW));
2819 n = show_1_acs(n, BOTH(ACS_RARROW));
2820 n = show_1_acs(n, BOTH(ACS_UARROW));
2821 n = show_1_acs(n, BOTH(ACS_DARROW));
2823 n = show_1_acs(n, BOTH(ACS_BLOCK));
2824 n = show_1_acs(n, BOTH(ACS_BOARD));
2825 n = show_1_acs(n, BOTH(ACS_LANTERN));
2826 n = show_1_acs(n, BOTH(ACS_BULLET));
2827 n = show_1_acs(n, BOTH(ACS_CKBOARD));
2828 n = show_1_acs(n, BOTH(ACS_DEGREE));
2829 n = show_1_acs(n, BOTH(ACS_DIAMOND));
2830 n = show_1_acs(n, BOTH(ACS_PLMINUS));
2831 n = show_1_acs(n, BOTH(ACS_PLUS));
2833 n = show_1_acs(n, BOTH(ACS_GEQUAL));
2834 n = show_1_acs(n, BOTH(ACS_NEQUAL));
2835 n = show_1_acs(n, BOTH(ACS_LEQUAL));
2837 n = show_1_acs(n, BOTH(ACS_STERLING));
2838 n = show_1_acs(n, BOTH(ACS_PI));
2839 n = show_1_acs(n, BOTH(ACS_S1));
2840 n = show_1_acs(n, BOTH(ACS_S3));
2841 n = show_1_acs(n, BOTH(ACS_S7));
2842 n = show_1_acs(n, BOTH(ACS_S9));
2850 char *term = getenv("TERM");
2851 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
2870 show_upper_chars((unsigned) ((c - '0') * 32 + 128));
2879 mvprintw(LINES - 3, 0,
2880 "Note: ANSI terminals may not display C1 characters.");
2881 mvprintw(LINES - 2, 0,
2882 "Select: a=ACS, x=box, %s0=C1, 1,2,3=GR characters, ESC=quit",
2885 } while (!isQuit(c = Getchar()));
2892 #if USE_WIDEC_SUPPORT
2894 merge_wide_attr(cchar_t *dst, cchar_t *src, attr_t attr, short pair)
2896 int count = getcchar(src, NULL, NULL, NULL, 0);
2903 if ((wch = typeMalloc(wchar_t, count)) != 0) {
2904 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
2905 attr |= (ignore_attr & A_ALTCHARSET);
2906 setcchar(dst, wch, attr, pair, 0);
2915 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
2919 int last = first + 31;
2923 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
2926 for (code = first; code <= last; code++) {
2927 int row = 2 + ((code - first) % 16);
2928 int col = ((code - first) / 16) * COLS / 2;
2934 memset(&codes, 0, sizeof(codes));
2936 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
2937 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2938 setcchar(&temp, codes, attr, pair, 0);
2941 * Give non-spacing characters something to combine with. If we
2942 * don't, they'll bunch up in a heap on the space after the ":".
2943 * Mark them with reverse-video to make them simpler to find on
2946 if (wcwidth(code) == 0)
2947 addch(space | A_REVERSE);
2949 * This could use add_wch(), but is done for comparison with the
2950 * normal 'f' test (and to make a test-case for echo_wchar()).
2951 * The screen will flicker because the erase() at the top of the
2952 * function is met by the builtin refresh() in echo_wchar().
2956 * The repeat-count may make text wrap - avoid that.
2958 getyx(stdscr, y, x);
2959 if (x >= col + (COLS / 2) - 2)
2961 } while (--count > 0);
2966 show_1_wacs(int n, const char *name, const cchar_t *code)
2968 const int height = 16;
2969 int row = 2 + (n % height);
2970 int col = (n / height) * COLS / 2;
2971 mvprintw(row, col, "%*s : ", COLS / 4, name);
2972 add_wchnstr(code, 1);
2976 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
2979 show_wacs_chars(attr_t attr, short pair)
2980 /* display the wide-ACS character set */
2986 /*#define BOTH2(name) #name, &(name) */
2987 #define BOTH2(name) #name, MERGE_ATTR(name)
2991 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
2995 n = show_1_wacs(0, BOTH2(WACS_ULCORNER));
2996 n = show_1_wacs(n, BOTH2(WACS_URCORNER));
2997 n = show_1_wacs(n, BOTH2(WACS_LLCORNER));
2998 n = show_1_wacs(n, BOTH2(WACS_LRCORNER));
3000 n = show_1_wacs(n, BOTH2(WACS_LTEE));
3001 n = show_1_wacs(n, BOTH2(WACS_RTEE));
3002 n = show_1_wacs(n, BOTH2(WACS_TTEE));
3003 n = show_1_wacs(n, BOTH2(WACS_BTEE));
3005 n = show_1_wacs(n, BOTH2(WACS_HLINE));
3006 n = show_1_wacs(n, BOTH2(WACS_VLINE));
3008 n = show_1_wacs(n, BOTH2(WACS_LARROW));
3009 n = show_1_wacs(n, BOTH2(WACS_RARROW));
3010 n = show_1_wacs(n, BOTH2(WACS_UARROW));
3011 n = show_1_wacs(n, BOTH2(WACS_DARROW));
3013 n = show_1_wacs(n, BOTH2(WACS_BLOCK));
3014 n = show_1_wacs(n, BOTH2(WACS_BOARD));
3015 n = show_1_wacs(n, BOTH2(WACS_LANTERN));
3016 n = show_1_wacs(n, BOTH2(WACS_BULLET));
3017 n = show_1_wacs(n, BOTH2(WACS_CKBOARD));
3018 n = show_1_wacs(n, BOTH2(WACS_DEGREE));
3019 n = show_1_wacs(n, BOTH2(WACS_DIAMOND));
3020 n = show_1_wacs(n, BOTH2(WACS_PLMINUS));
3021 n = show_1_wacs(n, BOTH2(WACS_PLUS));
3023 #ifdef CURSES_WACS_ARRAY
3024 n = show_1_wacs(n, BOTH2(WACS_GEQUAL));
3025 n = show_1_wacs(n, BOTH2(WACS_NEQUAL));
3026 n = show_1_wacs(n, BOTH2(WACS_LEQUAL));
3028 n = show_1_wacs(n, BOTH2(WACS_STERLING));
3029 n = show_1_wacs(n, BOTH2(WACS_PI));
3030 n = show_1_wacs(n, BOTH2(WACS_S1));
3031 n = show_1_wacs(n, BOTH2(WACS_S3));
3032 n = show_1_wacs(n, BOTH2(WACS_S7));
3033 n = show_1_wacs(n, BOTH2(WACS_S9));
3039 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3042 show_wbox_chars(attr_t attr, short pair)
3048 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3052 attr_set(attr, pair, 0);
3053 box_set(stdscr, 0, 0);
3054 attr_set(A_NORMAL, 0, 0);
3056 mvhline_set(LINES / 2, 0, MERGE_ATTR(WACS_HLINE), COLS);
3057 mvvline_set(0, COLS / 2, MERGE_ATTR(WACS_VLINE), LINES);
3058 mvadd_wch(0, COLS / 2, MERGE_ATTR(WACS_TTEE));
3059 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(WACS_PLUS));
3060 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(WACS_BTEE));
3061 mvadd_wch(LINES / 2, 0, MERGE_ATTR(WACS_LTEE));
3062 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(WACS_RTEE));
3070 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3072 const int height = 16;
3073 int row = 2 + (n % height);
3074 int col = (n / height) * COLS / 2;
3077 mvprintw(row, col, "%*s : ", COLS / 4, name);
3078 attr_set(attr, pair, 0);
3079 addstr(strcpy(temp, code));
3080 attr_set(A_NORMAL, 0, 0);
3084 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3087 show_utf8_chars(attr_t attr, short pair)
3093 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3097 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3098 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3099 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3100 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3102 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3103 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3104 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3105 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3107 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3108 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3110 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3111 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3112 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3113 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3115 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3116 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3117 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3118 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3119 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3120 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3121 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3122 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3123 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3124 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3125 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3126 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3128 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3129 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3130 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3131 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3132 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3133 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3141 } attrs_to_cycle[] = {
3142 { A_NORMAL, "normal" },
3144 { A_REVERSE, "reverse" },
3145 { A_UNDERLINE, "underline" },
3150 cycle_attr(int ch, unsigned *at_code, chtype *attr)
3156 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
3161 *at_code = SIZEOF(attrs_to_cycle) - 1;
3170 *attr = attrs_to_cycle[*at_code].attr;
3175 cycle_colors(int ch, int *fg, int *bg, short *pair)
3177 bool result = FALSE;
3187 if ((*fg += 1) >= COLORS)
3203 *pair = (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3206 if (init_pair(*pair, *fg, *bg) == ERR) {
3215 /* display the wide-ACS character set */
3217 wide_acs_display(void)
3223 chtype attr = A_NORMAL;
3224 int fg = COLOR_BLACK;
3225 int bg = COLOR_BLACK;
3226 unsigned at_code = 0;
3228 void (*last_show_wacs) (attr_t, short) = 0;
3236 last_show_wacs = show_wacs_chars;
3239 last_show_wacs = show_wbox_chars;
3242 last_show_wacs = show_utf8_chars;
3245 if (c < 256 && isdigit(c)) {
3247 } else if (c == '+') {
3249 } else if (c == '-' && digit > 0) {
3251 } else if (c == '>' && repeat < (COLS / 4)) {
3253 } else if (c == '<' && repeat > 0) {
3255 } else if (c == '_') {
3256 space = (space == ' ') ? '_' : ' ';
3257 } else if (cycle_attr(c, &at_code, &attr)
3258 || cycle_colors(c, &fg, &bg, &pair)) {
3259 if (last_show_wacs != 0)
3266 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3269 if (last_show_wacs != 0)
3270 last_show_wacs(attr, pair);
3272 mvprintw(LINES - 3, 0,
3273 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3275 mvprintw(LINES - 2, 0,
3276 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3277 attrs_to_cycle[at_code].name,
3280 mvprintw(LINES - 2, 0,
3281 "v/V cycles through video attributes (%s).",
3282 attrs_to_cycle[at_code].name);
3285 } while (!isQuit(c = Getchar()));
3295 * Graphic-rendition test (adapted from vttest)
3298 test_sgr_attributes(void)
3302 for (pass = 0; pass < 2; pass++) {
3303 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3305 /* Use non-default colors if possible to exercise bce a little */
3307 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3308 normal |= COLOR_PAIR(1);
3312 mvprintw(1, 20, "Graphic rendition test pattern:");
3314 mvprintw(4, 1, "vanilla");
3316 #define set_sgr(mask) bkgdset((normal^(mask)));
3318 mvprintw(4, 40, "bold");
3320 set_sgr(A_UNDERLINE);
3321 mvprintw(6, 6, "underline");
3323 set_sgr(A_BOLD | A_UNDERLINE);
3324 mvprintw(6, 45, "bold underline");
3327 mvprintw(8, 1, "blink");
3329 set_sgr(A_BLINK | A_BOLD);
3330 mvprintw(8, 40, "bold blink");
3332 set_sgr(A_UNDERLINE | A_BLINK);
3333 mvprintw(10, 6, "underline blink");
3335 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3336 mvprintw(10, 45, "bold underline blink");
3339 mvprintw(12, 1, "negative");
3341 set_sgr(A_BOLD | A_REVERSE);
3342 mvprintw(12, 40, "bold negative");
3344 set_sgr(A_UNDERLINE | A_REVERSE);
3345 mvprintw(14, 6, "underline negative");
3347 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3348 mvprintw(14, 45, "bold underline negative");
3350 set_sgr(A_BLINK | A_REVERSE);
3351 mvprintw(16, 1, "blink negative");
3353 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3354 mvprintw(16, 40, "bold blink negative");
3356 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3357 mvprintw(18, 6, "underline blink negative");
3359 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3360 mvprintw(18, 45, "bold underline blink negative");
3363 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3369 bkgdset(A_NORMAL | BLANK);
3374 /****************************************************************************
3376 * Windows and scrolling tester.
3378 ****************************************************************************/
3380 #define BOTLINES 4 /* number of line stolen from screen bottom */
3386 #define FRAME struct frame
3395 #if defined(NCURSES_VERSION)
3396 #if NCURSES_VERSION_PATCH < 20070331
3397 #define is_keypad(win) (win)->_use_keypad
3398 #define is_scrollok(win) (win)->_scroll
3401 #define is_keypad(win) FALSE
3402 #define is_scrollok(win) FALSE
3405 /* We need to know if these flags are actually set, so don't look in FRAME.
3406 * These names are known to work with SVr4 curses as well as ncurses. The
3407 * _use_keypad name does not work with Solaris 8.
3410 HaveKeypad(FRAME * curp)
3412 WINDOW *win = (curp ? curp->wind : stdscr);
3414 return is_keypad(win);
3418 HaveScroll(FRAME * curp)
3420 WINDOW *win = (curp ? curp->wind : stdscr);
3422 return is_scrollok(win);
3426 newwin_legend(FRAME * curp)
3428 static const struct {
3433 "^C = create window", 0
3436 "^N = next window", 0
3439 "^P = previous window", 0
3442 "^F = scroll forward", 0
3445 "^B = scroll backward", 0
3448 "^K = keypad(%s)", 1
3451 "^S = scrollok(%s)", 2
3454 "^W = save window to file", 0
3457 "^R = restore window", 0
3470 bool do_keypad = HaveKeypad(curp);
3471 bool do_scroll = HaveScroll(curp);
3475 for (n = 0; n < SIZEOF(legend); n++) {
3476 switch (legend[n].code) {
3478 strcpy(buf, legend[n].msg);
3481 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3484 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3487 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3490 x = getcurx(stdscr);
3491 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3498 transient(FRAME * curp, NCURSES_CONST char *msg)
3500 newwin_legend(curp);
3502 mvaddstr(LINES - 1, 0, msg);
3508 printw("%s characters are echoed, window should %sscroll.",
3509 HaveKeypad(curp) ? "Non-arrow" : "All other",
3510 HaveScroll(curp) ? "" : "not ");
3515 newwin_report(FRAME * curp)
3516 /* report on the cursor's current position, then restore it */
3518 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
3522 transient(curp, (char *) 0);
3524 move(LINES - 1, COLS - 17);
3525 printw("Y = %2d X = %2d", y, x);
3533 selectcell(int uli, int ulj, int lri, int lrj)
3534 /* arrows keys move cursor, return location at current on non-arrow key */
3536 static pair res; /* result cell */
3537 int si = lri - uli + 1; /* depth of the select area */
3538 int sj = lrj - ulj + 1; /* width of the select area */
3539 int i = 0, j = 0; /* offsets into the select area */
3544 move(uli + i, ulj + j);
3545 newwin_report((FRAME *) 0);
3547 switch (Getchar()) {
3561 return ((pair *) 0);
3562 #ifdef NCURSES_MOUSE_VERSION
3568 if (event.y > uli && event.x > ulj) {
3589 outerbox(pair ul, pair lr, bool onoff)
3590 /* draw or erase a box *outside* the given pair of corners */
3592 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3593 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3594 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3595 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3596 move(ul.y - 1, ul.x);
3597 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3598 move(ul.y, ul.x - 1);
3599 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3600 move(lr.y + 1, ul.x);
3601 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3602 move(ul.y, lr.x + 1);
3603 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3608 /* Ask user for a window definition */
3615 addstr("Use arrows to move cursor, anything else to mark corner 1");
3617 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3618 return ((WINDOW *) 0);
3619 memcpy(&ul, tmp, sizeof(pair));
3620 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3623 addstr("Use arrows to move cursor, anything else to mark corner 2");
3625 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
3627 return ((WINDOW *) 0);
3628 memcpy(&lr, tmp, sizeof(pair));
3630 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
3632 outerbox(ul, lr, TRUE);
3643 newwin_move(FRAME * curp, int dy, int dx)
3645 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
3649 getyx(win, cur_y, cur_x);
3650 getmaxyx(win, max_y, max_x);
3651 if ((cur_x += dx) < 0)
3653 else if (cur_x >= max_x)
3655 if ((cur_y += dy) < 0)
3657 else if (cur_y >= max_y)
3659 wmove(win, cur_y, cur_x);
3663 delete_framed(FRAME * fp, bool showit)
3667 fp->last->next = fp->next;
3668 fp->next->last = fp->last;
3676 np = (fp == fp->next) ? 0 : fp->next;
3682 acs_and_scroll(void)
3683 /* Demonstrate windows */
3686 FRAME *current = (FRAME *) 0, *neww;
3687 WINDOW *usescr = stdscr;
3688 #if HAVE_PUTWIN && HAVE_GETWIN
3692 #define DUMPFILE "screendump"
3694 #ifdef NCURSES_MOUSE_VERSION
3695 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
3700 transient((FRAME *) 0, (char *) 0);
3703 neww = (FRAME *) calloc(1, sizeof(FRAME));
3704 if ((neww->wind = getwindow()) == (WINDOW *) 0)
3707 if (current == 0) { /* First element, */
3708 neww->next = neww; /* so point it at itself */
3711 neww->next = current->next;
3712 neww->last = current;
3713 neww->last->next = neww;
3714 neww->next->last = neww;
3717 /* SVr4 curses sets the keypad on all newly-created windows to
3718 * false. Someone reported that PDCurses makes new windows inherit
3719 * this flag. Remove the following 'keypad()' call to test this
3721 keypad(current->wind, TRUE);
3722 current->do_keypad = HaveKeypad(current);
3723 current->do_scroll = HaveScroll(current);
3726 case CTRL('N'): /* go to next window */
3728 current = current->next;
3731 case CTRL('P'): /* go to previous window */
3733 current = current->last;
3736 case CTRL('F'): /* scroll current window forward */
3738 wscrl(current->wind, 1);
3741 case CTRL('B'): /* scroll current window backwards */
3743 wscrl(current->wind, -1);
3746 case CTRL('K'): /* toggle keypad mode for current */
3748 current->do_keypad = !current->do_keypad;
3749 keypad(current->wind, current->do_keypad);
3755 current->do_scroll = !current->do_scroll;
3756 scrollok(current->wind, current->do_scroll);
3760 #if HAVE_PUTWIN && HAVE_GETWIN
3761 case CTRL('W'): /* save and delete window */
3762 if (current == current->next) {
3763 transient(current, "Will not save/delete ONLY window");
3765 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
3766 transient(current, "Can't open screen dump file");
3768 (void) putwin(current->wind, fp);
3771 current = delete_framed(current, TRUE);
3775 case CTRL('R'): /* restore window */
3776 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
3777 transient(current, "Can't open screen dump file");
3779 neww = (FRAME *) calloc(1, sizeof(FRAME));
3781 neww->next = current->next;
3782 neww->last = current;
3783 neww->last->next = neww;
3784 neww->next->last = neww;
3786 neww->wind = getwin(fp);
3789 wrefresh(neww->wind);
3795 case CTRL('X'): /* resize window */
3802 addstr("Use arrows to move cursor, anything else to mark new corner");
3805 getbegyx(current->wind, ul.y, ul.x);
3807 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
3808 if (tmp == (pair *) 0) {
3813 getmaxyx(current->wind, lr.y, lr.x);
3816 outerbox(ul, lr, FALSE);
3817 wnoutrefresh(stdscr);
3819 /* strictly cosmetic hack for the test */
3820 getmaxyx(current->wind, my, mx);
3821 if (my > tmp->y - ul.y) {
3822 getyx(current->wind, lr.y, lr.x);
3823 wmove(current->wind, tmp->y - ul.y + 1, 0);
3824 wclrtobot(current->wind);
3825 wmove(current->wind, lr.y, lr.x);
3827 if (mx > tmp->x - ul.x)
3828 for (i = 0; i < my; i++) {
3829 wmove(current->wind, i, tmp->x - ul.x + 1);
3830 wclrtoeol(current->wind);
3832 wnoutrefresh(current->wind);
3834 memcpy(&lr, tmp, sizeof(pair));
3835 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
3837 getbegyx(current->wind, ul.y, ul.x);
3838 getmaxyx(current->wind, lr.y, lr.x);
3841 outerbox(ul, lr, TRUE);
3842 wnoutrefresh(stdscr);
3844 wnoutrefresh(current->wind);
3850 #endif /* HAVE_WRESIZE */
3852 case KEY_F(10): /* undocumented --- use this to test area clears */
3853 selectcell(0, 0, LINES - 1, COLS - 1);
3859 newwin_move(current, -1, 0);
3862 newwin_move(current, 1, 0);
3865 newwin_move(current, 0, -1);
3868 newwin_move(current, 0, 1);
3876 getyx(current->wind, y, x);
3880 x = getmaxx(current->wind) - 1;
3882 mvwdelch(current->wind, y, x);
3892 waddch(current->wind, (chtype) c);
3897 newwin_report(current);
3898 usescr = (current ? current->wind : stdscr);
3901 (!isQuit(c = wGetchar(usescr))
3905 while (current != 0)
3906 current = delete_framed(current, FALSE);
3908 scrollok(stdscr, TRUE); /* reset to driver's default */
3909 #ifdef NCURSES_MOUSE_VERSION
3910 mousemask(0, (mmask_t *) 0);
3917 /****************************************************************************
3921 ****************************************************************************/
3924 static int nap_msec = 1;
3926 static NCURSES_CONST char *mod[] =
3936 /*+-------------------------------------------------------------------------
3938 --------------------------------------------------------------------------*/
3940 wait_a_while(int msec GCC_UNUSED)
3950 else if (msec > 1000)
3951 sleep((unsigned) msec / 1000);
3955 } /* end of wait_a_while */
3957 /*+-------------------------------------------------------------------------
3959 --------------------------------------------------------------------------*/
3961 saywhat(NCURSES_CONST char *text)
3963 wmove(stdscr, LINES - 1, 0);
3965 if (text != 0 && *text != '\0') {
3966 waddstr(stdscr, text);
3967 waddstr(stdscr, "; ");
3969 waddstr(stdscr, "press any key to continue");
3970 } /* end of saywhat */
3972 /*+-------------------------------------------------------------------------
3973 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
3974 --------------------------------------------------------------------------*/
3976 mkpanel(short color, int rows, int cols, int tly, int tlx)
3981 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
3982 if ((pan = new_panel(win)) == 0) {
3984 } else if (use_colors) {
3985 short fg = (color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK;
3988 init_pair(color, fg, bg);
3989 wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
3991 wbkgdset(win, A_BOLD | ' ');
3995 } /* end of mkpanel */
3997 /*+-------------------------------------------------------------------------
3999 --------------------------------------------------------------------------*/
4001 rmpanel(PANEL * pan)
4003 WINDOW *win = panel_window(pan);
4006 } /* end of rmpanel */
4008 /*+-------------------------------------------------------------------------
4010 --------------------------------------------------------------------------*/
4016 } /* end of pflush */
4018 /*+-------------------------------------------------------------------------
4020 --------------------------------------------------------------------------*/
4026 for (y = 0; y < LINES - 1; y++) {
4027 for (x = 0; x < COLS; x++)
4028 wprintw(stdscr, "%d", (y + x) % 10);
4033 fill_panel(PANEL * pan)
4035 WINDOW *win = panel_window(pan);
4036 int num = ((const char *) panel_userptr(pan))[1];
4040 wprintw(win, "-pan%c-", num);
4043 for (y = 2; y < getmaxy(win) - 1; y++) {
4044 for (x = 1; x < getmaxx(win) - 1; x++) {
4046 waddch(win, UChar(num));
4051 #if USE_WIDEC_SUPPORT
4053 make_fullwidth_digit(cchar_t *target, int digit)
4057 source[0] = digit + 0xff10;
4059 setcchar(target, source, A_NORMAL, 0, 0);
4063 init_wide_panel(void)
4068 for (digit = 0; digit < 10; ++digit)
4069 make_fullwidth_digit(&temp[digit], digit);
4073 getyx(stdscr, y, x);
4074 digit = (y + x / 2) % 10;
4075 } while (add_wch(&temp[digit]) != ERR);
4079 fill_wide_panel(PANEL * pan)
4081 WINDOW *win = panel_window(pan);
4082 int num = ((const char *) panel_userptr(pan))[1];
4086 wprintw(win, "-pan%c-", num);
4089 for (y = 2; y < getmaxy(win) - 1; y++) {
4090 for (x = 1; x < getmaxx(win) - 1; x++) {
4092 waddch(win, UChar(num));
4098 #define MAX_PANELS 5
4101 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4103 int which = cmd[1] - '0';
4108 hide_panel(px[which]);
4111 show_panel(px[which]);
4114 top_panel(px[which]);
4117 bottom_panel(px[which]);
4124 wait_a_while(nap_msec);
4128 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4132 PANEL *px[MAX_PANELS + 1];
4134 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4138 for (count = 0; count < 5; count++) {
4139 px[1] = mkpanel(COLOR_RED,
4144 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4146 px[2] = mkpanel(COLOR_GREEN,
4151 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4153 px[3] = mkpanel(COLOR_YELLOW,
4158 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4160 px[4] = mkpanel(COLOR_BLUE,
4165 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4167 px[5] = mkpanel(COLOR_MAGENTA,
4172 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4184 wait_a_while(nap_msec);
4186 saywhat("h3 s1 s2 s4 s5");
4187 move_panel(px[1], 0, 0);
4194 wait_a_while(nap_msec);
4196 canned_panel(px, "s1");
4197 canned_panel(px, "s2");
4200 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4202 wait_a_while(nap_msec);
4204 canned_panel(px, "s3");
4207 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4209 wait_a_while(nap_msec);
4211 canned_panel(px, "b3");
4212 canned_panel(px, "s4");
4213 canned_panel(px, "s5");
4214 canned_panel(px, "t3");
4215 canned_panel(px, "t1");
4216 canned_panel(px, "t2");
4217 canned_panel(px, "t3");
4218 canned_panel(px, "t4");
4220 for (itmp = 0; itmp < 6; itmp++) {
4221 WINDOW *w4 = panel_window(px[4]);
4222 WINDOW *w5 = panel_window(px[5]);
4225 wmove(w4, LINES / 8, 1);
4226 waddstr(w4, mod[itmp]);
4227 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4228 wmove(w5, LINES / 6, 1);
4229 waddstr(w5, mod[itmp]);
4231 wait_a_while(nap_msec);
4234 wmove(w4, LINES / 6, 1);
4235 waddstr(w4, mod[itmp]);
4236 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4237 wmove(w5, LINES / 8, 1);
4238 waddstr(w5, mod[itmp]);
4240 wait_a_while(nap_msec);
4244 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4246 wait_a_while(nap_msec);
4248 canned_panel(px, "t5");
4249 canned_panel(px, "t2");
4250 canned_panel(px, "t1");
4251 canned_panel(px, "d2");
4252 canned_panel(px, "h3");
4253 canned_panel(px, "d1");
4254 canned_panel(px, "d4");
4255 canned_panel(px, "d5");
4256 canned_panel(px, "d3");
4258 wait_a_while(nap_msec);
4267 #endif /* USE_LIBPANEL */
4269 /****************************************************************************
4273 ****************************************************************************/
4277 static bool pending_pan = FALSE;
4278 static bool show_panner_legend = TRUE;
4281 panner_legend(int line)
4283 static const char *const legend[] =
4285 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4286 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4287 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4288 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4290 int n = (SIZEOF(legend) - (LINES - line));
4291 if (line < LINES && (n >= 0)) {
4293 if (show_panner_legend)
4294 printw("%s", legend[n]);
4296 return show_panner_legend;
4302 panner_h_cleanup(int from_y, int from_x, int to_x)
4304 if (!panner_legend(from_y))
4305 do_h_line(from_y, from_x, ' ', to_x);
4309 panner_v_cleanup(int from_y, int from_x, int to_y)
4311 if (!panner_legend(from_y))
4312 do_v_line(from_y, from_x, ' ', to_y);
4316 fill_pad(WINDOW *panpad, bool pan_lines)
4319 unsigned gridcount = 0;
4321 wmove(panpad, 0, 0);
4322 for (y = 0; y < getmaxy(panpad); y++) {
4323 for (x = 0; x < getmaxx(panpad); x++) {
4324 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4325 if (y == 0 && x == 0)
4326 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4328 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4329 else if (y == 0 || x == 0)
4330 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4332 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4333 (gridcount++ % 26)));
4334 } else if (y % GRIDSIZE == 0)
4335 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4336 else if (x % GRIDSIZE == 0)
4337 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4339 waddch(panpad, ' ');
4346 int top_x, int top_y, int porty, int portx,
4347 int (*pgetc) (WINDOW *))
4349 #if HAVE_GETTIMEOFDAY
4350 struct timeval before, after;
4353 bool pan_lines = FALSE;
4354 bool scrollers = TRUE;
4357 int pxmax, pymax, lowend, highend, c;
4359 getmaxyx(pad, pymax, pxmax);
4360 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4364 #ifdef NCURSES_VERSION
4366 * During shell-out, the user may have resized the window. Adjust
4367 * the port size of the pad to accommodate this. Ncurses automatically
4368 * resizes all of the normal windows to fit on the new screen.
4386 show_panner_legend = !show_panner_legend;
4387 panner_legend(LINES - 4);
4388 panner_legend(LINES - 3);
4389 panner_legend(LINES - 2);
4390 panner_legend(LINES - 1);
4393 pan_lines = !pan_lines;
4394 fill_pad(pad, pan_lines);
4395 pending_pan = FALSE;
4398 #if HAVE_GETTIMEOFDAY
4402 panner_legend(LINES - 1);
4406 scrollers = !scrollers;
4409 /* Move the top-left corner of the pad, keeping the bottom-right
4412 case 'h': /* increase-columns: move left edge to left */
4416 panner_v_cleanup(top_y, top_x, porty);
4421 case 'j': /* decrease-lines: move top-edge down */
4425 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
4430 case 'k': /* increase-lines: move top-edge up */
4435 panner_h_cleanup(top_y, top_x, portx);
4439 case 'l': /* decrease-columns: move left-edge to right */
4443 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
4448 /* Move the bottom-right corner of the pad, keeping the top-left
4451 case KEY_IC: /* increase-columns: move right-edge to right */
4452 if (portx >= pxmax || portx >= COLS)
4455 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
4460 case KEY_IL: /* increase-lines: move bottom-edge down */
4461 if (porty >= pymax || porty >= LINES)
4464 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
4469 case KEY_DC: /* decrease-columns: move bottom edge up */
4474 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
4478 case KEY_DL: /* decrease-lines */
4483 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
4487 case KEY_LEFT: /* pan leftwards */
4494 case KEY_RIGHT: /* pan rightwards */
4495 if (basex + portx - (pymax > porty) < pxmax)
4501 case KEY_UP: /* pan upwards */
4508 case KEY_DOWN: /* pan downwards */
4509 if (basey + porty - (pxmax > portx) < pymax)
4524 basey = pymax - porty;
4534 mvaddch(top_y - 1, top_x - 1, ACS_ULCORNER);
4535 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
4536 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
4538 if (scrollers && (pxmax > portx - 1)) {
4539 int length = (portx - top_x - 1);
4540 float ratio = ((float) length) / ((float) pxmax);
4542 lowend = (int) (top_x + (basex * ratio));
4543 highend = (int) (top_x + ((basex + length) * ratio));
4545 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
4546 if (highend < portx) {
4548 do_h_line(porty - 1, lowend, ' ', highend + 1);
4550 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
4553 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
4555 if (scrollers && (pymax > porty - 1)) {
4556 int length = (porty - top_y - 1);
4557 float ratio = ((float) length) / ((float) pymax);
4559 lowend = (int) (top_y + (basey * ratio));
4560 highend = (int) (top_y + ((basey + length) * ratio));
4562 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
4563 if (highend < porty) {
4565 do_v_line(lowend, portx - 1, ' ', highend + 1);
4567 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
4570 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
4572 mvaddch(top_y - 1, portx - 1, ACS_URCORNER);
4573 mvaddch(porty - 1, top_x - 1, ACS_LLCORNER);
4574 mvaddch(porty - 1, portx - 1, ACS_LRCORNER);
4577 #if HAVE_GETTIMEOFDAY
4578 gettimeofday(&before, 0);
4580 wnoutrefresh(stdscr);
4585 porty - (pxmax > portx) - 1,
4586 portx - (pymax > porty) - 1);
4589 #if HAVE_GETTIMEOFDAY
4592 gettimeofday(&after, 0);
4593 elapsed = (after.tv_sec + after.tv_usec / 1.0e6)
4594 - (before.tv_sec + before.tv_usec / 1.0e6);
4595 move(LINES - 1, COLS - 12);
4596 printw("Secs: %2.03f", elapsed);
4603 ((c = pgetc(pad)) != KEY_EXIT);
4605 scrollok(stdscr, TRUE); /* reset to driver's default */
4609 padgetch(WINDOW *win)
4615 if ((pending_pan = (count > 0)) != FALSE) {
4617 pending_pan = (count != 0);
4620 switch (c = wGetchar(win)) {
4656 case ERR: /* FALLTHRU */
4662 if (c >= '0' && c <= '9') {
4663 count = count * 10 + (c - '0');
4677 #define PAD_HIGH 200
4678 #define PAD_WIDE 200
4682 /* Demonstrate pads. */
4684 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
4687 Cannot("cannot create requested pad");
4691 fill_pad(panpad, FALSE);
4693 panner_legend(LINES - 4);
4694 panner_legend(LINES - 3);
4695 panner_legend(LINES - 2);
4696 panner_legend(LINES - 1);
4698 keypad(panpad, TRUE);
4700 /* Make the pad (initially) narrow enough that a trace file won't wrap.
4701 * We'll still be able to widen it during a test, since that's required
4702 * for testing boundaries.
4704 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
4711 /****************************************************************************
4713 * Tests from John Burnell's PDCurses tester
4715 ****************************************************************************/
4718 Continue(WINDOW *win)
4722 mvwaddstr(win, 10, 1, " Press any key to continue");
4728 flushinp_test(WINDOW *win)
4729 /* Input test, adapted from John Burnell's PDCurses tester */
4731 int w, h, bx, by, sw, sh, i;
4736 getmaxyx(win, h, w);
4737 getbegyx(win, by, bx);
4740 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
4745 init_pair(2, COLOR_CYAN, COLOR_BLUE);
4746 wbkgd(subWin, COLOR_PAIR(2) | ' ');
4749 wattrset(subWin, A_BOLD);
4750 box(subWin, ACS_VLINE, ACS_HLINE);
4751 mvwaddstr(subWin, 2, 1, "This is a subwindow");
4755 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
4756 * it only happened to "work" on SVr4 because that implementation does not
4757 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
4758 * test behavior, we're using 'cbreak()', which will allow a single
4759 * character to return without needing a newline. - T.Dickey 1997/10/11.
4762 mvwaddstr(win, 0, 1, "This is a test of the flushinp() call.");
4764 mvwaddstr(win, 2, 1, "Type random keys for 5 seconds.");
4765 mvwaddstr(win, 3, 1,
4766 "These should be discarded (not echoed) after the subwindow goes away.");
4769 for (i = 0; i < 5; i++) {
4770 mvwprintw(subWin, 1, 1, "Time = %d", i);
4782 mvwaddstr(win, 2, 1,
4783 "If you were still typing when the window timer expired,");
4784 mvwaddstr(win, 3, 1,
4785 "or else you typed nothing at all while it was running,");
4786 mvwaddstr(win, 4, 1,
4787 "test was invalid. You'll see garbage or nothing at all. ");
4788 mvwaddstr(win, 6, 1, "Press a key");
4794 mvwaddstr(win, 12, 0,
4795 "If you see any key other than what you typed, flushinp() is broken.");
4804 "What you typed should now have been deleted; if not, wdelch() failed.");
4810 /****************************************************************************
4814 ****************************************************************************/
4822 menu_virtualize(int c)
4824 if (c == '\n' || c == KEY_EXIT)
4825 return (MAX_COMMAND + 1);
4827 return (REQ_SCR_ULINE);
4829 return (REQ_SCR_DLINE);
4830 else if (c == 'b' || c == KEY_NPAGE)
4831 return (REQ_SCR_UPAGE);
4832 else if (c == 'f' || c == KEY_PPAGE)
4833 return (REQ_SCR_DPAGE);
4834 else if (c == 'n' || c == KEY_DOWN)
4835 return (REQ_NEXT_ITEM);
4836 else if (c == 'p' || c == KEY_UP)
4837 return (REQ_PREV_ITEM);
4839 return (REQ_TOGGLE_ITEM);
4847 static const char *animals[] =
4860 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
4861 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
4869 ITEM *items[SIZEOF(animals)];
4872 int mrows, mcols, c;
4875 #ifdef NCURSES_MOUSE_VERSION
4876 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
4878 mvaddstr(0, 0, "This is the menu test:");
4879 mvaddstr(2, 0, " Use up and down arrow to move the select bar.");
4880 mvaddstr(3, 0, " 'n' and 'p' act like arrows.");
4882 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
4883 mvaddstr(5, 0, " Press return to exit.");
4886 for (ap = animals; *ap; ap++)
4887 *ip++ = new_item(*ap, "");
4890 m = new_menu(items);
4892 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
4893 scale_menu(m, &mrows, &mcols);
4895 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
4896 set_menu_win(m, menuwin);
4897 keypad(menuwin, TRUE);
4900 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
4904 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
4905 if (c == E_NOT_POSTED)
4907 if (c == E_REQUEST_DENIED)
4912 (void) mvprintw(LINES - 2, 0,
4913 "You chose: %s\n", item_name(current_item(m)));
4914 (void) addstr("Press any key to continue...");
4921 for (ip = items; *ip; ip++)
4923 #ifdef NCURSES_MOUSE_VERSION
4924 mousemask(0, (mmask_t *) 0);
4929 #define T_TBL(name) { #name, name }
4935 T_TBL(TRACE_DISABLE),
4938 T_TBL(TRACE_UPDATE),
4940 T_TBL(TRACE_CHARPUT),
4941 T_TBL(TRACE_ORDINARY),
4943 T_TBL(TRACE_VIRTPUT),
4944 T_TBL(TRACE_IEVENT),
4946 T_TBL(TRACE_ICALLS),
4947 T_TBL(TRACE_CCALLS),
4948 T_TBL(TRACE_DATABASE),
4950 T_TBL(TRACE_MAXIMUM),
4957 tracetrace(unsigned tlevel)
4964 for (n = 0; t_tbl[n].name != 0; n++)
4965 need += strlen(t_tbl[n].name) + 2;
4966 buf = (char *) malloc(need);
4968 sprintf(buf, "0x%02x = {", tlevel);
4970 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
4972 for (n = 1; t_tbl[n].name != 0; n++)
4973 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
4974 strcat(buf, t_tbl[n].name);
4978 if (buf[strlen(buf) - 2] == ',')
4979 buf[strlen(buf) - 2] = '\0';
4980 return (strcat(buf, "}"));
4983 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
4987 run_trace_menu(MENU * m)
4993 bool changed = FALSE;
4994 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
4995 case E_UNKNOWN_COMMAND:
4998 items = menu_items(m);
4999 i = current_item(m);
5000 if (i == items[0]) {
5001 if (item_value(i)) {
5002 for (p = items + 1; *p != 0; p++)
5003 if (item_value(*p)) {
5004 set_item_value(*p, FALSE);
5009 for (p = items + 1; *p != 0; p++)
5010 if (item_value(*p)) {
5011 set_item_value(items[0], FALSE);
5024 /* interactively set the trace level */
5027 ITEM *items[SIZEOF(t_tbl)];
5034 mvaddstr(0, 0, "Interactively set trace level:");
5035 mvaddstr(2, 0, " Press space bar to toggle a selection.");
5036 mvaddstr(3, 0, " Use up and down arrow to move the select bar.");
5037 mvaddstr(4, 0, " Press return to set the trace level.");
5038 mvprintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5042 for (n = 0; t_tbl[n].name != 0; n++)
5043 *ip++ = new_item(t_tbl[n].name, "");
5046 m = new_menu(items);
5048 set_menu_format(m, 0, 2);
5049 scale_menu(m, &mrows, &mcols);
5051 menu_opts_off(m, O_ONEVALUE);
5052 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5053 set_menu_win(m, menuwin);
5054 keypad(menuwin, TRUE);
5057 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5061 for (ip = menu_items(m); *ip; ip++) {
5062 unsigned mask = t_tbl[item_index(*ip)].mask;
5064 set_item_value(*ip, _nc_tracing == 0);
5065 else if ((mask & _nc_tracing) == mask)
5066 set_item_value(*ip, TRUE);
5069 while (run_trace_menu(m))
5073 for (ip = menu_items(m); *ip; ip++)
5074 if (item_value(*ip))
5075 newtrace |= t_tbl[item_index(*ip)].mask;
5077 _tracef("trace level interactively set to %s", tracetrace(_nc_tracing));
5079 (void) mvprintw(LINES - 2, 0,
5080 "Trace level is %s\n", tracetrace(_nc_tracing));
5081 (void) addstr("Press any key to continue...");
5088 for (ip = items; *ip; ip++)
5092 #endif /* USE_LIBMENU */
5094 /****************************************************************************
5098 ****************************************************************************/
5101 make_label(int frow, int fcol, NCURSES_CONST char *label)
5103 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5106 set_field_buffer(f, 0, label);
5107 set_field_opts(f, (int) (field_opts(f) & ~O_ACTIVE));
5113 make_field(int frow, int fcol, int rows, int cols, bool secure)
5115 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5118 set_field_back(f, A_UNDERLINE);
5119 set_field_userptr(f, (void *) 0);
5125 display_form(FORM * f)
5130 scale_form(f, &rows, &cols);
5132 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5134 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5139 if (post_form(f) != E_OK)
5144 erase_form(FORM * f)
5146 WINDOW *w = form_win(f);
5147 WINDOW *s = form_sub(f);
5157 edit_secure(FIELD * me, int c)
5159 int rows, cols, frow, fcol, nrow, nbuf;
5161 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5163 char *source = field_buffer(me, 1);
5167 strcpy(temp, source ? source : "");
5168 len = (long) (char *) field_userptr(me);
5170 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5173 set_field_buffer(me, 1, temp);
5193 case REQ_RIGHT_CHAR:
5195 c = 0; /* we don't want to do inline editing */
5200 set_field_buffer(me, 1, temp);
5207 set_field_buffer(me, 1, temp);
5212 set_field_userptr(me, (void *) len);
5218 form_virtualize(FORM * f, WINDOW *w)
5221 static const struct {
5225 { CTRL('A'), REQ_NEXT_CHOICE },
5226 { CTRL('B'), REQ_PREV_WORD },
5227 { CTRL('C'), REQ_CLR_EOL },
5228 { CTRL('D'), REQ_DOWN_FIELD },
5229 { CTRL('E'), REQ_END_FIELD },
5230 { CTRL('F'), REQ_NEXT_PAGE },
5231 { CTRL('G'), REQ_DEL_WORD },
5232 { CTRL('H'), REQ_DEL_PREV },
5233 { CTRL('I'), REQ_INS_CHAR },
5234 { CTRL('K'), REQ_CLR_EOF },
5235 { CTRL('L'), REQ_LEFT_FIELD },
5236 { CTRL('M'), REQ_NEW_LINE },
5237 { CTRL('N'), REQ_NEXT_FIELD },
5238 { CTRL('O'), REQ_INS_LINE },
5239 { CTRL('P'), REQ_PREV_FIELD },
5240 { CTRL('R'), REQ_RIGHT_FIELD },
5241 { CTRL('S'), REQ_BEG_FIELD },
5242 { CTRL('U'), REQ_UP_FIELD },
5243 { CTRL('V'), REQ_DEL_CHAR },
5244 { CTRL('W'), REQ_NEXT_WORD },
5245 { CTRL('X'), REQ_CLR_FIELD },
5246 { CTRL('Y'), REQ_DEL_LINE },
5247 { CTRL('Z'), REQ_PREV_CHOICE },
5248 { ESCAPE, MAX_FORM_COMMAND + 1 },
5249 { KEY_BACKSPACE, REQ_DEL_PREV },
5250 { KEY_DOWN, REQ_DOWN_CHAR },
5251 { KEY_END, REQ_LAST_FIELD },
5252 { KEY_HOME, REQ_FIRST_FIELD },
5253 { KEY_LEFT, REQ_LEFT_CHAR },
5254 { KEY_LL, REQ_LAST_FIELD },
5255 { KEY_NEXT, REQ_NEXT_FIELD },
5256 { KEY_NPAGE, REQ_NEXT_PAGE },
5257 { KEY_PPAGE, REQ_PREV_PAGE },
5258 { KEY_PREVIOUS, REQ_PREV_FIELD },
5259 { KEY_RIGHT, REQ_RIGHT_CHAR },
5260 { KEY_UP, REQ_UP_CHAR },
5261 { QUIT, MAX_FORM_COMMAND + 1 }
5265 static int mode = REQ_INS_MODE;
5266 int c = wGetchar(w);
5268 FIELD *me = current_field(f);
5269 bool current = TRUE;
5271 if (c == CTRL(']')) {
5272 if (mode == REQ_INS_MODE) {
5273 mode = REQ_OVL_MODE;
5275 mode = REQ_INS_MODE;
5279 for (n = 0; n < SIZEOF(lookup); n++) {
5280 if (lookup[n].code == c) {
5281 c = lookup[n].result;
5286 mvprintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5289 * Force the field that the user is typing into to be in reverse video,
5290 * while the other fields are shown underlined.
5305 case REQ_LEFT_FIELD:
5307 case REQ_RIGHT_CHAR:
5311 current = (c < KEY_MAX);
5315 c = edit_secure(me, c);
5316 set_field_back(me, A_REVERSE);
5318 c = edit_secure(me, c);
5319 set_field_back(me, A_UNDERLINE);
5325 my_form_driver(FORM * form, int c)
5327 if (c == (MAX_FORM_COMMAND + 1)
5328 && form_driver(form, REQ_VALIDATION) == E_OK)
5336 #ifdef NCURSES_VERSION
5337 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5338 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5340 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5341 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5345 * Allow a middle initial, optionally with a '.' to end it.
5348 FIELDCHECK_CB(mi_field_check)
5350 char *s = field_buffer(fld, 0);
5354 for (n = 0; s[n] != '\0'; ++n) {
5361 } else if (isspace(UChar(s[n]))) {
5366 if (!isspace(UChar(s[n])))
5372 /* force the form to display a leading capital */
5373 if (islower(UChar(s[0]))) {
5374 s[0] = toupper(UChar(s[0]));
5375 set_field_buffer(fld, 0, s);
5381 CHAR_CHECK_CB(mi_char_check)
5383 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5387 * Passwords should be at least 6 characters.
5390 FIELDCHECK_CB(pw_field_check)
5392 char *s = field_buffer(fld, 0);
5395 for (n = 0; s[n] != '\0'; ++n) {
5396 if (isspace(UChar(s[n]))) {
5405 CHAR_CHECK_CB(pw_char_check)
5407 return (isgraph(ch) ? TRUE : FALSE);
5415 FIELD *f[12], *secure;
5416 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
5417 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
5418 int finished = 0, c;
5421 #ifdef NCURSES_MOUSE_VERSION
5422 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5426 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
5427 addstr("^N -- go to next field ^P -- go to previous field\n");
5428 addstr("Home -- go to first field End -- go to last field\n");
5429 addstr("^L -- go to field to left ^R -- go to field to right\n");
5430 addstr("^U -- move upward to field ^D -- move downward to field\n");
5431 addstr("^W -- go to next word ^B -- go to previous word\n");
5432 addstr("^S -- go to start of field ^E -- go to end of field\n");
5433 addstr("^H -- delete previous char ^Y -- delete line\n");
5434 addstr("^G -- delete current word ^C -- clear to end of line\n");
5435 addstr("^K -- clear to end of field ^X -- clear field\n");
5436 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
5438 mvaddstr(4, 57, "Forms Entry Test");
5442 /* describe the form */
5443 f[n++] = make_label(0, 15, "Sample Form");
5445 f[n++] = make_label(2, 0, "Last Name");
5446 f[n++] = make_field(3, 0, 1, 18, FALSE);
5447 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5449 f[n++] = make_label(2, 20, "First Name");
5450 f[n++] = make_field(3, 20, 1, 12, FALSE);
5451 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5453 f[n++] = make_label(2, 34, "Middle Name");
5454 f[n++] = make_field(3, 34, 1, 12, FALSE);
5455 set_field_type(f[n - 1], fty_middle);
5457 f[n++] = make_label(5, 0, "Comments");
5458 f[n++] = make_field(6, 0, 4, 46, FALSE);
5460 f[n++] = make_label(5, 20, "Password:");
5462 f[n++] = make_field(5, 30, 1, 9, TRUE);
5463 set_field_type(f[n - 1], fty_passwd);
5464 f[n++] = (FIELD *) 0;
5472 nonl(); /* lets us read ^M's */
5474 switch (form_driver(form, c = form_virtualize(form, w))) {
5476 mvaddstr(5, 57, field_buffer(secure, 1));
5480 case E_UNKNOWN_COMMAND:
5481 finished = my_form_driver(form, c);
5492 for (c = 0; f[c] != 0; c++)
5494 free_fieldtype(fty_middle);
5495 free_fieldtype(fty_passwd);
5499 #ifdef NCURSES_MOUSE_VERSION
5500 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5503 #endif /* USE_LIBFORM */
5505 /****************************************************************************
5509 ****************************************************************************/
5512 fillwin(WINDOW *win, char ch)
5517 getmaxyx(win, y1, x1);
5518 for (y = 0; y < y1; y++) {
5520 for (x = 0; x < x1; x++)
5521 waddch(win, UChar(ch));
5526 crosswin(WINDOW *win, char ch)
5531 getmaxyx(win, y1, x1);
5532 for (y = 0; y < y1; y++) {
5533 for (x = 0; x < x1; x++)
5534 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
5535 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
5537 waddch(win, UChar(ch));
5542 #define OVERLAP_FLAVORS 5
5545 overlap_helpitem(int state, int item, char *message)
5547 int row = (item / 2);
5548 int col = ((item % 2) ? COLS / 2 : 0);
5550 move(LINES - 6 + row, col);
5551 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
5556 overlap_test_1_attr(WINDOW *win, int flavor, int col)
5558 short cpair = 1 + (flavor * 2) + col;
5562 wattrset(win, A_NORMAL);
5565 wattrset(win, A_BOLD);
5568 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
5569 wattrset(win, COLOR_PAIR(cpair) | A_NORMAL);
5572 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
5573 wattrset(win, COLOR_PAIR(cpair) | A_BOLD);
5579 overlap_test_2_attr(WINDOW *win, int flavor, int col)
5581 short cpair = 9 + (flavor * 2) + col;
5591 init_pair(cpair, COLOR_RED, COLOR_GREEN);
5592 wbkgdset(win, ' ' | A_BLINK | COLOR_PAIR(cpair));
5595 wbkgdset(win, ' ' | A_NORMAL);
5601 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
5606 const char *ths, *tht;
5610 state += OVERLAP_FLAVORS;
5611 state = state % OVERLAP_FLAVORS;
5613 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
5616 ths = col ? "B" : "A";
5617 tht = col ? "A" : "B";
5622 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
5630 overlap_test_1_attr(stdscr, flavors[row], col);
5631 sprintf(msg, "fill window %s with letter %s.", ths, ths);
5639 switch (flavors[row]) {
5641 sprintf(msg, "cross pattern in window %s.", ths);
5644 sprintf(msg, "draw box in window %s.", ths);
5647 sprintf(msg, "set background of window %s.", ths);
5650 sprintf(msg, "reset background of window %s.", ths);
5656 sprintf(msg, "clear window %s.", ths);
5660 switch (flavors[row]) {
5662 sprintf(msg, "overwrite %s onto %s.", ths, tht);
5665 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
5668 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
5671 sprintf(msg, "overlay %s onto %s.", ths, tht);
5676 overlap_helpitem(state, item, msg);
5677 wattrset(stdscr, A_NORMAL);
5678 wbkgdset(stdscr, ' ' | A_NORMAL);
5681 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
5682 state, flavors[state]);
5688 overlap_test_0(WINDOW *a, WINDOW *b)
5698 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
5700 overlap_test_1_attr(a, flavor, col);
5702 wattrset(a, A_NORMAL);
5706 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
5708 overlap_test_2_attr(a, flavor, col);
5717 /* done in overlap_test_2_attr */
5720 /* done in overlap_test_2_attr */
5726 overlap_test_3(WINDOW *a)
5733 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
5740 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
5743 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
5751 /* test effects of overlapping windows */
5756 int state, flavor[OVERLAP_FLAVORS];
5758 WINDOW *win1 = newwin(9, 20, 3, 3);
5759 WINDOW *win2 = newwin(9, 20, 9, 16);
5765 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
5766 printw("the shared region of two overlapping windows A and B. The cross\n");
5767 printw("pattern in each window does not overlap the other.\n");
5769 memset(flavor, 0, sizeof(flavor));
5770 state = overlap_help(0, flavor);
5772 while (!isQuit(ch = Getchar()))
5774 case 'a': /* refresh window A first, then B */
5775 overlap_test_0(win1, win2);
5778 case 'b': /* refresh window B first, then A */
5779 overlap_test_0(win2, win1);
5782 case 'c': /* fill window A so it's visible */
5783 overlap_test_1(flavor[1], 0, win1, 'A');
5786 case 'd': /* fill window B so it's visible */
5787 overlap_test_1(flavor[1], 1, win2, 'B');
5790 case 'e': /* cross test pattern in window A */
5791 overlap_test_2(flavor[2], 0, win1, 'A');
5794 case 'f': /* cross test pattern in window A */
5795 overlap_test_2(flavor[2], 1, win2, 'B');
5798 case 'g': /* clear window A */
5799 overlap_test_3(win1);
5802 case 'h': /* clear window B */
5803 overlap_test_3(win2);
5806 case 'i': /* overwrite A onto B */
5807 overlap_test_4(flavor[4], win1, win2);
5810 case 'j': /* overwrite B onto A */
5811 overlap_test_4(flavor[4], win2, win1);
5816 state = overlap_help(state + 1, flavor);
5821 state = overlap_help(state - 1, flavor);
5826 state = overlap_help(state, flavor);
5830 state = overlap_help(state, flavor);
5845 /****************************************************************************
5849 ****************************************************************************/
5852 do_single_test(const char c)
5853 /* perform a single specified test */
5860 #if USE_WIDEC_SUPPORT
5870 #if USE_WIDEC_SUPPORT
5878 Cannot("does not support color.");
5883 #if USE_WIDEC_SUPPORT
5886 Cannot("does not support color.");
5894 Cannot("does not support color.");
5895 else if (!can_change_color())
5896 Cannot("has hardwired color values.");
5907 #if USE_WIDEC_SUPPORT
5916 #if USE_WIDEC_SUPPORT
5924 demo_panels(init_panel, fill_panel);
5928 #if USE_WIDEC_SUPPORT
5930 demo_panels(init_wide_panel, fill_wide_panel);
5939 flushinp_test(stdscr);
5943 test_sgr_attributes();
5966 #if USE_LIBMENU && defined(TRACE)
5985 static const char *const tbl[] =
5987 "Usage: ncurses [options]"
5990 #ifdef NCURSES_VERSION
5991 ," -a f,b set default-colors (assumed white-on-black)"
5992 ," -d use default-colors if terminal supports them"
5995 ," -e fmt specify format for soft-keys test (e)"
5998 ," -f rip-off footer line (can repeat)"
5999 ," -h rip-off header line (can repeat)"
6001 ," -m do not use colors"
6002 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6004 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6007 ," -t mask specify default trace-level (may toggle with ^T)"
6011 for (n = 0; n < SIZEOF(tbl); n++)
6012 fprintf(stderr, "%s\n", tbl[n]);
6013 ExitProgram(EXIT_FAILURE);
6017 set_terminal_modes(void)
6022 scrollok(stdscr, TRUE);
6023 idlok(stdscr, TRUE);
6024 keypad(stdscr, TRUE);
6029 announce_sig(int sig)
6031 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6037 rip_footer(WINDOW *win, int cols)
6039 wbkgd(win, A_REVERSE);
6042 wprintw(win, "footer: window %p, %d columns", win, cols);
6048 rip_header(WINDOW *win, int cols)
6050 wbkgd(win, A_REVERSE);
6053 wprintw(win, "header: window %p, %d columns", win, cols);
6057 #endif /* HAVE_RIPOFFLINE */
6065 (void) puts("This is the ncurses main menu");
6066 (void) puts("a = keyboard and mouse input test");
6067 #if USE_WIDEC_SUPPORT
6068 (void) puts("A = wide-character keyboard and mouse input test");
6070 (void) puts("b = character attribute test");
6071 #if USE_WIDEC_SUPPORT
6072 (void) puts("B = wide-character attribute test");
6074 (void) puts("c = color test pattern");
6075 #if USE_WIDEC_SUPPORT
6076 (void) puts("C = color test pattern using wide-character calls");
6079 (void) puts("d = edit RGB color values");
6081 (void) puts("e = exercise soft keys");
6082 #if USE_WIDEC_SUPPORT
6083 (void) puts("E = exercise soft keys using wide-characters");
6086 (void) puts("f = display ACS characters");
6087 #if USE_WIDEC_SUPPORT
6088 (void) puts("F = display Wide-ACS characters");
6090 (void) puts("g = display windows and scrolling");
6091 (void) puts("i = test of flushinp()");
6092 (void) puts("k = display character attributes");
6094 (void) puts("m = menu code test");
6097 (void) puts("o = exercise panels library");
6098 #if USE_WIDEC_SUPPORT
6099 (void) puts("O = exercise panels with wide-characters");
6102 (void) puts("p = exercise pad features");
6103 (void) puts("q = quit");
6105 (void) puts("r = exercise forms code");
6107 (void) puts("s = overlapping-refresh test");
6108 #if USE_LIBMENU && defined(TRACE)
6109 (void) puts("t = set trace level");
6111 (void) puts("? = repeat this command summary");
6113 (void) fputs("> ", stdout);
6114 (void) fflush(stdout); /* necessary under SVr4 curses */
6117 * This used to be an 'fgets()' call. However (on Linux, at least)
6118 * mixing stream I/O and 'read()' (used in the library) causes the
6119 * input stream to be flushed when switching between the two.
6124 if (read(fileno(stdin), &ch, 1) <= 0) {
6128 } else if (command == 0 && !isspace(UChar(ch))) {
6130 } else if (ch == '\n' || ch == '\r') {
6131 if ((command == 'd') && !top) {
6132 (void) fputs("Do not nest test-d\n", stdout);
6137 (void) fputs("> ", stdout);
6138 (void) fflush(stdout);
6142 if (do_single_test(command)) {
6144 * This may be overkill; it's intended to reset everything back
6145 * to the initial terminal modes so that tests don't get in
6149 set_terminal_modes();
6154 if (command == '?') {
6155 (void) puts("This is the ncurses capability tester.");
6157 puts("You may select a test from the main menu by typing the");
6159 puts("key letter of the choice (the letter to left of the =)");
6161 puts("at the > prompt. Type `q' to exit.");
6169 /*+-------------------------------------------------------------------------
6171 --------------------------------------------------------------------------*/
6173 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6174 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6177 main(int argc, char *argv[])
6181 #ifdef NCURSES_VERSION
6182 int default_fg = COLOR_WHITE;
6183 int default_bg = COLOR_BLACK;
6184 bool assumed_colors = FALSE;
6185 bool default_colors = FALSE;
6187 char *palette_file = 0;
6188 bool monochrome = FALSE;
6190 setlocale(LC_ALL, "");
6192 while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) {
6194 #ifdef NCURSES_VERSION
6196 assumed_colors = TRUE;
6197 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6200 default_colors = TRUE;
6204 my_e_param = atoi(optarg);
6205 #ifdef NCURSES_VERSION
6206 if (my_e_param > 3) /* allow extended layouts */
6215 ripoffline(-1, rip_footer);
6218 ripoffline(1, rip_header);
6220 #endif /* HAVE_RIPOFFLINE */
6225 palette_file = optarg;
6229 nap_msec = atol(optarg);
6234 save_trace = strtol(optarg, 0, 0);
6243 * If there's no menus (unlikely for ncurses!), then we'll have to set
6244 * tracing on initially, just in case the user wants to test something that
6245 * doesn't involve wGetchar.
6248 /* enable debugging */
6252 if (!isatty(fileno(stdin)))
6254 #endif /* USE_LIBMENU */
6258 /* tell it we're going to play with soft keys */
6259 slk_init(my_e_param);
6263 /* set up null signal catcher so we can see what interrupts to getch do */
6264 signal(SIGUSR1, announce_sig);
6267 /* we must initialize the curses data structure only once */
6271 /* tests, in general, will want these modes */
6272 use_colors = monochrome ? FALSE : has_colors();
6276 #ifdef NCURSES_VERSION_PATCH
6277 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6278 #if HAVE_USE_DEFAULT_COLORS
6279 if (default_colors) {
6280 use_default_colors();
6283 #if NCURSES_VERSION_PATCH >= 20000708
6284 else if (assumed_colors)
6285 assume_default_colors(default_fg, default_bg);
6288 #else /* normal SVr4 curses */
6289 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6291 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6293 if (can_change_color()) {
6295 all_colors = (RGB_DATA *) malloc(max_colors * sizeof(RGB_DATA));
6296 for (cp = 0; cp < max_colors; ++cp) {
6298 &all_colors[cp].red,
6299 &all_colors[cp].green,
6300 &all_colors[cp].blue);
6302 if (palette_file != 0) {
6303 FILE *fp = fopen(palette_file, "r");
6305 char buffer[BUFSIZ];
6306 int red, green, blue;
6308 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6309 if (sscanf(buffer, "scale:%d", &c) == 1) {
6311 } else if (sscanf(buffer, "%d:%d %d %d",
6320 all_colors[c].red = (red * 1000) / scale;
6321 all_colors[c].green = (green * 1000) / scale;
6322 all_colors[c].blue = (blue * 1000) / scale;
6330 set_terminal_modes();
6334 * Return to terminal mode, so we're guaranteed of being able to
6335 * select terminal commands even if the capabilities are wrong.
6339 #if HAVE_CURSES_VERSION
6340 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6341 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6342 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6343 NCURSES_VERSION_MAJOR,
6344 NCURSES_VERSION_MINOR,
6345 NCURSES_VERSION_PATCH);
6347 (void) puts("Welcome to ncurses. Press ? for help.");
6352 ExitProgram(EXIT_SUCCESS);
6355 /* ncurses.c ends here */