1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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.309 2008/03/08 20:57:09 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_ICALLS | 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 ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
123 #define P(string) printw("%s\n", string)
125 #define BLANK ' ' /* this is the background character */
128 static int max_colors; /* the actual number of colors we'll use */
129 static int min_colors; /* the minimum color code */
130 static bool use_colors; /* true if we use colors */
133 static int max_pairs; /* ...and the number of color pairs */
141 static RGB_DATA *all_colors;
143 static void main_menu(bool);
145 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
146 * though we can rely on negative x/y values to stop the macro.
149 do_h_line(int y, int x, chtype c, int to)
152 mvhline(y, x, c, (to) - (x));
156 do_v_line(int y, int x, chtype c, int to)
159 mvvline(y, x, c, (to) - (y));
173 return ((c) == QUIT || (c) == ESCAPE);
175 #define case_QUIT case QUIT: case ESCAPE
177 /* Common function to allow ^T to toggle trace-mode in the middle of a test
178 * so that trace-files can be made smaller.
181 wGetchar(WINDOW *win)
185 while ((c = wgetch(win)) == CTRL('T')) {
187 save_trace = _nc_tracing;
188 Trace(("TOGGLE-TRACING OFF"));
191 _nc_tracing = save_trace;
195 Trace(("TOGGLE-TRACING ON"));
202 #define Getchar() wGetchar(stdscr)
204 /* replaces wgetnstr(), since we want to be able to edit values */
206 wGetstring(WINDOW *win, char *buffer, int limit)
213 wattrset(win, A_REVERSE);
217 if (x > (int) strlen(buffer))
218 x = (int) strlen(buffer);
220 wprintw(win, "%-*s", limit, buffer);
221 wmove(win, y0, x0 + x);
222 switch (ch = wGetchar(win)) {
235 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
253 if (!isprint(ch) || ch >= KEY_MIN) {
255 } else if ((int) strlen(buffer) < limit) {
257 for (j = strlen(buffer) + 1; j > x; --j) {
258 buffer[j] = buffer[j - 1];
267 wattroff(win, A_REVERSE);
272 #if USE_WIDEC_SUPPORT
274 wGet_wchar(WINDOW *win, wint_t *result)
278 while ((c = wget_wch(win, result)) == CTRL('T')) {
280 save_trace = _nc_tracing;
281 Trace(("TOGGLE-TRACING OFF"));
284 _nc_tracing = save_trace;
288 Trace(("TOGGLE-TRACING ON"));
291 c = wget_wch(win, result);
295 #define Get_wchar(result) wGet_wchar(stdscr, result)
297 /* replaces wgetn_wstr(), since we want to be able to edit values */
299 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
308 wattrset(win, A_REVERSE);
312 if (x > (int) wcslen(buffer))
313 x = (int) wcslen(buffer);
315 /* clear the "window' */
317 wprintw(win, "%*s", limit, " ");
319 /* write the existing buffer contents */
321 waddnwstr(win, buffer, limit);
323 /* positions the cursor past character 'x' */
325 waddnwstr(win, buffer, x);
327 switch (wGet_wchar(win, &ch)) {
367 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
387 } else if ((int) wcslen(buffer) < limit) {
389 for (j = wcslen(buffer) + 1; j > x; --j) {
390 buffer[j] = buffer[j - 1];
399 wattroff(win, A_REVERSE);
410 addstr("Press any key to continue... ");
415 Cannot(const char *what)
417 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
422 ShellOut(bool message)
425 addstr("Shelling out...");
430 addstr("returned from shellout.\n");
434 #ifdef NCURSES_MOUSE_VERSION
436 * This function is the same as _tracemouse(), but we cannot count on that
437 * being available in the non-debug library.
440 mouse_decode(MEVENT const *ep)
442 static char buf[80 + (5 * 10) + (32 * 15)];
444 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
445 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
447 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
449 SHOW(BUTTON1_RELEASED, "release-1");
450 SHOW(BUTTON1_PRESSED, "press-1");
451 SHOW(BUTTON1_CLICKED, "click-1");
452 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
453 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
454 #if NCURSES_MOUSE_VERSION == 1
455 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
458 SHOW(BUTTON2_RELEASED, "release-2");
459 SHOW(BUTTON2_PRESSED, "press-2");
460 SHOW(BUTTON2_CLICKED, "click-2");
461 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
462 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
463 #if NCURSES_MOUSE_VERSION == 1
464 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
467 SHOW(BUTTON3_RELEASED, "release-3");
468 SHOW(BUTTON3_PRESSED, "press-3");
469 SHOW(BUTTON3_CLICKED, "click-3");
470 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
471 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
472 #if NCURSES_MOUSE_VERSION == 1
473 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
476 SHOW(BUTTON4_RELEASED, "release-4");
477 SHOW(BUTTON4_PRESSED, "press-4");
478 SHOW(BUTTON4_CLICKED, "click-4");
479 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
480 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
481 #if NCURSES_MOUSE_VERSION == 1
482 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
485 #if NCURSES_MOUSE_VERSION == 2
486 SHOW(BUTTON5_RELEASED, "release-5");
487 SHOW(BUTTON5_PRESSED, "press-5");
488 SHOW(BUTTON5_CLICKED, "click-5");
489 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
490 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
493 SHOW(BUTTON_CTRL, "ctrl");
494 SHOW(BUTTON_SHIFT, "shift");
495 SHOW(BUTTON_ALT, "alt");
496 SHOW(ALL_MOUSE_EVENTS, "all-events");
497 SHOW(REPORT_MOUSE_POSITION, "position");
501 if (buf[strlen(buf) - 1] == ' ')
502 buf[strlen(buf) - 2] = '\0';
503 (void) strcat(buf, "}");
506 #endif /* NCURSES_MOUSE_VERSION */
508 /****************************************************************************
510 * Character input test
512 ****************************************************************************/
515 setup_getch(WINDOW *win, bool flags[])
517 keypad(win, flags['k']); /* should be redundant, but for testing */
518 meta(win, flags['m']); /* force this to a known state */
526 wgetch_help(WINDOW *win, bool flags[])
528 static const char *help[] =
530 "e -- toggle echo mode"
531 ,"g -- triggers a getstr test"
532 ,"k -- toggle keypad/literal mode"
533 ,"m -- toggle meta (7-bit/8-bit) mode"
536 ,"w -- create a new window"
538 ,"z -- suspend this process"
542 unsigned chk = ((SIZEOF(help) + 1) / 2);
547 printw("Type any key to see its %s value. Also:\n",
548 flags['k'] ? "keypad" : "literal");
549 for (n = 0; n < SIZEOF(help); ++n) {
550 int row = 1 + (n % chk);
551 int col = (n >= chk) ? COLS / 2 : 0;
552 int flg = ((strstr(help[n], "toggle") != 0)
553 && (flags[UChar(*help[n])] != FALSE));
556 mvprintw(row, col, "%s", help[n]);
567 wgetch_wrap(WINDOW *win, int first_y)
569 int last_y = getmaxy(win) - 1;
570 int y = getcury(win) + 1;
578 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
584 static WINSTACK *winstack = 0;
585 static unsigned len_winstack = 0;
598 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
600 unsigned need = (level + 1) * 2;
604 winstack = (WINSTACK *) malloc(len_winstack * sizeof(WINSTACK));
605 } else if (need >= len_winstack) {
607 winstack = (WINSTACK *) realloc(winstack, len_winstack * sizeof(WINSTACK));
609 winstack[level].text = txt_win;
610 winstack[level].frame = box_win;
613 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
617 /* this chunk is now done in resize_term() */
624 #define slk_repaint() /* nothing */
628 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
629 * Resize both and paint the box in the parent.
632 resize_boxes(unsigned level, WINDOW *win)
636 int high = LINES - base;
640 wnoutrefresh(stdscr);
644 for (n = 0; n < level; ++n) {
645 wresize(winstack[n].frame, high, wide);
646 wresize(winstack[n].text, high - 2, wide - 2);
649 werase(winstack[n].text);
650 box(winstack[n].frame, 0, 0);
651 wnoutrefresh(winstack[n].frame);
652 wprintw(winstack[n].text,
654 getmaxy(winstack[n].text),
655 getmaxx(winstack[n].text));
656 wnoutrefresh(winstack[n].text);
657 if (winstack[n].text == win)
663 #define forget_boxes() /* nothing */
664 #define remember_boxes(level,text,frame) /* nothing */
668 wgetch_test(unsigned level, WINDOW *win, int delay)
671 int first_y, first_x;
675 bool blocking = (delay < 0);
677 memset(flags, FALSE, sizeof(flags));
678 flags[UChar('k')] = (win == stdscr);
680 setup_getch(win, flags);
681 wtimeout(win, delay);
682 getyx(win, first_y, first_x);
684 wgetch_help(win, flags);
685 wsetscrreg(win, first_y, getmaxy(win) - 1);
689 while ((c = wGetchar(win)) == ERR) {
692 (void) wprintw(win, "%05d: input error", incount);
695 (void) wprintw(win, "%05d: input timed out", incount);
697 wgetch_wrap(win, first_y);
699 if (c == ERR && blocking) {
701 wgetch_wrap(win, first_y);
702 } else if (isQuit(c)) {
704 } else if (c == 'e') {
705 flags[UChar('e')] = !flags[UChar('e')];
706 setup_getch(win, flags);
707 wgetch_help(win, flags);
708 } else if (c == 'g') {
709 waddstr(win, "getstr test: ");
711 wgetnstr(win, buf, sizeof(buf) - 1);
713 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
715 wgetch_wrap(win, first_y);
716 } else if (c == 'k') {
717 flags[UChar('k')] = !flags[UChar('k')];
718 setup_getch(win, flags);
719 wgetch_help(win, flags);
720 } else if (c == 'm') {
721 flags[UChar('m')] = !flags[UChar('m')];
722 setup_getch(win, flags);
723 wgetch_help(win, flags);
724 } else if (c == 's') {
726 } else if (c == 'w') {
727 int high = getmaxy(win) - 1 - first_y + 1;
728 int wide = getmaxx(win) - first_x;
730 int new_y = first_y + getbegy(win);
731 int new_x = first_x + getbegx(win);
733 getyx(win, old_y, old_x);
734 if (high > 2 && wide > 2) {
735 WINDOW *wb = newwin(high, wide, new_y, new_x);
736 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
741 remember_boxes(level, wi, wb);
742 wgetch_test(level + 1, wi, delay);
746 wgetch_help(win, flags);
747 wmove(win, old_y, old_x);
753 } else if (c == 'z') {
754 kill(getpid(), SIGTSTP);
757 wprintw(win, "Key pressed: %04o ", c);
758 #ifdef NCURSES_MOUSE_VERSION
759 if (c == KEY_MOUSE) {
764 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
766 move(event.y, event.x);
770 #endif /* NCURSES_MOUSE_VERSION */
772 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
773 if (c == KEY_RESIZE) {
774 resize_boxes(level, win);
777 (void) waddstr(win, keyname(c));
778 } else if (c > 0x80) {
779 unsigned c2 = (c & 0x7f);
781 (void) wprintw(win, "M-%c", UChar(c2));
783 (void) wprintw(win, "M-%s", unctrl(c2));
784 waddstr(win, " (high-half character)");
787 (void) wprintw(win, "%c (ASCII printable character)", c);
789 (void) wprintw(win, "%s (ASCII control character)",
792 wgetch_wrap(win, first_y);
800 begin_getch_test(void)
807 #ifdef NCURSES_MOUSE_VERSION
808 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
811 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
813 getnstr(buf, sizeof(buf) - 1);
817 if (isdigit(UChar(buf[0]))) {
818 delay = atoi(buf) * 100;
828 finish_getch_test(void)
830 #ifdef NCURSES_MOUSE_VERSION
831 mousemask(0, (mmask_t *) 0);
842 int delay = begin_getch_test();
845 wgetch_test(0, stdscr, delay);
850 #if USE_WIDEC_SUPPORT
852 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
853 * Resize both and paint the box in the parent.
855 #if defined(KEY_RESIZE) && HAVE_WRESIZE
857 resize_wide_boxes(unsigned level, WINDOW *win)
861 int high = LINES - base;
865 wnoutrefresh(stdscr);
869 for (n = 0; n < level; ++n) {
870 wresize(winstack[n].frame, high, wide);
871 wresize(winstack[n].text, high - 2, wide - 2);
874 werase(winstack[n].text);
875 box_set(winstack[n].frame, 0, 0);
876 wnoutrefresh(winstack[n].frame);
877 wprintw(winstack[n].text,
879 getmaxy(winstack[n].text),
880 getmaxx(winstack[n].text));
881 wnoutrefresh(winstack[n].text);
882 if (winstack[n].text == win)
887 #endif /* KEY_RESIZE */
890 wcstos(const wchar_t *src)
895 const wchar_t *tmp = src;
897 memset(&state, 0, sizeof(state));
898 if ((need = wcsrtombs(0, &tmp, 0, &state)) > 0) {
899 unsigned have = need;
900 result = (char *) calloc(have + 1, 1);
902 if (wcsrtombs(result, &tmp, have, &state) != have) {
911 wget_wch_test(unsigned level, WINDOW *win, int delay)
913 wchar_t wchar_buf[BUFSIZ];
914 wint_t wint_buf[BUFSIZ];
915 int first_y, first_x;
919 bool blocking = (delay < 0);
923 memset(flags, FALSE, sizeof(flags));
924 flags[UChar('k')] = (win == stdscr);
926 setup_getch(win, flags);
927 wtimeout(win, delay);
928 getyx(win, first_y, first_x);
930 wgetch_help(win, flags);
931 wsetscrreg(win, first_y, getmaxy(win) - 1);
935 while ((code = wGet_wchar(win, &c)) == ERR) {
938 (void) wprintw(win, "%05d: input error", incount);
941 (void) wprintw(win, "%05d: input timed out", incount);
943 wgetch_wrap(win, first_y);
945 if (code == ERR && blocking) {
947 wgetch_wrap(win, first_y);
948 } else if (isQuit((int) c)) {
950 } else if (c == 'e') {
951 flags[UChar('e')] = !flags[UChar('e')];
952 setup_getch(win, flags);
953 wgetch_help(win, flags);
954 } else if (c == 'g') {
955 waddstr(win, "getstr test: ");
957 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
960 wprintw(win, "wgetn_wstr returns an error.");
963 for (n = 0; (wchar_buf[n] = wint_buf[n]) != 0; ++n) ;
964 if ((temp = wcstos(wchar_buf)) != 0) {
965 wprintw(win, "I saw %d characters:\n\t`%s'.",
966 (int) wcslen(wchar_buf), temp);
969 wprintw(win, "I saw %d characters (cannot convert).",
970 (int) wcslen(wchar_buf));
974 wgetch_wrap(win, first_y);
975 } else if (c == 'k') {
976 flags[UChar('k')] = !flags[UChar('k')];
977 setup_getch(win, flags);
978 wgetch_help(win, flags);
979 } else if (c == 'm') {
980 flags[UChar('m')] = !flags[UChar('m')];
981 setup_getch(win, flags);
982 wgetch_help(win, flags);
983 } else if (c == 's') {
985 } else if (c == 'w') {
986 int high = getmaxy(win) - 1 - first_y + 1;
987 int wide = getmaxx(win) - first_x;
989 int new_y = first_y + getbegy(win);
990 int new_x = first_x + getbegx(win);
992 getyx(win, old_y, old_x);
993 if (high > 2 && wide > 2) {
994 WINDOW *wb = newwin(high, wide, new_y, new_x);
995 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1000 remember_boxes(level, wi, wb);
1001 wget_wch_test(level + 1, wi, delay);
1005 wgetch_help(win, flags);
1006 wmove(win, old_y, old_x);
1011 } else if (c == 'z') {
1012 kill(getpid(), SIGTSTP);
1015 wprintw(win, "Key pressed: %04o ", c);
1016 #ifdef NCURSES_MOUSE_VERSION
1017 if (c == KEY_MOUSE) {
1021 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1023 move(event.y, event.x);
1027 #endif /* NCURSES_MOUSE_VERSION */
1028 if (code == KEY_CODE_YES) {
1029 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1030 if (c == KEY_RESIZE) {
1031 resize_wide_boxes(level, win);
1034 (void) waddstr(win, key_name((wchar_t) c));
1036 if (c < 256 && iscntrl(c)) {
1037 (void) wprintw(win, "%s (control character)", unctrl(c));
1040 waddnwstr(win, &c2, 1);
1041 (void) wprintw(win, " = %#x (printable character)", c);
1044 wgetch_wrap(win, first_y);
1054 int delay = begin_getch_test();
1057 wget_wch_test(0, stdscr, delay);
1059 finish_getch_test();
1063 /****************************************************************************
1065 * Character attributes test
1067 ****************************************************************************/
1069 #if HAVE_SETUPTERM || HAVE_TGETENT
1070 #define get_ncv() TIGETNUM("ncv","NC")
1071 #define get_xmc() TIGETNUM("xmc","sg")
1073 #define get_ncv() -1
1074 #define get_xmc() -1
1081 static int first = TRUE;
1082 static chtype result = 0;
1088 char *area_pointer = parsed;
1090 tgetent(buffer, getenv("TERM"));
1093 if (TIGETSTR("smso", "so"))
1094 result |= A_STANDOUT;
1095 if (TIGETSTR("smul", "us"))
1096 result |= A_UNDERLINE;
1097 if (TIGETSTR("rev", "mr"))
1098 result |= A_REVERSE;
1099 if (TIGETSTR("blink", "mb"))
1101 if (TIGETSTR("dim", "mh"))
1103 if (TIGETSTR("bold", "md"))
1105 if (TIGETSTR("smacs", "ac"))
1106 result |= A_ALTCHARSET;
1112 #define termattrs() my_termattrs()
1115 #define MAX_ATTRSTRING 31
1116 #define LEN_ATTRSTRING 26
1118 static char attr_test_string[MAX_ATTRSTRING + 1];
1121 attr_legend(WINDOW *helpwin)
1126 mvwprintw(helpwin, row++, col,
1128 mvwprintw(helpwin, row++, col,
1131 mvwprintw(helpwin, row++, col,
1132 "Modify the test strings:");
1133 mvwprintw(helpwin, row++, col,
1134 " A digit sets gaps on each side of displayed attributes");
1135 mvwprintw(helpwin, row++, col,
1136 " </> shifts the text left/right. ");
1138 mvwprintw(helpwin, row++, col,
1141 mvwprintw(helpwin, row++, col,
1142 " f/F/b/F toggle foreground/background background color");
1143 mvwprintw(helpwin, row++, col,
1144 " t/T toggle text/background color attribute");
1146 mvwprintw(helpwin, row++, col,
1147 " a/A toggle ACS (alternate character set) mapping");
1148 mvwprintw(helpwin, row++, col,
1149 " v/V toggle video attribute to combine with each line");
1153 show_color_attr(int fg, int bg, int tx)
1156 printw(" Colors (fg %d, bg %d", fg, bg);
1158 printw(", text %d", tx);
1164 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1195 if (*fg < min_colors)
1199 if (*bg < min_colors)
1213 adjust_attr_string(int adjust)
1215 int first = ((int) UChar(attr_test_string[0])) + adjust;
1216 int last = first + LEN_ATTRSTRING;
1218 if (first >= ' ' && last <= '~') { /* 32..126 */
1220 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1221 attr_test_string[j] = k;
1222 if (((k + 1 - first) % 5) == 0) {
1224 if (j < MAX_ATTRSTRING)
1225 attr_test_string[j] = ' ';
1228 while (j < MAX_ATTRSTRING)
1229 attr_test_string[j++] = ' ';
1230 attr_test_string[j] = '\0';
1237 init_attr_string(void)
1239 attr_test_string[0] = 'a';
1240 adjust_attr_string(0);
1244 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1246 int ncv = get_ncv();
1247 chtype test = attr & (chtype) (~A_ALTCHARSET);
1250 mvprintw(row, 5, "-->");
1251 mvprintw(row, 8, "%s mode:", name);
1252 mvprintw(row, 24, "|");
1254 printw("%*s", skip, " ");
1256 * Just for testing, write text using the alternate character set one
1257 * character at a time (to pass its rendition directly), and use the
1258 * string operation for the other attributes.
1260 if (attr & A_ALTCHARSET) {
1264 for (s = attr_test_string; *s != '\0'; ++s) {
1270 addstr(attr_test_string);
1274 printw("%*s", skip, " ");
1276 if (test != A_NORMAL) {
1277 if (!(termattrs() & test)) {
1280 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1281 static const chtype table[] =
1297 for (n = 0; n < SIZEOF(table); n++) {
1298 if ((table[n] & attr) != 0
1299 && ((1 << n) & ncv) != 0) {
1307 if ((termattrs() & test) != test)
1314 static const struct {
1316 NCURSES_CONST char * name;
1317 } attrs_to_test[] = {
1318 { A_STANDOUT, "STANDOUT" },
1319 { A_REVERSE, "REVERSE" },
1321 { A_UNDERLINE, "UNDERLINE" },
1323 { A_BLINK, "BLINK" },
1324 { A_PROTECT, "PROTECT" },
1326 { A_INVIS, "INVISIBLE" },
1328 { A_NORMAL, "NORMAL" },
1333 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1343 if (ch < 256 && isdigit(ch)) {
1351 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1353 attr_legend(helpwin);
1366 *kc = SIZEOF(attrs_to_test) - 1;
1372 if (*kc >= SIZEOF(attrs_to_test))
1376 adjust_attr_string(-1);
1379 adjust_attr_string(1);
1385 error = cycle_color_attr(ch, fg, bg, tx);
1395 /* test text attributes */
1398 int skip = get_xmc();
1399 short fg = COLOR_BLACK; /* color pair 0 is special */
1400 short bg = COLOR_BLACK;
1408 n = skip; /* make it easy */
1409 k = SIZEOF(attrs_to_test) - 1;
1414 chtype normal = A_NORMAL | BLANK;
1418 short pair = (fg != COLOR_BLACK || bg != COLOR_BLACK);
1421 if (init_pair(pair, fg, bg) == ERR) {
1424 normal |= COLOR_PAIR(pair);
1429 if (init_pair(pair, tx, bg) == ERR) {
1432 extras |= COLOR_PAIR(pair);
1441 mvaddstr(0, 20, "Character attribute test display");
1443 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1444 bool arrow = (j == k);
1445 row = show_attr(row, n, arrow,
1447 attrs_to_test[j].attr |
1448 attrs_to_test[k].attr,
1449 attrs_to_test[j].name);
1453 "This terminal does %shave the magic-cookie glitch",
1454 get_xmc() > -1 ? "" : "not ");
1455 mvprintw(row + 1, 8, "Enter '?' for help.");
1456 show_color_attr(fg, bg, tx);
1457 printw(" ACS (%d)", ac != 0);
1460 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1462 bkgdset(A_NORMAL | BLANK);
1467 #if USE_WIDEC_SUPPORT
1468 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1471 wide_adjust_attr_string(int adjust)
1473 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1474 int last = first + LEN_ATTRSTRING;
1476 if (first >= ' ' && last <= '~') { /* 32..126 */
1478 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1479 wide_attr_test_string[j] = k;
1480 if (((k + 1 - first) % 5) == 0) {
1482 if (j < MAX_ATTRSTRING)
1483 wide_attr_test_string[j] = ' ';
1486 while (j < MAX_ATTRSTRING)
1487 wide_attr_test_string[j++] = ' ';
1488 wide_attr_test_string[j] = '\0';
1495 wide_init_attr_string(void)
1497 wide_attr_test_string[0] = 'a';
1498 wide_adjust_attr_string(0);
1502 set_wide_background(short pair)
1509 setcchar(&normal, blank, A_NORMAL, pair, 0);
1515 get_wide_background(void)
1517 attr_t result = A_NORMAL;
1523 if (getbkgrnd(&ch) != ERR) {
1524 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1532 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1534 int ncv = get_ncv();
1535 chtype test = attr & ~WA_ALTCHARSET;
1538 mvprintw(row, 5, "-->");
1539 mvprintw(row, 8, "%s mode:", name);
1540 mvprintw(row, 24, "|");
1542 printw("%*s", skip, " ");
1545 * Just for testing, write text using the alternate character set one
1546 * character at a time (to pass its rendition directly), and use the
1547 * string operation for the other attributes.
1549 if (attr & WA_ALTCHARSET) {
1553 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1557 setcchar(&ch, fill, attr, pair, 0);
1564 attr_get(&old_attr, &old_pair, 0);
1565 attr_set(attr, pair, 0);
1566 addwstr(wide_attr_test_string);
1567 attr_set(old_attr, old_pair, 0);
1570 printw("%*s", skip, " ");
1572 if (test != A_NORMAL) {
1573 if (!(term_attrs() & test)) {
1576 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1577 static const attr_t table[] =
1591 for (n = 0; n < SIZEOF(table); n++) {
1592 if ((table[n] & attr) != 0
1593 && ((1 << n) & ncv) != 0) {
1601 if ((term_attrs() & test) != test)
1609 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1619 if (ch < 256 && isdigit(ch)) {
1627 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1628 box_set(helpwin, 0, 0);
1629 attr_legend(helpwin);
1642 *kc = SIZEOF(attrs_to_test) - 1;
1648 if (*kc >= SIZEOF(attrs_to_test))
1652 wide_adjust_attr_string(-1);
1655 wide_adjust_attr_string(1);
1661 error = cycle_color_attr(ch, fg, bg, tx);
1670 wide_attr_test(void)
1671 /* test text attributes using wide-character calls */
1674 int skip = get_xmc();
1675 short fg = COLOR_BLACK; /* color pair 0 is special */
1676 short bg = COLOR_BLACK;
1684 n = skip; /* make it easy */
1685 k = SIZEOF(attrs_to_test) - 1;
1686 wide_init_attr_string();
1694 pair = (fg != COLOR_BLACK || bg != COLOR_BLACK);
1697 if (init_pair(pair, fg, bg) == ERR) {
1704 if (init_pair(extras, tx, bg) == ERR) {
1709 set_wide_background(pair);
1712 box_set(stdscr, 0, 0);
1713 mvaddstr(0, 20, "Character attribute test display");
1715 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1716 row = wide_show_attr(row, n, j == k,
1718 attrs_to_test[j].attr |
1719 attrs_to_test[k].attr,
1721 attrs_to_test[j].name);
1725 "This terminal does %shave the magic-cookie glitch",
1726 get_xmc() > -1 ? "" : "not ");
1727 mvprintw(row + 1, 8, "Enter '?' for help.");
1728 show_color_attr(fg, bg, tx);
1729 printw(" ACS (%d)", ac != 0);
1732 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1734 set_wide_background(0);
1740 /****************************************************************************
1742 * Color support tests
1744 ****************************************************************************/
1746 static NCURSES_CONST char *the_color_names[] =
1767 show_color_name(int y, int x, int color, bool wide)
1769 if (move(y, x) != ERR) {
1774 sprintf(temp, "%02d", color);
1776 } else if (color >= 8) {
1777 sprintf(temp, "[%02d]", color);
1779 strcpy(temp, the_color_names[color]);
1781 printw("%-*.*s", width, width, temp);
1786 color_legend(WINDOW *helpwin)
1791 mvwprintw(helpwin, row++, col,
1794 mvwprintw(helpwin, row++, col,
1795 "Use up/down arrow to scroll through the display if it is");
1796 mvwprintw(helpwin, row++, col,
1797 "longer than one screen. Control/N and Control/P can be used");
1798 mvwprintw(helpwin, row++, col,
1799 "in place up up/down arrow. Use pageup/pagedown to scroll a");
1800 mvwprintw(helpwin, row++, col,
1801 "full screen; control/B and control/F can be used here.");
1803 mvwprintw(helpwin, row++, col,
1805 mvwprintw(helpwin, row++, col,
1806 " b/B toggle bold off/on");
1807 mvwprintw(helpwin, row++, col,
1808 " n/N toggle text/number on/off");
1809 mvwprintw(helpwin, row++, col,
1810 " w/W toggle width between 8/16 colors");
1813 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1815 /* generate a color test pattern */
1822 int grid_top = top + 3;
1823 int page_size = (LINES - grid_top);
1824 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1830 bool opt_bold = FALSE;
1831 bool opt_wide = FALSE;
1832 bool opt_nums = FALSE;
1835 if (pairs_max > COLOR_PAIRS)
1836 pairs_max = COLOR_PAIRS;
1841 /* this assumes an 80-column line */
1845 per_row = (COLORS > 8) ? 16 : 8;
1852 row_limit = (pairs_max + per_row - 1) / per_row;
1855 (void) printw("There are %d color pairs and %d colors\n",
1859 (void) mvprintw(top + 1, 0,
1860 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1863 opt_bold ? "on" : "off");
1865 /* show color names/numbers across the top */
1866 for (i = 0; i < per_row; i++)
1867 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
1869 /* show a grid of colors, with color names/ numbers on the left */
1870 for (i = (base_row * per_row); i < pairs_max; i++) {
1871 int row = grid_top + (i / per_row) - base_row;
1872 int col = (i % per_row + 1) * width;
1875 if (row >= 0 && move(row, col) != ERR) {
1876 short fg = i % COLORS;
1877 short bg = i / COLORS;
1879 init_pair(pair, fg, bg);
1880 attron((attr_t) COLOR_PAIR(pair));
1882 attron((attr_t) A_BOLD);
1885 sprintf(numbered, "{%02X}", i);
1888 printw("%-*.*s", width, width, hello);
1891 if ((i % per_row) == 0 && (i % COLORS) == 0) {
1892 show_color_name(row, 0, i / COLORS, opt_wide);
1900 switch (wGetchar(stdscr)) {
1917 set_color_test(opt_wide, FALSE);
1920 set_color_test(opt_wide, TRUE);
1924 if (base_row <= 0) {
1932 if (base_row + page_size >= row_limit) {
1941 if (base_row <= 0) {
1944 base_row -= (page_size - 1);
1952 if (base_row + page_size >= row_limit) {
1955 base_row += page_size - 1;
1956 if (base_row + page_size >= row_limit) {
1957 base_row = row_limit - page_size - 1;
1962 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1964 color_legend(helpwin);
1979 #if USE_WIDEC_SUPPORT
1980 /* generate a color test pattern */
1982 wide_color_test(void)
1988 int grid_top = top + 3;
1989 int page_size = (LINES - grid_top);
1990 int pairs_max = COLOR_PAIRS;
1996 bool opt_bold = FALSE;
1997 bool opt_wide = FALSE;
1998 bool opt_nums = FALSE;
2004 /* this assumes an 80-column line */
2008 per_row = (COLORS > 8) ? 16 : 8;
2015 row_limit = (pairs_max + per_row - 1) / per_row;
2018 (void) printw("There are %d color pairs and %d colors\n",
2022 (void) mvprintw(top + 1, 0,
2023 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2026 opt_bold ? "on" : "off");
2028 /* show color names/numbers across the top */
2029 for (i = 0; i < per_row; i++)
2030 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
2032 /* show a grid of colors, with color names/ numbers on the left */
2033 for (i = (base_row * per_row); i < pairs_max; i++) {
2034 int row = grid_top + (i / per_row) - base_row;
2035 int col = (i % per_row + 1) * width;
2038 if (row >= 0 && move(row, col) != ERR) {
2039 init_pair(pair, i % COLORS, i / COLORS);
2040 color_set(pair, NULL);
2042 attr_on((attr_t) A_BOLD, NULL);
2045 sprintf(numbered, "{%02X}", i);
2048 printw("%-*.*s", width, width, hello);
2049 attr_set(A_NORMAL, 0, NULL);
2051 if ((i % per_row) == 0 && (i % COLORS) == 0) {
2052 show_color_name(row, 0, i / COLORS, opt_wide);
2060 switch (c = wGetchar(stdscr)) {
2077 set_color_test(opt_wide, FALSE);
2080 set_color_test(opt_wide, TRUE);
2084 if (base_row <= 0) {
2092 if (base_row + page_size >= row_limit) {
2101 if (base_row <= 0) {
2104 base_row -= (page_size - 1);
2112 if (base_row + page_size >= row_limit) {
2115 base_row += page_size - 1;
2116 if (base_row + page_size >= row_limit) {
2117 base_row = row_limit - page_size - 1;
2122 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2124 color_legend(helpwin);
2138 #endif /* USE_WIDEC_SUPPORT */
2141 change_color(short current, int field, int value, int usebase)
2143 short red, green, blue;
2145 color_content(current, &red, &green, &blue);
2149 red = usebase ? red + value : value;
2152 green = usebase ? green + value : value;
2155 blue = usebase ? blue + value : value;
2159 if (init_color(current, red, green, blue) == ERR)
2164 init_all_colors(void)
2168 for (c = 0; c < COLORS; ++c)
2171 all_colors[c].green,
2172 all_colors[c].blue);
2175 #define scaled_rgb(n) ((255 * (n)) / 1000)
2179 /* display the color test pattern, without trying to edit colors */
2183 int this_c = 0, value = 0, field = 0;
2186 int page_size = (LINES - 6);
2191 for (i = 0; i < max_colors; i++)
2192 init_pair(i, COLOR_WHITE, i);
2194 mvprintw(LINES - 2, 0, "Number: %d", value);
2197 short red, green, blue;
2200 mvaddstr(0, 20, "Color RGB Value Editing");
2204 (i - top_color < page_size)
2205 && (i < max_colors); i++) {
2208 sprintf(numeric, "[%d]", i);
2209 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2210 (i == current ? '>' : ' '),
2211 (i < (int) SIZEOF(the_color_names)
2212 ? the_color_names[i] : numeric));
2213 attrset(COLOR_PAIR(i));
2217 color_content(i, &red, &green, &blue);
2219 if (current == i && field == 0)
2221 printw("%04d", red);
2222 if (current == i && field == 0)
2225 if (current == i && field == 1)
2227 printw("%04d", green);
2228 if (current == i && field == 1)
2231 if (current == i && field == 2)
2233 printw("%04d", blue);
2234 if (current == i && field == 2)
2237 printw(" ( %3d %3d %3d )",
2243 mvaddstr(LINES - 3, 0,
2244 "Use up/down to select a color, left/right to change fields.");
2245 mvaddstr(LINES - 2, 0,
2246 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2248 move(2 + current - top_color, 0);
2252 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2259 current -= (page_size - 1);
2266 if (current < (max_colors - 1))
2267 current += (page_size - 1);
2274 current = (current == 0 ? (max_colors - 1) : current - 1);
2279 current = (current == (max_colors - 1) ? 0 : current + 1);
2283 field = (field == 2 ? 0 : field + 1);
2287 field = (field == 0 ? 2 : field - 1);
2300 value = value * 10 + (this_c - '0');
2304 change_color(current, field, value, 1);
2308 change_color(current, field, -value, 1);
2312 change_color(current, field, value, 0);
2317 P(" RGB Value Editing Help");
2319 P("You are in the RGB value editor. Use the arrow keys to select one of");
2320 P("the fields in one of the RGB triples of the current colors; the one");
2321 P("currently selected will be reverse-video highlighted.");
2323 P("To change a field, enter the digits of the new value; they are echoed");
2324 P("as entered. Finish by typing `='. The change will take effect instantly.");
2325 P("To increment or decrement a value, use the same procedure, but finish");
2326 P("with a `+' or `-'.");
2328 P("Press 'm' to invoke the top-level menu with the current color settings.");
2329 P("To quit, do ESC");
2351 if (current >= max_colors)
2352 current = max_colors - 1;
2353 if (current < top_color)
2354 top_color = current;
2355 if (current - top_color >= page_size)
2356 top_color = current - (page_size - 1);
2358 mvprintw(LINES - 1, 0, "Number: %d", value);
2366 * ncurses does not reset each color individually when calling endwin().
2373 /****************************************************************************
2375 * Soft-key label test
2377 ****************************************************************************/
2382 #define SLK_WORK (SLK_HELP + 3)
2387 static const char *table[] =
2389 "Available commands are:"
2391 ,"^L -- repaint this message and activate soft keys"
2392 ,"a/d -- activate/disable soft keys"
2393 ,"c -- set centered format for labels"
2394 ,"l -- set left-justified format for labels"
2395 ,"r -- set right-justified format for labels"
2396 ,"[12345678] -- set label; labels are numbered 1 through 8"
2397 ,"e -- erase stdscr (should not erase labels)"
2398 ,"s -- test scrolling of shortened screen"
2400 ,"F/B -- cycle through foreground/background colors"
2402 ,"ESC -- return to main menu"
2404 ,"Note: if activating the soft keys causes your terminal to scroll up"
2405 ,"one line, your terminal auto-scrolls when anything is written to the"
2406 ,"last screen position. The ncurses code does not yet handle this"
2412 for (j = 0; j < SIZEOF(table); ++j) {
2420 call_slk_color(short fg, short bg)
2422 init_pair(1, bg, fg);
2424 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2432 /* exercise the soft keys */
2438 short fg = COLOR_BLACK;
2439 short bg = COLOR_WHITE;
2445 call_slk_color(fg, bg);
2455 mvaddstr(0, 20, "Soft Key Exerciser");
2470 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2471 while ((c = Getchar()) != 'Q' && (c != ERR))
2499 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2501 if ((s = slk_label(c - '0')) != 0) {
2504 wGetstring(stdscr, buf, 8);
2505 slk_set((c - '0'), buf, fmt);
2517 fg = (fg + 1) % COLORS;
2518 call_slk_color(fg, bg);
2523 bg = (bg + 1) % COLORS;
2524 call_slk_color(fg, bg);
2528 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2530 wnoutrefresh(stdscr);
2537 } while (!isQuit(c = Getchar()));
2545 #if USE_WIDEC_SUPPORT
2549 /* exercise the soft keys */
2552 wchar_t buf[SLKLEN + 1];
2554 short fg = COLOR_BLACK;
2555 short bg = COLOR_WHITE;
2559 call_slk_color(fg, bg);
2566 attr_on(WA_BOLD, NULL);
2567 mvaddstr(0, 20, "Soft Key Exerciser");
2568 attr_off(WA_BOLD, NULL);
2582 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2583 while ((c = Getchar()) != 'Q' && (c != ERR))
2611 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2613 if ((s = slk_label(c - '0')) != 0) {
2614 char *temp = strdup(s);
2615 size_t used = strlen(temp);
2616 size_t want = SLKLEN;
2621 while (want > 0 && used != 0) {
2622 const char *base = s;
2623 memset(&state, 0, sizeof(state));
2624 test = mbsrtowcs(0, &base, 0, &state);
2625 if (test == (size_t) -1) {
2627 } else if (test > want) {
2630 memset(&state, 0, sizeof(state));
2631 mbsrtowcs(buf, &base, want, &state);
2637 wGet_wstring(stdscr, buf, SLKLEN);
2638 slk_wset((c - '0'), buf, fmt);
2649 fg = (fg + 1) % COLORS;
2650 call_slk_color(fg, bg);
2655 bg = (bg + 1) % COLORS;
2656 call_slk_color(fg, bg);
2659 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2661 wnoutrefresh(stdscr);
2667 } while (!isQuit(c = Getchar()));
2675 #endif /* SLK_INIT */
2677 /****************************************************************************
2679 * Alternate character-set stuff
2681 ****************************************************************************/
2686 } attrs_to_cycle[] = {
2687 { A_NORMAL, "normal" },
2689 { A_REVERSE, "reverse" },
2690 { A_UNDERLINE, "underline" },
2695 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2701 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2706 *at_code = SIZEOF(attrs_to_cycle) - 1;
2715 *attr = attrs_to_cycle[*at_code].attr;
2720 cycle_colors(int ch, int *fg, int *bg, short *pair)
2722 bool result = FALSE;
2732 if ((*fg += 1) >= COLORS)
2740 if ((*bg += 1) >= COLORS)
2748 *pair = (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2751 if (init_pair(*pair, *fg, *bg) == ERR) {
2760 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2761 * terminal to perform functions. The remaining codes can be graphic.
2764 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
2766 bool C1 = (first == 128);
2768 unsigned last = first + 31;
2773 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2774 C1 ? "C1" : "GR", first, last);
2778 for (code = first; code <= last; code++) {
2780 int row = 2 + ((code - first) % 16);
2781 int col = ((code - first) / 16) * COLS / 2;
2783 sprintf(tmp, "%3u (0x%x)", code, code);
2784 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2788 nodelay(stdscr, TRUE);
2789 echochar(code | attr | COLOR_PAIR(pair));
2791 /* (yes, this _is_ crude) */
2792 while ((reply = Getchar()) != ERR) {
2793 addch(UChar(reply));
2796 nodelay(stdscr, FALSE);
2798 } while (--count > 0);
2805 show_pc_chars(int repeat, attr_t attr, short pair)
2811 mvprintw(0, 20, "Display of PC Character Codes");
2815 for (code = 0; code < 16; ++code) {
2816 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
2818 for (code = 0; code < 256; code++) {
2820 int row = 3 + (code / 16) + (code >= 128);
2821 int col = 8 + (code % 16) * PC_COLS;
2822 if ((code % 16) == 0)
2823 mvprintw(row, 0, "0x%02x:", code);
2834 * Skip the ones that do not work.
2838 addch(code | A_ALTCHARSET | attr | COLOR_PAIR(pair));
2841 } while (--count > 0);
2846 show_box_chars(int repeat, attr_t attr, short pair)
2849 attr |= COLOR_PAIR(pair);
2853 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
2858 mvhline(LINES / 2, 0, ACS_HLINE | attr, COLS);
2859 mvvline(0, COLS / 2, ACS_VLINE | attr, LINES);
2860 mvaddch(0, COLS / 2, ACS_TTEE | attr);
2861 mvaddch(LINES / 2, COLS / 2, ACS_PLUS | attr);
2862 mvaddch(LINES - 1, COLS / 2, ACS_BTEE | attr);
2863 mvaddch(LINES / 2, 0, ACS_LTEE | attr);
2864 mvaddch(LINES / 2, COLS - 1, ACS_RTEE | attr);
2870 show_1_acs(int n, int repeat, const char *name, chtype code)
2872 const int height = 16;
2873 int row = 2 + (n % height);
2874 int col = (n / height) * COLS / 2;
2876 mvprintw(row, col, "%*s : ", COLS / 4, name);
2879 } while (--repeat > 0);
2884 show_acs_chars(int repeat, attr_t attr, short pair)
2885 /* display the ACS character set */
2889 #define BOTH(name) #name, (name | attr | COLOR_PAIR(pair))
2893 mvaddstr(0, 20, "Display of the ACS Character Set");
2897 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
2898 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
2899 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
2900 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
2902 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
2903 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
2904 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
2905 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
2907 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
2908 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
2911 * HPUX's ACS definitions are broken here. Just give up.
2913 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
2914 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
2915 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
2916 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
2917 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
2919 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
2920 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
2921 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
2922 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
2923 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
2924 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
2925 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
2926 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
2927 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
2929 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
2930 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
2931 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
2933 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
2934 n = show_1_acs(n, repeat, BOTH(ACS_PI));
2935 n = show_1_acs(n, repeat, BOTH(ACS_S1));
2936 n = show_1_acs(n, repeat, BOTH(ACS_S3));
2937 n = show_1_acs(n, repeat, BOTH(ACS_S7));
2938 n = show_1_acs(n, repeat, BOTH(ACS_S9));
2946 char *term = getenv("TERM");
2947 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
2950 chtype attr = A_NORMAL;
2953 int fg = COLOR_BLACK;
2954 int bg = COLOR_BLACK;
2955 unsigned at_code = 0;
2957 void (*last_show_acs) (int, attr_t, short) = 0;
2965 ToggleAcs(last_show_acs, show_acs_chars);
2969 ToggleAcs(last_show_acs, show_pc_chars);
2974 ToggleAcs(last_show_acs, show_box_chars);
3000 if (repeat < (COLS / 4))
3008 if (cycle_attr(c, &at_code, &attr)
3009 || cycle_colors(c, &fg, &bg, &pair)) {
3016 if (last_show_acs != 0)
3017 last_show_acs(repeat, attr, pair);
3019 show_upper_chars(digit * 32 + 128, repeat, attr, pair);
3021 mvprintw(LINES - 3, 0,
3022 "Note: ANSI terminals may not display C1 characters.");
3023 mvprintw(LINES - 2, 0,
3024 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3027 mvprintw(LINES - 1, 0,
3028 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3029 attrs_to_cycle[at_code].name,
3032 mvprintw(LINES - 1, 0,
3033 "v/V cycles through video attributes (%s).",
3034 attrs_to_cycle[at_code].name);
3037 } while (!isQuit(c = Getchar()));
3044 #if USE_WIDEC_SUPPORT
3046 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3048 int count = getcchar(src, NULL, NULL, NULL, 0);
3055 if ((wch = typeMalloc(wchar_t, count + 1)) != 0) {
3056 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
3057 attr |= (ignore_attr & A_ALTCHARSET);
3058 setcchar(dst, wch, attr, pair, 0);
3067 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3071 int last = first + 31;
3075 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3078 for (code = first; code <= last; code++) {
3079 int row = 2 + ((code - first) % 16);
3080 int col = ((code - first) / 16) * COLS / 2;
3086 memset(&codes, 0, sizeof(codes));
3088 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3089 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3090 setcchar(&temp, codes, attr, pair, 0);
3093 * Give non-spacing characters something to combine with. If we
3094 * don't, they'll bunch up in a heap on the space after the ":".
3095 * Mark them with reverse-video to make them simpler to find on
3098 if (wcwidth(code) == 0)
3099 addch(space | A_REVERSE);
3101 * This could use add_wch(), but is done for comparison with the
3102 * normal 'f' test (and to make a test-case for echo_wchar()).
3103 * The screen will flicker because the erase() at the top of the
3104 * function is met by the builtin refresh() in echo_wchar().
3108 * The repeat-count may make text wrap - avoid that.
3110 getyx(stdscr, y, x);
3111 if (x >= col + (COLS / 2) - 2)
3113 } while (--count > 0);
3118 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3120 const int height = 16;
3121 int row = 2 + (n % height);
3122 int col = (n / height) * COLS / 2;
3124 mvprintw(row, col, "%*s : ", COLS / 4, name);
3125 while (repeat-- >= 0) {
3131 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3134 show_wacs_chars(int repeat, attr_t attr, short pair)
3135 /* display the wide-ACS character set */
3141 /*#define BOTH2(name) #name, &(name) */
3142 #define BOTH2(name) #name, MERGE_ATTR(name)
3146 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3150 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3151 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3152 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3153 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3155 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3156 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3157 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3158 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3160 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3161 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3163 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3164 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3165 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3166 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3168 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3169 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3170 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3171 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3172 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3173 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3174 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3175 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3176 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3178 #ifdef CURSES_WACS_ARRAY
3179 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3180 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3181 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3183 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3184 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3185 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3186 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3187 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3188 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3194 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3197 show_wbox_chars(int repeat, attr_t attr, short pair)
3204 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3208 attr_set(attr, pair, 0);
3209 box_set(stdscr, 0, 0);
3210 attr_set(A_NORMAL, 0, 0);
3212 mvhline_set(LINES / 2, 0, MERGE_ATTR(WACS_HLINE), COLS);
3213 mvvline_set(0, COLS / 2, MERGE_ATTR(WACS_VLINE), LINES);
3214 mvadd_wch(0, COLS / 2, MERGE_ATTR(WACS_TTEE));
3215 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(WACS_PLUS));
3216 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(WACS_BTEE));
3217 mvadd_wch(LINES / 2, 0, MERGE_ATTR(WACS_LTEE));
3218 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(WACS_RTEE));
3226 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3228 const int height = 16;
3229 int row = 2 + (n % height);
3230 int col = (n / height) * COLS / 2;
3233 mvprintw(row, col, "%*s : ", COLS / 4, name);
3234 attr_set(attr, pair, 0);
3235 addstr(strcpy(temp, code));
3236 attr_set(A_NORMAL, 0, 0);
3240 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3243 show_utf8_chars(int repeat, attr_t attr, short pair)
3250 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3254 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3255 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3256 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3257 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3259 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3260 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3261 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3262 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3264 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3265 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3267 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3268 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3269 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3270 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3272 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3273 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3274 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3275 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3276 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3277 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3278 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3279 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3280 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3281 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3282 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3283 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3285 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3286 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3287 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3288 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3289 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3290 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3295 /* display the wide-ACS character set */
3297 wide_acs_display(void)
3303 chtype attr = A_NORMAL;
3304 int fg = COLOR_BLACK;
3305 int bg = COLOR_BLACK;
3306 unsigned at_code = 0;
3308 void (*last_show_wacs) (int, attr_t, short) = 0;
3316 ToggleAcs(last_show_wacs, show_wacs_chars);
3319 ToggleAcs(last_show_wacs, show_wbox_chars);
3322 ToggleAcs(last_show_wacs, show_utf8_chars);
3325 if (c < 256 && isdigit(c)) {
3328 } else if (c == '+') {
3331 } else if (c == '-' && digit > 0) {
3334 } else if (c == '>' && repeat < (COLS / 4)) {
3336 } else if (c == '<' && repeat > 1) {
3338 } else if (c == '_') {
3339 space = (space == ' ') ? '_' : ' ';
3341 } else if (cycle_attr(c, &at_code, &attr)
3342 || cycle_colors(c, &fg, &bg, &pair)) {
3343 if (last_show_wacs != 0)
3351 if (last_show_wacs != 0)
3352 last_show_wacs(repeat, attr, pair);
3354 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3356 mvprintw(LINES - 3, 0,
3357 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3359 mvprintw(LINES - 2, 0,
3360 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3361 attrs_to_cycle[at_code].name,
3364 mvprintw(LINES - 2, 0,
3365 "v/V cycles through video attributes (%s).",
3366 attrs_to_cycle[at_code].name);
3369 } while (!isQuit(c = Getchar()));
3379 * Graphic-rendition test (adapted from vttest)
3382 test_sgr_attributes(void)
3386 for (pass = 0; pass < 2; pass++) {
3387 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3389 /* Use non-default colors if possible to exercise bce a little */
3391 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3392 normal |= COLOR_PAIR(1);
3396 mvprintw(1, 20, "Graphic rendition test pattern:");
3398 mvprintw(4, 1, "vanilla");
3400 #define set_sgr(mask) bkgdset((normal^(mask)));
3402 mvprintw(4, 40, "bold");
3404 set_sgr(A_UNDERLINE);
3405 mvprintw(6, 6, "underline");
3407 set_sgr(A_BOLD | A_UNDERLINE);
3408 mvprintw(6, 45, "bold underline");
3411 mvprintw(8, 1, "blink");
3413 set_sgr(A_BLINK | A_BOLD);
3414 mvprintw(8, 40, "bold blink");
3416 set_sgr(A_UNDERLINE | A_BLINK);
3417 mvprintw(10, 6, "underline blink");
3419 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3420 mvprintw(10, 45, "bold underline blink");
3423 mvprintw(12, 1, "negative");
3425 set_sgr(A_BOLD | A_REVERSE);
3426 mvprintw(12, 40, "bold negative");
3428 set_sgr(A_UNDERLINE | A_REVERSE);
3429 mvprintw(14, 6, "underline negative");
3431 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3432 mvprintw(14, 45, "bold underline negative");
3434 set_sgr(A_BLINK | A_REVERSE);
3435 mvprintw(16, 1, "blink negative");
3437 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3438 mvprintw(16, 40, "bold blink negative");
3440 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3441 mvprintw(18, 6, "underline blink negative");
3443 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3444 mvprintw(18, 45, "bold underline blink negative");
3447 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3453 bkgdset(A_NORMAL | BLANK);
3458 /****************************************************************************
3460 * Windows and scrolling tester.
3462 ****************************************************************************/
3464 #define BOTLINES 4 /* number of line stolen from screen bottom */
3470 #define FRAME struct frame
3479 #if defined(NCURSES_VERSION)
3480 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3481 #define is_keypad(win) (win)->_use_keypad
3482 #define is_scrollok(win) (win)->_scroll
3483 #elif !defined(is_keypad)
3484 #define is_keypad(win) FALSE
3485 #define is_scrollok(win) FALSE
3488 #define is_keypad(win) FALSE
3489 #define is_scrollok(win) FALSE
3492 /* We need to know if these flags are actually set, so don't look in FRAME.
3493 * These names are known to work with SVr4 curses as well as ncurses. The
3494 * _use_keypad name does not work with Solaris 8.
3497 HaveKeypad(FRAME * curp)
3499 WINDOW *win = (curp ? curp->wind : stdscr);
3501 return is_keypad(win);
3505 HaveScroll(FRAME * curp)
3507 WINDOW *win = (curp ? curp->wind : stdscr);
3509 return is_scrollok(win);
3513 newwin_legend(FRAME * curp)
3515 static const struct {
3520 "^C = create window", 0
3523 "^N = next window", 0
3526 "^P = previous window", 0
3529 "^F = scroll forward", 0
3532 "^B = scroll backward", 0
3535 "^K = keypad(%s)", 1
3538 "^S = scrollok(%s)", 2
3541 "^W = save window to file", 0
3544 "^R = restore window", 0
3557 bool do_keypad = HaveKeypad(curp);
3558 bool do_scroll = HaveScroll(curp);
3562 for (n = 0; n < SIZEOF(legend); n++) {
3563 switch (legend[n].code) {
3565 strcpy(buf, legend[n].msg);
3568 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3571 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3574 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3577 x = getcurx(stdscr);
3578 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3585 transient(FRAME * curp, NCURSES_CONST char *msg)
3587 newwin_legend(curp);
3589 mvaddstr(LINES - 1, 0, msg);
3595 printw("%s characters are echoed, window should %sscroll.",
3596 HaveKeypad(curp) ? "Non-arrow" : "All other",
3597 HaveScroll(curp) ? "" : "not ");
3602 newwin_report(FRAME * curp)
3603 /* report on the cursor's current position, then restore it */
3605 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
3609 transient(curp, (char *) 0);
3611 move(LINES - 1, COLS - 17);
3612 printw("Y = %2d X = %2d", y, x);
3620 selectcell(int uli, int ulj, int lri, int lrj)
3621 /* arrows keys move cursor, return location at current on non-arrow key */
3623 static pair res; /* result cell */
3624 int si = lri - uli + 1; /* depth of the select area */
3625 int sj = lrj - ulj + 1; /* width of the select area */
3626 int i = 0, j = 0; /* offsets into the select area */
3631 move(uli + i, ulj + j);
3632 newwin_report((FRAME *) 0);
3634 switch (Getchar()) {
3648 return ((pair *) 0);
3649 #ifdef NCURSES_MOUSE_VERSION
3655 if (event.y > uli && event.x > ulj) {
3676 outerbox(pair ul, pair lr, bool onoff)
3677 /* draw or erase a box *outside* the given pair of corners */
3679 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3680 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3681 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3682 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3683 move(ul.y - 1, ul.x);
3684 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3685 move(ul.y, ul.x - 1);
3686 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3687 move(lr.y + 1, ul.x);
3688 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3689 move(ul.y, lr.x + 1);
3690 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3695 /* Ask user for a window definition */
3702 addstr("Use arrows to move cursor, anything else to mark corner 1");
3704 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3705 return ((WINDOW *) 0);
3706 memcpy(&ul, tmp, sizeof(pair));
3707 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3710 addstr("Use arrows to move cursor, anything else to mark corner 2");
3712 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
3714 return ((WINDOW *) 0);
3715 memcpy(&lr, tmp, sizeof(pair));
3717 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
3719 outerbox(ul, lr, TRUE);
3730 newwin_move(FRAME * curp, int dy, int dx)
3732 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
3736 getyx(win, cur_y, cur_x);
3737 getmaxyx(win, max_y, max_x);
3738 if ((cur_x += dx) < 0)
3740 else if (cur_x >= max_x)
3742 if ((cur_y += dy) < 0)
3744 else if (cur_y >= max_y)
3746 wmove(win, cur_y, cur_x);
3750 delete_framed(FRAME * fp, bool showit)
3754 fp->last->next = fp->next;
3755 fp->next->last = fp->last;
3763 np = (fp == fp->next) ? 0 : fp->next;
3769 acs_and_scroll(void)
3770 /* Demonstrate windows */
3773 FRAME *current = (FRAME *) 0, *neww;
3774 WINDOW *usescr = stdscr;
3775 #if HAVE_PUTWIN && HAVE_GETWIN
3779 #define DUMPFILE "screendump"
3781 #ifdef NCURSES_MOUSE_VERSION
3782 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
3787 transient((FRAME *) 0, (char *) 0);
3790 neww = (FRAME *) calloc(1, sizeof(FRAME));
3791 if ((neww->wind = getwindow()) == (WINDOW *) 0)
3794 if (current == 0) { /* First element, */
3795 neww->next = neww; /* so point it at itself */
3798 neww->next = current->next;
3799 neww->last = current;
3800 neww->last->next = neww;
3801 neww->next->last = neww;
3804 /* SVr4 curses sets the keypad on all newly-created windows to
3805 * false. Someone reported that PDCurses makes new windows inherit
3806 * this flag. Remove the following 'keypad()' call to test this
3808 keypad(current->wind, TRUE);
3809 current->do_keypad = HaveKeypad(current);
3810 current->do_scroll = HaveScroll(current);
3813 case CTRL('N'): /* go to next window */
3815 current = current->next;
3818 case CTRL('P'): /* go to previous window */
3820 current = current->last;
3823 case CTRL('F'): /* scroll current window forward */
3825 wscrl(current->wind, 1);
3828 case CTRL('B'): /* scroll current window backwards */
3830 wscrl(current->wind, -1);
3833 case CTRL('K'): /* toggle keypad mode for current */
3835 current->do_keypad = !current->do_keypad;
3836 keypad(current->wind, current->do_keypad);
3842 current->do_scroll = !current->do_scroll;
3843 scrollok(current->wind, current->do_scroll);
3847 #if HAVE_PUTWIN && HAVE_GETWIN
3848 case CTRL('W'): /* save and delete window */
3849 if (current == current->next) {
3850 transient(current, "Will not save/delete ONLY window");
3852 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
3853 transient(current, "Can't open screen dump file");
3855 (void) putwin(current->wind, fp);
3858 current = delete_framed(current, TRUE);
3862 case CTRL('R'): /* restore window */
3863 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
3864 transient(current, "Can't open screen dump file");
3866 neww = (FRAME *) calloc(1, sizeof(FRAME));
3868 neww->next = current->next;
3869 neww->last = current;
3870 neww->last->next = neww;
3871 neww->next->last = neww;
3873 neww->wind = getwin(fp);
3876 wrefresh(neww->wind);
3882 case CTRL('X'): /* resize window */
3889 addstr("Use arrows to move cursor, anything else to mark new corner");
3892 getbegyx(current->wind, ul.y, ul.x);
3894 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
3895 if (tmp == (pair *) 0) {
3900 getmaxyx(current->wind, lr.y, lr.x);
3903 outerbox(ul, lr, FALSE);
3904 wnoutrefresh(stdscr);
3906 /* strictly cosmetic hack for the test */
3907 getmaxyx(current->wind, my, mx);
3908 if (my > tmp->y - ul.y) {
3909 getyx(current->wind, lr.y, lr.x);
3910 wmove(current->wind, tmp->y - ul.y + 1, 0);
3911 wclrtobot(current->wind);
3912 wmove(current->wind, lr.y, lr.x);
3914 if (mx > tmp->x - ul.x)
3915 for (i = 0; i < my; i++) {
3916 wmove(current->wind, i, tmp->x - ul.x + 1);
3917 wclrtoeol(current->wind);
3919 wnoutrefresh(current->wind);
3921 memcpy(&lr, tmp, sizeof(pair));
3922 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
3924 getbegyx(current->wind, ul.y, ul.x);
3925 getmaxyx(current->wind, lr.y, lr.x);
3928 outerbox(ul, lr, TRUE);
3929 wnoutrefresh(stdscr);
3931 wnoutrefresh(current->wind);
3937 #endif /* HAVE_WRESIZE */
3939 case KEY_F(10): /* undocumented --- use this to test area clears */
3940 selectcell(0, 0, LINES - 1, COLS - 1);
3946 newwin_move(current, -1, 0);
3949 newwin_move(current, 1, 0);
3952 newwin_move(current, 0, -1);
3955 newwin_move(current, 0, 1);
3963 getyx(current->wind, y, x);
3967 x = getmaxx(current->wind) - 1;
3969 mvwdelch(current->wind, y, x);
3979 waddch(current->wind, (chtype) c);
3984 newwin_report(current);
3985 usescr = (current ? current->wind : stdscr);
3988 (!isQuit(c = wGetchar(usescr))
3992 while (current != 0)
3993 current = delete_framed(current, FALSE);
3995 scrollok(stdscr, TRUE); /* reset to driver's default */
3996 #ifdef NCURSES_MOUSE_VERSION
3997 mousemask(0, (mmask_t *) 0);
4004 /****************************************************************************
4008 ****************************************************************************/
4011 static int nap_msec = 1;
4013 static NCURSES_CONST char *mod[] =
4023 /*+-------------------------------------------------------------------------
4025 --------------------------------------------------------------------------*/
4027 wait_a_while(int msec GCC_UNUSED)
4037 else if (msec > 1000)
4038 sleep((unsigned) msec / 1000);
4042 } /* end of wait_a_while */
4044 /*+-------------------------------------------------------------------------
4046 --------------------------------------------------------------------------*/
4048 saywhat(NCURSES_CONST char *text)
4050 wmove(stdscr, LINES - 1, 0);
4052 if (text != 0 && *text != '\0') {
4053 waddstr(stdscr, text);
4054 waddstr(stdscr, "; ");
4056 waddstr(stdscr, "press any key to continue");
4057 } /* end of saywhat */
4059 /*+-------------------------------------------------------------------------
4060 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4061 --------------------------------------------------------------------------*/
4063 mkpanel(short color, int rows, int cols, int tly, int tlx)
4068 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4069 if ((pan = new_panel(win)) == 0) {
4071 } else if (use_colors) {
4072 short fg = (color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK;
4075 init_pair(color, fg, bg);
4076 wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
4078 wbkgdset(win, A_BOLD | ' ');
4082 } /* end of mkpanel */
4084 /*+-------------------------------------------------------------------------
4086 --------------------------------------------------------------------------*/
4088 rmpanel(PANEL * pan)
4090 WINDOW *win = panel_window(pan);
4093 } /* end of rmpanel */
4095 /*+-------------------------------------------------------------------------
4097 --------------------------------------------------------------------------*/
4103 } /* end of pflush */
4105 /*+-------------------------------------------------------------------------
4107 --------------------------------------------------------------------------*/
4113 for (y = 0; y < LINES - 1; y++) {
4114 for (x = 0; x < COLS; x++)
4115 wprintw(stdscr, "%d", (y + x) % 10);
4120 fill_panel(PANEL * pan)
4122 WINDOW *win = panel_window(pan);
4123 int num = ((const char *) panel_userptr(pan))[1];
4127 wprintw(win, "-pan%c-", num);
4130 for (y = 2; y < getmaxy(win) - 1; y++) {
4131 for (x = 1; x < getmaxx(win) - 1; x++) {
4133 waddch(win, UChar(num));
4138 #if USE_WIDEC_SUPPORT
4140 make_fullwidth_digit(cchar_t *target, int digit)
4144 source[0] = digit + 0xff10;
4146 setcchar(target, source, A_NORMAL, 0, 0);
4150 init_wide_panel(void)
4155 for (digit = 0; digit < 10; ++digit)
4156 make_fullwidth_digit(&temp[digit], digit);
4160 getyx(stdscr, y, x);
4161 digit = (y + x / 2) % 10;
4162 } while (add_wch(&temp[digit]) != ERR);
4166 fill_wide_panel(PANEL * pan)
4168 WINDOW *win = panel_window(pan);
4169 int num = ((const char *) panel_userptr(pan))[1];
4173 wprintw(win, "-pan%c-", num);
4176 for (y = 2; y < getmaxy(win) - 1; y++) {
4177 for (x = 1; x < getmaxx(win) - 1; x++) {
4179 waddch(win, UChar(num));
4185 #define MAX_PANELS 5
4188 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4190 int which = cmd[1] - '0';
4195 hide_panel(px[which]);
4198 show_panel(px[which]);
4201 top_panel(px[which]);
4204 bottom_panel(px[which]);
4211 wait_a_while(nap_msec);
4215 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4219 PANEL *px[MAX_PANELS + 1];
4221 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4225 for (count = 0; count < 5; count++) {
4226 px[1] = mkpanel(COLOR_RED,
4231 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4233 px[2] = mkpanel(COLOR_GREEN,
4238 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4240 px[3] = mkpanel(COLOR_YELLOW,
4245 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4247 px[4] = mkpanel(COLOR_BLUE,
4252 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4254 px[5] = mkpanel(COLOR_MAGENTA,
4259 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4271 wait_a_while(nap_msec);
4273 saywhat("h3 s1 s2 s4 s5");
4274 move_panel(px[1], 0, 0);
4281 wait_a_while(nap_msec);
4283 canned_panel(px, "s1");
4284 canned_panel(px, "s2");
4287 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4289 wait_a_while(nap_msec);
4291 canned_panel(px, "s3");
4294 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4296 wait_a_while(nap_msec);
4298 canned_panel(px, "b3");
4299 canned_panel(px, "s4");
4300 canned_panel(px, "s5");
4301 canned_panel(px, "t3");
4302 canned_panel(px, "t1");
4303 canned_panel(px, "t2");
4304 canned_panel(px, "t3");
4305 canned_panel(px, "t4");
4307 for (itmp = 0; itmp < 6; itmp++) {
4308 WINDOW *w4 = panel_window(px[4]);
4309 WINDOW *w5 = panel_window(px[5]);
4312 wmove(w4, LINES / 8, 1);
4313 waddstr(w4, mod[itmp]);
4314 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4315 wmove(w5, LINES / 6, 1);
4316 waddstr(w5, mod[itmp]);
4318 wait_a_while(nap_msec);
4321 wmove(w4, LINES / 6, 1);
4322 waddstr(w4, mod[itmp]);
4323 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4324 wmove(w5, LINES / 8, 1);
4325 waddstr(w5, mod[itmp]);
4327 wait_a_while(nap_msec);
4331 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4333 wait_a_while(nap_msec);
4335 canned_panel(px, "t5");
4336 canned_panel(px, "t2");
4337 canned_panel(px, "t1");
4338 canned_panel(px, "d2");
4339 canned_panel(px, "h3");
4340 canned_panel(px, "d1");
4341 canned_panel(px, "d4");
4342 canned_panel(px, "d5");
4343 canned_panel(px, "d3");
4345 wait_a_while(nap_msec);
4354 #endif /* USE_LIBPANEL */
4356 /****************************************************************************
4360 ****************************************************************************/
4364 static bool pending_pan = FALSE;
4365 static bool show_panner_legend = TRUE;
4368 panner_legend(int line)
4370 static const char *const legend[] =
4372 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4373 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4374 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4375 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4377 int n = (SIZEOF(legend) - (LINES - line));
4378 if (line < LINES && (n >= 0)) {
4380 if (show_panner_legend)
4381 printw("%s", legend[n]);
4383 return show_panner_legend;
4389 panner_h_cleanup(int from_y, int from_x, int to_x)
4391 if (!panner_legend(from_y))
4392 do_h_line(from_y, from_x, ' ', to_x);
4396 panner_v_cleanup(int from_y, int from_x, int to_y)
4398 if (!panner_legend(from_y))
4399 do_v_line(from_y, from_x, ' ', to_y);
4403 fill_pad(WINDOW *panpad, bool pan_lines)
4406 unsigned gridcount = 0;
4408 wmove(panpad, 0, 0);
4409 for (y = 0; y < getmaxy(panpad); y++) {
4410 for (x = 0; x < getmaxx(panpad); x++) {
4411 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4412 if (y == 0 && x == 0)
4413 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4415 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4416 else if (y == 0 || x == 0)
4417 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4419 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4420 (gridcount++ % 26)));
4421 } else if (y % GRIDSIZE == 0)
4422 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4423 else if (x % GRIDSIZE == 0)
4424 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4426 waddch(panpad, ' ');
4433 int top_x, int top_y, int porty, int portx,
4434 int (*pgetc) (WINDOW *))
4436 #if HAVE_GETTIMEOFDAY
4437 struct timeval before, after;
4440 bool pan_lines = FALSE;
4441 bool scrollers = TRUE;
4444 int pxmax, pymax, lowend, highend, c;
4446 getmaxyx(pad, pymax, pxmax);
4447 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4451 #ifdef NCURSES_VERSION
4453 * During shell-out, the user may have resized the window. Adjust
4454 * the port size of the pad to accommodate this. Ncurses automatically
4455 * resizes all of the normal windows to fit on the new screen.
4473 show_panner_legend = !show_panner_legend;
4474 panner_legend(LINES - 4);
4475 panner_legend(LINES - 3);
4476 panner_legend(LINES - 2);
4477 panner_legend(LINES - 1);
4480 pan_lines = !pan_lines;
4481 fill_pad(pad, pan_lines);
4482 pending_pan = FALSE;
4485 #if HAVE_GETTIMEOFDAY
4489 panner_legend(LINES - 1);
4493 scrollers = !scrollers;
4496 /* Move the top-left corner of the pad, keeping the bottom-right
4499 case 'h': /* increase-columns: move left edge to left */
4503 panner_v_cleanup(top_y, top_x, porty);
4508 case 'j': /* decrease-lines: move top-edge down */
4512 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
4517 case 'k': /* increase-lines: move top-edge up */
4522 panner_h_cleanup(top_y, top_x, portx);
4526 case 'l': /* decrease-columns: move left-edge to right */
4530 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
4535 /* Move the bottom-right corner of the pad, keeping the top-left
4538 case KEY_IC: /* increase-columns: move right-edge to right */
4539 if (portx >= pxmax || portx >= COLS)
4542 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
4547 case KEY_IL: /* increase-lines: move bottom-edge down */
4548 if (porty >= pymax || porty >= LINES)
4551 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
4556 case KEY_DC: /* decrease-columns: move bottom edge up */
4561 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
4565 case KEY_DL: /* decrease-lines */
4570 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
4574 case KEY_LEFT: /* pan leftwards */
4581 case KEY_RIGHT: /* pan rightwards */
4582 if (basex + portx - (pymax > porty) < pxmax)
4588 case KEY_UP: /* pan upwards */
4595 case KEY_DOWN: /* pan downwards */
4596 if (basey + porty - (pxmax > portx) < pymax)
4611 basey = pymax - porty;
4621 mvaddch(top_y - 1, top_x - 1, ACS_ULCORNER);
4622 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
4623 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
4625 if (scrollers && (pxmax > portx - 1)) {
4626 int length = (portx - top_x - 1);
4627 float ratio = ((float) length) / ((float) pxmax);
4629 lowend = (int) (top_x + (basex * ratio));
4630 highend = (int) (top_x + ((basex + length) * ratio));
4632 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
4633 if (highend < portx) {
4635 do_h_line(porty - 1, lowend, ' ', highend + 1);
4637 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
4640 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
4642 if (scrollers && (pymax > porty - 1)) {
4643 int length = (porty - top_y - 1);
4644 float ratio = ((float) length) / ((float) pymax);
4646 lowend = (int) (top_y + (basey * ratio));
4647 highend = (int) (top_y + ((basey + length) * ratio));
4649 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
4650 if (highend < porty) {
4652 do_v_line(lowend, portx - 1, ' ', highend + 1);
4654 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
4657 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
4659 mvaddch(top_y - 1, portx - 1, ACS_URCORNER);
4660 mvaddch(porty - 1, top_x - 1, ACS_LLCORNER);
4661 mvaddch(porty - 1, portx - 1, ACS_LRCORNER);
4664 #if HAVE_GETTIMEOFDAY
4665 gettimeofday(&before, 0);
4667 wnoutrefresh(stdscr);
4672 porty - (pxmax > portx) - 1,
4673 portx - (pymax > porty) - 1);
4676 #if HAVE_GETTIMEOFDAY
4679 gettimeofday(&after, 0);
4680 elapsed = (after.tv_sec + after.tv_usec / 1.0e6)
4681 - (before.tv_sec + before.tv_usec / 1.0e6);
4682 move(LINES - 1, COLS - 12);
4683 printw("Secs: %2.03f", elapsed);
4690 ((c = pgetc(pad)) != KEY_EXIT);
4692 scrollok(stdscr, TRUE); /* reset to driver's default */
4696 padgetch(WINDOW *win)
4702 if ((pending_pan = (count > 0)) != FALSE) {
4704 pending_pan = (count != 0);
4707 switch (c = wGetchar(win)) {
4743 case ERR: /* FALLTHRU */
4749 if (c >= '0' && c <= '9') {
4750 count = count * 10 + (c - '0');
4764 #define PAD_HIGH 200
4765 #define PAD_WIDE 200
4769 /* Demonstrate pads. */
4771 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
4774 Cannot("cannot create requested pad");
4778 fill_pad(panpad, FALSE);
4780 panner_legend(LINES - 4);
4781 panner_legend(LINES - 3);
4782 panner_legend(LINES - 2);
4783 panner_legend(LINES - 1);
4785 keypad(panpad, TRUE);
4787 /* Make the pad (initially) narrow enough that a trace file won't wrap.
4788 * We'll still be able to widen it during a test, since that's required
4789 * for testing boundaries.
4791 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
4798 /****************************************************************************
4800 * Tests from John Burnell's PDCurses tester
4802 ****************************************************************************/
4805 Continue(WINDOW *win)
4809 mvwaddstr(win, 10, 1, " Press any key to continue");
4815 flushinp_test(WINDOW *win)
4816 /* Input test, adapted from John Burnell's PDCurses tester */
4818 int w, h, bx, by, sw, sh, i;
4823 getmaxyx(win, h, w);
4824 getbegyx(win, by, bx);
4827 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
4832 init_pair(2, COLOR_CYAN, COLOR_BLUE);
4833 wbkgd(subWin, COLOR_PAIR(2) | ' ');
4836 wattrset(subWin, A_BOLD);
4837 box(subWin, ACS_VLINE, ACS_HLINE);
4838 mvwaddstr(subWin, 2, 1, "This is a subwindow");
4842 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
4843 * it only happened to "work" on SVr4 because that implementation does not
4844 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
4845 * test behavior, we're using 'cbreak()', which will allow a single
4846 * character to return without needing a newline. - T.Dickey 1997/10/11.
4849 mvwaddstr(win, 0, 1, "This is a test of the flushinp() call.");
4851 mvwaddstr(win, 2, 1, "Type random keys for 5 seconds.");
4852 mvwaddstr(win, 3, 1,
4853 "These should be discarded (not echoed) after the subwindow goes away.");
4856 for (i = 0; i < 5; i++) {
4857 mvwprintw(subWin, 1, 1, "Time = %d", i);
4869 mvwaddstr(win, 2, 1,
4870 "If you were still typing when the window timer expired,");
4871 mvwaddstr(win, 3, 1,
4872 "or else you typed nothing at all while it was running,");
4873 mvwaddstr(win, 4, 1,
4874 "test was invalid. You'll see garbage or nothing at all. ");
4875 mvwaddstr(win, 6, 1, "Press a key");
4881 mvwaddstr(win, 12, 0,
4882 "If you see any key other than what you typed, flushinp() is broken.");
4891 "What you typed should now have been deleted; if not, wdelch() failed.");
4897 /****************************************************************************
4901 ****************************************************************************/
4909 menu_virtualize(int c)
4911 if (c == '\n' || c == KEY_EXIT)
4912 return (MAX_COMMAND + 1);
4914 return (REQ_SCR_ULINE);
4916 return (REQ_SCR_DLINE);
4917 else if (c == 'b' || c == KEY_NPAGE)
4918 return (REQ_SCR_UPAGE);
4919 else if (c == 'f' || c == KEY_PPAGE)
4920 return (REQ_SCR_DPAGE);
4921 else if (c == 'n' || c == KEY_DOWN)
4922 return (REQ_NEXT_ITEM);
4923 else if (c == 'p' || c == KEY_UP)
4924 return (REQ_PREV_ITEM);
4926 return (REQ_TOGGLE_ITEM);
4934 static CONST_MENUS char *animals[] =
4947 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
4948 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
4956 ITEM *items[SIZEOF(animals)];
4958 CONST_MENUS char **ap;
4959 int mrows, mcols, c;
4962 #ifdef NCURSES_MOUSE_VERSION
4963 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
4965 mvaddstr(0, 0, "This is the menu test:");
4966 mvaddstr(2, 0, " Use up and down arrow to move the select bar.");
4967 mvaddstr(3, 0, " 'n' and 'p' act like arrows.");
4969 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
4970 mvaddstr(5, 0, " Press return to exit.");
4973 for (ap = animals; *ap; ap++)
4974 *ip++ = new_item(*ap, "");
4977 m = new_menu(items);
4979 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
4980 scale_menu(m, &mrows, &mcols);
4982 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
4983 set_menu_win(m, menuwin);
4984 keypad(menuwin, TRUE);
4987 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
4991 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
4992 if (c == E_NOT_POSTED)
4994 if (c == E_REQUEST_DENIED)
4999 (void) mvprintw(LINES - 2, 0,
5000 "You chose: %s\n", item_name(current_item(m)));
5001 (void) addstr("Press any key to continue...");
5008 for (ip = items; *ip; ip++)
5010 #ifdef NCURSES_MOUSE_VERSION
5011 mousemask(0, (mmask_t *) 0);
5016 #define T_TBL(name) { #name, name }
5022 T_TBL(TRACE_DISABLE),
5025 T_TBL(TRACE_UPDATE),
5027 T_TBL(TRACE_CHARPUT),
5028 T_TBL(TRACE_ORDINARY),
5030 T_TBL(TRACE_VIRTPUT),
5031 T_TBL(TRACE_IEVENT),
5033 T_TBL(TRACE_ICALLS),
5034 T_TBL(TRACE_CCALLS),
5035 T_TBL(TRACE_DATABASE),
5037 T_TBL(TRACE_MAXIMUM),
5044 tracetrace(unsigned tlevel)
5051 for (n = 0; t_tbl[n].name != 0; n++)
5052 need += strlen(t_tbl[n].name) + 2;
5053 buf = (char *) malloc(need);
5055 sprintf(buf, "0x%02x = {", tlevel);
5057 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5059 for (n = 1; t_tbl[n].name != 0; n++)
5060 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5061 strcat(buf, t_tbl[n].name);
5065 if (buf[strlen(buf) - 2] == ',')
5066 buf[strlen(buf) - 2] = '\0';
5067 return (strcat(buf, "}"));
5070 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5074 run_trace_menu(MENU * m)
5080 bool changed = FALSE;
5081 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5082 case E_UNKNOWN_COMMAND:
5085 items = menu_items(m);
5086 i = current_item(m);
5087 if (i == items[0]) {
5088 if (item_value(i)) {
5089 for (p = items + 1; *p != 0; p++)
5090 if (item_value(*p)) {
5091 set_item_value(*p, FALSE);
5096 for (p = items + 1; *p != 0; p++)
5097 if (item_value(*p)) {
5098 set_item_value(items[0], FALSE);
5111 /* interactively set the trace level */
5114 ITEM *items[SIZEOF(t_tbl)];
5121 mvaddstr(0, 0, "Interactively set trace level:");
5122 mvaddstr(2, 0, " Press space bar to toggle a selection.");
5123 mvaddstr(3, 0, " Use up and down arrow to move the select bar.");
5124 mvaddstr(4, 0, " Press return to set the trace level.");
5125 mvprintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5129 for (n = 0; t_tbl[n].name != 0; n++)
5130 *ip++ = new_item(t_tbl[n].name, "");
5133 m = new_menu(items);
5135 set_menu_format(m, 0, 2);
5136 scale_menu(m, &mrows, &mcols);
5138 menu_opts_off(m, O_ONEVALUE);
5139 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5140 set_menu_win(m, menuwin);
5141 keypad(menuwin, TRUE);
5144 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5148 for (ip = menu_items(m); *ip; ip++) {
5149 unsigned mask = t_tbl[item_index(*ip)].mask;
5151 set_item_value(*ip, _nc_tracing == 0);
5152 else if ((mask & _nc_tracing) == mask)
5153 set_item_value(*ip, TRUE);
5156 while (run_trace_menu(m))
5160 for (ip = menu_items(m); *ip; ip++)
5161 if (item_value(*ip))
5162 newtrace |= t_tbl[item_index(*ip)].mask;
5164 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5166 (void) mvprintw(LINES - 2, 0,
5167 "Trace level is %s\n", tracetrace(_nc_tracing));
5168 (void) addstr("Press any key to continue...");
5175 for (ip = items; *ip; ip++)
5179 #endif /* USE_LIBMENU */
5181 /****************************************************************************
5185 ****************************************************************************/
5188 make_label(int frow, int fcol, NCURSES_CONST char *label)
5190 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5193 set_field_buffer(f, 0, label);
5194 set_field_opts(f, (int) (field_opts(f) & ~O_ACTIVE));
5200 make_field(int frow, int fcol, int rows, int cols, bool secure)
5202 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5205 set_field_back(f, A_UNDERLINE);
5206 set_field_userptr(f, (void *) 0);
5212 display_form(FORM * f)
5217 scale_form(f, &rows, &cols);
5219 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5221 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5226 if (post_form(f) != E_OK)
5231 erase_form(FORM * f)
5233 WINDOW *w = form_win(f);
5234 WINDOW *s = form_sub(f);
5244 edit_secure(FIELD * me, int c)
5246 int rows, cols, frow, fcol, nrow, nbuf;
5248 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5250 char *source = field_buffer(me, 1);
5254 strcpy(temp, source ? source : "");
5255 len = (long) (char *) field_userptr(me);
5257 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5260 set_field_buffer(me, 1, temp);
5280 case REQ_RIGHT_CHAR:
5282 c = 0; /* we don't want to do inline editing */
5287 set_field_buffer(me, 1, temp);
5294 set_field_buffer(me, 1, temp);
5299 set_field_userptr(me, (void *) len);
5305 form_virtualize(FORM * f, WINDOW *w)
5308 static const struct {
5312 { CTRL('A'), REQ_NEXT_CHOICE },
5313 { CTRL('B'), REQ_PREV_WORD },
5314 { CTRL('C'), REQ_CLR_EOL },
5315 { CTRL('D'), REQ_DOWN_FIELD },
5316 { CTRL('E'), REQ_END_FIELD },
5317 { CTRL('F'), REQ_NEXT_PAGE },
5318 { CTRL('G'), REQ_DEL_WORD },
5319 { CTRL('H'), REQ_DEL_PREV },
5320 { CTRL('I'), REQ_INS_CHAR },
5321 { CTRL('K'), REQ_CLR_EOF },
5322 { CTRL('L'), REQ_LEFT_FIELD },
5323 { CTRL('M'), REQ_NEW_LINE },
5324 { CTRL('N'), REQ_NEXT_FIELD },
5325 { CTRL('O'), REQ_INS_LINE },
5326 { CTRL('P'), REQ_PREV_FIELD },
5327 { CTRL('R'), REQ_RIGHT_FIELD },
5328 { CTRL('S'), REQ_BEG_FIELD },
5329 { CTRL('U'), REQ_UP_FIELD },
5330 { CTRL('V'), REQ_DEL_CHAR },
5331 { CTRL('W'), REQ_NEXT_WORD },
5332 { CTRL('X'), REQ_CLR_FIELD },
5333 { CTRL('Y'), REQ_DEL_LINE },
5334 { CTRL('Z'), REQ_PREV_CHOICE },
5335 { ESCAPE, MAX_FORM_COMMAND + 1 },
5336 { KEY_BACKSPACE, REQ_DEL_PREV },
5337 { KEY_DOWN, REQ_DOWN_CHAR },
5338 { KEY_END, REQ_LAST_FIELD },
5339 { KEY_HOME, REQ_FIRST_FIELD },
5340 { KEY_LEFT, REQ_LEFT_CHAR },
5341 { KEY_LL, REQ_LAST_FIELD },
5342 { KEY_NEXT, REQ_NEXT_FIELD },
5343 { KEY_NPAGE, REQ_NEXT_PAGE },
5344 { KEY_PPAGE, REQ_PREV_PAGE },
5345 { KEY_PREVIOUS, REQ_PREV_FIELD },
5346 { KEY_RIGHT, REQ_RIGHT_CHAR },
5347 { KEY_UP, REQ_UP_CHAR },
5348 { QUIT, MAX_FORM_COMMAND + 1 }
5352 static int mode = REQ_INS_MODE;
5353 int c = wGetchar(w);
5355 FIELD *me = current_field(f);
5356 bool current = TRUE;
5358 if (c == CTRL(']')) {
5359 if (mode == REQ_INS_MODE) {
5360 mode = REQ_OVL_MODE;
5362 mode = REQ_INS_MODE;
5366 for (n = 0; n < SIZEOF(lookup); n++) {
5367 if (lookup[n].code == c) {
5368 c = lookup[n].result;
5373 mvprintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5376 * Force the field that the user is typing into to be in reverse video,
5377 * while the other fields are shown underlined.
5392 case REQ_LEFT_FIELD:
5394 case REQ_RIGHT_CHAR:
5398 current = (c < KEY_MAX);
5402 c = edit_secure(me, c);
5403 set_field_back(me, A_REVERSE);
5405 c = edit_secure(me, c);
5406 set_field_back(me, A_UNDERLINE);
5412 my_form_driver(FORM * form, int c)
5414 if (c == (MAX_FORM_COMMAND + 1)
5415 && form_driver(form, REQ_VALIDATION) == E_OK)
5423 #ifdef NCURSES_VERSION
5424 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5425 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5427 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5428 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5432 * Allow a middle initial, optionally with a '.' to end it.
5435 FIELDCHECK_CB(mi_field_check)
5437 char *s = field_buffer(fld, 0);
5441 for (n = 0; s[n] != '\0'; ++n) {
5448 } else if (isspace(UChar(s[n]))) {
5453 if (!isspace(UChar(s[n])))
5459 /* force the form to display a leading capital */
5460 if (islower(UChar(s[0]))) {
5461 s[0] = toupper(UChar(s[0]));
5462 set_field_buffer(fld, 0, s);
5468 CHAR_CHECK_CB(mi_char_check)
5470 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5474 * Passwords should be at least 6 characters.
5477 FIELDCHECK_CB(pw_field_check)
5479 char *s = field_buffer(fld, 0);
5482 for (n = 0; s[n] != '\0'; ++n) {
5483 if (isspace(UChar(s[n]))) {
5492 CHAR_CHECK_CB(pw_char_check)
5494 return (isgraph(ch) ? TRUE : FALSE);
5502 FIELD *f[12], *secure;
5503 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
5504 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
5505 int finished = 0, c;
5508 #ifdef NCURSES_MOUSE_VERSION
5509 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5513 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
5514 addstr("^N -- go to next field ^P -- go to previous field\n");
5515 addstr("Home -- go to first field End -- go to last field\n");
5516 addstr("^L -- go to field to left ^R -- go to field to right\n");
5517 addstr("^U -- move upward to field ^D -- move downward to field\n");
5518 addstr("^W -- go to next word ^B -- go to previous word\n");
5519 addstr("^S -- go to start of field ^E -- go to end of field\n");
5520 addstr("^H -- delete previous char ^Y -- delete line\n");
5521 addstr("^G -- delete current word ^C -- clear to end of line\n");
5522 addstr("^K -- clear to end of field ^X -- clear field\n");
5523 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
5525 mvaddstr(4, 57, "Forms Entry Test");
5529 /* describe the form */
5530 f[n++] = make_label(0, 15, "Sample Form");
5532 f[n++] = make_label(2, 0, "Last Name");
5533 f[n++] = make_field(3, 0, 1, 18, FALSE);
5534 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5536 f[n++] = make_label(2, 20, "First Name");
5537 f[n++] = make_field(3, 20, 1, 12, FALSE);
5538 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5540 f[n++] = make_label(2, 34, "Middle Name");
5541 f[n++] = make_field(3, 34, 1, 12, FALSE);
5542 set_field_type(f[n - 1], fty_middle);
5544 f[n++] = make_label(5, 0, "Comments");
5545 f[n++] = make_field(6, 0, 4, 46, FALSE);
5547 f[n++] = make_label(5, 20, "Password:");
5549 f[n++] = make_field(5, 30, 1, 9, TRUE);
5550 set_field_type(f[n - 1], fty_passwd);
5551 f[n++] = (FIELD *) 0;
5559 nonl(); /* lets us read ^M's */
5561 switch (form_driver(form, c = form_virtualize(form, w))) {
5563 mvaddstr(5, 57, field_buffer(secure, 1));
5567 case E_UNKNOWN_COMMAND:
5568 finished = my_form_driver(form, c);
5579 for (c = 0; f[c] != 0; c++)
5581 free_fieldtype(fty_middle);
5582 free_fieldtype(fty_passwd);
5586 #ifdef NCURSES_MOUSE_VERSION
5587 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5590 #endif /* USE_LIBFORM */
5592 /****************************************************************************
5596 ****************************************************************************/
5599 fillwin(WINDOW *win, char ch)
5604 getmaxyx(win, y1, x1);
5605 for (y = 0; y < y1; y++) {
5607 for (x = 0; x < x1; x++)
5608 waddch(win, UChar(ch));
5613 crosswin(WINDOW *win, char ch)
5618 getmaxyx(win, y1, x1);
5619 for (y = 0; y < y1; y++) {
5620 for (x = 0; x < x1; x++)
5621 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
5622 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
5624 waddch(win, UChar(ch));
5629 #define OVERLAP_FLAVORS 5
5632 overlap_helpitem(int state, int item, char *message)
5634 int row = (item / 2);
5635 int col = ((item % 2) ? COLS / 2 : 0);
5637 move(LINES - 6 + row, col);
5638 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
5643 overlap_test_1_attr(WINDOW *win, int flavor, int col)
5645 short cpair = 1 + (flavor * 2) + col;
5649 wattrset(win, A_NORMAL);
5652 wattrset(win, A_BOLD);
5655 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
5656 wattrset(win, COLOR_PAIR(cpair) | A_NORMAL);
5659 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
5660 wattrset(win, COLOR_PAIR(cpair) | A_BOLD);
5666 overlap_test_2_attr(WINDOW *win, int flavor, int col)
5668 short cpair = 9 + (flavor * 2) + col;
5678 init_pair(cpair, COLOR_RED, COLOR_GREEN);
5679 wbkgdset(win, ' ' | A_BLINK | COLOR_PAIR(cpair));
5682 wbkgdset(win, ' ' | A_NORMAL);
5688 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
5693 const char *ths, *tht;
5697 state += OVERLAP_FLAVORS;
5698 state = state % OVERLAP_FLAVORS;
5700 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
5703 ths = col ? "B" : "A";
5704 tht = col ? "A" : "B";
5709 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
5717 overlap_test_1_attr(stdscr, flavors[row], col);
5718 sprintf(msg, "fill window %s with letter %s.", ths, ths);
5726 switch (flavors[row]) {
5728 sprintf(msg, "cross pattern in window %s.", ths);
5731 sprintf(msg, "draw box in window %s.", ths);
5734 sprintf(msg, "set background of window %s.", ths);
5737 sprintf(msg, "reset background of window %s.", ths);
5743 sprintf(msg, "clear window %s.", ths);
5747 switch (flavors[row]) {
5749 sprintf(msg, "overwrite %s onto %s.", ths, tht);
5752 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
5755 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
5758 sprintf(msg, "overlay %s onto %s.", ths, tht);
5763 overlap_helpitem(state, item, msg);
5764 wattrset(stdscr, A_NORMAL);
5765 wbkgdset(stdscr, ' ' | A_NORMAL);
5768 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
5769 state, flavors[state]);
5775 overlap_test_0(WINDOW *a, WINDOW *b)
5785 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
5787 overlap_test_1_attr(a, flavor, col);
5789 wattrset(a, A_NORMAL);
5793 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
5795 overlap_test_2_attr(a, flavor, col);
5804 /* done in overlap_test_2_attr */
5807 /* done in overlap_test_2_attr */
5813 overlap_test_3(WINDOW *a)
5820 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
5827 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
5830 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
5838 /* test effects of overlapping windows */
5843 int state, flavor[OVERLAP_FLAVORS];
5845 WINDOW *win1 = newwin(9, 20, 3, 3);
5846 WINDOW *win2 = newwin(9, 20, 9, 16);
5852 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
5853 printw("the shared region of two overlapping windows A and B. The cross\n");
5854 printw("pattern in each window does not overlap the other.\n");
5856 memset(flavor, 0, sizeof(flavor));
5857 state = overlap_help(0, flavor);
5859 while (!isQuit(ch = Getchar()))
5861 case 'a': /* refresh window A first, then B */
5862 overlap_test_0(win1, win2);
5865 case 'b': /* refresh window B first, then A */
5866 overlap_test_0(win2, win1);
5869 case 'c': /* fill window A so it's visible */
5870 overlap_test_1(flavor[1], 0, win1, 'A');
5873 case 'd': /* fill window B so it's visible */
5874 overlap_test_1(flavor[1], 1, win2, 'B');
5877 case 'e': /* cross test pattern in window A */
5878 overlap_test_2(flavor[2], 0, win1, 'A');
5881 case 'f': /* cross test pattern in window A */
5882 overlap_test_2(flavor[2], 1, win2, 'B');
5885 case 'g': /* clear window A */
5886 overlap_test_3(win1);
5889 case 'h': /* clear window B */
5890 overlap_test_3(win2);
5893 case 'i': /* overwrite A onto B */
5894 overlap_test_4(flavor[4], win1, win2);
5897 case 'j': /* overwrite B onto A */
5898 overlap_test_4(flavor[4], win2, win1);
5903 state = overlap_help(state + 1, flavor);
5908 state = overlap_help(state - 1, flavor);
5913 state = overlap_help(state, flavor);
5917 state = overlap_help(state, flavor);
5932 /****************************************************************************
5936 ****************************************************************************/
5939 do_single_test(const char c)
5940 /* perform a single specified test */
5947 #if USE_WIDEC_SUPPORT
5957 #if USE_WIDEC_SUPPORT
5965 Cannot("does not support color.");
5970 #if USE_WIDEC_SUPPORT
5973 Cannot("does not support color.");
5981 Cannot("does not support color.");
5982 else if (!can_change_color())
5983 Cannot("has hardwired color values.");
5994 #if USE_WIDEC_SUPPORT
6003 #if USE_WIDEC_SUPPORT
6011 demo_panels(init_panel, fill_panel);
6015 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6017 demo_panels(init_wide_panel, fill_wide_panel);
6026 flushinp_test(stdscr);
6030 test_sgr_attributes();
6053 #if USE_LIBMENU && defined(TRACE)
6072 static const char *const tbl[] =
6074 "Usage: ncurses [options]"
6077 #ifdef NCURSES_VERSION
6078 ," -a f,b set default-colors (assumed white-on-black)"
6079 ," -d use default-colors if terminal supports them"
6082 ," -e fmt specify format for soft-keys test (e)"
6085 ," -f rip-off footer line (can repeat)"
6086 ," -h rip-off header line (can repeat)"
6088 ," -m do not use colors"
6089 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6091 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6094 ," -t mask specify default trace-level (may toggle with ^T)"
6098 for (n = 0; n < SIZEOF(tbl); n++)
6099 fprintf(stderr, "%s\n", tbl[n]);
6100 ExitProgram(EXIT_FAILURE);
6104 set_terminal_modes(void)
6109 scrollok(stdscr, TRUE);
6110 idlok(stdscr, TRUE);
6111 keypad(stdscr, TRUE);
6116 announce_sig(int sig)
6118 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6124 rip_footer(WINDOW *win, int cols)
6126 wbkgd(win, A_REVERSE);
6129 wprintw(win, "footer: window %p, %d columns", win, cols);
6135 rip_header(WINDOW *win, int cols)
6137 wbkgd(win, A_REVERSE);
6140 wprintw(win, "header: window %p, %d columns", win, cols);
6144 #endif /* HAVE_RIPOFFLINE */
6152 (void) puts("This is the ncurses main menu");
6153 (void) puts("a = keyboard and mouse input test");
6154 #if USE_WIDEC_SUPPORT
6155 (void) puts("A = wide-character keyboard and mouse input test");
6157 (void) puts("b = character attribute test");
6158 #if USE_WIDEC_SUPPORT
6159 (void) puts("B = wide-character attribute test");
6161 (void) puts("c = color test pattern");
6162 #if USE_WIDEC_SUPPORT
6163 (void) puts("C = color test pattern using wide-character calls");
6166 (void) puts("d = edit RGB color values");
6168 (void) puts("e = exercise soft keys");
6169 #if USE_WIDEC_SUPPORT
6170 (void) puts("E = exercise soft keys using wide-characters");
6173 (void) puts("f = display ACS characters");
6174 #if USE_WIDEC_SUPPORT
6175 (void) puts("F = display Wide-ACS characters");
6177 (void) puts("g = display windows and scrolling");
6178 (void) puts("i = test of flushinp()");
6179 (void) puts("k = display character attributes");
6181 (void) puts("m = menu code test");
6184 (void) puts("o = exercise panels library");
6185 #if USE_WIDEC_SUPPORT
6186 (void) puts("O = exercise panels with wide-characters");
6189 (void) puts("p = exercise pad features");
6190 (void) puts("q = quit");
6192 (void) puts("r = exercise forms code");
6194 (void) puts("s = overlapping-refresh test");
6195 #if USE_LIBMENU && defined(TRACE)
6196 (void) puts("t = set trace level");
6198 (void) puts("? = repeat this command summary");
6200 (void) fputs("> ", stdout);
6201 (void) fflush(stdout); /* necessary under SVr4 curses */
6204 * This used to be an 'fgets()' call. However (on Linux, at least)
6205 * mixing stream I/O and 'read()' (used in the library) causes the
6206 * input stream to be flushed when switching between the two.
6211 if (read(fileno(stdin), &ch, 1) <= 0) {
6215 } else if (command == 0 && !isspace(UChar(ch))) {
6217 } else if (ch == '\n' || ch == '\r') {
6218 if ((command == 'd') && !top) {
6219 (void) fputs("Do not nest test-d\n", stdout);
6224 (void) fputs("> ", stdout);
6225 (void) fflush(stdout);
6229 if (do_single_test(command)) {
6231 * This may be overkill; it's intended to reset everything back
6232 * to the initial terminal modes so that tests don't get in
6236 set_terminal_modes();
6241 if (command == '?') {
6242 (void) puts("This is the ncurses capability tester.");
6244 puts("You may select a test from the main menu by typing the");
6246 puts("key letter of the choice (the letter to left of the =)");
6248 puts("at the > prompt. Type `q' to exit.");
6256 /*+-------------------------------------------------------------------------
6258 --------------------------------------------------------------------------*/
6260 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6261 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6264 main(int argc, char *argv[])
6268 #ifdef NCURSES_VERSION
6269 int default_fg = COLOR_WHITE;
6270 int default_bg = COLOR_BLACK;
6271 bool assumed_colors = FALSE;
6272 bool default_colors = FALSE;
6274 char *palette_file = 0;
6275 bool monochrome = FALSE;
6277 setlocale(LC_ALL, "");
6279 while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) {
6281 #ifdef NCURSES_VERSION
6283 assumed_colors = TRUE;
6284 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6287 default_colors = TRUE;
6291 my_e_param = atoi(optarg);
6292 #ifdef NCURSES_VERSION
6293 if (my_e_param > 3) /* allow extended layouts */
6302 ripoffline(-1, rip_footer);
6305 ripoffline(1, rip_header);
6307 #endif /* HAVE_RIPOFFLINE */
6312 palette_file = optarg;
6316 nap_msec = atol(optarg);
6321 save_trace = strtol(optarg, 0, 0);
6330 * If there's no menus (unlikely for ncurses!), then we'll have to set
6331 * tracing on initially, just in case the user wants to test something that
6332 * doesn't involve wGetchar.
6335 /* enable debugging */
6339 if (!isatty(fileno(stdin)))
6341 #endif /* USE_LIBMENU */
6345 /* tell it we're going to play with soft keys */
6346 slk_init(my_e_param);
6350 /* set up null signal catcher so we can see what interrupts to getch do */
6351 signal(SIGUSR1, announce_sig);
6354 /* we must initialize the curses data structure only once */
6358 /* tests, in general, will want these modes */
6359 use_colors = monochrome ? FALSE : has_colors();
6363 #ifdef NCURSES_VERSION_PATCH
6364 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6365 #if HAVE_USE_DEFAULT_COLORS
6366 if (default_colors) {
6367 use_default_colors();
6370 #if NCURSES_VERSION_PATCH >= 20000708
6371 else if (assumed_colors)
6372 assume_default_colors(default_fg, default_bg);
6375 #else /* normal SVr4 curses */
6376 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6378 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6380 if (can_change_color()) {
6382 all_colors = (RGB_DATA *) malloc(max_colors * sizeof(RGB_DATA));
6383 for (cp = 0; cp < max_colors; ++cp) {
6385 &all_colors[cp].red,
6386 &all_colors[cp].green,
6387 &all_colors[cp].blue);
6389 if (palette_file != 0) {
6390 FILE *fp = fopen(palette_file, "r");
6392 char buffer[BUFSIZ];
6393 int red, green, blue;
6395 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6396 if (sscanf(buffer, "scale:%d", &c) == 1) {
6398 } else if (sscanf(buffer, "%d:%d %d %d",
6407 all_colors[c].red = (red * 1000) / scale;
6408 all_colors[c].green = (green * 1000) / scale;
6409 all_colors[c].blue = (blue * 1000) / scale;
6417 set_terminal_modes();
6421 * Return to terminal mode, so we're guaranteed of being able to
6422 * select terminal commands even if the capabilities are wrong.
6426 #if HAVE_CURSES_VERSION
6427 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6428 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6429 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6430 NCURSES_VERSION_MAJOR,
6431 NCURSES_VERSION_MINOR,
6432 NCURSES_VERSION_PATCH);
6434 (void) puts("Welcome to ncurses. Press ? for help.");
6439 ExitProgram(EXIT_SUCCESS);
6442 /* ncurses.c ends here */