1 /****************************************************************************
2 * Copyright (c) 1998-2003,2004 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.202 2004/02/07 20:24:08 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
54 #include <sys/select.h>
70 #ifdef NCURSES_VERSION
73 static int save_trace = TRACE_ORDINARY | TRACE_CALLS;
74 extern int _nc_tracing;
79 #define mmask_t chtype /* not specified in XSI */
81 #ifdef CURSES_ACS_ARRAY
82 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
83 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
84 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
85 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
86 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
87 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
88 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
90 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
91 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
92 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
93 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
94 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
95 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
96 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
99 #ifdef CURSES_WACS_ARRAY
100 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
101 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
102 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
103 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
104 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
105 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
106 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
111 #define P(string) printw("%s\n", string)
113 #define BLANK ' ' /* this is the background character */
116 static int max_colors; /* the actual number of colors we'll use */
119 static int max_pairs; /* ...and the number of color pairs */
121 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
122 * though we can rely on negative x/y values to stop the macro.
125 do_h_line(int y, int x, chtype c, int to)
128 mvhline(y, x, c, (to) - (x));
132 do_v_line(int y, int x, chtype c, int to)
135 mvvline(y, x, c, (to) - (y));
138 /* Common function to allow ^T to toggle trace-mode in the middle of a test
139 * so that trace-files can be made smaller.
142 wGetchar(WINDOW *win)
146 while ((c = wgetch(win)) == CTRL('T')) {
148 save_trace = _nc_tracing;
149 _tracef("TOGGLE-TRACING OFF");
152 _nc_tracing = save_trace;
156 _tracef("TOGGLE-TRACING ON");
163 #define Getchar() wGetchar(stdscr)
165 /* replaces wgetnstr(), since we want to be able to edit values */
167 wGetstring(WINDOW *win, char *buffer, int limit)
174 wattrset(win, A_REVERSE);
178 if (x > (int) strlen(buffer))
179 x = (int) strlen(buffer);
181 wprintw(win, "%-*s", limit, buffer);
182 wmove(win, y0, x0 + x);
183 switch (ch = wGetchar(win)) {
196 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
214 if (!isprint(ch) || ch >= KEY_MIN) {
216 } else if ((int) strlen(buffer) < limit) {
218 for (j = strlen(buffer) + 1; j > x; --j) {
219 buffer[j] = buffer[j - 1];
228 wattroff(win, A_REVERSE);
233 #if USE_WIDEC_SUPPORT
235 wGet_wchar(WINDOW *win, wint_t * result)
239 while ((c = wget_wch(win, result)) == CTRL('T')) {
241 save_trace = _nc_tracing;
242 _tracef("TOGGLE-TRACING OFF");
245 _nc_tracing = save_trace;
249 _tracef("TOGGLE-TRACING ON");
252 c = wget_wch(win, result);
256 #define Get_wchar(result) wGet_wchar(stdscr, result)
258 /* replaces wgetn_wstr(), since we want to be able to edit values */
260 wGet_wstring(WINDOW *win, wchar_t * buffer, int limit)
268 wattrset(win, A_REVERSE);
272 if (x > (int) wcslen(buffer))
273 x = (int) wcslen(buffer);
275 waddnwstr(win, buffer, limit);
277 wprintw(win, "%*s", limit - x, " ");
278 wmove(win, y0, x0 + x);
279 switch (wGet_wchar(win, &ch)) {
313 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
331 if (!isprint(ch) || ch >= KEY_MIN) {
333 } else if ((int) wcslen(buffer) < limit) {
335 for (j = wcslen(buffer) + 1; j > x; --j) {
336 buffer[j] = buffer[j - 1];
345 wattroff(win, A_REVERSE);
356 addstr("Press any key to continue... ");
361 Cannot(const char *what)
363 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
368 ShellOut(bool message)
371 addstr("Shelling out...");
376 addstr("returned from shellout.\n");
380 #ifdef NCURSES_MOUSE_VERSION
382 mouse_decode(MEVENT const *ep)
386 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
387 ep->id, ep->x, ep->y, ep->z, ep->bstate);
389 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
390 SHOW(BUTTON1_RELEASED, "release-1");
391 SHOW(BUTTON1_PRESSED, "press-1");
392 SHOW(BUTTON1_CLICKED, "click-1");
393 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
394 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
395 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
396 SHOW(BUTTON2_RELEASED, "release-2");
397 SHOW(BUTTON2_PRESSED, "press-2");
398 SHOW(BUTTON2_CLICKED, "click-2");
399 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
400 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
401 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
402 SHOW(BUTTON3_RELEASED, "release-3");
403 SHOW(BUTTON3_PRESSED, "press-3");
404 SHOW(BUTTON3_CLICKED, "click-3");
405 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
406 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
407 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
408 SHOW(BUTTON4_RELEASED, "release-4");
409 SHOW(BUTTON4_PRESSED, "press-4");
410 SHOW(BUTTON4_CLICKED, "click-4");
411 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
412 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
413 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
414 SHOW(BUTTON_CTRL, "ctrl");
415 SHOW(BUTTON_SHIFT, "shift");
416 SHOW(BUTTON_ALT, "alt");
417 SHOW(ALL_MOUSE_EVENTS, "all-events");
418 SHOW(REPORT_MOUSE_POSITION, "position");
421 if (buf[strlen(buf) - 1] == ' ')
422 buf[strlen(buf) - 2] = '\0';
423 (void) strcat(buf, "}");
426 #endif /* NCURSES_MOUSE_VERSION */
428 /****************************************************************************
430 * Character input test
432 ****************************************************************************/
435 setup_getch(WINDOW *win, bool flags[])
437 keypad(win, flags['k']); /* should be redundant, but for testing */
438 meta(win, flags['m']); /* force this to a known state */
446 wgetch_help(WINDOW *win, bool flags[])
448 static const char *help[] =
450 "e -- toggle echo mode"
451 ,"g -- triggers a getstr test"
452 ,"k -- toggle keypad/literal mode"
453 ,"m -- toggle meta (7-bit/8-bit) mode"
454 ,"q -- quit (x also exits)"
456 ,"w -- create a new window"
458 ,"z -- suspend this process"
462 unsigned chk = ((SIZEOF(help) + 1) / 2);
467 printw("Type any key to see its %s value. Also:\n",
468 flags['k'] ? "keypad" : "literal");
469 for (n = 0; n < SIZEOF(help); ++n) {
470 int row = 1 + (n % chk);
471 int col = (n >= chk) ? COLS / 2 : 0;
472 int flg = ((strstr(help[n], "toggle") != 0)
473 && (flags[UChar(*help[n])] != FALSE));
476 mvprintw(row, col, "%s", help[n]);
487 wgetch_wrap(WINDOW *win, int first_y)
489 int last_y = getmaxy(win) - 1;
490 int y = getcury(win) + 1;
498 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
504 static WINSTACK *winstack = 0;
505 static unsigned len_winstack = 0;
508 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
510 unsigned need = (level + 1) * 2;
514 winstack = (WINSTACK *) malloc(len_winstack * sizeof(WINSTACK));
515 } else if (need >= len_winstack) {
517 winstack = (WINSTACK *) realloc(winstack, len_winstack * sizeof(WINSTACK));
519 winstack[level].text = txt_win;
520 winstack[level].frame = box_win;
524 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
525 * Resize both and paint the box in the parent.
528 resize_boxes(int level, WINDOW *win)
532 int high = LINES - base;
536 wnoutrefresh(stdscr);
538 /* FIXME: this chunk should be done in resizeterm() */
543 for (n = 0; (int) n < level; ++n) {
544 wresize(winstack[n].frame, high, wide);
545 wresize(winstack[n].text, high - 2, wide - 2);
548 werase(winstack[n].text);
549 box(winstack[n].frame, 0, 0);
550 wnoutrefresh(winstack[n].frame);
551 wprintw(winstack[n].text,
553 getmaxy(winstack[n].text),
554 getmaxx(winstack[n].text));
555 wnoutrefresh(winstack[n].text);
556 if (winstack[n].text == win)
562 #define remember_boxes(level,text,frame) /* nothing */
566 wgetch_test(int level, WINDOW *win, int delay)
569 int first_y, first_x;
573 bool blocking = (delay < 0);
576 memset(flags, FALSE, sizeof(flags));
577 flags[UChar('k')] = (win == stdscr);
579 setup_getch(win, flags);
580 wtimeout(win, delay);
581 getyx(win, first_y, first_x);
583 wgetch_help(win, flags);
584 wsetscrreg(win, first_y, getmaxy(win) - 1);
588 while ((c = wGetchar(win)) == ERR) {
591 (void) wprintw(win, "%05d: input error", incount);
594 (void) wprintw(win, "%05d: input timed out", incount);
596 wgetch_wrap(win, first_y);
598 if (c == ERR && blocking) {
600 wgetch_wrap(win, first_y);
601 } else if (c == 'x' || c == 'q') {
603 } else if (c == 'e') {
604 flags[UChar('e')] = !flags[UChar('e')];
605 setup_getch(win, flags);
606 wgetch_help(win, flags);
607 } else if (c == 'g') {
608 waddstr(win, "getstr test: ");
610 wgetnstr(win, buf, sizeof(buf) - 1);
612 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
614 wgetch_wrap(win, first_y);
615 } else if (c == 'k') {
616 flags[UChar('k')] = !flags[UChar('k')];
617 setup_getch(win, flags);
618 wgetch_help(win, flags);
619 } else if (c == 'm') {
620 flags[UChar('m')] = !flags[UChar('m')];
621 setup_getch(win, flags);
622 wgetch_help(win, flags);
623 } else if (c == 's') {
625 } else if (c == 'w') {
626 int high = getmaxy(win) - 1 - first_y + 1;
627 int wide = getmaxx(win) - first_x;
629 int new_y = first_y + getbegy(win);
630 int new_x = first_x + getbegx(win);
632 getyx(win, old_y, old_x);
633 if (high > 2 && wide > 2) {
634 WINDOW *wb = newwin(high, wide, new_y, new_x);
635 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
640 remember_boxes(level, wi, wb);
641 wgetch_test(level + 1, wi, delay);
645 wgetch_help(win, flags);
646 wmove(win, old_y, old_x);
652 } else if (c == 'z') {
653 kill(getpid(), SIGTSTP);
656 wprintw(win, "Key pressed: %04o ", c);
657 #ifdef NCURSES_MOUSE_VERSION
658 if (c == KEY_MOUSE) {
662 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
664 move(event.y, event.x);
668 #endif /* NCURSES_MOUSE_VERSION */
670 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
671 if (c == KEY_RESIZE) {
672 resize_boxes(level, win);
675 (void) waddstr(win, keyname(c));
676 } else if (c > 0x80) {
679 (void) wprintw(win, "M-%c", c2);
681 (void) wprintw(win, "M-%s", unctrl(c2));
682 waddstr(win, " (high-half character)");
685 (void) wprintw(win, "%c (ASCII printable character)", c);
687 (void) wprintw(win, "%s (ASCII control character)",
690 wgetch_wrap(win, first_y);
698 begin_getch_test(void)
705 #ifdef NCURSES_MOUSE_VERSION
706 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
709 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
711 getnstr(buf, sizeof(buf) - 1);
715 if (isdigit(UChar(buf[0]))) {
716 delay = atoi(buf) * 100;
726 finish_getch_test(void)
728 #ifdef NCURSES_MOUSE_VERSION
729 mousemask(0, (mmask_t *) 0);
740 int delay = begin_getch_test();
741 wgetch_test(0, stdscr, delay);
745 #if USE_WIDEC_SUPPORT
747 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
748 * Resize both and paint the box in the parent.
752 resize_wide_boxes(int level, WINDOW *win)
756 int high = LINES - base;
760 wnoutrefresh(stdscr);
762 /* FIXME: this chunk should be done in resizeterm() */
767 for (n = 0; (int) n < level; ++n) {
768 wresize(winstack[n].frame, high, wide);
769 wresize(winstack[n].text, high - 2, wide - 2);
772 werase(winstack[n].text);
773 box_set(winstack[n].frame, 0, 0);
774 wnoutrefresh(winstack[n].frame);
775 wprintw(winstack[n].text,
777 getmaxy(winstack[n].text),
778 getmaxx(winstack[n].text));
779 wnoutrefresh(winstack[n].text);
780 if (winstack[n].text == win)
785 #endif /* KEY_RESIZE */
788 wcstos(const wchar_t * src)
793 const wchar_t *tmp = src;
795 memset(&state, 0, sizeof(state));
796 if ((need = wcsrtombs(0, &tmp, 0, &state)) > 0) {
797 result = (char *) calloc(need + 1, 1);
799 if (wcsrtombs(result, &tmp, need, &state) != (size_t) need) {
808 wget_wch_test(int level, WINDOW *win, int delay)
811 int first_y, first_x;
815 bool blocking = (delay < 0);
819 memset(flags, FALSE, sizeof(flags));
820 flags[UChar('k')] = (win == stdscr);
822 setup_getch(win, flags);
823 wtimeout(win, delay);
824 getyx(win, first_y, first_x);
826 wgetch_help(win, flags);
827 wsetscrreg(win, first_y, getmaxy(win) - 1);
831 while ((code = wGet_wchar(win, &c)) == ERR) {
834 (void) wprintw(win, "%05d: input error", incount);
837 (void) wprintw(win, "%05d: input timed out", incount);
839 wgetch_wrap(win, first_y);
841 if (code == ERR && blocking) {
843 wgetch_wrap(win, first_y);
844 } else if (c == 'x' || c == 'q') {
846 } else if (c == 'e') {
847 flags[UChar('e')] = !flags[UChar('e')];
848 setup_getch(win, flags);
849 wgetch_help(win, flags);
850 } else if (c == 'g') {
851 waddstr(win, "getstr test: ");
853 wgetn_wstr(win, (wint_t *) buf, sizeof(buf) - 1);
855 if ((temp = wcstos(buf)) != 0) {
856 wprintw(win, "I saw %d characters:\n\t`%s'.", wcslen(buf), temp);
859 wprintw(win, "I saw %d characters (cannot convert).", wcslen(buf));
862 wgetch_wrap(win, first_y);
863 } else if (c == 'k') {
864 flags[UChar('k')] = !flags[UChar('k')];
865 setup_getch(win, flags);
866 wgetch_help(win, flags);
867 } else if (c == 'm') {
868 flags[UChar('m')] = !flags[UChar('m')];
869 setup_getch(win, flags);
870 wgetch_help(win, flags);
871 } else if (c == 's') {
873 } else if (c == 'w') {
874 int high = getmaxy(win) - 1 - first_y + 1;
875 int wide = getmaxx(win) - first_x;
877 int new_y = first_y + getbegy(win);
878 int new_x = first_x + getbegx(win);
880 getyx(win, old_y, old_x);
881 if (high > 2 && wide > 2) {
882 WINDOW *wb = newwin(high, wide, new_y, new_x);
883 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
888 remember_boxes(level, wi, wb);
889 wget_wch_test(level + 1, wi, delay);
893 wgetch_help(win, flags);
894 wmove(win, old_y, old_x);
899 } else if (c == 'z') {
900 kill(getpid(), SIGTSTP);
903 wprintw(win, "Key pressed: %04o ", c);
904 #ifdef NCURSES_MOUSE_VERSION
905 if (c == KEY_MOUSE) {
909 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
911 move(event.y, event.x);
915 #endif /* NCURSES_MOUSE_VERSION */
916 if (code == KEY_CODE_YES) {
918 if (c == KEY_RESIZE) {
919 resize_wide_boxes(level, win);
922 (void) waddstr(win, key_name(c));
924 if (c < 256 && iscntrl(c)) {
925 (void) wprintw(win, "%s (control character)", unctrl(c));
928 waddnwstr(win, &c2, 1);
929 (void) wprintw(win, " = %#x (printable character)", c);
932 wgetch_wrap(win, first_y);
942 int delay = begin_getch_test();
943 wget_wch_test(0, stdscr, delay);
948 /****************************************************************************
950 * Character attributes test
952 ****************************************************************************/
954 #define MAX_ATTRSTRING 31
955 #define LEN_ATTRSTRING 26
957 static char attr_test_string[] = "abcde fghij klmno pqrst uvwxy z";
960 adjust_attr_string(int adjust)
962 int first = ((int) UChar(attr_test_string[0])) + adjust;
963 int last = first + LEN_ATTRSTRING;
965 if (first >= ' ' && last <= '~') { /* 32..126 */
967 for (j = 0, k = first; k <= last; ++j, ++k) {
968 attr_test_string[j] = k;
969 if (((k + 1 - first) % 5) == 0) {
971 if (j < MAX_ATTRSTRING)
972 attr_test_string[j] = ' ';
975 while (j < MAX_ATTRSTRING)
976 attr_test_string[j++] = ' ';
977 attr_test_string[j] = '\0';
984 show_attr(int row, int skip, chtype attr, const char *name)
986 int ncv = tigetnum("ncv");
987 chtype test = attr & ~A_ALTCHARSET;
989 mvprintw(row, 8, "%s mode:", name);
990 mvprintw(row, 24, "|");
992 printw("%*s", skip, " ");
995 * If we're to write a string in the alternate character set, it is not
996 * sufficient to just set A_ALTCHARSET. We have to perform the mapping
997 * that corresponds. This is not needed for vt100-compatible devices
998 * because the acs_map[] is 1:1, but for PC-style devices such as Linux
999 * console, the acs_map[] is scattered about the range.
1001 * The addch/addstr functions do not themselves do this mapping, since it
1002 * is possible to turn off the A_ALTCHARSET flag for the characters which
1003 * are added, and it would be an unexpected result to have the mapped
1004 * characters visible on the screen.
1006 if (attr & A_ALTCHARSET) {
1010 for (s = attr_test_string; *s != '\0'; ++s) {
1015 addstr(attr_test_string);
1019 printw("%*s", skip, " ");
1021 if (test != A_NORMAL) {
1022 if (!(termattrs() & test)) {
1024 } else if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1025 static const chtype table[] =
1039 for (n = 0; n < SIZEOF(table); n++) {
1040 if ((table[n] & attr) != 0
1041 && ((1 << n) & ncv) != 0) {
1054 attr_getc(int *skip, int *fg, int *bg, int *ac)
1060 } else if (ch == CTRL('L')) {
1073 adjust_attr_string(-1);
1076 adjust_attr_string(1);
1096 if (*fg >= max_colors)
1099 *fg = max_colors - 1;
1100 if (*bg >= max_colors)
1103 *bg = max_colors - 1;
1113 /* test text attributes */
1116 int skip = tigetnum("xmc");
1117 int fg = COLOR_BLACK; /* color pair 0 is special */
1118 int bg = COLOR_BLACK;
1120 bool *pairs = (bool *) calloc(max_pairs, sizeof(bool));
1126 n = skip; /* make it easy */
1130 int normal = A_NORMAL | BLANK;
1133 int pair = (fg * max_colors) + bg;
1135 init_pair(pair, fg, bg);
1138 normal |= COLOR_PAIR(pair);
1145 mvaddstr(0, 20, "Character attribute test display");
1147 row = show_attr(row, n, ac | A_STANDOUT, "STANDOUT");
1148 row = show_attr(row, n, ac | A_REVERSE, "REVERSE");
1149 row = show_attr(row, n, ac | A_BOLD, "BOLD");
1150 row = show_attr(row, n, ac | A_UNDERLINE, "UNDERLINE");
1151 row = show_attr(row, n, ac | A_DIM, "DIM");
1152 row = show_attr(row, n, ac | A_BLINK, "BLINK");
1153 row = show_attr(row, n, ac | A_PROTECT, "PROTECT");
1154 row = show_attr(row, n, ac | A_INVIS, "INVISIBLE");
1155 row = show_attr(row, n, ac | A_NORMAL, "NORMAL");
1158 "This terminal does %shave the magic-cookie glitch",
1159 tigetnum("xmc") > -1 ? "" : "not ");
1160 mvprintw(row + 1, 8,
1161 "Enter a digit to set gaps on each side of displayed attributes");
1162 mvprintw(row + 2, 8,
1163 "^L repaints, </> shifts, ");
1165 printw("f/F/b/F toggle color (now %d/%d), a/A ACS (%d)",
1168 printw("a/A ACS (%d)", ac != 0);
1171 } while (attr_getc(&n, &fg, &bg, &ac));
1173 free((char *) pairs);
1174 bkgdset(A_NORMAL | BLANK);
1179 /****************************************************************************
1181 * Color support tests
1183 ****************************************************************************/
1185 static NCURSES_CONST char *the_color_names[] =
1206 show_color_name(int y, int x, int color)
1209 mvprintw(y, x, "%02d ", color);
1211 mvaddstr(y, x, the_color_names[color]);
1216 /* generate a color test pattern */
1219 int base, top, width;
1223 (void) printw("There are %d color pairs\n", COLOR_PAIRS);
1225 width = (max_colors > 8) ? 4 : 8;
1226 hello = (max_colors > 8) ? "Test" : "Hello";
1228 for (base = 0; base < 2; base++) {
1229 top = (max_colors > 8) ? 0 : base * (max_colors + 3);
1231 (void) mvprintw(top + 1, 0,
1232 "%dx%d matrix of foreground/background colors, bright *%s*\n",
1233 max_colors, max_colors,
1234 base ? "on" : "off");
1235 for (i = 0; i < max_colors; i++)
1236 show_color_name(top + 2, (i + 1) * width, i);
1237 for (i = 0; i < max_colors; i++)
1238 show_color_name(top + 3 + i, 0, i);
1239 for (i = 1; i < max_pairs; i++) {
1240 init_pair(i, i % max_colors, i / max_colors);
1241 attron((attr_t) COLOR_PAIR(i));
1243 attron((attr_t) A_BOLD);
1244 mvaddstr(top + 3 + (i / max_colors), (i % max_colors + 1) *
1248 if ((max_colors > 8) || base)
1257 change_color(int current, int field, int value, int usebase)
1259 short red, green, blue;
1262 color_content(current, &red, &green, &blue);
1264 red = green = blue = 0;
1278 if (init_color(current, red, green, blue) == ERR)
1284 /* display the color test pattern, without trying to edit colors */
1286 int i, this_c = 0, value = 0, current = 0, field = 0;
1291 for (i = 0; i < max_colors; i++)
1292 init_pair(i, COLOR_WHITE, i);
1294 mvprintw(LINES - 2, 0, "Number: %d", value);
1297 short red, green, blue;
1300 mvaddstr(0, 20, "Color RGB Value Editing");
1303 for (i = 0; i < max_colors; i++) {
1304 mvprintw(2 + i, 0, "%c %-8s:",
1305 (i == current ? '>' : ' '),
1306 (i < (int) SIZEOF(the_color_names)
1307 ? the_color_names[i] : ""));
1308 attrset(COLOR_PAIR(i));
1313 * Note: this refresh should *not* be necessary! It works around
1314 * a bug in attribute handling that apparently causes the A_NORMAL
1315 * attribute sets to interfere with the actual emission of the
1316 * color setting somehow. This needs to be fixed.
1320 color_content(i, &red, &green, &blue);
1322 if (current == i && field == 0)
1324 printw("%04d", red);
1325 if (current == i && field == 0)
1328 if (current == i && field == 1)
1330 printw("%04d", green);
1331 if (current == i && field == 1)
1334 if (current == i && field == 2)
1336 printw("%04d", blue);
1337 if (current == i && field == 2)
1343 mvaddstr(max_colors + 3, 0,
1344 "Use up/down to select a color, left/right to change fields.");
1345 mvaddstr(max_colors + 4, 0,
1346 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
1348 move(2 + current, 0);
1352 if (isdigit(this_c) && !isdigit(last_c))
1357 current = (current == 0 ? (max_colors - 1) : current - 1);
1361 current = (current == (max_colors - 1) ? 0 : current + 1);
1365 field = (field == 2 ? 0 : field + 1);
1369 field = (field == 0 ? 2 : field - 1);
1382 value = value * 10 + (this_c - '0');
1386 change_color(current, field, value, 1);
1390 change_color(current, field, -value, 1);
1394 change_color(current, field, value, 0);
1399 P(" RGB Value Editing Help");
1401 P("You are in the RGB value editor. Use the arrow keys to select one of");
1402 P("the fields in one of the RGB triples of the current colors; the one");
1403 P("currently selected will be reverse-video highlighted.");
1405 P("To change a field, enter the digits of the new value; they are echoed");
1406 P("as entered. Finish by typing `='. The change will take effect instantly.");
1407 P("To increment or decrement a value, use the same procedure, but finish");
1408 P("with a `+' or `-'.");
1410 P("To quit, do `x' or 'q'");
1424 mvprintw(LINES - 2, 0, "Number: %d", value);
1427 (this_c != 'x' && this_c != 'q');
1433 /****************************************************************************
1435 * Soft-key label test
1437 ****************************************************************************/
1440 #define SLK_WORK (SLK_HELP + 3)
1445 static const char *table[] =
1447 "Available commands are:"
1449 ,"^L -- repaint this message and activate soft keys"
1450 ,"a/d -- activate/disable soft keys"
1451 ,"c -- set centered format for labels"
1452 ,"l -- set left-justified format for labels"
1453 ,"r -- set right-justified format for labels"
1454 ,"[12345678] -- set label; labels are numbered 1 through 8"
1455 ,"e -- erase stdscr (should not erase labels)"
1456 ,"s -- test scrolling of shortened screen"
1458 ,"F/B -- cycle through foreground/background colors"
1460 ,"x, q -- return to main menu"
1462 ,"Note: if activating the soft keys causes your terminal to scroll up"
1463 ,"one line, your terminal auto-scrolls when anything is written to the"
1464 ,"last screen position. The ncurses code does not yet handle this"
1470 for (j = 0; j < SIZEOF(table); ++j) {
1478 /* exercise the soft keys */
1484 short fg = COLOR_BLACK;
1485 short bg = COLOR_WHITE;
1486 bool new_color = FALSE;
1499 init_pair(1, bg, fg);
1502 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
1511 mvaddstr(0, 20, "Soft Key Exerciser");
1526 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
1527 while ((c = Getchar()) != 'Q' && (c != ERR))
1555 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
1557 if ((s = slk_label(c - '0')) != 0) {
1560 wGetstring(stdscr, buf, 8);
1561 slk_set((c - '0'), buf, fmt);
1574 fg = (fg + 1) % max_colors;
1580 bg = (bg + 1) % max_colors;
1590 ((c = Getchar()) != EOF);
1597 #if USE_WIDEC_SUPPORT
1600 /* exercise the soft keys */
1605 short fg = COLOR_BLACK;
1606 short bg = COLOR_WHITE;
1607 bool new_color = FALSE;
1615 init_pair(1, bg, fg);
1618 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
1625 attr_on(WA_BOLD, NULL);
1626 mvaddstr(0, 20, "Soft Key Exerciser");
1627 attr_off(WA_BOLD, NULL);
1641 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
1642 while ((c = Getchar()) != 'Q' && (c != ERR))
1670 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
1672 if ((s = slk_label(c - '0')) != 0) {
1674 for (j = 0; j < 8; ++j) {
1675 if ((buf[j] = UChar(s[j])) == 0)
1680 wGet_wstring(stdscr, buf, 8);
1681 slk_wset((c - '0'), buf, fmt);
1693 fg = (fg + 1) % max_colors;
1699 bg = (bg + 1) % max_colors;
1708 ((c = Getchar()) != EOF);
1716 /****************************************************************************
1718 * Alternate character-set stuff
1720 ****************************************************************************/
1722 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
1723 * terminal to perform functions. The remaining codes can be graphic.
1726 show_upper_chars(int first)
1728 bool C1 = (first == 128);
1730 int last = first + 31;
1735 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
1736 C1 ? "C1" : "GR", first, last);
1740 for (code = first; code <= last; code++) {
1741 int row = 4 + ((code - first) % 16);
1742 int col = ((code - first) / 16) * COLS / 2;
1744 sprintf(tmp, "%3d (0x%x)", code, code);
1745 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
1747 nodelay(stdscr, TRUE);
1750 /* (yes, this _is_ crude) */
1751 while ((reply = Getchar()) != ERR) {
1755 nodelay(stdscr, FALSE);
1761 show_box_chars(void)
1765 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
1770 mvhline(LINES / 2, 0, ACS_HLINE, COLS);
1771 mvvline(0, COLS / 2, ACS_VLINE, LINES);
1772 mvaddch(0, COLS / 2, ACS_TTEE);
1773 mvaddch(LINES / 2, COLS / 2, ACS_PLUS);
1774 mvaddch(LINES - 1, COLS / 2, ACS_BTEE);
1775 mvaddch(LINES / 2, 0, ACS_LTEE);
1776 mvaddch(LINES / 2, COLS - 1, ACS_RTEE);
1782 show_1_acs(int n, const char *name, chtype code)
1784 const int height = 16;
1785 int row = 4 + (n % height);
1786 int col = (n / height) * COLS / 2;
1787 mvprintw(row, col, "%*s : ", COLS / 4, name);
1793 show_acs_chars(void)
1794 /* display the ACS character set */
1798 #define BOTH(name) #name, name
1802 mvaddstr(0, 20, "Display of the ACS Character Set");
1806 n = show_1_acs(0, BOTH(ACS_ULCORNER));
1807 n = show_1_acs(n, BOTH(ACS_URCORNER));
1808 n = show_1_acs(n, BOTH(ACS_LLCORNER));
1809 n = show_1_acs(n, BOTH(ACS_LRCORNER));
1811 n = show_1_acs(n, BOTH(ACS_LTEE));
1812 n = show_1_acs(n, BOTH(ACS_RTEE));
1813 n = show_1_acs(n, BOTH(ACS_TTEE));
1814 n = show_1_acs(n, BOTH(ACS_BTEE));
1816 n = show_1_acs(n, BOTH(ACS_HLINE));
1817 n = show_1_acs(n, BOTH(ACS_VLINE));
1819 n = show_1_acs(n, BOTH(ACS_LARROW));
1820 n = show_1_acs(n, BOTH(ACS_RARROW));
1821 n = show_1_acs(n, BOTH(ACS_UARROW));
1822 n = show_1_acs(n, BOTH(ACS_DARROW));
1824 n = show_1_acs(n, BOTH(ACS_BLOCK));
1825 n = show_1_acs(n, BOTH(ACS_BOARD));
1826 n = show_1_acs(n, BOTH(ACS_LANTERN));
1827 n = show_1_acs(n, BOTH(ACS_BULLET));
1828 n = show_1_acs(n, BOTH(ACS_CKBOARD));
1829 n = show_1_acs(n, BOTH(ACS_DEGREE));
1830 n = show_1_acs(n, BOTH(ACS_DIAMOND));
1831 n = show_1_acs(n, BOTH(ACS_PLMINUS));
1832 n = show_1_acs(n, BOTH(ACS_PLUS));
1834 n = show_1_acs(n, BOTH(ACS_GEQUAL));
1835 n = show_1_acs(n, BOTH(ACS_NEQUAL));
1836 n = show_1_acs(n, BOTH(ACS_LEQUAL));
1838 n = show_1_acs(n, BOTH(ACS_STERLING));
1839 n = show_1_acs(n, BOTH(ACS_PI));
1840 n = show_1_acs(n, BOTH(ACS_S1));
1841 n = show_1_acs(n, BOTH(ACS_S3));
1842 n = show_1_acs(n, BOTH(ACS_S7));
1843 n = show_1_acs(n, BOTH(ACS_S9));
1863 show_upper_chars((c - '0') * 32 + 128);
1866 mvprintw(LINES - 3, 0,
1867 "Note: ANSI terminals may not display C1 characters.");
1868 mvprintw(LINES - 2, 0,
1869 "Select: a=ACS, b=box, 0=C1, 1,2,3=GR characters, q=quit");
1871 } while ((c = Getchar()) != 'x' && c != 'q');
1878 #if USE_WIDEC_SUPPORT
1880 show_upper_widechars(int first, int repeat)
1884 int last = first + 31;
1888 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
1891 for (code = first; code <= last; code++) {
1892 int row = 4 + ((code - first) % 16);
1893 int col = ((code - first) / 16) * COLS / 2;
1895 attr_t attrs = A_NORMAL;
1899 memset(&codes, 0, sizeof(codes));
1901 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
1902 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
1903 setcchar(&temp, codes, attrs, 0, 0);
1906 * This could use add_wch(), but is done for comparison with the
1907 * normal 'f' test (and to make a test-case for echo_wchar()).
1908 * The screen will flicker because the erase() at the top of the
1909 * function is met by the builtin refresh() in echo_wchar().
1912 } while (--count > 0);
1917 show_1_wacs(int n, const char *name, const cchar_t * code)
1919 const int height = 16;
1920 int row = 4 + (n % height);
1921 int col = (n / height) * COLS / 2;
1922 mvprintw(row, col, "%*s : ", COLS / 4, name);
1923 add_wchnstr(code, 1);
1928 show_wacs_chars(void)
1929 /* display the wide-ACS character set */
1933 /*#define BOTH2(name) #name, &(name) */
1934 #define BOTH2(name) #name, name
1938 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
1942 n = show_1_wacs(0, BOTH2(WACS_ULCORNER));
1943 n = show_1_wacs(n, BOTH2(WACS_URCORNER));
1944 n = show_1_wacs(n, BOTH2(WACS_LLCORNER));
1945 n = show_1_wacs(n, BOTH2(WACS_LRCORNER));
1947 n = show_1_wacs(n, BOTH2(WACS_LTEE));
1948 n = show_1_wacs(n, BOTH2(WACS_RTEE));
1949 n = show_1_wacs(n, BOTH2(WACS_TTEE));
1950 n = show_1_wacs(n, BOTH2(WACS_BTEE));
1952 n = show_1_wacs(n, BOTH2(WACS_HLINE));
1953 n = show_1_wacs(n, BOTH2(WACS_VLINE));
1955 n = show_1_wacs(n, BOTH2(WACS_LARROW));
1956 n = show_1_wacs(n, BOTH2(WACS_RARROW));
1957 n = show_1_wacs(n, BOTH2(WACS_UARROW));
1958 n = show_1_wacs(n, BOTH2(WACS_DARROW));
1960 n = show_1_wacs(n, BOTH2(WACS_BLOCK));
1961 n = show_1_wacs(n, BOTH2(WACS_BOARD));
1962 n = show_1_wacs(n, BOTH2(WACS_LANTERN));
1963 n = show_1_wacs(n, BOTH2(WACS_BULLET));
1964 n = show_1_wacs(n, BOTH2(WACS_CKBOARD));
1965 n = show_1_wacs(n, BOTH2(WACS_DEGREE));
1966 n = show_1_wacs(n, BOTH2(WACS_DIAMOND));
1967 n = show_1_wacs(n, BOTH2(WACS_PLMINUS));
1968 n = show_1_wacs(n, BOTH2(WACS_PLUS));
1970 #ifdef CURSES_WACS_ARRAY
1971 n = show_1_wacs(n, BOTH2(WACS_GEQUAL));
1972 n = show_1_wacs(n, BOTH2(WACS_NEQUAL));
1973 n = show_1_wacs(n, BOTH2(WACS_LEQUAL));
1975 n = show_1_wacs(n, BOTH2(WACS_STERLING));
1976 n = show_1_wacs(n, BOTH2(WACS_PI));
1977 n = show_1_wacs(n, BOTH2(WACS_S1));
1978 n = show_1_wacs(n, BOTH2(WACS_S3));
1979 n = show_1_wacs(n, BOTH2(WACS_S7));
1980 n = show_1_wacs(n, BOTH2(WACS_S9));
1985 show_wbox_chars(void)
1989 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
1992 box_set(stdscr, 0, 0);
1994 mvhline_set(LINES / 2, 0, WACS_HLINE, COLS);
1995 mvvline_set(0, COLS / 2, WACS_VLINE, LINES);
1996 mvadd_wch(0, COLS / 2, WACS_TTEE);
1997 mvadd_wch(LINES / 2, COLS / 2, WACS_PLUS);
1998 mvadd_wch(LINES - 1, COLS / 2, WACS_BTEE);
1999 mvadd_wch(LINES / 2, 0, WACS_LTEE);
2000 mvadd_wch(LINES / 2, COLS - 1, WACS_RTEE);
2006 show_2_wacs(int n, const char *name, const char *code)
2008 const int height = 16;
2009 int row = 4 + (n % height);
2010 int col = (n / height) * COLS / 2;
2013 mvprintw(row, col, "%*s : ", COLS / 4, name);
2014 addstr(strcpy(temp, code));
2019 show_utf8_chars(void)
2020 /* display the wide-ACS character set */
2026 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
2030 n = show_2_wacs(0, "WACS_ULCORNER", "\342\224\214");
2031 n = show_2_wacs(n, "WACS_URCORNER", "\342\224\220");
2032 n = show_2_wacs(n, "WACS_LLCORNER", "\342\224\224");
2033 n = show_2_wacs(n, "WACS_LRCORNER", "\342\224\230");
2035 n = show_2_wacs(n, "WACS_LTEE", "\342\224\234");
2036 n = show_2_wacs(n, "WACS_RTEE", "\342\224\244");
2037 n = show_2_wacs(n, "WACS_TTEE", "\342\224\254");
2038 n = show_2_wacs(n, "WACS_BTEE", "\342\224\264");
2040 n = show_2_wacs(n, "WACS_HLINE", "\342\224\200");
2041 n = show_2_wacs(n, "WACS_VLINE", "\342\224\202");
2043 n = show_2_wacs(n, "WACS_LARROW", "\342\206\220");
2044 n = show_2_wacs(n, "WACS_RARROW", "\342\206\222");
2045 n = show_2_wacs(n, "WACS_UARROW", "\342\206\221");
2046 n = show_2_wacs(n, "WACS_DARROW", "\342\206\223");
2048 n = show_2_wacs(n, "WACS_BLOCK", "\342\226\256");
2049 n = show_2_wacs(n, "WACS_BOARD", "\342\226\222");
2050 n = show_2_wacs(n, "WACS_LANTERN", "\342\230\203");
2051 n = show_2_wacs(n, "WACS_BULLET", "\302\267");
2052 n = show_2_wacs(n, "WACS_CKBOARD", "\342\226\222");
2053 n = show_2_wacs(n, "WACS_DEGREE", "\302\260");
2054 n = show_2_wacs(n, "WACS_DIAMOND", "\342\227\206");
2055 n = show_2_wacs(n, "WACS_PLMINUS", "\302\261");
2056 n = show_2_wacs(n, "WACS_PLUS", "\342\224\274");
2057 n = show_2_wacs(n, "WACS_GEQUAL", "\342\211\245");
2058 n = show_2_wacs(n, "WACS_NEQUAL", "\342\211\240");
2059 n = show_2_wacs(n, "WACS_LEQUAL", "\342\211\244");
2061 n = show_2_wacs(n, "WACS_STERLING", "\302\243");
2062 n = show_2_wacs(n, "WACS_PI", "\317\200");
2063 n = show_2_wacs(n, "WACS_S1", "\342\216\272");
2064 n = show_2_wacs(n, "WACS_S3", "\342\216\273");
2065 n = show_2_wacs(n, "WACS_S7", "\342\216\274");
2066 n = show_2_wacs(n, "WACS_S9", "\342\216\275");
2072 wide_acs_display(void)
2094 else if (c == '-' && digit > 0)
2098 else if (c == '<' && repeat > 0)
2104 show_upper_widechars(digit * 32 + 128, repeat);
2107 mvprintw(LINES - 2, 0,
2108 "Select: a WACS, b box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, q=quit");
2110 } while ((c = Getchar()) != 'x' && c != 'q');
2120 * Graphic-rendition test (adapted from vttest)
2123 test_sgr_attributes(void)
2127 for (pass = 0; pass < 2; pass++) {
2128 int normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
2130 /* Use non-default colors if possible to exercise bce a little */
2132 init_pair(1, COLOR_WHITE, COLOR_BLUE);
2133 normal |= COLOR_PAIR(1);
2137 mvprintw(1, 20, "Graphic rendition test pattern:");
2139 mvprintw(4, 1, "vanilla");
2141 #define set_sgr(mask) bkgdset((normal^(mask)));
2143 mvprintw(4, 40, "bold");
2145 set_sgr(A_UNDERLINE);
2146 mvprintw(6, 6, "underline");
2148 set_sgr(A_BOLD | A_UNDERLINE);
2149 mvprintw(6, 45, "bold underline");
2152 mvprintw(8, 1, "blink");
2154 set_sgr(A_BLINK | A_BOLD);
2155 mvprintw(8, 40, "bold blink");
2157 set_sgr(A_UNDERLINE | A_BLINK);
2158 mvprintw(10, 6, "underline blink");
2160 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
2161 mvprintw(10, 45, "bold underline blink");
2164 mvprintw(12, 1, "negative");
2166 set_sgr(A_BOLD | A_REVERSE);
2167 mvprintw(12, 40, "bold negative");
2169 set_sgr(A_UNDERLINE | A_REVERSE);
2170 mvprintw(14, 6, "underline negative");
2172 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
2173 mvprintw(14, 45, "bold underline negative");
2175 set_sgr(A_BLINK | A_REVERSE);
2176 mvprintw(16, 1, "blink negative");
2178 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
2179 mvprintw(16, 40, "bold blink negative");
2181 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
2182 mvprintw(18, 6, "underline blink negative");
2184 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
2185 mvprintw(18, 45, "bold underline blink negative");
2188 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
2194 bkgdset(A_NORMAL | BLANK);
2199 /****************************************************************************
2201 * Windows and scrolling tester.
2203 ****************************************************************************/
2205 #define BOTLINES 4 /* number of line stolen from screen bottom */
2211 #define FRAME struct frame
2220 #ifdef NCURSES_VERSION
2221 #define keypad_active(win) (win)->_use_keypad
2222 #define scroll_active(win) (win)->_scroll
2224 #define keypad_active(win) FALSE
2225 #define scroll_active(win) FALSE
2228 /* We need to know if these flags are actually set, so don't look in FRAME.
2229 * These names are known to work with SVr4 curses as well as ncurses. The
2230 * _use_keypad name does not work with Solaris 8.
2233 HaveKeypad(FRAME * curp)
2235 WINDOW *win = (curp ? curp->wind : stdscr);
2236 return keypad_active(win);
2240 HaveScroll(FRAME * curp)
2242 WINDOW *win = (curp ? curp->wind : stdscr);
2243 return scroll_active(win);
2247 newwin_legend(FRAME * curp)
2249 static const struct {
2254 "^C = create window", 0
2257 "^N = next window", 0
2260 "^P = previous window", 0
2263 "^F = scroll forward", 0
2266 "^B = scroll backward", 0
2269 "^K = keypad(%s)", 1
2272 "^S = scrollok(%s)", 2
2275 "^W = save window to file", 0
2278 "^R = restore window", 0
2291 bool do_keypad = HaveKeypad(curp);
2292 bool do_scroll = HaveScroll(curp);
2296 for (n = 0; n < SIZEOF(legend); n++) {
2297 switch (legend[n].code) {
2299 strcpy(buf, legend[n].msg);
2302 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
2305 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
2308 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
2311 x = getcurx(stdscr);
2312 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
2319 transient(FRAME * curp, NCURSES_CONST char *msg)
2321 newwin_legend(curp);
2323 mvaddstr(LINES - 1, 0, msg);
2329 printw("%s characters are echoed, window should %sscroll.",
2330 HaveKeypad(curp) ? "Non-arrow" : "All other",
2331 HaveScroll(curp) ? "" : "not ");
2336 newwin_report(FRAME * curp)
2337 /* report on the cursor's current position, then restore it */
2339 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
2343 transient(curp, (char *) 0);
2345 move(LINES - 1, COLS - 17);
2346 printw("Y = %2d X = %2d", y, x);
2354 selectcell(int uli, int ulj, int lri, int lrj)
2355 /* arrows keys move cursor, return location at current on non-arrow key */
2357 static pair res; /* result cell */
2358 int si = lri - uli + 1; /* depth of the select area */
2359 int sj = lrj - ulj + 1; /* width of the select area */
2360 int i = 0, j = 0; /* offsets into the select area */
2365 move(uli + i, ulj + j);
2366 newwin_report((FRAME *) 0);
2368 switch (Getchar()) {
2383 return ((pair *) 0);
2384 #ifdef NCURSES_MOUSE_VERSION
2390 if (event.y > uli && event.x > ulj) {
2411 outerbox(pair ul, pair lr, bool onoff)
2412 /* draw or erase a box *outside* the given pair of corners */
2414 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
2415 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
2416 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
2417 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
2418 move(ul.y - 1, ul.x);
2419 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
2420 move(ul.y, ul.x - 1);
2421 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
2422 move(lr.y + 1, ul.x);
2423 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
2424 move(ul.y, lr.x + 1);
2425 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
2430 /* Ask user for a window definition */
2437 addstr("Use arrows to move cursor, anything else to mark corner 1");
2439 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
2440 return ((WINDOW *) 0);
2441 memcpy(&ul, tmp, sizeof(pair));
2442 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
2445 addstr("Use arrows to move cursor, anything else to mark corner 2");
2447 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
2449 return ((WINDOW *) 0);
2450 memcpy(&lr, tmp, sizeof(pair));
2452 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
2454 outerbox(ul, lr, TRUE);
2465 newwin_move(FRAME * curp, int dy, int dx)
2467 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
2471 getyx(win, cur_y, cur_x);
2472 getmaxyx(win, max_y, max_x);
2473 if ((cur_x += dx) < 0)
2475 else if (cur_x >= max_x)
2477 if ((cur_y += dy) < 0)
2479 else if (cur_y >= max_y)
2481 wmove(win, cur_y, cur_x);
2485 delete_framed(FRAME * fp, bool showit)
2489 fp->last->next = fp->next;
2490 fp->next->last = fp->last;
2498 np = (fp == fp->next) ? 0 : fp->next;
2504 acs_and_scroll(void)
2505 /* Demonstrate windows */
2509 FRAME *current = (FRAME *) 0, *neww;
2510 WINDOW *usescr = stdscr;
2512 #define DUMPFILE "screendump"
2514 #ifdef NCURSES_MOUSE_VERSION
2515 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
2520 transient((FRAME *) 0, (char *) 0);
2523 neww = (FRAME *) calloc(1, sizeof(FRAME));
2524 if ((neww->wind = getwindow()) == (WINDOW *) 0)
2527 if (current == 0) { /* First element, */
2528 neww->next = neww; /* so point it at itself */
2531 neww->next = current->next;
2532 neww->last = current;
2533 neww->last->next = neww;
2534 neww->next->last = neww;
2537 /* SVr4 curses sets the keypad on all newly-created windows to
2538 * false. Someone reported that PDCurses makes new windows inherit
2539 * this flag. Remove the following 'keypad()' call to test this
2541 keypad(current->wind, TRUE);
2542 current->do_keypad = HaveKeypad(current);
2543 current->do_scroll = HaveScroll(current);
2546 case CTRL('N'): /* go to next window */
2548 current = current->next;
2551 case CTRL('P'): /* go to previous window */
2553 current = current->last;
2556 case CTRL('F'): /* scroll current window forward */
2558 wscrl(current->wind, 1);
2561 case CTRL('B'): /* scroll current window backwards */
2563 wscrl(current->wind, -1);
2566 case CTRL('K'): /* toggle keypad mode for current */
2568 current->do_keypad = !current->do_keypad;
2569 keypad(current->wind, current->do_keypad);
2575 current->do_scroll = !current->do_scroll;
2576 scrollok(current->wind, current->do_scroll);
2580 case CTRL('W'): /* save and delete window */
2581 if (current == current->next) {
2582 transient(current, "Will not save/delete ONLY window");
2584 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
2585 transient(current, "Can't open screen dump file");
2587 (void) putwin(current->wind, fp);
2590 current = delete_framed(current, TRUE);
2594 case CTRL('R'): /* restore window */
2595 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
2596 transient(current, "Can't open screen dump file");
2598 neww = (FRAME *) calloc(1, sizeof(FRAME));
2600 neww->next = current->next;
2601 neww->last = current;
2602 neww->last->next = neww;
2603 neww->next->last = neww;
2605 neww->wind = getwin(fp);
2608 wrefresh(neww->wind);
2613 case CTRL('X'): /* resize window */
2620 addstr("Use arrows to move cursor, anything else to mark new corner");
2623 getbegyx(current->wind, ul.y, ul.x);
2625 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
2626 if (tmp == (pair *) 0) {
2631 getmaxyx(current->wind, lr.y, lr.x);
2634 outerbox(ul, lr, FALSE);
2635 wnoutrefresh(stdscr);
2637 /* strictly cosmetic hack for the test */
2638 getmaxyx(current->wind, my, mx);
2639 if (my > tmp->y - ul.y) {
2640 getyx(current->wind, lr.y, lr.x);
2641 wmove(current->wind, tmp->y - ul.y + 1, 0);
2642 wclrtobot(current->wind);
2643 wmove(current->wind, lr.y, lr.x);
2645 if (mx > tmp->x - ul.x)
2646 for (i = 0; i < my; i++) {
2647 wmove(current->wind, i, tmp->x - ul.x + 1);
2648 wclrtoeol(current->wind);
2650 wnoutrefresh(current->wind);
2652 memcpy(&lr, tmp, sizeof(pair));
2653 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
2655 getbegyx(current->wind, ul.y, ul.x);
2656 getmaxyx(current->wind, lr.y, lr.x);
2659 outerbox(ul, lr, TRUE);
2660 wnoutrefresh(stdscr);
2662 wnoutrefresh(current->wind);
2668 #endif /* HAVE_WRESIZE */
2670 case KEY_F(10): /* undocumented --- use this to test area clears */
2671 selectcell(0, 0, LINES - 1, COLS - 1);
2677 newwin_move(current, -1, 0);
2680 newwin_move(current, 1, 0);
2683 newwin_move(current, 0, -1);
2686 newwin_move(current, 0, 1);
2694 getyx(current->wind, y, x);
2698 x = getmaxx(current->wind) - 1;
2700 mvwdelch(current->wind, y, x);
2710 waddch(current->wind, (chtype) c);
2715 newwin_report(current);
2716 usescr = (current ? current->wind : stdscr);
2719 ((c = wGetchar(usescr)) != QUIT
2720 && !((c == ESCAPE) && (keypad_active(usescr)))
2724 while (current != 0)
2725 current = delete_framed(current, FALSE);
2727 scrollok(stdscr, TRUE); /* reset to driver's default */
2728 #ifdef NCURSES_MOUSE_VERSION
2729 mousemask(0, (mmask_t *) 0);
2736 /****************************************************************************
2740 ****************************************************************************/
2743 static unsigned long nap_msec = 1;
2745 static NCURSES_CONST char *mod[] =
2755 /*+-------------------------------------------------------------------------
2757 --------------------------------------------------------------------------*/
2759 wait_a_while(unsigned long msec GCC_UNUSED)
2769 else if (msec > 1000L)
2770 sleep((int) msec / 1000L);
2774 } /* end of wait_a_while */
2776 /*+-------------------------------------------------------------------------
2778 --------------------------------------------------------------------------*/
2780 saywhat(NCURSES_CONST char *text)
2782 wmove(stdscr, LINES - 1, 0);
2784 waddstr(stdscr, text);
2785 } /* end of saywhat */
2787 /*+-------------------------------------------------------------------------
2788 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
2789 --------------------------------------------------------------------------*/
2791 mkpanel(int color, int rows, int cols, int tly, int tlx)
2796 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
2797 if ((pan = new_panel(win)) == 0) {
2799 } else if (has_colors()) {
2800 int fg = (color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK;
2802 init_pair(color, fg, bg);
2803 wbkgdset(win, COLOR_PAIR(color) | ' ');
2805 wbkgdset(win, A_BOLD | ' ');
2809 } /* end of mkpanel */
2811 /*+-------------------------------------------------------------------------
2813 --------------------------------------------------------------------------*/
2815 rmpanel(PANEL * pan)
2817 WINDOW *win = panel_window(pan);
2820 } /* end of rmpanel */
2822 /*+-------------------------------------------------------------------------
2824 --------------------------------------------------------------------------*/
2830 } /* end of pflush */
2832 /*+-------------------------------------------------------------------------
2834 --------------------------------------------------------------------------*/
2836 fill_panel(PANEL * pan)
2838 WINDOW *win = panel_window(pan);
2839 int num = ((const char *) panel_userptr(pan))[1];
2843 wprintw(win, "-pan%c-", num);
2846 for (y = 2; y < getmaxy(win) - 1; y++) {
2847 for (x = 1; x < getmaxx(win) - 1; x++) {
2852 } /* end of fill_panel */
2862 for (y = 0; y < LINES - 1; y++) {
2863 for (x = 0; x < COLS; x++)
2864 wprintw(stdscr, "%d", (y + x) % 10);
2866 for (y = 0; y < 5; y++) {
2873 p1 = mkpanel(COLOR_RED,
2878 set_panel_userptr(p1, (NCURSES_CONST void *) "p1");
2880 p2 = mkpanel(COLOR_GREEN,
2885 set_panel_userptr(p2, (NCURSES_CONST void *) "p2");
2887 p3 = mkpanel(COLOR_YELLOW,
2892 set_panel_userptr(p3, (NCURSES_CONST void *) "p3");
2894 p4 = mkpanel(COLOR_BLUE,
2899 set_panel_userptr(p4, (NCURSES_CONST void *) "p4");
2901 p5 = mkpanel(COLOR_MAGENTA,
2906 set_panel_userptr(p5, (NCURSES_CONST void *) "p5");
2916 saywhat("press any key to continue");
2917 wait_a_while(nap_msec);
2919 saywhat("h3 s1 s2 s4 s5; press any key to continue");
2920 move_panel(p1, 0, 0);
2927 wait_a_while(nap_msec);
2929 saywhat("s1; press any key to continue");
2932 wait_a_while(nap_msec);
2934 saywhat("s2; press any key to continue");
2937 wait_a_while(nap_msec);
2939 saywhat("m2; press any key to continue");
2940 move_panel(p2, LINES / 3 + 1, COLS / 8);
2942 wait_a_while(nap_msec);
2947 wait_a_while(nap_msec);
2949 saywhat("m3; press any key to continue");
2950 move_panel(p3, LINES / 4 + 1, COLS / 15);
2952 wait_a_while(nap_msec);
2954 saywhat("b3; press any key to continue");
2957 wait_a_while(nap_msec);
2959 saywhat("s4; press any key to continue");
2962 wait_a_while(nap_msec);
2964 saywhat("s5; press any key to continue");
2967 wait_a_while(nap_msec);
2969 saywhat("t3; press any key to continue");
2972 wait_a_while(nap_msec);
2974 saywhat("t1; press any key to continue");
2977 wait_a_while(nap_msec);
2979 saywhat("t2; press any key to continue");
2982 wait_a_while(nap_msec);
2984 saywhat("t3; press any key to continue");
2987 wait_a_while(nap_msec);
2989 saywhat("t4; press any key to continue");
2992 wait_a_while(nap_msec);
2994 for (itmp = 0; itmp < 6; itmp++) {
2995 WINDOW *w4 = panel_window(p4);
2996 WINDOW *w5 = panel_window(p5);
2998 saywhat("m4; press any key to continue");
2999 wmove(w4, LINES / 8, 1);
3000 waddstr(w4, mod[itmp]);
3001 move_panel(p4, LINES / 6, itmp * (COLS / 8));
3002 wmove(w5, LINES / 6, 1);
3003 waddstr(w5, mod[itmp]);
3005 wait_a_while(nap_msec);
3007 saywhat("m5; press any key to continue");
3008 wmove(w4, LINES / 6, 1);
3009 waddstr(w4, mod[itmp]);
3010 move_panel(p5, LINES / 3 - 1, (itmp * 10) + 6);
3011 wmove(w5, LINES / 8, 1);
3012 waddstr(w5, mod[itmp]);
3014 wait_a_while(nap_msec);
3017 saywhat("m4; press any key to continue");
3018 move_panel(p4, LINES / 6, itmp * (COLS / 8));
3020 wait_a_while(nap_msec);
3022 saywhat("t5; press any key to continue");
3025 wait_a_while(nap_msec);
3027 saywhat("t2; press any key to continue");
3030 wait_a_while(nap_msec);
3032 saywhat("t1; press any key to continue");
3035 wait_a_while(nap_msec);
3037 saywhat("d2; press any key to continue");
3040 wait_a_while(nap_msec);
3042 saywhat("h3; press any key to continue");
3045 wait_a_while(nap_msec);
3047 saywhat("d1; press any key to continue");
3050 wait_a_while(nap_msec);
3052 saywhat("d4; press any key to continue");
3055 wait_a_while(nap_msec);
3057 saywhat("d5; press any key to continue");
3060 wait_a_while(nap_msec);
3070 /****************************************************************************
3074 ****************************************************************************/
3078 static bool pending_pan = FALSE;
3079 static bool show_panner_legend = TRUE;
3082 panner_legend(int line)
3084 static const char *const legend[] =
3086 "Use arrow keys (or U,D,L,R) to pan, q to quit, ! to shell-out.",
3087 "Use +,- (or j,k) to grow/shrink the panner vertically.",
3088 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
3089 "Number repeats. Toggle legend:?, timer:t, scroll mark:s."
3091 int n = (SIZEOF(legend) - (LINES - line));
3092 if (line < LINES && (n >= 0)) {
3094 if (show_panner_legend)
3095 printw("%s", legend[n]);
3097 return show_panner_legend;
3103 panner_h_cleanup(int from_y, int from_x, int to_x)
3105 if (!panner_legend(from_y))
3106 do_h_line(from_y, from_x, ' ', to_x);
3110 panner_v_cleanup(int from_y, int from_x, int to_y)
3112 if (!panner_legend(from_y))
3113 do_v_line(from_y, from_x, ' ', to_y);
3118 int top_x, int top_y, int porty, int portx,
3119 int (*pgetc) (WINDOW *))
3121 #if HAVE_GETTIMEOFDAY
3122 struct timeval before, after;
3125 bool scrollers = TRUE;
3128 int pxmax, pymax, lowend, highend, c;
3130 getmaxyx(pad, pymax, pxmax);
3131 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
3135 #ifdef NCURSES_VERSION
3137 * During shell-out, the user may have resized the window. Adjust
3138 * the port size of the pad to accommodate this. Ncurses automatically
3139 * resizes all of the normal windows to fit on the new screen.
3157 show_panner_legend = !show_panner_legend;
3158 panner_legend(LINES - 4);
3159 panner_legend(LINES - 3);
3160 panner_legend(LINES - 2);
3161 panner_legend(LINES - 1);
3163 #if HAVE_GETTIMEOFDAY
3167 panner_legend(LINES - 1);
3171 scrollers = !scrollers;
3174 /* Move the top-left corner of the pad, keeping the bottom-right
3177 case 'h': /* increase-columns: move left edge to left */
3181 panner_v_cleanup(top_y, top_x, porty);
3186 case 'j': /* decrease-lines: move top-edge down */
3190 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
3195 case 'k': /* increase-lines: move top-edge up */
3200 panner_h_cleanup(top_y, top_x, portx);
3204 case 'l': /* decrease-columns: move left-edge to right */
3208 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
3213 /* Move the bottom-right corner of the pad, keeping the top-left
3216 case KEY_IC: /* increase-columns: move right-edge to right */
3217 if (portx >= pxmax || portx >= COLS)
3220 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
3225 case KEY_IL: /* increase-lines: move bottom-edge down */
3226 if (porty >= pymax || porty >= LINES)
3229 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
3234 case KEY_DC: /* decrease-columns: move bottom edge up */
3239 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
3243 case KEY_DL: /* decrease-lines */
3248 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
3252 case KEY_LEFT: /* pan leftwards */
3259 case KEY_RIGHT: /* pan rightwards */
3260 if (basex + portx - (pymax > porty) < pxmax)
3266 case KEY_UP: /* pan upwards */
3273 case KEY_DOWN: /* pan downwards */
3274 if (basey + porty - (pxmax > portx) < pymax)
3289 basey = pymax - porty;
3299 mvaddch(top_y - 1, top_x - 1, ACS_ULCORNER);
3300 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
3301 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
3303 if (scrollers && (pxmax > portx - 1)) {
3304 int length = (portx - top_x - 1);
3305 float ratio = ((float) length) / ((float) pxmax);
3307 lowend = (int) (top_x + (basex * ratio));
3308 highend = (int) (top_x + ((basex + length) * ratio));
3310 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
3311 if (highend < portx) {
3313 do_h_line(porty - 1, lowend, ' ', highend + 1);
3315 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
3318 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
3320 if (scrollers && (pymax > porty - 1)) {
3321 int length = (porty - top_y - 1);
3322 float ratio = ((float) length) / ((float) pymax);
3324 lowend = (int) (top_y + (basey * ratio));
3325 highend = (int) (top_y + ((basey + length) * ratio));
3327 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
3328 if (highend < porty) {
3330 do_v_line(lowend, portx - 1, ' ', highend + 1);
3332 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
3335 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
3337 mvaddch(top_y - 1, portx - 1, ACS_URCORNER);
3338 mvaddch(porty - 1, top_x - 1, ACS_LLCORNER);
3339 mvaddch(porty - 1, portx - 1, ACS_LRCORNER);
3342 #if HAVE_GETTIMEOFDAY
3343 gettimeofday(&before, 0);
3345 wnoutrefresh(stdscr);
3350 porty - (pxmax > portx) - 1,
3351 portx - (pymax > porty) - 1);
3354 #if HAVE_GETTIMEOFDAY
3357 gettimeofday(&after, 0);
3358 elapsed = (after.tv_sec + after.tv_usec / 1.0e6)
3359 - (before.tv_sec + before.tv_usec / 1.0e6);
3360 move(LINES - 1, COLS - 20);
3361 printw("Secs: %2.03f", elapsed);
3368 ((c = pgetc(pad)) != KEY_EXIT);
3370 scrollok(stdscr, TRUE); /* reset to driver's default */
3374 padgetch(WINDOW *win)
3380 if ((pending_pan = (count > 0)) != FALSE) {
3382 pending_pan = (count != 0);
3385 switch (c = wGetchar(win)) {
3421 case ERR: /* FALLTHRU */
3427 if (c >= '0' && c <= '9') {
3428 count = count * 10 + (c - '0');
3442 #define PAD_HIGH 200
3443 #define PAD_WIDE 200
3447 /* Demonstrate pads. */
3450 unsigned gridcount = 0;
3451 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
3454 Cannot("cannot create requested pad");
3458 for (i = 0; i < PAD_HIGH; i++) {
3459 for (j = 0; j < PAD_WIDE; j++)
3460 if (i % GRIDSIZE == 0 && j % GRIDSIZE == 0) {
3461 if (i == 0 || j == 0)
3462 waddch(panpad, '+');
3464 waddch(panpad, (chtype) ('A' + (gridcount++ % 26)));
3465 } else if (i % GRIDSIZE == 0)
3466 waddch(panpad, '-');
3467 else if (j % GRIDSIZE == 0)
3468 waddch(panpad, '|');
3470 waddch(panpad, ' ');
3472 panner_legend(LINES - 4);
3473 panner_legend(LINES - 3);
3474 panner_legend(LINES - 2);
3475 panner_legend(LINES - 1);
3477 keypad(panpad, TRUE);
3479 /* Make the pad (initially) narrow enough that a trace file won't wrap.
3480 * We'll still be able to widen it during a test, since that's required
3481 * for testing boundaries.
3483 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
3489 #endif /* USE_LIBPANEL */
3491 /****************************************************************************
3493 * Tests from John Burnell's PDCurses tester
3495 ****************************************************************************/
3498 Continue(WINDOW *win)
3502 mvwaddstr(win, 10, 1, " Press any key to continue");
3508 flushinp_test(WINDOW *win)
3509 /* Input test, adapted from John Burnell's PDCurses tester */
3511 int w, h, bx, by, sw, sh, i;
3516 getmaxyx(win, h, w);
3517 getbegyx(win, by, bx);
3520 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
3525 init_pair(2, COLOR_CYAN, COLOR_BLUE);
3526 wbkgd(subWin, COLOR_PAIR(2) | ' ');
3529 wattrset(subWin, A_BOLD);
3530 box(subWin, ACS_VLINE, ACS_HLINE);
3531 mvwaddstr(subWin, 2, 1, "This is a subwindow");
3535 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
3536 * it only happened to "work" on SVr4 because that implementation does not
3537 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
3538 * test behavior, we're using 'cbreak()', which will allow a single
3539 * character to return without needing a newline. - T.Dickey 1997/10/11.
3542 mvwaddstr(win, 0, 1, "This is a test of the flushinp() call.");
3544 mvwaddstr(win, 2, 1, "Type random keys for 5 seconds.");
3545 mvwaddstr(win, 3, 1,
3546 "These should be discarded (not echoed) after the subwindow goes away.");
3549 for (i = 0; i < 5; i++) {
3550 mvwprintw(subWin, 1, 1, "Time = %d", i);
3562 mvwaddstr(win, 2, 1,
3563 "If you were still typing when the window timer expired,");
3564 mvwaddstr(win, 3, 1,
3565 "or else you typed nothing at all while it was running,");
3566 mvwaddstr(win, 4, 1,
3567 "test was invalid. You'll see garbage or nothing at all. ");
3568 mvwaddstr(win, 6, 1, "Press a key");
3574 mvwaddstr(win, 12, 0,
3575 "If you see any key other than what you typed, flushinp() is broken.");
3584 "What you typed should now have been deleted; if not, wdelch() failed.");
3590 /****************************************************************************
3594 ****************************************************************************/
3602 menu_virtualize(int c)
3604 if (c == '\n' || c == KEY_EXIT)
3605 return (MAX_COMMAND + 1);
3607 return (REQ_SCR_ULINE);
3609 return (REQ_SCR_DLINE);
3610 else if (c == 'b' || c == KEY_NPAGE)
3611 return (REQ_SCR_UPAGE);
3612 else if (c == 'f' || c == KEY_PPAGE)
3613 return (REQ_SCR_DPAGE);
3614 else if (c == 'n' || c == KEY_DOWN)
3615 return (REQ_NEXT_ITEM);
3616 else if (c == 'p' || c == KEY_UP)
3617 return (REQ_PREV_ITEM);
3619 return (REQ_TOGGLE_ITEM);
3627 static const char *animals[] =
3629 "Lions", "Tigers", "Bears", "(Oh my!)", "Newts", "Platypi", "Lemurs",
3637 ITEM *items[SIZEOF(animals)];
3640 int mrows, mcols, c;
3643 #ifdef NCURSES_MOUSE_VERSION
3644 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
3646 mvaddstr(0, 0, "This is the menu test:");
3647 mvaddstr(2, 0, " Use up and down arrow to move the select bar.");
3648 mvaddstr(3, 0, " 'n' and 'p' act like arrows.");
3650 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
3651 mvaddstr(5, 0, " Press return to exit.");
3654 for (ap = animals; *ap; ap++)
3655 *ip++ = new_item(*ap, "");
3658 m = new_menu(items);
3660 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
3661 scale_menu(m, &mrows, &mcols);
3663 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
3664 set_menu_win(m, menuwin);
3665 keypad(menuwin, TRUE);
3668 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
3672 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
3673 if (c == E_REQUEST_DENIED)
3678 (void) mvprintw(LINES - 2, 0,
3679 "You chose: %s\n", item_name(current_item(m)));
3680 (void) addstr("Press any key to continue...");
3687 for (ip = items; *ip; ip++)
3689 #ifdef NCURSES_MOUSE_VERSION
3690 mousemask(0, (mmask_t *) 0);
3695 #define T_TBL(name) { #name, name }
3701 T_TBL(TRACE_DISABLE),
3704 T_TBL(TRACE_UPDATE),
3706 T_TBL(TRACE_CHARPUT),
3707 T_TBL(TRACE_ORDINARY),
3709 T_TBL(TRACE_VIRTPUT),
3710 T_TBL(TRACE_IEVENT),
3712 T_TBL(TRACE_ICALLS),
3713 T_TBL(TRACE_CCALLS),
3714 T_TBL(TRACE_DATABASE),
3716 T_TBL(TRACE_MAXIMUM),
3723 tracetrace(int tlevel)
3730 for (n = 0; t_tbl[n].name != 0; n++)
3731 need += strlen(t_tbl[n].name) + 2;
3732 buf = (char *) malloc(need);
3734 sprintf(buf, "0x%02x = {", tlevel);
3736 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
3738 for (n = 1; t_tbl[n].name != 0; n++)
3739 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
3740 strcat(buf, t_tbl[n].name);
3744 if (buf[strlen(buf) - 2] == ',')
3745 buf[strlen(buf) - 2] = '\0';
3746 return (strcat(buf, "}"));
3749 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
3753 run_trace_menu(MENU * m)
3759 bool changed = FALSE;
3760 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
3761 case E_UNKNOWN_COMMAND:
3764 items = menu_items(m);
3765 i = current_item(m);
3766 if (i == items[0]) {
3767 if (item_value(i)) {
3768 for (p = items + 1; *p != 0; p++)
3769 if (item_value(*p)) {
3770 set_item_value(*p, FALSE);
3775 for (p = items + 1; *p != 0; p++)
3776 if (item_value(*p)) {
3777 set_item_value(items[0], FALSE);
3790 /* interactively set the trace level */
3793 ITEM *items[SIZEOF(t_tbl)];
3795 int mrows, mcols, newtrace;
3799 mvaddstr(0, 0, "Interactively set trace level:");
3800 mvaddstr(2, 0, " Press space bar to toggle a selection.");
3801 mvaddstr(3, 0, " Use up and down arrow to move the select bar.");
3802 mvaddstr(4, 0, " Press return to set the trace level.");
3803 mvprintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
3807 for (n = 0; t_tbl[n].name != 0; n++)
3808 *ip++ = new_item(t_tbl[n].name, "");
3811 m = new_menu(items);