1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
28 /****************************************************************************
31 ncurses.c --- ncurses library exerciser
37 An interactive test module for the ncurses library.
40 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
41 Thomas E. Dickey (beginning revision 1.27 in 1996).
43 $Id: ncurses.c,v 1.336 2009/01/25 00:39:14 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
109 #ifdef CURSES_WACS_ARRAY
110 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
111 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
112 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
113 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
114 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
115 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
116 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
122 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
123 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
124 #define reset_wchars(state) memset(&state, 0, sizeof(state))
125 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
126 #define count_wchars(src, len, state) wcstombs(0, src, len)
127 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
128 #define reset_wchars(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
133 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
134 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
135 #define reset_mbytes(state) memset(&state, 0, sizeof(state))
136 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
137 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
138 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
139 #define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
143 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
145 #define P(string) printw("%s\n", string)
147 #define BLANK ' ' /* this is the background character */
150 static int max_colors; /* the actual number of colors we'll use */
151 static int min_colors; /* the minimum color code */
152 static bool use_colors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
163 static RGB_DATA *all_colors;
165 static void main_menu(bool);
167 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
168 * though we can rely on negative x/y values to stop the macro.
171 do_h_line(int y, int x, chtype c, int to)
174 mvhline(y, x, c, (to) - (x));
178 do_v_line(int y, int x, chtype c, int to)
181 mvvline(y, x, c, (to) - (y));
195 return ((c) == QUIT || (c) == ESCAPE);
197 #define case_QUIT QUIT: case ESCAPE
199 /* Common function to allow ^T to toggle trace-mode in the middle of a test
200 * so that trace-files can be made smaller.
203 wGetchar(WINDOW *win)
207 while ((c = wgetch(win)) == CTRL('T')) {
209 save_trace = _nc_tracing;
210 Trace(("TOGGLE-TRACING OFF"));
213 _nc_tracing = save_trace;
217 Trace(("TOGGLE-TRACING ON"));
224 #define Getchar() wGetchar(stdscr)
226 /* replaces wgetnstr(), since we want to be able to edit values */
228 wGetstring(WINDOW *win, char *buffer, int limit)
235 wattrset(win, A_REVERSE);
237 x = (int) strlen(buffer);
239 if (x > (int) strlen(buffer))
240 x = (int) strlen(buffer);
242 wprintw(win, "%-*s", limit, buffer);
243 wmove(win, y0, x0 + x);
244 switch (ch = wGetchar(win)) {
257 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
275 if (!isprint(ch) || ch >= KEY_MIN) {
277 } else if ((int) strlen(buffer) < limit) {
279 for (j = (int) strlen(buffer) + 1; j > x; --j) {
280 buffer[j] = buffer[j - 1];
282 buffer[x++] = (char) ch;
289 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
298 return (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_of(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
322 make_fullwidth_digit(cchar_t *target, int digit)
326 source[0] = fullwidth_of(digit + '0');
328 setcchar(target, source, A_NORMAL, 0, 0);
332 wGet_wchar(WINDOW *win, wint_t *result)
336 while ((c = wget_wch(win, result)) == CTRL('T')) {
338 save_trace = _nc_tracing;
339 Trace(("TOGGLE-TRACING OFF"));
342 _nc_tracing = save_trace;
346 Trace(("TOGGLE-TRACING ON"));
349 c = wget_wch(win, result);
353 #define Get_wchar(result) wGet_wchar(stdscr, result)
355 /* replaces wgetn_wstr(), since we want to be able to edit values */
357 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
366 wattrset(win, A_REVERSE);
368 x = (int) wcslen(buffer);
370 if (x > (int) wcslen(buffer))
371 x = (int) wcslen(buffer);
373 /* clear the "window' */
375 wprintw(win, "%*s", limit, " ");
377 /* write the existing buffer contents */
379 waddnwstr(win, buffer, limit);
381 /* positions the cursor past character 'x' */
383 waddnwstr(win, buffer, x);
385 switch (wGet_wchar(win, &ch)) {
425 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
445 } else if ((int) wcslen(buffer) < limit) {
447 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
448 buffer[j] = buffer[j - 1];
450 buffer[x++] = (wchar_t) ch;
457 wattroff(win, A_REVERSE);
468 addstr("Press any key to continue... ");
473 Cannot(const char *what)
475 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
480 ShellOut(bool message)
483 addstr("Shelling out...");
488 addstr("returned from shellout.\n");
492 #ifdef NCURSES_MOUSE_VERSION
494 * This function is the same as _tracemouse(), but we cannot count on that
495 * being available in the non-debug library.
498 mouse_decode(MEVENT const *ep)
500 static char buf[80 + (5 * 10) + (32 * 15)];
502 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
503 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
505 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
507 SHOW(BUTTON1_RELEASED, "release-1");
508 SHOW(BUTTON1_PRESSED, "press-1");
509 SHOW(BUTTON1_CLICKED, "click-1");
510 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
511 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
512 #if NCURSES_MOUSE_VERSION == 1
513 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
516 SHOW(BUTTON2_RELEASED, "release-2");
517 SHOW(BUTTON2_PRESSED, "press-2");
518 SHOW(BUTTON2_CLICKED, "click-2");
519 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
520 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
521 #if NCURSES_MOUSE_VERSION == 1
522 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
525 SHOW(BUTTON3_RELEASED, "release-3");
526 SHOW(BUTTON3_PRESSED, "press-3");
527 SHOW(BUTTON3_CLICKED, "click-3");
528 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
529 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
530 #if NCURSES_MOUSE_VERSION == 1
531 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
534 SHOW(BUTTON4_RELEASED, "release-4");
535 SHOW(BUTTON4_PRESSED, "press-4");
536 SHOW(BUTTON4_CLICKED, "click-4");
537 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
538 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
539 #if NCURSES_MOUSE_VERSION == 1
540 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
543 #if NCURSES_MOUSE_VERSION == 2
544 SHOW(BUTTON5_RELEASED, "release-5");
545 SHOW(BUTTON5_PRESSED, "press-5");
546 SHOW(BUTTON5_CLICKED, "click-5");
547 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
548 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
551 SHOW(BUTTON_CTRL, "ctrl");
552 SHOW(BUTTON_SHIFT, "shift");
553 SHOW(BUTTON_ALT, "alt");
554 SHOW(ALL_MOUSE_EVENTS, "all-events");
555 SHOW(REPORT_MOUSE_POSITION, "position");
559 if (buf[strlen(buf) - 1] == ' ')
560 buf[strlen(buf) - 2] = '\0';
561 (void) strcat(buf, "}");
564 #endif /* NCURSES_MOUSE_VERSION */
566 /****************************************************************************
568 * Character input test
570 ****************************************************************************/
572 #define NUM_GETCH_FLAGS 256
573 typedef bool GetchFlags[NUM_GETCH_FLAGS];
576 setup_getch(WINDOW *win, GetchFlags flags)
578 keypad(win, flags['k']); /* should be redundant, but for testing */
579 meta(win, flags['m']); /* force this to a known state */
587 init_getch(WINDOW *win, GetchFlags flags)
589 memset(flags, FALSE, NUM_GETCH_FLAGS);
590 flags[UChar('k')] = (win == stdscr);
591 flags[UChar('m')] = TRUE;
593 setup_getch(win, flags);
597 wgetch_help(WINDOW *win, GetchFlags flags)
599 static const char *help[] =
601 "e -- toggle echo mode"
602 ,"g -- triggers a getstr test"
603 ,"k -- toggle keypad/literal mode"
604 ,"m -- toggle meta (7-bit/8-bit) mode"
607 ,"w -- create a new window"
609 ,"z -- suspend this process"
613 unsigned chk = ((SIZEOF(help) + 1) / 2);
618 printw("Type any key to see its %s value. Also:\n",
619 flags['k'] ? "keypad" : "literal");
620 for (n = 0; n < SIZEOF(help); ++n) {
621 int row = 1 + (int) (n % chk);
622 int col = (n >= chk) ? COLS / 2 : 0;
623 int flg = ((strstr(help[n], "toggle") != 0)
624 && (flags[UChar(*help[n])] != FALSE));
627 mvprintw(row, col, "%s", help[n]);
638 wgetch_wrap(WINDOW *win, int first_y)
640 int last_y = getmaxy(win) - 1;
641 int y = getcury(win) + 1;
649 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
655 static WINSTACK *winstack = 0;
656 static unsigned len_winstack = 0;
669 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
671 unsigned need = (level + 1) * 2;
673 assert(level < COLS);
677 winstack = typeMalloc(WINSTACK, len_winstack);
678 } else if (need >= len_winstack) {
680 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
682 winstack[level].text = txt_win;
683 winstack[level].frame = box_win;
686 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
690 /* this chunk is now done in resize_term() */
697 #define slk_repaint() /* nothing */
701 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
702 * Resize both and paint the box in the parent.
705 resize_boxes(unsigned level, WINDOW *win)
709 int high = LINES - base;
713 wnoutrefresh(stdscr);
717 for (n = 0; n < level; ++n) {
718 wresize(winstack[n].frame, high, wide);
719 wresize(winstack[n].text, high - 2, wide - 2);
722 werase(winstack[n].text);
723 box(winstack[n].frame, 0, 0);
724 wnoutrefresh(winstack[n].frame);
725 wprintw(winstack[n].text,
727 getmaxy(winstack[n].text),
728 getmaxx(winstack[n].text));
729 wnoutrefresh(winstack[n].text);
730 if (winstack[n].text == win)
736 #define forget_boxes() /* nothing */
737 #define remember_boxes(level,text,frame) /* nothing */
741 wgetch_test(unsigned level, WINDOW *win, int delay)
744 int first_y, first_x;
748 bool blocking = (delay < 0);
750 init_getch(win, flags);
751 wtimeout(win, delay);
752 getyx(win, first_y, first_x);
754 wgetch_help(win, flags);
755 wsetscrreg(win, first_y, getmaxy(win) - 1);
759 while ((c = wGetchar(win)) == ERR) {
762 (void) wprintw(win, "%05d: input error", incount);
765 (void) wprintw(win, "%05d: input timed out", incount);
767 wgetch_wrap(win, first_y);
769 if (c == ERR && blocking) {
771 wgetch_wrap(win, first_y);
772 } else if (isQuit(c)) {
774 } else if (c == 'e') {
775 flags[UChar('e')] = !flags[UChar('e')];
776 setup_getch(win, flags);
777 wgetch_help(win, flags);
778 } else if (c == 'g') {
779 waddstr(win, "getstr test: ");
781 wgetnstr(win, buf, sizeof(buf) - 1);
783 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
785 wgetch_wrap(win, first_y);
786 } else if (c == 'k') {
787 flags[UChar('k')] = !flags[UChar('k')];
788 setup_getch(win, flags);
789 wgetch_help(win, flags);
790 } else if (c == 'm') {
791 flags[UChar('m')] = !flags[UChar('m')];
792 setup_getch(win, flags);
793 wgetch_help(win, flags);
794 } else if (c == 's') {
796 } else if (c == 'w') {
797 int high = getmaxy(win) - 1 - first_y + 1;
798 int wide = getmaxx(win) - first_x;
800 int new_y = first_y + getbegy(win);
801 int new_x = first_x + getbegx(win);
803 getyx(win, old_y, old_x);
804 if (high > 2 && wide > 2) {
805 WINDOW *wb = newwin(high, wide, new_y, new_x);
806 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
811 remember_boxes(level, wi, wb);
812 wgetch_test(level + 1, wi, delay);
816 wgetch_help(win, flags);
817 wmove(win, old_y, old_x);
823 } else if (c == 'z') {
824 kill(getpid(), SIGTSTP);
827 wprintw(win, "Key pressed: %04o ", c);
828 #ifdef NCURSES_MOUSE_VERSION
829 if (c == KEY_MOUSE) {
834 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
836 move(event.y, event.x);
840 #endif /* NCURSES_MOUSE_VERSION */
842 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
843 if (c == KEY_RESIZE) {
844 resize_boxes(level, win);
847 (void) waddstr(win, keyname(c));
848 } else if (c >= 0x80) {
849 unsigned c2 = (unsigned) c;
850 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
851 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
855 (void) wprintw(win, "%c", UChar(c));
856 else if (c2 != UChar(c))
857 (void) wprintw(win, "M-%s", unctrl(c2));
859 (void) wprintw(win, "%s", unctrl(c2));
860 waddstr(win, " (high-half character)");
863 (void) wprintw(win, "%c (ASCII printable character)", c);
865 (void) wprintw(win, "%s (ASCII control character)",
868 wgetch_wrap(win, first_y);
875 init_getch(win, flags);
879 begin_getch_test(void)
886 #ifdef NCURSES_MOUSE_VERSION
887 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
890 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
892 getnstr(buf, sizeof(buf) - 1);
896 if (isdigit(UChar(buf[0]))) {
897 delay = atoi(buf) * 100;
907 finish_getch_test(void)
909 #ifdef NCURSES_MOUSE_VERSION
910 mousemask(0, (mmask_t *) 0);
921 int delay = begin_getch_test();
924 wgetch_test(0, stdscr, delay);
929 #if USE_WIDEC_SUPPORT
931 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
932 * Resize both and paint the box in the parent.
934 #if defined(KEY_RESIZE) && HAVE_WRESIZE
936 resize_wide_boxes(unsigned level, WINDOW *win)
940 int high = LINES - base;
944 wnoutrefresh(stdscr);
948 for (n = 0; n < level; ++n) {
949 wresize(winstack[n].frame, high, wide);
950 wresize(winstack[n].text, high - 2, wide - 2);
953 werase(winstack[n].text);
954 box_set(winstack[n].frame, 0, 0);
955 wnoutrefresh(winstack[n].frame);
956 wprintw(winstack[n].text,
958 getmaxy(winstack[n].text),
959 getmaxx(winstack[n].text));
960 wnoutrefresh(winstack[n].text);
961 if (winstack[n].text == win)
966 #endif /* KEY_RESIZE */
969 wcstos(const wchar_t *src)
973 const wchar_t *tmp = src;
979 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
980 unsigned have = (unsigned) need;
981 if ((result = typeCalloc(char, have + 1)) != 0) {
983 if (trans_wchars(result, tmp, have, &state) != have) {
993 wget_wch_test(unsigned level, WINDOW *win, int delay)
995 wchar_t wchar_buf[BUFSIZ];
996 wint_t wint_buf[BUFSIZ];
997 int first_y, first_x;
1001 bool blocking = (delay < 0);
1005 init_getch(win, flags);
1006 wtimeout(win, delay);
1007 getyx(win, first_y, first_x);
1009 wgetch_help(win, flags);
1010 wsetscrreg(win, first_y, getmaxy(win) - 1);
1011 scrollok(win, TRUE);
1014 while ((code = wGet_wchar(win, &c)) == ERR) {
1017 (void) wprintw(win, "%05d: input error", incount);
1020 (void) wprintw(win, "%05d: input timed out", incount);
1022 wgetch_wrap(win, first_y);
1024 if (code == ERR && blocking) {
1025 wprintw(win, "ERR");
1026 wgetch_wrap(win, first_y);
1027 } else if (isQuit((int) c)) {
1029 } else if (c == 'e') {
1030 flags[UChar('e')] = !flags[UChar('e')];
1031 setup_getch(win, flags);
1032 wgetch_help(win, flags);
1033 } else if (c == 'g') {
1034 waddstr(win, "getstr test: ");
1036 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1039 wprintw(win, "wgetn_wstr returns an error.");
1042 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1045 if ((temp = wcstos(wchar_buf)) != 0) {
1046 wprintw(win, "I saw %d characters:\n\t`%s'.",
1047 (int) wcslen(wchar_buf), temp);
1050 wprintw(win, "I saw %d characters (cannot convert).",
1051 (int) wcslen(wchar_buf));
1055 wgetch_wrap(win, first_y);
1056 } else if (c == 'k') {
1057 flags[UChar('k')] = !flags[UChar('k')];
1058 setup_getch(win, flags);
1059 wgetch_help(win, flags);
1060 } else if (c == 'm') {
1061 flags[UChar('m')] = !flags[UChar('m')];
1062 setup_getch(win, flags);
1063 wgetch_help(win, flags);
1064 } else if (c == 's') {
1066 } else if (c == 'w') {
1067 int high = getmaxy(win) - 1 - first_y + 1;
1068 int wide = getmaxx(win) - first_x;
1070 int new_y = first_y + getbegy(win);
1071 int new_x = first_x + getbegx(win);
1073 getyx(win, old_y, old_x);
1074 if (high > 2 && wide > 2) {
1075 WINDOW *wb = newwin(high, wide, new_y, new_x);
1076 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1081 remember_boxes(level, wi, wb);
1082 wget_wch_test(level + 1, wi, delay);
1086 wgetch_help(win, flags);
1087 wmove(win, old_y, old_x);
1092 } else if (c == 'z') {
1093 kill(getpid(), SIGTSTP);
1096 wprintw(win, "Key pressed: %04o ", (int) c);
1097 #ifdef NCURSES_MOUSE_VERSION
1098 if (c == KEY_MOUSE) {
1102 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1104 move(event.y, event.x);
1108 #endif /* NCURSES_MOUSE_VERSION */
1109 if (code == KEY_CODE_YES) {
1110 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1111 if (c == KEY_RESIZE) {
1112 resize_wide_boxes(level, win);
1115 (void) waddstr(win, keyname((wchar_t) c));
1117 (void) waddstr(win, key_name((wchar_t) c));
1118 if (c < 256 && iscntrl(c)) {
1119 (void) wprintw(win, " (control character)");
1121 (void) wprintw(win, " = %#x (printable character)",
1125 wgetch_wrap(win, first_y);
1132 init_getch(win, flags);
1138 int delay = begin_getch_test();
1141 wget_wch_test(0, stdscr, delay);
1143 finish_getch_test();
1147 /****************************************************************************
1149 * Character attributes test
1151 ****************************************************************************/
1153 #if HAVE_SETUPTERM || HAVE_TGETENT
1154 #define get_ncv() TIGETNUM("ncv","NC")
1155 #define get_xmc() TIGETNUM("xmc","sg")
1157 #define get_ncv() -1
1158 #define get_xmc() -1
1165 static int first = TRUE;
1166 static chtype result = 0;
1172 char *area_pointer = parsed;
1174 tgetent(buffer, getenv("TERM"));
1177 if (TIGETSTR("smso", "so"))
1178 result |= A_STANDOUT;
1179 if (TIGETSTR("smul", "us"))
1180 result |= A_UNDERLINE;
1181 if (TIGETSTR("rev", "mr"))
1182 result |= A_REVERSE;
1183 if (TIGETSTR("blink", "mb"))
1185 if (TIGETSTR("dim", "mh"))
1187 if (TIGETSTR("bold", "md"))
1189 if (TIGETSTR("smacs", "ac"))
1190 result |= A_ALTCHARSET;
1196 #define termattrs() my_termattrs()
1199 #define MAX_ATTRSTRING 31
1200 #define LEN_ATTRSTRING 26
1202 static char attr_test_string[MAX_ATTRSTRING + 1];
1205 attr_legend(WINDOW *helpwin)
1210 mvwprintw(helpwin, row++, col,
1212 mvwprintw(helpwin, row++, col,
1215 mvwprintw(helpwin, row++, col,
1216 "Modify the test strings:");
1217 mvwprintw(helpwin, row++, col,
1218 " A digit sets gaps on each side of displayed attributes");
1219 mvwprintw(helpwin, row++, col,
1220 " </> shifts the text left/right. ");
1222 mvwprintw(helpwin, row++, col,
1225 mvwprintw(helpwin, row++, col,
1226 " f/F/b/F toggle foreground/background background color");
1227 mvwprintw(helpwin, row++, col,
1228 " t/T toggle text/background color attribute");
1230 mvwprintw(helpwin, row++, col,
1231 " a/A toggle ACS (alternate character set) mapping");
1232 mvwprintw(helpwin, row++, col,
1233 " v/V toggle video attribute to combine with each line");
1237 show_color_attr(int fg, int bg, int tx)
1240 printw(" Colors (fg %d, bg %d", fg, bg);
1242 printw(", text %d", tx);
1248 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1255 *fg = (short) (*fg + 1);
1258 *fg = (short) (*fg - 1);
1261 *bg = (short) (*bg + 1);
1264 *bg = (short) (*bg - 1);
1267 *tx = (short) (*tx + 1);
1270 *tx = (short) (*tx - 1);
1278 *fg = (short) min_colors;
1279 if (*fg < min_colors)
1280 *fg = (short) (COLORS - 1);
1282 *bg = (short) min_colors;
1283 if (*bg < min_colors)
1284 *bg = (short) (COLORS - 1);
1288 *tx = (short) (COLORS - 1);
1297 adjust_attr_string(int adjust)
1299 int first = ((int) UChar(attr_test_string[0])) + adjust;
1300 int last = first + LEN_ATTRSTRING;
1302 if (first >= ' ' && last <= '~') { /* 32..126 */
1304 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1305 attr_test_string[j] = (char) k;
1306 if (((k + 1 - first) % 5) == 0) {
1307 if (++j >= MAX_ATTRSTRING)
1309 attr_test_string[j] = ' ';
1312 while (j < MAX_ATTRSTRING)
1313 attr_test_string[j++] = ' ';
1314 attr_test_string[j] = '\0';
1321 init_attr_string(void)
1323 attr_test_string[0] = 'a';
1324 adjust_attr_string(0);
1328 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1330 int ncv = get_ncv();
1331 chtype test = attr & (chtype) (~A_ALTCHARSET);
1334 mvprintw(row, 5, "-->");
1335 mvprintw(row, 8, "%s mode:", name);
1336 mvprintw(row, 24, "|");
1338 printw("%*s", skip, " ");
1340 * Just for testing, write text using the alternate character set one
1341 * character at a time (to pass its rendition directly), and use the
1342 * string operation for the other attributes.
1344 if (attr & A_ALTCHARSET) {
1348 for (s = attr_test_string; *s != '\0'; ++s) {
1354 addstr(attr_test_string);
1358 printw("%*s", skip, " ");
1360 if (test != A_NORMAL) {
1361 if (!(termattrs() & test)) {
1364 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1365 static const chtype table[] =
1381 for (n = 0; n < SIZEOF(table); n++) {
1382 if ((table[n] & attr) != 0
1383 && ((1 << n) & ncv) != 0) {
1391 if ((termattrs() & test) != test)
1398 static const struct {
1400 NCURSES_CONST char * name;
1401 } attrs_to_test[] = {
1402 { A_STANDOUT, "STANDOUT" },
1403 { A_REVERSE, "REVERSE" },
1405 { A_UNDERLINE, "UNDERLINE" },
1407 { A_BLINK, "BLINK" },
1408 { A_PROTECT, "PROTECT" },
1410 { A_INVIS, "INVISIBLE" },
1412 { A_NORMAL, "NORMAL" },
1417 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1427 if (ch < 256 && isdigit(ch)) {
1435 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1437 attr_legend(helpwin);
1450 *kc = SIZEOF(attrs_to_test) - 1;
1456 if (*kc >= SIZEOF(attrs_to_test))
1460 adjust_attr_string(-1);
1463 adjust_attr_string(1);
1469 error = cycle_color_attr(ch, fg, bg, tx);
1479 /* test text attributes */
1482 int skip = get_xmc();
1483 short fg = COLOR_BLACK; /* color pair 0 is special */
1484 short bg = COLOR_BLACK;
1492 n = skip; /* make it easy */
1493 k = SIZEOF(attrs_to_test) - 1;
1498 chtype normal = A_NORMAL | BLANK;
1499 chtype extras = (chtype) ac;
1502 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1505 if (init_pair(pair, fg, bg) == ERR) {
1508 normal |= COLOR_PAIR(pair);
1513 if (init_pair(pair, tx, bg) == ERR) {
1516 extras |= COLOR_PAIR(pair);
1525 mvaddstr(0, 20, "Character attribute test display");
1527 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1528 bool arrow = (j == k);
1529 row = show_attr(row, n, arrow,
1531 attrs_to_test[j].attr |
1532 attrs_to_test[k].attr,
1533 attrs_to_test[j].name);
1537 "This terminal does %shave the magic-cookie glitch",
1538 get_xmc() > -1 ? "" : "not ");
1539 mvprintw(row + 1, 8, "Enter '?' for help.");
1540 show_color_attr(fg, bg, tx);
1541 printw(" ACS (%d)", ac != 0);
1544 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1546 bkgdset(A_NORMAL | BLANK);
1551 #if USE_WIDEC_SUPPORT
1552 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1555 wide_adjust_attr_string(int adjust)
1557 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1558 int last = first + LEN_ATTRSTRING;
1560 if (first >= ' ' && last <= '~') { /* 32..126 */
1562 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1563 wide_attr_test_string[j] = k;
1564 if (((k + 1 - first) % 5) == 0) {
1565 if (++j >= MAX_ATTRSTRING)
1567 wide_attr_test_string[j] = ' ';
1570 while (j < MAX_ATTRSTRING)
1571 wide_attr_test_string[j++] = ' ';
1572 wide_attr_test_string[j] = '\0';
1579 wide_init_attr_string(void)
1581 wide_attr_test_string[0] = 'a';
1582 wide_adjust_attr_string(0);
1586 set_wide_background(short pair)
1593 setcchar(&normal, blank, A_NORMAL, pair, 0);
1599 get_wide_background(void)
1601 attr_t result = A_NORMAL;
1607 if (getbkgrnd(&ch) != ERR) {
1608 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1616 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1618 int ncv = get_ncv();
1619 chtype test = attr & ~WA_ALTCHARSET;
1622 mvprintw(row, 5, "-->");
1623 mvprintw(row, 8, "%s mode:", name);
1624 mvprintw(row, 24, "|");
1626 printw("%*s", skip, " ");
1629 * Just for testing, write text using the alternate character set one
1630 * character at a time (to pass its rendition directly), and use the
1631 * string operation for the other attributes.
1633 if (attr & WA_ALTCHARSET) {
1637 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1641 setcchar(&ch, fill, attr, pair, 0);
1648 attr_get(&old_attr, &old_pair, 0);
1649 attr_set(attr, pair, 0);
1650 addwstr(wide_attr_test_string);
1651 attr_set(old_attr, old_pair, 0);
1654 printw("%*s", skip, " ");
1656 if (test != A_NORMAL) {
1657 if (!(term_attrs() & test)) {
1660 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1661 static const attr_t table[] =
1675 for (n = 0; n < SIZEOF(table); n++) {
1676 if ((table[n] & attr) != 0
1677 && ((1 << n) & ncv) != 0) {
1685 if ((term_attrs() & test) != test)
1693 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1703 if (ch < 256 && isdigit(ch)) {
1711 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1712 box_set(helpwin, 0, 0);
1713 attr_legend(helpwin);
1726 *kc = SIZEOF(attrs_to_test) - 1;
1732 if (*kc >= SIZEOF(attrs_to_test))
1736 wide_adjust_attr_string(-1);
1739 wide_adjust_attr_string(1);
1745 error = cycle_color_attr(ch, fg, bg, tx);
1754 wide_attr_test(void)
1755 /* test text attributes using wide-character calls */
1758 int skip = get_xmc();
1759 short fg = COLOR_BLACK; /* color pair 0 is special */
1760 short bg = COLOR_BLACK;
1768 n = skip; /* make it easy */
1769 k = SIZEOF(attrs_to_test) - 1;
1770 wide_init_attr_string();
1778 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1781 if (init_pair(pair, fg, bg) == ERR) {
1788 if (init_pair(extras, tx, bg) == ERR) {
1793 set_wide_background(pair);
1796 box_set(stdscr, 0, 0);
1797 mvaddstr(0, 20, "Character attribute test display");
1799 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1800 row = wide_show_attr(row, n, j == k,
1802 attrs_to_test[j].attr |
1803 attrs_to_test[k].attr,
1805 attrs_to_test[j].name);
1809 "This terminal does %shave the magic-cookie glitch",
1810 get_xmc() > -1 ? "" : "not ");
1811 mvprintw(row + 1, 8, "Enter '?' for help.");
1812 show_color_attr(fg, bg, tx);
1813 printw(" ACS (%d)", ac != 0);
1816 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1818 set_wide_background(0);
1824 /****************************************************************************
1826 * Color support tests
1828 ****************************************************************************/
1830 static NCURSES_CONST char *the_color_names[] =
1851 show_color_name(int y, int x, int color, bool wide)
1853 if (move(y, x) != ERR) {
1858 sprintf(temp, "%02d", color);
1860 } else if (color >= 8) {
1861 sprintf(temp, "[%02d]", color);
1862 } else if (color < 0) {
1863 strcpy(temp, "default");
1865 strcpy(temp, the_color_names[color]);
1867 printw("%-*.*s", width, width, temp);
1872 color_legend(WINDOW *helpwin, bool wide)
1877 mvwprintw(helpwin, row++, col,
1880 mvwprintw(helpwin, row++, col,
1881 "Use up/down arrow to scroll through the display if it is");
1882 mvwprintw(helpwin, row++, col,
1883 "longer than one screen. Control/N and Control/P can be used");
1884 mvwprintw(helpwin, row++, col,
1885 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1886 mvwprintw(helpwin, row++, col,
1887 "full screen; control/B and control/F can be used here.");
1889 mvwprintw(helpwin, row++, col,
1891 mvwprintw(helpwin, row++, col,
1892 " a/A toggle altcharset off/on");
1893 mvwprintw(helpwin, row++, col,
1894 " b/B toggle bold off/on");
1895 mvwprintw(helpwin, row++, col,
1896 " n/N toggle text/number on/off");
1897 mvwprintw(helpwin, row++, col,
1898 " r/R toggle reverse on/off");
1899 mvwprintw(helpwin, row++, col,
1900 " w/W toggle width between 8/16 colors");
1901 #if USE_WIDEC_SUPPORT
1903 mvwprintw(helpwin, row++, col,
1904 "Wide characters:");
1905 mvwprintw(helpwin, row++, col,
1906 " x/X toggle text between ASCII and wide-character");
1913 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1915 /* generate a color test pattern */
1922 int grid_top = top + 3;
1923 int page_size = (LINES - grid_top);
1924 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1930 bool opt_acsc = FALSE;
1931 bool opt_bold = FALSE;
1932 bool opt_revs = FALSE;
1933 bool opt_nums = FALSE;
1934 bool opt_wide = FALSE;
1937 if (COLORS * COLORS == COLOR_PAIRS) {
1938 int limit = (COLORS - min_colors) * (COLORS - min_colors);
1939 if (pairs_max > limit)
1942 if (pairs_max > COLOR_PAIRS)
1943 pairs_max = COLOR_PAIRS;
1949 /* this assumes an 80-column line */
1953 per_row = (COLORS > 8) ? 16 : 8;
1959 per_row -= min_colors;
1961 row_limit = (pairs_max + per_row - 1) / per_row;
1964 (void) printw("There are %d color pairs and %d colors%s\n",
1966 min_colors ? " besides 'default'" : "");
1969 (void) mvprintw(top + 1, 0,
1970 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1973 opt_bold ? "on" : "off");
1975 /* show color names/numbers across the top */
1976 for (i = 0; i < per_row; i++)
1977 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
1979 /* show a grid of colors, with color names/ numbers on the left */
1980 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
1981 int row = grid_top + (i / per_row) - base_row;
1982 int col = (i % per_row + 1) * width;
1985 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
1986 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
1987 if (row >= 0 && move(row, col) != ERR) {
1988 short fg = InxToFG(i);
1989 short bg = InxToBG(i);
1991 init_pair(pair, fg, bg);
1992 attron((attr_t) COLOR_PAIR(pair));
1994 attron((attr_t) A_ALTCHARSET);
1996 attron((attr_t) A_BOLD);
1998 attron((attr_t) A_REVERSE);
2001 sprintf(numbered, "{%02X}", i);
2004 printw("%-*.*s", width, width, hello);
2007 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2008 show_color_name(row, 0, InxToBG(i), opt_wide);
2016 switch (wGetchar(stdscr)) {
2045 set_color_test(opt_wide, FALSE);
2048 set_color_test(opt_wide, TRUE);
2052 if (base_row <= 0) {
2060 if (base_row + page_size >= row_limit) {
2069 if (base_row <= 0) {
2072 base_row -= (page_size - 1);
2080 if (base_row + page_size >= row_limit) {
2083 base_row += page_size - 1;
2084 if (base_row + page_size >= row_limit) {
2085 base_row = row_limit - page_size - 1;
2090 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2092 color_legend(helpwin, FALSE);
2107 #if USE_WIDEC_SUPPORT
2108 /* generate a color test pattern */
2110 wide_color_test(void)
2116 int grid_top = top + 3;
2117 int page_size = (LINES - grid_top);
2118 int pairs_max = (unsigned short) (-1);
2124 bool opt_acsc = FALSE;
2125 bool opt_bold = FALSE;
2126 bool opt_revs = FALSE;
2127 bool opt_wide = FALSE;
2128 bool opt_nums = FALSE;
2129 bool opt_xchr = FALSE;
2133 if (COLORS * COLORS == COLOR_PAIRS) {
2134 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2135 if (pairs_max > limit)
2138 if (pairs_max > COLOR_PAIRS)
2139 pairs_max = COLOR_PAIRS;
2145 /* this assumes an 80-column line */
2149 per_row = (COLORS > 8) ? 16 : 8;
2155 per_row -= min_colors;
2158 make_fullwidth_text(buffer, hello);
2162 make_narrow_text(buffer, hello);
2165 row_limit = (pairs_max + per_row - 1) / per_row;
2168 (void) printw("There are %d color pairs and %d colors%s\n",
2170 min_colors ? " besides 'default'" : "");
2173 (void) mvprintw(top + 1, 0,
2174 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2177 opt_bold ? "on" : "off");
2179 /* show color names/numbers across the top */
2180 for (i = 0; i < per_row; i++)
2181 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2183 /* show a grid of colors, with color names/ numbers on the left */
2184 for (i = (base_row * per_row); i < pairs_max; i++) {
2185 int row = grid_top + (i / per_row) - base_row;
2186 int col = (i % per_row + 1) * width;
2187 short pair = (short) i;
2189 if (row >= 0 && move(row, col) != ERR) {
2190 init_pair(pair, InxToFG(i), InxToBG(i));
2191 color_set(pair, NULL);
2193 attr_on((attr_t) A_ALTCHARSET, NULL);
2195 attr_on((attr_t) A_BOLD, NULL);
2197 attr_on((attr_t) A_REVERSE, NULL);
2200 sprintf(numbered, "{%02X}", i);
2202 make_fullwidth_text(buffer, numbered);
2204 make_narrow_text(buffer, numbered);
2207 addnwstr(buffer, width);
2208 attr_set(A_NORMAL, 0, NULL);
2210 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2211 show_color_name(row, 0, InxToBG(i), opt_wide);
2219 switch (c = wGetchar(stdscr)) {
2248 set_color_test(opt_wide, FALSE);
2251 set_color_test(opt_wide, TRUE);
2261 if (base_row <= 0) {
2269 if (base_row + page_size >= row_limit) {
2278 if (base_row <= 0) {
2281 base_row -= (page_size - 1);
2289 if (base_row + page_size >= row_limit) {
2292 base_row += page_size - 1;
2293 if (base_row + page_size >= row_limit) {
2294 base_row = row_limit - page_size - 1;
2299 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2301 color_legend(helpwin, TRUE);
2315 #endif /* USE_WIDEC_SUPPORT */
2318 change_color(short current, int field, int value, int usebase)
2320 short red, green, blue;
2322 color_content(current, &red, &green, &blue);
2326 red = (short) (usebase ? (red + value) : value);
2329 green = (short) (usebase ? (green + value) : value);
2332 blue = (short) (usebase ? (blue + value) : value);
2336 if (init_color(current, red, green, blue) == ERR)
2341 init_all_colors(void)
2345 for (c = 0; c < COLORS; ++c)
2348 all_colors[c].green,
2349 all_colors[c].blue);
2352 #define scaled_rgb(n) ((255 * (n)) / 1000)
2356 /* display the color test pattern, without trying to edit colors */
2360 int this_c = 0, value = 0, field = 0;
2363 int page_size = (LINES - 6);
2368 for (i = 0; i < max_colors; i++)
2369 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2371 mvprintw(LINES - 2, 0, "Number: %d", value);
2374 short red, green, blue;
2377 mvaddstr(0, 20, "Color RGB Value Editing");
2380 for (i = (short) top_color;
2381 (i - top_color < page_size)
2382 && (i < max_colors); i++) {
2385 sprintf(numeric, "[%d]", i);
2386 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2387 (i == current ? '>' : ' '),
2388 (i < (int) SIZEOF(the_color_names)
2389 ? the_color_names[i] : numeric));
2390 attrset(COLOR_PAIR(i));
2394 color_content((short) i, &red, &green, &blue);
2396 if (current == i && field == 0)
2398 printw("%04d", red);
2399 if (current == i && field == 0)
2402 if (current == i && field == 1)
2404 printw("%04d", green);
2405 if (current == i && field == 1)
2408 if (current == i && field == 2)
2410 printw("%04d", blue);
2411 if (current == i && field == 2)
2414 printw(" ( %3d %3d %3d )",
2420 mvaddstr(LINES - 3, 0,
2421 "Use up/down to select a color, left/right to change fields.");
2422 mvaddstr(LINES - 2, 0,
2423 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2425 move(2 + current - top_color, 0);
2429 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2436 current -= (page_size - 1);
2443 if (current < (max_colors - 1))
2444 current += (page_size - 1);
2451 current = (current == 0 ? (max_colors - 1) : current - 1);
2456 current = (current == (max_colors - 1) ? 0 : current + 1);
2460 field = (field == 2 ? 0 : field + 1);
2464 field = (field == 0 ? 2 : field - 1);
2477 value = value * 10 + (this_c - '0');
2481 change_color((short) current, field, value, 1);
2485 change_color((short) current, field, -value, 1);
2489 change_color((short) current, field, value, 0);
2494 P(" RGB Value Editing Help");
2496 P("You are in the RGB value editor. Use the arrow keys to select one of");
2497 P("the fields in one of the RGB triples of the current colors; the one");
2498 P("currently selected will be reverse-video highlighted.");
2500 P("To change a field, enter the digits of the new value; they are echoed");
2501 P("as entered. Finish by typing `='. The change will take effect instantly.");
2502 P("To increment or decrement a value, use the same procedure, but finish");
2503 P("with a `+' or `-'.");
2505 P("Press 'm' to invoke the top-level menu with the current color settings.");
2506 P("To quit, do ESC");
2528 if (current >= max_colors)
2529 current = max_colors - 1;
2530 if (current < top_color)
2531 top_color = current;
2532 if (current - top_color >= page_size)
2533 top_color = current - (page_size - 1);
2535 mvprintw(LINES - 1, 0, "Number: %d", value);
2543 * ncurses does not reset each color individually when calling endwin().
2550 /****************************************************************************
2552 * Soft-key label test
2554 ****************************************************************************/
2559 #define SLK_WORK (SLK_HELP + 3)
2564 static const char *table[] =
2566 "Available commands are:"
2568 ,"^L -- repaint this message and activate soft keys"
2569 ,"a/d -- activate/disable soft keys"
2570 ,"c -- set centered format for labels"
2571 ,"l -- set left-justified format for labels"
2572 ,"r -- set right-justified format for labels"
2573 ,"[12345678] -- set label; labels are numbered 1 through 8"
2574 ,"e -- erase stdscr (should not erase labels)"
2575 ,"s -- test scrolling of shortened screen"
2577 ,"F/B -- cycle through foreground/background colors"
2579 ,"ESC -- return to main menu"
2581 ,"Note: if activating the soft keys causes your terminal to scroll up"
2582 ,"one line, your terminal auto-scrolls when anything is written to the"
2583 ,"last screen position. The ncurses code does not yet handle this"
2589 for (j = 0; j < SIZEOF(table); ++j) {
2597 call_slk_color(short fg, short bg)
2599 init_pair(1, bg, fg);
2601 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2609 /* exercise the soft keys */
2615 short fg = COLOR_BLACK;
2616 short bg = COLOR_WHITE;
2622 call_slk_color(fg, bg);
2632 mvaddstr(0, 20, "Soft Key Exerciser");
2647 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2648 while ((c = Getchar()) != 'Q' && (c != ERR))
2676 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2678 if ((s = slk_label(c - '0')) != 0) {
2681 wGetstring(stdscr, buf, 8);
2682 slk_set((c - '0'), buf, fmt);
2694 fg = (short) ((fg + 1) % COLORS);
2695 call_slk_color(fg, bg);
2700 bg = (short) ((bg + 1) % COLORS);
2701 call_slk_color(fg, bg);
2705 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2707 wnoutrefresh(stdscr);
2714 } while (!isQuit(c = Getchar()));
2722 #if USE_WIDEC_SUPPORT
2726 /* exercise the soft keys */
2729 wchar_t buf[SLKLEN + 1];
2731 short fg = COLOR_BLACK;
2732 short bg = COLOR_WHITE;
2736 call_slk_color(fg, bg);
2743 attr_on(WA_BOLD, NULL);
2744 mvaddstr(0, 20, "Soft Key Exerciser");
2745 attr_off(WA_BOLD, NULL);
2759 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2760 while ((c = Getchar()) != 'Q' && (c != ERR))
2788 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2790 if ((s = slk_label(c - '0')) != 0) {
2791 char *temp = strdup(s);
2792 size_t used = strlen(temp);
2793 size_t want = SLKLEN;
2795 #ifndef state_unused
2800 while (want > 0 && used != 0) {
2801 const char *base = s;
2802 reset_mbytes(state);
2803 test = count_mbytes(base, 0, &state);
2804 if (test == (size_t) -1) {
2806 } else if (test > want) {
2809 reset_mbytes(state);
2810 trans_mbytes(buf, base, want, &state);
2816 wGet_wstring(stdscr, buf, SLKLEN);
2817 slk_wset((c - '0'), buf, fmt);
2828 fg = (short) ((fg + 1) % COLORS);
2829 call_slk_color(fg, bg);
2834 bg = (short) ((bg + 1) % COLORS);
2835 call_slk_color(fg, bg);
2838 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2840 wnoutrefresh(stdscr);
2846 } while (!isQuit(c = Getchar()));
2854 #endif /* SLK_INIT */
2856 /****************************************************************************
2858 * Alternate character-set stuff
2860 ****************************************************************************/
2865 } attrs_to_cycle[] = {
2866 { A_NORMAL, "normal" },
2868 { A_BLINK, "blink" },
2869 { A_REVERSE, "reverse" },
2870 { A_UNDERLINE, "underline" },
2875 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2881 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2886 *at_code = SIZEOF(attrs_to_cycle) - 1;
2895 *attr = attrs_to_cycle[*at_code].attr;
2900 cycle_colors(int ch, int *fg, int *bg, short *pair)
2902 bool result = FALSE;
2912 if ((*fg += 1) >= COLORS)
2920 if ((*bg += 1) >= COLORS)
2928 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2931 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2940 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2941 * terminal to perform functions. The remaining codes can be graphic.
2944 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
2946 bool C1 = (first == 128);
2948 unsigned last = first + 31;
2953 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2954 C1 ? "C1" : "GR", first, last);
2958 for (code = first; code <= last; code++) {
2960 int row = 2 + ((int) (code - first) % 16);
2961 int col = ((int) (code - first) / 16) * COLS / 2;
2963 sprintf(tmp, "%3u (0x%x)", code, code);
2964 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2968 nodelay(stdscr, TRUE);
2969 echochar(colored_chtype(code, attr, pair));
2971 /* (yes, this _is_ crude) */
2972 while ((reply = Getchar()) != ERR) {
2973 addch(UChar(reply));
2976 nodelay(stdscr, FALSE);
2978 } while (--count > 0);
2985 show_pc_chars(int repeat, attr_t attr, short pair)
2991 mvprintw(0, 20, "Display of PC Character Codes");
2995 for (code = 0; code < 16; ++code) {
2996 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
2998 for (code = 0; code < 256; code++) {
3000 int row = 3 + (int) (code / 16) + (code >= 128);
3001 int col = 8 + (int) (code % 16) * PC_COLS;
3002 if ((code % 16) == 0)
3003 mvprintw(row, 0, "0x%02x:", code);
3014 * Skip the ones that do not work.
3018 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3021 } while (--count > 0);
3026 show_box_chars(int repeat, attr_t attr, short pair)
3029 attr |= COLOR_PAIR(pair);
3033 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
3038 colored_chtype(ACS_VLINE, attr, pair),
3039 colored_chtype(ACS_VLINE, attr, pair),
3040 colored_chtype(ACS_HLINE, attr, pair),
3041 colored_chtype(ACS_HLINE, attr, pair),
3042 colored_chtype(ACS_ULCORNER, attr, pair),
3043 colored_chtype(ACS_URCORNER, attr, pair),
3044 colored_chtype(ACS_LLCORNER, attr, pair),
3045 colored_chtype(ACS_LRCORNER, attr, pair));
3046 mvhline(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3047 mvvline(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3048 mvaddch(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3049 mvaddch(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3050 mvaddch(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3051 mvaddch(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3052 mvaddch(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3058 show_1_acs(int n, int repeat, const char *name, chtype code)
3060 const int height = 16;
3061 int row = 2 + (n % height);
3062 int col = (n / height) * COLS / 2;
3064 mvprintw(row, col, "%*s : ", COLS / 4, name);
3067 } while (--repeat > 0);
3072 show_acs_chars(int repeat, attr_t attr, short pair)
3073 /* display the ACS character set */
3077 #define BOTH(name) #name, colored_chtype(name, attr, pair)
3081 mvaddstr(0, 20, "Display of the ACS Character Set");
3085 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3086 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3087 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3088 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3090 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3091 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3092 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3093 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3095 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3096 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3099 * HPUX's ACS definitions are broken here. Just give up.
3101 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3102 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3103 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3104 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3105 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3107 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3108 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3109 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3110 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3111 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3112 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3113 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3114 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3115 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3117 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3118 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3119 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3121 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3122 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3123 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3124 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3125 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3126 n = show_1_acs(n, repeat, BOTH(ACS_S9));
3134 char *term = getenv("TERM");
3135 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3138 chtype attr = A_NORMAL;
3141 int fg = COLOR_BLACK;
3142 int bg = COLOR_BLACK;
3143 unsigned at_code = 0;
3145 void (*last_show_acs) (int, attr_t, short) = 0;
3153 ToggleAcs(last_show_acs, show_acs_chars);
3157 ToggleAcs(last_show_acs, show_pc_chars);
3162 ToggleAcs(last_show_acs, show_box_chars);
3188 if (repeat < (COLS / 4))
3196 if (cycle_attr(c, &at_code, &attr)
3197 || cycle_colors(c, &fg, &bg, &pair)) {
3204 if (last_show_acs != 0)
3205 last_show_acs(repeat, attr, pair);
3207 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3209 mvprintw(LINES - 3, 0,
3210 "Note: ANSI terminals may not display C1 characters.");
3211 mvprintw(LINES - 2, 0,
3212 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3215 mvprintw(LINES - 1, 0,
3216 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3217 attrs_to_cycle[at_code].name,
3220 mvprintw(LINES - 1, 0,
3221 "v/V cycles through video attributes (%s).",
3222 attrs_to_cycle[at_code].name);
3225 } while (!isQuit(c = Getchar()));
3232 #if USE_WIDEC_SUPPORT
3234 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3236 int count = getcchar(src, NULL, NULL, NULL, 0);
3243 if ((wch = typeMalloc(wchar_t, (unsigned) count + 1)) != 0) {
3244 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
3245 attr |= (ignore_attr & A_ALTCHARSET);
3246 setcchar(dst, wch, attr, pair, 0);
3255 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3259 int last = first + 31;
3263 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3266 for (code = first; (int) code <= last; code++) {
3267 int row = 2 + ((code - first) % 16);
3268 int col = ((code - first) / 16) * COLS / 2;
3274 memset(&codes, 0, sizeof(codes));
3276 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3277 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3278 setcchar(&temp, codes, attr, pair, 0);
3281 * Give non-spacing characters something to combine with. If we
3282 * don't, they'll bunch up in a heap on the space after the ":".
3283 * Mark them with reverse-video to make them simpler to find on
3286 if (wcwidth(code) == 0)
3287 addch(space | A_REVERSE);
3289 * This could use add_wch(), but is done for comparison with the
3290 * normal 'f' test (and to make a test-case for echo_wchar()).
3291 * The screen will flicker because the erase() at the top of the
3292 * function is met by the builtin refresh() in echo_wchar().
3296 * The repeat-count may make text wrap - avoid that.
3298 getyx(stdscr, y, x);
3299 if (x >= col + (COLS / 2) - 2)
3301 } while (--count > 0);
3306 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3308 const int height = 16;
3309 int row = 2 + (n % height);
3310 int col = (n / height) * COLS / 2;
3312 mvprintw(row, col, "%*s : ", COLS / 4, name);
3313 while (--repeat >= 0) {
3319 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3322 show_wacs_chars(int repeat, attr_t attr, short pair)
3323 /* display the wide-ACS character set */
3329 /*#define BOTH2(name) #name, &(name) */
3330 #define BOTH2(name) #name, MERGE_ATTR(name)
3334 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3338 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3339 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3340 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3341 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3343 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3344 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3345 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3346 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3348 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3349 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3351 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3352 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3353 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3354 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3356 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3357 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3358 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3359 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3360 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3361 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3362 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3363 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3364 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3366 #ifdef CURSES_WACS_ARRAY
3367 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3368 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3369 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3371 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3372 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3373 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3374 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3375 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3376 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3382 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3385 show_wbox_chars(int repeat, attr_t attr, short pair)
3392 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3397 MERGE_ATTR(0, WACS_VLINE),
3398 MERGE_ATTR(1, WACS_VLINE),
3399 MERGE_ATTR(2, WACS_HLINE),
3400 MERGE_ATTR(3, WACS_HLINE),
3401 MERGE_ATTR(4, WACS_ULCORNER),
3402 MERGE_ATTR(5, WACS_URCORNER),
3403 MERGE_ATTR(6, WACS_LLCORNER),
3404 MERGE_ATTR(7, WACS_LRCORNER));
3406 mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3407 mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3408 mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3409 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3410 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3411 mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3412 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3420 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3422 const int height = 16;
3423 int row = 2 + (n % height);
3424 int col = (n / height) * COLS / 2;
3427 mvprintw(row, col, "%*s : ", COLS / 4, name);
3428 attr_set(attr, pair, 0);
3429 addstr(strcpy(temp, code));
3430 attr_set(A_NORMAL, 0, 0);
3434 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3437 show_utf8_chars(int repeat, attr_t attr, short pair)
3444 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3448 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3449 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3450 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3451 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3453 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3454 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3455 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3456 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3458 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3459 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3461 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3462 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3463 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3464 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3466 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3467 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3468 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3469 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3470 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3471 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3472 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3473 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3474 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3475 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3476 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3477 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3479 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3480 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3481 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3482 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3483 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3484 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3489 /* display the wide-ACS character set */
3491 wide_acs_display(void)
3497 chtype attr = A_NORMAL;
3498 int fg = COLOR_BLACK;
3499 int bg = COLOR_BLACK;
3500 unsigned at_code = 0;
3502 void (*last_show_wacs) (int, attr_t, short) = 0;
3510 ToggleAcs(last_show_wacs, show_wacs_chars);
3513 ToggleAcs(last_show_wacs, show_wbox_chars);
3516 ToggleAcs(last_show_wacs, show_utf8_chars);
3519 if (c < 256 && isdigit(c)) {
3522 } else if (c == '+') {
3525 } else if (c == '-' && digit > 0) {
3528 } else if (c == '>' && repeat < (COLS / 4)) {
3530 } else if (c == '<' && repeat > 1) {
3532 } else if (c == '_') {
3533 space = (space == ' ') ? '_' : ' ';
3535 } else if (cycle_attr(c, &at_code, &attr)
3536 || cycle_colors(c, &fg, &bg, &pair)) {
3537 if (last_show_wacs != 0)
3545 if (last_show_wacs != 0)
3546 last_show_wacs(repeat, attr, pair);
3548 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3550 mvprintw(LINES - 3, 0,
3551 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3553 mvprintw(LINES - 2, 0,
3554 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3555 attrs_to_cycle[at_code].name,
3558 mvprintw(LINES - 2, 0,
3559 "v/V cycles through video attributes (%s).",
3560 attrs_to_cycle[at_code].name);
3563 } while (!isQuit(c = Getchar()));
3573 * Graphic-rendition test (adapted from vttest)
3576 test_sgr_attributes(void)
3580 for (pass = 0; pass < 2; pass++) {
3581 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3583 /* Use non-default colors if possible to exercise bce a little */
3585 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3586 normal |= COLOR_PAIR(1);
3590 mvprintw(1, 20, "Graphic rendition test pattern:");
3592 mvprintw(4, 1, "vanilla");
3594 #define set_sgr(mask) bkgdset((normal^(mask)));
3596 mvprintw(4, 40, "bold");
3598 set_sgr(A_UNDERLINE);
3599 mvprintw(6, 6, "underline");
3601 set_sgr(A_BOLD | A_UNDERLINE);
3602 mvprintw(6, 45, "bold underline");
3605 mvprintw(8, 1, "blink");
3607 set_sgr(A_BLINK | A_BOLD);
3608 mvprintw(8, 40, "bold blink");
3610 set_sgr(A_UNDERLINE | A_BLINK);
3611 mvprintw(10, 6, "underline blink");
3613 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3614 mvprintw(10, 45, "bold underline blink");
3617 mvprintw(12, 1, "negative");
3619 set_sgr(A_BOLD | A_REVERSE);
3620 mvprintw(12, 40, "bold negative");
3622 set_sgr(A_UNDERLINE | A_REVERSE);
3623 mvprintw(14, 6, "underline negative");
3625 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3626 mvprintw(14, 45, "bold underline negative");
3628 set_sgr(A_BLINK | A_REVERSE);
3629 mvprintw(16, 1, "blink negative");
3631 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3632 mvprintw(16, 40, "bold blink negative");
3634 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3635 mvprintw(18, 6, "underline blink negative");
3637 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3638 mvprintw(18, 45, "bold underline blink negative");
3641 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3647 bkgdset(A_NORMAL | BLANK);
3652 /****************************************************************************
3654 * Windows and scrolling tester.
3656 ****************************************************************************/
3658 #define BOTLINES 4 /* number of line stolen from screen bottom */
3664 #define FRAME struct frame
3673 #if defined(NCURSES_VERSION)
3674 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3675 #define is_keypad(win) (win)->_use_keypad
3676 #define is_scrollok(win) (win)->_scroll
3677 #elif !defined(is_keypad)
3678 #define is_keypad(win) FALSE
3679 #define is_scrollok(win) FALSE
3682 #define is_keypad(win) FALSE
3683 #define is_scrollok(win) FALSE
3687 frame_win(FRAME * curp)
3689 return (curp != 0) ? curp->wind : stdscr;
3692 /* We need to know if these flags are actually set, so don't look in FRAME.
3693 * These names are known to work with SVr4 curses as well as ncurses. The
3694 * _use_keypad name does not work with Solaris 8.
3697 HaveKeypad(FRAME * curp)
3699 WINDOW *win = frame_win(curp);
3701 return is_keypad(win);
3705 HaveScroll(FRAME * curp)
3707 WINDOW *win = frame_win(curp);
3709 return is_scrollok(win);
3713 newwin_legend(FRAME * curp)
3715 static const struct {
3720 "^C = create window", 0
3723 "^N = next window", 0
3726 "^P = previous window", 0
3729 "^F = scroll forward", 0
3732 "^B = scroll backward", 0
3735 "^K = keypad(%s)", 1
3738 "^S = scrollok(%s)", 2
3741 "^W = save window to file", 0
3744 "^R = restore window", 0
3757 bool do_keypad = HaveKeypad(curp);
3758 bool do_scroll = HaveScroll(curp);
3762 for (n = 0; n < SIZEOF(legend); n++) {
3763 switch (legend[n].code) {
3765 strcpy(buf, legend[n].msg);
3768 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3771 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3774 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3777 x = getcurx(stdscr);
3778 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3785 transient(FRAME * curp, NCURSES_CONST char *msg)
3787 newwin_legend(curp);
3789 mvaddstr(LINES - 1, 0, msg);
3795 printw("%s characters are echoed, window should %sscroll.",
3796 HaveKeypad(curp) ? "Non-arrow" : "All other",
3797 HaveScroll(curp) ? "" : "not ");
3802 newwin_report(FRAME * curp)
3803 /* report on the cursor's current position, then restore it */
3805 WINDOW *win = frame_win(curp);
3809 transient(curp, (char *) 0);
3811 move(LINES - 1, COLS - 17);
3812 printw("Y = %2d X = %2d", y, x);
3820 selectcell(int uli, int ulj, int lri, int lrj)
3821 /* arrows keys move cursor, return location at current on non-arrow key */
3823 static pair res; /* result cell */
3824 int si = lri - uli + 1; /* depth of the select area */
3825 int sj = lrj - ulj + 1; /* width of the select area */
3826 int i = 0, j = 0; /* offsets into the select area */
3831 move(uli + i, ulj + j);
3832 newwin_report((FRAME *) 0);
3834 switch (Getchar()) {
3848 return ((pair *) 0);
3849 #ifdef NCURSES_MOUSE_VERSION
3855 if (event.y > uli && event.x > ulj) {
3876 outerbox(pair ul, pair lr, bool onoff)
3877 /* draw or erase a box *outside* the given pair of corners */
3879 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3880 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3881 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3882 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3883 move(ul.y - 1, ul.x);
3884 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3885 move(ul.y, ul.x - 1);
3886 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3887 move(lr.y + 1, ul.x);
3888 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3889 move(ul.y, lr.x + 1);
3890 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3895 /* Ask user for a window definition */
3902 addstr("Use arrows to move cursor, anything else to mark corner 1");
3904 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3905 return ((WINDOW *) 0);
3906 memcpy(&ul, tmp, sizeof(pair));
3907 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3910 addstr("Use arrows to move cursor, anything else to mark corner 2");
3912 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
3914 return ((WINDOW *) 0);
3915 memcpy(&lr, tmp, sizeof(pair));
3917 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
3919 outerbox(ul, lr, TRUE);
3930 newwin_move(FRAME * curp, int dy, int dx)
3932 WINDOW *win = frame_win(curp);
3936 getyx(win, cur_y, cur_x);
3937 getmaxyx(win, max_y, max_x);
3938 if ((cur_x += dx) < 0)
3940 else if (cur_x >= max_x)
3942 if ((cur_y += dy) < 0)
3944 else if (cur_y >= max_y)
3946 wmove(win, cur_y, cur_x);
3950 delete_framed(FRAME * fp, bool showit)
3955 fp->last->next = fp->next;
3956 fp->next->last = fp->last;
3964 np = (fp == fp->next) ? 0 : fp->next;
3971 acs_and_scroll(void)
3972 /* Demonstrate windows */
3975 FRAME *current = (FRAME *) 0, *neww;
3976 WINDOW *usescr = stdscr;
3977 #if HAVE_PUTWIN && HAVE_GETWIN
3981 #define DUMPFILE "screendump"
3983 #ifdef NCURSES_MOUSE_VERSION
3984 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
3989 transient((FRAME *) 0, (char *) 0);
3992 if ((neww = typeCalloc(FRAME, 1)) == 0) {
3995 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4000 if (current == 0) { /* First element, */
4001 neww->next = neww; /* so point it at itself */
4004 neww->next = current->next;
4005 neww->last = current;
4006 neww->last->next = neww;
4007 neww->next->last = neww;
4010 /* SVr4 curses sets the keypad on all newly-created windows to
4011 * false. Someone reported that PDCurses makes new windows inherit
4012 * this flag. Remove the following 'keypad()' call to test this
4014 keypad(current->wind, TRUE);
4015 current->do_keypad = HaveKeypad(current);
4016 current->do_scroll = HaveScroll(current);
4019 case CTRL('N'): /* go to next window */
4021 current = current->next;
4024 case CTRL('P'): /* go to previous window */
4026 current = current->last;
4029 case CTRL('F'): /* scroll current window forward */
4031 wscrl(frame_win(current), 1);
4034 case CTRL('B'): /* scroll current window backwards */
4036 wscrl(frame_win(current), -1);
4039 case CTRL('K'): /* toggle keypad mode for current */
4041 current->do_keypad = !current->do_keypad;
4042 keypad(current->wind, current->do_keypad);
4048 current->do_scroll = !current->do_scroll;
4049 scrollok(current->wind, current->do_scroll);
4053 #if HAVE_PUTWIN && HAVE_GETWIN
4054 case CTRL('W'): /* save and delete window */
4055 if ((current != 0) && (current == current->next)) {
4056 transient(current, "Will not save/delete ONLY window");
4058 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4059 transient(current, "Can't open screen dump file");
4061 (void) putwin(frame_win(current), fp);
4064 current = delete_framed(current, TRUE);
4068 case CTRL('R'): /* restore window */
4069 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4070 transient(current, "Can't open screen dump file");
4072 if ((neww = typeCalloc(FRAME, 1)) != 0) {
4074 neww->next = current ? current->next : 0;
4075 neww->last = current;
4076 neww->last->next = neww;
4077 neww->next->last = neww;
4079 neww->wind = getwin(fp);
4081 wrefresh(neww->wind);
4089 case CTRL('X'): /* resize window */
4096 addstr("Use arrows to move cursor, anything else to mark new corner");
4099 getbegyx(current->wind, ul.y, ul.x);
4101 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4102 if (tmp == (pair *) 0) {
4107 getmaxyx(current->wind, lr.y, lr.x);
4110 outerbox(ul, lr, FALSE);
4111 wnoutrefresh(stdscr);
4113 /* strictly cosmetic hack for the test */
4114 getmaxyx(current->wind, my, mx);
4115 if (my > tmp->y - ul.y) {
4116 getyx(current->wind, lr.y, lr.x);
4117 wmove(current->wind, tmp->y - ul.y + 1, 0);
4118 wclrtobot(current->wind);
4119 wmove(current->wind, lr.y, lr.x);
4121 if (mx > tmp->x - ul.x)
4122 for (i = 0; i < my; i++) {
4123 wmove(current->wind, i, tmp->x - ul.x + 1);
4124 wclrtoeol(current->wind);
4126 wnoutrefresh(current->wind);
4128 memcpy(&lr, tmp, sizeof(pair));
4129 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4131 getbegyx(current->wind, ul.y, ul.x);
4132 getmaxyx(current->wind, lr.y, lr.x);
4135 outerbox(ul, lr, TRUE);
4136 wnoutrefresh(stdscr);
4138 wnoutrefresh(current->wind);
4144 #endif /* HAVE_WRESIZE */
4146 case KEY_F(10): /* undocumented --- use this to test area clears */
4147 selectcell(0, 0, LINES - 1, COLS - 1);
4153 newwin_move(current, -1, 0);
4156 newwin_move(current, 1, 0);
4159 newwin_move(current, 0, -1);
4162 newwin_move(current, 0, 1);
4170 getyx(frame_win(current), y, x);
4174 x = getmaxx(frame_win(current)) - 1;
4176 mvwdelch(frame_win(current), y, x);
4186 waddch(current->wind, (chtype) c);
4191 newwin_report(current);
4192 usescr = frame_win(current);
4195 (!isQuit(c = wGetchar(usescr))
4199 while (current != 0)
4200 current = delete_framed(current, FALSE);
4202 scrollok(stdscr, TRUE); /* reset to driver's default */
4203 #ifdef NCURSES_MOUSE_VERSION
4204 mousemask(0, (mmask_t *) 0);
4211 /****************************************************************************
4215 ****************************************************************************/
4218 static int nap_msec = 1;
4220 static NCURSES_CONST char *mod[] =
4230 /*+-------------------------------------------------------------------------
4232 --------------------------------------------------------------------------*/
4234 wait_a_while(int msec GCC_UNUSED)
4244 else if (msec > 1000)
4245 sleep((unsigned) msec / 1000);
4249 } /* end of wait_a_while */
4251 /*+-------------------------------------------------------------------------
4253 --------------------------------------------------------------------------*/
4255 saywhat(NCURSES_CONST char *text)
4257 wmove(stdscr, LINES - 1, 0);
4259 if (text != 0 && *text != '\0') {
4260 waddstr(stdscr, text);
4261 waddstr(stdscr, "; ");
4263 waddstr(stdscr, "press any key to continue");
4264 } /* end of saywhat */
4266 /*+-------------------------------------------------------------------------
4267 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4268 --------------------------------------------------------------------------*/
4270 mkpanel(short color, int rows, int cols, int tly, int tlx)
4275 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4276 if ((pan = new_panel(win)) == 0) {
4278 } else if (use_colors) {
4279 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4282 init_pair(color, fg, bg);
4283 wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
4285 wbkgdset(win, A_BOLD | ' ');
4289 } /* end of mkpanel */
4291 /*+-------------------------------------------------------------------------
4293 --------------------------------------------------------------------------*/
4295 rmpanel(PANEL * pan)
4297 WINDOW *win = panel_window(pan);
4300 } /* end of rmpanel */
4302 /*+-------------------------------------------------------------------------
4304 --------------------------------------------------------------------------*/
4310 } /* end of pflush */
4312 /*+-------------------------------------------------------------------------
4314 --------------------------------------------------------------------------*/
4320 for (y = 0; y < LINES - 1; y++) {
4321 for (x = 0; x < COLS; x++)
4322 wprintw(stdscr, "%d", (y + x) % 10);
4327 fill_panel(PANEL * pan)
4329 WINDOW *win = panel_window(pan);
4330 const char *userptr = (const char *) panel_userptr(pan);
4331 int num = (userptr && *userptr) ? userptr[1] : '?';
4335 wprintw(win, "-pan%c-", num);
4338 for (y = 2; y < getmaxy(win) - 1; y++) {
4339 for (x = 1; x < getmaxx(win) - 1; x++) {
4341 waddch(win, UChar(num));
4346 #if USE_WIDEC_SUPPORT
4348 init_wide_panel(void)
4353 for (digit = 0; digit < 10; ++digit)
4354 make_fullwidth_digit(&temp[digit], digit);
4358 getyx(stdscr, y, x);
4359 digit = (y + x / 2) % 10;
4360 } while (add_wch(&temp[digit]) != ERR);
4364 fill_wide_panel(PANEL * pan)
4366 WINDOW *win = panel_window(pan);
4367 const char *userptr = (const char *) panel_userptr(pan);
4368 int num = (userptr && *userptr) ? userptr[1] : '?';
4372 wprintw(win, "-pan%c-", num);
4375 for (y = 2; y < getmaxy(win) - 1; y++) {
4376 for (x = 1; x < getmaxx(win) - 1; x++) {
4378 waddch(win, UChar(num));
4384 #define MAX_PANELS 5
4387 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4389 int which = cmd[1] - '0';
4394 hide_panel(px[which]);
4397 show_panel(px[which]);
4400 top_panel(px[which]);
4403 bottom_panel(px[which]);
4410 wait_a_while(nap_msec);
4414 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4418 PANEL *px[MAX_PANELS + 1];
4420 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4424 for (count = 0; count < 5; count++) {
4425 px[1] = mkpanel(COLOR_RED,
4430 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4432 px[2] = mkpanel(COLOR_GREEN,
4437 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4439 px[3] = mkpanel(COLOR_YELLOW,
4444 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4446 px[4] = mkpanel(COLOR_BLUE,
4451 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4453 px[5] = mkpanel(COLOR_MAGENTA,
4458 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4470 wait_a_while(nap_msec);
4472 saywhat("h3 s1 s2 s4 s5");
4473 move_panel(px[1], 0, 0);
4480 wait_a_while(nap_msec);
4482 canned_panel(px, "s1");
4483 canned_panel(px, "s2");
4486 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4488 wait_a_while(nap_msec);
4490 canned_panel(px, "s3");
4493 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4495 wait_a_while(nap_msec);
4497 canned_panel(px, "b3");
4498 canned_panel(px, "s4");
4499 canned_panel(px, "s5");
4500 canned_panel(px, "t3");
4501 canned_panel(px, "t1");
4502 canned_panel(px, "t2");
4503 canned_panel(px, "t3");
4504 canned_panel(px, "t4");
4506 for (itmp = 0; itmp < 6; itmp++) {
4507 WINDOW *w4 = panel_window(px[4]);
4508 WINDOW *w5 = panel_window(px[5]);
4511 wmove(w4, LINES / 8, 1);
4512 waddstr(w4, mod[itmp]);
4513 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4514 wmove(w5, LINES / 6, 1);
4515 waddstr(w5, mod[itmp]);
4517 wait_a_while(nap_msec);
4520 wmove(w4, LINES / 6, 1);
4521 waddstr(w4, mod[itmp]);
4522 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4523 wmove(w5, LINES / 8, 1);
4524 waddstr(w5, mod[itmp]);
4526 wait_a_while(nap_msec);
4530 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4532 wait_a_while(nap_msec);
4534 canned_panel(px, "t5");
4535 canned_panel(px, "t2");
4536 canned_panel(px, "t1");
4537 canned_panel(px, "d2");
4538 canned_panel(px, "h3");
4539 canned_panel(px, "d1");
4540 canned_panel(px, "d4");
4541 canned_panel(px, "d5");
4542 canned_panel(px, "d3");
4544 wait_a_while(nap_msec);
4553 #endif /* USE_LIBPANEL */
4555 /****************************************************************************
4559 ****************************************************************************/
4563 static bool pending_pan = FALSE;
4564 static bool show_panner_legend = TRUE;
4567 panner_legend(int line)
4569 static const char *const legend[] =
4571 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4572 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4573 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4574 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4576 int n = ((int) SIZEOF(legend) - (LINES - line));
4577 if (line < LINES && (n >= 0)) {
4579 if (show_panner_legend)
4580 printw("%s", legend[n]);
4582 return show_panner_legend;
4588 panner_h_cleanup(int from_y, int from_x, int to_x)
4590 if (!panner_legend(from_y))
4591 do_h_line(from_y, from_x, ' ', to_x);
4595 panner_v_cleanup(int from_y, int from_x, int to_y)
4597 if (!panner_legend(from_y))
4598 do_v_line(from_y, from_x, ' ', to_y);
4602 fill_pad(WINDOW *panpad, bool pan_lines)
4605 unsigned gridcount = 0;
4607 wmove(panpad, 0, 0);
4608 for (y = 0; y < getmaxy(panpad); y++) {
4609 for (x = 0; x < getmaxx(panpad); x++) {
4610 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4611 if (y == 0 && x == 0)
4612 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4614 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4615 else if (y == 0 || x == 0)
4616 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4618 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4619 (int) (gridcount++ % 26)));
4620 } else if (y % GRIDSIZE == 0)
4621 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4622 else if (x % GRIDSIZE == 0)
4623 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4625 waddch(panpad, ' ');
4632 int top_x, int top_y, int porty, int portx,
4633 int (*pgetc) (WINDOW *))
4635 #if HAVE_GETTIMEOFDAY
4636 struct timeval before, after;
4639 bool pan_lines = FALSE;
4640 bool scrollers = TRUE;
4643 int pxmax, pymax, lowend, highend, c;
4645 getmaxyx(pad, pymax, pxmax);
4646 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4650 #ifdef NCURSES_VERSION
4652 * During shell-out, the user may have resized the window. Adjust
4653 * the port size of the pad to accommodate this. Ncurses automatically
4654 * resizes all of the normal windows to fit on the new screen.
4672 show_panner_legend = !show_panner_legend;
4673 panner_legend(LINES - 4);
4674 panner_legend(LINES - 3);
4675 panner_legend(LINES - 2);
4676 panner_legend(LINES - 1);
4679 pan_lines = !pan_lines;
4680 fill_pad(pad, pan_lines);
4681 pending_pan = FALSE;
4684 #if HAVE_GETTIMEOFDAY
4688 panner_legend(LINES - 1);
4692 scrollers = !scrollers;
4695 /* Move the top-left corner of the pad, keeping the bottom-right
4698 case 'h': /* increase-columns: move left edge to left */
4702 panner_v_cleanup(top_y, top_x, porty);
4707 case 'j': /* decrease-lines: move top-edge down */
4711 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
4716 case 'k': /* increase-lines: move top-edge up */
4721 panner_h_cleanup(top_y, top_x, portx);
4725 case 'l': /* decrease-columns: move left-edge to right */
4729 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
4734 /* Move the bottom-right corner of the pad, keeping the top-left
4737 case KEY_IC: /* increase-columns: move right-edge to right */
4738 if (portx >= pxmax || portx >= COLS)
4741 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
4746 case KEY_IL: /* increase-lines: move bottom-edge down */
4747 if (porty >= pymax || porty >= LINES)
4750 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
4755 case KEY_DC: /* decrease-columns: move bottom edge up */
4760 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
4764 case KEY_DL: /* decrease-lines */
4769 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
4773 case KEY_LEFT: /* pan leftwards */
4780 case KEY_RIGHT: /* pan rightwards */
4781 if (basex + portx - (pymax > porty) < pxmax)
4787 case KEY_UP: /* pan upwards */
4794 case KEY_DOWN: /* pan downwards */
4795 if (basey + porty - (pxmax > portx) < pymax)
4810 basey = pymax - porty;
4820 mvaddch(top_y - 1, top_x - 1, ACS_ULCORNER);
4821 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
4822 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
4824 if (scrollers && (pxmax > portx - 1)) {
4825 int length = (portx - top_x - 1);
4826 float ratio = ((float) length) / ((float) pxmax);
4828 lowend = (int) ((float) top_x + ((float) basex * ratio));
4829 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
4831 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
4832 if (highend < portx) {
4834 do_h_line(porty - 1, lowend, ' ', highend + 1);
4836 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
4839 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
4841 if (scrollers && (pymax > porty - 1)) {
4842 int length = (porty - top_y - 1);
4843 float ratio = ((float) length) / ((float) pymax);
4845 lowend = (int) ((float) top_y + ((float) basey * ratio));
4846 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
4848 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
4849 if (highend < porty) {
4851 do_v_line(lowend, portx - 1, ' ', highend + 1);
4853 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
4856 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
4858 mvaddch(top_y - 1, portx - 1, ACS_URCORNER);
4859 mvaddch(porty - 1, top_x - 1, ACS_LLCORNER);
4860 mvaddch(porty - 1, portx - 1, ACS_LRCORNER);
4863 #if HAVE_GETTIMEOFDAY
4864 gettimeofday(&before, 0);
4866 wnoutrefresh(stdscr);
4871 porty - (pxmax > portx) - 1,
4872 portx - (pymax > porty) - 1);
4875 #if HAVE_GETTIMEOFDAY
4878 gettimeofday(&after, 0);
4879 elapsed = (after.tv_sec + after.tv_usec / 1.0e6)
4880 - (before.tv_sec + before.tv_usec / 1.0e6);
4881 move(LINES - 1, COLS - 12);
4882 printw("Secs: %2.03f", elapsed);
4889 ((c = pgetc(pad)) != KEY_EXIT);
4891 scrollok(stdscr, TRUE); /* reset to driver's default */
4895 padgetch(WINDOW *win)
4901 if ((pending_pan = (count > 0)) != FALSE) {
4903 pending_pan = (count != 0);
4906 switch (c = wGetchar(win)) {
4942 case ERR: /* FALLTHRU */
4948 if (c >= '0' && c <= '9') {
4949 count = count * 10 + (c - '0');
4963 #define PAD_HIGH 200
4964 #define PAD_WIDE 200
4968 /* Demonstrate pads. */
4970 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
4973 Cannot("cannot create requested pad");
4977 fill_pad(panpad, FALSE);
4979 panner_legend(LINES - 4);
4980 panner_legend(LINES - 3);
4981 panner_legend(LINES - 2);
4982 panner_legend(LINES - 1);
4984 keypad(panpad, TRUE);
4986 /* Make the pad (initially) narrow enough that a trace file won't wrap.
4987 * We'll still be able to widen it during a test, since that's required
4988 * for testing boundaries.
4990 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
4997 /****************************************************************************
4999 * Tests from John Burnell's PDCurses tester
5001 ****************************************************************************/
5004 Continue(WINDOW *win)
5008 mvwaddstr(win, 10, 1, " Press any key to continue");
5014 flushinp_test(WINDOW *win)
5015 /* Input test, adapted from John Burnell's PDCurses tester */
5017 int w, h, bx, by, sw, sh, i;
5022 getmaxyx(win, h, w);
5023 getbegyx(win, by, bx);
5026 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5031 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5032 wbkgd(subWin, COLOR_PAIR(2) | ' ');
5035 wattrset(subWin, A_BOLD);
5036 box(subWin, ACS_VLINE, ACS_HLINE);
5037 mvwaddstr(subWin, 2, 1, "This is a subwindow");
5041 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5042 * it only happened to "work" on SVr4 because that implementation does not
5043 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5044 * test behavior, we're using 'cbreak()', which will allow a single
5045 * character to return without needing a newline. - T.Dickey 1997/10/11.
5048 mvwaddstr(win, 0, 1, "This is a test of the flushinp() call.");
5050 mvwaddstr(win, 2, 1, "Type random keys for 5 seconds.");
5051 mvwaddstr(win, 3, 1,
5052 "These should be discarded (not echoed) after the subwindow goes away.");
5055 for (i = 0; i < 5; i++) {
5056 mvwprintw(subWin, 1, 1, "Time = %d", i);
5068 mvwaddstr(win, 2, 1,
5069 "If you were still typing when the window timer expired,");
5070 mvwaddstr(win, 3, 1,
5071 "or else you typed nothing at all while it was running,");
5072 mvwaddstr(win, 4, 1,
5073 "test was invalid. You'll see garbage or nothing at all. ");
5074 mvwaddstr(win, 6, 1, "Press a key");
5080 mvwaddstr(win, 12, 0,
5081 "If you see any key other than what you typed, flushinp() is broken.");
5090 "What you typed should now have been deleted; if not, wdelch() failed.");
5096 /****************************************************************************
5100 ****************************************************************************/
5108 menu_virtualize(int c)
5110 if (c == '\n' || c == KEY_EXIT)
5111 return (MAX_COMMAND + 1);
5113 return (REQ_SCR_ULINE);
5115 return (REQ_SCR_DLINE);
5116 else if (c == 'b' || c == KEY_NPAGE)
5117 return (REQ_SCR_UPAGE);
5118 else if (c == 'f' || c == KEY_PPAGE)
5119 return (REQ_SCR_DPAGE);
5120 else if (c == 'n' || c == KEY_DOWN)
5121 return (REQ_NEXT_ITEM);
5122 else if (c == 'p' || c == KEY_UP)
5123 return (REQ_PREV_ITEM);
5125 return (REQ_TOGGLE_ITEM);
5133 static CONST_MENUS char *animals[] =
5146 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5147 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5155 ITEM *items[SIZEOF(animals)];
5157 CONST_MENUS char **ap;
5158 int mrows, mcols, c;
5161 #ifdef NCURSES_MOUSE_VERSION
5162 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5164 mvaddstr(0, 0, "This is the menu test:");
5165 mvaddstr(2, 0, " Use up and down arrow to move the select bar.");
5166 mvaddstr(3, 0, " 'n' and 'p' act like arrows.");
5168 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
5169 mvaddstr(5, 0, " Press return to exit.");
5172 for (ap = animals; *ap; ap++) {
5173 if ((*ip = new_item(*ap, "")) != 0)
5178 m = new_menu(items);
5180 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
5181 scale_menu(m, &mrows, &mcols);
5183 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5184 set_menu_win(m, menuwin);
5185 keypad(menuwin, TRUE);
5188 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5192 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
5193 if (c == E_NOT_POSTED)
5195 if (c == E_REQUEST_DENIED)
5200 (void) mvprintw(LINES - 2, 0,
5201 "You chose: %s\n", item_name(current_item(m)));
5202 (void) addstr("Press any key to continue...");
5209 for (ip = items; *ip; ip++)
5211 #ifdef NCURSES_MOUSE_VERSION
5212 mousemask(0, (mmask_t *) 0);
5217 #define T_TBL(name) { #name, name }
5223 T_TBL(TRACE_DISABLE),
5226 T_TBL(TRACE_UPDATE),
5228 T_TBL(TRACE_CHARPUT),
5229 T_TBL(TRACE_ORDINARY),
5231 T_TBL(TRACE_VIRTPUT),
5232 T_TBL(TRACE_IEVENT),
5234 T_TBL(TRACE_ICALLS),
5235 T_TBL(TRACE_CCALLS),
5236 T_TBL(TRACE_DATABASE),
5238 T_TBL(TRACE_MAXIMUM),
5245 tracetrace(unsigned tlevel)
5252 for (n = 0; t_tbl[n].name != 0; n++)
5253 need += strlen(t_tbl[n].name) + 2;
5254 buf = typeMalloc(char, need);
5256 sprintf(buf, "0x%02x = {", tlevel);
5258 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5260 for (n = 1; t_tbl[n].name != 0; n++)
5261 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5262 strcat(buf, t_tbl[n].name);
5266 if (buf[strlen(buf) - 2] == ',')
5267 buf[strlen(buf) - 2] = '\0';
5268 return (strcat(buf, "}"));
5271 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5275 run_trace_menu(MENU * m)
5281 bool changed = FALSE;
5282 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5283 case E_UNKNOWN_COMMAND:
5286 items = menu_items(m);
5287 i = current_item(m);
5288 if (i == items[0]) {
5289 if (item_value(i)) {
5290 for (p = items + 1; *p != 0; p++)
5291 if (item_value(*p)) {
5292 set_item_value(*p, FALSE);
5297 for (p = items + 1; *p != 0; p++)
5298 if (item_value(*p)) {
5299 set_item_value(items[0], FALSE);
5312 /* interactively set the trace level */
5315 ITEM *items[SIZEOF(t_tbl)];
5322 mvaddstr(0, 0, "Interactively set trace level:");
5323 mvaddstr(2, 0, " Press space bar to toggle a selection.");
5324 mvaddstr(3, 0, " Use up and down arrow to move the select bar.");
5325 mvaddstr(4, 0, " Press return to set the trace level.");
5326 mvprintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5330 for (n = 0; t_tbl[n].name != 0; n++) {
5331 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
5337 m = new_menu(items);
5339 set_menu_format(m, 0, 2);
5340 scale_menu(m, &mrows, &mcols);
5342 menu_opts_off(m, O_ONEVALUE);
5343 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5344 set_menu_win(m, menuwin);
5345 keypad(menuwin, TRUE);
5348 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5352 for (ip = menu_items(m); *ip; ip++) {
5353 unsigned mask = t_tbl[item_index(*ip)].mask;
5355 set_item_value(*ip, _nc_tracing == 0);
5356 else if ((mask & _nc_tracing) == mask)
5357 set_item_value(*ip, TRUE);
5360 while (run_trace_menu(m))
5364 for (ip = menu_items(m); *ip; ip++)
5365 if (item_value(*ip))
5366 newtrace |= t_tbl[item_index(*ip)].mask;
5368 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5370 (void) mvprintw(LINES - 2, 0,
5371 "Trace level is %s\n", tracetrace(_nc_tracing));
5372 (void) addstr("Press any key to continue...");
5379 for (ip = items; *ip; ip++)
5383 #endif /* USE_LIBMENU */
5385 /****************************************************************************
5389 ****************************************************************************/
5392 make_label(int frow, int fcol, NCURSES_CONST char *label)
5394 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5397 set_field_buffer(f, 0, label);
5398 set_field_opts(f, (int) (field_opts(f) & ~O_ACTIVE));
5404 make_field(int frow, int fcol, int rows, int cols, bool secure)
5406 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5409 set_field_back(f, A_UNDERLINE);
5410 set_field_userptr(f, (void *) 0);
5416 display_form(FORM * f)
5421 scale_form(f, &rows, &cols);
5423 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5425 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5430 if (post_form(f) != E_OK)
5435 erase_form(FORM * f)
5437 WINDOW *w = form_win(f);
5438 WINDOW *s = form_sub(f);
5448 edit_secure(FIELD * me, int c)
5450 int rows, cols, frow, fcol, nrow, nbuf;
5452 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5454 char *source = field_buffer(me, 1);
5458 strcpy(temp, source ? source : "");
5459 len = (long) (char *) field_userptr(me);
5461 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5462 temp[len++] = (char) c;
5464 set_field_buffer(me, 1, temp);
5484 case REQ_RIGHT_CHAR:
5486 c = 0; /* we don't want to do inline editing */
5491 set_field_buffer(me, 1, temp);
5498 set_field_buffer(me, 1, temp);
5503 set_field_userptr(me, (void *) len);
5509 form_virtualize(FORM * f, WINDOW *w)
5512 static const struct {
5516 { CTRL('A'), REQ_NEXT_CHOICE },
5517 { CTRL('B'), REQ_PREV_WORD },
5518 { CTRL('C'), REQ_CLR_EOL },
5519 { CTRL('D'), REQ_DOWN_FIELD },
5520 { CTRL('E'), REQ_END_FIELD },
5521 { CTRL('F'), REQ_NEXT_PAGE },
5522 { CTRL('G'), REQ_DEL_WORD },
5523 { CTRL('H'), REQ_DEL_PREV },
5524 { CTRL('I'), REQ_INS_CHAR },
5525 { CTRL('K'), REQ_CLR_EOF },
5526 { CTRL('L'), REQ_LEFT_FIELD },
5527 { CTRL('M'), REQ_NEW_LINE },
5528 { CTRL('N'), REQ_NEXT_FIELD },
5529 { CTRL('O'), REQ_INS_LINE },
5530 { CTRL('P'), REQ_PREV_FIELD },
5531 { CTRL('R'), REQ_RIGHT_FIELD },
5532 { CTRL('S'), REQ_BEG_FIELD },
5533 { CTRL('U'), REQ_UP_FIELD },
5534 { CTRL('V'), REQ_DEL_CHAR },
5535 { CTRL('W'), REQ_NEXT_WORD },
5536 { CTRL('X'), REQ_CLR_FIELD },
5537 { CTRL('Y'), REQ_DEL_LINE },
5538 { CTRL('Z'), REQ_PREV_CHOICE },
5539 { ESCAPE, MAX_FORM_COMMAND + 1 },
5540 { KEY_BACKSPACE, REQ_DEL_PREV },
5541 { KEY_DOWN, REQ_DOWN_CHAR },
5542 { KEY_END, REQ_LAST_FIELD },
5543 { KEY_HOME, REQ_FIRST_FIELD },
5544 { KEY_LEFT, REQ_LEFT_CHAR },
5545 { KEY_LL, REQ_LAST_FIELD },
5546 { KEY_NEXT, REQ_NEXT_FIELD },
5547 { KEY_NPAGE, REQ_NEXT_PAGE },
5548 { KEY_PPAGE, REQ_PREV_PAGE },
5549 { KEY_PREVIOUS, REQ_PREV_FIELD },
5550 { KEY_RIGHT, REQ_RIGHT_CHAR },
5551 { KEY_UP, REQ_UP_CHAR },
5552 { QUIT, MAX_FORM_COMMAND + 1 }
5556 static int mode = REQ_INS_MODE;
5557 int c = wGetchar(w);
5559 FIELD *me = current_field(f);
5560 bool current = TRUE;
5562 if (c == CTRL(']')) {
5563 if (mode == REQ_INS_MODE) {
5564 mode = REQ_OVL_MODE;
5566 mode = REQ_INS_MODE;
5570 for (n = 0; n < SIZEOF(lookup); n++) {
5571 if (lookup[n].code == c) {
5572 c = lookup[n].result;
5577 mvprintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5580 * Force the field that the user is typing into to be in reverse video,
5581 * while the other fields are shown underlined.
5596 case REQ_LEFT_FIELD:
5598 case REQ_RIGHT_CHAR:
5602 current = (c < KEY_MAX);
5606 c = edit_secure(me, c);
5607 set_field_back(me, A_REVERSE);
5609 c = edit_secure(me, c);
5610 set_field_back(me, A_UNDERLINE);
5616 my_form_driver(FORM * form, int c)
5618 if (c == (MAX_FORM_COMMAND + 1)
5619 && form_driver(form, REQ_VALIDATION) == E_OK)
5627 #ifdef NCURSES_VERSION
5628 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5629 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5631 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5632 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5636 * Allow a middle initial, optionally with a '.' to end it.
5639 FIELDCHECK_CB(mi_field_check)
5641 char *s = field_buffer(fld, 0);
5645 for (n = 0; s[n] != '\0'; ++n) {
5652 } else if (isspace(UChar(s[n]))) {
5657 if (!isspace(UChar(s[n])))
5663 /* force the form to display a leading capital */
5664 if (islower(UChar(s[0]))) {
5665 s[0] = (char) toupper(UChar(s[0]));
5666 set_field_buffer(fld, 0, s);
5672 CHAR_CHECK_CB(mi_char_check)
5674 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5678 * Passwords should be at least 6 characters.
5681 FIELDCHECK_CB(pw_field_check)
5683 char *s = field_buffer(fld, 0);
5686 for (n = 0; s[n] != '\0'; ++n) {
5687 if (isspace(UChar(s[n]))) {
5696 CHAR_CHECK_CB(pw_char_check)
5698 return (isgraph(ch) ? TRUE : FALSE);
5706 FIELD *f[12], *secure;
5707 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
5708 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
5709 int finished = 0, c;
5712 #ifdef NCURSES_MOUSE_VERSION
5713 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5717 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
5718 addstr("^N -- go to next field ^P -- go to previous field\n");
5719 addstr("Home -- go to first field End -- go to last field\n");
5720 addstr("^L -- go to field to left ^R -- go to field to right\n");
5721 addstr("^U -- move upward to field ^D -- move downward to field\n");
5722 addstr("^W -- go to next word ^B -- go to previous word\n");
5723 addstr("^S -- go to start of field ^E -- go to end of field\n");
5724 addstr("^H -- delete previous char ^Y -- delete line\n");
5725 addstr("^G -- delete current word ^C -- clear to end of line\n");
5726 addstr("^K -- clear to end of field ^X -- clear field\n");
5727 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
5729 mvaddstr(4, 57, "Forms Entry Test");
5733 /* describe the form */
5734 memset(f, 0, sizeof(f));
5735 f[n++] = make_label(0, 15, "Sample Form");
5737 f[n++] = make_label(2, 0, "Last Name");
5738 f[n++] = make_field(3, 0, 1, 18, FALSE);
5739 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5741 f[n++] = make_label(2, 20, "First Name");
5742 f[n++] = make_field(3, 20, 1, 12, FALSE);
5743 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5745 f[n++] = make_label(2, 34, "Middle Name");
5746 f[n++] = make_field(3, 34, 1, 12, FALSE);
5747 set_field_type(f[n - 1], fty_middle);
5749 f[n++] = make_label(5, 0, "Comments");
5750 f[n++] = make_field(6, 0, 4, 46, FALSE);
5752 f[n++] = make_label(5, 20, "Password:");
5754 f[n++] = make_field(5, 30, 1, 9, TRUE);
5755 set_field_type(f[n - 1], fty_passwd);
5756 f[n++] = (FIELD *) 0;
5758 if ((form = new_form(f)) != 0) {
5764 nonl(); /* lets us read ^M's */
5766 switch (form_driver(form, c = form_virtualize(form, w))) {
5768 mvaddstr(5, 57, field_buffer(secure, 1));
5772 case E_UNKNOWN_COMMAND:
5773 finished = my_form_driver(form, c);
5785 for (c = 0; f[c] != 0; c++)
5787 free_fieldtype(fty_middle);
5788 free_fieldtype(fty_passwd);
5792 #ifdef NCURSES_MOUSE_VERSION
5793 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5796 #endif /* USE_LIBFORM */
5798 /****************************************************************************
5802 ****************************************************************************/
5805 fillwin(WINDOW *win, char ch)
5810 getmaxyx(win, y1, x1);
5811 for (y = 0; y < y1; y++) {
5813 for (x = 0; x < x1; x++)
5814 waddch(win, UChar(ch));
5819 crosswin(WINDOW *win, char ch)
5824 getmaxyx(win, y1, x1);
5825 for (y = 0; y < y1; y++) {
5826 for (x = 0; x < x1; x++)
5827 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
5828 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
5830 waddch(win, UChar(ch));
5835 #define OVERLAP_FLAVORS 5
5838 overlap_helpitem(int state, int item, char *message)
5840 int row = (item / 2);
5841 int col = ((item % 2) ? COLS / 2 : 0);
5843 move(LINES - 6 + row, col);
5844 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
5849 overlap_test_1_attr(WINDOW *win, int flavor, int col)
5851 short cpair = (short) (1 + (flavor * 2) + col);
5855 wattrset(win, A_NORMAL);
5858 wattrset(win, A_BOLD);
5861 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
5862 wattrset(win, COLOR_PAIR(cpair) | A_NORMAL);
5865 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
5866 wattrset(win, COLOR_PAIR(cpair) | A_BOLD);
5872 overlap_test_2_attr(WINDOW *win, int flavor, int col)
5874 short cpair = (short) (9 + (flavor * 2) + col);
5884 init_pair(cpair, COLOR_RED, COLOR_GREEN);
5885 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
5888 wbkgdset(win, ' ' | A_NORMAL);
5894 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
5899 const char *ths, *tht;
5903 state += OVERLAP_FLAVORS;
5904 state = state % OVERLAP_FLAVORS;
5905 assert(state >= 0 && state < OVERLAP_FLAVORS);
5907 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
5910 ths = col ? "B" : "A";
5911 tht = col ? "A" : "B";
5916 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
5924 overlap_test_1_attr(stdscr, flavors[row], col);
5925 sprintf(msg, "fill window %s with letter %s.", ths, ths);
5933 switch (flavors[row]) {
5935 sprintf(msg, "cross pattern in window %s.", ths);
5938 sprintf(msg, "draw box in window %s.", ths);
5941 sprintf(msg, "set background of window %s.", ths);
5944 sprintf(msg, "reset background of window %s.", ths);
5950 sprintf(msg, "clear window %s.", ths);
5954 switch (flavors[row]) {
5956 sprintf(msg, "overwrite %s onto %s.", ths, tht);
5959 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
5962 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
5965 sprintf(msg, "overlay %s onto %s.", ths, tht);
5970 overlap_helpitem(state, item, msg);
5971 wattrset(stdscr, A_NORMAL);
5972 wbkgdset(stdscr, ' ' | A_NORMAL);
5975 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
5976 state, flavors[state]);
5982 overlap_test_0(WINDOW *a, WINDOW *b)
5992 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
5994 overlap_test_1_attr(a, flavor, col);
5996 wattrset(a, A_NORMAL);
6000 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6002 overlap_test_2_attr(a, flavor, col);
6011 /* done in overlap_test_2_attr */
6014 /* done in overlap_test_2_attr */
6020 overlap_test_3(WINDOW *a)
6027 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
6034 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
6037 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
6045 /* test effects of overlapping windows */
6050 int state, flavor[OVERLAP_FLAVORS];
6052 WINDOW *win1 = newwin(9, 20, 3, 3);
6053 WINDOW *win2 = newwin(9, 20, 9, 16);
6059 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
6060 printw("the shared region of two overlapping windows A and B. The cross\n");
6061 printw("pattern in each window does not overlap the other.\n");
6063 memset(flavor, 0, sizeof(flavor));
6064 state = overlap_help(0, flavor);
6066 while (!isQuit(ch = Getchar()))
6068 case 'a': /* refresh window A first, then B */
6069 overlap_test_0(win1, win2);
6072 case 'b': /* refresh window B first, then A */
6073 overlap_test_0(win2, win1);
6076 case 'c': /* fill window A so it's visible */
6077 overlap_test_1(flavor[1], 0, win1, 'A');
6080 case 'd': /* fill window B so it's visible */
6081 overlap_test_1(flavor[1], 1, win2, 'B');
6084 case 'e': /* cross test pattern in window A */
6085 overlap_test_2(flavor[2], 0, win1, 'A');
6088 case 'f': /* cross test pattern in window A */
6089 overlap_test_2(flavor[2], 1, win2, 'B');
6092 case 'g': /* clear window A */
6093 overlap_test_3(win1);
6096 case 'h': /* clear window B */
6097 overlap_test_3(win2);
6100 case 'i': /* overwrite A onto B */
6101 overlap_test_4(flavor[4], win1, win2);
6104 case 'j': /* overwrite B onto A */
6105 overlap_test_4(flavor[4], win2, win1);
6110 state = overlap_help(state + 1, flavor);
6115 state = overlap_help(state - 1, flavor);
6120 state = overlap_help(state, flavor);
6124 state = overlap_help(state, flavor);
6139 /****************************************************************************
6143 ****************************************************************************/
6146 do_single_test(const char c)
6147 /* perform a single specified test */
6154 #if USE_WIDEC_SUPPORT
6164 #if USE_WIDEC_SUPPORT
6172 Cannot("does not support color.");
6177 #if USE_WIDEC_SUPPORT
6180 Cannot("does not support color.");
6188 Cannot("does not support color.");
6189 else if (!can_change_color())
6190 Cannot("has hardwired color values.");
6201 #if USE_WIDEC_SUPPORT
6210 #if USE_WIDEC_SUPPORT
6218 demo_panels(init_panel, fill_panel);
6222 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6224 demo_panels(init_wide_panel, fill_wide_panel);
6233 flushinp_test(stdscr);
6237 test_sgr_attributes();
6260 #if USE_LIBMENU && defined(TRACE)
6279 static const char *const tbl[] =
6281 "Usage: ncurses [options]"
6284 #ifdef NCURSES_VERSION
6285 ," -a f,b set default-colors (assumed white-on-black)"
6286 ," -d use default-colors if terminal supports them"
6289 ," -e fmt specify format for soft-keys test (e)"
6292 ," -f rip-off footer line (can repeat)"
6293 ," -h rip-off header line (can repeat)"
6295 ," -m do not use colors"
6296 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6298 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6301 ," -t mask specify default trace-level (may toggle with ^T)"
6305 for (n = 0; n < SIZEOF(tbl); n++)
6306 fprintf(stderr, "%s\n", tbl[n]);
6307 ExitProgram(EXIT_FAILURE);
6311 set_terminal_modes(void)
6316 scrollok(stdscr, TRUE);
6317 idlok(stdscr, TRUE);
6318 keypad(stdscr, TRUE);
6323 announce_sig(int sig)
6325 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6331 rip_footer(WINDOW *win, int cols)
6333 wbkgd(win, A_REVERSE);
6336 wprintw(win, "footer: window %p, %d columns", win, cols);
6342 rip_header(WINDOW *win, int cols)
6344 wbkgd(win, A_REVERSE);
6347 wprintw(win, "header: window %p, %d columns", win, cols);
6351 #endif /* HAVE_RIPOFFLINE */
6359 (void) puts("This is the ncurses main menu");
6360 (void) puts("a = keyboard and mouse input test");
6361 #if USE_WIDEC_SUPPORT
6362 (void) puts("A = wide-character keyboard and mouse input test");
6364 (void) puts("b = character attribute test");
6365 #if USE_WIDEC_SUPPORT
6366 (void) puts("B = wide-character attribute test");
6368 (void) puts("c = color test pattern");
6369 #if USE_WIDEC_SUPPORT
6370 (void) puts("C = color test pattern using wide-character calls");
6373 (void) puts("d = edit RGB color values");
6375 (void) puts("e = exercise soft keys");
6376 #if USE_WIDEC_SUPPORT
6377 (void) puts("E = exercise soft keys using wide-characters");
6380 (void) puts("f = display ACS characters");
6381 #if USE_WIDEC_SUPPORT
6382 (void) puts("F = display Wide-ACS characters");
6384 (void) puts("g = display windows and scrolling");
6385 (void) puts("i = test of flushinp()");
6386 (void) puts("k = display character attributes");
6388 (void) puts("m = menu code test");
6391 (void) puts("o = exercise panels library");
6392 #if USE_WIDEC_SUPPORT
6393 (void) puts("O = exercise panels with wide-characters");
6396 (void) puts("p = exercise pad features");
6397 (void) puts("q = quit");
6399 (void) puts("r = exercise forms code");
6401 (void) puts("s = overlapping-refresh test");
6402 #if USE_LIBMENU && defined(TRACE)
6403 (void) puts("t = set trace level");
6405 (void) puts("? = repeat this command summary");
6407 (void) fputs("> ", stdout);
6408 (void) fflush(stdout); /* necessary under SVr4 curses */
6411 * This used to be an 'fgets()' call. However (on Linux, at least)
6412 * mixing stream I/O and 'read()' (used in the library) causes the
6413 * input stream to be flushed when switching between the two.
6418 if (read(fileno(stdin), &ch, 1) <= 0) {
6422 } else if (command == 0 && !isspace(UChar(ch))) {
6424 } else if (ch == '\n' || ch == '\r') {
6425 if ((command == 'd') && !top) {
6426 (void) fputs("Do not nest test-d\n", stdout);
6431 (void) fputs("> ", stdout);
6432 (void) fflush(stdout);
6436 if (do_single_test(command)) {
6438 * This may be overkill; it's intended to reset everything back
6439 * to the initial terminal modes so that tests don't get in
6443 set_terminal_modes();
6448 if (command == '?') {
6449 (void) puts("This is the ncurses capability tester.");
6451 puts("You may select a test from the main menu by typing the");
6453 puts("key letter of the choice (the letter to left of the =)");
6455 puts("at the > prompt. Type `q' to exit.");
6463 /*+-------------------------------------------------------------------------
6465 --------------------------------------------------------------------------*/
6467 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6468 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6471 main(int argc, char *argv[])
6475 #ifdef NCURSES_VERSION
6476 int default_fg = COLOR_WHITE;
6477 int default_bg = COLOR_BLACK;
6478 bool assumed_colors = FALSE;
6479 bool default_colors = FALSE;
6481 char *palette_file = 0;
6482 bool monochrome = FALSE;
6484 setlocale(LC_ALL, "");
6486 while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) {
6488 #ifdef NCURSES_VERSION
6490 assumed_colors = TRUE;
6491 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6494 default_colors = TRUE;
6498 my_e_param = atoi(optarg);
6499 #ifdef NCURSES_VERSION
6500 if (my_e_param > 3) /* allow extended layouts */
6509 ripoffline(-1, rip_footer);
6512 ripoffline(1, rip_header);
6514 #endif /* HAVE_RIPOFFLINE */
6519 palette_file = optarg;
6523 nap_msec = atol(optarg);
6528 save_trace = (unsigned) strtol(optarg, 0, 0);
6537 * If there's no menus (unlikely for ncurses!), then we'll have to set
6538 * tracing on initially, just in case the user wants to test something that
6539 * doesn't involve wGetchar.
6542 /* enable debugging */
6546 if (!isatty(fileno(stdin)))
6548 #endif /* USE_LIBMENU */
6552 /* tell it we're going to play with soft keys */
6553 slk_init(my_e_param);
6557 /* set up null signal catcher so we can see what interrupts to getch do */
6558 signal(SIGUSR1, announce_sig);
6561 /* we must initialize the curses data structure only once */
6565 /* tests, in general, will want these modes */
6566 use_colors = monochrome ? FALSE : has_colors();
6570 #ifdef NCURSES_VERSION_PATCH
6571 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6572 #if HAVE_USE_DEFAULT_COLORS
6573 if (default_colors) {
6574 use_default_colors();
6577 #if NCURSES_VERSION_PATCH >= 20000708
6578 else if (assumed_colors)
6579 assume_default_colors(default_fg, default_bg);
6582 #else /* normal SVr4 curses */
6583 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6585 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6587 if (can_change_color()) {
6589 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
6590 for (cp = 0; cp < max_colors; ++cp) {
6592 &all_colors[cp].red,
6593 &all_colors[cp].green,
6594 &all_colors[cp].blue);
6596 if (palette_file != 0) {
6597 FILE *fp = fopen(palette_file, "r");
6599 char buffer[BUFSIZ];
6600 int red, green, blue;
6602 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6603 if (sscanf(buffer, "scale:%d", &c) == 1) {
6605 } else if (sscanf(buffer, "%d:%d %d %d",
6614 all_colors[c].red = (short) ((red * 1000) / scale);
6615 all_colors[c].green = (short) ((green * 1000) / scale);
6616 all_colors[c].blue = (short) ((blue * 1000) / scale);
6624 set_terminal_modes();
6628 * Return to terminal mode, so we're guaranteed of being able to
6629 * select terminal commands even if the capabilities are wrong.
6633 #if HAVE_CURSES_VERSION
6634 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6635 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6636 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6637 NCURSES_VERSION_MAJOR,
6638 NCURSES_VERSION_MINOR,
6639 NCURSES_VERSION_PATCH);
6641 (void) puts("Welcome to ncurses. Press ? for help.");
6646 ExitProgram(EXIT_SUCCESS);
6649 /* ncurses.c ends here */