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.291 2007/06/23 21:43:25 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;
612 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
613 * Resize both and paint the box in the parent.
616 resize_boxes(unsigned level, WINDOW *win)
620 int high = LINES - base;
624 wnoutrefresh(stdscr);
627 /* FIXME: this chunk should be done in resizeterm() */
633 for (n = 0; n < level; ++n) {
634 wresize(winstack[n].frame, high, wide);
635 wresize(winstack[n].text, high - 2, wide - 2);
638 werase(winstack[n].text);
639 box(winstack[n].frame, 0, 0);
640 wnoutrefresh(winstack[n].frame);
641 wprintw(winstack[n].text,
643 getmaxy(winstack[n].text),
644 getmaxx(winstack[n].text));
645 wnoutrefresh(winstack[n].text);
646 if (winstack[n].text == win)
652 #define forget_boxes() /* nothing */
653 #define remember_boxes(level,text,frame) /* nothing */
657 wgetch_test(unsigned level, WINDOW *win, int delay)
660 int first_y, first_x;
664 bool blocking = (delay < 0);
666 memset(flags, FALSE, sizeof(flags));
667 flags[UChar('k')] = (win == stdscr);
669 setup_getch(win, flags);
670 wtimeout(win, delay);
671 getyx(win, first_y, first_x);
673 wgetch_help(win, flags);
674 wsetscrreg(win, first_y, getmaxy(win) - 1);
678 while ((c = wGetchar(win)) == ERR) {
681 (void) wprintw(win, "%05d: input error", incount);
684 (void) wprintw(win, "%05d: input timed out", incount);
686 wgetch_wrap(win, first_y);
688 if (c == ERR && blocking) {
690 wgetch_wrap(win, first_y);
691 } else if (isQuit(c)) {
693 } else if (c == 'e') {
694 flags[UChar('e')] = !flags[UChar('e')];
695 setup_getch(win, flags);
696 wgetch_help(win, flags);
697 } else if (c == 'g') {
698 waddstr(win, "getstr test: ");
700 wgetnstr(win, buf, sizeof(buf) - 1);
702 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
704 wgetch_wrap(win, first_y);
705 } else if (c == 'k') {
706 flags[UChar('k')] = !flags[UChar('k')];
707 setup_getch(win, flags);
708 wgetch_help(win, flags);
709 } else if (c == 'm') {
710 flags[UChar('m')] = !flags[UChar('m')];
711 setup_getch(win, flags);
712 wgetch_help(win, flags);
713 } else if (c == 's') {
715 } else if (c == 'w') {
716 int high = getmaxy(win) - 1 - first_y + 1;
717 int wide = getmaxx(win) - first_x;
719 int new_y = first_y + getbegy(win);
720 int new_x = first_x + getbegx(win);
722 getyx(win, old_y, old_x);
723 if (high > 2 && wide > 2) {
724 WINDOW *wb = newwin(high, wide, new_y, new_x);
725 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
730 remember_boxes(level, wi, wb);
731 wgetch_test(level + 1, wi, delay);
735 wgetch_help(win, flags);
736 wmove(win, old_y, old_x);
742 } else if (c == 'z') {
743 kill(getpid(), SIGTSTP);
746 wprintw(win, "Key pressed: %04o ", c);
747 #ifdef NCURSES_MOUSE_VERSION
748 if (c == KEY_MOUSE) {
753 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
755 move(event.y, event.x);
759 #endif /* NCURSES_MOUSE_VERSION */
761 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
762 if (c == KEY_RESIZE) {
763 resize_boxes(level, win);
766 (void) waddstr(win, keyname(c));
767 } else if (c > 0x80) {
768 unsigned c2 = (c & 0x7f);
770 (void) wprintw(win, "M-%c", UChar(c2));
772 (void) wprintw(win, "M-%s", unctrl(c2));
773 waddstr(win, " (high-half character)");
776 (void) wprintw(win, "%c (ASCII printable character)", c);
778 (void) wprintw(win, "%s (ASCII control character)",
781 wgetch_wrap(win, first_y);
789 begin_getch_test(void)
796 #ifdef NCURSES_MOUSE_VERSION
797 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
800 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
802 getnstr(buf, sizeof(buf) - 1);
806 if (isdigit(UChar(buf[0]))) {
807 delay = atoi(buf) * 100;
817 finish_getch_test(void)
819 #ifdef NCURSES_MOUSE_VERSION
820 mousemask(0, (mmask_t *) 0);
831 int delay = begin_getch_test();
832 wgetch_test(0, stdscr, delay);
837 #if USE_WIDEC_SUPPORT
839 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
840 * Resize both and paint the box in the parent.
844 resize_wide_boxes(unsigned level, WINDOW *win)
848 int high = LINES - base;
852 wnoutrefresh(stdscr);
855 /* FIXME: this chunk should be done in resizeterm() */
861 for (n = 0; n < level; ++n) {
862 wresize(winstack[n].frame, high, wide);
863 wresize(winstack[n].text, high - 2, wide - 2);
866 werase(winstack[n].text);
867 box_set(winstack[n].frame, 0, 0);
868 wnoutrefresh(winstack[n].frame);
869 wprintw(winstack[n].text,
871 getmaxy(winstack[n].text),
872 getmaxx(winstack[n].text));
873 wnoutrefresh(winstack[n].text);
874 if (winstack[n].text == win)
879 #endif /* KEY_RESIZE */
882 wcstos(const wchar_t *src)
887 const wchar_t *tmp = src;
889 memset(&state, 0, sizeof(state));
890 if ((need = wcsrtombs(0, &tmp, 0, &state)) > 0) {
891 unsigned have = need;
892 result = (char *) calloc(have + 1, 1);
894 if (wcsrtombs(result, &tmp, have, &state) != have) {
903 wget_wch_test(unsigned level, WINDOW *win, int delay)
905 wchar_t wchar_buf[BUFSIZ];
906 wint_t wint_buf[BUFSIZ];
907 int first_y, first_x;
911 bool blocking = (delay < 0);
915 memset(flags, FALSE, sizeof(flags));
916 flags[UChar('k')] = (win == stdscr);
918 setup_getch(win, flags);
919 wtimeout(win, delay);
920 getyx(win, first_y, first_x);
922 wgetch_help(win, flags);
923 wsetscrreg(win, first_y, getmaxy(win) - 1);
927 while ((code = wGet_wchar(win, &c)) == ERR) {
930 (void) wprintw(win, "%05d: input error", incount);
933 (void) wprintw(win, "%05d: input timed out", incount);
935 wgetch_wrap(win, first_y);
937 if (code == ERR && blocking) {
939 wgetch_wrap(win, first_y);
940 } else if (isQuit((int) c)) {
942 } else if (c == 'e') {
943 flags[UChar('e')] = !flags[UChar('e')];
944 setup_getch(win, flags);
945 wgetch_help(win, flags);
946 } else if (c == 'g') {
947 waddstr(win, "getstr test: ");
949 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
952 wprintw(win, "wgetn_wstr returns an error.");
955 for (n = 0; (wchar_buf[n] = wint_buf[n]) != 0; ++n) ;
956 if ((temp = wcstos(wchar_buf)) != 0) {
957 wprintw(win, "I saw %d characters:\n\t`%s'.",
958 (int) wcslen(wchar_buf), temp);
961 wprintw(win, "I saw %d characters (cannot convert).",
962 (int) wcslen(wchar_buf));
966 wgetch_wrap(win, first_y);
967 } else if (c == 'k') {
968 flags[UChar('k')] = !flags[UChar('k')];
969 setup_getch(win, flags);
970 wgetch_help(win, flags);
971 } else if (c == 'm') {
972 flags[UChar('m')] = !flags[UChar('m')];
973 setup_getch(win, flags);
974 wgetch_help(win, flags);
975 } else if (c == 's') {
977 } else if (c == 'w') {
978 int high = getmaxy(win) - 1 - first_y + 1;
979 int wide = getmaxx(win) - first_x;
981 int new_y = first_y + getbegy(win);
982 int new_x = first_x + getbegx(win);
984 getyx(win, old_y, old_x);
985 if (high > 2 && wide > 2) {
986 WINDOW *wb = newwin(high, wide, new_y, new_x);
987 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
992 remember_boxes(level, wi, wb);
993 wget_wch_test(level + 1, wi, delay);
997 wgetch_help(win, flags);
998 wmove(win, old_y, old_x);
1003 } else if (c == 'z') {
1004 kill(getpid(), SIGTSTP);
1007 wprintw(win, "Key pressed: %04o ", c);
1008 #ifdef NCURSES_MOUSE_VERSION
1009 if (c == KEY_MOUSE) {
1013 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1015 move(event.y, event.x);
1019 #endif /* NCURSES_MOUSE_VERSION */
1020 if (code == KEY_CODE_YES) {
1022 if (c == KEY_RESIZE) {
1023 resize_wide_boxes(level, win);
1026 (void) waddstr(win, key_name((wchar_t) c));
1028 if (c < 256 && iscntrl(c)) {
1029 (void) wprintw(win, "%s (control character)", unctrl(c));
1032 waddnwstr(win, &c2, 1);
1033 (void) wprintw(win, " = %#x (printable character)", c);
1036 wgetch_wrap(win, first_y);
1046 int delay = begin_getch_test();
1047 wget_wch_test(0, stdscr, delay);
1049 finish_getch_test();
1053 /****************************************************************************
1055 * Character attributes test
1057 ****************************************************************************/
1059 #if HAVE_SETUPTERM || HAVE_TGETENT
1060 #define get_ncv() TIGETNUM("ncv","NC")
1061 #define get_xmc() TIGETNUM("xmc","sg")
1063 #define get_ncv() -1
1064 #define get_xmc() -1
1071 static int first = TRUE;
1072 static chtype result = 0;
1078 char *area_pointer = parsed;
1080 tgetent(buffer, getenv("TERM"));
1083 if (TIGETSTR("smso", "so"))
1084 result |= A_STANDOUT;
1085 if (TIGETSTR("smul", "us"))
1086 result |= A_UNDERLINE;
1087 if (TIGETSTR("rev", "mr"))
1088 result |= A_REVERSE;
1089 if (TIGETSTR("blink", "mb"))
1091 if (TIGETSTR("dim", "mh"))
1093 if (TIGETSTR("bold", "md"))
1095 if (TIGETSTR("smacs", "ac"))
1096 result |= A_ALTCHARSET;
1102 #define termattrs() my_termattrs()
1105 #define MAX_ATTRSTRING 31
1106 #define LEN_ATTRSTRING 26
1108 static char attr_test_string[MAX_ATTRSTRING + 1];
1111 attr_legend(WINDOW *helpwin)
1116 mvwprintw(helpwin, row++, col,
1118 mvwprintw(helpwin, row++, col,
1121 mvwprintw(helpwin, row++, col,
1122 "Modify the test strings:");
1123 mvwprintw(helpwin, row++, col,
1124 " A digit sets gaps on each side of displayed attributes");
1125 mvwprintw(helpwin, row++, col,
1126 " </> shifts the text left/right. ");
1128 mvwprintw(helpwin, row++, col,
1131 mvwprintw(helpwin, row++, col,
1132 " f/F/b/F toggle foreground/background background color");
1133 mvwprintw(helpwin, row++, col,
1134 " t/T toggle text/background color attribute");
1136 mvwprintw(helpwin, row++, col,
1137 " a/A toggle ACS (alternate character set) mapping");
1138 mvwprintw(helpwin, row++, col,
1139 " v/V toggle video attribute to combine with each line");
1143 show_color_attr(int fg, int bg, int tx)
1146 printw(" Colors (fg %d, bg %d", fg, bg);
1148 printw(", text %d", tx);
1154 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1185 if (*fg < min_colors)
1189 if (*bg < min_colors)
1203 adjust_attr_string(int adjust)
1205 int first = ((int) UChar(attr_test_string[0])) + adjust;
1206 int last = first + LEN_ATTRSTRING;
1208 if (first >= ' ' && last <= '~') { /* 32..126 */
1210 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1211 attr_test_string[j] = k;
1212 if (((k + 1 - first) % 5) == 0) {
1214 if (j < MAX_ATTRSTRING)
1215 attr_test_string[j] = ' ';
1218 while (j < MAX_ATTRSTRING)
1219 attr_test_string[j++] = ' ';
1220 attr_test_string[j] = '\0';
1227 init_attr_string(void)
1229 attr_test_string[0] = 'a';
1230 adjust_attr_string(0);
1234 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1236 int ncv = get_ncv();
1237 chtype test = attr & (chtype) (~A_ALTCHARSET);
1240 mvprintw(row, 5, "-->");
1241 mvprintw(row, 8, "%s mode:", name);
1242 mvprintw(row, 24, "|");
1244 printw("%*s", skip, " ");
1246 * Just for testing, write text using the alternate character set one
1247 * character at a time (to pass its rendition directly), and use the
1248 * string operation for the other attributes.
1250 if (attr & A_ALTCHARSET) {
1254 for (s = attr_test_string; *s != '\0'; ++s) {
1260 addstr(attr_test_string);
1264 printw("%*s", skip, " ");
1266 if (test != A_NORMAL) {
1267 if (!(termattrs() & test)) {
1270 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1271 static const chtype table[] =
1287 for (n = 0; n < SIZEOF(table); n++) {
1288 if ((table[n] & attr) != 0
1289 && ((1 << n) & ncv) != 0) {
1297 if ((termattrs() & test) != test)
1304 static const struct {
1306 NCURSES_CONST char * name;
1307 } attrs_to_test[] = {
1308 { A_STANDOUT, "STANDOUT" },
1309 { A_REVERSE, "REVERSE" },
1311 { A_UNDERLINE, "UNDERLINE" },
1313 { A_BLINK, "BLINK" },
1314 { A_PROTECT, "PROTECT" },
1316 { A_INVIS, "INVISIBLE" },
1318 { A_NORMAL, "NORMAL" },
1323 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1333 if (ch < 256 && isdigit(ch)) {
1341 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1343 attr_legend(helpwin);
1356 *kc = SIZEOF(attrs_to_test) - 1;
1362 if (*kc >= SIZEOF(attrs_to_test))
1366 adjust_attr_string(-1);
1369 adjust_attr_string(1);
1375 error = cycle_color_attr(ch, fg, bg, tx);
1385 /* test text attributes */
1388 int skip = get_xmc();
1389 short fg = COLOR_BLACK; /* color pair 0 is special */
1390 short bg = COLOR_BLACK;
1398 n = skip; /* make it easy */
1399 k = SIZEOF(attrs_to_test) - 1;
1404 chtype normal = A_NORMAL | BLANK;
1408 short pair = (fg != COLOR_BLACK || bg != COLOR_BLACK);
1411 if (init_pair(pair, fg, bg) == ERR) {
1414 normal |= COLOR_PAIR(pair);
1419 if (init_pair(pair, tx, bg) == ERR) {
1422 extras |= COLOR_PAIR(pair);
1431 mvaddstr(0, 20, "Character attribute test display");
1433 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1434 bool arrow = (j == k);
1435 row = show_attr(row, n, arrow,
1437 attrs_to_test[j].attr |
1438 attrs_to_test[k].attr,
1439 attrs_to_test[j].name);
1443 "This terminal does %shave the magic-cookie glitch",
1444 get_xmc() > -1 ? "" : "not ");
1445 mvprintw(row + 1, 8, "Enter '?' for help.");
1446 show_color_attr(fg, bg, tx);
1447 printw(" ACS (%d)", ac != 0);
1450 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1452 bkgdset(A_NORMAL | BLANK);
1457 #if USE_WIDEC_SUPPORT
1458 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1461 wide_adjust_attr_string(int adjust)
1463 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1464 int last = first + LEN_ATTRSTRING;
1466 if (first >= ' ' && last <= '~') { /* 32..126 */
1468 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1469 wide_attr_test_string[j] = k;
1470 if (((k + 1 - first) % 5) == 0) {
1472 if (j < MAX_ATTRSTRING)
1473 wide_attr_test_string[j] = ' ';
1476 while (j < MAX_ATTRSTRING)
1477 wide_attr_test_string[j++] = ' ';
1478 wide_attr_test_string[j] = '\0';
1485 wide_init_attr_string(void)
1487 wide_attr_test_string[0] = 'a';
1488 wide_adjust_attr_string(0);
1492 set_wide_background(short pair)
1499 setcchar(&normal, blank, A_NORMAL, pair, 0);
1505 get_wide_background(void)
1507 attr_t result = A_NORMAL;
1513 if (getbkgrnd(&ch) != ERR) {
1514 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1522 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1524 int ncv = get_ncv();
1525 chtype test = attr & ~WA_ALTCHARSET;
1528 mvprintw(row, 5, "-->");
1529 mvprintw(row, 8, "%s mode:", name);
1530 mvprintw(row, 24, "|");
1532 printw("%*s", skip, " ");
1535 * Just for testing, write text using the alternate character set one
1536 * character at a time (to pass its rendition directly), and use the
1537 * string operation for the other attributes.
1539 if (attr & WA_ALTCHARSET) {
1543 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1547 setcchar(&ch, fill, attr, pair, 0);
1554 attr_get(&old_attr, &old_pair, 0);
1555 attr_set(attr, pair, 0);
1556 addwstr(wide_attr_test_string);
1557 attr_set(old_attr, old_pair, 0);
1560 printw("%*s", skip, " ");
1562 if (test != A_NORMAL) {
1563 if (!(term_attrs() & test)) {
1566 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1567 static const attr_t table[] =
1581 for (n = 0; n < SIZEOF(table); n++) {
1582 if ((table[n] & attr) != 0
1583 && ((1 << n) & ncv) != 0) {
1591 if ((term_attrs() & test) != test)
1599 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1609 if (ch < 256 && isdigit(ch)) {
1617 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1618 box_set(helpwin, 0, 0);
1619 attr_legend(helpwin);
1632 *kc = SIZEOF(attrs_to_test) - 1;
1638 if (*kc >= SIZEOF(attrs_to_test))
1642 wide_adjust_attr_string(-1);
1645 wide_adjust_attr_string(1);
1651 error = cycle_color_attr(ch, fg, bg, tx);
1660 wide_attr_test(void)
1661 /* test text attributes using wide-character calls */
1664 int skip = get_xmc();
1665 short fg = COLOR_BLACK; /* color pair 0 is special */
1666 short bg = COLOR_BLACK;
1674 n = skip; /* make it easy */
1675 k = SIZEOF(attrs_to_test) - 1;
1676 wide_init_attr_string();
1684 pair = (fg != COLOR_BLACK || bg != COLOR_BLACK);
1687 if (init_pair(pair, fg, bg) == ERR) {
1694 if (init_pair(extras, tx, bg) == ERR) {
1699 set_wide_background(pair);
1702 box_set(stdscr, 0, 0);
1703 mvaddstr(0, 20, "Character attribute test display");
1705 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1706 row = wide_show_attr(row, n, j == k,
1708 attrs_to_test[j].attr |
1709 attrs_to_test[k].attr,
1711 attrs_to_test[j].name);
1715 "This terminal does %shave the magic-cookie glitch",
1716 get_xmc() > -1 ? "" : "not ");
1717 mvprintw(row + 1, 8, "Enter '?' for help.");
1718 show_color_attr(fg, bg, tx);
1719 printw(" ACS (%d)", ac != 0);
1722 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1724 set_wide_background(0);
1730 /****************************************************************************
1732 * Color support tests
1734 ****************************************************************************/
1736 static NCURSES_CONST char *the_color_names[] =
1757 show_color_name(int y, int x, int color, bool wide)
1759 if (move(y, x) != ERR) {
1764 sprintf(temp, "%02d", color);
1766 } else if (color >= 8) {
1767 sprintf(temp, "[%02d]", color);
1769 strcpy(temp, the_color_names[color]);
1771 printw("%-*.*s", width, width, temp);
1776 color_legend(WINDOW *helpwin)
1781 mvwprintw(helpwin, row++, col,
1784 mvwprintw(helpwin, row++, col,
1785 "Use up/down arrow to scroll through the display if it is");
1786 mvwprintw(helpwin, row++, col,
1787 "longer than one screen. Control/N and Control/P can be used");
1788 mvwprintw(helpwin, row++, col,
1789 "in place up up/down arrow. Use pageup/pagedown to scroll a");
1790 mvwprintw(helpwin, row++, col,
1791 "full screen; control/B and control/F can be used here.");
1793 mvwprintw(helpwin, row++, col,
1795 mvwprintw(helpwin, row++, col,
1796 " b/B toggle bold off/on");
1797 mvwprintw(helpwin, row++, col,
1798 " n/N toggle text/number on/off");
1799 mvwprintw(helpwin, row++, col,
1800 " w/W toggle width between 8/16 colors");
1803 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1805 /* generate a color test pattern */
1812 int grid_top = top + 3;
1813 int page_size = (LINES - grid_top);
1814 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1820 bool opt_bold = FALSE;
1821 bool opt_wide = FALSE;
1822 bool opt_nums = FALSE;
1825 if (pairs_max > COLOR_PAIRS)
1826 pairs_max = COLOR_PAIRS;
1831 /* this assumes an 80-column line */
1835 per_row = (COLORS > 8) ? 16 : 8;
1842 row_limit = (pairs_max + per_row - 1) / per_row;
1845 (void) printw("There are %d color pairs and %d colors\n",
1849 (void) mvprintw(top + 1, 0,
1850 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1853 opt_bold ? "on" : "off");
1855 /* show color names/numbers across the top */
1856 for (i = 0; i < per_row; i++)
1857 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
1859 /* show a grid of colors, with color names/ numbers on the left */
1860 for (i = (base_row * per_row); i < pairs_max; i++) {
1861 int row = grid_top + (i / per_row) - base_row;
1862 int col = (i % per_row + 1) * width;
1865 if (row >= 0 && move(row, col) != ERR) {
1866 short fg = i % COLORS;
1867 short bg = i / COLORS;
1869 init_pair(pair, fg, bg);
1870 attron((attr_t) COLOR_PAIR(pair));
1872 attron((attr_t) A_BOLD);
1875 sprintf(numbered, "{%02X}", i);
1878 printw("%-*.*s", width, width, hello);
1881 if ((i % per_row) == 0 && (i % COLORS) == 0) {
1882 show_color_name(row, 0, i / COLORS, opt_wide);
1890 switch (wGetchar(stdscr)) {
1907 set_color_test(opt_wide, FALSE);
1910 set_color_test(opt_wide, TRUE);
1914 if (base_row <= 0) {
1922 if (base_row + page_size >= row_limit) {
1931 if (base_row <= 0) {
1934 base_row -= (page_size - 1);
1942 if (base_row + page_size >= row_limit) {
1945 base_row += page_size - 1;
1946 if (base_row + page_size >= row_limit) {
1947 base_row = row_limit - page_size - 1;
1952 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1954 color_legend(helpwin);
1969 #if USE_WIDEC_SUPPORT
1970 /* generate a color test pattern */
1972 wide_color_test(void)
1978 int grid_top = top + 3;
1979 int page_size = (LINES - grid_top);
1980 int pairs_max = COLOR_PAIRS;
1986 bool opt_bold = FALSE;
1987 bool opt_wide = FALSE;
1988 bool opt_nums = FALSE;
1994 /* this assumes an 80-column line */
1998 per_row = (COLORS > 8) ? 16 : 8;
2005 row_limit = (pairs_max + per_row - 1) / per_row;
2008 (void) printw("There are %d color pairs and %d colors\n",
2012 (void) mvprintw(top + 1, 0,
2013 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2016 opt_bold ? "on" : "off");
2018 /* show color names/numbers across the top */
2019 for (i = 0; i < per_row; i++)
2020 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
2022 /* show a grid of colors, with color names/ numbers on the left */
2023 for (i = (base_row * per_row); i < pairs_max; i++) {
2024 int row = grid_top + (i / per_row) - base_row;
2025 int col = (i % per_row + 1) * width;
2028 if (row >= 0 && move(row, col) != ERR) {
2029 init_pair(pair, i % COLORS, i / COLORS);
2030 color_set(pair, NULL);
2032 attr_on((attr_t) A_BOLD, NULL);
2035 sprintf(numbered, "{%02X}", i);
2038 printw("%-*.*s", width, width, hello);
2039 attr_set(A_NORMAL, 0, NULL);
2041 if ((i % per_row) == 0 && (i % COLORS) == 0) {
2042 show_color_name(row, 0, i / COLORS, opt_wide);
2050 switch (c = wGetchar(stdscr)) {
2067 set_color_test(opt_wide, FALSE);
2070 set_color_test(opt_wide, TRUE);
2074 if (base_row <= 0) {
2082 if (base_row + page_size >= row_limit) {
2091 if (base_row <= 0) {
2094 base_row -= (page_size - 1);
2102 if (base_row + page_size >= row_limit) {
2105 base_row += page_size - 1;
2106 if (base_row + page_size >= row_limit) {
2107 base_row = row_limit - page_size - 1;
2112 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2114 color_legend(helpwin);
2128 #endif /* USE_WIDEC_SUPPORT */
2131 change_color(short current, int field, int value, int usebase)
2133 short red, green, blue;
2135 color_content(current, &red, &green, &blue);
2139 red = usebase ? red + value : value;
2142 green = usebase ? green + value : value;
2145 blue = usebase ? blue + value : value;
2149 if (init_color(current, red, green, blue) == ERR)
2154 init_all_colors(void)
2158 for (c = 0; c < COLORS; ++c)
2161 all_colors[c].green,
2162 all_colors[c].blue);
2165 #define scaled_rgb(n) ((255 * (n)) / 1000)
2169 /* display the color test pattern, without trying to edit colors */
2173 int this_c = 0, value = 0, field = 0;
2176 int page_size = (LINES - 6);
2181 for (i = 0; i < max_colors; i++)
2182 init_pair(i, COLOR_WHITE, i);
2184 mvprintw(LINES - 2, 0, "Number: %d", value);
2187 short red, green, blue;
2190 mvaddstr(0, 20, "Color RGB Value Editing");
2194 (i - top_color < page_size)
2195 && (i < max_colors); i++) {
2198 sprintf(numeric, "[%d]", i);
2199 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2200 (i == current ? '>' : ' '),
2201 (i < (int) SIZEOF(the_color_names)
2202 ? the_color_names[i] : numeric));
2203 attrset(COLOR_PAIR(i));
2207 color_content(i, &red, &green, &blue);
2209 if (current == i && field == 0)
2211 printw("%04d", red);
2212 if (current == i && field == 0)
2215 if (current == i && field == 1)
2217 printw("%04d", green);
2218 if (current == i && field == 1)
2221 if (current == i && field == 2)
2223 printw("%04d", blue);
2224 if (current == i && field == 2)
2227 printw(" ( %3d %3d %3d )",
2233 mvaddstr(LINES - 3, 0,
2234 "Use up/down to select a color, left/right to change fields.");
2235 mvaddstr(LINES - 2, 0,
2236 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2238 move(2 + current - top_color, 0);
2242 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2249 current -= (page_size - 1);
2256 if (current < (max_colors - 1))
2257 current += (page_size - 1);
2264 current = (current == 0 ? (max_colors - 1) : current - 1);
2269 current = (current == (max_colors - 1) ? 0 : current + 1);
2273 field = (field == 2 ? 0 : field + 1);
2277 field = (field == 0 ? 2 : field - 1);
2290 value = value * 10 + (this_c - '0');
2294 change_color(current, field, value, 1);
2298 change_color(current, field, -value, 1);
2302 change_color(current, field, value, 0);
2307 P(" RGB Value Editing Help");
2309 P("You are in the RGB value editor. Use the arrow keys to select one of");
2310 P("the fields in one of the RGB triples of the current colors; the one");
2311 P("currently selected will be reverse-video highlighted.");
2313 P("To change a field, enter the digits of the new value; they are echoed");
2314 P("as entered. Finish by typing `='. The change will take effect instantly.");
2315 P("To increment or decrement a value, use the same procedure, but finish");
2316 P("with a `+' or `-'.");
2318 P("Press 'm' to invoke the top-level menu with the current color settings.");
2319 P("To quit, do ESC");
2341 if (current >= max_colors)
2342 current = max_colors - 1;
2343 if (current < top_color)
2344 top_color = current;
2345 if (current - top_color >= page_size)
2346 top_color = current - (page_size - 1);
2348 mvprintw(LINES - 1, 0, "Number: %d", value);
2356 * ncurses does not reset each color individually when calling endwin().
2363 /****************************************************************************
2365 * Soft-key label test
2367 ****************************************************************************/
2372 #define SLK_WORK (SLK_HELP + 3)
2377 static const char *table[] =
2379 "Available commands are:"
2381 ,"^L -- repaint this message and activate soft keys"
2382 ,"a/d -- activate/disable soft keys"
2383 ,"c -- set centered format for labels"
2384 ,"l -- set left-justified format for labels"
2385 ,"r -- set right-justified format for labels"
2386 ,"[12345678] -- set label; labels are numbered 1 through 8"
2387 ,"e -- erase stdscr (should not erase labels)"
2388 ,"s -- test scrolling of shortened screen"
2390 ,"F/B -- cycle through foreground/background colors"
2392 ,"ESC -- return to main menu"
2394 ,"Note: if activating the soft keys causes your terminal to scroll up"
2395 ,"one line, your terminal auto-scrolls when anything is written to the"
2396 ,"last screen position. The ncurses code does not yet handle this"
2402 for (j = 0; j < SIZEOF(table); ++j) {
2410 call_slk_color(short fg, short bg)
2412 init_pair(1, bg, fg);
2414 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2422 /* exercise the soft keys */
2428 short fg = COLOR_BLACK;
2429 short bg = COLOR_WHITE;
2435 call_slk_color(fg, bg);
2445 mvaddstr(0, 20, "Soft Key Exerciser");
2460 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2461 while ((c = Getchar()) != 'Q' && (c != ERR))
2489 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2491 if ((s = slk_label(c - '0')) != 0) {
2494 wGetstring(stdscr, buf, 8);
2495 slk_set((c - '0'), buf, fmt);
2507 fg = (fg + 1) % COLORS;
2508 call_slk_color(fg, bg);
2513 bg = (bg + 1) % COLORS;
2514 call_slk_color(fg, bg);
2523 ((c = Getchar()) != EOF);
2531 #if USE_WIDEC_SUPPORT
2535 /* exercise the soft keys */
2538 wchar_t buf[SLKLEN + 1];
2540 short fg = COLOR_BLACK;
2541 short bg = COLOR_WHITE;
2545 call_slk_color(fg, bg);
2552 attr_on(WA_BOLD, NULL);
2553 mvaddstr(0, 20, "Soft Key Exerciser");
2554 attr_off(WA_BOLD, NULL);
2568 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2569 while ((c = Getchar()) != 'Q' && (c != ERR))
2597 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2599 if ((s = slk_label(c - '0')) != 0) {
2600 char *temp = strdup(s);
2601 size_t used = strlen(temp);
2602 size_t want = SLKLEN;
2607 while (want > 0 && used != 0) {
2608 const char *base = s;
2609 memset(&state, 0, sizeof(state));
2610 test = mbsrtowcs(0, &base, 0, &state);
2611 if (test == (size_t) -1) {
2613 } else if (test > want) {
2616 memset(&state, 0, sizeof(state));
2617 mbsrtowcs(buf, &base, want, &state);
2623 wGet_wstring(stdscr, buf, SLKLEN);
2624 slk_wset((c - '0'), buf, fmt);
2635 fg = (fg + 1) % COLORS;
2636 call_slk_color(fg, bg);
2641 bg = (bg + 1) % COLORS;
2642 call_slk_color(fg, bg);
2650 ((c = Getchar()) != EOF);
2658 #endif /* SLK_INIT */
2660 /****************************************************************************
2662 * Alternate character-set stuff
2664 ****************************************************************************/
2666 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2667 * terminal to perform functions. The remaining codes can be graphic.
2670 show_upper_chars(unsigned first)
2672 bool C1 = (first == 128);
2674 unsigned last = first + 31;
2679 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2680 C1 ? "C1" : "GR", first, last);
2684 for (code = first; code <= last; code++) {
2685 int row = 2 + ((code - first) % 16);
2686 int col = ((code - first) / 16) * COLS / 2;
2688 sprintf(tmp, "%3u (0x%x)", code, code);
2689 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2691 nodelay(stdscr, TRUE);
2694 /* (yes, this _is_ crude) */
2695 while ((reply = Getchar()) != ERR) {
2696 addch(UChar(reply));
2699 nodelay(stdscr, FALSE);
2711 mvprintw(0, 20, "Display of PC Character Codes");
2715 for (code = 0; code < 16; ++code) {
2716 mvprintw(2, (int) code * 3 + 8, "%X", code);
2718 for (code = 0; code < 256; code++) {
2719 int row = 3 + (code / 16) + (code >= 128);
2720 int col = 8 + (code % 16) * 3;
2721 if ((code % 16) == 0)
2722 mvprintw(row, 0, "0x%02x:", code);
2732 * Skip the ones that do not work.
2736 addch(code | A_ALTCHARSET);
2743 show_box_chars(void)
2747 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
2752 mvhline(LINES / 2, 0, ACS_HLINE, COLS);
2753 mvvline(0, COLS / 2, ACS_VLINE, LINES);
2754 mvaddch(0, COLS / 2, ACS_TTEE);
2755 mvaddch(LINES / 2, COLS / 2, ACS_PLUS);
2756 mvaddch(LINES - 1, COLS / 2, ACS_BTEE);
2757 mvaddch(LINES / 2, 0, ACS_LTEE);
2758 mvaddch(LINES / 2, COLS - 1, ACS_RTEE);
2764 show_1_acs(int n, const char *name, chtype code)
2766 const int height = 16;
2767 int row = 2 + (n % height);
2768 int col = (n / height) * COLS / 2;
2769 mvprintw(row, col, "%*s : ", COLS / 4, name);
2775 show_acs_chars(void)
2776 /* display the ACS character set */
2780 #define BOTH(name) #name, name
2784 mvaddstr(0, 20, "Display of the ACS Character Set");
2788 n = show_1_acs(0, BOTH(ACS_ULCORNER));
2789 n = show_1_acs(n, BOTH(ACS_URCORNER));
2790 n = show_1_acs(n, BOTH(ACS_LLCORNER));
2791 n = show_1_acs(n, BOTH(ACS_LRCORNER));
2793 n = show_1_acs(n, BOTH(ACS_LTEE));
2794 n = show_1_acs(n, BOTH(ACS_RTEE));
2795 n = show_1_acs(n, BOTH(ACS_TTEE));
2796 n = show_1_acs(n, BOTH(ACS_BTEE));
2798 n = show_1_acs(n, BOTH(ACS_HLINE));
2799 n = show_1_acs(n, BOTH(ACS_VLINE));
2802 * HPUX's ACS definitions are broken here. Just give up.
2804 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
2805 n = show_1_acs(n, BOTH(ACS_LARROW));
2806 n = show_1_acs(n, BOTH(ACS_RARROW));
2807 n = show_1_acs(n, BOTH(ACS_UARROW));
2808 n = show_1_acs(n, BOTH(ACS_DARROW));
2810 n = show_1_acs(n, BOTH(ACS_BLOCK));
2811 n = show_1_acs(n, BOTH(ACS_BOARD));
2812 n = show_1_acs(n, BOTH(ACS_LANTERN));
2813 n = show_1_acs(n, BOTH(ACS_BULLET));
2814 n = show_1_acs(n, BOTH(ACS_CKBOARD));
2815 n = show_1_acs(n, BOTH(ACS_DEGREE));
2816 n = show_1_acs(n, BOTH(ACS_DIAMOND));
2817 n = show_1_acs(n, BOTH(ACS_PLMINUS));
2818 n = show_1_acs(n, BOTH(ACS_PLUS));
2820 n = show_1_acs(n, BOTH(ACS_GEQUAL));
2821 n = show_1_acs(n, BOTH(ACS_NEQUAL));
2822 n = show_1_acs(n, BOTH(ACS_LEQUAL));
2824 n = show_1_acs(n, BOTH(ACS_STERLING));
2825 n = show_1_acs(n, BOTH(ACS_PI));
2826 n = show_1_acs(n, BOTH(ACS_S1));
2827 n = show_1_acs(n, BOTH(ACS_S3));
2828 n = show_1_acs(n, BOTH(ACS_S7));
2829 n = show_1_acs(n, BOTH(ACS_S9));
2837 char *term = getenv("TERM");
2838 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
2857 show_upper_chars((unsigned) ((c - '0') * 32 + 128));
2866 mvprintw(LINES - 3, 0,
2867 "Note: ANSI terminals may not display C1 characters.");
2868 mvprintw(LINES - 2, 0,
2869 "Select: a=ACS, x=box, %s0=C1, 1,2,3=GR characters, ESC=quit",
2872 } while (!isQuit(c = Getchar()));
2879 #if USE_WIDEC_SUPPORT
2881 merge_wide_attr(cchar_t *dst, cchar_t *src, attr_t attr, short pair)
2883 int count = getcchar(src, NULL, NULL, NULL, 0);
2890 if ((wch = typeMalloc(wchar_t, count)) != 0) {
2891 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
2892 attr |= (ignore_attr & A_ALTCHARSET);
2893 setcchar(dst, wch, attr, pair, 0);
2902 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
2906 int last = first + 31;
2910 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
2913 for (code = first; code <= last; code++) {
2914 int row = 2 + ((code - first) % 16);
2915 int col = ((code - first) / 16) * COLS / 2;
2921 memset(&codes, 0, sizeof(codes));
2923 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
2924 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2925 setcchar(&temp, codes, attr, pair, 0);
2928 * Give non-spacing characters something to combine with. If we
2929 * don't, they'll bunch up in a heap on the space after the ":".
2930 * Mark them with reverse-video to make them simpler to find on
2933 if (wcwidth(code) == 0)
2934 addch(space | A_REVERSE);
2936 * This could use add_wch(), but is done for comparison with the
2937 * normal 'f' test (and to make a test-case for echo_wchar()).
2938 * The screen will flicker because the erase() at the top of the
2939 * function is met by the builtin refresh() in echo_wchar().
2943 * The repeat-count may make text wrap - avoid that.
2945 getyx(stdscr, y, x);
2946 if (x >= col + (COLS / 2) - 2)
2948 } while (--count > 0);
2953 show_1_wacs(int n, const char *name, const cchar_t *code)
2955 const int height = 16;
2956 int row = 2 + (n % height);
2957 int col = (n / height) * COLS / 2;
2958 mvprintw(row, col, "%*s : ", COLS / 4, name);
2959 add_wchnstr(code, 1);
2963 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
2966 show_wacs_chars(attr_t attr, short pair)
2967 /* display the wide-ACS character set */
2973 /*#define BOTH2(name) #name, &(name) */
2974 #define BOTH2(name) #name, MERGE_ATTR(name)
2978 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
2982 n = show_1_wacs(0, BOTH2(WACS_ULCORNER));
2983 n = show_1_wacs(n, BOTH2(WACS_URCORNER));
2984 n = show_1_wacs(n, BOTH2(WACS_LLCORNER));
2985 n = show_1_wacs(n, BOTH2(WACS_LRCORNER));
2987 n = show_1_wacs(n, BOTH2(WACS_LTEE));
2988 n = show_1_wacs(n, BOTH2(WACS_RTEE));
2989 n = show_1_wacs(n, BOTH2(WACS_TTEE));
2990 n = show_1_wacs(n, BOTH2(WACS_BTEE));
2992 n = show_1_wacs(n, BOTH2(WACS_HLINE));
2993 n = show_1_wacs(n, BOTH2(WACS_VLINE));
2995 n = show_1_wacs(n, BOTH2(WACS_LARROW));
2996 n = show_1_wacs(n, BOTH2(WACS_RARROW));
2997 n = show_1_wacs(n, BOTH2(WACS_UARROW));
2998 n = show_1_wacs(n, BOTH2(WACS_DARROW));
3000 n = show_1_wacs(n, BOTH2(WACS_BLOCK));
3001 n = show_1_wacs(n, BOTH2(WACS_BOARD));
3002 n = show_1_wacs(n, BOTH2(WACS_LANTERN));
3003 n = show_1_wacs(n, BOTH2(WACS_BULLET));
3004 n = show_1_wacs(n, BOTH2(WACS_CKBOARD));
3005 n = show_1_wacs(n, BOTH2(WACS_DEGREE));
3006 n = show_1_wacs(n, BOTH2(WACS_DIAMOND));
3007 n = show_1_wacs(n, BOTH2(WACS_PLMINUS));
3008 n = show_1_wacs(n, BOTH2(WACS_PLUS));
3010 #ifdef CURSES_WACS_ARRAY
3011 n = show_1_wacs(n, BOTH2(WACS_GEQUAL));
3012 n = show_1_wacs(n, BOTH2(WACS_NEQUAL));
3013 n = show_1_wacs(n, BOTH2(WACS_LEQUAL));
3015 n = show_1_wacs(n, BOTH2(WACS_STERLING));
3016 n = show_1_wacs(n, BOTH2(WACS_PI));
3017 n = show_1_wacs(n, BOTH2(WACS_S1));
3018 n = show_1_wacs(n, BOTH2(WACS_S3));
3019 n = show_1_wacs(n, BOTH2(WACS_S7));
3020 n = show_1_wacs(n, BOTH2(WACS_S9));
3026 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3029 show_wbox_chars(attr_t attr, short pair)
3035 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3039 attr_set(attr, pair, 0);
3040 box_set(stdscr, 0, 0);
3041 attr_set(A_NORMAL, 0, 0);
3043 mvhline_set(LINES / 2, 0, MERGE_ATTR(WACS_HLINE), COLS);
3044 mvvline_set(0, COLS / 2, MERGE_ATTR(WACS_VLINE), LINES);
3045 mvadd_wch(0, COLS / 2, MERGE_ATTR(WACS_TTEE));
3046 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(WACS_PLUS));
3047 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(WACS_BTEE));
3048 mvadd_wch(LINES / 2, 0, MERGE_ATTR(WACS_LTEE));
3049 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(WACS_RTEE));
3057 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3059 const int height = 16;
3060 int row = 2 + (n % height);
3061 int col = (n / height) * COLS / 2;
3064 mvprintw(row, col, "%*s : ", COLS / 4, name);
3065 attr_set(attr, pair, 0);
3066 addstr(strcpy(temp, code));
3067 attr_set(A_NORMAL, 0, 0);
3071 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3074 show_utf8_chars(attr_t attr, short pair)
3080 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3084 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3085 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3086 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3087 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3089 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3090 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3091 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3092 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3094 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3095 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3097 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3098 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3099 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3100 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3102 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3103 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3104 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3105 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3106 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3107 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3108 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3109 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3110 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3111 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3112 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3113 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3115 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3116 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3117 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3118 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3119 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3120 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3128 } attrs_to_cycle[] = {
3129 { A_NORMAL, "normal" },
3131 { A_REVERSE, "reverse" },
3132 { A_UNDERLINE, "underline" },
3137 cycle_attr(int ch, unsigned *at_code, chtype *attr)
3143 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
3148 *at_code = SIZEOF(attrs_to_cycle) - 1;
3157 *attr = attrs_to_cycle[*at_code].attr;
3162 cycle_colors(int ch, int *fg, int *bg, short *pair)
3164 bool result = FALSE;
3174 if ((*fg += 1) >= COLORS)
3190 *pair = (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3193 if (init_pair(*pair, *fg, *bg) == ERR) {
3202 /* display the wide-ACS character set */
3204 wide_acs_display(void)
3210 chtype attr = A_NORMAL;
3211 int fg = COLOR_BLACK;
3212 int bg = COLOR_BLACK;
3213 unsigned at_code = 0;
3215 void (*last_show_wacs) (attr_t, short) = 0;
3223 last_show_wacs = show_wacs_chars;
3226 last_show_wacs = show_wbox_chars;
3229 last_show_wacs = show_utf8_chars;
3232 if (c < 256 && isdigit(c)) {
3234 } else if (c == '+') {
3236 } else if (c == '-' && digit > 0) {
3238 } else if (c == '>' && repeat < (COLS / 4)) {
3240 } else if (c == '<' && repeat > 0) {
3242 } else if (c == '_') {
3243 space = (space == ' ') ? '_' : ' ';
3244 } else if (cycle_attr(c, &at_code, &attr)
3245 || cycle_colors(c, &fg, &bg, &pair)) {
3246 if (last_show_wacs != 0)
3253 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3256 if (last_show_wacs != 0)
3257 last_show_wacs(attr, pair);
3259 mvprintw(LINES - 3, 0,
3260 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3262 mvprintw(LINES - 2, 0,
3263 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3264 attrs_to_cycle[at_code].name,
3267 mvprintw(LINES - 2, 0,
3268 "v/V cycles through video attributes (%s).",
3269 attrs_to_cycle[at_code].name);
3272 } while (!isQuit(c = Getchar()));
3282 * Graphic-rendition test (adapted from vttest)
3285 test_sgr_attributes(void)
3289 for (pass = 0; pass < 2; pass++) {
3290 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3292 /* Use non-default colors if possible to exercise bce a little */
3294 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3295 normal |= COLOR_PAIR(1);
3299 mvprintw(1, 20, "Graphic rendition test pattern:");
3301 mvprintw(4, 1, "vanilla");
3303 #define set_sgr(mask) bkgdset((normal^(mask)));
3305 mvprintw(4, 40, "bold");
3307 set_sgr(A_UNDERLINE);
3308 mvprintw(6, 6, "underline");
3310 set_sgr(A_BOLD | A_UNDERLINE);
3311 mvprintw(6, 45, "bold underline");
3314 mvprintw(8, 1, "blink");
3316 set_sgr(A_BLINK | A_BOLD);
3317 mvprintw(8, 40, "bold blink");
3319 set_sgr(A_UNDERLINE | A_BLINK);
3320 mvprintw(10, 6, "underline blink");
3322 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3323 mvprintw(10, 45, "bold underline blink");
3326 mvprintw(12, 1, "negative");
3328 set_sgr(A_BOLD | A_REVERSE);
3329 mvprintw(12, 40, "bold negative");
3331 set_sgr(A_UNDERLINE | A_REVERSE);
3332 mvprintw(14, 6, "underline negative");
3334 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3335 mvprintw(14, 45, "bold underline negative");
3337 set_sgr(A_BLINK | A_REVERSE);
3338 mvprintw(16, 1, "blink negative");
3340 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3341 mvprintw(16, 40, "bold blink negative");
3343 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3344 mvprintw(18, 6, "underline blink negative");
3346 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3347 mvprintw(18, 45, "bold underline blink negative");
3350 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3356 bkgdset(A_NORMAL | BLANK);
3361 /****************************************************************************
3363 * Windows and scrolling tester.
3365 ****************************************************************************/
3367 #define BOTLINES 4 /* number of line stolen from screen bottom */
3373 #define FRAME struct frame
3382 #if defined(NCURSES_VERSION)
3383 #if NCURSES_VERSION_PATCH < 20070331
3384 #define is_keypad(win) (win)->_use_keypad
3385 #define is_scrollok(win) (win)->_scroll
3388 #define is_keypad(win) FALSE
3389 #define is_scrollok(win) FALSE
3392 /* We need to know if these flags are actually set, so don't look in FRAME.
3393 * These names are known to work with SVr4 curses as well as ncurses. The
3394 * _use_keypad name does not work with Solaris 8.
3397 HaveKeypad(FRAME * curp)
3399 WINDOW *win = (curp ? curp->wind : stdscr);
3401 return is_keypad(win);
3405 HaveScroll(FRAME * curp)
3407 WINDOW *win = (curp ? curp->wind : stdscr);
3409 return is_scrollok(win);
3413 newwin_legend(FRAME * curp)
3415 static const struct {
3420 "^C = create window", 0
3423 "^N = next window", 0
3426 "^P = previous window", 0
3429 "^F = scroll forward", 0
3432 "^B = scroll backward", 0
3435 "^K = keypad(%s)", 1
3438 "^S = scrollok(%s)", 2
3441 "^W = save window to file", 0
3444 "^R = restore window", 0
3457 bool do_keypad = HaveKeypad(curp);
3458 bool do_scroll = HaveScroll(curp);
3462 for (n = 0; n < SIZEOF(legend); n++) {
3463 switch (legend[n].code) {
3465 strcpy(buf, legend[n].msg);
3468 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3471 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3474 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3477 x = getcurx(stdscr);
3478 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3485 transient(FRAME * curp, NCURSES_CONST char *msg)
3487 newwin_legend(curp);
3489 mvaddstr(LINES - 1, 0, msg);
3495 printw("%s characters are echoed, window should %sscroll.",
3496 HaveKeypad(curp) ? "Non-arrow" : "All other",
3497 HaveScroll(curp) ? "" : "not ");
3502 newwin_report(FRAME * curp)
3503 /* report on the cursor's current position, then restore it */
3505 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
3509 transient(curp, (char *) 0);
3511 move(LINES - 1, COLS - 17);
3512 printw("Y = %2d X = %2d", y, x);
3520 selectcell(int uli, int ulj, int lri, int lrj)
3521 /* arrows keys move cursor, return location at current on non-arrow key */
3523 static pair res; /* result cell */
3524 int si = lri - uli + 1; /* depth of the select area */
3525 int sj = lrj - ulj + 1; /* width of the select area */
3526 int i = 0, j = 0; /* offsets into the select area */
3531 move(uli + i, ulj + j);
3532 newwin_report((FRAME *) 0);
3534 switch (Getchar()) {
3548 return ((pair *) 0);
3549 #ifdef NCURSES_MOUSE_VERSION
3555 if (event.y > uli && event.x > ulj) {
3576 outerbox(pair ul, pair lr, bool onoff)
3577 /* draw or erase a box *outside* the given pair of corners */
3579 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3580 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3581 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3582 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3583 move(ul.y - 1, ul.x);
3584 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3585 move(ul.y, ul.x - 1);
3586 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3587 move(lr.y + 1, ul.x);
3588 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3589 move(ul.y, lr.x + 1);
3590 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3595 /* Ask user for a window definition */
3602 addstr("Use arrows to move cursor, anything else to mark corner 1");
3604 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3605 return ((WINDOW *) 0);
3606 memcpy(&ul, tmp, sizeof(pair));
3607 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3610 addstr("Use arrows to move cursor, anything else to mark corner 2");
3612 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
3614 return ((WINDOW *) 0);
3615 memcpy(&lr, tmp, sizeof(pair));
3617 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
3619 outerbox(ul, lr, TRUE);
3630 newwin_move(FRAME * curp, int dy, int dx)
3632 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
3636 getyx(win, cur_y, cur_x);
3637 getmaxyx(win, max_y, max_x);
3638 if ((cur_x += dx) < 0)
3640 else if (cur_x >= max_x)
3642 if ((cur_y += dy) < 0)
3644 else if (cur_y >= max_y)
3646 wmove(win, cur_y, cur_x);
3650 delete_framed(FRAME * fp, bool showit)
3654 fp->last->next = fp->next;
3655 fp->next->last = fp->last;
3663 np = (fp == fp->next) ? 0 : fp->next;
3669 acs_and_scroll(void)
3670 /* Demonstrate windows */
3673 FRAME *current = (FRAME *) 0, *neww;
3674 WINDOW *usescr = stdscr;
3675 #if HAVE_PUTWIN && HAVE_GETWIN
3679 #define DUMPFILE "screendump"
3681 #ifdef NCURSES_MOUSE_VERSION
3682 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
3687 transient((FRAME *) 0, (char *) 0);
3690 neww = (FRAME *) calloc(1, sizeof(FRAME));
3691 if ((neww->wind = getwindow()) == (WINDOW *) 0)
3694 if (current == 0) { /* First element, */
3695 neww->next = neww; /* so point it at itself */
3698 neww->next = current->next;
3699 neww->last = current;
3700 neww->last->next = neww;
3701 neww->next->last = neww;
3704 /* SVr4 curses sets the keypad on all newly-created windows to
3705 * false. Someone reported that PDCurses makes new windows inherit
3706 * this flag. Remove the following 'keypad()' call to test this
3708 keypad(current->wind, TRUE);
3709 current->do_keypad = HaveKeypad(current);
3710 current->do_scroll = HaveScroll(current);
3713 case CTRL('N'): /* go to next window */
3715 current = current->next;
3718 case CTRL('P'): /* go to previous window */
3720 current = current->last;
3723 case CTRL('F'): /* scroll current window forward */
3725 wscrl(current->wind, 1);
3728 case CTRL('B'): /* scroll current window backwards */
3730 wscrl(current->wind, -1);
3733 case CTRL('K'): /* toggle keypad mode for current */
3735 current->do_keypad = !current->do_keypad;
3736 keypad(current->wind, current->do_keypad);
3742 current->do_scroll = !current->do_scroll;
3743 scrollok(current->wind, current->do_scroll);
3747 #if HAVE_PUTWIN && HAVE_GETWIN
3748 case CTRL('W'): /* save and delete window */
3749 if (current == current->next) {
3750 transient(current, "Will not save/delete ONLY window");
3752 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
3753 transient(current, "Can't open screen dump file");
3755 (void) putwin(current->wind, fp);
3758 current = delete_framed(current, TRUE);
3762 case CTRL('R'): /* restore window */
3763 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
3764 transient(current, "Can't open screen dump file");
3766 neww = (FRAME *) calloc(1, sizeof(FRAME));
3768 neww->next = current->next;
3769 neww->last = current;
3770 neww->last->next = neww;
3771 neww->next->last = neww;
3773 neww->wind = getwin(fp);
3776 wrefresh(neww->wind);
3782 case CTRL('X'): /* resize window */
3789 addstr("Use arrows to move cursor, anything else to mark new corner");
3792 getbegyx(current->wind, ul.y, ul.x);
3794 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
3795 if (tmp == (pair *) 0) {
3800 getmaxyx(current->wind, lr.y, lr.x);
3803 outerbox(ul, lr, FALSE);
3804 wnoutrefresh(stdscr);
3806 /* strictly cosmetic hack for the test */
3807 getmaxyx(current->wind, my, mx);
3808 if (my > tmp->y - ul.y) {
3809 getyx(current->wind, lr.y, lr.x);
3810 wmove(current->wind, tmp->y - ul.y + 1, 0);
3811 wclrtobot(current->wind);
3812 wmove(current->wind, lr.y, lr.x);
3814 if (mx > tmp->x - ul.x)
3815 for (i = 0; i < my; i++) {
3816 wmove(current->wind, i, tmp->x - ul.x + 1);
3817 wclrtoeol(current->wind);
3819 wnoutrefresh(current->wind);
3821 memcpy(&lr, tmp, sizeof(pair));
3822 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
3824 getbegyx(current->wind, ul.y, ul.x);
3825 getmaxyx(current->wind, lr.y, lr.x);
3828 outerbox(ul, lr, TRUE);
3829 wnoutrefresh(stdscr);
3831 wnoutrefresh(current->wind);
3837 #endif /* HAVE_WRESIZE */
3839 case KEY_F(10): /* undocumented --- use this to test area clears */
3840 selectcell(0, 0, LINES - 1, COLS - 1);
3846 newwin_move(current, -1, 0);
3849 newwin_move(current, 1, 0);
3852 newwin_move(current, 0, -1);
3855 newwin_move(current, 0, 1);
3863 getyx(current->wind, y, x);
3867 x = getmaxx(current->wind) - 1;
3869 mvwdelch(current->wind, y, x);
3879 waddch(current->wind, (chtype) c);
3884 newwin_report(current);
3885 usescr = (current ? current->wind : stdscr);
3888 (!isQuit(c = wGetchar(usescr))
3892 while (current != 0)
3893 current = delete_framed(current, FALSE);
3895 scrollok(stdscr, TRUE); /* reset to driver's default */
3896 #ifdef NCURSES_MOUSE_VERSION
3897 mousemask(0, (mmask_t *) 0);
3904 /****************************************************************************
3908 ****************************************************************************/
3911 static int nap_msec = 1;
3913 static NCURSES_CONST char *mod[] =
3923 /*+-------------------------------------------------------------------------
3925 --------------------------------------------------------------------------*/
3927 wait_a_while(int msec GCC_UNUSED)
3937 else if (msec > 1000)
3938 sleep((unsigned) msec / 1000);
3942 } /* end of wait_a_while */
3944 /*+-------------------------------------------------------------------------
3946 --------------------------------------------------------------------------*/
3948 saywhat(NCURSES_CONST char *text)
3950 wmove(stdscr, LINES - 1, 0);
3952 if (text != 0 && *text != '\0') {
3953 waddstr(stdscr, text);
3954 waddstr(stdscr, "; ");
3956 waddstr(stdscr, "press any key to continue");
3957 } /* end of saywhat */
3959 /*+-------------------------------------------------------------------------
3960 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
3961 --------------------------------------------------------------------------*/
3963 mkpanel(short color, int rows, int cols, int tly, int tlx)
3968 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
3969 if ((pan = new_panel(win)) == 0) {
3971 } else if (use_colors) {
3972 short fg = (color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK;
3975 init_pair(color, fg, bg);
3976 wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
3978 wbkgdset(win, A_BOLD | ' ');
3982 } /* end of mkpanel */
3984 /*+-------------------------------------------------------------------------
3986 --------------------------------------------------------------------------*/
3988 rmpanel(PANEL * pan)
3990 WINDOW *win = panel_window(pan);
3993 } /* end of rmpanel */
3995 /*+-------------------------------------------------------------------------
3997 --------------------------------------------------------------------------*/
4003 } /* end of pflush */
4005 /*+-------------------------------------------------------------------------
4007 --------------------------------------------------------------------------*/
4013 for (y = 0; y < LINES - 1; y++) {
4014 for (x = 0; x < COLS; x++)
4015 wprintw(stdscr, "%d", (y + x) % 10);
4020 fill_panel(PANEL * pan)
4022 WINDOW *win = panel_window(pan);
4023 int num = ((const char *) panel_userptr(pan))[1];
4027 wprintw(win, "-pan%c-", num);
4030 for (y = 2; y < getmaxy(win) - 1; y++) {
4031 for (x = 1; x < getmaxx(win) - 1; x++) {
4033 waddch(win, UChar(num));
4038 #if USE_WIDEC_SUPPORT
4040 make_fullwidth_digit(cchar_t *target, int digit)
4044 source[0] = digit + 0xff10;
4046 setcchar(target, source, A_NORMAL, 0, 0);
4050 init_wide_panel(void)
4055 for (digit = 0; digit < 10; ++digit)
4056 make_fullwidth_digit(&temp[digit], digit);
4060 getyx(stdscr, y, x);
4061 digit = (y + x / 2) % 10;
4062 } while (add_wch(&temp[digit]) != ERR);
4066 fill_wide_panel(PANEL * pan)
4068 WINDOW *win = panel_window(pan);
4069 int num = ((const char *) panel_userptr(pan))[1];
4073 wprintw(win, "-pan%c-", num);
4076 for (y = 2; y < getmaxy(win) - 1; y++) {
4077 for (x = 1; x < getmaxx(win) - 1; x++) {
4079 waddch(win, UChar(num));
4085 #define MAX_PANELS 5
4088 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4090 int which = cmd[1] - '0';
4095 hide_panel(px[which]);
4098 show_panel(px[which]);
4101 top_panel(px[which]);
4104 bottom_panel(px[which]);
4111 wait_a_while(nap_msec);
4115 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4119 PANEL *px[MAX_PANELS + 1];
4121 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4125 for (count = 0; count < 5; count++) {
4126 px[1] = mkpanel(COLOR_RED,
4131 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4133 px[2] = mkpanel(COLOR_GREEN,
4138 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4140 px[3] = mkpanel(COLOR_YELLOW,
4145 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4147 px[4] = mkpanel(COLOR_BLUE,
4152 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4154 px[5] = mkpanel(COLOR_MAGENTA,
4159 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4171 wait_a_while(nap_msec);
4173 saywhat("h3 s1 s2 s4 s5");
4174 move_panel(px[1], 0, 0);
4181 wait_a_while(nap_msec);
4183 canned_panel(px, "s1");
4184 canned_panel(px, "s2");
4187 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4189 wait_a_while(nap_msec);
4191 canned_panel(px, "s3");
4194 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4196 wait_a_while(nap_msec);
4198 canned_panel(px, "b3");
4199 canned_panel(px, "s4");
4200 canned_panel(px, "s5");
4201 canned_panel(px, "t3");
4202 canned_panel(px, "t1");
4203 canned_panel(px, "t2");
4204 canned_panel(px, "t3");
4205 canned_panel(px, "t4");
4207 for (itmp = 0; itmp < 6; itmp++) {
4208 WINDOW *w4 = panel_window(px[4]);
4209 WINDOW *w5 = panel_window(px[5]);
4212 wmove(w4, LINES / 8, 1);
4213 waddstr(w4, mod[itmp]);
4214 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4215 wmove(w5, LINES / 6, 1);
4216 waddstr(w5, mod[itmp]);
4218 wait_a_while(nap_msec);
4221 wmove(w4, LINES / 6, 1);
4222 waddstr(w4, mod[itmp]);
4223 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4224 wmove(w5, LINES / 8, 1);
4225 waddstr(w5, mod[itmp]);
4227 wait_a_while(nap_msec);
4231 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4233 wait_a_while(nap_msec);
4235 canned_panel(px, "t5");
4236 canned_panel(px, "t2");
4237 canned_panel(px, "t1");
4238 canned_panel(px, "d2");
4239 canned_panel(px, "h3");
4240 canned_panel(px, "d1");
4241 canned_panel(px, "d4");
4242 canned_panel(px, "d5");
4243 canned_panel(px, "d3");
4245 wait_a_while(nap_msec);
4254 #endif /* USE_LIBPANEL */
4256 /****************************************************************************
4260 ****************************************************************************/
4264 static bool pending_pan = FALSE;
4265 static bool show_panner_legend = TRUE;
4268 panner_legend(int line)
4270 static const char *const legend[] =
4272 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4273 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4274 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4275 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4277 int n = (SIZEOF(legend) - (LINES - line));
4278 if (line < LINES && (n >= 0)) {
4280 if (show_panner_legend)
4281 printw("%s", legend[n]);
4283 return show_panner_legend;
4289 panner_h_cleanup(int from_y, int from_x, int to_x)
4291 if (!panner_legend(from_y))
4292 do_h_line(from_y, from_x, ' ', to_x);
4296 panner_v_cleanup(int from_y, int from_x, int to_y)
4298 if (!panner_legend(from_y))
4299 do_v_line(from_y, from_x, ' ', to_y);
4303 fill_pad(WINDOW *panpad, bool pan_lines)
4306 unsigned gridcount = 0;
4308 wmove(panpad, 0, 0);
4309 for (y = 0; y < getmaxy(panpad); y++) {
4310 for (x = 0; x < getmaxx(panpad); x++) {
4311 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4312 if (y == 0 && x == 0)
4313 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4315 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4316 else if (y == 0 || x == 0)
4317 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4319 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4320 (gridcount++ % 26)));
4321 } else if (y % GRIDSIZE == 0)
4322 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4323 else if (x % GRIDSIZE == 0)
4324 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4326 waddch(panpad, ' ');
4333 int top_x, int top_y, int porty, int portx,
4334 int (*pgetc) (WINDOW *))
4336 #if HAVE_GETTIMEOFDAY
4337 struct timeval before, after;
4340 bool pan_lines = FALSE;
4341 bool scrollers = TRUE;
4344 int pxmax, pymax, lowend, highend, c;
4346 getmaxyx(pad, pymax, pxmax);
4347 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4351 #ifdef NCURSES_VERSION
4353 * During shell-out, the user may have resized the window. Adjust
4354 * the port size of the pad to accommodate this. Ncurses automatically
4355 * resizes all of the normal windows to fit on the new screen.
4373 show_panner_legend = !show_panner_legend;
4374 panner_legend(LINES - 4);
4375 panner_legend(LINES - 3);
4376 panner_legend(LINES - 2);
4377 panner_legend(LINES - 1);
4380 pan_lines = !pan_lines;
4381 fill_pad(pad, pan_lines);
4382 pending_pan = FALSE;
4385 #if HAVE_GETTIMEOFDAY
4389 panner_legend(LINES - 1);
4393 scrollers = !scrollers;
4396 /* Move the top-left corner of the pad, keeping the bottom-right
4399 case 'h': /* increase-columns: move left edge to left */
4403 panner_v_cleanup(top_y, top_x, porty);
4408 case 'j': /* decrease-lines: move top-edge down */
4412 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
4417 case 'k': /* increase-lines: move top-edge up */
4422 panner_h_cleanup(top_y, top_x, portx);
4426 case 'l': /* decrease-columns: move left-edge to right */
4430 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
4435 /* Move the bottom-right corner of the pad, keeping the top-left
4438 case KEY_IC: /* increase-columns: move right-edge to right */
4439 if (portx >= pxmax || portx >= COLS)
4442 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
4447 case KEY_IL: /* increase-lines: move bottom-edge down */
4448 if (porty >= pymax || porty >= LINES)
4451 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
4456 case KEY_DC: /* decrease-columns: move bottom edge up */
4461 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
4465 case KEY_DL: /* decrease-lines */
4470 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
4474 case KEY_LEFT: /* pan leftwards */
4481 case KEY_RIGHT: /* pan rightwards */
4482 if (basex + portx - (pymax > porty) < pxmax)
4488 case KEY_UP: /* pan upwards */
4495 case KEY_DOWN: /* pan downwards */
4496 if (basey + porty - (pxmax > portx) < pymax)
4511 basey = pymax - porty;
4521 mvaddch(top_y - 1, top_x - 1, ACS_ULCORNER);
4522 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
4523 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
4525 if (scrollers && (pxmax > portx - 1)) {
4526 int length = (portx - top_x - 1);
4527 float ratio = ((float) length) / ((float) pxmax);
4529 lowend = (int) (top_x + (basex * ratio));
4530 highend = (int) (top_x + ((basex + length) * ratio));
4532 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
4533 if (highend < portx) {
4535 do_h_line(porty - 1, lowend, ' ', highend + 1);
4537 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
4540 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
4542 if (scrollers && (pymax > porty - 1)) {
4543 int length = (porty - top_y - 1);
4544 float ratio = ((float) length) / ((float) pymax);
4546 lowend = (int) (top_y + (basey * ratio));
4547 highend = (int) (top_y + ((basey + length) * ratio));
4549 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
4550 if (highend < porty) {
4552 do_v_line(lowend, portx - 1, ' ', highend + 1);
4554 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
4557 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
4559 mvaddch(top_y - 1, portx - 1, ACS_URCORNER);
4560 mvaddch(porty - 1, top_x - 1, ACS_LLCORNER);
4561 mvaddch(porty - 1, portx - 1, ACS_LRCORNER);
4564 #if HAVE_GETTIMEOFDAY
4565 gettimeofday(&before, 0);
4567 wnoutrefresh(stdscr);
4572 porty - (pxmax > portx) - 1,
4573 portx - (pymax > porty) - 1);
4576 #if HAVE_GETTIMEOFDAY
4579 gettimeofday(&after, 0);
4580 elapsed = (after.tv_sec + after.tv_usec / 1.0e6)
4581 - (before.tv_sec + before.tv_usec / 1.0e6);
4582 move(LINES - 1, COLS - 12);
4583 printw("Secs: %2.03f", elapsed);
4590 ((c = pgetc(pad)) != KEY_EXIT);
4592 scrollok(stdscr, TRUE); /* reset to driver's default */
4596 padgetch(WINDOW *win)
4602 if ((pending_pan = (count > 0)) != FALSE) {
4604 pending_pan = (count != 0);
4607 switch (c = wGetchar(win)) {
4643 case ERR: /* FALLTHRU */
4649 if (c >= '0' && c <= '9') {
4650 count = count * 10 + (c - '0');
4664 #define PAD_HIGH 200
4665 #define PAD_WIDE 200
4669 /* Demonstrate pads. */
4671 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
4674 Cannot("cannot create requested pad");
4678 fill_pad(panpad, FALSE);
4680 panner_legend(LINES - 4);
4681 panner_legend(LINES - 3);
4682 panner_legend(LINES - 2);
4683 panner_legend(LINES - 1);
4685 keypad(panpad, TRUE);
4687 /* Make the pad (initially) narrow enough that a trace file won't wrap.
4688 * We'll still be able to widen it during a test, since that's required
4689 * for testing boundaries.
4691 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
4698 /****************************************************************************
4700 * Tests from John Burnell's PDCurses tester
4702 ****************************************************************************/
4705 Continue(WINDOW *win)
4709 mvwaddstr(win, 10, 1, " Press any key to continue");
4715 flushinp_test(WINDOW *win)
4716 /* Input test, adapted from John Burnell's PDCurses tester */
4718 int w, h, bx, by, sw, sh, i;
4723 getmaxyx(win, h, w);
4724 getbegyx(win, by, bx);
4727 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
4732 init_pair(2, COLOR_CYAN, COLOR_BLUE);
4733 wbkgd(subWin, COLOR_PAIR(2) | ' ');
4736 wattrset(subWin, A_BOLD);
4737 box(subWin, ACS_VLINE, ACS_HLINE);
4738 mvwaddstr(subWin, 2, 1, "This is a subwindow");
4742 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
4743 * it only happened to "work" on SVr4 because that implementation does not
4744 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
4745 * test behavior, we're using 'cbreak()', which will allow a single
4746 * character to return without needing a newline. - T.Dickey 1997/10/11.
4749 mvwaddstr(win, 0, 1, "This is a test of the flushinp() call.");
4751 mvwaddstr(win, 2, 1, "Type random keys for 5 seconds.");
4752 mvwaddstr(win, 3, 1,
4753 "These should be discarded (not echoed) after the subwindow goes away.");
4756 for (i = 0; i < 5; i++) {
4757 mvwprintw(subWin, 1, 1, "Time = %d", i);
4769 mvwaddstr(win, 2, 1,
4770 "If you were still typing when the window timer expired,");
4771 mvwaddstr(win, 3, 1,
4772 "or else you typed nothing at all while it was running,");
4773 mvwaddstr(win, 4, 1,
4774 "test was invalid. You'll see garbage or nothing at all. ");
4775 mvwaddstr(win, 6, 1, "Press a key");
4781 mvwaddstr(win, 12, 0,
4782 "If you see any key other than what you typed, flushinp() is broken.");
4791 "What you typed should now have been deleted; if not, wdelch() failed.");
4797 /****************************************************************************
4801 ****************************************************************************/
4809 menu_virtualize(int c)
4811 if (c == '\n' || c == KEY_EXIT)
4812 return (MAX_COMMAND + 1);
4814 return (REQ_SCR_ULINE);
4816 return (REQ_SCR_DLINE);
4817 else if (c == 'b' || c == KEY_NPAGE)
4818 return (REQ_SCR_UPAGE);
4819 else if (c == 'f' || c == KEY_PPAGE)
4820 return (REQ_SCR_DPAGE);
4821 else if (c == 'n' || c == KEY_DOWN)
4822 return (REQ_NEXT_ITEM);
4823 else if (c == 'p' || c == KEY_UP)
4824 return (REQ_PREV_ITEM);
4826 return (REQ_TOGGLE_ITEM);
4834 static const char *animals[] =
4847 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
4848 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
4856 ITEM *items[SIZEOF(animals)];
4859 int mrows, mcols, c;
4862 #ifdef NCURSES_MOUSE_VERSION
4863 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
4865 mvaddstr(0, 0, "This is the menu test:");
4866 mvaddstr(2, 0, " Use up and down arrow to move the select bar.");
4867 mvaddstr(3, 0, " 'n' and 'p' act like arrows.");
4869 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
4870 mvaddstr(5, 0, " Press return to exit.");
4873 for (ap = animals; *ap; ap++)
4874 *ip++ = new_item(*ap, "");
4877 m = new_menu(items);
4879 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
4880 scale_menu(m, &mrows, &mcols);
4882 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
4883 set_menu_win(m, menuwin);
4884 keypad(menuwin, TRUE);
4887 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
4891 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
4892 if (c == E_NOT_POSTED)
4894 if (c == E_REQUEST_DENIED)
4899 (void) mvprintw(LINES - 2, 0,
4900 "You chose: %s\n", item_name(current_item(m)));
4901 (void) addstr("Press any key to continue...");
4908 for (ip = items; *ip; ip++)
4910 #ifdef NCURSES_MOUSE_VERSION
4911 mousemask(0, (mmask_t *) 0);
4916 #define T_TBL(name) { #name, name }
4922 T_TBL(TRACE_DISABLE),
4925 T_TBL(TRACE_UPDATE),
4927 T_TBL(TRACE_CHARPUT),
4928 T_TBL(TRACE_ORDINARY),
4930 T_TBL(TRACE_VIRTPUT),
4931 T_TBL(TRACE_IEVENT),
4933 T_TBL(TRACE_ICALLS),
4934 T_TBL(TRACE_CCALLS),
4935 T_TBL(TRACE_DATABASE),
4937 T_TBL(TRACE_MAXIMUM),
4944 tracetrace(unsigned tlevel)
4951 for (n = 0; t_tbl[n].name != 0; n++)
4952 need += strlen(t_tbl[n].name) + 2;
4953 buf = (char *) malloc(need);
4955 sprintf(buf, "0x%02x = {", tlevel);
4957 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
4959 for (n = 1; t_tbl[n].name != 0; n++)
4960 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
4961 strcat(buf, t_tbl[n].name);
4965 if (buf[strlen(buf) - 2] == ',')
4966 buf[strlen(buf) - 2] = '\0';
4967 return (strcat(buf, "}"));
4970 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
4974 run_trace_menu(MENU * m)
4980 bool changed = FALSE;
4981 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
4982 case E_UNKNOWN_COMMAND:
4985 items = menu_items(m);
4986 i = current_item(m);
4987 if (i == items[0]) {
4988 if (item_value(i)) {
4989 for (p = items + 1; *p != 0; p++)
4990 if (item_value(*p)) {
4991 set_item_value(*p, FALSE);
4996 for (p = items + 1; *p != 0; p++)
4997 if (item_value(*p)) {
4998 set_item_value(items[0], FALSE);
5011 /* interactively set the trace level */
5014 ITEM *items[SIZEOF(t_tbl)];
5021 mvaddstr(0, 0, "Interactively set trace level:");
5022 mvaddstr(2, 0, " Press space bar to toggle a selection.");
5023 mvaddstr(3, 0, " Use up and down arrow to move the select bar.");
5024 mvaddstr(4, 0, " Press return to set the trace level.");
5025 mvprintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5029 for (n = 0; t_tbl[n].name != 0; n++)
5030 *ip++ = new_item(t_tbl[n].name, "");
5033 m = new_menu(items);
5035 set_menu_format(m, 0, 2);
5036 scale_menu(m, &mrows, &mcols);
5038 menu_opts_off(m, O_ONEVALUE);
5039 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5040 set_menu_win(m, menuwin);
5041 keypad(menuwin, TRUE);
5044 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5048 for (ip = menu_items(m); *ip; ip++) {
5049 unsigned mask = t_tbl[item_index(*ip)].mask;
5051 set_item_value(*ip, _nc_tracing == 0);
5052 else if ((mask & _nc_tracing) == mask)
5053 set_item_value(*ip, TRUE);
5056 while (run_trace_menu(m))
5060 for (ip = menu_items(m); *ip; ip++)
5061 if (item_value(*ip))
5062 newtrace |= t_tbl[item_index(*ip)].mask;
5064 _tracef("trace level interactively set to %s", tracetrace(_nc_tracing));
5066 (void) mvprintw(LINES - 2, 0,
5067 "Trace level is %s\n", tracetrace(_nc_tracing));
5068 (void) addstr("Press any key to continue...");
5075 for (ip = items; *ip; ip++)
5079 #endif /* USE_LIBMENU */
5081 /****************************************************************************
5085 ****************************************************************************/
5088 make_label(int frow, int fcol, NCURSES_CONST char *label)
5090 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5093 set_field_buffer(f, 0, label);
5094 set_field_opts(f, (int) (field_opts(f) & ~O_ACTIVE));
5100 make_field(int frow, int fcol, int rows, int cols, bool secure)
5102 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5105 set_field_back(f, A_UNDERLINE);
5106 set_field_userptr(f, (void *) 0);
5112 display_form(FORM * f)
5117 scale_form(f, &rows, &cols);
5119 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5121 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5126 if (post_form(f) != E_OK)
5131 erase_form(FORM * f)
5133 WINDOW *w = form_win(f);
5134 WINDOW *s = form_sub(f);
5144 edit_secure(FIELD * me, int c)
5146 int rows, cols, frow, fcol, nrow, nbuf;
5148 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5150 char *source = field_buffer(me, 1);
5154 strcpy(temp, source ? source : "");
5155 len = (long) (char *) field_userptr(me);
5157 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5160 set_field_buffer(me, 1, temp);
5180 case REQ_RIGHT_CHAR:
5182 c = 0; /* we don't want to do inline editing */
5187 set_field_buffer(me, 1, temp);
5194 set_field_buffer(me, 1, temp);
5199 set_field_userptr(me, (void *) len);
5205 form_virtualize(FORM * f, WINDOW *w)
5208 static const struct {
5212 { CTRL('A'), REQ_NEXT_CHOICE },
5213 { CTRL('B'), REQ_PREV_WORD },
5214 { CTRL('C'), REQ_CLR_EOL },
5215 { CTRL('D'), REQ_DOWN_FIELD },
5216 { CTRL('E'), REQ_END_FIELD },
5217 { CTRL('F'), REQ_NEXT_PAGE },
5218 { CTRL('G'), REQ_DEL_WORD },
5219 { CTRL('H'), REQ_DEL_PREV },
5220 { CTRL('I'), REQ_INS_CHAR },
5221 { CTRL('K'), REQ_CLR_EOF },
5222 { CTRL('L'), REQ_LEFT_FIELD },
5223 { CTRL('M'), REQ_NEW_LINE },
5224 { CTRL('N'), REQ_NEXT_FIELD },
5225 { CTRL('O'), REQ_INS_LINE },
5226 { CTRL('P'), REQ_PREV_FIELD },
5227 { CTRL('R'), REQ_RIGHT_FIELD },
5228 { CTRL('S'), REQ_BEG_FIELD },
5229 { CTRL('U'), REQ_UP_FIELD },
5230 { CTRL('V'), REQ_DEL_CHAR },
5231 { CTRL('W'), REQ_NEXT_WORD },
5232 { CTRL('X'), REQ_CLR_FIELD },
5233 { CTRL('Y'), REQ_DEL_LINE },
5234 { CTRL('Z'), REQ_PREV_CHOICE },
5235 { ESCAPE, MAX_FORM_COMMAND + 1 },
5236 { KEY_BACKSPACE, REQ_DEL_PREV },
5237 { KEY_DOWN, REQ_DOWN_CHAR },
5238 { KEY_END, REQ_LAST_FIELD },
5239 { KEY_HOME, REQ_FIRST_FIELD },
5240 { KEY_LEFT, REQ_LEFT_CHAR },
5241 { KEY_LL, REQ_LAST_FIELD },
5242 { KEY_NEXT, REQ_NEXT_FIELD },
5243 { KEY_NPAGE, REQ_NEXT_PAGE },
5244 { KEY_PPAGE, REQ_PREV_PAGE },
5245 { KEY_PREVIOUS, REQ_PREV_FIELD },
5246 { KEY_RIGHT, REQ_RIGHT_CHAR },
5247 { KEY_UP, REQ_UP_CHAR },
5248 { QUIT, MAX_FORM_COMMAND + 1 }
5252 static int mode = REQ_INS_MODE;
5253 int c = wGetchar(w);
5255 FIELD *me = current_field(f);
5256 bool current = TRUE;
5258 if (c == CTRL(']')) {
5259 if (mode == REQ_INS_MODE) {
5260 mode = REQ_OVL_MODE;
5262 mode = REQ_INS_MODE;
5266 for (n = 0; n < SIZEOF(lookup); n++) {
5267 if (lookup[n].code == c) {
5268 c = lookup[n].result;
5273 mvprintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5276 * Force the field that the user is typing into to be in reverse video,
5277 * while the other fields are shown underlined.
5292 case REQ_LEFT_FIELD:
5294 case REQ_RIGHT_CHAR:
5298 current = (c < KEY_MAX);
5302 c = edit_secure(me, c);
5303 set_field_back(me, A_REVERSE);
5305 c = edit_secure(me, c);
5306 set_field_back(me, A_UNDERLINE);
5312 my_form_driver(FORM * form, int c)
5314 if (c == (MAX_FORM_COMMAND + 1)
5315 && form_driver(form, REQ_VALIDATION) == E_OK)
5323 #ifdef NCURSES_VERSION
5324 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5325 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5327 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5328 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5332 * Allow a middle initial, optionally with a '.' to end it.
5335 FIELDCHECK_CB(mi_field_check)
5337 char *s = field_buffer(fld, 0);
5341 for (n = 0; s[n] != '\0'; ++n) {
5348 } else if (isspace(UChar(s[n]))) {
5353 if (!isspace(UChar(s[n])))
5359 /* force the form to display a leading capital */
5360 if (islower(UChar(s[0]))) {
5361 s[0] = toupper(UChar(s[0]));
5362 set_field_buffer(fld, 0, s);
5368 CHAR_CHECK_CB(mi_char_check)
5370 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5374 * Passwords should be at least 6 characters.
5377 FIELDCHECK_CB(pw_field_check)
5379 char *s = field_buffer(fld, 0);
5382 for (n = 0; s[n] != '\0'; ++n) {
5383 if (isspace(UChar(s[n]))) {
5392 CHAR_CHECK_CB(pw_char_check)
5394 return (isgraph(ch) ? TRUE : FALSE);
5402 FIELD *f[12], *secure;
5403 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
5404 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
5405 int finished = 0, c;
5408 #ifdef NCURSES_MOUSE_VERSION
5409 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5413 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
5414 addstr("^N -- go to next field ^P -- go to previous field\n");
5415 addstr("Home -- go to first field End -- go to last field\n");
5416 addstr("^L -- go to field to left ^R -- go to field to right\n");
5417 addstr("^U -- move upward to field ^D -- move downward to field\n");
5418 addstr("^W -- go to next word ^B -- go to previous word\n");
5419 addstr("^S -- go to start of field ^E -- go to end of field\n");
5420 addstr("^H -- delete previous char ^Y -- delete line\n");
5421 addstr("^G -- delete current word ^C -- clear to end of line\n");
5422 addstr("^K -- clear to end of field ^X -- clear field\n");
5423 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
5425 mvaddstr(4, 57, "Forms Entry Test");
5429 /* describe the form */
5430 f[n++] = make_label(0, 15, "Sample Form");
5432 f[n++] = make_label(2, 0, "Last Name");
5433 f[n++] = make_field(3, 0, 1, 18, FALSE);
5434 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5436 f[n++] = make_label(2, 20, "First Name");
5437 f[n++] = make_field(3, 20, 1, 12, FALSE);
5438 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5440 f[n++] = make_label(2, 34, "Middle Name");
5441 f[n++] = make_field(3, 34, 1, 12, FALSE);
5442 set_field_type(f[n - 1], fty_middle);
5444 f[n++] = make_label(5, 0, "Comments");
5445 f[n++] = make_field(6, 0, 4, 46, FALSE);
5447 f[n++] = make_label(5, 20, "Password:");
5449 f[n++] = make_field(5, 30, 1, 9, TRUE);
5450 set_field_type(f[n - 1], fty_passwd);
5451 f[n++] = (FIELD *) 0;
5459 nonl(); /* lets us read ^M's */
5461 switch (form_driver(form, c = form_virtualize(form, w))) {
5463 mvaddstr(5, 57, field_buffer(secure, 1));
5467 case E_UNKNOWN_COMMAND:
5468 finished = my_form_driver(form, c);
5479 for (c = 0; f[c] != 0; c++)
5481 free_fieldtype(fty_middle);
5482 free_fieldtype(fty_passwd);
5486 #ifdef NCURSES_MOUSE_VERSION
5487 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5490 #endif /* USE_LIBFORM */
5492 /****************************************************************************
5496 ****************************************************************************/
5499 fillwin(WINDOW *win, char ch)
5504 getmaxyx(win, y1, x1);
5505 for (y = 0; y < y1; y++) {
5507 for (x = 0; x < x1; x++)
5508 waddch(win, UChar(ch));
5513 crosswin(WINDOW *win, char ch)
5518 getmaxyx(win, y1, x1);
5519 for (y = 0; y < y1; y++) {
5520 for (x = 0; x < x1; x++)
5521 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
5522 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
5524 waddch(win, UChar(ch));
5529 #define OVERLAP_FLAVORS 5
5532 overlap_helpitem(int state, int item, char *message)
5534 int row = (item / 2);
5535 int col = ((item % 2) ? COLS / 2 : 0);
5537 move(LINES - 6 + row, col);
5538 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
5543 overlap_test_1_attr(WINDOW *win, int flavor, int col)
5545 short cpair = 1 + (flavor * 2) + col;
5549 wattrset(win, A_NORMAL);
5552 wattrset(win, A_BOLD);
5555 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
5556 wattrset(win, COLOR_PAIR(cpair) | A_NORMAL);
5559 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
5560 wattrset(win, COLOR_PAIR(cpair) | A_BOLD);
5566 overlap_test_2_attr(WINDOW *win, int flavor, int col)
5568 short cpair = 9 + (flavor * 2) + col;
5578 init_pair(cpair, COLOR_RED, COLOR_GREEN);
5579 wbkgdset(win, ' ' | A_BLINK | COLOR_PAIR(cpair));
5582 wbkgdset(win, ' ' | A_NORMAL);
5588 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
5593 const char *ths, *tht;
5597 state += OVERLAP_FLAVORS;
5598 state = state % OVERLAP_FLAVORS;
5600 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
5603 ths = col ? "B" : "A";
5604 tht = col ? "A" : "B";
5609 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
5617 overlap_test_1_attr(stdscr, flavors[row], col);
5618 sprintf(msg, "fill window %s with letter %s.", ths, ths);
5626 switch (flavors[row]) {
5628 sprintf(msg, "cross pattern in window %s.", ths);
5631 sprintf(msg, "draw box in window %s.", ths);
5634 sprintf(msg, "set background of window %s.", ths);
5637 sprintf(msg, "reset background of window %s.", ths);
5643 sprintf(msg, "clear window %s.", ths);
5647 switch (flavors[row]) {
5649 sprintf(msg, "overwrite %s onto %s.", ths, tht);
5652 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
5655 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
5658 sprintf(msg, "overlay %s onto %s.", ths, tht);
5663 overlap_helpitem(state, item, msg);
5664 wattrset(stdscr, A_NORMAL);
5665 wbkgdset(stdscr, ' ' | A_NORMAL);
5668 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
5669 state, flavors[state]);
5675 overlap_test_0(WINDOW *a, WINDOW *b)
5685 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
5687 overlap_test_1_attr(a, flavor, col);
5689 wattrset(a, A_NORMAL);
5693 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
5695 overlap_test_2_attr(a, flavor, col);
5704 /* done in overlap_test_2_attr */
5707 /* done in overlap_test_2_attr */
5713 overlap_test_3(WINDOW *a)
5720 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
5727 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
5730 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
5738 /* test effects of overlapping windows */
5743 int state, flavor[OVERLAP_FLAVORS];
5745 WINDOW *win1 = newwin(9, 20, 3, 3);
5746 WINDOW *win2 = newwin(9, 20, 9, 16);
5752 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
5753 printw("the shared region of two overlapping windows A and B. The cross\n");
5754 printw("pattern in each window does not overlap the other.\n");
5756 memset(flavor, 0, sizeof(flavor));
5757 state = overlap_help(0, flavor);
5759 while (!isQuit(ch = Getchar()))
5761 case 'a': /* refresh window A first, then B */
5762 overlap_test_0(win1, win2);
5765 case 'b': /* refresh window B first, then A */
5766 overlap_test_0(win2, win1);
5769 case 'c': /* fill window A so it's visible */
5770 overlap_test_1(flavor[1], 0, win1, 'A');
5773 case 'd': /* fill window B so it's visible */
5774 overlap_test_1(flavor[1], 1, win2, 'B');
5777 case 'e': /* cross test pattern in window A */
5778 overlap_test_2(flavor[2], 0, win1, 'A');
5781 case 'f': /* cross test pattern in window A */
5782 overlap_test_2(flavor[2], 1, win2, 'B');
5785 case 'g': /* clear window A */
5786 overlap_test_3(win1);
5789 case 'h': /* clear window B */
5790 overlap_test_3(win2);
5793 case 'i': /* overwrite A onto B */
5794 overlap_test_4(flavor[4], win1, win2);
5797 case 'j': /* overwrite B onto A */
5798 overlap_test_4(flavor[4], win2, win1);
5803 state = overlap_help(state + 1, flavor);
5808 state = overlap_help(state - 1, flavor);
5813 state = overlap_help(state, flavor);
5817 state = overlap_help(state, flavor);
5832 /****************************************************************************
5836 ****************************************************************************/
5839 do_single_test(const char c)
5840 /* perform a single specified test */
5847 #if USE_WIDEC_SUPPORT
5857 #if USE_WIDEC_SUPPORT
5865 Cannot("does not support color.");
5870 #if USE_WIDEC_SUPPORT
5873 Cannot("does not support color.");
5881 Cannot("does not support color.");
5882 else if (!can_change_color())
5883 Cannot("has hardwired color values.");
5894 #if USE_WIDEC_SUPPORT
5903 #if USE_WIDEC_SUPPORT
5911 demo_panels(init_panel, fill_panel);
5915 #if USE_WIDEC_SUPPORT
5917 demo_panels(init_wide_panel, fill_wide_panel);
5926 flushinp_test(stdscr);
5930 test_sgr_attributes();
5953 #if USE_LIBMENU && defined(TRACE)
5972 static const char *const tbl[] =
5974 "Usage: ncurses [options]"
5977 #ifdef NCURSES_VERSION
5978 ," -a f,b set default-colors (assumed white-on-black)"
5979 ," -d use default-colors if terminal supports them"
5982 ," -e fmt specify format for soft-keys test (e)"
5985 ," -f rip-off footer line (can repeat)"
5986 ," -h rip-off header line (can repeat)"
5988 ," -m do not use colors"
5989 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
5991 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
5994 ," -t mask specify default trace-level (may toggle with ^T)"
5998 for (n = 0; n < SIZEOF(tbl); n++)
5999 fprintf(stderr, "%s\n", tbl[n]);
6000 ExitProgram(EXIT_FAILURE);
6004 set_terminal_modes(void)
6009 scrollok(stdscr, TRUE);
6010 idlok(stdscr, TRUE);
6011 keypad(stdscr, TRUE);
6016 announce_sig(int sig)
6018 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6024 rip_footer(WINDOW *win, int cols)
6026 wbkgd(win, A_REVERSE);
6029 wprintw(win, "footer: %d columns", cols);
6035 rip_header(WINDOW *win, int cols)
6037 wbkgd(win, A_REVERSE);
6040 wprintw(win, "header: %d columns", cols);
6044 #endif /* HAVE_RIPOFFLINE */
6052 (void) puts("This is the ncurses main menu");
6053 (void) puts("a = keyboard and mouse input test");
6054 #if USE_WIDEC_SUPPORT
6055 (void) puts("A = wide-character keyboard and mouse input test");
6057 (void) puts("b = character attribute test");
6058 #if USE_WIDEC_SUPPORT
6059 (void) puts("B = wide-character attribute test");
6061 (void) puts("c = color test pattern");
6062 #if USE_WIDEC_SUPPORT
6063 (void) puts("C = color test pattern using wide-character calls");
6066 (void) puts("d = edit RGB color values");
6068 (void) puts("e = exercise soft keys");
6069 #if USE_WIDEC_SUPPORT
6070 (void) puts("E = exercise soft keys using wide-characters");
6073 (void) puts("f = display ACS characters");
6074 #if USE_WIDEC_SUPPORT
6075 (void) puts("F = display Wide-ACS characters");
6077 (void) puts("g = display windows and scrolling");
6078 (void) puts("i = test of flushinp()");
6079 (void) puts("k = display character attributes");
6081 (void) puts("m = menu code test");
6084 (void) puts("o = exercise panels library");
6085 #if USE_WIDEC_SUPPORT
6086 (void) puts("O = exercise panels with wide-characters");
6089 (void) puts("p = exercise pad features");
6090 (void) puts("q = quit");
6092 (void) puts("r = exercise forms code");
6094 (void) puts("s = overlapping-refresh test");
6095 #if USE_LIBMENU && defined(TRACE)
6096 (void) puts("t = set trace level");
6098 (void) puts("? = repeat this command summary");
6100 (void) fputs("> ", stdout);
6101 (void) fflush(stdout); /* necessary under SVr4 curses */
6104 * This used to be an 'fgets()' call. However (on Linux, at least)
6105 * mixing stream I/O and 'read()' (used in the library) causes the
6106 * input stream to be flushed when switching between the two.
6111 if (read(fileno(stdin), &ch, 1) <= 0) {
6115 } else if (command == 0 && !isspace(UChar(ch))) {
6117 } else if (ch == '\n' || ch == '\r') {
6118 if ((command == 'd') && !top) {
6119 (void) fputs("Do not nest test-d\n", stdout);
6124 (void) fputs("> ", stdout);
6125 (void) fflush(stdout);
6129 if (do_single_test(command)) {
6131 * This may be overkill; it's intended to reset everything back
6132 * to the initial terminal modes so that tests don't get in
6136 set_terminal_modes();
6141 if (command == '?') {
6142 (void) puts("This is the ncurses capability tester.");
6144 puts("You may select a test from the main menu by typing the");
6146 puts("key letter of the choice (the letter to left of the =)");
6148 puts("at the > prompt. Type `q' to exit.");
6156 /*+-------------------------------------------------------------------------
6158 --------------------------------------------------------------------------*/
6160 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6161 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6164 main(int argc, char *argv[])
6168 #ifdef NCURSES_VERSION
6169 int default_fg = COLOR_WHITE;
6170 int default_bg = COLOR_BLACK;
6171 bool assumed_colors = FALSE;
6172 bool default_colors = FALSE;
6174 char *palette_file = 0;
6175 bool monochrome = FALSE;
6177 setlocale(LC_ALL, "");
6179 while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != EOF) {
6181 #ifdef NCURSES_VERSION
6183 assumed_colors = TRUE;
6184 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6187 default_colors = TRUE;
6191 my_e_param = atoi(optarg);
6192 #ifdef NCURSES_VERSION
6193 if (my_e_param > 3) /* allow extended layouts */
6202 ripoffline(-1, rip_footer);
6205 ripoffline(1, rip_header);
6207 #endif /* HAVE_RIPOFFLINE */
6212 palette_file = optarg;
6216 nap_msec = atol(optarg);
6221 save_trace = strtol(optarg, 0, 0);
6230 * If there's no menus (unlikely for ncurses!), then we'll have to set
6231 * tracing on initially, just in case the user wants to test something that
6232 * doesn't involve wGetchar.
6235 /* enable debugging */
6239 if (!isatty(fileno(stdin)))
6241 #endif /* USE_LIBMENU */
6245 /* tell it we're going to play with soft keys */
6246 slk_init(my_e_param);
6250 /* set up null signal catcher so we can see what interrupts to getch do */
6251 signal(SIGUSR1, announce_sig);
6254 /* we must initialize the curses data structure only once */
6258 /* tests, in general, will want these modes */
6259 use_colors = monochrome ? FALSE : has_colors();
6263 #ifdef NCURSES_VERSION_PATCH
6264 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6265 #if HAVE_USE_DEFAULT_COLORS
6266 if (default_colors) {
6267 use_default_colors();
6270 #if NCURSES_VERSION_PATCH >= 20000708
6271 else if (assumed_colors)
6272 assume_default_colors(default_fg, default_bg);
6275 #else /* normal SVr4 curses */
6276 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6278 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6280 if (can_change_color()) {
6282 all_colors = (RGB_DATA *) malloc(max_colors * sizeof(RGB_DATA));
6283 for (cp = 0; cp < max_colors; ++cp) {
6285 &all_colors[cp].red,
6286 &all_colors[cp].green,
6287 &all_colors[cp].blue);
6289 if (palette_file != 0) {
6290 FILE *fp = fopen(palette_file, "r");
6292 char buffer[BUFSIZ];
6293 int red, green, blue;
6295 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6296 if (sscanf(buffer, "scale:%d", &c) == 1) {
6298 } else if (sscanf(buffer, "%d:%d %d %d",
6307 all_colors[c].red = (red * 1000) / scale;
6308 all_colors[c].green = (green * 1000) / scale;
6309 all_colors[c].blue = (blue * 1000) / scale;
6317 set_terminal_modes();
6321 * Return to terminal mode, so we're guaranteed of being able to
6322 * select terminal commands even if the capabilities are wrong.
6326 #if HAVE_CURSES_VERSION
6327 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6328 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6329 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6330 NCURSES_VERSION_MAJOR,
6331 NCURSES_VERSION_MINOR,
6332 NCURSES_VERSION_PATCH);
6334 (void) puts("Welcome to ncurses. Press ? for help.");
6339 ExitProgram(EXIT_SUCCESS);
6342 /* ncurses.c ends here */