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.329 2008/09/27 14:34:58 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 */
122 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
123 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
124 #define reset_wchars(state) memset(&state, 0, sizeof(state))
125 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
126 #define count_wchars(src, len, state) wcstombs(0, src, len)
127 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
128 #define reset_wchars(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
133 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
134 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
135 #define reset_mbytes(state) memset(&state, 0, sizeof(state))
136 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
137 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
138 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
139 #define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
143 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
145 #define P(string) printw("%s\n", string)
147 #define BLANK ' ' /* this is the background character */
150 static int max_colors; /* the actual number of colors we'll use */
151 static int min_colors; /* the minimum color code */
152 static bool use_colors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
163 static RGB_DATA *all_colors;
165 static void main_menu(bool);
167 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
168 * though we can rely on negative x/y values to stop the macro.
171 do_h_line(int y, int x, chtype c, int to)
174 mvhline(y, x, c, (to) - (x));
178 do_v_line(int y, int x, chtype c, int to)
181 mvvline(y, x, c, (to) - (y));
195 return ((c) == QUIT || (c) == ESCAPE);
197 #define case_QUIT QUIT: case ESCAPE
199 /* Common function to allow ^T to toggle trace-mode in the middle of a test
200 * so that trace-files can be made smaller.
203 wGetchar(WINDOW *win)
207 while ((c = wgetch(win)) == CTRL('T')) {
209 save_trace = _nc_tracing;
210 Trace(("TOGGLE-TRACING OFF"));
213 _nc_tracing = save_trace;
217 Trace(("TOGGLE-TRACING ON"));
224 #define Getchar() wGetchar(stdscr)
226 /* replaces wgetnstr(), since we want to be able to edit values */
228 wGetstring(WINDOW *win, char *buffer, int limit)
235 wattrset(win, A_REVERSE);
237 x = (int) strlen(buffer);
239 if (x > (int) strlen(buffer))
240 x = (int) strlen(buffer);
242 wprintw(win, "%-*s", limit, buffer);
243 wmove(win, y0, x0 + x);
244 switch (ch = wGetchar(win)) {
257 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
275 if (!isprint(ch) || ch >= KEY_MIN) {
277 } else if ((int) strlen(buffer) < limit) {
279 for (j = (int) strlen(buffer) + 1; j > x; --j) {
280 buffer[j] = buffer[j - 1];
282 buffer[x++] = (char) ch;
289 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
298 return (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_of(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
322 make_fullwidth_digit(cchar_t *target, int digit)
326 source[0] = fullwidth_of(digit + '0');
328 setcchar(target, source, A_NORMAL, 0, 0);
332 wGet_wchar(WINDOW *win, wint_t *result)
336 while ((c = wget_wch(win, result)) == CTRL('T')) {
338 save_trace = _nc_tracing;
339 Trace(("TOGGLE-TRACING OFF"));
342 _nc_tracing = save_trace;
346 Trace(("TOGGLE-TRACING ON"));
349 c = wget_wch(win, result);
353 #define Get_wchar(result) wGet_wchar(stdscr, result)
355 /* replaces wgetn_wstr(), since we want to be able to edit values */
357 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
366 wattrset(win, A_REVERSE);
368 x = (int) wcslen(buffer);
370 if (x > (int) wcslen(buffer))
371 x = (int) wcslen(buffer);
373 /* clear the "window' */
375 wprintw(win, "%*s", limit, " ");
377 /* write the existing buffer contents */
379 waddnwstr(win, buffer, limit);
381 /* positions the cursor past character 'x' */
383 waddnwstr(win, buffer, x);
385 switch (wGet_wchar(win, &ch)) {
425 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
445 } else if ((int) wcslen(buffer) < limit) {
447 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
448 buffer[j] = buffer[j - 1];
450 buffer[x++] = (wchar_t) ch;
457 wattroff(win, A_REVERSE);
468 addstr("Press any key to continue... ");
473 Cannot(const char *what)
475 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
480 ShellOut(bool message)
483 addstr("Shelling out...");
488 addstr("returned from shellout.\n");
492 #ifdef NCURSES_MOUSE_VERSION
494 * This function is the same as _tracemouse(), but we cannot count on that
495 * being available in the non-debug library.
498 mouse_decode(MEVENT const *ep)
500 static char buf[80 + (5 * 10) + (32 * 15)];
502 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
503 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
505 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
507 SHOW(BUTTON1_RELEASED, "release-1");
508 SHOW(BUTTON1_PRESSED, "press-1");
509 SHOW(BUTTON1_CLICKED, "click-1");
510 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
511 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
512 #if NCURSES_MOUSE_VERSION == 1
513 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
516 SHOW(BUTTON2_RELEASED, "release-2");
517 SHOW(BUTTON2_PRESSED, "press-2");
518 SHOW(BUTTON2_CLICKED, "click-2");
519 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
520 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
521 #if NCURSES_MOUSE_VERSION == 1
522 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
525 SHOW(BUTTON3_RELEASED, "release-3");
526 SHOW(BUTTON3_PRESSED, "press-3");
527 SHOW(BUTTON3_CLICKED, "click-3");
528 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
529 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
530 #if NCURSES_MOUSE_VERSION == 1
531 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
534 SHOW(BUTTON4_RELEASED, "release-4");
535 SHOW(BUTTON4_PRESSED, "press-4");
536 SHOW(BUTTON4_CLICKED, "click-4");
537 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
538 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
539 #if NCURSES_MOUSE_VERSION == 1
540 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
543 #if NCURSES_MOUSE_VERSION == 2
544 SHOW(BUTTON5_RELEASED, "release-5");
545 SHOW(BUTTON5_PRESSED, "press-5");
546 SHOW(BUTTON5_CLICKED, "click-5");
547 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
548 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
551 SHOW(BUTTON_CTRL, "ctrl");
552 SHOW(BUTTON_SHIFT, "shift");
553 SHOW(BUTTON_ALT, "alt");
554 SHOW(ALL_MOUSE_EVENTS, "all-events");
555 SHOW(REPORT_MOUSE_POSITION, "position");
559 if (buf[strlen(buf) - 1] == ' ')
560 buf[strlen(buf) - 2] = '\0';
561 (void) strcat(buf, "}");
564 #endif /* NCURSES_MOUSE_VERSION */
566 /****************************************************************************
568 * Character input test
570 ****************************************************************************/
573 setup_getch(WINDOW *win, bool flags[])
575 keypad(win, flags['k']); /* should be redundant, but for testing */
576 meta(win, flags['m']); /* force this to a known state */
584 wgetch_help(WINDOW *win, bool flags[])
586 static const char *help[] =
588 "e -- toggle echo mode"
589 ,"g -- triggers a getstr test"
590 ,"k -- toggle keypad/literal mode"
591 ,"m -- toggle meta (7-bit/8-bit) mode"
594 ,"w -- create a new window"
596 ,"z -- suspend this process"
600 unsigned chk = ((SIZEOF(help) + 1) / 2);
605 printw("Type any key to see its %s value. Also:\n",
606 flags['k'] ? "keypad" : "literal");
607 for (n = 0; n < SIZEOF(help); ++n) {
608 int row = 1 + (int) (n % chk);
609 int col = (n >= chk) ? COLS / 2 : 0;
610 int flg = ((strstr(help[n], "toggle") != 0)
611 && (flags[UChar(*help[n])] != FALSE));
614 mvprintw(row, col, "%s", help[n]);
625 wgetch_wrap(WINDOW *win, int first_y)
627 int last_y = getmaxy(win) - 1;
628 int y = getcury(win) + 1;
636 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
642 static WINSTACK *winstack = 0;
643 static unsigned len_winstack = 0;
656 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
658 unsigned need = (level + 1) * 2;
660 assert(level < COLS);
664 winstack = typeMalloc(WINSTACK, len_winstack);
665 } else if (need >= len_winstack) {
667 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
669 winstack[level].text = txt_win;
670 winstack[level].frame = box_win;
673 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
677 /* this chunk is now done in resize_term() */
684 #define slk_repaint() /* nothing */
688 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
689 * Resize both and paint the box in the parent.
692 resize_boxes(unsigned level, WINDOW *win)
696 int high = LINES - base;
700 wnoutrefresh(stdscr);
704 for (n = 0; n < level; ++n) {
705 wresize(winstack[n].frame, high, wide);
706 wresize(winstack[n].text, high - 2, wide - 2);
709 werase(winstack[n].text);
710 box(winstack[n].frame, 0, 0);
711 wnoutrefresh(winstack[n].frame);
712 wprintw(winstack[n].text,
714 getmaxy(winstack[n].text),
715 getmaxx(winstack[n].text));
716 wnoutrefresh(winstack[n].text);
717 if (winstack[n].text == win)
723 #define forget_boxes() /* nothing */
724 #define remember_boxes(level,text,frame) /* nothing */
728 wgetch_test(unsigned level, WINDOW *win, int delay)
731 int first_y, first_x;
735 bool blocking = (delay < 0);
737 memset(flags, FALSE, sizeof(flags));
738 flags[UChar('k')] = (win == stdscr);
740 setup_getch(win, flags);
741 wtimeout(win, delay);
742 getyx(win, first_y, first_x);
744 wgetch_help(win, flags);
745 wsetscrreg(win, first_y, getmaxy(win) - 1);
749 while ((c = wGetchar(win)) == ERR) {
752 (void) wprintw(win, "%05d: input error", incount);
755 (void) wprintw(win, "%05d: input timed out", incount);
757 wgetch_wrap(win, first_y);
759 if (c == ERR && blocking) {
761 wgetch_wrap(win, first_y);
762 } else if (isQuit(c)) {
764 } else if (c == 'e') {
765 flags[UChar('e')] = !flags[UChar('e')];
766 setup_getch(win, flags);
767 wgetch_help(win, flags);
768 } else if (c == 'g') {
769 waddstr(win, "getstr test: ");
771 wgetnstr(win, buf, sizeof(buf) - 1);
773 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
775 wgetch_wrap(win, first_y);
776 } else if (c == 'k') {
777 flags[UChar('k')] = !flags[UChar('k')];
778 setup_getch(win, flags);
779 wgetch_help(win, flags);
780 } else if (c == 'm') {
781 flags[UChar('m')] = !flags[UChar('m')];
782 setup_getch(win, flags);
783 wgetch_help(win, flags);
784 } else if (c == 's') {
786 } else if (c == 'w') {
787 int high = getmaxy(win) - 1 - first_y + 1;
788 int wide = getmaxx(win) - first_x;
790 int new_y = first_y + getbegy(win);
791 int new_x = first_x + getbegx(win);
793 getyx(win, old_y, old_x);
794 if (high > 2 && wide > 2) {
795 WINDOW *wb = newwin(high, wide, new_y, new_x);
796 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
801 remember_boxes(level, wi, wb);
802 wgetch_test(level + 1, wi, delay);
806 wgetch_help(win, flags);
807 wmove(win, old_y, old_x);
813 } else if (c == 'z') {
814 kill(getpid(), SIGTSTP);
817 wprintw(win, "Key pressed: %04o ", c);
818 #ifdef NCURSES_MOUSE_VERSION
819 if (c == KEY_MOUSE) {
824 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
826 move(event.y, event.x);
830 #endif /* NCURSES_MOUSE_VERSION */
832 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
833 if (c == KEY_RESIZE) {
834 resize_boxes(level, win);
837 (void) waddstr(win, keyname(c));
838 } else if (c > 0x80) {
839 unsigned c2 = (unsigned) (c & 0x7f);
841 (void) wprintw(win, "M-%c", UChar(c2));
843 (void) wprintw(win, "M-%s", unctrl(c2));
844 waddstr(win, " (high-half character)");
847 (void) wprintw(win, "%c (ASCII printable character)", c);
849 (void) wprintw(win, "%s (ASCII control character)",
852 wgetch_wrap(win, first_y);
860 begin_getch_test(void)
867 #ifdef NCURSES_MOUSE_VERSION
868 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
871 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
873 getnstr(buf, sizeof(buf) - 1);
877 if (isdigit(UChar(buf[0]))) {
878 delay = atoi(buf) * 100;
888 finish_getch_test(void)
890 #ifdef NCURSES_MOUSE_VERSION
891 mousemask(0, (mmask_t *) 0);
902 int delay = begin_getch_test();
905 wgetch_test(0, stdscr, delay);
910 #if USE_WIDEC_SUPPORT
912 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
913 * Resize both and paint the box in the parent.
915 #if defined(KEY_RESIZE) && HAVE_WRESIZE
917 resize_wide_boxes(unsigned level, WINDOW *win)
921 int high = LINES - base;
925 wnoutrefresh(stdscr);
929 for (n = 0; n < level; ++n) {
930 wresize(winstack[n].frame, high, wide);
931 wresize(winstack[n].text, high - 2, wide - 2);
934 werase(winstack[n].text);
935 box_set(winstack[n].frame, 0, 0);
936 wnoutrefresh(winstack[n].frame);
937 wprintw(winstack[n].text,
939 getmaxy(winstack[n].text),
940 getmaxx(winstack[n].text));
941 wnoutrefresh(winstack[n].text);
942 if (winstack[n].text == win)
947 #endif /* KEY_RESIZE */
950 wcstos(const wchar_t *src)
954 const wchar_t *tmp = src;
960 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
961 unsigned have = (unsigned) need;
962 if ((result = typeCalloc(char, have + 1)) != 0) {
964 if (trans_wchars(result, tmp, have, &state) != have) {
974 wget_wch_test(unsigned level, WINDOW *win, int delay)
976 wchar_t wchar_buf[BUFSIZ];
977 wint_t wint_buf[BUFSIZ];
978 int first_y, first_x;
982 bool blocking = (delay < 0);
986 memset(flags, FALSE, sizeof(flags));
987 flags[UChar('k')] = (win == stdscr);
989 setup_getch(win, flags);
990 wtimeout(win, delay);
991 getyx(win, first_y, first_x);
993 wgetch_help(win, flags);
994 wsetscrreg(win, first_y, getmaxy(win) - 1);
998 while ((code = wGet_wchar(win, &c)) == ERR) {
1001 (void) wprintw(win, "%05d: input error", incount);
1004 (void) wprintw(win, "%05d: input timed out", incount);
1006 wgetch_wrap(win, first_y);
1008 if (code == ERR && blocking) {
1009 wprintw(win, "ERR");
1010 wgetch_wrap(win, first_y);
1011 } else if (isQuit((int) c)) {
1013 } else if (c == 'e') {
1014 flags[UChar('e')] = !flags[UChar('e')];
1015 setup_getch(win, flags);
1016 wgetch_help(win, flags);
1017 } else if (c == 'g') {
1018 waddstr(win, "getstr test: ");
1020 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1023 wprintw(win, "wgetn_wstr returns an error.");
1026 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1029 if ((temp = wcstos(wchar_buf)) != 0) {
1030 wprintw(win, "I saw %d characters:\n\t`%s'.",
1031 (int) wcslen(wchar_buf), temp);
1034 wprintw(win, "I saw %d characters (cannot convert).",
1035 (int) wcslen(wchar_buf));
1039 wgetch_wrap(win, first_y);
1040 } else if (c == 'k') {
1041 flags[UChar('k')] = !flags[UChar('k')];
1042 setup_getch(win, flags);
1043 wgetch_help(win, flags);
1044 } else if (c == 'm') {
1045 flags[UChar('m')] = !flags[UChar('m')];
1046 setup_getch(win, flags);
1047 wgetch_help(win, flags);
1048 } else if (c == 's') {
1050 } else if (c == 'w') {
1051 int high = getmaxy(win) - 1 - first_y + 1;
1052 int wide = getmaxx(win) - first_x;
1054 int new_y = first_y + getbegy(win);
1055 int new_x = first_x + getbegx(win);
1057 getyx(win, old_y, old_x);
1058 if (high > 2 && wide > 2) {
1059 WINDOW *wb = newwin(high, wide, new_y, new_x);
1060 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1065 remember_boxes(level, wi, wb);
1066 wget_wch_test(level + 1, wi, delay);
1070 wgetch_help(win, flags);
1071 wmove(win, old_y, old_x);
1076 } else if (c == 'z') {
1077 kill(getpid(), SIGTSTP);
1080 wprintw(win, "Key pressed: %04o ", (int) c);
1081 #ifdef NCURSES_MOUSE_VERSION
1082 if (c == KEY_MOUSE) {
1086 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1088 move(event.y, event.x);
1092 #endif /* NCURSES_MOUSE_VERSION */
1093 if (code == KEY_CODE_YES) {
1094 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1095 if (c == KEY_RESIZE) {
1096 resize_wide_boxes(level, win);
1099 (void) waddstr(win, key_name((wchar_t) c));
1101 if (c < 256 && iscntrl(c)) {
1102 (void) wprintw(win, "%s (control character)", unctrl(c));
1104 wchar_t c2 = (wchar_t) c;
1105 waddnwstr(win, &c2, 1);
1106 (void) wprintw(win, " = %#x (printable character)", (unsigned) c);
1109 wgetch_wrap(win, first_y);
1119 int delay = begin_getch_test();
1122 wget_wch_test(0, stdscr, delay);
1124 finish_getch_test();
1128 /****************************************************************************
1130 * Character attributes test
1132 ****************************************************************************/
1134 #if HAVE_SETUPTERM || HAVE_TGETENT
1135 #define get_ncv() TIGETNUM("ncv","NC")
1136 #define get_xmc() TIGETNUM("xmc","sg")
1138 #define get_ncv() -1
1139 #define get_xmc() -1
1146 static int first = TRUE;
1147 static chtype result = 0;
1153 char *area_pointer = parsed;
1155 tgetent(buffer, getenv("TERM"));
1158 if (TIGETSTR("smso", "so"))
1159 result |= A_STANDOUT;
1160 if (TIGETSTR("smul", "us"))
1161 result |= A_UNDERLINE;
1162 if (TIGETSTR("rev", "mr"))
1163 result |= A_REVERSE;
1164 if (TIGETSTR("blink", "mb"))
1166 if (TIGETSTR("dim", "mh"))
1168 if (TIGETSTR("bold", "md"))
1170 if (TIGETSTR("smacs", "ac"))
1171 result |= A_ALTCHARSET;
1177 #define termattrs() my_termattrs()
1180 #define MAX_ATTRSTRING 31
1181 #define LEN_ATTRSTRING 26
1183 static char attr_test_string[MAX_ATTRSTRING + 1];
1186 attr_legend(WINDOW *helpwin)
1191 mvwprintw(helpwin, row++, col,
1193 mvwprintw(helpwin, row++, col,
1196 mvwprintw(helpwin, row++, col,
1197 "Modify the test strings:");
1198 mvwprintw(helpwin, row++, col,
1199 " A digit sets gaps on each side of displayed attributes");
1200 mvwprintw(helpwin, row++, col,
1201 " </> shifts the text left/right. ");
1203 mvwprintw(helpwin, row++, col,
1206 mvwprintw(helpwin, row++, col,
1207 " f/F/b/F toggle foreground/background background color");
1208 mvwprintw(helpwin, row++, col,
1209 " t/T toggle text/background color attribute");
1211 mvwprintw(helpwin, row++, col,
1212 " a/A toggle ACS (alternate character set) mapping");
1213 mvwprintw(helpwin, row++, col,
1214 " v/V toggle video attribute to combine with each line");
1218 show_color_attr(int fg, int bg, int tx)
1221 printw(" Colors (fg %d, bg %d", fg, bg);
1223 printw(", text %d", tx);
1229 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1236 *fg = (short) (*fg + 1);
1239 *fg = (short) (*fg - 1);
1242 *bg = (short) (*bg + 1);
1245 *bg = (short) (*bg - 1);
1248 *tx = (short) (*tx + 1);
1251 *tx = (short) (*tx - 1);
1259 *fg = (short) min_colors;
1260 if (*fg < min_colors)
1261 *fg = (short) (COLORS - 1);
1263 *bg = (short) min_colors;
1264 if (*bg < min_colors)
1265 *bg = (short) (COLORS - 1);
1269 *tx = (short) (COLORS - 1);
1278 adjust_attr_string(int adjust)
1280 int first = ((int) UChar(attr_test_string[0])) + adjust;
1281 int last = first + LEN_ATTRSTRING;
1283 if (first >= ' ' && last <= '~') { /* 32..126 */
1285 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1286 attr_test_string[j] = (char) k;
1287 if (((k + 1 - first) % 5) == 0) {
1288 if (++j >= MAX_ATTRSTRING)
1290 attr_test_string[j] = ' ';
1293 while (j < MAX_ATTRSTRING)
1294 attr_test_string[j++] = ' ';
1295 attr_test_string[j] = '\0';
1302 init_attr_string(void)
1304 attr_test_string[0] = 'a';
1305 adjust_attr_string(0);
1309 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1311 int ncv = get_ncv();
1312 chtype test = attr & (chtype) (~A_ALTCHARSET);
1315 mvprintw(row, 5, "-->");
1316 mvprintw(row, 8, "%s mode:", name);
1317 mvprintw(row, 24, "|");
1319 printw("%*s", skip, " ");
1321 * Just for testing, write text using the alternate character set one
1322 * character at a time (to pass its rendition directly), and use the
1323 * string operation for the other attributes.
1325 if (attr & A_ALTCHARSET) {
1329 for (s = attr_test_string; *s != '\0'; ++s) {
1335 addstr(attr_test_string);
1339 printw("%*s", skip, " ");
1341 if (test != A_NORMAL) {
1342 if (!(termattrs() & test)) {
1345 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1346 static const chtype table[] =
1362 for (n = 0; n < SIZEOF(table); n++) {
1363 if ((table[n] & attr) != 0
1364 && ((1 << n) & ncv) != 0) {
1372 if ((termattrs() & test) != test)
1379 static const struct {
1381 NCURSES_CONST char * name;
1382 } attrs_to_test[] = {
1383 { A_STANDOUT, "STANDOUT" },
1384 { A_REVERSE, "REVERSE" },
1386 { A_UNDERLINE, "UNDERLINE" },
1388 { A_BLINK, "BLINK" },
1389 { A_PROTECT, "PROTECT" },
1391 { A_INVIS, "INVISIBLE" },
1393 { A_NORMAL, "NORMAL" },
1398 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1408 if (ch < 256 && isdigit(ch)) {
1416 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1418 attr_legend(helpwin);
1431 *kc = SIZEOF(attrs_to_test) - 1;
1437 if (*kc >= SIZEOF(attrs_to_test))
1441 adjust_attr_string(-1);
1444 adjust_attr_string(1);
1450 error = cycle_color_attr(ch, fg, bg, tx);
1460 /* test text attributes */
1463 int skip = get_xmc();
1464 short fg = COLOR_BLACK; /* color pair 0 is special */
1465 short bg = COLOR_BLACK;
1473 n = skip; /* make it easy */
1474 k = SIZEOF(attrs_to_test) - 1;
1479 chtype normal = A_NORMAL | BLANK;
1480 chtype extras = (chtype) ac;
1483 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1486 if (init_pair(pair, fg, bg) == ERR) {
1489 normal |= COLOR_PAIR(pair);
1494 if (init_pair(pair, tx, bg) == ERR) {
1497 extras |= COLOR_PAIR(pair);
1506 mvaddstr(0, 20, "Character attribute test display");
1508 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1509 bool arrow = (j == k);
1510 row = show_attr(row, n, arrow,
1512 attrs_to_test[j].attr |
1513 attrs_to_test[k].attr,
1514 attrs_to_test[j].name);
1518 "This terminal does %shave the magic-cookie glitch",
1519 get_xmc() > -1 ? "" : "not ");
1520 mvprintw(row + 1, 8, "Enter '?' for help.");
1521 show_color_attr(fg, bg, tx);
1522 printw(" ACS (%d)", ac != 0);
1525 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1527 bkgdset(A_NORMAL | BLANK);
1532 #if USE_WIDEC_SUPPORT
1533 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1536 wide_adjust_attr_string(int adjust)
1538 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1539 int last = first + LEN_ATTRSTRING;
1541 if (first >= ' ' && last <= '~') { /* 32..126 */
1543 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1544 wide_attr_test_string[j] = k;
1545 if (((k + 1 - first) % 5) == 0) {
1546 if (++j >= MAX_ATTRSTRING)
1548 wide_attr_test_string[j] = ' ';
1551 while (j < MAX_ATTRSTRING)
1552 wide_attr_test_string[j++] = ' ';
1553 wide_attr_test_string[j] = '\0';
1560 wide_init_attr_string(void)
1562 wide_attr_test_string[0] = 'a';
1563 wide_adjust_attr_string(0);
1567 set_wide_background(short pair)
1574 setcchar(&normal, blank, A_NORMAL, pair, 0);
1580 get_wide_background(void)
1582 attr_t result = A_NORMAL;
1588 if (getbkgrnd(&ch) != ERR) {
1589 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1597 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1599 int ncv = get_ncv();
1600 chtype test = attr & ~WA_ALTCHARSET;
1603 mvprintw(row, 5, "-->");
1604 mvprintw(row, 8, "%s mode:", name);
1605 mvprintw(row, 24, "|");
1607 printw("%*s", skip, " ");
1610 * Just for testing, write text using the alternate character set one
1611 * character at a time (to pass its rendition directly), and use the
1612 * string operation for the other attributes.
1614 if (attr & WA_ALTCHARSET) {
1618 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1622 setcchar(&ch, fill, attr, pair, 0);
1629 attr_get(&old_attr, &old_pair, 0);
1630 attr_set(attr, pair, 0);
1631 addwstr(wide_attr_test_string);
1632 attr_set(old_attr, old_pair, 0);
1635 printw("%*s", skip, " ");
1637 if (test != A_NORMAL) {
1638 if (!(term_attrs() & test)) {
1641 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1642 static const attr_t table[] =
1656 for (n = 0; n < SIZEOF(table); n++) {
1657 if ((table[n] & attr) != 0
1658 && ((1 << n) & ncv) != 0) {
1666 if ((term_attrs() & test) != test)
1674 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1684 if (ch < 256 && isdigit(ch)) {
1692 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1693 box_set(helpwin, 0, 0);
1694 attr_legend(helpwin);
1707 *kc = SIZEOF(attrs_to_test) - 1;
1713 if (*kc >= SIZEOF(attrs_to_test))
1717 wide_adjust_attr_string(-1);
1720 wide_adjust_attr_string(1);
1726 error = cycle_color_attr(ch, fg, bg, tx);
1735 wide_attr_test(void)
1736 /* test text attributes using wide-character calls */
1739 int skip = get_xmc();
1740 short fg = COLOR_BLACK; /* color pair 0 is special */
1741 short bg = COLOR_BLACK;
1749 n = skip; /* make it easy */
1750 k = SIZEOF(attrs_to_test) - 1;
1751 wide_init_attr_string();
1759 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1762 if (init_pair(pair, fg, bg) == ERR) {
1769 if (init_pair(extras, tx, bg) == ERR) {
1774 set_wide_background(pair);
1777 box_set(stdscr, 0, 0);
1778 mvaddstr(0, 20, "Character attribute test display");
1780 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1781 row = wide_show_attr(row, n, j == k,
1783 attrs_to_test[j].attr |
1784 attrs_to_test[k].attr,
1786 attrs_to_test[j].name);
1790 "This terminal does %shave the magic-cookie glitch",
1791 get_xmc() > -1 ? "" : "not ");
1792 mvprintw(row + 1, 8, "Enter '?' for help.");
1793 show_color_attr(fg, bg, tx);
1794 printw(" ACS (%d)", ac != 0);
1797 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1799 set_wide_background(0);
1805 /****************************************************************************
1807 * Color support tests
1809 ****************************************************************************/
1811 static NCURSES_CONST char *the_color_names[] =
1832 show_color_name(int y, int x, int color, bool wide)
1834 if (move(y, x) != ERR) {
1839 sprintf(temp, "%02d", color);
1841 } else if (color >= 8) {
1842 sprintf(temp, "[%02d]", color);
1844 strcpy(temp, the_color_names[color]);
1846 printw("%-*.*s", width, width, temp);
1851 color_legend(WINDOW *helpwin, bool wide)
1856 mvwprintw(helpwin, row++, col,
1859 mvwprintw(helpwin, row++, col,
1860 "Use up/down arrow to scroll through the display if it is");
1861 mvwprintw(helpwin, row++, col,
1862 "longer than one screen. Control/N and Control/P can be used");
1863 mvwprintw(helpwin, row++, col,
1864 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1865 mvwprintw(helpwin, row++, col,
1866 "full screen; control/B and control/F can be used here.");
1868 mvwprintw(helpwin, row++, col,
1870 mvwprintw(helpwin, row++, col,
1871 " a/A toggle altcharset off/on");
1872 mvwprintw(helpwin, row++, col,
1873 " b/B toggle bold off/on");
1874 mvwprintw(helpwin, row++, col,
1875 " n/N toggle text/number on/off");
1876 mvwprintw(helpwin, row++, col,
1877 " w/W toggle width between 8/16 colors");
1878 #if USE_WIDEC_SUPPORT
1880 mvwprintw(helpwin, row++, col,
1881 "Wide characters:");
1882 mvwprintw(helpwin, row++, col,
1883 " x/X toggle text between ASCII and wide-character");
1890 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1892 /* generate a color test pattern */
1899 int grid_top = top + 3;
1900 int page_size = (LINES - grid_top);
1901 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1907 bool opt_acsc = FALSE;
1908 bool opt_bold = FALSE;
1909 bool opt_wide = FALSE;
1910 bool opt_nums = FALSE;
1913 if (pairs_max > COLOR_PAIRS)
1914 pairs_max = COLOR_PAIRS;
1919 /* this assumes an 80-column line */
1923 per_row = (COLORS > 8) ? 16 : 8;
1930 row_limit = (pairs_max + per_row - 1) / per_row;
1933 (void) printw("There are %d color pairs and %d colors\n",
1937 (void) mvprintw(top + 1, 0,
1938 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1941 opt_bold ? "on" : "off");
1943 /* show color names/numbers across the top */
1944 for (i = 0; i < per_row; i++)
1945 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
1947 /* show a grid of colors, with color names/ numbers on the left */
1948 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
1949 int row = grid_top + (i / per_row) - base_row;
1950 int col = (i % per_row + 1) * width;
1953 if (row >= 0 && move(row, col) != ERR) {
1954 short fg = (short) (i % COLORS);
1955 short bg = (short) (i / COLORS);
1957 init_pair(pair, fg, bg);
1958 attron((attr_t) COLOR_PAIR(pair));
1960 attron((attr_t) A_ALTCHARSET);
1962 attron((attr_t) A_BOLD);
1965 sprintf(numbered, "{%02X}", i);
1968 printw("%-*.*s", width, width, hello);
1971 if ((i % per_row) == 0 && (i % COLORS) == 0) {
1972 show_color_name(row, 0, i / COLORS, opt_wide);
1980 switch (wGetchar(stdscr)) {
2003 set_color_test(opt_wide, FALSE);
2006 set_color_test(opt_wide, TRUE);
2010 if (base_row <= 0) {
2018 if (base_row + page_size >= row_limit) {
2027 if (base_row <= 0) {
2030 base_row -= (page_size - 1);
2038 if (base_row + page_size >= row_limit) {
2041 base_row += page_size - 1;
2042 if (base_row + page_size >= row_limit) {
2043 base_row = row_limit - page_size - 1;
2048 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2050 color_legend(helpwin, FALSE);
2065 #if USE_WIDEC_SUPPORT
2066 /* generate a color test pattern */
2068 wide_color_test(void)
2074 int grid_top = top + 3;
2075 int page_size = (LINES - grid_top);
2076 int pairs_max = COLOR_PAIRS;
2082 bool opt_acsc = FALSE;
2083 bool opt_bold = FALSE;
2084 bool opt_wide = FALSE;
2085 bool opt_nums = FALSE;
2086 bool opt_xchr = FALSE;
2093 /* this assumes an 80-column line */
2097 per_row = (COLORS > 8) ? 16 : 8;
2104 make_fullwidth_text(buffer, hello);
2108 make_narrow_text(buffer, hello);
2111 row_limit = (pairs_max + per_row - 1) / per_row;
2114 (void) printw("There are %d color pairs and %d colors\n",
2118 (void) mvprintw(top + 1, 0,
2119 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2122 opt_bold ? "on" : "off");
2124 /* show color names/numbers across the top */
2125 for (i = 0; i < per_row; i++)
2126 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
2128 /* show a grid of colors, with color names/ numbers on the left */
2129 for (i = (base_row * per_row); i < pairs_max; i++) {
2130 int row = grid_top + (i / per_row) - base_row;
2131 int col = (i % per_row + 1) * width;
2132 short pair = (short) i;
2134 if (row >= 0 && move(row, col) != ERR) {
2135 init_pair(pair, (short) (i % COLORS), (short) (i / COLORS));
2136 color_set(pair, NULL);
2138 attr_on((attr_t) A_ALTCHARSET, NULL);
2140 attr_on((attr_t) A_BOLD, NULL);
2143 sprintf(numbered, "{%02X}", i);
2145 make_fullwidth_text(buffer, numbered);
2147 make_narrow_text(buffer, numbered);
2150 addnwstr(buffer, width);
2151 attr_set(A_NORMAL, 0, NULL);
2153 if ((i % per_row) == 0 && (i % COLORS) == 0) {
2154 show_color_name(row, 0, i / COLORS, opt_wide);
2162 switch (c = wGetchar(stdscr)) {
2185 set_color_test(opt_wide, FALSE);
2188 set_color_test(opt_wide, TRUE);
2198 if (base_row <= 0) {
2206 if (base_row + page_size >= row_limit) {
2215 if (base_row <= 0) {
2218 base_row -= (page_size - 1);
2226 if (base_row + page_size >= row_limit) {
2229 base_row += page_size - 1;
2230 if (base_row + page_size >= row_limit) {
2231 base_row = row_limit - page_size - 1;
2236 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2238 color_legend(helpwin, TRUE);
2252 #endif /* USE_WIDEC_SUPPORT */
2255 change_color(short current, int field, int value, int usebase)
2257 short red, green, blue;
2259 color_content(current, &red, &green, &blue);
2263 red = (short) (usebase ? (red + value) : value);
2266 green = (short) (usebase ? (green + value) : value);
2269 blue = (short) (usebase ? (blue + value) : value);
2273 if (init_color(current, red, green, blue) == ERR)
2278 init_all_colors(void)
2282 for (c = 0; c < COLORS; ++c)
2285 all_colors[c].green,
2286 all_colors[c].blue);
2289 #define scaled_rgb(n) ((255 * (n)) / 1000)
2293 /* display the color test pattern, without trying to edit colors */
2297 int this_c = 0, value = 0, field = 0;
2300 int page_size = (LINES - 6);
2305 for (i = 0; i < max_colors; i++)
2306 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2308 mvprintw(LINES - 2, 0, "Number: %d", value);
2311 short red, green, blue;
2314 mvaddstr(0, 20, "Color RGB Value Editing");
2317 for (i = (short) top_color;
2318 (i - top_color < page_size)
2319 && (i < max_colors); i++) {
2322 sprintf(numeric, "[%d]", i);
2323 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2324 (i == current ? '>' : ' '),
2325 (i < (int) SIZEOF(the_color_names)
2326 ? the_color_names[i] : numeric));
2327 attrset(COLOR_PAIR(i));
2331 color_content((short) i, &red, &green, &blue);
2333 if (current == i && field == 0)
2335 printw("%04d", red);
2336 if (current == i && field == 0)
2339 if (current == i && field == 1)
2341 printw("%04d", green);
2342 if (current == i && field == 1)
2345 if (current == i && field == 2)
2347 printw("%04d", blue);
2348 if (current == i && field == 2)
2351 printw(" ( %3d %3d %3d )",
2357 mvaddstr(LINES - 3, 0,
2358 "Use up/down to select a color, left/right to change fields.");
2359 mvaddstr(LINES - 2, 0,
2360 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2362 move(2 + current - top_color, 0);
2366 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2373 current -= (page_size - 1);
2380 if (current < (max_colors - 1))
2381 current += (page_size - 1);
2388 current = (current == 0 ? (max_colors - 1) : current - 1);
2393 current = (current == (max_colors - 1) ? 0 : current + 1);
2397 field = (field == 2 ? 0 : field + 1);
2401 field = (field == 0 ? 2 : field - 1);
2414 value = value * 10 + (this_c - '0');
2418 change_color((short) current, field, value, 1);
2422 change_color((short) current, field, -value, 1);
2426 change_color((short) current, field, value, 0);
2431 P(" RGB Value Editing Help");
2433 P("You are in the RGB value editor. Use the arrow keys to select one of");
2434 P("the fields in one of the RGB triples of the current colors; the one");
2435 P("currently selected will be reverse-video highlighted.");
2437 P("To change a field, enter the digits of the new value; they are echoed");
2438 P("as entered. Finish by typing `='. The change will take effect instantly.");
2439 P("To increment or decrement a value, use the same procedure, but finish");
2440 P("with a `+' or `-'.");
2442 P("Press 'm' to invoke the top-level menu with the current color settings.");
2443 P("To quit, do ESC");
2465 if (current >= max_colors)
2466 current = max_colors - 1;
2467 if (current < top_color)
2468 top_color = current;
2469 if (current - top_color >= page_size)
2470 top_color = current - (page_size - 1);
2472 mvprintw(LINES - 1, 0, "Number: %d", value);
2480 * ncurses does not reset each color individually when calling endwin().
2487 /****************************************************************************
2489 * Soft-key label test
2491 ****************************************************************************/
2496 #define SLK_WORK (SLK_HELP + 3)
2501 static const char *table[] =
2503 "Available commands are:"
2505 ,"^L -- repaint this message and activate soft keys"
2506 ,"a/d -- activate/disable soft keys"
2507 ,"c -- set centered format for labels"
2508 ,"l -- set left-justified format for labels"
2509 ,"r -- set right-justified format for labels"
2510 ,"[12345678] -- set label; labels are numbered 1 through 8"
2511 ,"e -- erase stdscr (should not erase labels)"
2512 ,"s -- test scrolling of shortened screen"
2514 ,"F/B -- cycle through foreground/background colors"
2516 ,"ESC -- return to main menu"
2518 ,"Note: if activating the soft keys causes your terminal to scroll up"
2519 ,"one line, your terminal auto-scrolls when anything is written to the"
2520 ,"last screen position. The ncurses code does not yet handle this"
2526 for (j = 0; j < SIZEOF(table); ++j) {
2534 call_slk_color(short fg, short bg)
2536 init_pair(1, bg, fg);
2538 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2546 /* exercise the soft keys */
2552 short fg = COLOR_BLACK;
2553 short bg = COLOR_WHITE;
2559 call_slk_color(fg, bg);
2569 mvaddstr(0, 20, "Soft Key Exerciser");
2584 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2585 while ((c = Getchar()) != 'Q' && (c != ERR))
2613 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2615 if ((s = slk_label(c - '0')) != 0) {
2618 wGetstring(stdscr, buf, 8);
2619 slk_set((c - '0'), buf, fmt);
2631 fg = (short) ((fg + 1) % COLORS);
2632 call_slk_color(fg, bg);
2637 bg = (short) ((bg + 1) % COLORS);
2638 call_slk_color(fg, bg);
2642 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2644 wnoutrefresh(stdscr);
2651 } while (!isQuit(c = Getchar()));
2659 #if USE_WIDEC_SUPPORT
2663 /* exercise the soft keys */
2666 wchar_t buf[SLKLEN + 1];
2668 short fg = COLOR_BLACK;
2669 short bg = COLOR_WHITE;
2673 call_slk_color(fg, bg);
2680 attr_on(WA_BOLD, NULL);
2681 mvaddstr(0, 20, "Soft Key Exerciser");
2682 attr_off(WA_BOLD, NULL);
2696 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2697 while ((c = Getchar()) != 'Q' && (c != ERR))
2725 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2727 if ((s = slk_label(c - '0')) != 0) {
2728 char *temp = strdup(s);
2729 size_t used = strlen(temp);
2730 size_t want = SLKLEN;
2732 #ifndef state_unused
2737 while (want > 0 && used != 0) {
2738 const char *base = s;
2739 reset_mbytes(state);
2740 test = count_mbytes(base, 0, &state);
2741 if (test == (size_t) -1) {
2743 } else if (test > want) {
2746 reset_mbytes(state);
2747 trans_mbytes(buf, base, want, &state);
2753 wGet_wstring(stdscr, buf, SLKLEN);
2754 slk_wset((c - '0'), buf, fmt);
2765 fg = (short) ((fg + 1) % COLORS);
2766 call_slk_color(fg, bg);
2771 bg = (short) ((bg + 1) % COLORS);
2772 call_slk_color(fg, bg);
2775 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2777 wnoutrefresh(stdscr);
2783 } while (!isQuit(c = Getchar()));
2791 #endif /* SLK_INIT */
2793 /****************************************************************************
2795 * Alternate character-set stuff
2797 ****************************************************************************/
2802 } attrs_to_cycle[] = {
2803 { A_NORMAL, "normal" },
2805 { A_REVERSE, "reverse" },
2806 { A_UNDERLINE, "underline" },
2811 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2817 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2822 *at_code = SIZEOF(attrs_to_cycle) - 1;
2831 *attr = attrs_to_cycle[*at_code].attr;
2836 cycle_colors(int ch, int *fg, int *bg, short *pair)
2838 bool result = FALSE;
2848 if ((*fg += 1) >= COLORS)
2856 if ((*bg += 1) >= COLORS)
2864 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2867 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2876 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2877 * terminal to perform functions. The remaining codes can be graphic.
2880 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
2882 bool C1 = (first == 128);
2884 unsigned last = first + 31;
2889 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2890 C1 ? "C1" : "GR", first, last);
2894 for (code = first; code <= last; code++) {
2896 int row = 2 + ((int) (code - first) % 16);
2897 int col = ((int) (code - first) / 16) * COLS / 2;
2899 sprintf(tmp, "%3u (0x%x)", code, code);
2900 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2904 nodelay(stdscr, TRUE);
2905 echochar(code | attr | COLOR_PAIR(pair));
2907 /* (yes, this _is_ crude) */
2908 while ((reply = Getchar()) != ERR) {
2909 addch(UChar(reply));
2912 nodelay(stdscr, FALSE);
2914 } while (--count > 0);
2921 show_pc_chars(int repeat, attr_t attr, short pair)
2927 mvprintw(0, 20, "Display of PC Character Codes");
2931 for (code = 0; code < 16; ++code) {
2932 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
2934 for (code = 0; code < 256; code++) {
2936 int row = 3 + (int) (code / 16) + (code >= 128);
2937 int col = 8 + (int) (code % 16) * PC_COLS;
2938 if ((code % 16) == 0)
2939 mvprintw(row, 0, "0x%02x:", code);
2950 * Skip the ones that do not work.
2954 addch(code | A_ALTCHARSET | attr | COLOR_PAIR(pair));
2957 } while (--count > 0);
2962 show_box_chars(int repeat, attr_t attr, short pair)
2965 attr |= COLOR_PAIR(pair);
2969 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
2974 mvhline(LINES / 2, 0, ACS_HLINE | attr, COLS);
2975 mvvline(0, COLS / 2, ACS_VLINE | attr, LINES);
2976 mvaddch(0, COLS / 2, ACS_TTEE | attr);
2977 mvaddch(LINES / 2, COLS / 2, ACS_PLUS | attr);
2978 mvaddch(LINES - 1, COLS / 2, ACS_BTEE | attr);
2979 mvaddch(LINES / 2, 0, ACS_LTEE | attr);
2980 mvaddch(LINES / 2, COLS - 1, ACS_RTEE | attr);
2986 show_1_acs(int n, int repeat, const char *name, chtype code)
2988 const int height = 16;
2989 int row = 2 + (n % height);
2990 int col = (n / height) * COLS / 2;
2992 mvprintw(row, col, "%*s : ", COLS / 4, name);
2995 } while (--repeat > 0);
3000 show_acs_chars(int repeat, attr_t attr, short pair)
3001 /* display the ACS character set */
3005 #define BOTH(name) #name, (name | attr | COLOR_PAIR(pair))
3009 mvaddstr(0, 20, "Display of the ACS Character Set");
3013 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3014 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3015 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3016 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3018 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3019 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3020 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3021 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3023 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3024 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3027 * HPUX's ACS definitions are broken here. Just give up.
3029 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3030 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3031 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3032 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3033 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3035 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3036 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3037 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3038 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3039 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3040 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3041 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3042 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3043 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3045 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3046 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3047 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3049 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3050 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3051 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3052 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3053 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3054 n = show_1_acs(n, repeat, BOTH(ACS_S9));
3062 char *term = getenv("TERM");
3063 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3066 chtype attr = A_NORMAL;
3069 int fg = COLOR_BLACK;
3070 int bg = COLOR_BLACK;
3071 unsigned at_code = 0;
3073 void (*last_show_acs) (int, attr_t, short) = 0;
3081 ToggleAcs(last_show_acs, show_acs_chars);
3085 ToggleAcs(last_show_acs, show_pc_chars);
3090 ToggleAcs(last_show_acs, show_box_chars);
3116 if (repeat < (COLS / 4))
3124 if (cycle_attr(c, &at_code, &attr)
3125 || cycle_colors(c, &fg, &bg, &pair)) {
3132 if (last_show_acs != 0)
3133 last_show_acs(repeat, attr, pair);
3135 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3137 mvprintw(LINES - 3, 0,
3138 "Note: ANSI terminals may not display C1 characters.");
3139 mvprintw(LINES - 2, 0,
3140 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3143 mvprintw(LINES - 1, 0,
3144 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3145 attrs_to_cycle[at_code].name,
3148 mvprintw(LINES - 1, 0,
3149 "v/V cycles through video attributes (%s).",
3150 attrs_to_cycle[at_code].name);
3153 } while (!isQuit(c = Getchar()));
3160 #if USE_WIDEC_SUPPORT
3162 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3164 int count = getcchar(src, NULL, NULL, NULL, 0);
3171 if ((wch = typeMalloc(wchar_t, (unsigned) count + 1)) != 0) {
3172 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
3173 attr |= (ignore_attr & A_ALTCHARSET);
3174 setcchar(dst, wch, attr, pair, 0);
3183 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3187 int last = first + 31;
3191 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3194 for (code = first; (int) code <= last; code++) {
3195 int row = 2 + ((code - first) % 16);
3196 int col = ((code - first) / 16) * COLS / 2;
3202 memset(&codes, 0, sizeof(codes));
3204 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3205 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3206 setcchar(&temp, codes, attr, pair, 0);
3209 * Give non-spacing characters something to combine with. If we
3210 * don't, they'll bunch up in a heap on the space after the ":".
3211 * Mark them with reverse-video to make them simpler to find on
3214 if (wcwidth(code) == 0)
3215 addch(space | A_REVERSE);
3217 * This could use add_wch(), but is done for comparison with the
3218 * normal 'f' test (and to make a test-case for echo_wchar()).
3219 * The screen will flicker because the erase() at the top of the
3220 * function is met by the builtin refresh() in echo_wchar().
3224 * The repeat-count may make text wrap - avoid that.
3226 getyx(stdscr, y, x);
3227 if (x >= col + (COLS / 2) - 2)
3229 } while (--count > 0);
3234 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3236 const int height = 16;
3237 int row = 2 + (n % height);
3238 int col = (n / height) * COLS / 2;
3240 mvprintw(row, col, "%*s : ", COLS / 4, name);
3241 while (repeat-- >= 0) {
3247 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3250 show_wacs_chars(int repeat, attr_t attr, short pair)
3251 /* display the wide-ACS character set */
3257 /*#define BOTH2(name) #name, &(name) */
3258 #define BOTH2(name) #name, MERGE_ATTR(name)
3262 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3266 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3267 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3268 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3269 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3271 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3272 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3273 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3274 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3276 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3277 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3279 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3280 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3281 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3282 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3284 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3285 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3286 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3287 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3288 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3289 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3290 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3291 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3292 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3294 #ifdef CURSES_WACS_ARRAY
3295 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3296 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3297 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3299 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3300 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3301 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3302 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3303 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3304 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3310 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3313 show_wbox_chars(int repeat, attr_t attr, short pair)
3320 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3324 attr_set(attr, pair, 0);
3325 box_set(stdscr, 0, 0);
3326 attr_set(A_NORMAL, 0, 0);
3328 mvhline_set(LINES / 2, 0, MERGE_ATTR(WACS_HLINE), COLS);
3329 mvvline_set(0, COLS / 2, MERGE_ATTR(WACS_VLINE), LINES);
3330 mvadd_wch(0, COLS / 2, MERGE_ATTR(WACS_TTEE));
3331 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(WACS_PLUS));
3332 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(WACS_BTEE));
3333 mvadd_wch(LINES / 2, 0, MERGE_ATTR(WACS_LTEE));
3334 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(WACS_RTEE));
3342 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3344 const int height = 16;
3345 int row = 2 + (n % height);
3346 int col = (n / height) * COLS / 2;
3349 mvprintw(row, col, "%*s : ", COLS / 4, name);
3350 attr_set(attr, pair, 0);
3351 addstr(strcpy(temp, code));
3352 attr_set(A_NORMAL, 0, 0);
3356 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3359 show_utf8_chars(int repeat, attr_t attr, short pair)
3366 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3370 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3371 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3372 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3373 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3375 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3376 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3377 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3378 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3380 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3381 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3383 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3384 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3385 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3386 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3388 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3389 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3390 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3391 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3392 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3393 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3394 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3395 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3396 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3397 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3398 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3399 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3401 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3402 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3403 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3404 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3405 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3406 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3411 /* display the wide-ACS character set */
3413 wide_acs_display(void)
3419 chtype attr = A_NORMAL;
3420 int fg = COLOR_BLACK;
3421 int bg = COLOR_BLACK;
3422 unsigned at_code = 0;
3424 void (*last_show_wacs) (int, attr_t, short) = 0;
3432 ToggleAcs(last_show_wacs, show_wacs_chars);
3435 ToggleAcs(last_show_wacs, show_wbox_chars);
3438 ToggleAcs(last_show_wacs, show_utf8_chars);
3441 if (c < 256 && isdigit(c)) {
3444 } else if (c == '+') {
3447 } else if (c == '-' && digit > 0) {
3450 } else if (c == '>' && repeat < (COLS / 4)) {
3452 } else if (c == '<' && repeat > 1) {
3454 } else if (c == '_') {
3455 space = (space == ' ') ? '_' : ' ';
3457 } else if (cycle_attr(c, &at_code, &attr)
3458 || cycle_colors(c, &fg, &bg, &pair)) {
3459 if (last_show_wacs != 0)
3467 if (last_show_wacs != 0)
3468 last_show_wacs(repeat, attr, pair);
3470 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3472 mvprintw(LINES - 3, 0,
3473 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3475 mvprintw(LINES - 2, 0,
3476 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3477 attrs_to_cycle[at_code].name,
3480 mvprintw(LINES - 2, 0,
3481 "v/V cycles through video attributes (%s).",
3482 attrs_to_cycle[at_code].name);
3485 } while (!isQuit(c = Getchar()));
3495 * Graphic-rendition test (adapted from vttest)
3498 test_sgr_attributes(void)
3502 for (pass = 0; pass < 2; pass++) {
3503 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3505 /* Use non-default colors if possible to exercise bce a little */
3507 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3508 normal |= COLOR_PAIR(1);
3512 mvprintw(1, 20, "Graphic rendition test pattern:");
3514 mvprintw(4, 1, "vanilla");
3516 #define set_sgr(mask) bkgdset((normal^(mask)));
3518 mvprintw(4, 40, "bold");
3520 set_sgr(A_UNDERLINE);
3521 mvprintw(6, 6, "underline");
3523 set_sgr(A_BOLD | A_UNDERLINE);
3524 mvprintw(6, 45, "bold underline");
3527 mvprintw(8, 1, "blink");
3529 set_sgr(A_BLINK | A_BOLD);
3530 mvprintw(8, 40, "bold blink");
3532 set_sgr(A_UNDERLINE | A_BLINK);
3533 mvprintw(10, 6, "underline blink");
3535 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3536 mvprintw(10, 45, "bold underline blink");
3539 mvprintw(12, 1, "negative");
3541 set_sgr(A_BOLD | A_REVERSE);
3542 mvprintw(12, 40, "bold negative");
3544 set_sgr(A_UNDERLINE | A_REVERSE);
3545 mvprintw(14, 6, "underline negative");
3547 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3548 mvprintw(14, 45, "bold underline negative");
3550 set_sgr(A_BLINK | A_REVERSE);
3551 mvprintw(16, 1, "blink negative");
3553 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3554 mvprintw(16, 40, "bold blink negative");
3556 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3557 mvprintw(18, 6, "underline blink negative");
3559 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3560 mvprintw(18, 45, "bold underline blink negative");
3563 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3569 bkgdset(A_NORMAL | BLANK);
3574 /****************************************************************************
3576 * Windows and scrolling tester.
3578 ****************************************************************************/
3580 #define BOTLINES 4 /* number of line stolen from screen bottom */
3586 #define FRAME struct frame
3595 #if defined(NCURSES_VERSION)
3596 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3597 #define is_keypad(win) (win)->_use_keypad
3598 #define is_scrollok(win) (win)->_scroll
3599 #elif !defined(is_keypad)
3600 #define is_keypad(win) FALSE
3601 #define is_scrollok(win) FALSE
3604 #define is_keypad(win) FALSE
3605 #define is_scrollok(win) FALSE
3609 frame_win(FRAME * curp)
3611 return (curp != 0) ? curp->wind : stdscr;
3614 /* We need to know if these flags are actually set, so don't look in FRAME.
3615 * These names are known to work with SVr4 curses as well as ncurses. The
3616 * _use_keypad name does not work with Solaris 8.
3619 HaveKeypad(FRAME * curp)
3621 WINDOW *win = frame_win(curp);
3623 return is_keypad(win);
3627 HaveScroll(FRAME * curp)
3629 WINDOW *win = frame_win(curp);
3631 return is_scrollok(win);
3635 newwin_legend(FRAME * curp)
3637 static const struct {
3642 "^C = create window", 0
3645 "^N = next window", 0
3648 "^P = previous window", 0
3651 "^F = scroll forward", 0
3654 "^B = scroll backward", 0
3657 "^K = keypad(%s)", 1
3660 "^S = scrollok(%s)", 2
3663 "^W = save window to file", 0
3666 "^R = restore window", 0
3679 bool do_keypad = HaveKeypad(curp);
3680 bool do_scroll = HaveScroll(curp);
3684 for (n = 0; n < SIZEOF(legend); n++) {
3685 switch (legend[n].code) {
3687 strcpy(buf, legend[n].msg);
3690 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3693 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3696 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3699 x = getcurx(stdscr);
3700 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3707 transient(FRAME * curp, NCURSES_CONST char *msg)
3709 newwin_legend(curp);
3711 mvaddstr(LINES - 1, 0, msg);
3717 printw("%s characters are echoed, window should %sscroll.",
3718 HaveKeypad(curp) ? "Non-arrow" : "All other",
3719 HaveScroll(curp) ? "" : "not ");
3724 newwin_report(FRAME * curp)
3725 /* report on the cursor's current position, then restore it */
3727 WINDOW *win = frame_win(curp);
3731 transient(curp, (char *) 0);
3733 move(LINES - 1, COLS - 17);
3734 printw("Y = %2d X = %2d", y, x);
3742 selectcell(int uli, int ulj, int lri, int lrj)
3743 /* arrows keys move cursor, return location at current on non-arrow key */
3745 static pair res; /* result cell */
3746 int si = lri - uli + 1; /* depth of the select area */
3747 int sj = lrj - ulj + 1; /* width of the select area */
3748 int i = 0, j = 0; /* offsets into the select area */
3753 move(uli + i, ulj + j);
3754 newwin_report((FRAME *) 0);
3756 switch (Getchar()) {
3770 return ((pair *) 0);
3771 #ifdef NCURSES_MOUSE_VERSION
3777 if (event.y > uli && event.x > ulj) {
3798 outerbox(pair ul, pair lr, bool onoff)
3799 /* draw or erase a box *outside* the given pair of corners */
3801 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3802 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3803 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3804 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3805 move(ul.y - 1, ul.x);
3806 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3807 move(ul.y, ul.x - 1);
3808 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3809 move(lr.y + 1, ul.x);
3810 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3811 move(ul.y, lr.x + 1);
3812 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3817 /* Ask user for a window definition */
3824 addstr("Use arrows to move cursor, anything else to mark corner 1");
3826 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3827 return ((WINDOW *) 0);
3828 memcpy(&ul, tmp, sizeof(pair));
3829 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3832 addstr("Use arrows to move cursor, anything else to mark corner 2");
3834 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
3836 return ((WINDOW *) 0);
3837 memcpy(&lr, tmp, sizeof(pair));
3839 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
3841 outerbox(ul, lr, TRUE);
3852 newwin_move(FRAME * curp, int dy, int dx)
3854 WINDOW *win = frame_win(curp);
3858 getyx(win, cur_y, cur_x);
3859 getmaxyx(win, max_y, max_x);
3860 if ((cur_x += dx) < 0)
3862 else if (cur_x >= max_x)
3864 if ((cur_y += dy) < 0)
3866 else if (cur_y >= max_y)
3868 wmove(win, cur_y, cur_x);
3872 delete_framed(FRAME * fp, bool showit)
3877 fp->last->next = fp->next;
3878 fp->next->last = fp->last;
3886 np = (fp == fp->next) ? 0 : fp->next;
3893 acs_and_scroll(void)
3894 /* Demonstrate windows */
3897 FRAME *current = (FRAME *) 0, *neww;
3898 WINDOW *usescr = stdscr;
3899 #if HAVE_PUTWIN && HAVE_GETWIN
3903 #define DUMPFILE "screendump"
3905 #ifdef NCURSES_MOUSE_VERSION
3906 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
3911 transient((FRAME *) 0, (char *) 0);
3914 if ((neww = typeCalloc(FRAME, 1)) == 0) {
3917 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
3922 if (current == 0) { /* First element, */
3923 neww->next = neww; /* so point it at itself */
3926 neww->next = current->next;
3927 neww->last = current;
3928 neww->last->next = neww;
3929 neww->next->last = neww;
3932 /* SVr4 curses sets the keypad on all newly-created windows to
3933 * false. Someone reported that PDCurses makes new windows inherit
3934 * this flag. Remove the following 'keypad()' call to test this
3936 keypad(current->wind, TRUE);
3937 current->do_keypad = HaveKeypad(current);
3938 current->do_scroll = HaveScroll(current);
3941 case CTRL('N'): /* go to next window */
3943 current = current->next;
3946 case CTRL('P'): /* go to previous window */
3948 current = current->last;
3951 case CTRL('F'): /* scroll current window forward */
3953 wscrl(frame_win(current), 1);
3956 case CTRL('B'): /* scroll current window backwards */
3958 wscrl(frame_win(current), -1);
3961 case CTRL('K'): /* toggle keypad mode for current */
3963 current->do_keypad = !current->do_keypad;
3964 keypad(current->wind, current->do_keypad);
3970 current->do_scroll = !current->do_scroll;
3971 scrollok(current->wind, current->do_scroll);
3975 #if HAVE_PUTWIN && HAVE_GETWIN
3976 case CTRL('W'): /* save and delete window */
3977 if ((current != 0) && (current == current->next)) {
3978 transient(current, "Will not save/delete ONLY window");
3980 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
3981 transient(current, "Can't open screen dump file");
3983 (void) putwin(frame_win(current), fp);
3986 current = delete_framed(current, TRUE);
3990 case CTRL('R'): /* restore window */
3991 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
3992 transient(current, "Can't open screen dump file");
3994 if ((neww = typeCalloc(FRAME, 1)) != 0) {
3996 neww->next = current ? current->next : 0;
3997 neww->last = current;
3998 neww->last->next = neww;
3999 neww->next->last = neww;
4001 neww->wind = getwin(fp);
4003 wrefresh(neww->wind);
4011 case CTRL('X'): /* resize window */
4018 addstr("Use arrows to move cursor, anything else to mark new corner");
4021 getbegyx(current->wind, ul.y, ul.x);
4023 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4024 if (tmp == (pair *) 0) {
4029 getmaxyx(current->wind, lr.y, lr.x);
4032 outerbox(ul, lr, FALSE);
4033 wnoutrefresh(stdscr);
4035 /* strictly cosmetic hack for the test */
4036 getmaxyx(current->wind, my, mx);
4037 if (my > tmp->y - ul.y) {
4038 getyx(current->wind, lr.y, lr.x);
4039 wmove(current->wind, tmp->y - ul.y + 1, 0);
4040 wclrtobot(current->wind);
4041 wmove(current->wind, lr.y, lr.x);
4043 if (mx > tmp->x - ul.x)
4044 for (i = 0; i < my; i++) {
4045 wmove(current->wind, i, tmp->x - ul.x + 1);
4046 wclrtoeol(current->wind);
4048 wnoutrefresh(current->wind);
4050 memcpy(&lr, tmp, sizeof(pair));
4051 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4053 getbegyx(current->wind, ul.y, ul.x);
4054 getmaxyx(current->wind, lr.y, lr.x);
4057 outerbox(ul, lr, TRUE);
4058 wnoutrefresh(stdscr);
4060 wnoutrefresh(current->wind);
4066 #endif /* HAVE_WRESIZE */
4068 case KEY_F(10): /* undocumented --- use this to test area clears */
4069 selectcell(0, 0, LINES - 1, COLS - 1);
4075 newwin_move(current, -1, 0);
4078 newwin_move(current, 1, 0);
4081 newwin_move(current, 0, -1);
4084 newwin_move(current, 0, 1);
4092 getyx(frame_win(current), y, x);
4096 x = getmaxx(frame_win(current)) - 1;
4098 mvwdelch(frame_win(current), y, x);
4108 waddch(current->wind, (chtype) c);
4113 newwin_report(current);
4114 usescr = frame_win(current);
4117 (!isQuit(c = wGetchar(usescr))
4121 while (current != 0)
4122 current = delete_framed(current, FALSE);
4124 scrollok(stdscr, TRUE); /* reset to driver's default */
4125 #ifdef NCURSES_MOUSE_VERSION
4126 mousemask(0, (mmask_t *) 0);
4133 /****************************************************************************
4137 ****************************************************************************/
4140 static int nap_msec = 1;
4142 static NCURSES_CONST char *mod[] =
4152 /*+-------------------------------------------------------------------------
4154 --------------------------------------------------------------------------*/
4156 wait_a_while(int msec GCC_UNUSED)
4166 else if (msec > 1000)
4167 sleep((unsigned) msec / 1000);
4171 } /* end of wait_a_while */
4173 /*+-------------------------------------------------------------------------
4175 --------------------------------------------------------------------------*/
4177 saywhat(NCURSES_CONST char *text)
4179 wmove(stdscr, LINES - 1, 0);
4181 if (text != 0 && *text != '\0') {
4182 waddstr(stdscr, text);
4183 waddstr(stdscr, "; ");
4185 waddstr(stdscr, "press any key to continue");
4186 } /* end of saywhat */
4188 /*+-------------------------------------------------------------------------
4189 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4190 --------------------------------------------------------------------------*/
4192 mkpanel(short color, int rows, int cols, int tly, int tlx)
4197 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4198 if ((pan = new_panel(win)) == 0) {
4200 } else if (use_colors) {
4201 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4204 init_pair(color, fg, bg);
4205 wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
4207 wbkgdset(win, A_BOLD | ' ');
4211 } /* end of mkpanel */
4213 /*+-------------------------------------------------------------------------
4215 --------------------------------------------------------------------------*/
4217 rmpanel(PANEL * pan)
4219 WINDOW *win = panel_window(pan);
4222 } /* end of rmpanel */
4224 /*+-------------------------------------------------------------------------
4226 --------------------------------------------------------------------------*/
4232 } /* end of pflush */
4234 /*+-------------------------------------------------------------------------
4236 --------------------------------------------------------------------------*/
4242 for (y = 0; y < LINES - 1; y++) {
4243 for (x = 0; x < COLS; x++)
4244 wprintw(stdscr, "%d", (y + x) % 10);
4249 fill_panel(PANEL * pan)
4251 WINDOW *win = panel_window(pan);
4252 const char *userptr = (const char *) panel_userptr(pan);
4253 int num = (userptr && *userptr) ? userptr[1] : '?';
4257 wprintw(win, "-pan%c-", num);
4260 for (y = 2; y < getmaxy(win) - 1; y++) {
4261 for (x = 1; x < getmaxx(win) - 1; x++) {
4263 waddch(win, UChar(num));
4268 #if USE_WIDEC_SUPPORT
4270 init_wide_panel(void)
4275 for (digit = 0; digit < 10; ++digit)
4276 make_fullwidth_digit(&temp[digit], digit);
4280 getyx(stdscr, y, x);
4281 digit = (y + x / 2) % 10;
4282 } while (add_wch(&temp[digit]) != ERR);
4286 fill_wide_panel(PANEL * pan)
4288 WINDOW *win = panel_window(pan);
4289 const char *userptr = (const char *) panel_userptr(pan);
4290 int num = (userptr && *userptr) ? userptr[1] : '?';
4294 wprintw(win, "-pan%c-", num);
4297 for (y = 2; y < getmaxy(win) - 1; y++) {
4298 for (x = 1; x < getmaxx(win) - 1; x++) {
4300 waddch(win, UChar(num));
4306 #define MAX_PANELS 5
4309 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4311 int which = cmd[1] - '0';
4316 hide_panel(px[which]);
4319 show_panel(px[which]);
4322 top_panel(px[which]);
4325 bottom_panel(px[which]);
4332 wait_a_while(nap_msec);
4336 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4340 PANEL *px[MAX_PANELS + 1];
4342 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4346 for (count = 0; count < 5; count++) {
4347 px[1] = mkpanel(COLOR_RED,
4352 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4354 px[2] = mkpanel(COLOR_GREEN,
4359 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4361 px[3] = mkpanel(COLOR_YELLOW,
4366 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4368 px[4] = mkpanel(COLOR_BLUE,
4373 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4375 px[5] = mkpanel(COLOR_MAGENTA,
4380 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4392 wait_a_while(nap_msec);
4394 saywhat("h3 s1 s2 s4 s5");
4395 move_panel(px[1], 0, 0);
4402 wait_a_while(nap_msec);
4404 canned_panel(px, "s1");
4405 canned_panel(px, "s2");
4408 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4410 wait_a_while(nap_msec);
4412 canned_panel(px, "s3");
4415 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4417 wait_a_while(nap_msec);
4419 canned_panel(px, "b3");
4420 canned_panel(px, "s4");
4421 canned_panel(px, "s5");
4422 canned_panel(px, "t3");
4423 canned_panel(px, "t1");
4424 canned_panel(px, "t2");
4425 canned_panel(px, "t3");
4426 canned_panel(px, "t4");
4428 for (itmp = 0; itmp < 6; itmp++) {
4429 WINDOW *w4 = panel_window(px[4]);
4430 WINDOW *w5 = panel_window(px[5]);
4433 wmove(w4, LINES / 8, 1);
4434 waddstr(w4, mod[itmp]);
4435 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4436 wmove(w5, LINES / 6, 1);
4437 waddstr(w5, mod[itmp]);
4439 wait_a_while(nap_msec);
4442 wmove(w4, LINES / 6, 1);
4443 waddstr(w4, mod[itmp]);
4444 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4445 wmove(w5, LINES / 8, 1);
4446 waddstr(w5, mod[itmp]);
4448 wait_a_while(nap_msec);
4452 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4454 wait_a_while(nap_msec);
4456 canned_panel(px, "t5");
4457 canned_panel(px, "t2");
4458 canned_panel(px, "t1");
4459 canned_panel(px, "d2");
4460 canned_panel(px, "h3");
4461 canned_panel(px, "d1");
4462 canned_panel(px, "d4");
4463 canned_panel(px, "d5");
4464 canned_panel(px, "d3");
4466 wait_a_while(nap_msec);
4475 #endif /* USE_LIBPANEL */
4477 /****************************************************************************
4481 ****************************************************************************/
4485 static bool pending_pan = FALSE;
4486 static bool show_panner_legend = TRUE;
4489 panner_legend(int line)
4491 static const char *const legend[] =
4493 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4494 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4495 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4496 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4498 int n = ((int) SIZEOF(legend) - (LINES - line));
4499 if (line < LINES && (n >= 0)) {
4501 if (show_panner_legend)
4502 printw("%s", legend[n]);
4504 return show_panner_legend;
4510 panner_h_cleanup(int from_y, int from_x, int to_x)
4512 if (!panner_legend(from_y))
4513 do_h_line(from_y, from_x, ' ', to_x);
4517 panner_v_cleanup(int from_y, int from_x, int to_y)
4519 if (!panner_legend(from_y))
4520 do_v_line(from_y, from_x, ' ', to_y);
4524 fill_pad(WINDOW *panpad, bool pan_lines)
4527 unsigned gridcount = 0;
4529 wmove(panpad, 0, 0);
4530 for (y = 0; y < getmaxy(panpad); y++) {
4531 for (x = 0; x < getmaxx(panpad); x++) {
4532 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4533 if (y == 0 && x == 0)
4534 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4536 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4537 else if (y == 0 || x == 0)
4538 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4540 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4541 (int) (gridcount++ % 26)));
4542 } else if (y % GRIDSIZE == 0)
4543 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4544 else if (x % GRIDSIZE == 0)
4545 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4547 waddch(panpad, ' ');
4554 int top_x, int top_y, int porty, int portx,
4555 int (*pgetc) (WINDOW *))
4557 #if HAVE_GETTIMEOFDAY
4558 struct timeval before, after;
4561 bool pan_lines = FALSE;
4562 bool scrollers = TRUE;
4565 int pxmax, pymax, lowend, highend, c;
4567 getmaxyx(pad, pymax, pxmax);
4568 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4572 #ifdef NCURSES_VERSION
4574 * During shell-out, the user may have resized the window. Adjust
4575 * the port size of the pad to accommodate this. Ncurses automatically
4576 * resizes all of the normal windows to fit on the new screen.
4594 show_panner_legend = !show_panner_legend;
4595 panner_legend(LINES - 4);
4596 panner_legend(LINES - 3);
4597 panner_legend(LINES - 2);
4598 panner_legend(LINES - 1);
4601 pan_lines = !pan_lines;
4602 fill_pad(pad, pan_lines);
4603 pending_pan = FALSE;
4606 #if HAVE_GETTIMEOFDAY
4610 panner_legend(LINES - 1);
4614 scrollers = !scrollers;
4617 /* Move the top-left corner of the pad, keeping the bottom-right
4620 case 'h': /* increase-columns: move left edge to left */
4624 panner_v_cleanup(top_y, top_x, porty);
4629 case 'j': /* decrease-lines: move top-edge down */
4633 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
4638 case 'k': /* increase-lines: move top-edge up */
4643 panner_h_cleanup(top_y, top_x, portx);
4647 case 'l': /* decrease-columns: move left-edge to right */
4651 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
4656 /* Move the bottom-right corner of the pad, keeping the top-left
4659 case KEY_IC: /* increase-columns: move right-edge to right */
4660 if (portx >= pxmax || portx >= COLS)
4663 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
4668 case KEY_IL: /* increase-lines: move bottom-edge down */
4669 if (porty >= pymax || porty >= LINES)
4672 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
4677 case KEY_DC: /* decrease-columns: move bottom edge up */
4682 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
4686 case KEY_DL: /* decrease-lines */
4691 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
4695 case KEY_LEFT: /* pan leftwards */
4702 case KEY_RIGHT: /* pan rightwards */
4703 if (basex + portx - (pymax > porty) < pxmax)
4709 case KEY_UP: /* pan upwards */
4716 case KEY_DOWN: /* pan downwards */
4717 if (basey + porty - (pxmax > portx) < pymax)
4732 basey = pymax - porty;
4742 mvaddch(top_y - 1, top_x - 1, ACS_ULCORNER);
4743 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
4744 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
4746 if (scrollers && (pxmax > portx - 1)) {
4747 int length = (portx - top_x - 1);
4748 float ratio = ((float) length) / ((float) pxmax);
4750 lowend = (int) ((float) top_x + ((float) basex * ratio));
4751 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
4753 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
4754 if (highend < portx) {
4756 do_h_line(porty - 1, lowend, ' ', highend + 1);
4758 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
4761 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
4763 if (scrollers && (pymax > porty - 1)) {
4764 int length = (porty - top_y - 1);
4765 float ratio = ((float) length) / ((float) pymax);
4767 lowend = (int) ((float) top_y + ((float) basey * ratio));
4768 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
4770 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
4771 if (highend < porty) {
4773 do_v_line(lowend, portx - 1, ' ', highend + 1);
4775 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
4778 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
4780 mvaddch(top_y - 1, portx - 1, ACS_URCORNER);
4781 mvaddch(porty - 1, top_x - 1, ACS_LLCORNER);
4782 mvaddch(porty - 1, portx - 1, ACS_LRCORNER);
4785 #if HAVE_GETTIMEOFDAY
4786 gettimeofday(&before, 0);
4788 wnoutrefresh(stdscr);
4793 porty - (pxmax > portx) - 1,
4794 portx - (pymax > porty) - 1);
4797 #if HAVE_GETTIMEOFDAY
4800 gettimeofday(&after, 0);
4801 elapsed = (after.tv_sec + after.tv_usec / 1.0e6)
4802 - (before.tv_sec + before.tv_usec / 1.0e6);
4803 move(LINES - 1, COLS - 12);
4804 printw("Secs: %2.03f", elapsed);
4811 ((c = pgetc(pad)) != KEY_EXIT);
4813 scrollok(stdscr, TRUE); /* reset to driver's default */
4817 padgetch(WINDOW *win)
4823 if ((pending_pan = (count > 0)) != FALSE) {
4825 pending_pan = (count != 0);
4828 switch (c = wGetchar(win)) {
4864 case ERR: /* FALLTHRU */
4870 if (c >= '0' && c <= '9') {
4871 count = count * 10 + (c - '0');
4885 #define PAD_HIGH 200
4886 #define PAD_WIDE 200
4890 /* Demonstrate pads. */
4892 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
4895 Cannot("cannot create requested pad");
4899 fill_pad(panpad, FALSE);
4901 panner_legend(LINES - 4);
4902 panner_legend(LINES - 3);
4903 panner_legend(LINES - 2);
4904 panner_legend(LINES - 1);
4906 keypad(panpad, TRUE);
4908 /* Make the pad (initially) narrow enough that a trace file won't wrap.
4909 * We'll still be able to widen it during a test, since that's required
4910 * for testing boundaries.
4912 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
4919 /****************************************************************************
4921 * Tests from John Burnell's PDCurses tester
4923 ****************************************************************************/
4926 Continue(WINDOW *win)
4930 mvwaddstr(win, 10, 1, " Press any key to continue");
4936 flushinp_test(WINDOW *win)
4937 /* Input test, adapted from John Burnell's PDCurses tester */
4939 int w, h, bx, by, sw, sh, i;
4944 getmaxyx(win, h, w);
4945 getbegyx(win, by, bx);
4948 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
4953 init_pair(2, COLOR_CYAN, COLOR_BLUE);
4954 wbkgd(subWin, COLOR_PAIR(2) | ' ');
4957 wattrset(subWin, A_BOLD);
4958 box(subWin, ACS_VLINE, ACS_HLINE);
4959 mvwaddstr(subWin, 2, 1, "This is a subwindow");
4963 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
4964 * it only happened to "work" on SVr4 because that implementation does not
4965 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
4966 * test behavior, we're using 'cbreak()', which will allow a single
4967 * character to return without needing a newline. - T.Dickey 1997/10/11.
4970 mvwaddstr(win, 0, 1, "This is a test of the flushinp() call.");
4972 mvwaddstr(win, 2, 1, "Type random keys for 5 seconds.");
4973 mvwaddstr(win, 3, 1,
4974 "These should be discarded (not echoed) after the subwindow goes away.");
4977 for (i = 0; i < 5; i++) {
4978 mvwprintw(subWin, 1, 1, "Time = %d", i);
4990 mvwaddstr(win, 2, 1,
4991 "If you were still typing when the window timer expired,");
4992 mvwaddstr(win, 3, 1,
4993 "or else you typed nothing at all while it was running,");
4994 mvwaddstr(win, 4, 1,
4995 "test was invalid. You'll see garbage or nothing at all. ");
4996 mvwaddstr(win, 6, 1, "Press a key");
5002 mvwaddstr(win, 12, 0,
5003 "If you see any key other than what you typed, flushinp() is broken.");
5012 "What you typed should now have been deleted; if not, wdelch() failed.");
5018 /****************************************************************************
5022 ****************************************************************************/
5030 menu_virtualize(int c)
5032 if (c == '\n' || c == KEY_EXIT)
5033 return (MAX_COMMAND + 1);
5035 return (REQ_SCR_ULINE);
5037 return (REQ_SCR_DLINE);
5038 else if (c == 'b' || c == KEY_NPAGE)
5039 return (REQ_SCR_UPAGE);
5040 else if (c == 'f' || c == KEY_PPAGE)
5041 return (REQ_SCR_DPAGE);
5042 else if (c == 'n' || c == KEY_DOWN)
5043 return (REQ_NEXT_ITEM);
5044 else if (c == 'p' || c == KEY_UP)
5045 return (REQ_PREV_ITEM);
5047 return (REQ_TOGGLE_ITEM);
5055 static CONST_MENUS char *animals[] =
5068 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5069 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5077 ITEM *items[SIZEOF(animals)];
5079 CONST_MENUS char **ap;
5080 int mrows, mcols, c;
5083 #ifdef NCURSES_MOUSE_VERSION
5084 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5086 mvaddstr(0, 0, "This is the menu test:");
5087 mvaddstr(2, 0, " Use up and down arrow to move the select bar.");
5088 mvaddstr(3, 0, " 'n' and 'p' act like arrows.");
5090 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
5091 mvaddstr(5, 0, " Press return to exit.");
5094 for (ap = animals; *ap; ap++) {
5095 if ((*ip = new_item(*ap, "")) != 0)
5100 m = new_menu(items);
5102 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
5103 scale_menu(m, &mrows, &mcols);
5105 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5106 set_menu_win(m, menuwin);
5107 keypad(menuwin, TRUE);
5110 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5114 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
5115 if (c == E_NOT_POSTED)
5117 if (c == E_REQUEST_DENIED)
5122 (void) mvprintw(LINES - 2, 0,
5123 "You chose: %s\n", item_name(current_item(m)));
5124 (void) addstr("Press any key to continue...");
5131 for (ip = items; *ip; ip++)
5133 #ifdef NCURSES_MOUSE_VERSION
5134 mousemask(0, (mmask_t *) 0);
5139 #define T_TBL(name) { #name, name }
5145 T_TBL(TRACE_DISABLE),
5148 T_TBL(TRACE_UPDATE),
5150 T_TBL(TRACE_CHARPUT),
5151 T_TBL(TRACE_ORDINARY),
5153 T_TBL(TRACE_VIRTPUT),
5154 T_TBL(TRACE_IEVENT),
5156 T_TBL(TRACE_ICALLS),
5157 T_TBL(TRACE_CCALLS),
5158 T_TBL(TRACE_DATABASE),
5160 T_TBL(TRACE_MAXIMUM),
5167 tracetrace(unsigned tlevel)
5174 for (n = 0; t_tbl[n].name != 0; n++)
5175 need += strlen(t_tbl[n].name) + 2;
5176 buf = typeMalloc(char, need);
5178 sprintf(buf, "0x%02x = {", tlevel);
5180 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5182 for (n = 1; t_tbl[n].name != 0; n++)
5183 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5184 strcat(buf, t_tbl[n].name);
5188 if (buf[strlen(buf) - 2] == ',')
5189 buf[strlen(buf) - 2] = '\0';
5190 return (strcat(buf, "}"));
5193 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5197 run_trace_menu(MENU * m)
5203 bool changed = FALSE;
5204 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5205 case E_UNKNOWN_COMMAND:
5208 items = menu_items(m);
5209 i = current_item(m);
5210 if (i == items[0]) {
5211 if (item_value(i)) {
5212 for (p = items + 1; *p != 0; p++)
5213 if (item_value(*p)) {
5214 set_item_value(*p, FALSE);
5219 for (p = items + 1; *p != 0; p++)
5220 if (item_value(*p)) {
5221 set_item_value(items[0], FALSE);
5234 /* interactively set the trace level */
5237 ITEM *items[SIZEOF(t_tbl)];
5244 mvaddstr(0, 0, "Interactively set trace level:");
5245 mvaddstr(2, 0, " Press space bar to toggle a selection.");
5246 mvaddstr(3, 0, " Use up and down arrow to move the select bar.");
5247 mvaddstr(4, 0, " Press return to set the trace level.");
5248 mvprintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5252 for (n = 0; t_tbl[n].name != 0; n++) {
5253 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
5259 m = new_menu(items);
5261 set_menu_format(m, 0, 2);
5262 scale_menu(m, &mrows, &mcols);
5264 menu_opts_off(m, O_ONEVALUE);
5265 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5266 set_menu_win(m, menuwin);
5267 keypad(menuwin, TRUE);
5270 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5274 for (ip = menu_items(m); *ip; ip++) {
5275 unsigned mask = t_tbl[item_index(*ip)].mask;
5277 set_item_value(*ip, _nc_tracing == 0);
5278 else if ((mask & _nc_tracing) == mask)
5279 set_item_value(*ip, TRUE);
5282 while (run_trace_menu(m))
5286 for (ip = menu_items(m); *ip; ip++)
5287 if (item_value(*ip))
5288 newtrace |= t_tbl[item_index(*ip)].mask;
5290 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5292 (void) mvprintw(LINES - 2, 0,
5293 "Trace level is %s\n", tracetrace(_nc_tracing));
5294 (void) addstr("Press any key to continue...");
5301 for (ip = items; *ip; ip++)
5305 #endif /* USE_LIBMENU */
5307 /****************************************************************************
5311 ****************************************************************************/
5314 make_label(int frow, int fcol, NCURSES_CONST char *label)
5316 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5319 set_field_buffer(f, 0, label);
5320 set_field_opts(f, (int) (field_opts(f) & ~O_ACTIVE));
5326 make_field(int frow, int fcol, int rows, int cols, bool secure)
5328 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5331 set_field_back(f, A_UNDERLINE);
5332 set_field_userptr(f, (void *) 0);
5338 display_form(FORM * f)
5343 scale_form(f, &rows, &cols);
5345 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5347 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5352 if (post_form(f) != E_OK)
5357 erase_form(FORM * f)
5359 WINDOW *w = form_win(f);
5360 WINDOW *s = form_sub(f);
5370 edit_secure(FIELD * me, int c)
5372 int rows, cols, frow, fcol, nrow, nbuf;
5374 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5376 char *source = field_buffer(me, 1);
5380 strcpy(temp, source ? source : "");
5381 len = (long) (char *) field_userptr(me);
5383 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5384 temp[len++] = (char) c;
5386 set_field_buffer(me, 1, temp);
5406 case REQ_RIGHT_CHAR:
5408 c = 0; /* we don't want to do inline editing */
5413 set_field_buffer(me, 1, temp);
5420 set_field_buffer(me, 1, temp);
5425 set_field_userptr(me, (void *) len);
5431 form_virtualize(FORM * f, WINDOW *w)
5434 static const struct {
5438 { CTRL('A'), REQ_NEXT_CHOICE },
5439 { CTRL('B'), REQ_PREV_WORD },
5440 { CTRL('C'), REQ_CLR_EOL },
5441 { CTRL('D'), REQ_DOWN_FIELD },
5442 { CTRL('E'), REQ_END_FIELD },
5443 { CTRL('F'), REQ_NEXT_PAGE },
5444 { CTRL('G'), REQ_DEL_WORD },
5445 { CTRL('H'), REQ_DEL_PREV },
5446 { CTRL('I'), REQ_INS_CHAR },
5447 { CTRL('K'), REQ_CLR_EOF },
5448 { CTRL('L'), REQ_LEFT_FIELD },
5449 { CTRL('M'), REQ_NEW_LINE },
5450 { CTRL('N'), REQ_NEXT_FIELD },
5451 { CTRL('O'), REQ_INS_LINE },
5452 { CTRL('P'), REQ_PREV_FIELD },
5453 { CTRL('R'), REQ_RIGHT_FIELD },
5454 { CTRL('S'), REQ_BEG_FIELD },
5455 { CTRL('U'), REQ_UP_FIELD },
5456 { CTRL('V'), REQ_DEL_CHAR },
5457 { CTRL('W'), REQ_NEXT_WORD },
5458 { CTRL('X'), REQ_CLR_FIELD },
5459 { CTRL('Y'), REQ_DEL_LINE },
5460 { CTRL('Z'), REQ_PREV_CHOICE },
5461 { ESCAPE, MAX_FORM_COMMAND + 1 },
5462 { KEY_BACKSPACE, REQ_DEL_PREV },
5463 { KEY_DOWN, REQ_DOWN_CHAR },
5464 { KEY_END, REQ_LAST_FIELD },
5465 { KEY_HOME, REQ_FIRST_FIELD },
5466 { KEY_LEFT, REQ_LEFT_CHAR },
5467 { KEY_LL, REQ_LAST_FIELD },
5468 { KEY_NEXT, REQ_NEXT_FIELD },
5469 { KEY_NPAGE, REQ_NEXT_PAGE },
5470 { KEY_PPAGE, REQ_PREV_PAGE },
5471 { KEY_PREVIOUS, REQ_PREV_FIELD },
5472 { KEY_RIGHT, REQ_RIGHT_CHAR },
5473 { KEY_UP, REQ_UP_CHAR },
5474 { QUIT, MAX_FORM_COMMAND + 1 }
5478 static int mode = REQ_INS_MODE;
5479 int c = wGetchar(w);
5481 FIELD *me = current_field(f);
5482 bool current = TRUE;
5484 if (c == CTRL(']')) {
5485 if (mode == REQ_INS_MODE) {
5486 mode = REQ_OVL_MODE;
5488 mode = REQ_INS_MODE;
5492 for (n = 0; n < SIZEOF(lookup); n++) {
5493 if (lookup[n].code == c) {
5494 c = lookup[n].result;
5499 mvprintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5502 * Force the field that the user is typing into to be in reverse video,
5503 * while the other fields are shown underlined.
5518 case REQ_LEFT_FIELD:
5520 case REQ_RIGHT_CHAR:
5524 current = (c < KEY_MAX);
5528 c = edit_secure(me, c);
5529 set_field_back(me, A_REVERSE);
5531 c = edit_secure(me, c);
5532 set_field_back(me, A_UNDERLINE);
5538 my_form_driver(FORM * form, int c)
5540 if (c == (MAX_FORM_COMMAND + 1)
5541 && form_driver(form, REQ_VALIDATION) == E_OK)
5549 #ifdef NCURSES_VERSION
5550 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5551 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5553 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5554 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5558 * Allow a middle initial, optionally with a '.' to end it.
5561 FIELDCHECK_CB(mi_field_check)
5563 char *s = field_buffer(fld, 0);
5567 for (n = 0; s[n] != '\0'; ++n) {
5574 } else if (isspace(UChar(s[n]))) {
5579 if (!isspace(UChar(s[n])))
5585 /* force the form to display a leading capital */
5586 if (islower(UChar(s[0]))) {
5587 s[0] = (char) toupper(UChar(s[0]));
5588 set_field_buffer(fld, 0, s);
5594 CHAR_CHECK_CB(mi_char_check)
5596 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5600 * Passwords should be at least 6 characters.
5603 FIELDCHECK_CB(pw_field_check)
5605 char *s = field_buffer(fld, 0);
5608 for (n = 0; s[n] != '\0'; ++n) {
5609 if (isspace(UChar(s[n]))) {
5618 CHAR_CHECK_CB(pw_char_check)
5620 return (isgraph(ch) ? TRUE : FALSE);
5628 FIELD *f[12], *secure;
5629 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
5630 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
5631 int finished = 0, c;
5634 #ifdef NCURSES_MOUSE_VERSION
5635 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5639 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
5640 addstr("^N -- go to next field ^P -- go to previous field\n");
5641 addstr("Home -- go to first field End -- go to last field\n");
5642 addstr("^L -- go to field to left ^R -- go to field to right\n");
5643 addstr("^U -- move upward to field ^D -- move downward to field\n");
5644 addstr("^W -- go to next word ^B -- go to previous word\n");
5645 addstr("^S -- go to start of field ^E -- go to end of field\n");
5646 addstr("^H -- delete previous char ^Y -- delete line\n");
5647 addstr("^G -- delete current word ^C -- clear to end of line\n");
5648 addstr("^K -- clear to end of field ^X -- clear field\n");
5649 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
5651 mvaddstr(4, 57, "Forms Entry Test");
5655 /* describe the form */
5656 memset(f, 0, sizeof(f));
5657 f[n++] = make_label(0, 15, "Sample Form");
5659 f[n++] = make_label(2, 0, "Last Name");
5660 f[n++] = make_field(3, 0, 1, 18, FALSE);
5661 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5663 f[n++] = make_label(2, 20, "First Name");
5664 f[n++] = make_field(3, 20, 1, 12, FALSE);
5665 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5667 f[n++] = make_label(2, 34, "Middle Name");
5668 f[n++] = make_field(3, 34, 1, 12, FALSE);
5669 set_field_type(f[n - 1], fty_middle);
5671 f[n++] = make_label(5, 0, "Comments");
5672 f[n++] = make_field(6, 0, 4, 46, FALSE);
5674 f[n++] = make_label(5, 20, "Password:");
5676 f[n++] = make_field(5, 30, 1, 9, TRUE);
5677 set_field_type(f[n - 1], fty_passwd);
5678 f[n++] = (FIELD *) 0;
5680 if ((form = new_form(f)) != 0) {
5686 nonl(); /* lets us read ^M's */
5688 switch (form_driver(form, c = form_virtualize(form, w))) {
5690 mvaddstr(5, 57, field_buffer(secure, 1));
5694 case E_UNKNOWN_COMMAND:
5695 finished = my_form_driver(form, c);
5707 for (c = 0; f[c] != 0; c++)
5709 free_fieldtype(fty_middle);
5710 free_fieldtype(fty_passwd);
5714 #ifdef NCURSES_MOUSE_VERSION
5715 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5718 #endif /* USE_LIBFORM */
5720 /****************************************************************************
5724 ****************************************************************************/
5727 fillwin(WINDOW *win, char ch)
5732 getmaxyx(win, y1, x1);
5733 for (y = 0; y < y1; y++) {
5735 for (x = 0; x < x1; x++)
5736 waddch(win, UChar(ch));
5741 crosswin(WINDOW *win, char ch)
5746 getmaxyx(win, y1, x1);
5747 for (y = 0; y < y1; y++) {
5748 for (x = 0; x < x1; x++)
5749 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
5750 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
5752 waddch(win, UChar(ch));
5757 #define OVERLAP_FLAVORS 5
5760 overlap_helpitem(int state, int item, char *message)
5762 int row = (item / 2);
5763 int col = ((item % 2) ? COLS / 2 : 0);
5765 move(LINES - 6 + row, col);
5766 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
5771 overlap_test_1_attr(WINDOW *win, int flavor, int col)
5773 short cpair = (short) (1 + (flavor * 2) + col);
5777 wattrset(win, A_NORMAL);
5780 wattrset(win, A_BOLD);
5783 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
5784 wattrset(win, COLOR_PAIR(cpair) | A_NORMAL);
5787 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
5788 wattrset(win, COLOR_PAIR(cpair) | A_BOLD);
5794 overlap_test_2_attr(WINDOW *win, int flavor, int col)
5796 short cpair = (short) (9 + (flavor * 2) + col);
5806 init_pair(cpair, COLOR_RED, COLOR_GREEN);
5807 wbkgdset(win, ' ' | A_BLINK | COLOR_PAIR(cpair));
5810 wbkgdset(win, ' ' | A_NORMAL);
5816 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
5821 const char *ths, *tht;
5825 state += OVERLAP_FLAVORS;
5826 state = state % OVERLAP_FLAVORS;
5827 assert(state >= 0 && state < OVERLAP_FLAVORS);
5829 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
5832 ths = col ? "B" : "A";
5833 tht = col ? "A" : "B";
5838 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
5846 overlap_test_1_attr(stdscr, flavors[row], col);
5847 sprintf(msg, "fill window %s with letter %s.", ths, ths);
5855 switch (flavors[row]) {
5857 sprintf(msg, "cross pattern in window %s.", ths);
5860 sprintf(msg, "draw box in window %s.", ths);
5863 sprintf(msg, "set background of window %s.", ths);
5866 sprintf(msg, "reset background of window %s.", ths);
5872 sprintf(msg, "clear window %s.", ths);
5876 switch (flavors[row]) {
5878 sprintf(msg, "overwrite %s onto %s.", ths, tht);
5881 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
5884 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
5887 sprintf(msg, "overlay %s onto %s.", ths, tht);
5892 overlap_helpitem(state, item, msg);
5893 wattrset(stdscr, A_NORMAL);
5894 wbkgdset(stdscr, ' ' | A_NORMAL);
5897 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
5898 state, flavors[state]);
5904 overlap_test_0(WINDOW *a, WINDOW *b)
5914 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
5916 overlap_test_1_attr(a, flavor, col);
5918 wattrset(a, A_NORMAL);
5922 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
5924 overlap_test_2_attr(a, flavor, col);
5933 /* done in overlap_test_2_attr */
5936 /* done in overlap_test_2_attr */
5942 overlap_test_3(WINDOW *a)
5949 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
5956 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
5959 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
5967 /* test effects of overlapping windows */
5972 int state, flavor[OVERLAP_FLAVORS];
5974 WINDOW *win1 = newwin(9, 20, 3, 3);
5975 WINDOW *win2 = newwin(9, 20, 9, 16);
5981 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
5982 printw("the shared region of two overlapping windows A and B. The cross\n");
5983 printw("pattern in each window does not overlap the other.\n");
5985 memset(flavor, 0, sizeof(flavor));
5986 state = overlap_help(0, flavor);
5988 while (!isQuit(ch = Getchar()))
5990 case 'a': /* refresh window A first, then B */
5991 overlap_test_0(win1, win2);
5994 case 'b': /* refresh window B first, then A */
5995 overlap_test_0(win2, win1);
5998 case 'c': /* fill window A so it's visible */
5999 overlap_test_1(flavor[1], 0, win1, 'A');
6002 case 'd': /* fill window B so it's visible */
6003 overlap_test_1(flavor[1], 1, win2, 'B');
6006 case 'e': /* cross test pattern in window A */
6007 overlap_test_2(flavor[2], 0, win1, 'A');
6010 case 'f': /* cross test pattern in window A */
6011 overlap_test_2(flavor[2], 1, win2, 'B');
6014 case 'g': /* clear window A */
6015 overlap_test_3(win1);
6018 case 'h': /* clear window B */
6019 overlap_test_3(win2);
6022 case 'i': /* overwrite A onto B */
6023 overlap_test_4(flavor[4], win1, win2);
6026 case 'j': /* overwrite B onto A */
6027 overlap_test_4(flavor[4], win2, win1);
6032 state = overlap_help(state + 1, flavor);
6037 state = overlap_help(state - 1, flavor);
6042 state = overlap_help(state, flavor);
6046 state = overlap_help(state, flavor);
6061 /****************************************************************************
6065 ****************************************************************************/
6068 do_single_test(const char c)
6069 /* perform a single specified test */
6076 #if USE_WIDEC_SUPPORT
6086 #if USE_WIDEC_SUPPORT
6094 Cannot("does not support color.");
6099 #if USE_WIDEC_SUPPORT
6102 Cannot("does not support color.");
6110 Cannot("does not support color.");
6111 else if (!can_change_color())
6112 Cannot("has hardwired color values.");
6123 #if USE_WIDEC_SUPPORT
6132 #if USE_WIDEC_SUPPORT
6140 demo_panels(init_panel, fill_panel);
6144 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6146 demo_panels(init_wide_panel, fill_wide_panel);
6155 flushinp_test(stdscr);
6159 test_sgr_attributes();
6182 #if USE_LIBMENU && defined(TRACE)
6201 static const char *const tbl[] =
6203 "Usage: ncurses [options]"
6206 #ifdef NCURSES_VERSION
6207 ," -a f,b set default-colors (assumed white-on-black)"
6208 ," -d use default-colors if terminal supports them"
6211 ," -e fmt specify format for soft-keys test (e)"
6214 ," -f rip-off footer line (can repeat)"
6215 ," -h rip-off header line (can repeat)"
6217 ," -m do not use colors"
6218 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6220 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6223 ," -t mask specify default trace-level (may toggle with ^T)"
6227 for (n = 0; n < SIZEOF(tbl); n++)
6228 fprintf(stderr, "%s\n", tbl[n]);
6229 ExitProgram(EXIT_FAILURE);
6233 set_terminal_modes(void)
6238 scrollok(stdscr, TRUE);
6239 idlok(stdscr, TRUE);
6240 keypad(stdscr, TRUE);
6245 announce_sig(int sig)
6247 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6253 rip_footer(WINDOW *win, int cols)
6255 wbkgd(win, A_REVERSE);
6258 wprintw(win, "footer: window %p, %d columns", win, cols);
6264 rip_header(WINDOW *win, int cols)
6266 wbkgd(win, A_REVERSE);
6269 wprintw(win, "header: window %p, %d columns", win, cols);
6273 #endif /* HAVE_RIPOFFLINE */
6281 (void) puts("This is the ncurses main menu");
6282 (void) puts("a = keyboard and mouse input test");
6283 #if USE_WIDEC_SUPPORT
6284 (void) puts("A = wide-character keyboard and mouse input test");
6286 (void) puts("b = character attribute test");
6287 #if USE_WIDEC_SUPPORT
6288 (void) puts("B = wide-character attribute test");
6290 (void) puts("c = color test pattern");
6291 #if USE_WIDEC_SUPPORT
6292 (void) puts("C = color test pattern using wide-character calls");
6295 (void) puts("d = edit RGB color values");
6297 (void) puts("e = exercise soft keys");
6298 #if USE_WIDEC_SUPPORT
6299 (void) puts("E = exercise soft keys using wide-characters");
6302 (void) puts("f = display ACS characters");
6303 #if USE_WIDEC_SUPPORT
6304 (void) puts("F = display Wide-ACS characters");
6306 (void) puts("g = display windows and scrolling");
6307 (void) puts("i = test of flushinp()");
6308 (void) puts("k = display character attributes");
6310 (void) puts("m = menu code test");
6313 (void) puts("o = exercise panels library");
6314 #if USE_WIDEC_SUPPORT
6315 (void) puts("O = exercise panels with wide-characters");
6318 (void) puts("p = exercise pad features");
6319 (void) puts("q = quit");
6321 (void) puts("r = exercise forms code");
6323 (void) puts("s = overlapping-refresh test");
6324 #if USE_LIBMENU && defined(TRACE)
6325 (void) puts("t = set trace level");
6327 (void) puts("? = repeat this command summary");
6329 (void) fputs("> ", stdout);
6330 (void) fflush(stdout); /* necessary under SVr4 curses */
6333 * This used to be an 'fgets()' call. However (on Linux, at least)
6334 * mixing stream I/O and 'read()' (used in the library) causes the
6335 * input stream to be flushed when switching between the two.
6340 if (read(fileno(stdin), &ch, 1) <= 0) {
6344 } else if (command == 0 && !isspace(UChar(ch))) {
6346 } else if (ch == '\n' || ch == '\r') {
6347 if ((command == 'd') && !top) {
6348 (void) fputs("Do not nest test-d\n", stdout);
6353 (void) fputs("> ", stdout);
6354 (void) fflush(stdout);
6358 if (do_single_test(command)) {
6360 * This may be overkill; it's intended to reset everything back
6361 * to the initial terminal modes so that tests don't get in
6365 set_terminal_modes();
6370 if (command == '?') {
6371 (void) puts("This is the ncurses capability tester.");
6373 puts("You may select a test from the main menu by typing the");
6375 puts("key letter of the choice (the letter to left of the =)");
6377 puts("at the > prompt. Type `q' to exit.");
6385 /*+-------------------------------------------------------------------------
6387 --------------------------------------------------------------------------*/
6389 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6390 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6393 main(int argc, char *argv[])
6397 #ifdef NCURSES_VERSION
6398 int default_fg = COLOR_WHITE;
6399 int default_bg = COLOR_BLACK;
6400 bool assumed_colors = FALSE;
6401 bool default_colors = FALSE;
6403 char *palette_file = 0;
6404 bool monochrome = FALSE;
6406 setlocale(LC_ALL, "");
6408 while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) {
6410 #ifdef NCURSES_VERSION
6412 assumed_colors = TRUE;
6413 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6416 default_colors = TRUE;
6420 my_e_param = atoi(optarg);
6421 #ifdef NCURSES_VERSION
6422 if (my_e_param > 3) /* allow extended layouts */
6431 ripoffline(-1, rip_footer);
6434 ripoffline(1, rip_header);
6436 #endif /* HAVE_RIPOFFLINE */
6441 palette_file = optarg;
6445 nap_msec = atol(optarg);
6450 save_trace = (unsigned) strtol(optarg, 0, 0);
6459 * If there's no menus (unlikely for ncurses!), then we'll have to set
6460 * tracing on initially, just in case the user wants to test something that
6461 * doesn't involve wGetchar.
6464 /* enable debugging */
6468 if (!isatty(fileno(stdin)))
6470 #endif /* USE_LIBMENU */
6474 /* tell it we're going to play with soft keys */
6475 slk_init(my_e_param);
6479 /* set up null signal catcher so we can see what interrupts to getch do */
6480 signal(SIGUSR1, announce_sig);
6483 /* we must initialize the curses data structure only once */
6487 /* tests, in general, will want these modes */
6488 use_colors = monochrome ? FALSE : has_colors();
6492 #ifdef NCURSES_VERSION_PATCH
6493 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6494 #if HAVE_USE_DEFAULT_COLORS
6495 if (default_colors) {
6496 use_default_colors();
6499 #if NCURSES_VERSION_PATCH >= 20000708
6500 else if (assumed_colors)
6501 assume_default_colors(default_fg, default_bg);
6504 #else /* normal SVr4 curses */
6505 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6507 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6509 if (can_change_color()) {
6511 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
6512 for (cp = 0; cp < max_colors; ++cp) {
6514 &all_colors[cp].red,
6515 &all_colors[cp].green,
6516 &all_colors[cp].blue);
6518 if (palette_file != 0) {
6519 FILE *fp = fopen(palette_file, "r");
6521 char buffer[BUFSIZ];
6522 int red, green, blue;
6524 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6525 if (sscanf(buffer, "scale:%d", &c) == 1) {
6527 } else if (sscanf(buffer, "%d:%d %d %d",
6536 all_colors[c].red = (short) ((red * 1000) / scale);
6537 all_colors[c].green = (short) ((green * 1000) / scale);
6538 all_colors[c].blue = (short) ((blue * 1000) / scale);
6546 set_terminal_modes();
6550 * Return to terminal mode, so we're guaranteed of being able to
6551 * select terminal commands even if the capabilities are wrong.
6555 #if HAVE_CURSES_VERSION
6556 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6557 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6558 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6559 NCURSES_VERSION_MAJOR,
6560 NCURSES_VERSION_MINOR,
6561 NCURSES_VERSION_PATCH);
6563 (void) puts("Welcome to ncurses. Press ? for help.");
6568 ExitProgram(EXIT_SUCCESS);
6571 /* ncurses.c ends here */