1 /****************************************************************************
2 * Copyright (c) 1998-2018,2019 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.514 2019/01/21 20:15:28 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;
84 #define NCURSES_CONST_PARAM char
86 #define mmask_t chtype /* not specified in XSI */
89 #ifdef CURSES_ACS_ARRAY
90 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
91 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
92 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
93 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
94 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
95 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
96 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
98 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
99 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
100 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
101 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
102 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
103 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
104 #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 */
123 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
124 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
125 #define reset_wchars(state) init_mb(state)
126 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
127 #define count_wchars(src, len, state) wcstombs(0, src, len)
128 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
129 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
134 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
135 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
136 #define reset_mbytes(state) init_mb(state)
137 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
138 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
139 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
140 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
144 #define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real)
146 #define P(string) printw("%s\n", string)
148 #define BLANK ' ' /* this is the background character */
150 static int MaxColors; /* the actual number of colors we'll use */
151 static int MinColors; /* the minimum color code */
152 static bool UseColors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
157 #if HAVE_COLOR_CONTENT
160 NCURSES_COLOR_T green;
161 NCURSES_COLOR_T blue;
164 static RGB_DATA *all_colors;
167 static void main_menu(bool);
168 static void failed(const char *s) GCC_NORETURN;
171 failed(const char *s)
175 ExitProgram(EXIT_FAILURE);
191 isQuit(int c, bool escape)
193 return ((c) == QUIT || (escape && ((c) == ESCAPE)));
195 #define case_QUIT QUIT: case ESCAPE
197 /* Common function to allow ^T to toggle trace-mode in the middle of a test
198 * so that trace-files can be made smaller.
201 wGetchar(WINDOW *win)
205 while ((c = wgetch(win)) == CTRL('T')) {
207 save_trace = _nc_tracing;
208 Trace(("TOGGLE-TRACING OFF"));
211 _nc_tracing = save_trace;
215 Trace(("TOGGLE-TRACING ON"));
222 #define Getchar() wGetchar(stdscr)
225 /* replaces wgetnstr(), since we want to be able to edit values */
227 wGetstring(WINDOW *win, char *buffer, int limit)
234 (void) wattrset(win, A_REVERSE);
236 x = (int) strlen(buffer);
238 if (x > (int) strlen(buffer))
239 x = (int) strlen(buffer);
241 wprintw(win, "%-*s", limit, buffer);
242 wmove(win, y0, x0 + x);
243 switch (ch = wGetchar(win)) {
256 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
274 if (!isprint(ch) || ch >= KEY_MIN) {
276 } else if ((int) strlen(buffer) < limit) {
278 for (j = (int) strlen(buffer) + 1; j > x; --j) {
279 buffer[j] = buffer[j - 1];
281 buffer[x++] = (char) ch;
288 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
296 fullwidth_digit(int ch)
298 return (wchar_t) (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_digit(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = (wchar_t) ch;
323 make_fullwidth_digit(cchar_t *target, int digit)
327 source[0] = fullwidth_digit(digit + '0');
329 setcchar(target, source, A_NORMAL, 0, 0);
334 wGet_wchar(WINDOW *win, wint_t *result)
338 while ((c = wget_wch(win, result)) == CTRL('T')) {
340 save_trace = _nc_tracing;
341 Trace(("TOGGLE-TRACING OFF"));
344 _nc_tracing = save_trace;
348 Trace(("TOGGLE-TRACING ON"));
351 c = wget_wch(win, result);
355 #define Get_wchar(result) wGet_wchar(stdscr, result)
357 /* replaces wgetn_wstr(), since we want to be able to edit values */
360 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
369 (void) wattrset(win, A_REVERSE);
371 x = (int) wcslen(buffer);
373 if (x > (int) wcslen(buffer))
374 x = (int) wcslen(buffer);
376 /* clear the "window' */
378 wprintw(win, "%*s", limit, " ");
380 /* write the existing buffer contents */
382 waddnwstr(win, buffer, limit);
384 /* positions the cursor past character 'x' */
386 waddnwstr(win, buffer, x);
388 switch (wGet_wchar(win, &ch)) {
428 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
448 } else if ((int) wcslen(buffer) < limit) {
450 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
451 buffer[j] = buffer[j - 1];
453 buffer[x++] = (wchar_t) ch;
460 wattroff(win, A_REVERSE);
464 #endif /* USE_SOFTKEYS */
466 #endif /* USE_WIDEC_SUPPORT */
472 addstr("Press any key to continue... ");
477 Cannot(const char *what)
479 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
485 ShellOut(bool message)
488 addstr("Shelling out...");
494 IGNORE_RC(system("sh"));
497 addstr("returned from shellout.\n");
501 #ifdef NCURSES_MOUSE_VERSION
503 * This function is the same as _tracemouse(), but we cannot count on that
504 * being available in the non-debug library.
507 mouse_decode(MEVENT const *ep)
509 static char buf[80 + (5 * 10) + (32 * 15)];
511 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
512 "id %2d at (%2d, %2d, %d) state %4lx = {",
513 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
516 if ((ep->bstate & m)==m) { \
517 _nc_STRCAT(buf, s, sizeof(buf)); \
518 _nc_STRCAT(buf, ", ", sizeof(buf)); \
521 SHOW(BUTTON1_RELEASED, "release-1");
522 SHOW(BUTTON1_PRESSED, "press-1");
523 SHOW(BUTTON1_CLICKED, "click-1");
524 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
525 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
526 #if NCURSES_MOUSE_VERSION == 1
527 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
530 SHOW(BUTTON2_RELEASED, "release-2");
531 SHOW(BUTTON2_PRESSED, "press-2");
532 SHOW(BUTTON2_CLICKED, "click-2");
533 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
534 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
535 #if NCURSES_MOUSE_VERSION == 1
536 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
539 SHOW(BUTTON3_RELEASED, "release-3");
540 SHOW(BUTTON3_PRESSED, "press-3");
541 SHOW(BUTTON3_CLICKED, "click-3");
542 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
543 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
544 #if NCURSES_MOUSE_VERSION == 1
545 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
548 SHOW(BUTTON4_RELEASED, "release-4");
549 SHOW(BUTTON4_PRESSED, "press-4");
550 SHOW(BUTTON4_CLICKED, "click-4");
551 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
552 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
553 #if NCURSES_MOUSE_VERSION == 1
554 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
557 #if NCURSES_MOUSE_VERSION == 2
558 SHOW(BUTTON5_RELEASED, "release-5");
559 SHOW(BUTTON5_PRESSED, "press-5");
560 SHOW(BUTTON5_CLICKED, "click-5");
561 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
562 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
565 SHOW(BUTTON_CTRL, "ctrl");
566 SHOW(BUTTON_SHIFT, "shift");
567 SHOW(BUTTON_ALT, "alt");
568 SHOW(ALL_MOUSE_EVENTS, "all-events");
569 SHOW(REPORT_MOUSE_POSITION, "position");
573 if (buf[strlen(buf) - 1] == ' ')
574 buf[strlen(buf) - 2] = '\0';
575 _nc_STRCAT(buf, "}", sizeof(buf));
580 show_mouse(WINDOW *win)
588 outside = !wenclose(win, event.y, event.x);
591 (void) wstandout(win);
592 waddstr(win, "KEY_MOUSE");
593 (void) wstandend(win);
595 waddstr(win, "KEY_MOUSE");
597 wprintw(win, ", %s", mouse_decode(&event));
602 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
606 wmove(win, event.y, event.x);
614 #endif /* NCURSES_MOUSE_VERSION */
616 /****************************************************************************
618 * Character input test
620 ****************************************************************************/
622 #define NUM_GETCH_FLAGS 256
623 typedef bool GetchFlags[NUM_GETCH_FLAGS];
626 setup_getch(WINDOW *win, GetchFlags flags)
628 keypad(win, flags['k']); /* should be redundant, but for testing */
629 meta(win, flags['m']); /* force this to a known state */
637 init_getch(WINDOW *win, GetchFlags flags, int delay)
639 memset(flags, FALSE, NUM_GETCH_FLAGS);
640 flags[UChar('k')] = (win == stdscr);
641 flags[UChar('m')] = TRUE;
642 flags[UChar('t')] = (delay != 0);
644 setup_getch(win, flags);
648 blocking_getch(GetchFlags flags, int delay)
650 return ((delay < 0) && flags['t']);
653 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
656 wgetch_help(WINDOW *win, GetchFlags flags)
658 static const char *help[] =
660 "e -- toggle echo mode"
661 ,"g -- triggers a getstr test"
662 ,"k -- toggle keypad/literal mode"
663 ,"m -- toggle meta (7-bit/8-bit) mode"
666 ,"t -- toggle timeout"
667 ,"w -- create a new window"
669 ,"z -- suspend this process"
673 unsigned chk = ((SIZEOF(help) + 1) / 2);
678 printw("Type any key to see its %s value. Also:\n",
679 flags['k'] ? "keypad" : "literal");
680 for (n = 0; n < SIZEOF(help); ++n) {
681 const char *msg = help[n];
682 int row = 1 + (int) (n % chk);
683 int col = (n >= chk) ? COLS / 2 : 0;
684 int flg = ((strstr(msg, "toggle") != 0)
685 && (flags[UChar(*msg)] != FALSE));
686 if (*msg == '^' && ExitOnEscape())
687 msg = "^[,^q -- quit";
690 MvPrintw(row, col, "%s", msg);
701 wgetch_wrap(WINDOW *win, int first_y)
703 int last_y = getmaxy(win) - 1;
704 int y = getcury(win) + 1;
712 #if defined(KEY_RESIZE) && HAVE_WRESIZE
718 static WINSTACK *winstack = 0;
719 static unsigned len_winstack = 0;
732 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
734 unsigned need = (level + 1) * 2;
736 assert(level < (unsigned) COLS);
740 winstack = typeMalloc(WINSTACK, len_winstack);
741 } else if (need >= len_winstack) {
743 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
746 failed("remember_boxes");
747 winstack[level].text = txt_win;
748 winstack[level].frame = box_win;
751 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
755 /* this chunk is now done in resize_term() */
762 #define slk_repaint() /* nothing */
765 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
767 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
768 * Resize both and paint the box in the parent.
771 resize_boxes(unsigned level, WINDOW *win)
775 int high = LINES - base;
779 wnoutrefresh(stdscr);
783 for (n = 0; n < level; ++n) {
784 wresize(winstack[n].frame, high, wide);
785 wresize(winstack[n].text, high - 2, wide - 2);
788 werase(winstack[n].text);
789 box(winstack[n].frame, 0, 0);
790 wnoutrefresh(winstack[n].frame);
791 wprintw(winstack[n].text,
793 getmaxy(winstack[n].text),
794 getmaxx(winstack[n].text));
795 wnoutrefresh(winstack[n].text);
796 if (winstack[n].text == win)
801 #endif /* resize_boxes */
803 #define forget_boxes() /* nothing */
804 #define remember_boxes(level,text,frame) /* nothing */
808 * Return-code is OK/ERR or a keyname.
813 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
817 wgetch_test(unsigned level, WINDOW *win, int delay)
820 int first_y, first_x;
825 init_getch(win, flags, delay);
826 notimeout(win, FALSE);
827 wtimeout(win, delay);
828 getyx(win, first_y, first_x);
830 wgetch_help(win, flags);
831 wsetscrreg(win, first_y, getmaxy(win) - 1);
835 while ((c = wGetchar(win)) == ERR) {
837 if (blocking_getch(flags, delay)) {
838 (void) wprintw(win, "%05d: input error", incount);
841 (void) wprintw(win, "%05d: input timed out", incount);
843 wgetch_wrap(win, first_y);
845 if (c == ERR && blocking_getch(flags, delay)) {
847 wgetch_wrap(win, first_y);
848 } else if (isQuit(c, ExitOnEscape())) {
850 } else if (c == 'e') {
851 flags[UChar('e')] = !flags[UChar('e')];
852 setup_getch(win, flags);
853 wgetch_help(win, flags);
854 } else if (c == 'g') {
855 waddstr(win, "getstr test: ");
857 c = wgetnstr(win, buf, sizeof(buf) - 1);
859 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
860 (int) strlen(buf), buf,
863 wgetch_wrap(win, first_y);
864 } else if (c == 'k') {
865 flags[UChar('k')] = !flags[UChar('k')];
866 setup_getch(win, flags);
867 wgetch_help(win, flags);
868 } else if (c == 'm') {
869 flags[UChar('m')] = !flags[UChar('m')];
870 setup_getch(win, flags);
871 wgetch_help(win, flags);
872 } else if (c == 's') {
874 } else if (c == 't') {
875 notimeout(win, flags[UChar('t')]);
876 flags[UChar('t')] = !flags[UChar('t')];
877 wgetch_help(win, flags);
878 } else if (c == 'w') {
879 int high = getmaxy(win) - 1 - first_y + 1;
880 int wide = getmaxx(win) - first_x;
882 int new_y = first_y + getbegy(win);
883 int new_x = first_x + getbegx(win);
885 getyx(win, old_y, old_x);
886 if (high > 2 && wide > 2) {
887 WINDOW *wb = newwin(high, wide, new_y, new_x);
888 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
893 remember_boxes(level, wi, wb);
894 wgetch_test(level + 1, wi, delay);
898 wgetch_help(win, flags);
899 wmove(win, old_y, old_x);
905 } else if (c == 'z') {
906 kill(getpid(), SIGTSTP);
909 wprintw(win, "Key pressed: %04o ", c);
910 #ifdef NCURSES_MOUSE_VERSION
911 if (c == KEY_MOUSE) {
914 #endif /* NCURSES_MOUSE_VERSION */
916 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
917 if (c == KEY_RESIZE) {
918 resize_boxes(level, win);
921 (void) waddstr(win, keyname(c));
922 } else if (c >= 0x80) {
923 unsigned c2 = (unsigned) c;
924 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
925 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
929 (void) wprintw(win, "%c", UChar(c));
930 else if (c2 != UChar(c))
931 (void) wprintw(win, "M-%s", unctrl(c2));
933 (void) wprintw(win, "%s", unctrl(c2));
934 waddstr(win, " (high-half character)");
937 (void) wprintw(win, "%c (ASCII printable character)", c);
939 (void) wprintw(win, "%s (ASCII control character)",
942 wgetch_wrap(win, first_y);
949 init_getch(win, flags, delay);
953 begin_getch_test(void)
960 #ifdef NCURSES_MOUSE_VERSION
961 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
964 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
966 getnstr(buf, sizeof(buf) - 1);
970 if (isdigit(UChar(buf[0]))) {
971 delay = atoi(buf) * 100;
981 finish_getch_test(void)
983 #ifdef NCURSES_MOUSE_VERSION
984 mousemask(0, (mmask_t *) 0);
993 getch_test(bool recur GCC_UNUSED)
995 int delay = begin_getch_test();
998 wgetch_test(0, stdscr, delay);
1000 finish_getch_test();
1005 #if USE_WIDEC_SUPPORT
1007 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1008 * Resize both and paint the box in the parent.
1010 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1012 resize_wide_boxes(unsigned level, WINDOW *win)
1016 int high = LINES - base;
1020 wnoutrefresh(stdscr);
1024 for (n = 0; n < level; ++n) {
1025 wresize(winstack[n].frame, high, wide);
1026 wresize(winstack[n].text, high - 2, wide - 2);
1029 werase(winstack[n].text);
1030 box_set(winstack[n].frame, 0, 0);
1031 wnoutrefresh(winstack[n].frame);
1032 wprintw(winstack[n].text,
1034 getmaxy(winstack[n].text),
1035 getmaxx(winstack[n].text));
1036 wnoutrefresh(winstack[n].text);
1037 if (winstack[n].text == win)
1042 #endif /* KEY_RESIZE */
1045 wcstos(const wchar_t *src)
1049 const wchar_t *tmp = src;
1050 #ifndef state_unused
1054 reset_wchars(state);
1055 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1056 unsigned have = (unsigned) need;
1057 if ((result = typeCalloc(char, have + 1)) != 0) {
1059 if (trans_wchars(result, tmp, have, &state) != have) {
1071 wget_wch_test(unsigned level, WINDOW *win, int delay)
1073 wchar_t wchar_buf[BUFSIZ];
1074 wint_t wint_buf[BUFSIZ];
1075 int first_y, first_x;
1082 init_getch(win, flags, delay);
1083 notimeout(win, FALSE);
1084 wtimeout(win, delay);
1085 getyx(win, first_y, first_x);
1087 wgetch_help(win, flags);
1088 wsetscrreg(win, first_y, getmaxy(win) - 1);
1089 scrollok(win, TRUE);
1092 while ((code = wGet_wchar(win, &c)) == ERR) {
1094 if (blocking_getch(flags, delay)) {
1095 (void) wprintw(win, "%05d: input error", incount);
1098 (void) wprintw(win, "%05d: input timed out", incount);
1100 wgetch_wrap(win, first_y);
1102 if (code == ERR && blocking_getch(flags, delay)) {
1103 wprintw(win, "ERR");
1104 wgetch_wrap(win, first_y);
1105 } else if (isQuit((int) c, ExitOnEscape())) {
1107 } else if (c == 'e') {
1108 flags[UChar('e')] = !flags[UChar('e')];
1109 setup_getch(win, flags);
1110 wgetch_help(win, flags);
1111 } else if (c == 'g') {
1112 waddstr(win, "getstr test: ");
1114 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1117 wprintw(win, "wgetn_wstr returns an error.");
1120 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1123 if ((temp = wcstos(wchar_buf)) != 0) {
1124 wprintw(win, "I saw %d characters:\n\t`%s'.",
1125 (int) wcslen(wchar_buf), temp);
1128 wprintw(win, "I saw %d characters (cannot convert).",
1129 (int) wcslen(wchar_buf));
1133 wgetch_wrap(win, first_y);
1134 } else if (c == 'k') {
1135 flags[UChar('k')] = !flags[UChar('k')];
1136 setup_getch(win, flags);
1137 wgetch_help(win, flags);
1138 } else if (c == 'm') {
1139 flags[UChar('m')] = !flags[UChar('m')];
1140 setup_getch(win, flags);
1141 wgetch_help(win, flags);
1142 } else if (c == 's') {
1144 } else if (c == 't') {
1145 notimeout(win, flags[UChar('t')]);
1146 flags[UChar('t')] = !flags[UChar('t')];
1147 wgetch_help(win, flags);
1148 } else if (c == 'w') {
1149 int high = getmaxy(win) - 1 - first_y + 1;
1150 int wide = getmaxx(win) - first_x;
1152 int new_y = first_y + getbegy(win);
1153 int new_x = first_x + getbegx(win);
1155 getyx(win, old_y, old_x);
1156 if (high > 2 && wide > 2) {
1157 WINDOW *wb = newwin(high, wide, new_y, new_x);
1158 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1163 remember_boxes(level, wi, wb);
1164 wget_wch_test(level + 1, wi, delay);
1168 wgetch_help(win, flags);
1169 wmove(win, old_y, old_x);
1174 } else if (c == 'z') {
1175 kill(getpid(), SIGTSTP);
1178 wprintw(win, "Key pressed: %04o ", (int) c);
1179 #ifdef NCURSES_MOUSE_VERSION
1180 if (c == KEY_MOUSE) {
1183 #endif /* NCURSES_MOUSE_VERSION */
1184 if (code == KEY_CODE_YES) {
1185 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1186 if (c == KEY_RESIZE) {
1187 resize_wide_boxes(level, win);
1190 (void) waddstr(win, keyname((wchar_t) c));
1192 (void) waddstr(win, key_name((wchar_t) c));
1193 if (c < 256 && iscntrl(c)) {
1194 (void) wprintw(win, " (control character)");
1196 (void) wprintw(win, " = %#x (printable character)",
1200 wgetch_wrap(win, first_y);
1207 init_getch(win, flags, delay);
1211 x_getch_test(bool recur GCC_UNUSED)
1213 int delay = begin_getch_test();
1216 wget_wch_test(0, stdscr, delay);
1218 finish_getch_test();
1224 /****************************************************************************
1226 * Character attributes test
1228 ****************************************************************************/
1230 #if HAVE_SETUPTERM || HAVE_TGETENT
1231 #define get_ncv() TIGETNUM("ncv","NC")
1232 #define get_xmc() TIGETNUM("xmc","sg")
1234 #define get_ncv() -1
1235 #define get_xmc() -1
1242 static int first = TRUE;
1243 static chtype result = 0;
1249 char *area_pointer = parsed;
1251 tgetent(buffer, getenv("TERM"));
1254 if (TIGETSTR("smso", "so"))
1255 result |= A_STANDOUT;
1256 if (TIGETSTR("smul", "us"))
1257 result |= A_UNDERLINE;
1258 if (TIGETSTR("rev", "mr"))
1259 result |= A_REVERSE;
1260 if (TIGETSTR("blink", "mb"))
1262 if (TIGETSTR("dim", "mh"))
1264 if (TIGETSTR("bold", "md"))
1266 if (TIGETSTR("smacs", "ac"))
1267 result |= A_ALTCHARSET;
1273 #define termattrs() my_termattrs()
1276 #define ATTRSTRING_1ST 32 /* ' ' */
1277 #define ATTRSTRING_END 126 /* '~' */
1279 #define COLS_PRE_ATTRS 5
1280 #define COLS_AFT_ATTRS 15
1281 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1282 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1283 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1285 static char attr_test_string[MAX_ATTRSTRING + 1];
1288 attr_legend(WINDOW *helpwin)
1293 MvWPrintw(helpwin, row++, col,
1295 MvWPrintw(helpwin, row++, col,
1298 MvWPrintw(helpwin, row++, col,
1299 "Modify the test strings:");
1300 MvWPrintw(helpwin, row++, col,
1301 " A digit sets gaps on each side of displayed attributes");
1302 MvWPrintw(helpwin, row++, col,
1303 " </> shifts the text left/right. ");
1305 MvWPrintw(helpwin, row++, col,
1308 MvWPrintw(helpwin, row++, col,
1309 " f/F/b/B toggle foreground/background background color");
1310 MvWPrintw(helpwin, row++, col,
1311 " t/T toggle text/background color attribute");
1313 MvWPrintw(helpwin, row++, col,
1314 " a/A toggle ACS (alternate character set) mapping");
1315 MvWPrintw(helpwin, row, col,
1316 " v/V toggle video attribute to combine with each line");
1317 #if USE_WIDEC_SUPPORT
1318 MvWPrintw(helpwin, row, col,
1319 " w/W toggle normal/wide (double-width) test-characters");
1324 show_color_attr(int fg, int bg, int tx)
1327 printw(" Colors (fg %d, bg %d", fg, bg);
1329 printw(", text %d", tx);
1335 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1342 *fg = (NCURSES_COLOR_T) (*fg + 1);
1345 *fg = (NCURSES_COLOR_T) (*fg - 1);
1348 *bg = (NCURSES_COLOR_T) (*bg + 1);
1351 *bg = (NCURSES_COLOR_T) (*bg - 1);
1354 *tx = (NCURSES_COLOR_T) (*tx + 1);
1357 *tx = (NCURSES_COLOR_T) (*tx - 1);
1365 *fg = (NCURSES_COLOR_T) MinColors;
1366 if (*fg < MinColors)
1367 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1369 *bg = (NCURSES_COLOR_T) MinColors;
1370 if (*bg < MinColors)
1371 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1375 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1384 adjust_attr_string(int adjust)
1386 char save = attr_test_string[0];
1387 int first = ((int) UChar(save)) + adjust;
1390 if (first >= ATTRSTRING_1ST) {
1391 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1392 if (k > ATTRSTRING_END)
1394 attr_test_string[j] = (char) k;
1395 if (((k + 1 - first) % 5) == 0) {
1396 if (++j >= MAX_ATTRSTRING)
1398 attr_test_string[j] = ' ';
1401 if ((LEN_ATTRSTRING - j) > 5) {
1402 attr_test_string[0] = save;
1403 adjust_attr_string(adjust - 1);
1405 while (j < MAX_ATTRSTRING)
1406 attr_test_string[j++] = ' ';
1407 attr_test_string[j] = '\0';
1413 * Prefer the right-end of the string for starting, since that maps to the
1414 * VT100 line-drawing.
1417 default_attr_string(void)
1419 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1420 result += (LEN_ATTRSTRING / 5);
1421 if (result < ATTRSTRING_1ST)
1422 result = ATTRSTRING_1ST;
1427 init_attr_string(void)
1429 attr_test_string[0] = (char) default_attr_string();
1430 adjust_attr_string(0);
1434 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1436 int ncv = get_ncv();
1437 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1440 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1441 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1442 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1444 printw("%*s", skip, " ");
1446 * Just for testing, write text using the alternate character set one
1447 * character at a time (to pass its rendition directly), and use the
1448 * string operation for the other attributes.
1452 if (attr & A_ALTCHARSET) {
1456 for (s = attr_test_string; *s != '\0'; ++s) {
1458 (void) waddch(win, ch | attr);
1461 (void) wattrset(win, AttrArg(attr, 0));
1462 (void) waddstr(win, attr_test_string);
1463 (void) wattroff(win, (int) attr);
1466 printw("%*s", skip, " ");
1467 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1468 if (test != A_NORMAL) {
1469 if (!(termattrs() & test)) {
1472 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1473 static const chtype table[] =
1492 for (n = 0; n < SIZEOF(table); n++) {
1493 if ((table[n] & attr) != 0
1494 && ((1 << n) & ncv) != 0) {
1502 if ((termattrs() & test) != test) {
1512 NCURSES_CONST char *name;
1515 static const ATTR_TBL attrs_to_test[] = {
1516 { A_STANDOUT, "STANDOUT" },
1517 { A_REVERSE, "REVERSE" },
1519 { A_UNDERLINE, "UNDERLINE" },
1521 { A_BLINK, "BLINK" },
1522 { A_PROTECT, "PROTECT" },
1524 { A_INVIS, "INVISIBLE" },
1527 { A_ITALIC, "ITALIC" },
1529 { A_NORMAL, "NORMAL" },
1534 init_attr_list(ATTR_TBL * target, attr_t attrs)
1536 unsigned result = 0;
1539 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1540 attr_t test = attrs_to_test[n].attr;
1541 if (test == A_NORMAL || (test & attrs) != 0) {
1542 target[result++] = attrs_to_test[n];
1548 #if USE_WIDEC_SUPPORT
1551 NCURSES_CONST char *name;
1554 static const W_ATTR_TBL w_attrs_to_test[] = {
1555 { WA_STANDOUT, "STANDOUT" },
1556 { WA_REVERSE, "REVERSE" },
1557 { WA_BOLD, "BOLD" },
1558 { WA_UNDERLINE, "UNDERLINE" },
1560 { WA_BLINK, "BLINK" },
1561 { WA_PROTECT, "PROTECT" },
1563 { WA_INVIS, "INVISIBLE" },
1566 { WA_ITALIC, "ITALIC" },
1568 { WA_NORMAL, "NORMAL" },
1573 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1575 unsigned result = 0;
1578 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1579 attr_t test = w_attrs_to_test[n].attr;
1580 if (test == WA_NORMAL || (test & attrs) != 0) {
1581 target[result++] = w_attrs_to_test[n];
1589 attr_getc(int *skip,
1590 NCURSES_COLOR_T *fg,
1591 NCURSES_COLOR_T *bg,
1592 NCURSES_COLOR_T *tx,
1605 if (ch < 256 && isdigit(ch)) {
1613 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1615 attr_legend(helpwin);
1638 adjust_attr_string(-1);
1641 adjust_attr_string(1);
1647 error = cycle_color_attr(ch, fg, bg, tx);
1656 attr_test(bool recur GCC_UNUSED)
1657 /* test text attributes */
1660 int skip = get_xmc();
1661 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1662 NCURSES_COLOR_T bg = COLOR_BLACK;
1663 NCURSES_COLOR_T tx = -1;
1666 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1667 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1668 unsigned my_size = init_attr_list(my_list, termattrs());
1671 for (j = 0; j < my_size; ++j) {
1672 my_wins[j] = subwin(stdscr,
1674 2 + (int) (2 * j), COL_ATTRSTRING);
1675 scrollok(my_wins[j], FALSE);
1681 n = skip; /* make it easy */
1687 chtype normal = A_NORMAL | BLANK;
1688 chtype extras = (chtype) ac;
1691 NCURSES_PAIRS_T pair = 0;
1692 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1694 if (init_pair(pair, fg, bg) == ERR) {
1697 normal |= (chtype) COLOR_PAIR(pair);
1702 if (init_pair(pair, tx, bg) == ERR) {
1705 extras |= (chtype) COLOR_PAIR(pair);
1715 MvAddStr(0, 20, "Character attribute test display");
1717 for (j = 0; j < my_size; ++j) {
1718 bool arrow = (j == k);
1719 row = show_attr(my_wins[j], row, n, arrow,
1727 MvPrintw(row, COLS_PRE_ATTRS,
1728 "This terminal does %shave the magic-cookie glitch",
1729 get_xmc() > -1 ? "" : "not ");
1730 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1731 show_color_attr(fg, bg, tx);
1732 printw(" ACS (%d)", ac != 0);
1735 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1737 bkgdset(A_NORMAL | BLANK);
1742 Cannot("does not support video attributes.");
1747 #if USE_WIDEC_SUPPORT
1748 static bool use_fullwidth;
1749 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1751 #define FULL_LO 0xff00
1752 #define FULL_HI 0xff5e
1753 #define HALF_LO 0x20
1755 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1756 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1757 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1760 * Returns an ASCII code in [32..126]
1763 normal_wchar(int ch)
1765 wchar_t result = (wchar_t) ch;
1766 if (isFullWidth(ch))
1767 result = ToNormalWidth(ch);
1772 * Returns either an ASCII code in in [32..126] or full-width in
1773 * [0xff00..0xff5e], according to use_fullwidth setting.
1776 target_wchar(int ch)
1778 wchar_t result = (wchar_t) ch;
1779 if (use_fullwidth) {
1780 if (!isFullWidth(ch))
1781 result = ToFullWidth(ch);
1783 if (isFullWidth(ch))
1784 result = ToNormalWidth(ch);
1790 wide_adjust_attr_string(int adjust)
1792 wchar_t save = wide_attr_test_string[0];
1793 int first = ((int) normal_wchar(save)) + adjust;
1796 if (first >= ATTRSTRING_1ST) {
1797 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1798 if (k > ATTRSTRING_END)
1800 wide_attr_test_string[j] = target_wchar(k);
1801 if (((k + 1 - first) % 5) == 0) {
1802 if (++j >= MAX_ATTRSTRING)
1804 wide_attr_test_string[j] = ' ';
1807 if ((LEN_ATTRSTRING - j) > 5) {
1808 wide_attr_test_string[0] = save;
1809 wide_adjust_attr_string(adjust - 1);
1811 while (j < MAX_ATTRSTRING)
1812 wide_attr_test_string[j++] = ' ';
1813 wide_attr_test_string[j] = '\0';
1819 wide_init_attr_string(void)
1821 use_fullwidth = FALSE;
1822 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1823 wide_adjust_attr_string(0);
1827 set_wide_background(NCURSES_PAIRS_T pair)
1834 setcchar(&normal, blank, A_NORMAL, pair, 0);
1840 get_wide_background(void)
1842 attr_t result = WA_NORMAL;
1845 NCURSES_PAIRS_T pair;
1846 wchar_t wch[CCHARW_MAX];
1848 memset(&ch, 0, sizeof(ch));
1849 if (getbkgrnd(&ch) != ERR) {
1850 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1858 wide_show_attr(WINDOW *win,
1863 NCURSES_PAIRS_T pair,
1866 int ncv = get_ncv();
1867 attr_t test = attr & ~WA_ALTCHARSET;
1870 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1871 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1872 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1874 printw("%*s", skip, " ");
1877 * Just for testing, write text using the alternate character set one
1878 * character at a time (to pass its rendition directly), and use the
1879 * string operation for the other attributes.
1883 if (attr & WA_ALTCHARSET) {
1887 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1891 setcchar(&ch, fill, attr, pair, 0);
1892 (void) wadd_wch(win, &ch);
1895 attr_t old_attr = 0;
1896 NCURSES_PAIRS_T old_pair = 0;
1898 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1899 (void) wattr_set(win, attr, pair, 0);
1900 (void) waddwstr(win, wide_attr_test_string);
1901 (void) wattr_set(win, old_attr, old_pair, 0);
1904 printw("%*s", skip, " ");
1905 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1906 if (test != A_NORMAL) {
1907 if (!(term_attrs() & test)) {
1910 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1911 static const attr_t table[] =
1925 for (n = 0; n < SIZEOF(table); n++) {
1926 if ((table[n] & attr) != 0
1927 && ((1 << n) & ncv) != 0) {
1935 if ((term_attrs() & test) != test) {
1944 wide_attr_getc(int *skip,
1945 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1946 NCURSES_COLOR_T *tx, int *ac,
1947 unsigned *kc, unsigned limit)
1957 if (ch < 256 && isdigit(ch)) {
1965 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1966 box_set(helpwin, 0, 0);
1967 attr_legend(helpwin);
1990 use_fullwidth = FALSE;
1991 wide_adjust_attr_string(0);
1994 use_fullwidth = TRUE;
1995 wide_adjust_attr_string(0);
1998 wide_adjust_attr_string(-1);
2001 wide_adjust_attr_string(1);
2007 error = cycle_color_attr(ch, fg, bg, tx);
2016 x_attr_test(bool recur GCC_UNUSED)
2017 /* test text attributes using wide-character calls */
2020 int skip = get_xmc();
2021 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2022 NCURSES_COLOR_T bg = COLOR_BLACK;
2023 NCURSES_COLOR_T tx = -1;
2026 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2027 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2028 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2031 for (j = 0; j < my_size; ++j) {
2032 my_wins[j] = subwin(stdscr,
2034 2 + (int) (2 * j), COL_ATTRSTRING);
2035 scrollok(my_wins[j], FALSE);
2041 n = skip; /* make it easy */
2043 wide_init_attr_string();
2047 NCURSES_PAIRS_T pair = 0;
2048 NCURSES_PAIRS_T extras = 0;
2051 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2054 if (init_pair(pair, fg, bg) == ERR) {
2061 if (init_pair(extras, tx, bg) == ERR) {
2066 set_wide_background(pair);
2069 box_set(stdscr, 0, 0);
2070 MvAddStr(0, 20, "Character attribute test display");
2072 for (j = 0; j < my_size; ++j) {
2073 row = wide_show_attr(my_wins[j], row, n, (j == k),
2081 MvPrintw(row, COLS_PRE_ATTRS,
2082 "This terminal does %shave the magic-cookie glitch",
2083 get_xmc() > -1 ? "" : "not ");
2084 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2085 show_color_attr(fg, bg, tx);
2086 printw(" ACS (%d)", ac != 0);
2089 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2091 set_wide_background(0);
2096 Cannot("does not support extended video attributes.");
2102 /****************************************************************************
2104 * Color support tests
2106 ****************************************************************************/
2108 static NCURSES_CONST char *the_color_names[] =
2129 show_color_name(int y, int x, int color, bool wide, int zoom)
2131 if (move(y, x) != ERR) {
2138 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2142 if ((have = (int) strlen(temp)) >= width) {
2144 while ((1 << pwr2) < color)
2146 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2147 width > 4 ? "2^%d" : "^%d", pwr2);
2149 } else if (color >= 8) {
2150 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2152 } else if (color < 0) {
2153 _nc_STRCPY(temp, "default", sizeof(temp));
2155 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2156 "%.*s", 16, the_color_names[color]);
2158 printw("%-*.*s", width, width, temp);
2163 color_legend(WINDOW *helpwin, bool wide)
2168 MvWPrintw(helpwin, row++, col,
2171 MvWPrintw(helpwin, row++, col,
2172 "Use up/down arrow to scroll through the display if it is");
2173 MvWPrintw(helpwin, row++, col,
2174 "longer than one screen. Control/N and Control/P can be used");
2175 MvWPrintw(helpwin, row++, col,
2176 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2177 MvWPrintw(helpwin, row++, col,
2178 "full screen; control/B and control/F can be used here.");
2180 MvWPrintw(helpwin, row++, col,
2182 MvWPrintw(helpwin, row++, col,
2183 " a/A toggle altcharset off/on");
2184 MvWPrintw(helpwin, row++, col,
2185 " b/B toggle bold off/on");
2187 MvWPrintw(helpwin, row++, col,
2188 " c/C cycle used-colors through 8,16,...,COLORS");
2190 MvWPrintw(helpwin, row++, col,
2191 " n/N toggle text/number on/off");
2192 MvWPrintw(helpwin, row++, col,
2193 " r/R toggle reverse on/off");
2194 MvWPrintw(helpwin, row++, col,
2195 " w/W switch width between 4/8 columns");
2196 MvWPrintw(helpwin, row++, col,
2197 " z/Z zoom out (or in)");
2198 #if USE_WIDEC_SUPPORT
2200 MvWPrintw(helpwin, row++, col,
2201 "Wide characters:");
2202 MvWPrintw(helpwin, row, col,
2203 " x/X toggle text between ASCII and wide-character");
2210 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2213 color_cycle(int current, int step)
2215 int result = current;
2221 if ((result * 2) > COLORS) {
2224 while ((result * 2) < current) {
2230 if (current >= COLORS) {
2235 if (result > COLORS)
2241 /* generate a color test pattern */
2243 color_test(bool recur GCC_UNUSED)
2248 int grid_top = top + 3;
2249 int page_size = (LINES - grid_top);
2251 int colors_max = COLORS;
2258 bool opt_acsc = FALSE;
2259 bool opt_bold = FALSE;
2260 bool opt_revs = FALSE;
2261 bool opt_nums = FALSE;
2262 bool opt_wide = FALSE;
2267 Cannot("does not support color.");
2271 numbered = typeCalloc(char, COLS + 1);
2272 done = ((COLS < 16) || (numbered == 0));
2275 * Because the number of colors is usually a power of two, we also use
2276 * a power of two for the number of colors shown per line (to be tidy).
2278 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2283 int zoom_size = (1 << opt_zoom);
2284 int colors_max1 = colors_max / zoom_size;
2285 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2287 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2288 if (colors_max2 <= COLOR_PAIRS) {
2289 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2290 if (pairs_max > limit)
2293 if (pairs_max > COLOR_PAIRS)
2294 pairs_max = COLOR_PAIRS;
2295 if (pairs_max < colors_max1)
2296 pairs_max = colors_max1;
2298 /* this assumes an 80-column line */
2302 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2306 per_row = (col_limit / width);
2308 per_row -= MinColors;
2310 row_limit = (pairs_max + per_row - 1) / per_row;
2313 (void) printw("There are %d color pairs and %d colors",
2315 if (colors_max1 != COLORS)
2316 (void) printw(" (using %d colors)", colors_max1);
2318 (void) addstr(" besides 'default'");
2320 (void) printw(" zoom:%d", opt_zoom);
2323 MvPrintw(top + 1, 0,
2324 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2327 opt_bold ? "on" : "off");
2329 /* show color names/numbers across the top */
2330 for (i = 0; i < per_row; i++) {
2331 show_color_name(top + 2,
2333 (int) i * zoom_size + MinColors,
2338 /* show a grid of colors, with color names/ numbers on the left */
2339 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2340 int row = grid_top + (i / per_row) - base_row;
2341 int col = (i % per_row + 1) * width;
2342 NCURSES_PAIRS_T pair = i;
2344 if ((i / per_row) > row_limit)
2347 #define InxToFG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) % (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2348 #define InxToBG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) / (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2349 if (row >= 0 && move(row, col) != ERR) {
2350 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) InxToFG(i);
2351 NCURSES_COLOR_T bg = (NCURSES_COLOR_T) InxToBG(i);
2353 init_pair(pair, fg, bg);
2354 attron(COLOR_PAIR(pair));
2356 attron(A_ALTCHARSET);
2363 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2367 printw("%-*.*s", width, width, hello);
2368 (void) attrset(A_NORMAL);
2370 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2371 show_color_name(row, 0,
2382 switch (wGetchar(stdscr)) {
2396 colors_max = color_cycle(colors_max, -1);
2399 colors_max = color_cycle(colors_max, 1);
2417 set_color_test(opt_wide, FALSE);
2420 set_color_test(opt_wide, TRUE);
2423 if (opt_zoom <= 0) {
2431 if ((1 << opt_zoom) >= colors_max) {
2440 if (base_row <= 0) {
2448 if (base_row + page_size >= row_limit) {
2457 if (base_row <= 0) {
2460 base_row -= (page_size - 1);
2468 if (base_row + page_size >= row_limit) {
2471 base_row += page_size - 1;
2472 if (base_row + page_size >= row_limit) {
2473 base_row = row_limit - page_size - 1;
2478 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2480 color_legend(helpwin, FALSE);
2498 #if USE_WIDEC_SUPPORT
2500 #if USE_EXTENDED_COLOR
2501 #define InitExtendedPair(p,f,g) init_extended_pair((p),(f),(g))
2502 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), &(p))
2503 #define EXTENDED_PAIRS_T int
2505 #define InitExtendedPair(p,f,g) init_pair((NCURSES_PAIRS_T) (p),(NCURSES_COLOR_T)(f),(NCURSES_COLOR_T)(g))
2506 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), NULL)
2507 #define EXTENDED_PAIRS_T NCURSES_PAIRS_T
2510 /* generate a color test pattern */
2512 x_color_test(bool recur GCC_UNUSED)
2517 int grid_top = top + 3;
2518 int page_size = (LINES - grid_top);
2519 int pairs_max = (unsigned short) (-1);
2520 int colors_max = COLORS;
2527 bool opt_acsc = FALSE;
2528 bool opt_bold = FALSE;
2529 bool opt_revs = FALSE;
2530 bool opt_wide = FALSE;
2531 bool opt_nums = FALSE;
2532 bool opt_xchr = FALSE;
2534 wchar_t *buffer = 0;
2538 Cannot("does not support color.");
2541 numbered = typeCalloc(char, COLS + 1);
2542 buffer = typeCalloc(wchar_t, COLS + 1);
2543 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2546 * Because the number of colors is usually a power of two, we also use
2547 * a power of two for the number of colors shown per line (to be tidy).
2549 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2554 int zoom_size = (1 << opt_zoom);
2555 int colors_max1 = colors_max / zoom_size;
2556 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2558 pairs_max = ((unsigned) (-1)) / 2;
2559 if (colors_max2 <= COLOR_PAIRS) {
2560 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2561 if (pairs_max > limit)
2564 if (pairs_max > COLOR_PAIRS)
2565 pairs_max = COLOR_PAIRS;
2566 if (pairs_max < colors_max1)
2567 pairs_max = colors_max1;
2572 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2576 per_row = (col_limit / width);
2578 per_row -= MinColors;
2581 make_fullwidth_text(buffer, hello);
2585 make_narrow_text(buffer, hello);
2588 row_limit = (pairs_max + per_row - 1) / per_row;
2591 (void) printw("There are %d color pairs and %d colors",
2593 if (colors_max1 != COLORS)
2594 (void) printw(" (using %d colors)", colors_max1);
2596 (void) addstr(" besides 'default'");
2598 (void) printw(" zoom:%d", opt_zoom);
2601 MvPrintw(top + 1, 0,
2602 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2605 opt_bold ? "on" : "off");
2607 /* show color names/numbers across the top */
2608 for (i = 0; i < per_row; i++) {
2609 show_color_name(top + 2,
2610 ((int) i + 1) * width,
2611 (int) i * zoom_size + MinColors,
2616 /* show a grid of colors, with color names/ numbers on the left */
2617 for (i = (base_row * per_row); i < pairs_max; i++) {
2618 int row = grid_top + ((int) i / per_row) - base_row;
2619 int col = ((int) i % per_row + 1) * width;
2622 if ((i / per_row) > row_limit)
2625 if (row >= 0 && move(row, col) != ERR) {
2626 InitExtendedPair(pair, InxToFG(i), InxToBG(i));
2627 (void) ExtendedColorSet(pair);
2629 attr_on(WA_ALTCHARSET, NULL);
2631 attr_on(WA_BOLD, NULL);
2633 attr_on(WA_REVERSE, NULL);
2636 _nc_SPRINTF(numbered,
2637 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2638 "{%02X}", (unsigned) i);
2640 make_fullwidth_text(buffer, numbered);
2642 make_narrow_text(buffer, numbered);
2645 addnwstr(buffer, width);
2646 (void) attr_set(A_NORMAL, 0, NULL);
2648 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2649 show_color_name(row, 0,
2660 switch (wGetchar(stdscr)) {
2674 colors_max = color_cycle(colors_max, -1);
2677 colors_max = color_cycle(colors_max, 1);
2695 set_color_test(opt_wide, FALSE);
2698 set_color_test(opt_wide, TRUE);
2707 if (opt_zoom <= 0) {
2715 if ((1 << opt_zoom) >= colors_max) {
2724 if (base_row <= 0) {
2732 if (base_row + page_size >= row_limit) {
2741 if (base_row <= 0) {
2744 base_row -= (page_size - 1);
2752 if (base_row + page_size >= row_limit) {
2755 base_row += page_size - 1;
2756 if (base_row + page_size >= row_limit) {
2757 base_row = row_limit - page_size - 1;
2762 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2764 color_legend(helpwin, TRUE);
2782 #endif /* USE_WIDEC_SUPPORT */
2784 #if HAVE_COLOR_CONTENT
2786 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2788 NCURSES_COLOR_T red, green, blue;
2790 color_content(current, &red, &green, &blue);
2794 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2797 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2800 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2804 if (init_color(current, red, green, blue) == ERR)
2809 reset_all_colors(void)
2813 for (c = 0; c < COLORS; ++c)
2816 all_colors[c].green,
2817 all_colors[c].blue);
2820 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2821 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2822 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2825 init_all_colors(bool xterm_colors, char *palette_file)
2828 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2830 failed("all_colors");
2831 for (cp = 0; cp < MaxColors; ++cp) {
2833 &all_colors[cp].red,
2834 &all_colors[cp].green,
2835 &all_colors[cp].blue);
2837 /* xterm and compatible terminals can read results of an OSC string
2838 * asking for the current color palette.
2843 char result[BUFSIZ];
2845 unsigned check_r, check_g, check_b;
2849 for (n = 0; n < MaxColors; ++n) {
2850 fprintf(stderr, "\033]4;%d;?\007", n);
2851 got = (int) read(0, result, sizeof(result) - 1);
2855 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2861 all_colors[n].red = DecodeRGB(check_r);
2862 all_colors[n].green = DecodeRGB(check_g);
2863 all_colors[n].blue = DecodeRGB(check_b);
2870 if (palette_file != 0) {
2871 FILE *fp = fopen(palette_file, "r");
2873 char buffer[BUFSIZ];
2874 int red, green, blue;
2877 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2878 if (sscanf(buffer, "scale:%d", &c) == 1) {
2880 } else if (sscanf(buffer, "%d:%d %d %d",
2889 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2890 all_colors[c].red = Scaled(red);
2891 all_colors[c].green = Scaled(green);
2892 all_colors[c].blue = Scaled(blue);
2900 #define scaled_rgb(n) ((255 * (n)) / 1000)
2903 color_edit(bool recur GCC_UNUSED)
2904 /* display the color test pattern, without trying to edit colors */
2908 int this_c, value, field;
2914 Cannot("does not support color.");
2916 } else if (!can_change_color()) {
2917 Cannot("has hardwired color values.");
2930 page_size = (LINES - 6);
2933 for (i = 0; i < MaxColors; i++)
2934 init_pair((NCURSES_PAIRS_T) i,
2935 (NCURSES_COLOR_T) COLOR_WHITE,
2936 (NCURSES_COLOR_T) i);
2938 MvPrintw(LINES - 2, 0, "Number: %d", value);
2941 NCURSES_COLOR_T red, green, blue;
2944 MvAddStr(0, 20, "Color RGB Value Editing");
2947 for (i = (NCURSES_COLOR_T) top_color;
2948 (i - top_color < page_size)
2949 && (i < MaxColors); i++) {
2952 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2953 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2954 (i == current ? '>' : ' '),
2955 (i < (int) SIZEOF(the_color_names)
2956 ? the_color_names[i] : numeric));
2957 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2959 (void) attrset(A_NORMAL);
2961 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2963 if (current == i && field == 0)
2965 printw("%04d", (int) red);
2966 if (current == i && field == 0)
2967 (void) attrset(A_NORMAL);
2969 if (current == i && field == 1)
2971 printw("%04d", (int) green);
2972 if (current == i && field == 1)
2973 (void) attrset(A_NORMAL);
2975 if (current == i && field == 2)
2977 printw("%04d", (int) blue);
2978 if (current == i && field == 2)
2979 (void) attrset(A_NORMAL);
2980 (void) attrset(A_NORMAL);
2981 printw(" ( %3d %3d %3d )",
2982 (int) scaled_rgb(red),
2983 (int) scaled_rgb(green),
2984 (int) scaled_rgb(blue));
2987 MvAddStr(LINES - 3, 0,
2988 "Use up/down to select a color, left/right to change fields.");
2989 MvAddStr(LINES - 2, 0,
2990 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2992 move(2 + current - top_color, 0);
2996 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
3018 current -= (page_size - 1);
3025 if (current < (MaxColors - 1))
3026 current += (page_size - 1);
3033 current = (current == 0 ? (MaxColors - 1) : current - 1);
3038 current = (current == (MaxColors - 1) ? 0 : current + 1);
3043 field = (field == 2 ? 0 : field + 1);
3048 field = (field == 0 ? 2 : field - 1);
3061 value = value * 10 + (this_c - '0');
3065 change_color((NCURSES_PAIRS_T) current, field, value, 1);
3069 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
3073 change_color((NCURSES_PAIRS_T) current, field, value, 0);
3078 P(" RGB Value Editing Help");
3080 P("You are in the RGB value editor. Use the arrow keys to select one of");
3081 P("the fields in one of the RGB triples of the current colors; the one");
3082 P("currently selected will be reverse-video highlighted.");
3084 P("To change a field, enter the digits of the new value; they are echoed");
3085 P("as entered. Finish by typing `='. The change will take effect instantly.");
3086 P("To increment or decrement a value, use the same procedure, but finish");
3087 P("with a `+' or `-'.");
3089 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3091 P("Press 'm' to invoke the top-level menu with the current color settings.");
3092 P("To quit, do ESC");
3101 for (i = 0; i < MaxColors; i++)
3102 init_pair((NCURSES_PAIRS_T) i,
3103 (NCURSES_COLOR_T) COLOR_WHITE,
3104 (NCURSES_COLOR_T) i);
3118 if (current >= MaxColors)
3119 current = MaxColors - 1;
3120 if (current < top_color)
3121 top_color = current;
3122 if (current - top_color >= page_size)
3123 top_color = current - (page_size - 1);
3125 MvPrintw(LINES - 1, 0, "Number: %d", value);
3128 (!isQuit(this_c, TRUE));
3133 * ncurses does not reset each color individually when calling endwin().
3140 #endif /* HAVE_COLOR_CONTENT */
3142 /****************************************************************************
3144 * Alternate character-set stuff
3146 ****************************************************************************/
3148 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3154 if ((*at_code += 1) >= limit)
3159 *at_code = limit - 1;
3168 *attr = list[*at_code].attr;
3172 #if USE_WIDEC_SUPPORT
3174 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3180 if ((*at_code += 1) >= limit)
3185 *at_code = limit - 1;
3194 *attr = list[*at_code].attr;
3200 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3202 bool result = FALSE;
3212 if ((*fg += 1) >= COLORS)
3220 if ((*bg += 1) >= COLORS)
3228 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3231 if (init_pair(*pair,
3232 (NCURSES_COLOR_T) *fg,
3233 (NCURSES_COLOR_T) *bg) == ERR) {
3242 /****************************************************************************
3244 * Soft-key label test
3246 ****************************************************************************/
3251 #define SLK_WORK (SLK_HELP + 3)
3256 static const char *table[] =
3258 "Available commands are:"
3260 ,"^L -- repaint this message and activate soft keys"
3261 ,"a/d -- activate/disable soft keys"
3262 ,"c -- set centered format for labels"
3263 ,"l -- set left-justified format for labels"
3264 ,"r -- set right-justified format for labels"
3265 ,"[12345678] -- set label; labels are numbered 1 through 8"
3266 ,"e -- erase stdscr (should not erase labels)"
3267 ,"s -- test scrolling of shortened screen"
3268 ,"v/V -- cycle through video attributes"
3270 ,"F/f/B/b -- cycle through foreground/background colors"
3272 ,"ESC -- return to main menu"
3274 ,"Note: if activating the soft keys causes your terminal to scroll up"
3275 ,"one line, your terminal auto-scrolls when anything is written to the"
3276 ,"last screen position. The ncurses code does not yet handle this"
3282 for (j = 0; j < SIZEOF(table); ++j) {
3290 call_slk_color(int fg, int bg)
3292 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3294 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3303 slk_test(bool recur GCC_UNUSED)
3304 /* exercise the soft keys */
3309 chtype attr = A_NORMAL;
3310 unsigned at_code = 0;
3312 int fg = COLOR_BLACK;
3313 int bg = COLOR_WHITE;
3314 NCURSES_PAIRS_T pair = 0;
3316 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3317 unsigned my_size = init_attr_list(my_list, termattrs());
3322 call_slk_color(fg, bg);
3332 MvAddStr(0, 20, "Soft Key Exerciser");
3347 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3348 while ((c = Getchar()) != 'Q' && (c != ERR))
3376 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3377 _nc_STRCPY(buf, "", sizeof(buf));
3378 if ((s = slk_label(c - '0')) != 0) {
3379 _nc_STRNCPY(buf, s, (size_t) 8);
3381 wGetstring(stdscr, buf, 8);
3382 slk_set((c - '0'), buf, fmt);
3391 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3393 wnoutrefresh(stdscr);
3398 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3405 if (cycle_colors(c, &fg, &bg, &pair)) {
3407 call_slk_color(fg, bg);
3417 } while (!isQuit(c = Getchar(), TRUE));
3426 #if USE_WIDEC_SUPPORT
3429 x_slk_test(bool recur GCC_UNUSED)
3430 /* exercise the soft keys */
3433 wchar_t buf[SLKLEN + 1];
3435 attr_t attr = WA_NORMAL;
3436 unsigned at_code = 0;
3437 int fg = COLOR_BLACK;
3438 int bg = COLOR_WHITE;
3439 NCURSES_PAIRS_T pair = 0;
3440 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3441 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3445 call_slk_color(fg, bg);
3452 attr_on(WA_BOLD, NULL);
3453 MvAddStr(0, 20, "Soft Key Exerciser");
3454 attr_off(WA_BOLD, NULL);
3468 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3469 while ((c = Getchar()) != 'Q' && (c != ERR))
3497 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3499 if ((s = slk_label(c - '0')) != 0) {
3500 char *temp = strdup(s);
3501 size_t used = strlen(temp);
3502 size_t want = SLKLEN;
3504 #ifndef state_unused
3509 while (want > 0 && used != 0) {
3510 const char *base = s;
3511 reset_mbytes(state);
3512 test = count_mbytes(base, 0, &state);
3513 if (test == (size_t) -1) {
3515 } else if (test > want) {
3518 reset_mbytes(state);
3519 trans_mbytes(buf, base, want, &state);
3525 wGet_wstring(stdscr, buf, SLKLEN);
3526 slk_wset((c - '0'), buf, fmt);
3537 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3538 call_slk_color(fg, bg);
3543 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3544 call_slk_color(fg, bg);
3547 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3549 wnoutrefresh(stdscr);
3553 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3554 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3560 if (cycle_colors(c, &fg, &bg, &pair)) {
3562 call_slk_color(fg, bg);
3572 } while (!isQuit(c = Getchar(), TRUE));
3581 #endif /* SLK_INIT */
3584 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3587 unsigned last = 255;
3593 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3598 for (code = first; code <= last; ++code) {
3599 int row = (int) (2 + (code / 16));
3600 int col = (int) (5 * (code % 16));
3601 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3602 for (count = 1; count < repeat; ++count) {
3603 AddCh(colored_chtype(code, attr, pair));
3610 * Show a slice of 32 characters, allowing those to be repeated up to the
3613 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3614 * terminal to perform functions. The remaining codes can be graphic.
3617 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3620 unsigned first = (unsigned) base;
3621 unsigned last = first + (unsigned) pagesize - 2;
3622 bool C1 = (first == 128);
3627 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3628 C1 ? "C1" : "GR", first, last);
3632 for (code = first; code <= last; code++) {
3634 int row = 2 + ((int) (code - first) % (pagesize / 2));
3635 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3637 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3638 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3642 nodelay(stdscr, TRUE);
3643 echochar(colored_chtype(code, attr, pair));
3645 /* (yes, this _is_ crude) */
3646 while ((reply = Getchar()) != ERR) {
3647 AddCh(UChar(reply));
3650 nodelay(stdscr, FALSE);
3652 } while (--count > 0);
3659 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3665 MvPrintw(0, 20, "Display of PC Character Codes");
3669 for (code = 0; code < 16; ++code) {
3670 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3672 for (code = 0; code < 256; code++) {
3674 int row = 3 + (int) (code / 16) + (code >= 128);
3675 int col = 8 + (int) (code % 16) * PC_COLS;
3676 if ((code % 16) == 0)
3677 MvPrintw(row, 0, "0x%02x:", code);
3688 * Skip the ones that do not work.
3692 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3695 } while (--count > 0);
3700 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3704 attr |= (attr_t) COLOR_PAIR(pair);
3708 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3713 colored_chtype(ACS_VLINE, attr, pair),
3714 colored_chtype(ACS_VLINE, attr, pair),
3715 colored_chtype(ACS_HLINE, attr, pair),
3716 colored_chtype(ACS_HLINE, attr, pair),
3717 colored_chtype(ACS_ULCORNER, attr, pair),
3718 colored_chtype(ACS_URCORNER, attr, pair),
3719 colored_chtype(ACS_LLCORNER, attr, pair),
3720 colored_chtype(ACS_LRCORNER, attr, pair));
3721 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3722 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3723 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3724 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3725 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3726 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3727 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3733 show_1_acs(int n, int repeat, const char *name, chtype code)
3735 const int height = 16;
3736 int row = 2 + (n % height);
3737 int col = (n / height) * COLS / 2;
3739 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3742 } while (--repeat > 0);
3747 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3748 /* display the ACS character set */
3752 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3756 MvAddStr(0, 20, "Display of the ACS Character Set");
3760 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3761 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3762 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3763 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3765 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3766 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3767 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3768 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3770 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3771 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3774 * HPUX's ACS definitions are broken here. Just give up.
3776 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3777 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3778 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3779 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3780 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3782 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3783 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3784 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3785 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3786 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3787 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3788 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3789 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3790 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3792 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3793 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3794 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3796 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3797 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3798 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3799 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3800 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3801 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3807 acs_test(bool recur GCC_UNUSED)
3811 char *term = getenv("TERM");
3812 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3815 chtype attr = A_NORMAL;
3818 int fg = COLOR_BLACK;
3819 int bg = COLOR_BLACK;
3820 unsigned at_code = 0;
3821 NCURSES_PAIRS_T pair = 0;
3822 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3823 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3824 unsigned my_size = init_attr_list(my_list, termattrs());
3832 ToggleAcs(last_show_acs, show_acs_chars);
3836 ToggleAcs(last_show_acs, show_pc_chars);
3841 if (pagesize == 32) {
3848 ToggleAcs(last_show_acs, show_box_chars);
3874 if (repeat < (COLS / 4))
3882 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3883 || cycle_colors(c, &fg, &bg, &pair)) {
3890 if (pagesize != 32) {
3891 show_256_chars(repeat, attr, pair);
3892 } else if (last_show_acs != 0) {
3893 last_show_acs(repeat, attr, pair);
3895 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3898 MvPrintw(LINES - 3, 0,
3899 "Note: ANSI terminals may not display C1 characters.");
3900 MvPrintw(LINES - 2, 0,
3901 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3904 MvPrintw(LINES - 1, 0,
3905 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3906 my_list[at_code].name,
3909 MvPrintw(LINES - 1, 0,
3910 "v/V cycles through video attributes (%s).",
3911 my_list[at_code].name);
3914 } while (!isQuit(c = Getchar(), TRUE));
3922 #if USE_WIDEC_SUPPORT
3924 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3930 TEST_CCHAR(src, count, {
3931 attr |= (test_attrs & A_ALTCHARSET);
3932 setcchar(dst, test_wch, attr, pair, NULL);
3942 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3943 * display. If there are no repeats, we could normally display 16 lines of 64
3944 * characters (1024 total). However, taking repeats and double-width cells
3945 * into account, use 256 characters for the page.
3948 show_paged_widechars(unsigned base,
3953 NCURSES_PAIRS_T pair)
3955 unsigned first = base * pagesize;
3956 unsigned last = first + pagesize - 1;
3964 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3967 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
3968 int row = (2 + (int) (code - (wchar_t) first) / per_line);
3969 int col = 5 * ((int) code % per_line);
3972 memset(&codes, 0, sizeof(codes));
3974 setcchar(&temp, codes, attr, pair, 0);
3976 if (wcwidth(code) == 0 && code != 0) {
3977 AddCh((chtype) space |
3978 (A_REVERSE ^ attr) |
3979 (attr_t) COLOR_PAIR(pair));
3982 for (count = 1; count < repeat; ++count) {
3989 show_upper_widechars(unsigned first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3993 unsigned last = first + 31;
3997 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
4000 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
4001 int row = 2 + ((int) (code - (wchar_t) first) % 16);
4002 int col = ((int) (code - (wchar_t) first) / 16) * COLS / 2;
4008 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
4009 "%3ld (0x%lx)", (long) code, (long) code);
4010 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
4012 memset(&codes, 0, sizeof(codes));
4014 setcchar(&temp, codes, attr, pair, 0);
4018 * Give non-spacing characters something to combine with. If we
4019 * don't, they'll bunch up in a heap on the space after the ":".
4020 * Mark them with reverse-video to make them simpler to find on
4023 if (wcwidth(code) == 0) {
4024 AddCh((chtype) space |
4025 (A_REVERSE ^ attr) |
4026 (attr_t) COLOR_PAIR(pair));
4029 * This uses echo_wchar(), for comparison with the normal 'f'
4030 * test (and to make a test-case for echo_wchar()). The screen
4031 * may flicker because the erase() at the top of the function
4032 * is met by the builtin refresh() in echo_wchar().
4036 * The repeat-count may make text wrap - avoid that.
4038 getyx(stdscr, y, x);
4040 if (x >= col + (COLS / 2) - 2)
4042 } while (--count > 0);
4047 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
4049 const int height = 16;
4050 int row = 2 + (n % height);
4051 int col = (n / height) * COLS / 2;
4053 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4054 while (--repeat >= 0) {
4060 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
4063 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4064 /* display the wide-ACS character set */
4070 /*#define BOTH2(name) #name, &(name) */
4071 #define BOTH2(name) #name, MERGE_ATTR(name)
4075 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4079 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
4080 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
4081 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
4082 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
4084 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
4085 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
4086 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
4087 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
4089 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4090 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4092 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4093 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4094 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4095 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4097 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4098 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4099 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4100 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4101 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4102 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4103 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4104 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4105 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4107 #ifdef CURSES_WACS_ARRAY
4108 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4109 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4110 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4114 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4115 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4117 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4123 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4124 /* display the wide-ACS character set */
4130 /*#define BOTH2(name) #name, &(name) */
4131 #define BOTH2(name) #name, MERGE_ATTR(name)
4135 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4139 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4140 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4141 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4142 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4144 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4145 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4146 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4147 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4149 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4150 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4152 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4153 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4154 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4155 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4157 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4158 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4159 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4160 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4161 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4162 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4163 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4164 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4165 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4167 #ifdef CURSES_WACS_ARRAY
4168 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4169 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4170 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4172 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4173 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4174 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4175 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4176 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4177 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4184 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4185 /* display the wide-ACS character set */
4191 /*#define BOTH2(name) #name, &(name) */
4192 #define BOTH2(name) #name, MERGE_ATTR(name)
4196 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4200 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4201 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4202 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4203 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4205 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4206 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4207 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4208 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4210 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4211 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4213 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4214 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4215 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4216 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4218 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4219 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4220 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4221 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4222 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4223 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4224 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4225 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4226 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4228 #ifdef CURSES_WACS_ARRAY
4229 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4230 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4231 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4233 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4234 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4235 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4236 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4237 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4238 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4245 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4248 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4255 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4260 MERGE_ATTR(0, WACS_VLINE),
4261 MERGE_ATTR(1, WACS_VLINE),
4262 MERGE_ATTR(2, WACS_HLINE),
4263 MERGE_ATTR(3, WACS_HLINE),
4264 MERGE_ATTR(4, WACS_ULCORNER),
4265 MERGE_ATTR(5, WACS_URCORNER),
4266 MERGE_ATTR(6, WACS_LLCORNER),
4267 MERGE_ATTR(7, WACS_LRCORNER));
4269 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4270 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4271 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4272 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4273 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4274 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4275 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4283 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4285 const int height = 16;
4286 int row = 2 + (n % height);
4287 int col = (n / height) * COLS / 2;
4290 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4291 (void) attr_set(attr, pair, 0);
4292 _nc_STRNCPY(temp, code, 20);
4294 (void) attr_set(A_NORMAL, 0, 0);
4298 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4301 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4308 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4312 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4313 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4314 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4315 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4317 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4318 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4319 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4320 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4322 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4323 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4325 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4326 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4327 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4328 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4330 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4331 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4332 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4333 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4334 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4335 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4336 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4337 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4338 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4339 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4340 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4341 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4343 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4344 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4345 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4346 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4347 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4348 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4353 /* display the wide-ACS character set */
4355 x_acs_test(bool recur GCC_UNUSED)
4361 unsigned pagesize = 32;
4362 attr_t attr = WA_NORMAL;
4363 int fg = COLOR_BLACK;
4364 int bg = COLOR_BLACK;
4365 unsigned at_code = 0;
4366 NCURSES_PAIRS_T pair = 0;
4367 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4368 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4369 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4371 bool pending_code = FALSE;
4380 ToggleAcs(last_show_wacs, show_wacs_chars);
4384 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4389 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4393 if (pagesize == 32) {
4400 ToggleAcs(last_show_wacs, show_wbox_chars);
4403 ToggleAcs(last_show_wacs, show_utf8_chars);
4406 pending_code = !pending_code;
4408 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4409 } else if (at_page[0] != '\0') {
4410 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%x", digit);
4414 if (pending_code && isxdigit(c)) {
4415 size_t len = strlen(at_page);
4416 if (len && at_page[0] == '0') {
4417 memmove(at_page, at_page + 1, len--);
4419 if (len < sizeof(at_page) - 1) {
4420 at_page[len++] = (char) c;
4421 at_page[len] = '\0';
4423 } else if (pending_code
4424 && (c == '\b' || c == KEY_BACKSPACE || c == KEY_DC)) {
4425 size_t len = strlen(at_page);
4427 at_page[--len] = '\0';
4428 } else if (c < 256 && isdigit(c)) {
4429 digit = (unsigned) (c - '0');
4431 } else if (c == '+') {
4433 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4435 } else if (c == '-' && digit > 0) {
4437 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x",
4440 } else if (c == '>' && repeat < (COLS / 4)) {
4442 } else if (c == '<' && repeat > 1) {
4444 } else if (c == '_') {
4445 space = (space == ' ') ? '_' : ' ';
4447 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4448 || cycle_colors(c, &fg, &bg, &pair)) {
4449 if (last_show_wacs != 0)
4457 if (pagesize != 32) {
4458 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4459 } else if (last_show_wacs != 0) {
4460 last_show_wacs(repeat, attr, pair);
4462 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4465 MvPrintw(LINES - 4, 0,
4466 "Select: a/d/t WACS, w=%d/page, @",
4469 pending_code ? at_page : "page");
4470 addstr(", x=box, u UTF-8, ^L repaint");
4471 MvPrintw(LINES - 3, 2,
4472 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4474 MvPrintw(LINES - 2, 2,
4475 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4476 my_list[at_code].name,
4479 MvPrintw(LINES - 2, 2,
4480 "v/V cycles through video attributes (%s).",
4481 my_list[at_code].name);
4484 } while (!isQuit(c = Getchar(), TRUE));
4495 * Graphic-rendition test (adapted from vttest)
4498 sgr_attr_test(bool recur GCC_UNUSED)
4502 for (pass = 0; pass < 2; pass++) {
4503 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4505 /* Use non-default colors if possible to exercise bce a little */
4507 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4508 normal |= (chtype) COLOR_PAIR(1);
4512 MvPrintw(1, 20, "Graphic rendition test pattern:");
4514 MvPrintw(4, 1, "vanilla");
4516 #define set_sgr(mask) bkgdset((normal^(mask)));
4518 MvPrintw(4, 40, "bold");
4520 set_sgr(A_UNDERLINE);
4521 MvPrintw(6, 6, "underline");
4523 set_sgr(A_BOLD | A_UNDERLINE);
4524 MvPrintw(6, 45, "bold underline");
4527 MvPrintw(8, 1, "blink");
4529 set_sgr(A_BLINK | A_BOLD);
4530 MvPrintw(8, 40, "bold blink");
4532 set_sgr(A_UNDERLINE | A_BLINK);
4533 MvPrintw(10, 6, "underline blink");
4535 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4536 MvPrintw(10, 45, "bold underline blink");
4539 MvPrintw(12, 1, "negative");
4541 set_sgr(A_BOLD | A_REVERSE);
4542 MvPrintw(12, 40, "bold negative");
4544 set_sgr(A_UNDERLINE | A_REVERSE);
4545 MvPrintw(14, 6, "underline negative");
4547 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4548 MvPrintw(14, 45, "bold underline negative");
4550 set_sgr(A_BLINK | A_REVERSE);
4551 MvPrintw(16, 1, "blink negative");
4553 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4554 MvPrintw(16, 40, "bold blink negative");
4556 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4557 MvPrintw(18, 6, "underline blink negative");
4559 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4560 MvPrintw(18, 45, "bold underline blink negative");
4563 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4569 bkgdset(A_NORMAL | BLANK);
4575 /****************************************************************************
4577 * Windows and scrolling tester.
4579 ****************************************************************************/
4581 #define BOTLINES 4 /* number of line stolen from screen bottom */
4587 #define FRAME struct frame
4596 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4597 #if (NCURSES_VERSION_PATCH < 20070331)
4598 #define is_keypad(win) (win)->_use_keypad
4599 #define is_scrollok(win) (win)->_scroll
4602 #define is_keypad(win) FALSE
4603 #define is_scrollok(win) FALSE
4607 frame_win(FRAME * curp)
4609 return (curp != 0) ? curp->wind : stdscr;
4612 /* We need to know if these flags are actually set, so don't look in FRAME.
4613 * These names are known to work with SVr4 curses as well as ncurses. The
4614 * _use_keypad name does not work with Solaris 8.
4617 HaveKeypad(FRAME * curp)
4619 WINDOW *win = frame_win(curp);
4621 return is_keypad(win);
4625 HaveScroll(FRAME * curp)
4627 WINDOW *win = frame_win(curp);
4629 return is_scrollok(win);
4633 newwin_legend(FRAME * curp)
4635 #define DATA(num, name) { name, num }
4636 static const struct {
4640 DATA(0, "^C = create window"),
4641 DATA(0, "^N = next window"),
4642 DATA(0, "^P = previous window"),
4643 DATA(0, "^F = scroll forward"),
4644 DATA(0, "^B = scroll backward"),
4645 DATA(1, "^K = keypad(%s)"),
4646 DATA(2, "^S = scrollok(%s)"),
4647 DATA(0, "^W = save window"),
4648 DATA(0, "^R = restore window"),
4650 DATA(0, "^X = resize"),
4652 DATA(3, "^Q%s = exit")
4657 bool do_keypad = HaveKeypad(curp);
4658 bool do_scroll = HaveScroll(curp);
4662 for (n = 0; n < SIZEOF(legend); n++) {
4663 switch (legend[n].code) {
4665 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4668 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4669 legend[n].msg, do_keypad ? "yes" : "no");
4672 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4673 legend[n].msg, do_scroll ? "yes" : "no");
4676 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4677 legend[n].msg, do_keypad ? "/ESC" : "");
4680 x = getcurx(stdscr);
4681 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4688 transient(FRAME * curp, NCURSES_CONST char *msg)
4690 newwin_legend(curp);
4692 MvAddStr(LINES - 1, 0, msg);
4698 printw("%s characters are echoed, window should %sscroll.",
4699 HaveKeypad(curp) ? "Non-arrow" : "All other",
4700 HaveScroll(curp) ? "" : "not ");
4705 newwin_report(FRAME * curp)
4706 /* report on the cursor's current position, then restore it */
4708 WINDOW *win = frame_win(curp);
4712 transient(curp, (char *) 0);
4714 move(LINES - 1, COLS - 17);
4715 printw("Y = %2d X = %2d", y, x);
4723 selectcell(int uli, int ulj, int lri, int lrj)
4724 /* arrows keys move cursor, return location at current on non-arrow key */
4726 static pair res; /* result cell */
4727 int si = lri - uli + 1; /* depth of the select area */
4728 int sj = lrj - ulj + 1; /* width of the select area */
4729 int i = 0, j = 0; /* offsets into the select area */
4734 move(uli + i, ulj + j);
4735 newwin_report((FRAME *) 0);
4737 switch (Getchar()) {
4751 return ((pair *) 0);
4752 #ifdef NCURSES_MOUSE_VERSION
4758 if (event.y > uli && event.x > ulj) {
4779 outerbox(pair ul, pair lr, bool onoff)
4780 /* draw or erase a box *outside* the given pair of corners */
4782 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4783 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4784 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4785 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4786 move(ul.y - 1, ul.x);
4787 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4788 move(ul.y, ul.x - 1);
4789 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4790 move(lr.y + 1, ul.x);
4791 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4792 move(ul.y, lr.x + 1);
4793 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4798 /* Ask user for a window definition */
4805 addstr("Use arrows to move cursor, anything else to mark corner 1");
4807 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4808 return ((WINDOW *) 0);
4809 memcpy(&ul, tmp, sizeof(pair));
4810 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4813 addstr("Use arrows to move cursor, anything else to mark corner 2");
4815 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4817 return ((WINDOW *) 0);
4818 memcpy(&lr, tmp, sizeof(pair));
4820 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4822 outerbox(ul, lr, TRUE);
4834 newwin_move(FRAME * curp, int dy, int dx)
4836 WINDOW *win = frame_win(curp);
4840 getyx(win, cur_y, cur_x);
4841 getmaxyx(win, max_y, max_x);
4842 if ((cur_x += dx) < 0)
4844 else if (cur_x >= max_x)
4846 if ((cur_y += dy) < 0)
4848 else if (cur_y >= max_y)
4850 wmove(win, cur_y, cur_x);
4854 delete_framed(FRAME * fp, bool showit)
4859 fp->last->next = fp->next;
4860 fp->next->last = fp->last;
4868 np = (fp == fp->next) ? NULL : fp->next;
4875 scroll_test(bool recur GCC_UNUSED)
4876 /* Demonstrate windows */
4879 FRAME *current = (FRAME *) 0, *neww;
4881 #if HAVE_PUTWIN && HAVE_GETWIN
4885 #define DUMPFILE "screendump"
4887 #ifdef NCURSES_MOUSE_VERSION
4888 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4893 transient((FRAME *) 0, (char *) 0);
4896 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4897 failed("scroll_test");
4900 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4901 failed("scroll_test");
4906 if (current == 0) { /* First element, */
4907 neww->next = neww; /* so point it at itself */
4910 neww->next = current->next;
4911 neww->last = current;
4912 neww->last->next = neww;
4913 neww->next->last = neww;
4916 /* SVr4 curses sets the keypad on all newly-created windows to
4917 * false. Someone reported that PDCurses makes new windows inherit
4918 * this flag. Remove the following 'keypad()' call to test this
4920 keypad(current->wind, TRUE);
4921 current->do_keypad = HaveKeypad(current);
4922 current->do_scroll = HaveScroll(current);
4925 case CTRL('N'): /* go to next window */
4927 current = current->next;
4930 case CTRL('P'): /* go to previous window */
4932 current = current->last;
4935 case CTRL('F'): /* scroll current window forward */
4937 wscrl(frame_win(current), 1);
4940 case CTRL('B'): /* scroll current window backwards */
4942 wscrl(frame_win(current), -1);
4945 case CTRL('K'): /* toggle keypad mode for current */
4947 current->do_keypad = !current->do_keypad;
4948 keypad(current->wind, current->do_keypad);
4954 current->do_scroll = !current->do_scroll;
4955 scrollok(current->wind, current->do_scroll);
4959 #if HAVE_PUTWIN && HAVE_GETWIN
4960 case CTRL('W'): /* save and delete window */
4961 if ((current != 0) && (current == current->next)) {
4962 transient(current, "Will not save/delete ONLY window");
4964 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4965 transient(current, "Can't open screen dump file");
4967 int rc = putwin(frame_win(current), fp);
4971 current = delete_framed(current, TRUE);
4973 transient(current, "Can't write screen dump file");
4978 case CTRL('R'): /* restore window */
4979 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4980 transient(current, "Can't open screen dump file");
4982 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4984 neww->next = current ? current->next : 0;
4985 neww->last = current;
4986 if (neww->last != 0)
4987 neww->last->next = neww;
4988 if (neww->next != 0)
4989 neww->next->last = neww;
4991 neww->wind = getwin(fp);
4993 wrefresh(neww->wind);
4995 failed("scroll_test");
5003 case CTRL('X'): /* resize window */
5010 addstr("Use arrows to move cursor, anything else to mark new corner");
5013 getbegyx(current->wind, ul.y, ul.x);
5015 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
5016 if (tmp == (pair *) 0) {
5021 getmaxyx(current->wind, lr.y, lr.x);
5024 outerbox(ul, lr, FALSE);
5025 wnoutrefresh(stdscr);
5027 /* strictly cosmetic hack for the test */
5028 getmaxyx(current->wind, my, mx);
5029 if (my > tmp->y - ul.y) {
5030 getyx(current->wind, lr.y, lr.x);
5031 wmove(current->wind, tmp->y - ul.y + 1, 0);
5032 wclrtobot(current->wind);
5033 wmove(current->wind, lr.y, lr.x);
5035 if (mx > tmp->x - ul.x)
5036 for (i = 0; i < my; i++) {
5037 wmove(current->wind, i, tmp->x - ul.x + 1);
5038 wclrtoeol(current->wind);
5040 wnoutrefresh(current->wind);
5042 memcpy(&lr, tmp, sizeof(pair));
5043 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
5045 getbegyx(current->wind, ul.y, ul.x);
5046 getmaxyx(current->wind, lr.y, lr.x);
5049 outerbox(ul, lr, TRUE);
5050 wnoutrefresh(stdscr);
5052 wnoutrefresh(current->wind);
5058 #endif /* HAVE_WRESIZE */
5061 newwin_move(current, -1, 0);
5064 newwin_move(current, 1, 0);
5067 newwin_move(current, 0, -1);
5070 newwin_move(current, 0, 1);
5078 getyx(frame_win(current), y, x);
5082 x = getmaxx(frame_win(current)) - 1;
5084 (void) mvwdelch(frame_win(current), y, x);
5094 waddch(current->wind, (chtype) c);
5099 newwin_report(current);
5100 usescr = frame_win(current);
5103 (!isQuit(c = wGetchar(usescr), TRUE)
5107 while (current != 0)
5108 current = delete_framed(current, FALSE);
5110 scrollok(stdscr, TRUE); /* reset to driver's default */
5111 #ifdef NCURSES_MOUSE_VERSION
5112 mousemask(0, (mmask_t *) 0);
5120 /****************************************************************************
5124 ****************************************************************************/
5127 static int nap_msec = 1;
5129 static NCURSES_CONST char *mod[] =
5139 /*+-------------------------------------------------------------------------
5141 --------------------------------------------------------------------------*/
5143 wait_a_while(int msec GCC_UNUSED)
5153 else if (msec > 1000)
5154 sleep((unsigned) msec / 1000);
5158 } /* end of wait_a_while */
5160 /*+-------------------------------------------------------------------------
5162 --------------------------------------------------------------------------*/
5164 saywhat(NCURSES_CONST char *text)
5166 wmove(stdscr, LINES - 1, 0);
5168 if (text != 0 && *text != '\0') {
5169 waddstr(stdscr, text);
5170 waddstr(stdscr, "; ");
5172 waddstr(stdscr, "press any key to continue");
5173 } /* end of saywhat */
5175 /*+-------------------------------------------------------------------------
5176 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
5177 --------------------------------------------------------------------------*/
5179 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
5184 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
5185 if ((pan = new_panel(win)) == 0) {
5187 } else if (UseColors) {
5188 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
5191 NCURSES_COLOR_T bg = color;
5193 init_pair(color, fg, bg);
5194 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
5196 wbkgdset(win, A_BOLD | ' ');
5200 } /* end of mkpanel */
5202 /*+-------------------------------------------------------------------------
5204 --------------------------------------------------------------------------*/
5208 WINDOW *win = panel_window(pan);
5211 } /* end of rmpanel */
5213 /*+-------------------------------------------------------------------------
5215 --------------------------------------------------------------------------*/
5221 } /* end of pflush */
5223 /*+-------------------------------------------------------------------------
5225 --------------------------------------------------------------------------*/
5227 init_panel(WINDOW *win)
5231 for (y = 0; y < LINES - 1; y++) {
5232 for (x = 0; x < COLS; x++)
5233 wprintw(win, "%d", (y + x) % 10);
5238 fill_panel(PANEL *pan)
5240 WINDOW *win = panel_window(pan);
5241 const char *userptr = (const char *) panel_userptr(pan);
5242 int num = (userptr && *userptr) ? userptr[1] : '?';
5246 wprintw(win, "-pan%c-", num);
5249 for (y = 2; y < getmaxy(win) - 1; y++) {
5250 for (x = 1; x < getmaxx(win) - 1; x++) {
5252 waddch(win, UChar(num));
5257 #if USE_WIDEC_SUPPORT
5259 init_wide_panel(WINDOW *win)
5264 for (digit = 0; digit < 10; ++digit)
5265 make_fullwidth_digit(&temp[digit], digit);
5269 getyx(stdscr, y, x);
5270 digit = (y + x / 2) % 10;
5271 } while (wadd_wch(win, &temp[digit]) != ERR);
5275 fill_wide_panel(PANEL *pan)
5277 WINDOW *win = panel_window(pan);
5278 const char *userptr = (const char *) panel_userptr(pan);
5279 int num = (userptr && *userptr) ? userptr[1] : '?';
5283 wprintw(win, "-pan%c-", num);
5286 for (y = 2; y < getmaxy(win) - 1; y++) {
5287 for (x = 1; x < getmaxx(win) - 1; x++) {
5289 waddch(win, UChar(num));
5295 #define MAX_PANELS 5
5298 canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
5300 int which = cmd[1] - '0';
5305 hide_panel(px[which]);
5308 show_panel(px[which]);
5311 top_panel(px[which]);
5314 bottom_panel(px[which]);
5321 wait_a_while(nap_msec);
5325 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
5329 PANEL *px[MAX_PANELS + 1];
5331 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5335 for (count = 0; count < 5; count++) {
5336 px[1] = mkpanel(COLOR_RED,
5341 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
5343 px[2] = mkpanel(COLOR_GREEN,
5348 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5350 px[3] = mkpanel(COLOR_YELLOW,
5355 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5357 px[4] = mkpanel(COLOR_BLUE,
5362 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5364 px[5] = mkpanel(COLOR_MAGENTA,
5369 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5381 wait_a_while(nap_msec);
5383 saywhat("h3 s1 s2 s4 s5");
5384 move_panel(px[1], 0, 0);
5391 wait_a_while(nap_msec);
5393 canned_panel(px, "s1");
5394 canned_panel(px, "s2");
5397 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5399 wait_a_while(nap_msec);
5401 canned_panel(px, "s3");
5404 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5406 wait_a_while(nap_msec);
5408 canned_panel(px, "b3");
5409 canned_panel(px, "s4");
5410 canned_panel(px, "s5");
5411 canned_panel(px, "t3");
5412 canned_panel(px, "t1");
5413 canned_panel(px, "t2");
5414 canned_panel(px, "t3");
5415 canned_panel(px, "t4");
5417 for (itmp = 0; itmp < 6; itmp++) {
5418 WINDOW *w4 = panel_window(px[4]);
5419 WINDOW *w5 = panel_window(px[5]);
5422 wmove(w4, LINES / 8, 1);
5423 waddstr(w4, mod[itmp]);
5424 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5425 wmove(w5, LINES / 6, 1);
5426 waddstr(w5, mod[itmp]);
5428 wait_a_while(nap_msec);
5431 wmove(w4, LINES / 6, 1);
5432 waddstr(w4, mod[itmp]);
5433 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5434 wmove(w5, LINES / 8, 1);
5435 waddstr(w5, mod[itmp]);
5437 wait_a_while(nap_msec);
5441 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5443 wait_a_while(nap_msec);
5445 canned_panel(px, "t5");
5446 canned_panel(px, "t2");
5447 canned_panel(px, "t1");
5448 canned_panel(px, "d2");
5449 canned_panel(px, "h3");
5450 canned_panel(px, "d1");
5451 canned_panel(px, "d4");
5452 canned_panel(px, "d5");
5453 canned_panel(px, "d3");
5455 wait_a_while(nap_msec);
5468 panel_test(bool recur GCC_UNUSED)
5470 return demo_panels(init_panel, fill_panel);
5474 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
5476 x_panel_test(bool recur GCC_UNUSED)
5478 return demo_panels(init_wide_panel, fill_wide_panel);
5481 #endif /* USE_LIBPANEL */
5483 /****************************************************************************
5487 ****************************************************************************/
5491 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
5492 * though we can rely on negative x/y values to stop the macro.
5495 do_h_line(int y, int x, chtype c, int to)
5498 MvHLine(y, x, c, (to) - (x));
5502 do_v_line(int y, int x, chtype c, int to)
5505 MvVLine(y, x, c, (to) - (y));
5510 static bool pending_pan = FALSE;
5511 static bool show_panner_legend = TRUE;
5514 panner_legend(int line)
5516 static const char *const legend[] =
5518 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5519 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5520 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5521 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5523 int n = ((int) SIZEOF(legend) - (LINES - line));
5525 if (move(line, 0) != ERR) {
5526 if (show_panner_legend)
5527 printw("%s", legend[n]);
5529 return show_panner_legend;
5536 panner_h_cleanup(int from_y, int from_x, int to_x)
5538 if (!panner_legend(from_y))
5539 do_h_line(from_y, from_x, ' ', to_x);
5543 panner_v_cleanup(int from_y, int from_x, int to_y)
5545 if (!panner_legend(from_y))
5546 do_v_line(from_y, from_x, ' ', to_y);
5550 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5553 unsigned gridcount = 0;
5557 fill = (chtype) COLOR_PAIR(1);
5560 wmove(panpad, 0, 0);
5561 for (y = 0; y < getmaxy(panpad); y++) {
5562 for (x = 0; x < getmaxx(panpad); x++) {
5563 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5564 if (y == 0 && x == 0)
5565 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5567 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5568 else if (y == 0 || x == 0)
5569 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5571 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5572 (int) (gridcount++ % 26)) | fill);
5573 } else if (y % GRIDSIZE == 0)
5574 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5575 else if (x % GRIDSIZE == 0)
5576 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5578 waddch(panpad, ' ');
5585 int top_x, int top_y, int porty, int portx,
5586 int (*pgetc) (WINDOW *),
5589 #if HAVE_GETTIMEOFDAY
5590 struct timeval before, after;
5593 bool pan_lines = FALSE;
5594 bool scrollers = TRUE;
5597 int pxmax, pymax, lowend, highend, c;
5599 getmaxyx(pad, pymax, pxmax);
5600 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5604 #ifdef NCURSES_VERSION
5606 * During shell-out, the user may have resized the window. Adjust
5607 * the port size of the pad to accommodate this. Ncurses automatically
5608 * resizes all of the normal windows to fit on the new screen.
5625 if (c == HELP_KEY_1)
5626 show_panner_legend = !show_panner_legend;
5627 panner_legend(LINES - 4);
5628 panner_legend(LINES - 3);
5629 panner_legend(LINES - 2);
5630 panner_legend(LINES - 1);
5633 pan_lines = !pan_lines;
5634 fill_pad(pad, pan_lines, colored);
5635 pending_pan = FALSE;
5638 #if HAVE_GETTIMEOFDAY
5642 panner_legend(LINES - 1);
5646 scrollers = !scrollers;
5649 /* Move the top-left corner of the pad, keeping the bottom-right
5652 case 'h': /* increase-columns: move left edge to left */
5656 panner_v_cleanup(top_y, top_x, porty);
5661 case 'j': /* decrease-lines: move top-edge down */
5665 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5670 case 'k': /* increase-lines: move top-edge up */
5675 panner_h_cleanup(top_y, top_x, portx);
5679 case 'l': /* decrease-columns: move left-edge to right */
5683 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5688 /* Move the bottom-right corner of the pad, keeping the top-left
5691 case KEY_IC: /* increase-columns: move right-edge to right */
5692 if (portx >= pxmax || portx >= COLS)
5695 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5700 case KEY_IL: /* increase-lines: move bottom-edge down */
5701 if (porty >= pymax || porty >= LINES)
5704 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5709 case KEY_DC: /* decrease-columns: move bottom edge up */
5714 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5718 case KEY_DL: /* decrease-lines */
5723 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5727 case KEY_LEFT: /* pan leftwards */
5734 case KEY_RIGHT: /* pan rightwards */
5735 if (basex + portx - (pymax > porty) < pxmax)
5741 case KEY_UP: /* pan upwards */
5748 case KEY_DOWN: /* pan downwards */
5749 if (basey + porty - (pxmax > portx) < pymax)
5764 basey = pymax - porty;
5774 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5775 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5776 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5778 if (scrollers && (pxmax > portx - 1)) {
5779 int length = (portx - top_x - 1);
5780 float ratio = ((float) length) / ((float) pxmax);
5782 lowend = (int) ((float) top_x + ((float) basex * ratio));
5783 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5785 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5786 if (highend < portx) {
5788 do_h_line(porty - 1, lowend, ' ', highend + 1);
5790 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5793 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5795 if (scrollers && (pymax > porty - 1)) {
5796 int length = (porty - top_y - 1);
5797 float ratio = ((float) length) / ((float) pymax);
5799 lowend = (int) ((float) top_y + ((float) basey * ratio));
5800 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5802 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5803 if (highend < porty) {
5805 do_v_line(lowend, portx - 1, ' ', highend + 1);
5807 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5810 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5812 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5813 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5814 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5817 #if HAVE_GETTIMEOFDAY
5818 gettimeofday(&before, 0);
5820 wnoutrefresh(stdscr);
5825 porty - (pxmax > portx) - 1,
5826 portx - (pymax > porty) - 1);
5829 #if HAVE_GETTIMEOFDAY
5830 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5833 gettimeofday(&after, 0);
5834 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5835 move(LINES - 1, COLS - 12);
5836 printw("Secs: %2.03f", elapsed);
5843 ((c = pgetc(pad)) != KEY_EXIT);
5845 scrollok(stdscr, TRUE); /* reset to driver's default */
5849 padgetch(WINDOW *win)
5855 if ((pending_pan = (count > 0)) != FALSE) {
5857 pending_pan = (count != 0);
5860 switch (c = wGetchar(win)) {
5896 case ERR: /* FALLTHRU */
5902 if (c >= '0' && c <= '9') {
5903 count = count * 10 + (c - '0');
5917 #define PAD_HIGH 200
5918 #define PAD_WIDE 200
5921 pad_test(bool recur GCC_UNUSED)
5922 /* Demonstrate pads. */
5924 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5927 Cannot("cannot create requested pad");
5932 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5933 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5934 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5937 fill_pad(panpad, FALSE, TRUE);
5939 panner_legend(LINES - 4);
5940 panner_legend(LINES - 3);
5941 panner_legend(LINES - 2);
5942 panner_legend(LINES - 1);
5944 keypad(panpad, TRUE);
5946 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5947 * We'll still be able to widen it during a test, since that's required
5948 * for testing boundaries.
5950 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, TRUE);
5957 #endif /* HAVE_NEWPAD */
5959 /****************************************************************************
5961 * Tests from John Burnell's PDCurses tester
5963 ****************************************************************************/
5966 Continue(WINDOW *win)
5970 MvWAddStr(win, 10, 1, " Press any key to continue");
5976 flushinp_test(bool recur GCC_UNUSED)
5977 /* Input test, adapted from John Burnell's PDCurses tester */
5979 WINDOW *win = stdscr;
5980 int w, h, bx, by, sw, sh, i;
5985 getmaxyx(win, h, w);
5986 getbegyx(win, by, bx);
5989 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5994 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5995 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
5998 (void) wattrset(subWin, A_BOLD);
5999 box(subWin, ACS_VLINE, ACS_HLINE);
6000 MvWAddStr(subWin, 2, 1, "This is a subwindow");
6004 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
6005 * it only happened to "work" on SVr4 because that implementation does not
6006 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
6007 * test behavior, we're using 'cbreak()', which will allow a single
6008 * character to return without needing a newline. - T.Dickey 1997/10/11.
6011 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
6013 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
6014 MvWAddStr(win, 3, 1,
6015 "These should be discarded (not echoed) after the subwindow goes away.");
6018 for (i = 0; i < 5; i++) {
6019 MvWPrintw(subWin, 1, 1, "Time = %d", i);
6031 MvWAddStr(win, 2, 1,
6032 "If you were still typing when the window timer expired,");
6033 MvWAddStr(win, 3, 1,
6034 "or else you typed nothing at all while it was running,");
6035 MvWAddStr(win, 4, 1,
6036 "test was invalid. You'll see garbage or nothing at all. ");
6037 MvWAddStr(win, 6, 1, "Press a key");
6043 MvWAddStr(win, 12, 0,
6044 "If you see any key other than what you typed, flushinp() is broken.");
6053 "What you typed should now have been deleted; if not, wdelch() failed.");
6060 /****************************************************************************
6064 ****************************************************************************/
6072 menu_virtualize(int c)
6074 if (c == '\n' || c == KEY_EXIT)
6075 return (MAX_COMMAND + 1);
6077 return (REQ_SCR_ULINE);
6079 return (REQ_SCR_DLINE);
6080 else if (c == 'b' || c == KEY_NPAGE)
6081 return (REQ_SCR_UPAGE);
6082 else if (c == 'f' || c == KEY_PPAGE)
6083 return (REQ_SCR_DPAGE);
6084 else if (c == 'n' || c == KEY_DOWN)
6085 return (REQ_NEXT_ITEM);
6086 else if (c == 'p' || c == KEY_UP)
6087 return (REQ_PREV_ITEM);
6089 return (REQ_TOGGLE_ITEM);
6097 static CONST_MENUS char *animals[] =
6110 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6111 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6116 menu_test(bool recur GCC_UNUSED)
6119 ITEM *items[SIZEOF(animals)];
6121 CONST_MENUS char **ap;
6122 int mrows, mcols, c;
6125 #ifdef NCURSES_MOUSE_VERSION
6126 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6128 MvAddStr(0, 0, "This is the menu test:");
6129 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
6130 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
6132 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
6133 MvAddStr(5, 0, " Press return to exit.");
6136 for (ap = animals; *ap; ap++) {
6137 if ((*ip = new_item(*ap, "")) != 0)
6142 m = new_menu(items);
6144 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
6145 scale_menu(m, &mrows, &mcols);
6147 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6148 set_menu_win(m, menuwin);
6149 keypad(menuwin, TRUE);
6152 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6156 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
6157 if (c == E_NOT_POSTED)
6159 if (c == E_REQUEST_DENIED)
6164 MvPrintw(LINES - 2, 0,
6165 "You chose: %s\n", item_name(current_item(m)));
6166 (void) addstr("Press any key to continue...");
6173 for (ip = items; *ip; ip++)
6175 #ifdef NCURSES_MOUSE_VERSION
6176 mousemask(0, (mmask_t *) 0);
6182 #define T_TBL(name) { #name, name }
6188 T_TBL(TRACE_DISABLE),
6191 T_TBL(TRACE_UPDATE),
6193 T_TBL(TRACE_CHARPUT),
6194 T_TBL(TRACE_ORDINARY),
6196 T_TBL(TRACE_VIRTPUT),
6197 T_TBL(TRACE_IEVENT),
6199 T_TBL(TRACE_ICALLS),
6200 T_TBL(TRACE_CCALLS),
6201 T_TBL(TRACE_DATABASE),
6203 T_TBL(TRACE_MAXIMUM),
6210 tracetrace(unsigned tlevel)
6213 static size_t need = 12;
6217 for (n = 0; t_tbl[n].name != 0; n++)
6218 need += strlen(t_tbl[n].name) + 2;
6219 buf = typeMalloc(char, need);
6221 failed("tracetrace");
6223 _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
6225 _nc_STRCAT(buf, t_tbl[0].name, need);
6226 _nc_STRCAT(buf, ", ", need);
6228 for (n = 1; t_tbl[n].name != 0; n++)
6229 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
6230 _nc_STRCAT(buf, t_tbl[n].name, need);
6231 _nc_STRCAT(buf, ", ", need);
6234 if (buf[strlen(buf) - 2] == ',')
6235 buf[strlen(buf) - 2] = '\0';
6236 _nc_STRCAT(buf, "}", need);
6240 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
6244 run_trace_menu(MENU * m)
6250 bool changed = FALSE;
6251 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
6252 case E_UNKNOWN_COMMAND:
6255 items = menu_items(m);
6256 i = current_item(m);
6257 if (i == items[0]) {
6258 if (item_value(i)) {
6259 for (p = items + 1; *p != 0; p++)
6260 if (item_value(*p)) {
6261 set_item_value(*p, FALSE);
6266 for (p = items + 1; *p != 0; p++)
6267 if (item_value(*p)) {
6268 set_item_value(items[0], FALSE);
6280 trace_set(bool recur GCC_UNUSED)
6281 /* interactively set the trace level */
6284 ITEM *items[SIZEOF(t_tbl)];
6291 MvAddStr(0, 0, "Interactively set trace level:");
6292 MvAddStr(2, 0, " Press space bar to toggle a selection.");
6293 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
6294 MvAddStr(4, 0, " Press return to set the trace level.");
6295 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
6299 for (n = 0; t_tbl[n].name != 0; n++) {
6300 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
6306 m = new_menu(items);
6308 set_menu_format(m, 0, 2);
6309 scale_menu(m, &mrows, &mcols);
6311 menu_opts_off(m, O_ONEVALUE);
6312 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6313 set_menu_win(m, menuwin);
6314 keypad(menuwin, TRUE);
6317 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6321 for (ip = menu_items(m); *ip; ip++) {
6322 unsigned mask = t_tbl[item_index(*ip)].mask;
6324 set_item_value(*ip, _nc_tracing == 0);
6325 else if ((mask & _nc_tracing) == mask)
6326 set_item_value(*ip, TRUE);
6329 while (run_trace_menu(m))
6333 for (ip = menu_items(m); *ip; ip++)
6334 if (item_value(*ip))
6335 newtrace |= t_tbl[item_index(*ip)].mask;
6337 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
6339 MvPrintw(LINES - 2, 0,
6340 "Trace level is %s\n", tracetrace(_nc_tracing));
6341 (void) addstr("Press any key to continue...");
6348 for (ip = items; *ip; ip++)
6354 #endif /* USE_LIBMENU */
6356 /****************************************************************************
6360 ****************************************************************************/
6363 make_label(int frow, int fcol, NCURSES_CONST char *label)
6365 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
6368 set_field_buffer(f, 0, label);
6369 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
6375 make_field(int frow, int fcol, int rows, int cols, bool secure)
6377 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
6380 set_field_back(f, A_UNDERLINE);
6381 set_field_userptr(f, (void *) 0);
6387 display_form(FORM *f)
6392 scale_form(f, &rows, &cols);
6394 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6396 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6399 if (post_form(f) != E_OK)
6407 WINDOW *w = form_win(f);
6408 WINDOW *s = form_sub(f);
6418 edit_secure(FIELD *me, int c)
6420 int rows, cols, frow, fcol, nrow, nbuf;
6422 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6424 char *source = field_buffer(me, 1);
6425 size_t have = (source ? strlen(source) : 0) + 1;
6426 size_t need = 80 + have;
6427 char *temp = malloc(need);
6431 _nc_STRNCPY(temp, source ? source : "", have + 1);
6432 len = (size_t) (char *) field_userptr(me);
6434 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6435 temp[len++] = (char) c;
6437 set_field_buffer(me, 1, temp);
6457 case REQ_RIGHT_CHAR:
6459 c = 0; /* we don't want to do inline editing */
6464 set_field_buffer(me, 1, temp);
6471 set_field_buffer(me, 1, temp);
6476 set_field_userptr(me, (void *) len);
6484 form_virtualize(FORM *f, WINDOW *w)
6487 static const struct {
6491 { CTRL('A'), REQ_NEXT_CHOICE },
6492 { CTRL('B'), REQ_PREV_WORD },
6493 { CTRL('C'), REQ_CLR_EOL },
6494 { CTRL('D'), REQ_DOWN_FIELD },
6495 { CTRL('E'), REQ_END_FIELD },
6496 { CTRL('F'), REQ_NEXT_PAGE },
6497 { CTRL('G'), REQ_DEL_WORD },
6498 { CTRL('H'), REQ_DEL_PREV },
6499 { CTRL('I'), REQ_INS_CHAR },
6500 { CTRL('K'), REQ_CLR_EOF },
6501 { CTRL('L'), REQ_LEFT_FIELD },
6502 { CTRL('M'), REQ_NEW_LINE },
6503 { CTRL('N'), REQ_NEXT_FIELD },
6504 { CTRL('O'), REQ_INS_LINE },
6505 { CTRL('P'), REQ_PREV_FIELD },
6506 { CTRL('R'), REQ_RIGHT_FIELD },
6507 { CTRL('S'), REQ_BEG_FIELD },
6508 { CTRL('U'), REQ_UP_FIELD },
6509 { CTRL('V'), REQ_DEL_CHAR },
6510 { CTRL('W'), REQ_NEXT_WORD },
6511 { CTRL('X'), REQ_CLR_FIELD },
6512 { CTRL('Y'), REQ_DEL_LINE },
6513 { CTRL('Z'), REQ_PREV_CHOICE },
6514 { ESCAPE, MAX_FORM_COMMAND + 1 },
6515 { KEY_BACKSPACE, REQ_DEL_PREV },
6516 { KEY_DOWN, REQ_DOWN_CHAR },
6517 { KEY_END, REQ_LAST_FIELD },
6518 { KEY_HOME, REQ_FIRST_FIELD },
6519 { KEY_LEFT, REQ_LEFT_CHAR },
6520 { KEY_LL, REQ_LAST_FIELD },
6521 { KEY_NEXT, REQ_NEXT_FIELD },
6522 { KEY_NPAGE, REQ_NEXT_PAGE },
6523 { KEY_PPAGE, REQ_PREV_PAGE },
6524 { KEY_PREVIOUS, REQ_PREV_FIELD },
6525 { KEY_RIGHT, REQ_RIGHT_CHAR },
6526 { KEY_UP, REQ_UP_CHAR },
6527 { QUIT, MAX_FORM_COMMAND + 1 }
6531 static int mode = REQ_INS_MODE;
6532 int c = wGetchar(w);
6534 FIELD *me = current_field(f);
6535 bool current = TRUE;
6537 if (c == CTRL(']')) {
6538 if (mode == REQ_INS_MODE) {
6539 mode = REQ_OVL_MODE;
6541 mode = REQ_INS_MODE;
6545 for (n = 0; n < SIZEOF(lookup); n++) {
6546 if (lookup[n].code == c) {
6547 c = lookup[n].result;
6552 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6555 * Force the field that the user is typing into to be in reverse video,
6556 * while the other fields are shown underlined.
6571 case REQ_LEFT_FIELD:
6573 case REQ_RIGHT_CHAR:
6577 current = (c < KEY_MAX);
6581 c = edit_secure(me, c);
6582 set_field_back(me, A_REVERSE);
6584 c = edit_secure(me, c);
6585 set_field_back(me, A_UNDERLINE);
6591 my_form_driver(FORM *form, int c)
6593 if (c == (MAX_FORM_COMMAND + 1)
6594 && form_driver(form, REQ_VALIDATION) == E_OK)
6602 #ifdef NCURSES_VERSION
6603 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6604 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6606 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6607 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6611 * Allow a middle initial, optionally with a '.' to end it.
6614 FIELDCHECK_CB(mi_field_check)
6616 char *s = field_buffer(fld, 0);
6620 for (n = 0; s[n] != '\0'; ++n) {
6627 } else if (isspace(UChar(s[n]))) {
6632 if (!isspace(UChar(s[n])))
6638 /* force the form to display a leading capital */
6639 if (islower(UChar(s[0]))) {
6640 s[0] = (char) toupper(UChar(s[0]));
6641 set_field_buffer(fld, 0, s);
6647 CHAR_CHECK_CB(mi_char_check)
6649 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6653 * Passwords should be at least 6 characters.
6656 FIELDCHECK_CB(pw_field_check)
6658 char *s = field_buffer(fld, 0);
6661 for (n = 0; s[n] != '\0'; ++n) {
6662 if (isspace(UChar(s[n]))) {
6671 CHAR_CHECK_CB(pw_char_check)
6673 return (isgraph(ch) ? TRUE : FALSE);
6677 form_test(bool recur GCC_UNUSED)
6681 FIELD *f[12], *secure;
6682 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6683 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6684 int finished = 0, c;
6687 #ifdef NCURSES_MOUSE_VERSION
6688 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6692 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6693 addstr("^N -- go to next field ^P -- go to previous field\n");
6694 addstr("Home -- go to first field End -- go to last field\n");
6695 addstr("^L -- go to field to left ^R -- go to field to right\n");
6696 addstr("^U -- move upward to field ^D -- move downward to field\n");
6697 addstr("^W -- go to next word ^B -- go to previous word\n");
6698 addstr("^S -- go to start of field ^E -- go to end of field\n");
6699 addstr("^H -- delete previous char ^Y -- delete line\n");
6700 addstr("^G -- delete current word ^C -- clear to end of line\n");
6701 addstr("^K -- clear to end of field ^X -- clear field\n");
6702 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6704 MvAddStr(4, 57, "Forms Entry Test");
6708 /* describe the form */
6709 memset(f, 0, sizeof(f));
6710 f[n++] = make_label(0, 15, "Sample Form");
6712 f[n++] = make_label(2, 0, "Last Name");
6713 f[n++] = make_field(3, 0, 1, 18, FALSE);
6714 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6716 f[n++] = make_label(2, 20, "First Name");
6717 f[n++] = make_field(3, 20, 1, 12, FALSE);
6718 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6720 f[n++] = make_label(2, 34, "Middle Name");
6721 f[n++] = make_field(3, 34, 1, 12, FALSE);
6722 set_field_type(f[n - 1], fty_middle);
6724 f[n++] = make_label(5, 0, "Comments");
6725 f[n++] = make_field(6, 0, 4, 46, FALSE);
6727 f[n++] = make_label(5, 20, "Password:");
6729 f[n++] = make_field(5, 30, 1, 9, TRUE);
6730 set_field_type(f[n - 1], fty_passwd);
6733 if ((form = new_form(f)) != 0) {
6739 nonl(); /* lets us read ^M's */
6741 switch (form_driver(form, c = form_virtualize(form, w))) {
6743 MvAddStr(5, 57, field_buffer(secure, 1));
6747 case E_UNKNOWN_COMMAND:
6748 finished = my_form_driver(form, c);
6760 for (c = 0; f[c] != 0; c++)
6762 free_fieldtype(fty_middle);
6763 free_fieldtype(fty_passwd);
6767 #ifdef NCURSES_MOUSE_VERSION
6768 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6772 #endif /* USE_LIBFORM */
6774 /****************************************************************************
6778 ****************************************************************************/
6780 #if HAVE_COPYWIN /* ...and overlay, overwrite */
6782 static const int overlap_HEAD = 1;
6783 static const int overlap_FOOT = 6;
6791 getmaxyx(stdscr, y, x);
6792 if (y < 23 || x < 80) {
6793 Cannot("The screen is too small for this test");
6796 int ymax = y - (overlap_HEAD + overlap_FOOT);
6797 int high = ymax / 5; /* equal-sized parts for cross */
6798 int xmax = x - 2; /* margin */
6799 int wide = (xmax / 5) & ~1;
6808 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6809 lmar = (xmax - (5 * wide)) / 2;
6812 result = newwin(3 * high, 3 * wide, tmar, lmar);
6814 result = newwin(3 * high, 3 * wide, tmar + 2 * high, lmar + 2 * wide);
6825 for (row = overlap_HEAD; row < LINES - overlap_FOOT; ++row) {
6832 move_overlap(int shift, WINDOW *win1)
6834 int ymax = getmaxy(stdscr) - (overlap_HEAD + overlap_FOOT);
6835 int high = ymax / 5; /* equal-sized parts for cross */
6837 int xmax1 = getmaxx(win1) + 1;
6838 int lmar1 = (COLS - (5 * (xmax1) / 3)) / 2;
6843 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6845 rc = mvwin(win1, tmar, lmar1 + shift);
6850 fillwin(WINDOW *win, char ch)
6855 getmaxyx(win, y1, x1);
6856 for (y = 0; y < y1; y++) {
6858 for (x = 0; x < x1; x++)
6859 waddch(win, UChar(ch));
6863 #define InCross(x,y, x1,y1) \
6864 (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3)) \
6865 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3))))
6868 crosswin(WINDOW *win, char ch)
6874 getmaxyx(win, y1, x1);
6875 for (y = 0; y < y1; y++) {
6876 for (x = 0; x < x1; x += xw) {
6877 if (InCross(x, y, x1, y1)) {
6879 waddch(win, UChar(ch));
6886 * Match "crosswin()", but using line-drawing characters. This could be done
6887 * a little simpler using box(), but the reason for this example is to test
6888 * hline/vline and addch with line-drawing vs the copy/overlay functions.
6891 crossbox(WINDOW *win)
6896 getmaxyx(win, y1, x1);
6901 mvwhline(win, 0, (xmax / 3), ACS_HLINE, (xmax / 3));
6902 mvwhline(win, ymax / 3, 0, ACS_HLINE, xmax);
6903 mvwhline(win, ((2 * ymax) / 3) - 1, 0, ACS_HLINE, xmax);
6904 mvwhline(win, y1 - 1, (xmax / 3), ACS_HLINE, (xmax / 3));
6906 mvwvline(win, (ymax / 3), 0, ACS_VLINE, (ymax / 3));
6907 mvwvline(win, 0, xmax / 3, ACS_VLINE, ymax);
6908 mvwvline(win, 0, ((2 * xmax) / 3) - 1, ACS_VLINE, ymax);
6909 mvwvline(win, (ymax / 3), x1 - 1, ACS_VLINE, (ymax / 3));
6911 mvwaddch(win, 0, (xmax / 3), ACS_ULCORNER);
6912 mvwaddch(win, 0, ((2 * xmax) / 3) - 1, ACS_URCORNER);
6913 mvwaddch(win, y1 - 1, (xmax / 3), ACS_LLCORNER);
6914 mvwaddch(win, y1 - 1, ((2 * xmax) / 3) - 1, ACS_LRCORNER);
6916 mvwaddch(win, (ymax / 3), 0, ACS_ULCORNER);
6917 mvwaddch(win, ((2 * ymax) / 3) - 1, 0, ACS_LLCORNER);
6918 mvwaddch(win, (ymax / 3), x1 - 1, ACS_URCORNER);
6919 mvwaddch(win, ((2 * ymax) / 3) - 1, x1 - 1, ACS_LRCORNER);
6921 mvwaddch(win, (ymax / 3), (xmax / 3), ACS_PLUS);
6922 mvwaddch(win, (ymax / 3), ((2 * xmax) / 3) - 1, ACS_PLUS);
6923 mvwaddch(win, ((2 * ymax) / 3) - 1, ((2 * xmax) / 3) - 1, ACS_PLUS);
6924 mvwaddch(win, ((2 * ymax) / 3) - 1, (xmax / 3), ACS_PLUS);
6935 #define OVERLAP_FLAVORS 6
6944 #define LimitFILL() UseColors ? 4 : 2
6947 otDRAW_text_cross = 0
6954 #define LimitDRAW() UseColors ? 5 : 3
6957 otCOPY_overwrite = 0
6963 #define LimitCOPY() 4
6966 overlap_helpitem(int state, int item, char *message)
6968 int row = (item / 2);
6969 int col = ((item % 2) ? COLS / 2 : 0);
6971 move(LINES - 6 + row, col);
6972 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6977 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6979 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6981 switch ((otFILL) flavor) {
6983 (void) wattrset(win, A_NORMAL);
6986 (void) wattrset(win, A_BOLD);
6989 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6990 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
6993 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6994 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
7000 overlap_test_2_attr(WINDOW *win, int flavor, int col)
7002 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
7004 switch ((otDRAW) flavor) {
7005 case otDRAW_text_cross:
7008 case otDRAW_line_box:
7011 case otDRAW_line_cross:
7015 init_pair(cpair, COLOR_RED, COLOR_GREEN);
7016 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
7018 case otDRAW_reset_bg:
7019 wbkgdset(win, ' ' | A_NORMAL);
7025 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
7030 int limit[OVERLAP_FLAVORS];
7031 const char *ths, *tht;
7035 state += OVERLAP_FLAVORS;
7036 state = state % OVERLAP_FLAVORS;
7037 assert(state >= 0 && state < OVERLAP_FLAVORS);
7039 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
7042 ths = col ? "B" : "A";
7043 tht = col ? "A" : "B";
7045 switch ((otBASE) row) {
7046 case otBASE_refresh:
7049 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7050 "refresh %s, then %s, then doupdate.", ths, tht);
7053 limit[row] = LimitFILL();
7054 flavors[row] %= limit[row];
7055 overlap_test_1_attr(stdscr, flavors[row], col);
7056 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7057 "fill window %s with letter %s.", ths, ths);
7060 limit[row] = LimitDRAW();
7061 flavors[row] %= limit[row];
7062 switch ((otDRAW) flavors[row]) {
7063 case otDRAW_text_cross:
7064 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7065 "cross text-pattern in window %s.", ths);
7067 case otDRAW_line_box:
7068 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7069 "draw line-box in window %s.", ths);
7071 case otDRAW_line_cross:
7072 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7073 "draw line-cross in window %s.", ths);
7076 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7077 "set background of window %s.", ths);
7079 case otDRAW_reset_bg:
7080 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7081 "reset background of window %s.", ths);
7088 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7089 "clear window %s.", ths);
7092 limit[row] = LimitCOPY();
7093 flavors[row] %= limit[row];
7094 switch ((otCOPY) flavors[row]) {
7095 case otCOPY_overwrite:
7096 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7097 "overwrite %s onto %s.", ths, tht);
7100 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7101 "copywin(FALSE) %s onto %s.", ths, tht);
7104 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7105 "copywin(TRUE) %s onto %s.", ths, tht);
7107 case otCOPY_overlay:
7108 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7109 "overlay %s onto %s.", ths, tht);
7114 overlap_helpitem(state, item, msg);
7115 (void) wattrset(stdscr, A_NORMAL);
7116 wbkgdset(stdscr, ' ' | A_NORMAL);
7119 printw("^Q/ESC = terminate test. </> shift. Up/down/space select (row %d",
7121 if (limit[state] > 1)
7122 printw(" test %d:%d", 1 + flavors[state], limit[state]);
7130 overlap_test_0(WINDOW *a, WINDOW *b)
7140 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
7142 overlap_test_1_attr(a, flavor, col);
7144 (void) wattrset(a, A_NORMAL);
7148 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
7150 overlap_test_2_attr(a, flavor, col);
7151 switch ((otDRAW) flavor) {
7152 case otDRAW_text_cross:
7155 case otDRAW_line_box:
7158 case otDRAW_line_cross:
7162 /* done in overlap_test_2_attr */
7164 case otDRAW_reset_bg:
7165 /* done in overlap_test_2_attr */
7171 overlap_test_3(WINDOW *a)
7178 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
7180 switch ((otCOPY) flavor) {
7181 case otCOPY_overwrite:
7185 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
7188 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
7190 case otCOPY_overlay:
7196 /* test effects of overlapping windows */
7198 overlap_test(bool recur GCC_UNUSED)
7200 WINDOW *win1, *win2;
7202 int shift = 0, last_refresh = -1;
7203 int state, flavor[OVERLAP_FLAVORS];
7205 if ((win1 = make_overlap(0)) == 0) {
7207 } else if ((win2 = make_overlap(1)) == 0) {
7216 printw("Test wnoutrefresh() for two overlapping windows:");
7218 memset(flavor, 0, sizeof(flavor));
7219 state = overlap_help(0, flavor);
7221 while (!isQuit(ch = Getchar(), TRUE)) {
7223 case 'a': /* refresh window A first, then B */
7224 overlap_test_0(win1, win2);
7227 case 'b': /* refresh window B first, then A */
7228 overlap_test_0(win2, win1);
7231 case 'c': /* fill window A so it's visible */
7232 overlap_test_1(flavor[otBASE_fill], 0, win1, 'A');
7235 case 'd': /* fill window B so it's visible */
7236 overlap_test_1(flavor[otBASE_fill], 1, win2, 'B');
7239 case 'e': /* cross test pattern in window A */
7240 overlap_test_2(flavor[otBASE_draw], 0, win1, 'A');
7243 case 'f': /* cross test pattern in window A */
7244 overlap_test_2(flavor[otBASE_draw], 1, win2, 'B');
7247 case 'g': /* clear window A */
7248 overlap_test_3(win1);
7251 case 'h': /* clear window B */
7252 overlap_test_3(win2);
7255 case 'i': /* overwrite A onto B */
7256 overlap_test_4(flavor[otBASE_copy], win1, win2);
7259 case 'j': /* overwrite B onto A */
7260 overlap_test_4(flavor[otBASE_copy], win2, win1);
7265 state = overlap_help(state + 1, flavor);
7270 state = overlap_help(state - 1, flavor);
7275 state = overlap_help(state, flavor);
7279 state = overlap_help(state, flavor);
7304 if (move_overlap(shift, win1) != OK) {
7306 shift += (ch == '>') ? -1 : 1;
7307 } else if (last_refresh > 0) {
7309 wnoutrefresh(stdscr);
7310 if (last_refresh == 'a')
7311 overlap_test_0(win1, win2);
7313 overlap_test_0(win2, win1);
7329 #if USE_WIDEC_SUPPORT
7331 x_fillwin(WINDOW *win, wchar_t ch)
7336 getmaxyx(win, y1, x1);
7338 for (y = 0; y < y1; y++) {
7340 for (x = 0; x < x1; x++)
7341 waddnwstr(win, &ch, 1);
7346 x_crosswin(WINDOW *win, wchar_t ch)
7352 getmaxyx(win, y1, x1);
7353 for (y = 0; y < y1; y++) {
7354 for (x = 0; x < x1; x += xw) {
7355 if (InCross(x, y, x1, y1)) {
7357 waddnwstr(win, &ch, 1);
7364 x_overlap_test_1(int flavor, int col, WINDOW *a, wchar_t fill)
7366 overlap_test_1_attr(a, flavor, col);
7368 (void) wattrset(a, A_NORMAL);
7372 x_overlap_test_2(int flavor, int col, WINDOW *a, wchar_t fill)
7374 overlap_test_2_attr(a, flavor, col);
7375 switch ((otDRAW) flavor) {
7376 case otDRAW_text_cross:
7377 x_crosswin(a, fill);
7379 case otDRAW_line_box:
7382 case otDRAW_line_cross:
7386 /* done in overlap_test_2_attr */
7388 case otDRAW_reset_bg:
7389 /* done in overlap_test_2_attr */
7394 /* test effects of overlapping windows */
7396 x_overlap_test(bool recur GCC_UNUSED)
7398 const wchar_t WIDE_A = 0xff21;
7399 const wchar_t WIDE_B = 0xff22;
7400 WINDOW *win1, *win2;
7402 int shift = 0, last_refresh = -1;
7403 int state, flavor[OVERLAP_FLAVORS];
7405 if ((win1 = make_overlap(0)) == 0) {
7407 } else if ((win2 = make_overlap(1)) == 0) {
7416 printw("Test wnoutrefresh() for overlapping windows with double-cell characters:");
7418 memset(flavor, 0, sizeof(flavor));
7419 state = overlap_help(0, flavor);
7421 while (!isQuit(ch = Getchar(), TRUE)) {
7423 case 'a': /* refresh window A first, then B */
7424 overlap_test_0(win1, win2);
7427 case 'b': /* refresh window B first, then A */
7428 overlap_test_0(win2, win1);
7431 case 'c': /* fill window A so it's visible */
7432 x_overlap_test_1(flavor[otBASE_fill], 0, win1, WIDE_A);
7435 case 'd': /* fill window B so it's visible */
7436 x_overlap_test_1(flavor[otBASE_fill], 1, win2, WIDE_B);
7439 case 'e': /* cross test pattern in window A */
7440 x_overlap_test_2(flavor[otBASE_draw], 0, win1, WIDE_A);
7443 case 'f': /* cross test pattern in window A */
7444 x_overlap_test_2(flavor[otBASE_draw], 1, win2, WIDE_B);
7447 case 'g': /* clear window A */
7448 overlap_test_3(win1);
7451 case 'h': /* clear window B */
7452 overlap_test_3(win2);
7455 case 'i': /* overwrite A onto B */
7456 overlap_test_4(flavor[otBASE_copy], win1, win2);
7459 case 'j': /* overwrite B onto A */
7460 overlap_test_4(flavor[otBASE_copy], win2, win1);
7465 state = overlap_help(state + 1, flavor);
7470 state = overlap_help(state - 1, flavor);
7475 state = overlap_help(state, flavor);
7479 state = overlap_help(state, flavor);
7504 if (move_overlap(shift, win1) != OK) {
7506 shift += (ch == '>') ? -1 : 1;
7507 } else if (last_refresh > 0) {
7509 wnoutrefresh(stdscr);
7510 if (last_refresh == 'a')
7511 overlap_test_0(win1, win2);
7513 overlap_test_0(win2, win1);
7528 #endif /* USE_WIDEC_SUPPORT */
7530 #endif /* HAVE_COPYWIN */
7533 show_setting_name(const char *name)
7535 printw("%-25s ", name);
7539 show_string_setting(const char *name, const char *value)
7541 show_setting_name(name);
7543 printw("\"%s\"", value);
7553 show_number_setting(const char *name, int value)
7555 show_setting_name(name);
7557 printw("%d", value);
7560 printw("%d", value);
7567 show_boolean_setting(const char *name, int value)
7569 show_setting_name(name);
7571 printw("%s", value ? "TRUE" : "FALSE");
7574 printw("%d", value);
7581 settings_test(bool recur GCC_UNUSED)
7583 #if USE_WIDEC_SUPPORT
7588 show_string_setting("termname", termname());
7589 show_string_setting("longname", longname());
7590 show_number_setting("baudrate", baudrate());
7591 if (erasechar() > 0) {
7592 show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
7593 show_string_setting("keyname(erasechar)", keyname(erasechar()));
7595 if (killchar() > 0) {
7596 show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
7597 show_string_setting("keyname(killchar)", keyname(killchar()));
7599 #if USE_WIDEC_SUPPORT
7600 if (erasewchar(&ch) == OK) {
7601 show_string_setting("key_name(erasewchar)", key_name(ch));
7603 if (killwchar(&ch) == OK) {
7604 show_string_setting("key_name(killwchar)", key_name(ch));
7607 show_boolean_setting("has_ic", has_ic());
7608 show_boolean_setting("has_il", has_il());
7609 show_boolean_setting("has_colors", has_colors());
7610 #if HAVE_COLOR_CONTENT
7611 show_boolean_setting("can_change_color", can_change_color());
7619 /****************************************************************************
7623 ****************************************************************************/
7628 static const char *const tbl[] =
7630 "Usage: ncurses [options]"
7633 #ifdef NCURSES_VERSION
7634 ," -a f,b set default-colors (assumed white-on-black)"
7635 ," -d use default-colors if terminal supports them"
7638 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
7641 ," -e fmt specify format for soft-keys test (e)"
7644 ," -f rip-off footer line (can repeat)"
7645 ," -h rip-off header line (can repeat)"
7647 ," -m do not use colors"
7648 #if HAVE_COLOR_CONTENT
7649 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
7652 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
7654 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_WIN32)
7655 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
7658 ," -t mask specify default trace-level (may toggle with ^T)"
7660 #if HAVE_COLOR_CONTENT
7661 ," -x use xterm-compatible control for reading color palette"
7665 for (n = 0; n < SIZEOF(tbl); n++)
7666 fprintf(stderr, "%s\n", tbl[n]);
7667 ExitProgram(EXIT_FAILURE);
7671 set_terminal_modes(void)
7676 scrollok(stdscr, TRUE);
7677 idlok(stdscr, TRUE);
7678 keypad(stdscr, TRUE);
7683 announce_sig(int sig)
7685 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
7691 rip_footer(WINDOW *win, int cols)
7693 wbkgd(win, A_REVERSE);
7696 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
7702 rip_header(WINDOW *win, int cols)
7704 wbkgd(win, A_REVERSE);
7707 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
7711 #endif /* HAVE_RIPOFFLINE */
7716 #if USE_WIDEC_SUPPORT
7719 int (*narrow_func) (bool);
7720 int (*wide_func) (bool);
7724 #define BOTH(a) a, x_ ## a
7725 #define ONLY(a) a, NULL
7726 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7730 int (*narrow_func) (bool);
7736 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7739 static MyCmds cmds[] =
7741 CMDS(TRUE, BOTH(getch_test), 'a', "keyboard and mouse input test"),
7742 CMDS(TRUE, BOTH(attr_test), 'b', "character attribute test"),
7743 CMDS(TRUE, BOTH(color_test), 'c', "color test pattern"),
7744 #if HAVE_COLOR_CONTENT
7745 CMDS(FALSE, ONLY(color_edit), 'd', "edit RGB color values"),
7748 CMDS(TRUE, BOTH(slk_test), 'e', "exercise soft keys"),
7750 CMDS(TRUE, BOTH(acs_test), 'f', "display ACS characters"),
7751 CMDS(TRUE, ONLY(scroll_test), 'g', "display windows and scrolling"),
7752 CMDS(TRUE, ONLY(flushinp_test), 'i', "test flushinp()"),
7753 CMDS(TRUE, ONLY(sgr_attr_test), 'k', "display character attributes"),
7755 CMDS(TRUE, ONLY(menu_test), 'm', "exercise menu library"),
7758 CMDS(TRUE, BOTH(panel_test), 'o', "exercise panel library"),
7761 CMDS(TRUE, ONLY(pad_test), 'p', "exercise pad features"),
7763 CMDS(TRUE, ONLY(NULL), 'q', "quit"),
7765 CMDS(TRUE, ONLY(form_test), 'r', "exercise form library"),
7768 CMDS(TRUE, BOTH(overlap_test), 's', "overlapping-refresh test"),
7770 #if USE_LIBMENU && defined(TRACE)
7771 CMDS(TRUE, ONLY(trace_set), 't', "set trace level"),
7773 CMDS(TRUE, ONLY(settings_test), 'v', "show terminal name and settings"),
7774 CMDS(FALSE, ONLY(NULL), '?', "repeat this command summary")
7783 printf("This is the ncurses main menu (uppercase for wide-characters)\n");
7784 for (n = 0; n < SIZEOF(cmds); ++n) {
7785 if (top || cmds[n].recur) {
7787 #if USE_WIDEC_SUPPORT
7788 if (cmds[n].wide_func) {
7789 printf("%c,", toupper(cmds[n].code));
7792 printf("%c\t= %s\n", cmds[n].code, cmds[n].help);
7796 (void) fputs("> ", stdout);
7797 (void) fflush(stdout); /* necessary under SVr4 curses */
7800 * This used to be an 'fgets()' call (until 1996/10). However with
7801 * some runtime libraries, mixing stream I/O and 'read()' causes the
7802 * input stream to be flushed when switching between the two.
7807 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7810 if (errno == EINTR) {
7815 } else if (command == 0 && !isspace(UChar(ch))) {
7817 } else if (ch == '\n' || ch == '\r') {
7818 if ((command == 'd') && !top) {
7819 (void) fputs("Do not nest test-d\n", stdout);
7824 (void) fputs("> ", stdout);
7825 (void) fflush(stdout);
7830 for (n = 0; n < SIZEOF(cmds); ++n) {
7831 if (cmds[n].code == command) {
7832 doit = cmds[n].narrow_func;
7835 #if USE_WIDEC_SUPPORT
7836 if (toupper(cmds[n].code) == command) {
7837 doit = cmds[n].wide_func;
7843 if (doit != NULL && doit(FALSE) == OK) {
7845 * This may be overkill; it's intended to reset everything back
7846 * to the initial terminal modes so that tests don't get in
7850 set_terminal_modes();
7855 if (command == '?') {
7856 (void) puts("This is the ncurses capability tester.");
7858 puts("You may select a test from the main menu by typing the");
7860 puts("key letter of the choice (the letter to left of the =)");
7862 puts("at the > prompt. Type `q' to exit.");
7870 /*+-------------------------------------------------------------------------
7872 --------------------------------------------------------------------------*/
7875 main(int argc, char *argv[])
7879 #ifdef NCURSES_VERSION
7880 int default_fg = COLOR_WHITE;
7881 int default_bg = COLOR_BLACK;
7882 bool assumed_colors = FALSE;
7883 bool default_colors = FALSE;
7885 bool monochrome = FALSE;
7886 #if HAVE_COLOR_CONTENT
7887 bool xterm_colors = FALSE;
7888 char *palette_file = 0;
7891 setlocale(LC_ALL, "");
7893 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) {
7895 #ifdef NCURSES_VERSION
7897 assumed_colors = TRUE;
7898 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7900 default_fg = COLOR_WHITE;
7903 default_bg = COLOR_BLACK;
7908 default_colors = TRUE;
7917 my_e_param = atoi(optarg);
7918 #ifdef NCURSES_VERSION
7919 if (my_e_param > 3) /* allow extended layouts */
7928 ripoffline(-1, rip_footer);
7931 ripoffline(1, rip_header);
7933 #endif /* HAVE_RIPOFFLINE */
7937 #if HAVE_COLOR_CONTENT
7939 palette_file = optarg;
7944 nap_msec = (int) atol(optarg);
7947 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_WIN32)
7954 save_trace = (unsigned) strtol(optarg, 0, 0);
7957 #if HAVE_COLOR_CONTENT
7959 xterm_colors = TRUE;
7968 * If there's no menus (unlikely for ncurses!), then we'll have to set
7969 * tracing on initially, just in case the user wants to test something that
7970 * doesn't involve wGetchar.
7973 /* enable debugging */
7977 if (!isatty(fileno(stdin)))
7979 #endif /* USE_LIBMENU */
7983 /* tell it we're going to play with soft keys */
7984 slk_init(my_e_param);
7988 /* set up null signal catcher so we can see what interrupts to getch do */
7989 signal(SIGUSR1, announce_sig);
7992 /* we must initialize the curses data structure only once */
7996 set_terminal_modes();
7999 /* tests, in general, will want these modes */
8000 UseColors = (bool) (monochrome ? FALSE : has_colors());
8004 #ifdef NCURSES_VERSION_PATCH
8005 MaxColors = COLORS; /* was > 16 ? 16 : COLORS */
8006 #if HAVE_USE_DEFAULT_COLORS
8007 if (default_colors) {
8008 use_default_colors();
8011 #if HAVE_ASSUME_DEFAULT_COLORS
8013 assume_default_colors(default_fg, default_bg);
8016 #else /* normal SVr4 curses */
8017 MaxColors = COLORS; /* was > 8 ? 8 : COLORS */
8019 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
8021 #if HAVE_COLOR_CONTENT
8022 if (can_change_color()) {
8023 init_all_colors(xterm_colors, palette_file);
8029 * Return to terminal mode, so we're guaranteed of being able to
8030 * select terminal commands even if the capabilities are wrong.
8034 #if HAVE_CURSES_VERSION
8035 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
8036 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
8037 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
8038 NCURSES_VERSION_MAJOR,
8039 NCURSES_VERSION_MINOR,
8040 NCURSES_VERSION_PATCH);
8042 (void) puts("Welcome to ncurses. Press ? for help.");
8047 ExitProgram(EXIT_SUCCESS);
8050 /* ncurses.c ends here */