1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 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.362 2010/11/14 01:04:13 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) init_mb(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) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(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) init_mb(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) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(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 (void) 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) {
323 make_fullwidth_digit(cchar_t *target, int digit)
327 source[0] = fullwidth_of(digit + '0');
329 setcchar(target, source, A_NORMAL, 0, 0);
334 wGet_wchar(WINDOW *win, wint_t *result)
338 while ((c = wget_wch(win, result)) == CTRL('T')) {
340 save_trace = _nc_tracing;
341 Trace(("TOGGLE-TRACING OFF"));
344 _nc_tracing = save_trace;
348 Trace(("TOGGLE-TRACING ON"));
351 c = wget_wch(win, result);
355 #define Get_wchar(result) wGet_wchar(stdscr, result)
357 /* replaces wgetn_wstr(), since we want to be able to edit values */
359 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
368 (void) wattrset(win, A_REVERSE);
370 x = (int) wcslen(buffer);
372 if (x > (int) wcslen(buffer))
373 x = (int) wcslen(buffer);
375 /* clear the "window' */
377 wprintw(win, "%*s", limit, " ");
379 /* write the existing buffer contents */
381 waddnwstr(win, buffer, limit);
383 /* positions the cursor past character 'x' */
385 waddnwstr(win, buffer, x);
387 switch (wGet_wchar(win, &ch)) {
427 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
447 } else if ((int) wcslen(buffer) < limit) {
449 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
450 buffer[j] = buffer[j - 1];
452 buffer[x++] = (wchar_t) ch;
459 wattroff(win, A_REVERSE);
470 addstr("Press any key to continue... ");
475 Cannot(const char *what)
477 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
482 ShellOut(bool message)
485 addstr("Shelling out...");
494 addstr("returned from shellout.\n");
498 #ifdef NCURSES_MOUSE_VERSION
500 * This function is the same as _tracemouse(), but we cannot count on that
501 * being available in the non-debug library.
504 mouse_decode(MEVENT const *ep)
506 static char buf[80 + (5 * 10) + (32 * 15)];
508 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
509 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
511 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
513 SHOW(BUTTON1_RELEASED, "release-1");
514 SHOW(BUTTON1_PRESSED, "press-1");
515 SHOW(BUTTON1_CLICKED, "click-1");
516 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
517 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
518 #if NCURSES_MOUSE_VERSION == 1
519 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
522 SHOW(BUTTON2_RELEASED, "release-2");
523 SHOW(BUTTON2_PRESSED, "press-2");
524 SHOW(BUTTON2_CLICKED, "click-2");
525 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
526 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
527 #if NCURSES_MOUSE_VERSION == 1
528 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
531 SHOW(BUTTON3_RELEASED, "release-3");
532 SHOW(BUTTON3_PRESSED, "press-3");
533 SHOW(BUTTON3_CLICKED, "click-3");
534 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
535 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
536 #if NCURSES_MOUSE_VERSION == 1
537 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
540 SHOW(BUTTON4_RELEASED, "release-4");
541 SHOW(BUTTON4_PRESSED, "press-4");
542 SHOW(BUTTON4_CLICKED, "click-4");
543 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
544 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
545 #if NCURSES_MOUSE_VERSION == 1
546 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
549 #if NCURSES_MOUSE_VERSION == 2
550 SHOW(BUTTON5_RELEASED, "release-5");
551 SHOW(BUTTON5_PRESSED, "press-5");
552 SHOW(BUTTON5_CLICKED, "click-5");
553 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
554 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
557 SHOW(BUTTON_CTRL, "ctrl");
558 SHOW(BUTTON_SHIFT, "shift");
559 SHOW(BUTTON_ALT, "alt");
560 SHOW(ALL_MOUSE_EVENTS, "all-events");
561 SHOW(REPORT_MOUSE_POSITION, "position");
565 if (buf[strlen(buf) - 1] == ' ')
566 buf[strlen(buf) - 2] = '\0';
567 (void) strcat(buf, "}");
572 show_mouse(WINDOW *win)
580 outside = !wenclose(win, event.y, event.x);
583 (void) wstandout(win);
584 waddstr(win, "KEY_MOUSE");
585 (void) wstandend(win);
587 waddstr(win, "KEY_MOUSE");
589 wprintw(win, ", %s", mouse_decode(&event));
594 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
598 wmove(win, event.y, event.x);
606 #endif /* NCURSES_MOUSE_VERSION */
608 /****************************************************************************
610 * Character input test
612 ****************************************************************************/
614 #define NUM_GETCH_FLAGS 256
615 typedef bool GetchFlags[NUM_GETCH_FLAGS];
618 setup_getch(WINDOW *win, GetchFlags flags)
620 keypad(win, flags['k']); /* should be redundant, but for testing */
621 meta(win, flags['m']); /* force this to a known state */
629 init_getch(WINDOW *win, GetchFlags flags)
631 memset(flags, FALSE, NUM_GETCH_FLAGS);
632 flags[UChar('k')] = (win == stdscr);
633 flags[UChar('m')] = TRUE;
635 setup_getch(win, flags);
639 wgetch_help(WINDOW *win, GetchFlags flags)
641 static const char *help[] =
643 "e -- toggle echo mode"
644 ,"g -- triggers a getstr test"
645 ,"k -- toggle keypad/literal mode"
646 ,"m -- toggle meta (7-bit/8-bit) mode"
649 ,"w -- create a new window"
651 ,"z -- suspend this process"
655 unsigned chk = ((SIZEOF(help) + 1) / 2);
660 printw("Type any key to see its %s value. Also:\n",
661 flags['k'] ? "keypad" : "literal");
662 for (n = 0; n < SIZEOF(help); ++n) {
663 int row = 1 + (int) (n % chk);
664 int col = (n >= chk) ? COLS / 2 : 0;
665 int flg = ((strstr(help[n], "toggle") != 0)
666 && (flags[UChar(*help[n])] != FALSE));
669 MvPrintw(row, col, "%s", help[n]);
680 wgetch_wrap(WINDOW *win, int first_y)
682 int last_y = getmaxy(win) - 1;
683 int y = getcury(win) + 1;
691 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
697 static WINSTACK *winstack = 0;
698 static unsigned len_winstack = 0;
711 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
713 unsigned need = (level + 1) * 2;
715 assert(level < (unsigned) COLS);
719 winstack = typeMalloc(WINSTACK, len_winstack);
720 } else if (need >= len_winstack) {
722 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
724 winstack[level].text = txt_win;
725 winstack[level].frame = box_win;
728 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
732 /* this chunk is now done in resize_term() */
739 #define slk_repaint() /* nothing */
743 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
744 * Resize both and paint the box in the parent.
747 resize_boxes(unsigned level, WINDOW *win)
751 int high = LINES - base;
755 wnoutrefresh(stdscr);
759 for (n = 0; n < level; ++n) {
760 wresize(winstack[n].frame, high, wide);
761 wresize(winstack[n].text, high - 2, wide - 2);
764 werase(winstack[n].text);
765 box(winstack[n].frame, 0, 0);
766 wnoutrefresh(winstack[n].frame);
767 wprintw(winstack[n].text,
769 getmaxy(winstack[n].text),
770 getmaxx(winstack[n].text));
771 wnoutrefresh(winstack[n].text);
772 if (winstack[n].text == win)
778 #define forget_boxes() /* nothing */
779 #define remember_boxes(level,text,frame) /* nothing */
783 wgetch_test(unsigned level, WINDOW *win, int delay)
786 int first_y, first_x;
790 bool blocking = (delay < 0);
792 init_getch(win, flags);
793 wtimeout(win, delay);
794 getyx(win, first_y, first_x);
796 wgetch_help(win, flags);
797 wsetscrreg(win, first_y, getmaxy(win) - 1);
801 while ((c = wGetchar(win)) == ERR) {
804 (void) wprintw(win, "%05d: input error", incount);
807 (void) wprintw(win, "%05d: input timed out", incount);
809 wgetch_wrap(win, first_y);
811 if (c == ERR && blocking) {
813 wgetch_wrap(win, first_y);
814 } else if (isQuit(c)) {
816 } else if (c == 'e') {
817 flags[UChar('e')] = !flags[UChar('e')];
818 setup_getch(win, flags);
819 wgetch_help(win, flags);
820 } else if (c == 'g') {
821 waddstr(win, "getstr test: ");
823 wgetnstr(win, buf, sizeof(buf) - 1);
825 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
827 wgetch_wrap(win, first_y);
828 } else if (c == 'k') {
829 flags[UChar('k')] = !flags[UChar('k')];
830 setup_getch(win, flags);
831 wgetch_help(win, flags);
832 } else if (c == 'm') {
833 flags[UChar('m')] = !flags[UChar('m')];
834 setup_getch(win, flags);
835 wgetch_help(win, flags);
836 } else if (c == 's') {
838 } else if (c == 'w') {
839 int high = getmaxy(win) - 1 - first_y + 1;
840 int wide = getmaxx(win) - first_x;
842 int new_y = first_y + getbegy(win);
843 int new_x = first_x + getbegx(win);
845 getyx(win, old_y, old_x);
846 if (high > 2 && wide > 2) {
847 WINDOW *wb = newwin(high, wide, new_y, new_x);
848 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
853 remember_boxes(level, wi, wb);
854 wgetch_test(level + 1, wi, delay);
858 wgetch_help(win, flags);
859 wmove(win, old_y, old_x);
865 } else if (c == 'z') {
866 kill(getpid(), SIGTSTP);
869 wprintw(win, "Key pressed: %04o ", c);
870 #ifdef NCURSES_MOUSE_VERSION
871 if (c == KEY_MOUSE) {
874 #endif /* NCURSES_MOUSE_VERSION */
876 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
877 if (c == KEY_RESIZE) {
878 resize_boxes(level, win);
881 (void) waddstr(win, keyname(c));
882 } else if (c >= 0x80) {
883 unsigned c2 = (unsigned) c;
884 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
885 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
889 (void) wprintw(win, "%c", UChar(c));
890 else if (c2 != UChar(c))
891 (void) wprintw(win, "M-%s", unctrl(c2));
893 (void) wprintw(win, "%s", unctrl(c2));
894 waddstr(win, " (high-half character)");
897 (void) wprintw(win, "%c (ASCII printable character)", c);
899 (void) wprintw(win, "%s (ASCII control character)",
902 wgetch_wrap(win, first_y);
909 init_getch(win, flags);
913 begin_getch_test(void)
920 #ifdef NCURSES_MOUSE_VERSION
921 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
924 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
926 getnstr(buf, sizeof(buf) - 1);
930 if (isdigit(UChar(buf[0]))) {
931 delay = atoi(buf) * 100;
941 finish_getch_test(void)
943 #ifdef NCURSES_MOUSE_VERSION
944 mousemask(0, (mmask_t *) 0);
955 int delay = begin_getch_test();
958 wgetch_test(0, stdscr, delay);
964 #if USE_WIDEC_SUPPORT
966 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
967 * Resize both and paint the box in the parent.
969 #if defined(KEY_RESIZE) && HAVE_WRESIZE
971 resize_wide_boxes(unsigned level, WINDOW *win)
975 int high = LINES - base;
979 wnoutrefresh(stdscr);
983 for (n = 0; n < level; ++n) {
984 wresize(winstack[n].frame, high, wide);
985 wresize(winstack[n].text, high - 2, wide - 2);
988 werase(winstack[n].text);
989 box_set(winstack[n].frame, 0, 0);
990 wnoutrefresh(winstack[n].frame);
991 wprintw(winstack[n].text,
993 getmaxy(winstack[n].text),
994 getmaxx(winstack[n].text));
995 wnoutrefresh(winstack[n].text);
996 if (winstack[n].text == win)
1001 #endif /* KEY_RESIZE */
1004 wcstos(const wchar_t *src)
1008 const wchar_t *tmp = src;
1009 #ifndef state_unused
1013 reset_wchars(state);
1014 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1015 unsigned have = (unsigned) need;
1016 if ((result = typeCalloc(char, have + 1)) != 0) {
1018 if (trans_wchars(result, tmp, have, &state) != have) {
1028 wget_wch_test(unsigned level, WINDOW *win, int delay)
1030 wchar_t wchar_buf[BUFSIZ];
1031 wint_t wint_buf[BUFSIZ];
1032 int first_y, first_x;
1036 bool blocking = (delay < 0);
1040 init_getch(win, flags);
1041 wtimeout(win, delay);
1042 getyx(win, first_y, first_x);
1044 wgetch_help(win, flags);
1045 wsetscrreg(win, first_y, getmaxy(win) - 1);
1046 scrollok(win, TRUE);
1049 while ((code = wGet_wchar(win, &c)) == ERR) {
1052 (void) wprintw(win, "%05d: input error", incount);
1055 (void) wprintw(win, "%05d: input timed out", incount);
1057 wgetch_wrap(win, first_y);
1059 if (code == ERR && blocking) {
1060 wprintw(win, "ERR");
1061 wgetch_wrap(win, first_y);
1062 } else if (isQuit((int) c)) {
1064 } else if (c == 'e') {
1065 flags[UChar('e')] = !flags[UChar('e')];
1066 setup_getch(win, flags);
1067 wgetch_help(win, flags);
1068 } else if (c == 'g') {
1069 waddstr(win, "getstr test: ");
1071 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1074 wprintw(win, "wgetn_wstr returns an error.");
1077 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1080 if ((temp = wcstos(wchar_buf)) != 0) {
1081 wprintw(win, "I saw %d characters:\n\t`%s'.",
1082 (int) wcslen(wchar_buf), temp);
1085 wprintw(win, "I saw %d characters (cannot convert).",
1086 (int) wcslen(wchar_buf));
1090 wgetch_wrap(win, first_y);
1091 } else if (c == 'k') {
1092 flags[UChar('k')] = !flags[UChar('k')];
1093 setup_getch(win, flags);
1094 wgetch_help(win, flags);
1095 } else if (c == 'm') {
1096 flags[UChar('m')] = !flags[UChar('m')];
1097 setup_getch(win, flags);
1098 wgetch_help(win, flags);
1099 } else if (c == 's') {
1101 } else if (c == 'w') {
1102 int high = getmaxy(win) - 1 - first_y + 1;
1103 int wide = getmaxx(win) - first_x;
1105 int new_y = first_y + getbegy(win);
1106 int new_x = first_x + getbegx(win);
1108 getyx(win, old_y, old_x);
1109 if (high > 2 && wide > 2) {
1110 WINDOW *wb = newwin(high, wide, new_y, new_x);
1111 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1116 remember_boxes(level, wi, wb);
1117 wget_wch_test(level + 1, wi, delay);
1121 wgetch_help(win, flags);
1122 wmove(win, old_y, old_x);
1127 } else if (c == 'z') {
1128 kill(getpid(), SIGTSTP);
1131 wprintw(win, "Key pressed: %04o ", (int) c);
1132 #ifdef NCURSES_MOUSE_VERSION
1133 if (c == KEY_MOUSE) {
1136 #endif /* NCURSES_MOUSE_VERSION */
1137 if (code == KEY_CODE_YES) {
1138 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1139 if (c == KEY_RESIZE) {
1140 resize_wide_boxes(level, win);
1143 (void) waddstr(win, keyname((wchar_t) c));
1145 (void) waddstr(win, key_name((wchar_t) c));
1146 if (c < 256 && iscntrl(c)) {
1147 (void) wprintw(win, " (control character)");
1149 (void) wprintw(win, " = %#x (printable character)",
1153 wgetch_wrap(win, first_y);
1160 init_getch(win, flags);
1166 int delay = begin_getch_test();
1169 wget_wch_test(0, stdscr, delay);
1171 finish_getch_test();
1176 /****************************************************************************
1178 * Character attributes test
1180 ****************************************************************************/
1182 #if HAVE_SETUPTERM || HAVE_TGETENT
1183 #define get_ncv() TIGETNUM("ncv","NC")
1184 #define get_xmc() TIGETNUM("xmc","sg")
1186 #define get_ncv() -1
1187 #define get_xmc() -1
1194 static int first = TRUE;
1195 static chtype result = 0;
1201 char *area_pointer = parsed;
1203 tgetent(buffer, getenv("TERM"));
1206 if (TIGETSTR("smso", "so"))
1207 result |= A_STANDOUT;
1208 if (TIGETSTR("smul", "us"))
1209 result |= A_UNDERLINE;
1210 if (TIGETSTR("rev", "mr"))
1211 result |= A_REVERSE;
1212 if (TIGETSTR("blink", "mb"))
1214 if (TIGETSTR("dim", "mh"))
1216 if (TIGETSTR("bold", "md"))
1218 if (TIGETSTR("smacs", "ac"))
1219 result |= A_ALTCHARSET;
1225 #define termattrs() my_termattrs()
1228 #define MAX_ATTRSTRING 31
1229 #define LEN_ATTRSTRING 26
1231 static char attr_test_string[MAX_ATTRSTRING + 1];
1234 attr_legend(WINDOW *helpwin)
1239 MvWPrintw(helpwin, row++, col,
1241 MvWPrintw(helpwin, row++, col,
1244 MvWPrintw(helpwin, row++, col,
1245 "Modify the test strings:");
1246 MvWPrintw(helpwin, row++, col,
1247 " A digit sets gaps on each side of displayed attributes");
1248 MvWPrintw(helpwin, row++, col,
1249 " </> shifts the text left/right. ");
1251 MvWPrintw(helpwin, row++, col,
1254 MvWPrintw(helpwin, row++, col,
1255 " f/F/b/F toggle foreground/background background color");
1256 MvWPrintw(helpwin, row++, col,
1257 " t/T toggle text/background color attribute");
1259 MvWPrintw(helpwin, row++, col,
1260 " a/A toggle ACS (alternate character set) mapping");
1261 MvWPrintw(helpwin, row, col,
1262 " v/V toggle video attribute to combine with each line");
1266 show_color_attr(int fg, int bg, int tx)
1269 printw(" Colors (fg %d, bg %d", fg, bg);
1271 printw(", text %d", tx);
1277 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1284 *fg = (short) (*fg + 1);
1287 *fg = (short) (*fg - 1);
1290 *bg = (short) (*bg + 1);
1293 *bg = (short) (*bg - 1);
1296 *tx = (short) (*tx + 1);
1299 *tx = (short) (*tx - 1);
1307 *fg = (short) min_colors;
1308 if (*fg < min_colors)
1309 *fg = (short) (COLORS - 1);
1311 *bg = (short) min_colors;
1312 if (*bg < min_colors)
1313 *bg = (short) (COLORS - 1);
1317 *tx = (short) (COLORS - 1);
1326 adjust_attr_string(int adjust)
1328 int first = ((int) UChar(attr_test_string[0])) + adjust;
1329 int last = first + LEN_ATTRSTRING;
1331 if (first >= ' ' && last <= '~') { /* 32..126 */
1333 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1334 attr_test_string[j] = (char) k;
1335 if (((k + 1 - first) % 5) == 0) {
1336 if (++j >= MAX_ATTRSTRING)
1338 attr_test_string[j] = ' ';
1341 while (j < MAX_ATTRSTRING)
1342 attr_test_string[j++] = ' ';
1343 attr_test_string[j] = '\0';
1350 init_attr_string(void)
1352 attr_test_string[0] = 'a';
1353 adjust_attr_string(0);
1357 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1359 int ncv = get_ncv();
1360 chtype test = attr & (chtype) (~A_ALTCHARSET);
1363 MvPrintw(row, 5, "-->");
1364 MvPrintw(row, 8, "%s mode:", name);
1365 MvPrintw(row, 24, "|");
1367 printw("%*s", skip, " ");
1369 * Just for testing, write text using the alternate character set one
1370 * character at a time (to pass its rendition directly), and use the
1371 * string operation for the other attributes.
1373 if (attr & A_ALTCHARSET) {
1377 for (s = attr_test_string; *s != '\0'; ++s) {
1382 (void) attrset(attr);
1383 addstr(attr_test_string);
1387 printw("%*s", skip, " ");
1389 if (test != A_NORMAL) {
1390 if (!(termattrs() & test)) {
1393 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1394 static const chtype table[] =
1410 for (n = 0; n < SIZEOF(table); n++) {
1411 if ((table[n] & attr) != 0
1412 && ((1 << n) & ncv) != 0) {
1420 if ((termattrs() & test) != test)
1427 static const struct {
1429 NCURSES_CONST char * name;
1430 } attrs_to_test[] = {
1431 { A_STANDOUT, "STANDOUT" },
1432 { A_REVERSE, "REVERSE" },
1434 { A_UNDERLINE, "UNDERLINE" },
1436 { A_BLINK, "BLINK" },
1437 { A_PROTECT, "PROTECT" },
1439 { A_INVIS, "INVISIBLE" },
1441 { A_NORMAL, "NORMAL" },
1446 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1456 if (ch < 256 && isdigit(ch)) {
1464 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1466 attr_legend(helpwin);
1479 *kc = SIZEOF(attrs_to_test) - 1;
1485 if (*kc >= SIZEOF(attrs_to_test))
1489 adjust_attr_string(-1);
1492 adjust_attr_string(1);
1498 error = cycle_color_attr(ch, fg, bg, tx);
1508 /* test text attributes */
1511 int skip = get_xmc();
1512 short fg = COLOR_BLACK; /* color pair 0 is special */
1513 short bg = COLOR_BLACK;
1521 n = skip; /* make it easy */
1522 k = SIZEOF(attrs_to_test) - 1;
1527 chtype normal = A_NORMAL | BLANK;
1528 chtype extras = (chtype) ac;
1531 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1534 if (init_pair(pair, fg, bg) == ERR) {
1537 normal |= (chtype) COLOR_PAIR(pair);
1542 if (init_pair(pair, tx, bg) == ERR) {
1545 extras |= (chtype) COLOR_PAIR(pair);
1554 MvAddStr(0, 20, "Character attribute test display");
1556 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1557 bool arrow = (j == k);
1558 row = show_attr(row, n, arrow,
1560 attrs_to_test[j].attr |
1561 attrs_to_test[k].attr,
1562 attrs_to_test[j].name);
1566 "This terminal does %shave the magic-cookie glitch",
1567 get_xmc() > -1 ? "" : "not ");
1568 MvPrintw(row + 1, 8, "Enter '?' for help.");
1569 show_color_attr(fg, bg, tx);
1570 printw(" ACS (%d)", ac != 0);
1573 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1575 bkgdset(A_NORMAL | BLANK);
1580 #if USE_WIDEC_SUPPORT
1581 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1584 wide_adjust_attr_string(int adjust)
1586 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1587 int last = first + LEN_ATTRSTRING;
1589 if (first >= ' ' && last <= '~') { /* 32..126 */
1591 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1592 wide_attr_test_string[j] = k;
1593 if (((k + 1 - first) % 5) == 0) {
1594 if (++j >= MAX_ATTRSTRING)
1596 wide_attr_test_string[j] = ' ';
1599 while (j < MAX_ATTRSTRING)
1600 wide_attr_test_string[j++] = ' ';
1601 wide_attr_test_string[j] = '\0';
1608 wide_init_attr_string(void)
1610 wide_attr_test_string[0] = 'a';
1611 wide_adjust_attr_string(0);
1615 set_wide_background(short pair)
1622 setcchar(&normal, blank, A_NORMAL, pair, 0);
1628 get_wide_background(void)
1630 attr_t result = A_NORMAL;
1636 if (getbkgrnd(&ch) != ERR) {
1637 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1645 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1647 int ncv = get_ncv();
1648 chtype test = attr & ~WA_ALTCHARSET;
1651 MvPrintw(row, 5, "-->");
1652 MvPrintw(row, 8, "%s mode:", name);
1653 MvPrintw(row, 24, "|");
1655 printw("%*s", skip, " ");
1658 * Just for testing, write text using the alternate character set one
1659 * character at a time (to pass its rendition directly), and use the
1660 * string operation for the other attributes.
1662 if (attr & WA_ALTCHARSET) {
1666 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1670 setcchar(&ch, fill, attr, pair, 0);
1677 (void) attr_get(&old_attr, &old_pair, 0);
1678 (void) attr_set(attr, pair, 0);
1679 addwstr(wide_attr_test_string);
1680 (void) attr_set(old_attr, old_pair, 0);
1683 printw("%*s", skip, " ");
1685 if (test != A_NORMAL) {
1686 if (!(term_attrs() & test)) {
1689 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1690 static const attr_t table[] =
1704 for (n = 0; n < SIZEOF(table); n++) {
1705 if ((table[n] & attr) != 0
1706 && ((1 << n) & ncv) != 0) {
1714 if ((term_attrs() & test) != test)
1722 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1732 if (ch < 256 && isdigit(ch)) {
1740 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1741 box_set(helpwin, 0, 0);
1742 attr_legend(helpwin);
1755 *kc = SIZEOF(attrs_to_test) - 1;
1761 if (*kc >= SIZEOF(attrs_to_test))
1765 wide_adjust_attr_string(-1);
1768 wide_adjust_attr_string(1);
1774 error = cycle_color_attr(ch, fg, bg, tx);
1783 wide_attr_test(void)
1784 /* test text attributes using wide-character calls */
1787 int skip = get_xmc();
1788 short fg = COLOR_BLACK; /* color pair 0 is special */
1789 short bg = COLOR_BLACK;
1797 n = skip; /* make it easy */
1798 k = SIZEOF(attrs_to_test) - 1;
1799 wide_init_attr_string();
1807 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1810 if (init_pair(pair, fg, bg) == ERR) {
1817 if (init_pair(extras, tx, bg) == ERR) {
1822 set_wide_background(pair);
1825 box_set(stdscr, 0, 0);
1826 MvAddStr(0, 20, "Character attribute test display");
1828 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1829 row = wide_show_attr(row, n, j == k,
1831 attrs_to_test[j].attr |
1832 attrs_to_test[k].attr),
1834 attrs_to_test[j].name);
1838 "This terminal does %shave the magic-cookie glitch",
1839 get_xmc() > -1 ? "" : "not ");
1840 MvPrintw(row + 1, 8, "Enter '?' for help.");
1841 show_color_attr(fg, bg, tx);
1842 printw(" ACS (%d)", ac != 0);
1845 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1847 set_wide_background(0);
1853 /****************************************************************************
1855 * Color support tests
1857 ****************************************************************************/
1859 static NCURSES_CONST char *the_color_names[] =
1880 show_color_name(int y, int x, int color, bool wide)
1882 if (move(y, x) != ERR) {
1887 sprintf(temp, "%02d", color);
1889 } else if (color >= 8) {
1890 sprintf(temp, "[%02d]", color);
1891 } else if (color < 0) {
1892 strcpy(temp, "default");
1894 strcpy(temp, the_color_names[color]);
1896 printw("%-*.*s", width, width, temp);
1901 color_legend(WINDOW *helpwin, bool wide)
1906 MvWPrintw(helpwin, row++, col,
1909 MvWPrintw(helpwin, row++, col,
1910 "Use up/down arrow to scroll through the display if it is");
1911 MvWPrintw(helpwin, row++, col,
1912 "longer than one screen. Control/N and Control/P can be used");
1913 MvWPrintw(helpwin, row++, col,
1914 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1915 MvWPrintw(helpwin, row++, col,
1916 "full screen; control/B and control/F can be used here.");
1918 MvWPrintw(helpwin, row++, col,
1920 MvWPrintw(helpwin, row++, col,
1921 " a/A toggle altcharset off/on");
1922 MvWPrintw(helpwin, row++, col,
1923 " b/B toggle bold off/on");
1924 MvWPrintw(helpwin, row++, col,
1925 " n/N toggle text/number on/off");
1926 MvWPrintw(helpwin, row++, col,
1927 " r/R toggle reverse on/off");
1928 MvWPrintw(helpwin, row++, col,
1929 " w/W toggle width between 8/16 colors");
1930 #if USE_WIDEC_SUPPORT
1932 MvWPrintw(helpwin, row++, col,
1933 "Wide characters:");
1934 MvWPrintw(helpwin, row, col,
1935 " x/X toggle text between ASCII and wide-character");
1942 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1944 /* generate a color test pattern */
1951 int grid_top = top + 3;
1952 int page_size = (LINES - grid_top);
1953 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1959 bool opt_acsc = FALSE;
1960 bool opt_bold = FALSE;
1961 bool opt_revs = FALSE;
1962 bool opt_nums = FALSE;
1963 bool opt_wide = FALSE;
1966 if (COLORS * COLORS == COLOR_PAIRS) {
1967 int limit = (COLORS - min_colors) * (COLORS - min_colors);
1968 if (pairs_max > limit)
1971 if (pairs_max > COLOR_PAIRS)
1972 pairs_max = COLOR_PAIRS;
1978 /* this assumes an 80-column line */
1982 per_row = (COLORS > 8) ? 16 : 8;
1988 per_row -= min_colors;
1990 row_limit = (pairs_max + per_row - 1) / per_row;
1993 (void) printw("There are %d color pairs and %d colors%s\n",
1995 min_colors ? " besides 'default'" : "");
1998 MvPrintw(top + 1, 0,
1999 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2002 opt_bold ? "on" : "off");
2004 /* show color names/numbers across the top */
2005 for (i = 0; i < per_row; i++)
2006 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2008 /* show a grid of colors, with color names/ numbers on the left */
2009 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
2010 int row = grid_top + (i / per_row) - base_row;
2011 int col = (i % per_row + 1) * width;
2014 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
2015 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
2016 if (row >= 0 && move(row, col) != ERR) {
2017 short fg = InxToFG(i);
2018 short bg = InxToBG(i);
2020 init_pair(pair, fg, bg);
2021 attron((attr_t) COLOR_PAIR(pair));
2023 attron((attr_t) A_ALTCHARSET);
2025 attron((attr_t) A_BOLD);
2027 attron((attr_t) A_REVERSE);
2030 sprintf(numbered, "{%02X}", i);
2033 printw("%-*.*s", width, width, hello);
2034 (void) attrset(A_NORMAL);
2036 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2037 show_color_name(row, 0, InxToBG(i), opt_wide);
2045 switch (wGetchar(stdscr)) {
2074 set_color_test(opt_wide, FALSE);
2077 set_color_test(opt_wide, TRUE);
2081 if (base_row <= 0) {
2089 if (base_row + page_size >= row_limit) {
2098 if (base_row <= 0) {
2101 base_row -= (page_size - 1);
2109 if (base_row + page_size >= row_limit) {
2112 base_row += page_size - 1;
2113 if (base_row + page_size >= row_limit) {
2114 base_row = row_limit - page_size - 1;
2119 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2121 color_legend(helpwin, FALSE);
2136 #if USE_WIDEC_SUPPORT
2137 /* generate a color test pattern */
2139 wide_color_test(void)
2144 int grid_top = top + 3;
2145 int page_size = (LINES - grid_top);
2146 int pairs_max = (unsigned short) (-1);
2152 bool opt_acsc = FALSE;
2153 bool opt_bold = FALSE;
2154 bool opt_revs = FALSE;
2155 bool opt_wide = FALSE;
2156 bool opt_nums = FALSE;
2157 bool opt_xchr = FALSE;
2161 if (COLORS * COLORS == COLOR_PAIRS) {
2162 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2163 if (pairs_max > limit)
2166 if (pairs_max > COLOR_PAIRS)
2167 pairs_max = COLOR_PAIRS;
2173 /* this assumes an 80-column line */
2177 per_row = (COLORS > 8) ? 16 : 8;
2183 per_row -= min_colors;
2186 make_fullwidth_text(buffer, hello);
2190 make_narrow_text(buffer, hello);
2193 row_limit = (pairs_max + per_row - 1) / per_row;
2196 (void) printw("There are %d color pairs and %d colors%s\n",
2198 min_colors ? " besides 'default'" : "");
2201 MvPrintw(top + 1, 0,
2202 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2205 opt_bold ? "on" : "off");
2207 /* show color names/numbers across the top */
2208 for (i = 0; i < per_row; i++)
2209 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2211 /* show a grid of colors, with color names/ numbers on the left */
2212 for (i = (base_row * per_row); i < pairs_max; i++) {
2213 int row = grid_top + (i / per_row) - base_row;
2214 int col = (i % per_row + 1) * width;
2215 short pair = (short) i;
2217 if (row >= 0 && move(row, col) != ERR) {
2218 init_pair(pair, InxToFG(i), InxToBG(i));
2219 color_set(pair, NULL);
2221 attr_on((attr_t) A_ALTCHARSET, NULL);
2223 attr_on((attr_t) A_BOLD, NULL);
2225 attr_on((attr_t) A_REVERSE, NULL);
2228 sprintf(numbered, "{%02X}", i);
2230 make_fullwidth_text(buffer, numbered);
2232 make_narrow_text(buffer, numbered);
2235 addnwstr(buffer, width);
2236 (void) attr_set(A_NORMAL, 0, NULL);
2238 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2239 show_color_name(row, 0, InxToBG(i), opt_wide);
2247 switch (wGetchar(stdscr)) {
2276 set_color_test(opt_wide, FALSE);
2279 set_color_test(opt_wide, TRUE);
2289 if (base_row <= 0) {
2297 if (base_row + page_size >= row_limit) {
2306 if (base_row <= 0) {
2309 base_row -= (page_size - 1);
2317 if (base_row + page_size >= row_limit) {
2320 base_row += page_size - 1;
2321 if (base_row + page_size >= row_limit) {
2322 base_row = row_limit - page_size - 1;
2327 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2329 color_legend(helpwin, TRUE);
2343 #endif /* USE_WIDEC_SUPPORT */
2346 change_color(short current, int field, int value, int usebase)
2348 short red, green, blue;
2350 color_content(current, &red, &green, &blue);
2354 red = (short) (usebase ? (red + value) : value);
2357 green = (short) (usebase ? (green + value) : value);
2360 blue = (short) (usebase ? (blue + value) : value);
2364 if (init_color(current, red, green, blue) == ERR)
2369 init_all_colors(void)
2373 for (c = 0; c < COLORS; ++c)
2376 all_colors[c].green,
2377 all_colors[c].blue);
2380 #define scaled_rgb(n) ((255 * (n)) / 1000)
2384 /* display the color test pattern, without trying to edit colors */
2388 int this_c = 0, value = 0, field = 0;
2391 int page_size = (LINES - 6);
2396 for (i = 0; i < max_colors; i++)
2397 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2399 MvPrintw(LINES - 2, 0, "Number: %d", value);
2402 short red, green, blue;
2405 MvAddStr(0, 20, "Color RGB Value Editing");
2408 for (i = (short) top_color;
2409 (i - top_color < page_size)
2410 && (i < max_colors); i++) {
2413 sprintf(numeric, "[%d]", i);
2414 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2415 (i == current ? '>' : ' '),
2416 (i < (int) SIZEOF(the_color_names)
2417 ? the_color_names[i] : numeric));
2418 (void) attrset((attr_t) COLOR_PAIR(i));
2420 (void) attrset(A_NORMAL);
2422 color_content((short) i, &red, &green, &blue);
2424 if (current == i && field == 0)
2426 printw("%04d", red);
2427 if (current == i && field == 0)
2428 (void) attrset(A_NORMAL);
2430 if (current == i && field == 1)
2432 printw("%04d", green);
2433 if (current == i && field == 1)
2434 (void) attrset(A_NORMAL);
2436 if (current == i && field == 2)
2438 printw("%04d", blue);
2439 if (current == i && field == 2)
2440 (void) attrset(A_NORMAL);
2441 (void) attrset(A_NORMAL);
2442 printw(" ( %3d %3d %3d )",
2448 MvAddStr(LINES - 3, 0,
2449 "Use up/down to select a color, left/right to change fields.");
2450 MvAddStr(LINES - 2, 0,
2451 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2453 move(2 + current - top_color, 0);
2457 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2464 current -= (page_size - 1);
2471 if (current < (max_colors - 1))
2472 current += (page_size - 1);
2479 current = (current == 0 ? (max_colors - 1) : current - 1);
2484 current = (current == (max_colors - 1) ? 0 : current + 1);
2488 field = (field == 2 ? 0 : field + 1);
2492 field = (field == 0 ? 2 : field - 1);
2505 value = value * 10 + (this_c - '0');
2509 change_color((short) current, field, value, 1);
2513 change_color((short) current, field, -value, 1);
2517 change_color((short) current, field, value, 0);
2522 P(" RGB Value Editing Help");
2524 P("You are in the RGB value editor. Use the arrow keys to select one of");
2525 P("the fields in one of the RGB triples of the current colors; the one");
2526 P("currently selected will be reverse-video highlighted.");
2528 P("To change a field, enter the digits of the new value; they are echoed");
2529 P("as entered. Finish by typing `='. The change will take effect instantly.");
2530 P("To increment or decrement a value, use the same procedure, but finish");
2531 P("with a `+' or `-'.");
2533 P("Press 'm' to invoke the top-level menu with the current color settings.");
2534 P("To quit, do ESC");
2543 for (i = 0; i < max_colors; i++)
2544 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2558 if (current >= max_colors)
2559 current = max_colors - 1;
2560 if (current < top_color)
2561 top_color = current;
2562 if (current - top_color >= page_size)
2563 top_color = current - (page_size - 1);
2565 MvPrintw(LINES - 1, 0, "Number: %d", value);
2573 * ncurses does not reset each color individually when calling endwin().
2580 /****************************************************************************
2582 * Soft-key label test
2584 ****************************************************************************/
2589 #define SLK_WORK (SLK_HELP + 3)
2594 static const char *table[] =
2596 "Available commands are:"
2598 ,"^L -- repaint this message and activate soft keys"
2599 ,"a/d -- activate/disable soft keys"
2600 ,"c -- set centered format for labels"
2601 ,"l -- set left-justified format for labels"
2602 ,"r -- set right-justified format for labels"
2603 ,"[12345678] -- set label; labels are numbered 1 through 8"
2604 ,"e -- erase stdscr (should not erase labels)"
2605 ,"s -- test scrolling of shortened screen"
2606 ,"v/V -- cycle through video attributes"
2608 ,"F/f/B/b -- cycle through foreground/background colors"
2610 ,"ESC -- return to main menu"
2612 ,"Note: if activating the soft keys causes your terminal to scroll up"
2613 ,"one line, your terminal auto-scrolls when anything is written to the"
2614 ,"last screen position. The ncurses code does not yet handle this"
2620 for (j = 0; j < SIZEOF(table); ++j) {
2626 /****************************************************************************
2628 * Alternate character-set stuff
2630 ****************************************************************************/
2635 } attrs_to_cycle[] = {
2636 { A_NORMAL, "normal" },
2638 { A_BLINK, "blink" },
2639 { A_REVERSE, "reverse" },
2640 { A_UNDERLINE, "underline" },
2645 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2651 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2656 *at_code = SIZEOF(attrs_to_cycle) - 1;
2665 *attr = attrs_to_cycle[*at_code].attr;
2670 cycle_colors(int ch, int *fg, int *bg, short *pair)
2672 bool result = FALSE;
2682 if ((*fg += 1) >= COLORS)
2690 if ((*bg += 1) >= COLORS)
2698 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2701 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2712 call_slk_color(int fg, int bg)
2714 init_pair(1, (short) bg, (short) fg);
2716 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2726 /* exercise the soft keys */
2731 chtype attr = A_NORMAL;
2732 unsigned at_code = 0;
2734 int fg = COLOR_BLACK;
2735 int bg = COLOR_WHITE;
2742 call_slk_color(fg, bg);
2752 MvAddStr(0, 20, "Soft Key Exerciser");
2767 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2768 while ((c = Getchar()) != 'Q' && (c != ERR))
2796 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2798 if ((s = slk_label(c - '0')) != 0) {
2801 wGetstring(stdscr, buf, 8);
2802 slk_set((c - '0'), buf, fmt);
2811 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2813 wnoutrefresh(stdscr);
2818 if (cycle_attr(c, &at_code, &attr)) {
2825 if (cycle_colors(c, &fg, &bg, &pair)) {
2827 call_slk_color(fg, bg);
2837 } while (!isQuit(c = Getchar()));
2845 #if USE_WIDEC_SUPPORT
2849 /* exercise the soft keys */
2852 wchar_t buf[SLKLEN + 1];
2854 chtype attr = A_NORMAL;
2855 unsigned at_code = 0;
2856 int fg = COLOR_BLACK;
2857 int bg = COLOR_WHITE;
2862 call_slk_color(fg, bg);
2869 attr_on(WA_BOLD, NULL);
2870 MvAddStr(0, 20, "Soft Key Exerciser");
2871 attr_off(WA_BOLD, NULL);
2885 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2886 while ((c = Getchar()) != 'Q' && (c != ERR))
2914 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2916 if ((s = slk_label(c - '0')) != 0) {
2917 char *temp = strdup(s);
2918 size_t used = strlen(temp);
2919 size_t want = SLKLEN;
2921 #ifndef state_unused
2926 while (want > 0 && used != 0) {
2927 const char *base = s;
2928 reset_mbytes(state);
2929 test = count_mbytes(base, 0, &state);
2930 if (test == (size_t) -1) {
2932 } else if (test > want) {
2935 reset_mbytes(state);
2936 trans_mbytes(buf, base, want, &state);
2942 wGet_wstring(stdscr, buf, SLKLEN);
2943 slk_wset((c - '0'), buf, fmt);
2954 fg = (short) ((fg + 1) % COLORS);
2955 call_slk_color(fg, bg);
2960 bg = (short) ((bg + 1) % COLORS);
2961 call_slk_color(fg, bg);
2964 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2966 wnoutrefresh(stdscr);
2970 if (cycle_attr(c, &at_code, &attr)) {
2971 slk_attr_set(attr, (fg || bg), NULL);
2977 if (cycle_colors(c, &fg, &bg, &pair)) {
2979 call_slk_color(fg, bg);
2989 } while (!isQuit(c = Getchar()));
2997 #endif /* SLK_INIT */
2999 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3000 * terminal to perform functions. The remaining codes can be graphic.
3003 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
3005 bool C1 = (first == 128);
3007 unsigned last = first + 31;
3012 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3013 C1 ? "C1" : "GR", first, last);
3017 for (code = first; code <= last; code++) {
3019 int row = 2 + ((int) (code - first) % 16);
3020 int col = ((int) (code - first) / 16) * COLS / 2;
3022 sprintf(tmp, "%3u (0x%x)", code, code);
3023 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3027 nodelay(stdscr, TRUE);
3028 echochar(colored_chtype(code, attr, pair));
3030 /* (yes, this _is_ crude) */
3031 while ((reply = Getchar()) != ERR) {
3032 addch(UChar(reply));
3035 nodelay(stdscr, FALSE);
3037 } while (--count > 0);
3044 show_pc_chars(int repeat, attr_t attr, short pair)
3050 MvPrintw(0, 20, "Display of PC Character Codes");
3054 for (code = 0; code < 16; ++code) {
3055 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3057 for (code = 0; code < 256; code++) {
3059 int row = 3 + (int) (code / 16) + (code >= 128);
3060 int col = 8 + (int) (code % 16) * PC_COLS;
3061 if ((code % 16) == 0)
3062 MvPrintw(row, 0, "0x%02x:", code);
3073 * Skip the ones that do not work.
3077 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3080 } while (--count > 0);
3085 show_box_chars(int repeat, attr_t attr, short pair)
3089 attr |= (attr_t) COLOR_PAIR(pair);
3093 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3098 colored_chtype(ACS_VLINE, attr, pair),
3099 colored_chtype(ACS_VLINE, attr, pair),
3100 colored_chtype(ACS_HLINE, attr, pair),
3101 colored_chtype(ACS_HLINE, attr, pair),
3102 colored_chtype(ACS_ULCORNER, attr, pair),
3103 colored_chtype(ACS_URCORNER, attr, pair),
3104 colored_chtype(ACS_LLCORNER, attr, pair),
3105 colored_chtype(ACS_LRCORNER, attr, pair));
3106 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3107 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3108 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3109 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3110 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3111 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3112 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3118 show_1_acs(int n, int repeat, const char *name, chtype code)
3120 const int height = 16;
3121 int row = 2 + (n % height);
3122 int col = (n / height) * COLS / 2;
3124 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3127 } while (--repeat > 0);
3132 show_acs_chars(int repeat, attr_t attr, short pair)
3133 /* display the ACS character set */
3137 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3141 MvAddStr(0, 20, "Display of the ACS Character Set");
3145 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3146 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3147 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3148 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3150 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3151 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3152 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3153 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3155 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3156 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3159 * HPUX's ACS definitions are broken here. Just give up.
3161 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3162 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3163 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3164 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3165 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3167 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3168 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3169 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3170 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3171 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3172 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3173 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3174 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3175 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3177 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3178 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3179 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3181 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3182 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3183 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3184 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3185 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3186 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3194 char *term = getenv("TERM");
3195 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3198 chtype attr = A_NORMAL;
3201 int fg = COLOR_BLACK;
3202 int bg = COLOR_BLACK;
3203 unsigned at_code = 0;
3205 void (*last_show_acs) (int, attr_t, short) = 0;
3213 ToggleAcs(last_show_acs, show_acs_chars);
3217 ToggleAcs(last_show_acs, show_pc_chars);
3222 ToggleAcs(last_show_acs, show_box_chars);
3248 if (repeat < (COLS / 4))
3256 if (cycle_attr(c, &at_code, &attr)
3257 || cycle_colors(c, &fg, &bg, &pair)) {
3264 if (last_show_acs != 0)
3265 last_show_acs(repeat, attr, pair);
3267 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3269 MvPrintw(LINES - 3, 0,
3270 "Note: ANSI terminals may not display C1 characters.");
3271 MvPrintw(LINES - 2, 0,
3272 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3275 MvPrintw(LINES - 1, 0,
3276 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3277 attrs_to_cycle[at_code].name,
3280 MvPrintw(LINES - 1, 0,
3281 "v/V cycles through video attributes (%s).",
3282 attrs_to_cycle[at_code].name);
3285 } while (!isQuit(c = Getchar()));
3292 #if USE_WIDEC_SUPPORT
3294 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3300 TEST_CCHAR(src, count, {
3301 attr |= (test_attrs & A_ALTCHARSET);
3302 setcchar(dst, test_wch, attr, pair, NULL);
3312 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3316 int last = first + 31;
3320 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3323 for (code = first; (int) code <= last; code++) {
3324 int row = 2 + ((code - first) % 16);
3325 int col = ((code - first) / 16) * COLS / 2;
3331 memset(&codes, 0, sizeof(codes));
3333 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3334 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3335 setcchar(&temp, codes, attr, pair, 0);
3338 * Give non-spacing characters something to combine with. If we
3339 * don't, they'll bunch up in a heap on the space after the ":".
3340 * Mark them with reverse-video to make them simpler to find on
3343 if (wcwidth(code) == 0) {
3344 addch((chtype) space |
3345 (A_REVERSE ^ attr) |
3346 (attr_t) COLOR_PAIR(pair));
3349 * This could use add_wch(), but is done for comparison with the
3350 * normal 'f' test (and to make a test-case for echo_wchar()).
3351 * The screen will flicker because the erase() at the top of the
3352 * function is met by the builtin refresh() in echo_wchar().
3356 * The repeat-count may make text wrap - avoid that.
3358 getyx(stdscr, y, x);
3359 if (x >= col + (COLS / 2) - 2)
3361 } while (--count > 0);
3366 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3368 const int height = 16;
3369 int row = 2 + (n % height);
3370 int col = (n / height) * COLS / 2;
3372 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3373 while (--repeat >= 0) {
3379 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3382 show_wacs_chars(int repeat, attr_t attr, short pair)
3383 /* display the wide-ACS character set */
3389 /*#define BOTH2(name) #name, &(name) */
3390 #define BOTH2(name) #name, MERGE_ATTR(name)
3394 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3398 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3399 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3400 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3401 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3403 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3404 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3405 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3406 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3408 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3409 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3411 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3412 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3413 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3414 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3416 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3417 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3418 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3419 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3420 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3421 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3422 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3423 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3424 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3426 #ifdef CURSES_WACS_ARRAY
3427 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3428 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3429 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3431 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3432 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3433 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3434 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3435 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3436 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3442 show_wacs_chars_double(int repeat, attr_t attr, short pair)
3443 /* display the wide-ACS character set */
3449 /*#define BOTH2(name) #name, &(name) */
3450 #define BOTH2(name) #name, MERGE_ATTR(name)
3454 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3458 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3459 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3460 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3461 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3463 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3464 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3465 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3466 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3468 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3469 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3471 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3472 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3473 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3474 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3476 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3477 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3478 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3479 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3480 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3481 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3482 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3483 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3484 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3486 #ifdef CURSES_WACS_ARRAY
3487 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3488 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3489 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3491 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3492 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3493 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3494 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3495 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3496 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3503 show_wacs_chars_thick(int repeat, attr_t attr, short pair)
3504 /* display the wide-ACS character set */
3510 /*#define BOTH2(name) #name, &(name) */
3511 #define BOTH2(name) #name, MERGE_ATTR(name)
3515 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3519 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
3520 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
3521 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
3522 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
3524 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
3525 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
3526 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
3527 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
3529 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
3530 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
3532 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3533 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3534 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3535 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3537 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3538 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3539 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3540 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3541 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3542 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3543 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3544 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3545 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3547 #ifdef CURSES_WACS_ARRAY
3548 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3549 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3550 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3552 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3553 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3554 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3555 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3556 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3557 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3564 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3567 show_wbox_chars(int repeat, attr_t attr, short pair)
3574 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3579 MERGE_ATTR(0, WACS_VLINE),
3580 MERGE_ATTR(1, WACS_VLINE),
3581 MERGE_ATTR(2, WACS_HLINE),
3582 MERGE_ATTR(3, WACS_HLINE),
3583 MERGE_ATTR(4, WACS_ULCORNER),
3584 MERGE_ATTR(5, WACS_URCORNER),
3585 MERGE_ATTR(6, WACS_LLCORNER),
3586 MERGE_ATTR(7, WACS_LRCORNER));
3588 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3589 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3590 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3591 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3592 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3593 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3594 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3602 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3604 const int height = 16;
3605 int row = 2 + (n % height);
3606 int col = (n / height) * COLS / 2;
3609 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3610 (void) attr_set(attr, pair, 0);
3611 addstr(strcpy(temp, code));
3612 (void) attr_set(A_NORMAL, 0, 0);
3616 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3619 show_utf8_chars(int repeat, attr_t attr, short pair)
3626 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3630 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3631 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3632 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3633 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3635 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3636 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3637 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3638 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3640 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3641 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3643 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3644 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3645 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3646 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3648 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3649 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3650 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3651 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3652 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3653 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3654 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3655 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3656 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3657 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3658 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3659 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3661 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3662 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3663 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3664 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3665 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3666 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3671 /* display the wide-ACS character set */
3673 wide_acs_display(void)
3679 chtype attr = A_NORMAL;
3680 int fg = COLOR_BLACK;
3681 int bg = COLOR_BLACK;
3682 unsigned at_code = 0;
3684 void (*last_show_wacs) (int, attr_t, short) = 0;
3692 ToggleAcs(last_show_wacs, show_wacs_chars);
3696 ToggleAcs(last_show_wacs, show_wacs_chars_double);
3701 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
3705 ToggleAcs(last_show_wacs, show_wbox_chars);
3708 ToggleAcs(last_show_wacs, show_utf8_chars);
3711 if (c < 256 && isdigit(c)) {
3714 } else if (c == '+') {
3717 } else if (c == '-' && digit > 0) {
3720 } else if (c == '>' && repeat < (COLS / 4)) {
3722 } else if (c == '<' && repeat > 1) {
3724 } else if (c == '_') {
3725 space = (space == ' ') ? '_' : ' ';
3727 } else if (cycle_attr(c, &at_code, &attr)
3728 || cycle_colors(c, &fg, &bg, &pair)) {
3729 if (last_show_wacs != 0)
3737 if (last_show_wacs != 0)
3738 last_show_wacs(repeat, attr, pair);
3740 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3742 MvPrintw(LINES - 3, 0,
3743 "Select: a/d/t WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3745 MvPrintw(LINES - 2, 0,
3746 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3747 attrs_to_cycle[at_code].name,
3750 MvPrintw(LINES - 2, 0,
3751 "v/V cycles through video attributes (%s).",
3752 attrs_to_cycle[at_code].name);
3755 } while (!isQuit(c = Getchar()));
3765 * Graphic-rendition test (adapted from vttest)
3768 test_sgr_attributes(void)
3772 for (pass = 0; pass < 2; pass++) {
3773 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3775 /* Use non-default colors if possible to exercise bce a little */
3777 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3778 normal |= COLOR_PAIR(1);
3782 MvPrintw(1, 20, "Graphic rendition test pattern:");
3784 MvPrintw(4, 1, "vanilla");
3786 #define set_sgr(mask) bkgdset((normal^(mask)));
3788 MvPrintw(4, 40, "bold");
3790 set_sgr(A_UNDERLINE);
3791 MvPrintw(6, 6, "underline");
3793 set_sgr(A_BOLD | A_UNDERLINE);
3794 MvPrintw(6, 45, "bold underline");
3797 MvPrintw(8, 1, "blink");
3799 set_sgr(A_BLINK | A_BOLD);
3800 MvPrintw(8, 40, "bold blink");
3802 set_sgr(A_UNDERLINE | A_BLINK);
3803 MvPrintw(10, 6, "underline blink");
3805 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3806 MvPrintw(10, 45, "bold underline blink");
3809 MvPrintw(12, 1, "negative");
3811 set_sgr(A_BOLD | A_REVERSE);
3812 MvPrintw(12, 40, "bold negative");
3814 set_sgr(A_UNDERLINE | A_REVERSE);
3815 MvPrintw(14, 6, "underline negative");
3817 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3818 MvPrintw(14, 45, "bold underline negative");
3820 set_sgr(A_BLINK | A_REVERSE);
3821 MvPrintw(16, 1, "blink negative");
3823 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3824 MvPrintw(16, 40, "bold blink negative");
3826 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3827 MvPrintw(18, 6, "underline blink negative");
3829 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3830 MvPrintw(18, 45, "bold underline blink negative");
3833 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3839 bkgdset(A_NORMAL | BLANK);
3844 /****************************************************************************
3846 * Windows and scrolling tester.
3848 ****************************************************************************/
3850 #define BOTLINES 4 /* number of line stolen from screen bottom */
3856 #define FRAME struct frame
3865 #if defined(NCURSES_VERSION)
3866 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3867 #define is_keypad(win) (win)->_use_keypad
3868 #define is_scrollok(win) (win)->_scroll
3869 #elif !defined(is_keypad)
3870 #define is_keypad(win) FALSE
3871 #define is_scrollok(win) FALSE
3874 #define is_keypad(win) FALSE
3875 #define is_scrollok(win) FALSE
3879 frame_win(FRAME * curp)
3881 return (curp != 0) ? curp->wind : stdscr;
3884 /* We need to know if these flags are actually set, so don't look in FRAME.
3885 * These names are known to work with SVr4 curses as well as ncurses. The
3886 * _use_keypad name does not work with Solaris 8.
3889 HaveKeypad(FRAME * curp)
3891 WINDOW *win = frame_win(curp);
3893 return is_keypad(win);
3897 HaveScroll(FRAME * curp)
3899 WINDOW *win = frame_win(curp);
3901 return is_scrollok(win);
3905 newwin_legend(FRAME * curp)
3907 static const struct {
3912 "^C = create window", 0
3915 "^N = next window", 0
3918 "^P = previous window", 0
3921 "^F = scroll forward", 0
3924 "^B = scroll backward", 0
3927 "^K = keypad(%s)", 1
3930 "^S = scrollok(%s)", 2
3933 "^W = save window to file", 0
3936 "^R = restore window", 0
3949 bool do_keypad = HaveKeypad(curp);
3950 bool do_scroll = HaveScroll(curp);
3954 for (n = 0; n < SIZEOF(legend); n++) {
3955 switch (legend[n].code) {
3957 strcpy(buf, legend[n].msg);
3960 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3963 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3966 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3969 x = getcurx(stdscr);
3970 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3977 transient(FRAME * curp, NCURSES_CONST char *msg)
3979 newwin_legend(curp);
3981 MvAddStr(LINES - 1, 0, msg);
3987 printw("%s characters are echoed, window should %sscroll.",
3988 HaveKeypad(curp) ? "Non-arrow" : "All other",
3989 HaveScroll(curp) ? "" : "not ");
3994 newwin_report(FRAME * curp)
3995 /* report on the cursor's current position, then restore it */
3997 WINDOW *win = frame_win(curp);
4001 transient(curp, (char *) 0);
4003 move(LINES - 1, COLS - 17);
4004 printw("Y = %2d X = %2d", y, x);
4012 selectcell(int uli, int ulj, int lri, int lrj)
4013 /* arrows keys move cursor, return location at current on non-arrow key */
4015 static pair res; /* result cell */
4016 int si = lri - uli + 1; /* depth of the select area */
4017 int sj = lrj - ulj + 1; /* width of the select area */
4018 int i = 0, j = 0; /* offsets into the select area */
4023 move(uli + i, ulj + j);
4024 newwin_report((FRAME *) 0);
4026 switch (Getchar()) {
4040 return ((pair *) 0);
4041 #ifdef NCURSES_MOUSE_VERSION
4047 if (event.y > uli && event.x > ulj) {
4068 outerbox(pair ul, pair lr, bool onoff)
4069 /* draw or erase a box *outside* the given pair of corners */
4071 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4072 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4073 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4074 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4075 move(ul.y - 1, ul.x);
4076 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4077 move(ul.y, ul.x - 1);
4078 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4079 move(lr.y + 1, ul.x);
4080 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4081 move(ul.y, lr.x + 1);
4082 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4087 /* Ask user for a window definition */
4094 addstr("Use arrows to move cursor, anything else to mark corner 1");
4096 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4097 return ((WINDOW *) 0);
4098 memcpy(&ul, tmp, sizeof(pair));
4099 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4102 addstr("Use arrows to move cursor, anything else to mark corner 2");
4104 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4106 return ((WINDOW *) 0);
4107 memcpy(&lr, tmp, sizeof(pair));
4109 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4111 outerbox(ul, lr, TRUE);
4122 newwin_move(FRAME * curp, int dy, int dx)
4124 WINDOW *win = frame_win(curp);
4128 getyx(win, cur_y, cur_x);
4129 getmaxyx(win, max_y, max_x);
4130 if ((cur_x += dx) < 0)
4132 else if (cur_x >= max_x)
4134 if ((cur_y += dy) < 0)
4136 else if (cur_y >= max_y)
4138 wmove(win, cur_y, cur_x);
4142 delete_framed(FRAME * fp, bool showit)
4147 fp->last->next = fp->next;
4148 fp->next->last = fp->last;
4156 np = (fp == fp->next) ? 0 : fp->next;
4163 acs_and_scroll(void)
4164 /* Demonstrate windows */
4167 FRAME *current = (FRAME *) 0, *neww;
4169 #if HAVE_PUTWIN && HAVE_GETWIN
4173 #define DUMPFILE "screendump"
4175 #ifdef NCURSES_MOUSE_VERSION
4176 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4181 transient((FRAME *) 0, (char *) 0);
4184 if ((neww = typeCalloc(FRAME, 1)) == 0) {
4187 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4192 if (current == 0) { /* First element, */
4193 neww->next = neww; /* so point it at itself */
4196 neww->next = current->next;
4197 neww->last = current;
4198 neww->last->next = neww;
4199 neww->next->last = neww;
4202 /* SVr4 curses sets the keypad on all newly-created windows to
4203 * false. Someone reported that PDCurses makes new windows inherit
4204 * this flag. Remove the following 'keypad()' call to test this
4206 keypad(current->wind, TRUE);
4207 current->do_keypad = HaveKeypad(current);
4208 current->do_scroll = HaveScroll(current);
4211 case CTRL('N'): /* go to next window */
4213 current = current->next;
4216 case CTRL('P'): /* go to previous window */
4218 current = current->last;
4221 case CTRL('F'): /* scroll current window forward */
4223 wscrl(frame_win(current), 1);
4226 case CTRL('B'): /* scroll current window backwards */
4228 wscrl(frame_win(current), -1);
4231 case CTRL('K'): /* toggle keypad mode for current */
4233 current->do_keypad = !current->do_keypad;
4234 keypad(current->wind, current->do_keypad);
4240 current->do_scroll = !current->do_scroll;
4241 scrollok(current->wind, current->do_scroll);
4245 #if HAVE_PUTWIN && HAVE_GETWIN
4246 case CTRL('W'): /* save and delete window */
4247 if ((current != 0) && (current == current->next)) {
4248 transient(current, "Will not save/delete ONLY window");
4250 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4251 transient(current, "Can't open screen dump file");
4253 (void) putwin(frame_win(current), fp);
4256 current = delete_framed(current, TRUE);
4260 case CTRL('R'): /* restore window */
4261 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4262 transient(current, "Can't open screen dump file");
4264 if ((neww = typeCalloc(FRAME, 1)) != 0) {
4266 neww->next = current ? current->next : 0;
4267 neww->last = current;
4268 neww->last->next = neww;
4269 neww->next->last = neww;
4271 neww->wind = getwin(fp);
4273 wrefresh(neww->wind);
4281 case CTRL('X'): /* resize window */
4288 addstr("Use arrows to move cursor, anything else to mark new corner");
4291 getbegyx(current->wind, ul.y, ul.x);
4293 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4294 if (tmp == (pair *) 0) {
4299 getmaxyx(current->wind, lr.y, lr.x);
4302 outerbox(ul, lr, FALSE);
4303 wnoutrefresh(stdscr);
4305 /* strictly cosmetic hack for the test */
4306 getmaxyx(current->wind, my, mx);
4307 if (my > tmp->y - ul.y) {
4308 getyx(current->wind, lr.y, lr.x);
4309 wmove(current->wind, tmp->y - ul.y + 1, 0);
4310 wclrtobot(current->wind);
4311 wmove(current->wind, lr.y, lr.x);
4313 if (mx > tmp->x - ul.x)
4314 for (i = 0; i < my; i++) {
4315 wmove(current->wind, i, tmp->x - ul.x + 1);
4316 wclrtoeol(current->wind);
4318 wnoutrefresh(current->wind);
4320 memcpy(&lr, tmp, sizeof(pair));
4321 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4323 getbegyx(current->wind, ul.y, ul.x);
4324 getmaxyx(current->wind, lr.y, lr.x);
4327 outerbox(ul, lr, TRUE);
4328 wnoutrefresh(stdscr);
4330 wnoutrefresh(current->wind);
4336 #endif /* HAVE_WRESIZE */
4338 case KEY_F(10): /* undocumented --- use this to test area clears */
4339 selectcell(0, 0, LINES - 1, COLS - 1);
4345 newwin_move(current, -1, 0);
4348 newwin_move(current, 1, 0);
4351 newwin_move(current, 0, -1);
4354 newwin_move(current, 0, 1);
4362 getyx(frame_win(current), y, x);
4366 x = getmaxx(frame_win(current)) - 1;
4368 (void) mvwdelch(frame_win(current), y, x);
4378 waddch(current->wind, (chtype) c);
4383 newwin_report(current);
4384 usescr = frame_win(current);
4387 (!isQuit(c = wGetchar(usescr))
4391 while (current != 0)
4392 current = delete_framed(current, FALSE);
4394 scrollok(stdscr, TRUE); /* reset to driver's default */
4395 #ifdef NCURSES_MOUSE_VERSION
4396 mousemask(0, (mmask_t *) 0);
4403 /****************************************************************************
4407 ****************************************************************************/
4410 static int nap_msec = 1;
4412 static NCURSES_CONST char *mod[] =
4422 /*+-------------------------------------------------------------------------
4424 --------------------------------------------------------------------------*/
4426 wait_a_while(int msec GCC_UNUSED)
4436 else if (msec > 1000)
4437 sleep((unsigned) msec / 1000);
4441 } /* end of wait_a_while */
4443 /*+-------------------------------------------------------------------------
4445 --------------------------------------------------------------------------*/
4447 saywhat(NCURSES_CONST char *text)
4449 wmove(stdscr, LINES - 1, 0);
4451 if (text != 0 && *text != '\0') {
4452 waddstr(stdscr, text);
4453 waddstr(stdscr, "; ");
4455 waddstr(stdscr, "press any key to continue");
4456 } /* end of saywhat */
4458 /*+-------------------------------------------------------------------------
4459 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4460 --------------------------------------------------------------------------*/
4462 mkpanel(short color, int rows, int cols, int tly, int tlx)
4467 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4468 if ((pan = new_panel(win)) == 0) {
4470 } else if (use_colors) {
4471 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4474 init_pair(color, fg, bg);
4475 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
4477 wbkgdset(win, A_BOLD | ' ');
4481 } /* end of mkpanel */
4483 /*+-------------------------------------------------------------------------
4485 --------------------------------------------------------------------------*/
4487 rmpanel(PANEL * pan)
4489 WINDOW *win = panel_window(pan);
4492 } /* end of rmpanel */
4494 /*+-------------------------------------------------------------------------
4496 --------------------------------------------------------------------------*/
4502 } /* end of pflush */
4504 /*+-------------------------------------------------------------------------
4506 --------------------------------------------------------------------------*/
4512 for (y = 0; y < LINES - 1; y++) {
4513 for (x = 0; x < COLS; x++)
4514 wprintw(stdscr, "%d", (y + x) % 10);
4519 fill_panel(PANEL * pan)
4521 WINDOW *win = panel_window(pan);
4522 const char *userptr = (const char *) panel_userptr(pan);
4523 int num = (userptr && *userptr) ? userptr[1] : '?';
4527 wprintw(win, "-pan%c-", num);
4530 for (y = 2; y < getmaxy(win) - 1; y++) {
4531 for (x = 1; x < getmaxx(win) - 1; x++) {
4533 waddch(win, UChar(num));
4538 #if USE_WIDEC_SUPPORT
4540 init_wide_panel(void)
4545 for (digit = 0; digit < 10; ++digit)
4546 make_fullwidth_digit(&temp[digit], digit);
4550 getyx(stdscr, y, x);
4551 digit = (y + x / 2) % 10;
4552 } while (add_wch(&temp[digit]) != ERR);
4556 fill_wide_panel(PANEL * pan)
4558 WINDOW *win = panel_window(pan);
4559 const char *userptr = (const char *) panel_userptr(pan);
4560 int num = (userptr && *userptr) ? userptr[1] : '?';
4564 wprintw(win, "-pan%c-", num);
4567 for (y = 2; y < getmaxy(win) - 1; y++) {
4568 for (x = 1; x < getmaxx(win) - 1; x++) {
4570 waddch(win, UChar(num));
4576 #define MAX_PANELS 5
4579 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4581 int which = cmd[1] - '0';
4586 hide_panel(px[which]);
4589 show_panel(px[which]);
4592 top_panel(px[which]);
4595 bottom_panel(px[which]);
4602 wait_a_while(nap_msec);
4606 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4610 PANEL *px[MAX_PANELS + 1];
4612 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4616 for (count = 0; count < 5; count++) {
4617 px[1] = mkpanel(COLOR_RED,
4622 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4624 px[2] = mkpanel(COLOR_GREEN,
4629 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4631 px[3] = mkpanel(COLOR_YELLOW,
4636 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4638 px[4] = mkpanel(COLOR_BLUE,
4643 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4645 px[5] = mkpanel(COLOR_MAGENTA,
4650 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4662 wait_a_while(nap_msec);
4664 saywhat("h3 s1 s2 s4 s5");
4665 move_panel(px[1], 0, 0);
4672 wait_a_while(nap_msec);
4674 canned_panel(px, "s1");
4675 canned_panel(px, "s2");
4678 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4680 wait_a_while(nap_msec);
4682 canned_panel(px, "s3");
4685 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4687 wait_a_while(nap_msec);
4689 canned_panel(px, "b3");
4690 canned_panel(px, "s4");
4691 canned_panel(px, "s5");
4692 canned_panel(px, "t3");
4693 canned_panel(px, "t1");
4694 canned_panel(px, "t2");
4695 canned_panel(px, "t3");
4696 canned_panel(px, "t4");
4698 for (itmp = 0; itmp < 6; itmp++) {
4699 WINDOW *w4 = panel_window(px[4]);
4700 WINDOW *w5 = panel_window(px[5]);
4703 wmove(w4, LINES / 8, 1);
4704 waddstr(w4, mod[itmp]);
4705 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4706 wmove(w5, LINES / 6, 1);
4707 waddstr(w5, mod[itmp]);
4709 wait_a_while(nap_msec);
4712 wmove(w4, LINES / 6, 1);
4713 waddstr(w4, mod[itmp]);
4714 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4715 wmove(w5, LINES / 8, 1);
4716 waddstr(w5, mod[itmp]);
4718 wait_a_while(nap_msec);
4722 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4724 wait_a_while(nap_msec);
4726 canned_panel(px, "t5");
4727 canned_panel(px, "t2");
4728 canned_panel(px, "t1");
4729 canned_panel(px, "d2");
4730 canned_panel(px, "h3");
4731 canned_panel(px, "d1");
4732 canned_panel(px, "d4");
4733 canned_panel(px, "d5");
4734 canned_panel(px, "d3");
4736 wait_a_while(nap_msec);
4745 #endif /* USE_LIBPANEL */
4747 /****************************************************************************
4751 ****************************************************************************/
4755 static bool pending_pan = FALSE;
4756 static bool show_panner_legend = TRUE;
4759 panner_legend(int line)
4761 static const char *const legend[] =
4763 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4764 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4765 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4766 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4768 int n = ((int) SIZEOF(legend) - (LINES - line));
4770 if (move(line, 0) != ERR) {
4771 if (show_panner_legend)
4772 printw("%s", legend[n]);
4774 return show_panner_legend;
4781 panner_h_cleanup(int from_y, int from_x, int to_x)
4783 if (!panner_legend(from_y))
4784 do_h_line(from_y, from_x, ' ', to_x);
4788 panner_v_cleanup(int from_y, int from_x, int to_y)
4790 if (!panner_legend(from_y))
4791 do_v_line(from_y, from_x, ' ', to_y);
4795 fill_pad(WINDOW *panpad, bool pan_lines)
4798 unsigned gridcount = 0;
4800 wmove(panpad, 0, 0);
4801 for (y = 0; y < getmaxy(panpad); y++) {
4802 for (x = 0; x < getmaxx(panpad); x++) {
4803 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4804 if (y == 0 && x == 0)
4805 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4807 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4808 else if (y == 0 || x == 0)
4809 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4811 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4812 (int) (gridcount++ % 26)));
4813 } else if (y % GRIDSIZE == 0)
4814 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4815 else if (x % GRIDSIZE == 0)
4816 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4818 waddch(panpad, ' ');
4825 int top_x, int top_y, int porty, int portx,
4826 int (*pgetc) (WINDOW *))
4828 #if HAVE_GETTIMEOFDAY
4829 struct timeval before, after;
4832 bool pan_lines = FALSE;
4833 bool scrollers = TRUE;
4836 int pxmax, pymax, lowend, highend, c;
4838 getmaxyx(pad, pymax, pxmax);
4839 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4843 #ifdef NCURSES_VERSION
4845 * During shell-out, the user may have resized the window. Adjust
4846 * the port size of the pad to accommodate this. Ncurses automatically
4847 * resizes all of the normal windows to fit on the new screen.
4865 show_panner_legend = !show_panner_legend;
4866 panner_legend(LINES - 4);
4867 panner_legend(LINES - 3);
4868 panner_legend(LINES - 2);
4869 panner_legend(LINES - 1);
4872 pan_lines = !pan_lines;
4873 fill_pad(pad, pan_lines);
4874 pending_pan = FALSE;
4877 #if HAVE_GETTIMEOFDAY
4881 panner_legend(LINES - 1);
4885 scrollers = !scrollers;
4888 /* Move the top-left corner of the pad, keeping the bottom-right
4891 case 'h': /* increase-columns: move left edge to left */
4895 panner_v_cleanup(top_y, top_x, porty);
4900 case 'j': /* decrease-lines: move top-edge down */
4904 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
4909 case 'k': /* increase-lines: move top-edge up */
4914 panner_h_cleanup(top_y, top_x, portx);
4918 case 'l': /* decrease-columns: move left-edge to right */
4922 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
4927 /* Move the bottom-right corner of the pad, keeping the top-left
4930 case KEY_IC: /* increase-columns: move right-edge to right */
4931 if (portx >= pxmax || portx >= COLS)
4934 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
4939 case KEY_IL: /* increase-lines: move bottom-edge down */
4940 if (porty >= pymax || porty >= LINES)
4943 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
4948 case KEY_DC: /* decrease-columns: move bottom edge up */
4953 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
4957 case KEY_DL: /* decrease-lines */
4962 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
4966 case KEY_LEFT: /* pan leftwards */
4973 case KEY_RIGHT: /* pan rightwards */
4974 if (basex + portx - (pymax > porty) < pxmax)
4980 case KEY_UP: /* pan upwards */
4987 case KEY_DOWN: /* pan downwards */
4988 if (basey + porty - (pxmax > portx) < pymax)
5003 basey = pymax - porty;
5013 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5014 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5015 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5017 if (scrollers && (pxmax > portx - 1)) {
5018 int length = (portx - top_x - 1);
5019 float ratio = ((float) length) / ((float) pxmax);
5021 lowend = (int) ((float) top_x + ((float) basex * ratio));
5022 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5024 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5025 if (highend < portx) {
5027 do_h_line(porty - 1, lowend, ' ', highend + 1);
5029 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5032 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5034 if (scrollers && (pymax > porty - 1)) {
5035 int length = (porty - top_y - 1);
5036 float ratio = ((float) length) / ((float) pymax);
5038 lowend = (int) ((float) top_y + ((float) basey * ratio));
5039 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5041 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5042 if (highend < porty) {
5044 do_v_line(lowend, portx - 1, ' ', highend + 1);
5046 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5049 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5051 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5052 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5053 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5056 #if HAVE_GETTIMEOFDAY
5057 gettimeofday(&before, 0);
5059 wnoutrefresh(stdscr);
5064 porty - (pxmax > portx) - 1,
5065 portx - (pymax > porty) - 1);
5068 #if HAVE_GETTIMEOFDAY
5069 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5072 gettimeofday(&after, 0);
5073 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5074 move(LINES - 1, COLS - 12);
5075 printw("Secs: %2.03f", elapsed);
5082 ((c = pgetc(pad)) != KEY_EXIT);
5084 scrollok(stdscr, TRUE); /* reset to driver's default */
5088 padgetch(WINDOW *win)
5094 if ((pending_pan = (count > 0)) != FALSE) {
5096 pending_pan = (count != 0);
5099 switch (c = wGetchar(win)) {
5135 case ERR: /* FALLTHRU */
5141 if (c >= '0' && c <= '9') {
5142 count = count * 10 + (c - '0');
5156 #define PAD_HIGH 200
5157 #define PAD_WIDE 200
5161 /* Demonstrate pads. */
5163 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5166 Cannot("cannot create requested pad");
5170 fill_pad(panpad, FALSE);
5172 panner_legend(LINES - 4);
5173 panner_legend(LINES - 3);
5174 panner_legend(LINES - 2);
5175 panner_legend(LINES - 1);
5177 keypad(panpad, TRUE);
5179 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5180 * We'll still be able to widen it during a test, since that's required
5181 * for testing boundaries.
5183 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
5190 /****************************************************************************
5192 * Tests from John Burnell's PDCurses tester
5194 ****************************************************************************/
5197 Continue(WINDOW *win)
5201 MvWAddStr(win, 10, 1, " Press any key to continue");
5207 flushinp_test(WINDOW *win)
5208 /* Input test, adapted from John Burnell's PDCurses tester */
5210 int w, h, bx, by, sw, sh, i;
5215 getmaxyx(win, h, w);
5216 getbegyx(win, by, bx);
5219 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5224 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5225 wbkgd(subWin, COLOR_PAIR(2) | ' ');
5228 (void) wattrset(subWin, A_BOLD);
5229 box(subWin, ACS_VLINE, ACS_HLINE);
5230 MvWAddStr(subWin, 2, 1, "This is a subwindow");
5234 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5235 * it only happened to "work" on SVr4 because that implementation does not
5236 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5237 * test behavior, we're using 'cbreak()', which will allow a single
5238 * character to return without needing a newline. - T.Dickey 1997/10/11.
5241 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
5243 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
5244 MvWAddStr(win, 3, 1,
5245 "These should be discarded (not echoed) after the subwindow goes away.");
5248 for (i = 0; i < 5; i++) {
5249 MvWPrintw(subWin, 1, 1, "Time = %d", i);
5261 MvWAddStr(win, 2, 1,
5262 "If you were still typing when the window timer expired,");
5263 MvWAddStr(win, 3, 1,
5264 "or else you typed nothing at all while it was running,");
5265 MvWAddStr(win, 4, 1,
5266 "test was invalid. You'll see garbage or nothing at all. ");
5267 MvWAddStr(win, 6, 1, "Press a key");
5273 MvWAddStr(win, 12, 0,
5274 "If you see any key other than what you typed, flushinp() is broken.");
5283 "What you typed should now have been deleted; if not, wdelch() failed.");
5289 /****************************************************************************
5293 ****************************************************************************/
5301 menu_virtualize(int c)
5303 if (c == '\n' || c == KEY_EXIT)
5304 return (MAX_COMMAND + 1);
5306 return (REQ_SCR_ULINE);
5308 return (REQ_SCR_DLINE);
5309 else if (c == 'b' || c == KEY_NPAGE)
5310 return (REQ_SCR_UPAGE);
5311 else if (c == 'f' || c == KEY_PPAGE)
5312 return (REQ_SCR_DPAGE);
5313 else if (c == 'n' || c == KEY_DOWN)
5314 return (REQ_NEXT_ITEM);
5315 else if (c == 'p' || c == KEY_UP)
5316 return (REQ_PREV_ITEM);
5318 return (REQ_TOGGLE_ITEM);
5326 static CONST_MENUS char *animals[] =
5339 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5340 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5348 ITEM *items[SIZEOF(animals)];
5350 CONST_MENUS char **ap;
5351 int mrows, mcols, c;
5354 #ifdef NCURSES_MOUSE_VERSION
5355 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5357 MvAddStr(0, 0, "This is the menu test:");
5358 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
5359 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
5361 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
5362 MvAddStr(5, 0, " Press return to exit.");
5365 for (ap = animals; *ap; ap++) {
5366 if ((*ip = new_item(*ap, "")) != 0)
5371 m = new_menu(items);
5373 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
5374 scale_menu(m, &mrows, &mcols);
5376 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5377 set_menu_win(m, menuwin);
5378 keypad(menuwin, TRUE);
5381 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5385 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
5386 if (c == E_NOT_POSTED)
5388 if (c == E_REQUEST_DENIED)
5393 MvPrintw(LINES - 2, 0,
5394 "You chose: %s\n", item_name(current_item(m)));
5395 (void) addstr("Press any key to continue...");
5402 for (ip = items; *ip; ip++)
5404 #ifdef NCURSES_MOUSE_VERSION
5405 mousemask(0, (mmask_t *) 0);
5410 #define T_TBL(name) { #name, name }
5416 T_TBL(TRACE_DISABLE),
5419 T_TBL(TRACE_UPDATE),
5421 T_TBL(TRACE_CHARPUT),
5422 T_TBL(TRACE_ORDINARY),
5424 T_TBL(TRACE_VIRTPUT),
5425 T_TBL(TRACE_IEVENT),
5427 T_TBL(TRACE_ICALLS),
5428 T_TBL(TRACE_CCALLS),
5429 T_TBL(TRACE_DATABASE),
5431 T_TBL(TRACE_MAXIMUM),
5438 tracetrace(unsigned tlevel)
5445 for (n = 0; t_tbl[n].name != 0; n++)
5446 need += strlen(t_tbl[n].name) + 2;
5447 buf = typeMalloc(char, need);
5449 sprintf(buf, "0x%02x = {", tlevel);
5451 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5453 for (n = 1; t_tbl[n].name != 0; n++)
5454 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5455 strcat(buf, t_tbl[n].name);
5459 if (buf[strlen(buf) - 2] == ',')
5460 buf[strlen(buf) - 2] = '\0';
5461 return (strcat(buf, "}"));
5464 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5468 run_trace_menu(MENU * m)
5474 bool changed = FALSE;
5475 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5476 case E_UNKNOWN_COMMAND:
5479 items = menu_items(m);
5480 i = current_item(m);
5481 if (i == items[0]) {
5482 if (item_value(i)) {
5483 for (p = items + 1; *p != 0; p++)
5484 if (item_value(*p)) {
5485 set_item_value(*p, FALSE);
5490 for (p = items + 1; *p != 0; p++)
5491 if (item_value(*p)) {
5492 set_item_value(items[0], FALSE);
5505 /* interactively set the trace level */
5508 ITEM *items[SIZEOF(t_tbl)];
5515 MvAddStr(0, 0, "Interactively set trace level:");
5516 MvAddStr(2, 0, " Press space bar to toggle a selection.");
5517 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
5518 MvAddStr(4, 0, " Press return to set the trace level.");
5519 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5523 for (n = 0; t_tbl[n].name != 0; n++) {
5524 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
5530 m = new_menu(items);
5532 set_menu_format(m, 0, 2);
5533 scale_menu(m, &mrows, &mcols);
5535 menu_opts_off(m, O_ONEVALUE);
5536 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5537 set_menu_win(m, menuwin);
5538 keypad(menuwin, TRUE);
5541 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5545 for (ip = menu_items(m); *ip; ip++) {
5546 unsigned mask = t_tbl[item_index(*ip)].mask;
5548 set_item_value(*ip, _nc_tracing == 0);
5549 else if ((mask & _nc_tracing) == mask)
5550 set_item_value(*ip, TRUE);
5553 while (run_trace_menu(m))
5557 for (ip = menu_items(m); *ip; ip++)
5558 if (item_value(*ip))
5559 newtrace |= t_tbl[item_index(*ip)].mask;
5561 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5563 MvPrintw(LINES - 2, 0,
5564 "Trace level is %s\n", tracetrace(_nc_tracing));
5565 (void) addstr("Press any key to continue...");
5572 for (ip = items; *ip; ip++)
5576 #endif /* USE_LIBMENU */
5578 /****************************************************************************
5582 ****************************************************************************/
5585 make_label(int frow, int fcol, NCURSES_CONST char *label)
5587 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5590 set_field_buffer(f, 0, label);
5591 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
5597 make_field(int frow, int fcol, int rows, int cols, bool secure)
5599 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5602 set_field_back(f, A_UNDERLINE);
5603 set_field_userptr(f, (void *) 0);
5609 display_form(FORM * f)
5614 scale_form(f, &rows, &cols);
5616 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5618 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5623 if (post_form(f) != E_OK)
5628 erase_form(FORM * f)
5630 WINDOW *w = form_win(f);
5631 WINDOW *s = form_sub(f);
5641 edit_secure(FIELD * me, int c)
5643 int rows, cols, frow, fcol, nrow, nbuf;
5645 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5647 char *source = field_buffer(me, 1);
5651 strcpy(temp, source ? source : "");
5652 len = (long) (char *) field_userptr(me);
5654 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5655 temp[len++] = (char) c;
5657 set_field_buffer(me, 1, temp);
5677 case REQ_RIGHT_CHAR:
5679 c = 0; /* we don't want to do inline editing */
5684 set_field_buffer(me, 1, temp);
5691 set_field_buffer(me, 1, temp);
5696 set_field_userptr(me, (void *) len);
5702 form_virtualize(FORM * f, WINDOW *w)
5705 static const struct {
5709 { CTRL('A'), REQ_NEXT_CHOICE },
5710 { CTRL('B'), REQ_PREV_WORD },
5711 { CTRL('C'), REQ_CLR_EOL },
5712 { CTRL('D'), REQ_DOWN_FIELD },
5713 { CTRL('E'), REQ_END_FIELD },
5714 { CTRL('F'), REQ_NEXT_PAGE },
5715 { CTRL('G'), REQ_DEL_WORD },
5716 { CTRL('H'), REQ_DEL_PREV },
5717 { CTRL('I'), REQ_INS_CHAR },
5718 { CTRL('K'), REQ_CLR_EOF },
5719 { CTRL('L'), REQ_LEFT_FIELD },
5720 { CTRL('M'), REQ_NEW_LINE },
5721 { CTRL('N'), REQ_NEXT_FIELD },
5722 { CTRL('O'), REQ_INS_LINE },
5723 { CTRL('P'), REQ_PREV_FIELD },
5724 { CTRL('R'), REQ_RIGHT_FIELD },
5725 { CTRL('S'), REQ_BEG_FIELD },
5726 { CTRL('U'), REQ_UP_FIELD },
5727 { CTRL('V'), REQ_DEL_CHAR },
5728 { CTRL('W'), REQ_NEXT_WORD },
5729 { CTRL('X'), REQ_CLR_FIELD },
5730 { CTRL('Y'), REQ_DEL_LINE },
5731 { CTRL('Z'), REQ_PREV_CHOICE },
5732 { ESCAPE, MAX_FORM_COMMAND + 1 },
5733 { KEY_BACKSPACE, REQ_DEL_PREV },
5734 { KEY_DOWN, REQ_DOWN_CHAR },
5735 { KEY_END, REQ_LAST_FIELD },
5736 { KEY_HOME, REQ_FIRST_FIELD },
5737 { KEY_LEFT, REQ_LEFT_CHAR },
5738 { KEY_LL, REQ_LAST_FIELD },
5739 { KEY_NEXT, REQ_NEXT_FIELD },
5740 { KEY_NPAGE, REQ_NEXT_PAGE },
5741 { KEY_PPAGE, REQ_PREV_PAGE },
5742 { KEY_PREVIOUS, REQ_PREV_FIELD },
5743 { KEY_RIGHT, REQ_RIGHT_CHAR },
5744 { KEY_UP, REQ_UP_CHAR },
5745 { QUIT, MAX_FORM_COMMAND + 1 }
5749 static int mode = REQ_INS_MODE;
5750 int c = wGetchar(w);
5752 FIELD *me = current_field(f);
5753 bool current = TRUE;
5755 if (c == CTRL(']')) {
5756 if (mode == REQ_INS_MODE) {
5757 mode = REQ_OVL_MODE;
5759 mode = REQ_INS_MODE;
5763 for (n = 0; n < SIZEOF(lookup); n++) {
5764 if (lookup[n].code == c) {
5765 c = lookup[n].result;
5770 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5773 * Force the field that the user is typing into to be in reverse video,
5774 * while the other fields are shown underlined.
5789 case REQ_LEFT_FIELD:
5791 case REQ_RIGHT_CHAR:
5795 current = (c < KEY_MAX);
5799 c = edit_secure(me, c);
5800 set_field_back(me, A_REVERSE);
5802 c = edit_secure(me, c);
5803 set_field_back(me, A_UNDERLINE);
5809 my_form_driver(FORM * form, int c)
5811 if (c == (MAX_FORM_COMMAND + 1)
5812 && form_driver(form, REQ_VALIDATION) == E_OK)
5820 #ifdef NCURSES_VERSION
5821 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5822 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5824 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5825 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5829 * Allow a middle initial, optionally with a '.' to end it.
5832 FIELDCHECK_CB(mi_field_check)
5834 char *s = field_buffer(fld, 0);
5838 for (n = 0; s[n] != '\0'; ++n) {
5845 } else if (isspace(UChar(s[n]))) {
5850 if (!isspace(UChar(s[n])))
5856 /* force the form to display a leading capital */
5857 if (islower(UChar(s[0]))) {
5858 s[0] = (char) toupper(UChar(s[0]));
5859 set_field_buffer(fld, 0, s);
5865 CHAR_CHECK_CB(mi_char_check)
5867 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5871 * Passwords should be at least 6 characters.
5874 FIELDCHECK_CB(pw_field_check)
5876 char *s = field_buffer(fld, 0);
5879 for (n = 0; s[n] != '\0'; ++n) {
5880 if (isspace(UChar(s[n]))) {
5889 CHAR_CHECK_CB(pw_char_check)
5891 return (isgraph(ch) ? TRUE : FALSE);
5899 FIELD *f[12], *secure;
5900 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
5901 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
5902 int finished = 0, c;
5905 #ifdef NCURSES_MOUSE_VERSION
5906 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5910 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
5911 addstr("^N -- go to next field ^P -- go to previous field\n");
5912 addstr("Home -- go to first field End -- go to last field\n");
5913 addstr("^L -- go to field to left ^R -- go to field to right\n");
5914 addstr("^U -- move upward to field ^D -- move downward to field\n");
5915 addstr("^W -- go to next word ^B -- go to previous word\n");
5916 addstr("^S -- go to start of field ^E -- go to end of field\n");
5917 addstr("^H -- delete previous char ^Y -- delete line\n");
5918 addstr("^G -- delete current word ^C -- clear to end of line\n");
5919 addstr("^K -- clear to end of field ^X -- clear field\n");
5920 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
5922 MvAddStr(4, 57, "Forms Entry Test");
5926 /* describe the form */
5927 memset(f, 0, sizeof(f));
5928 f[n++] = make_label(0, 15, "Sample Form");
5930 f[n++] = make_label(2, 0, "Last Name");
5931 f[n++] = make_field(3, 0, 1, 18, FALSE);
5932 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5934 f[n++] = make_label(2, 20, "First Name");
5935 f[n++] = make_field(3, 20, 1, 12, FALSE);
5936 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5938 f[n++] = make_label(2, 34, "Middle Name");
5939 f[n++] = make_field(3, 34, 1, 12, FALSE);
5940 set_field_type(f[n - 1], fty_middle);
5942 f[n++] = make_label(5, 0, "Comments");
5943 f[n++] = make_field(6, 0, 4, 46, FALSE);
5945 f[n++] = make_label(5, 20, "Password:");
5947 f[n++] = make_field(5, 30, 1, 9, TRUE);
5948 set_field_type(f[n - 1], fty_passwd);
5951 if ((form = new_form(f)) != 0) {
5957 nonl(); /* lets us read ^M's */
5959 switch (form_driver(form, c = form_virtualize(form, w))) {
5961 MvAddStr(5, 57, field_buffer(secure, 1));
5965 case E_UNKNOWN_COMMAND:
5966 finished = my_form_driver(form, c);
5978 for (c = 0; f[c] != 0; c++)
5980 free_fieldtype(fty_middle);
5981 free_fieldtype(fty_passwd);
5985 #ifdef NCURSES_MOUSE_VERSION
5986 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5989 #endif /* USE_LIBFORM */
5991 /****************************************************************************
5995 ****************************************************************************/
5998 fillwin(WINDOW *win, char ch)
6003 getmaxyx(win, y1, x1);
6004 for (y = 0; y < y1; y++) {
6006 for (x = 0; x < x1; x++)
6007 waddch(win, UChar(ch));
6012 crosswin(WINDOW *win, char ch)
6017 getmaxyx(win, y1, x1);
6018 for (y = 0; y < y1; y++) {
6019 for (x = 0; x < x1; x++)
6020 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
6021 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
6023 waddch(win, UChar(ch));
6028 #define OVERLAP_FLAVORS 5
6031 overlap_helpitem(int state, int item, char *message)
6033 int row = (item / 2);
6034 int col = ((item % 2) ? COLS / 2 : 0);
6036 move(LINES - 6 + row, col);
6037 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6042 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6044 short cpair = (short) (1 + (flavor * 2) + col);
6048 (void) wattrset(win, A_NORMAL);
6051 (void) wattrset(win, A_BOLD);
6054 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6055 (void) wattrset(win, (attr_t) COLOR_PAIR(cpair) | A_NORMAL);
6058 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6059 (void) wattrset(win, (attr_t) COLOR_PAIR(cpair) | A_BOLD);
6065 overlap_test_2_attr(WINDOW *win, int flavor, int col)
6067 short cpair = (short) (9 + (flavor * 2) + col);
6077 init_pair(cpair, COLOR_RED, COLOR_GREEN);
6078 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
6081 wbkgdset(win, ' ' | A_NORMAL);
6087 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
6092 const char *ths, *tht;
6096 state += OVERLAP_FLAVORS;
6097 state = state % OVERLAP_FLAVORS;
6098 assert(state >= 0 && state < OVERLAP_FLAVORS);
6100 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
6103 ths = col ? "B" : "A";
6104 tht = col ? "A" : "B";
6109 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
6117 overlap_test_1_attr(stdscr, flavors[row], col);
6118 sprintf(msg, "fill window %s with letter %s.", ths, ths);
6126 switch (flavors[row]) {
6128 sprintf(msg, "cross pattern in window %s.", ths);
6131 sprintf(msg, "draw box in window %s.", ths);
6134 sprintf(msg, "set background of window %s.", ths);
6137 sprintf(msg, "reset background of window %s.", ths);
6143 sprintf(msg, "clear window %s.", ths);
6147 switch (flavors[row]) {
6149 sprintf(msg, "overwrite %s onto %s.", ths, tht);
6152 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
6155 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
6158 sprintf(msg, "overlay %s onto %s.", ths, tht);
6163 overlap_helpitem(state, item, msg);
6164 (void) wattrset(stdscr, A_NORMAL);
6165 wbkgdset(stdscr, ' ' | A_NORMAL);
6168 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
6169 state, flavors[state]);
6175 overlap_test_0(WINDOW *a, WINDOW *b)
6185 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
6187 overlap_test_1_attr(a, flavor, col);
6189 (void) wattrset(a, A_NORMAL);
6193 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6195 overlap_test_2_attr(a, flavor, col);
6204 /* done in overlap_test_2_attr */
6207 /* done in overlap_test_2_attr */
6213 overlap_test_3(WINDOW *a)
6220 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
6227 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
6230 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
6238 /* test effects of overlapping windows */
6243 int state, flavor[OVERLAP_FLAVORS];
6245 WINDOW *win1 = newwin(9, 20, 3, 3);
6246 WINDOW *win2 = newwin(9, 20, 9, 16);
6252 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
6253 printw("the shared region of two overlapping windows A and B. The cross\n");
6254 printw("pattern in each window does not overlap the other.\n");
6256 memset(flavor, 0, sizeof(flavor));
6257 state = overlap_help(0, flavor);
6259 while (!isQuit(ch = Getchar()))
6261 case 'a': /* refresh window A first, then B */
6262 overlap_test_0(win1, win2);
6265 case 'b': /* refresh window B first, then A */
6266 overlap_test_0(win2, win1);
6269 case 'c': /* fill window A so it's visible */
6270 overlap_test_1(flavor[1], 0, win1, 'A');
6273 case 'd': /* fill window B so it's visible */
6274 overlap_test_1(flavor[1], 1, win2, 'B');
6277 case 'e': /* cross test pattern in window A */
6278 overlap_test_2(flavor[2], 0, win1, 'A');
6281 case 'f': /* cross test pattern in window A */
6282 overlap_test_2(flavor[2], 1, win2, 'B');
6285 case 'g': /* clear window A */
6286 overlap_test_3(win1);
6289 case 'h': /* clear window B */
6290 overlap_test_3(win2);
6293 case 'i': /* overwrite A onto B */
6294 overlap_test_4(flavor[4], win1, win2);
6297 case 'j': /* overwrite B onto A */
6298 overlap_test_4(flavor[4], win2, win1);
6303 state = overlap_help(state + 1, flavor);
6308 state = overlap_help(state - 1, flavor);
6313 state = overlap_help(state, flavor);
6317 state = overlap_help(state, flavor);
6332 /****************************************************************************
6336 ****************************************************************************/
6339 do_single_test(const char c)
6340 /* perform a single specified test */
6347 #if USE_WIDEC_SUPPORT
6357 #if USE_WIDEC_SUPPORT
6365 Cannot("does not support color.");
6370 #if USE_WIDEC_SUPPORT
6373 Cannot("does not support color.");
6381 Cannot("does not support color.");
6382 else if (!can_change_color())
6383 Cannot("has hardwired color values.");
6394 #if USE_WIDEC_SUPPORT
6403 #if USE_WIDEC_SUPPORT
6411 demo_panels(init_panel, fill_panel);
6415 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6417 demo_panels(init_wide_panel, fill_wide_panel);
6426 flushinp_test(stdscr);
6430 test_sgr_attributes();
6453 #if USE_LIBMENU && defined(TRACE)
6472 static const char *const tbl[] =
6474 "Usage: ncurses [options]"
6477 #ifdef NCURSES_VERSION
6478 ," -a f,b set default-colors (assumed white-on-black)"
6479 ," -d use default-colors if terminal supports them"
6482 ," -e fmt specify format for soft-keys test (e)"
6485 ," -f rip-off footer line (can repeat)"
6486 ," -h rip-off header line (can repeat)"
6488 ," -m do not use colors"
6489 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6491 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6494 ," -t mask specify default trace-level (may toggle with ^T)"
6498 for (n = 0; n < SIZEOF(tbl); n++)
6499 fprintf(stderr, "%s\n", tbl[n]);
6500 ExitProgram(EXIT_FAILURE);
6504 set_terminal_modes(void)
6509 scrollok(stdscr, TRUE);
6510 idlok(stdscr, TRUE);
6511 keypad(stdscr, TRUE);
6516 announce_sig(int sig)
6518 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6524 rip_footer(WINDOW *win, int cols)
6526 wbkgd(win, A_REVERSE);
6529 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
6535 rip_header(WINDOW *win, int cols)
6537 wbkgd(win, A_REVERSE);
6540 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
6544 #endif /* HAVE_RIPOFFLINE */
6552 (void) puts("This is the ncurses main menu");
6553 (void) puts("a = keyboard and mouse input test");
6554 #if USE_WIDEC_SUPPORT
6555 (void) puts("A = wide-character keyboard and mouse input test");
6557 (void) puts("b = character attribute test");
6558 #if USE_WIDEC_SUPPORT
6559 (void) puts("B = wide-character attribute test");
6561 (void) puts("c = color test pattern");
6562 #if USE_WIDEC_SUPPORT
6563 (void) puts("C = color test pattern using wide-character calls");
6566 (void) puts("d = edit RGB color values");
6568 (void) puts("e = exercise soft keys");
6569 #if USE_WIDEC_SUPPORT
6570 (void) puts("E = exercise soft keys using wide-characters");
6573 (void) puts("f = display ACS characters");
6574 #if USE_WIDEC_SUPPORT
6575 (void) puts("F = display Wide-ACS characters");
6577 (void) puts("g = display windows and scrolling");
6578 (void) puts("i = test of flushinp()");
6579 (void) puts("k = display character attributes");
6581 (void) puts("m = menu code test");
6584 (void) puts("o = exercise panels library");
6585 #if USE_WIDEC_SUPPORT
6586 (void) puts("O = exercise panels with wide-characters");
6589 (void) puts("p = exercise pad features");
6590 (void) puts("q = quit");
6592 (void) puts("r = exercise forms code");
6594 (void) puts("s = overlapping-refresh test");
6595 #if USE_LIBMENU && defined(TRACE)
6596 (void) puts("t = set trace level");
6598 (void) puts("? = repeat this command summary");
6600 (void) fputs("> ", stdout);
6601 (void) fflush(stdout); /* necessary under SVr4 curses */
6604 * This used to be an 'fgets()' call (until 1996/10). However with
6605 * some runtime libraries, mixing stream I/O and 'read()' causes the
6606 * input stream to be flushed when switching between the two.
6611 if (read(fileno(stdin), &ch, 1) <= 0) {
6615 } else if (command == 0 && !isspace(UChar(ch))) {
6617 } else if (ch == '\n' || ch == '\r') {
6618 if ((command == 'd') && !top) {
6619 (void) fputs("Do not nest test-d\n", stdout);
6624 (void) fputs("> ", stdout);
6625 (void) fflush(stdout);
6629 if (do_single_test(command)) {
6631 * This may be overkill; it's intended to reset everything back
6632 * to the initial terminal modes so that tests don't get in
6636 set_terminal_modes();
6641 if (command == '?') {
6642 (void) puts("This is the ncurses capability tester.");
6644 puts("You may select a test from the main menu by typing the");
6646 puts("key letter of the choice (the letter to left of the =)");
6648 puts("at the > prompt. Type `q' to exit.");
6656 /*+-------------------------------------------------------------------------
6658 --------------------------------------------------------------------------*/
6660 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6661 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6664 main(int argc, char *argv[])
6668 #ifdef NCURSES_VERSION
6669 int default_fg = COLOR_WHITE;
6670 int default_bg = COLOR_BLACK;
6671 bool assumed_colors = FALSE;
6672 bool default_colors = FALSE;
6674 char *palette_file = 0;
6675 bool monochrome = FALSE;
6677 setlocale(LC_ALL, "");
6679 while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) {
6681 #ifdef NCURSES_VERSION
6683 assumed_colors = TRUE;
6684 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6687 default_colors = TRUE;
6691 my_e_param = atoi(optarg);
6692 #ifdef NCURSES_VERSION
6693 if (my_e_param > 3) /* allow extended layouts */
6702 ripoffline(-1, rip_footer);
6705 ripoffline(1, rip_header);
6707 #endif /* HAVE_RIPOFFLINE */
6712 palette_file = optarg;
6716 nap_msec = (int) atol(optarg);
6721 save_trace = (unsigned) strtol(optarg, 0, 0);
6730 * If there's no menus (unlikely for ncurses!), then we'll have to set
6731 * tracing on initially, just in case the user wants to test something that
6732 * doesn't involve wGetchar.
6735 /* enable debugging */
6739 if (!isatty(fileno(stdin)))
6741 #endif /* USE_LIBMENU */
6745 /* tell it we're going to play with soft keys */
6746 slk_init(my_e_param);
6750 /* set up null signal catcher so we can see what interrupts to getch do */
6751 signal(SIGUSR1, announce_sig);
6754 /* we must initialize the curses data structure only once */
6758 /* tests, in general, will want these modes */
6759 use_colors = monochrome ? FALSE : has_colors();
6763 #ifdef NCURSES_VERSION_PATCH
6764 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6765 #if HAVE_USE_DEFAULT_COLORS
6766 if (default_colors) {
6767 use_default_colors();
6770 #if NCURSES_VERSION_PATCH >= 20000708
6772 assume_default_colors(default_fg, default_bg);
6775 #else /* normal SVr4 curses */
6776 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6778 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6780 if (can_change_color()) {
6782 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
6783 for (cp = 0; cp < max_colors; ++cp) {
6785 &all_colors[cp].red,
6786 &all_colors[cp].green,
6787 &all_colors[cp].blue);
6789 if (palette_file != 0) {
6790 FILE *fp = fopen(palette_file, "r");
6792 char buffer[BUFSIZ];
6793 int red, green, blue;
6795 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6796 if (sscanf(buffer, "scale:%d", &c) == 1) {
6798 } else if (sscanf(buffer, "%d:%d %d %d",
6807 all_colors[c].red = (short) ((red * 1000) / scale);
6808 all_colors[c].green = (short) ((green * 1000) / scale);
6809 all_colors[c].blue = (short) ((blue * 1000) / scale);
6817 set_terminal_modes();
6821 * Return to terminal mode, so we're guaranteed of being able to
6822 * select terminal commands even if the capabilities are wrong.
6826 #if HAVE_CURSES_VERSION
6827 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6828 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6829 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6830 NCURSES_VERSION_MAJOR,
6831 NCURSES_VERSION_MINOR,
6832 NCURSES_VERSION_PATCH);
6834 (void) puts("Welcome to ncurses. Press ? for help.");
6839 ExitProgram(EXIT_SUCCESS);
6842 /* ncurses.c ends here */