1 /****************************************************************************
2 * Copyright 2018-2019,2020 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
29 /****************************************************************************
32 ncurses.c --- ncurses library exerciser
38 An interactive test module for the ncurses library.
41 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
42 Thomas E. Dickey (beginning revision 1.27 in 1996).
44 $Id: ncurses.c,v 1.523 2020/08/29 16:22:03 juergen Exp $
46 ***************************************************************************/
48 #include <test.priv.h>
51 #undef mvwdelch /* HPUX 11.23 macro will not compile */
55 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
59 #include <sys/select.h>
75 #ifdef NCURSES_VERSION
77 #define NCURSES_CONST_PARAM const void
80 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
110 #ifdef CURSES_WACS_ARRAY
111 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
112 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
113 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
114 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
115 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
116 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
117 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
124 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
125 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
126 #define reset_wchars(state) init_mb(state)
127 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
128 #define count_wchars(src, len, state) wcstombs(0, src, len)
129 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
130 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
135 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
136 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
137 #define reset_mbytes(state) init_mb(state)
138 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
139 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
140 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
141 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
145 #define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real)
147 #define P(string) printw("%s\n", string)
149 #define BLANK ' ' /* this is the background character */
151 static int MaxColors; /* the actual number of colors we'll use */
152 static int MinColors; /* the minimum color code */
153 static bool UseColors; /* true if we use colors */
156 static int max_pairs; /* ...and the number of color pairs */
158 #if HAVE_COLOR_CONTENT
161 NCURSES_COLOR_T green;
162 NCURSES_COLOR_T blue;
165 static RGB_DATA *all_colors;
168 static void main_menu(bool);
169 static void failed(const char *s) GCC_NORETURN;
172 failed(const char *s)
176 ExitProgram(EXIT_FAILURE);
192 isQuit(int c, bool escape)
194 return ((c) == QUIT || (escape && ((c) == ESCAPE)));
196 #define case_QUIT QUIT: case ESCAPE
198 /* Common function to allow ^T to toggle trace-mode in the middle of a test
199 * so that trace-files can be made smaller.
202 wGetchar(WINDOW *win)
206 while ((c = wgetch(win)) == CTRL('T')) {
208 save_trace = _nc_tracing;
209 Trace(("TOGGLE-TRACING OFF"));
212 _nc_tracing = save_trace;
214 curses_trace(_nc_tracing);
216 Trace(("TOGGLE-TRACING ON"));
223 #define Getchar() wGetchar(stdscr)
226 /* replaces wgetnstr(), since we want to be able to edit values */
228 wGetstring(WINDOW *win, char *buffer, int limit)
235 (void) wattrset(win, A_REVERSE);
237 x = (int) strlen(buffer);
240 if (x > (int) strlen(buffer))
241 x = (int) strlen(buffer);
243 wprintw(win, "%-*s", limit, buffer);
244 wmove(win, y0, x0 + x);
245 switch (ch = wGetchar(win)) {
258 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
276 if (!isprint(ch) || ch >= KEY_MIN) {
278 } else if ((int) strlen(buffer) < limit) {
280 for (j = (int) strlen(buffer) + 1; j > x; --j) {
281 buffer[j] = buffer[j - 1];
283 buffer[x++] = (char) ch;
290 wattroff(win, A_REVERSE);
296 #if USE_WIDEC_SUPPORT
298 fullwidth_digit(int ch)
300 return (wchar_t) (ch + 0xff10 - '0');
304 make_fullwidth_text(wchar_t *target, const char *source)
307 while ((ch = *source++) != 0) {
308 *target++ = fullwidth_digit(ch);
314 make_narrow_text(wchar_t *target, const char *source)
317 while ((ch = *source++) != 0) {
318 *target++ = (wchar_t) ch;
325 make_fullwidth_digit(cchar_t *target, int digit)
329 source[0] = fullwidth_digit(digit + '0');
331 setcchar(target, source, A_NORMAL, 0, 0);
336 wGet_wchar(WINDOW *win, wint_t *result)
340 while ((c = wget_wch(win, result)) == CTRL('T')) {
342 save_trace = _nc_tracing;
343 Trace(("TOGGLE-TRACING OFF"));
346 _nc_tracing = save_trace;
348 curses_trace(_nc_tracing);
350 Trace(("TOGGLE-TRACING ON"));
353 c = wget_wch(win, result);
357 #define Get_wchar(result) wGet_wchar(stdscr, result)
359 /* replaces wgetn_wstr(), since we want to be able to edit values */
362 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
371 (void) wattrset(win, A_REVERSE);
373 x = (int) wcslen(buffer);
375 if (x > (int) wcslen(buffer))
376 x = (int) wcslen(buffer);
378 /* clear the "window' */
380 wprintw(win, "%*s", limit, " ");
382 /* write the existing buffer contents */
384 waddnwstr(win, buffer, limit);
386 /* positions the cursor past character 'x' */
388 waddnwstr(win, buffer, x);
390 switch (wGet_wchar(win, &ch)) {
430 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
450 } else if ((int) wcslen(buffer) < limit) {
452 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
453 buffer[j] = buffer[j - 1];
455 buffer[x++] = (wchar_t) ch;
462 wattroff(win, A_REVERSE);
466 #endif /* USE_SOFTKEYS */
468 #endif /* USE_WIDEC_SUPPORT */
474 addstr("Press any key to continue... ");
479 Cannot(const char *what)
481 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
487 ShellOut(bool message)
490 addstr("Shelling out...");
496 IGNORE_RC(system("sh"));
499 addstr("returned from shellout.\n");
503 #ifdef NCURSES_MOUSE_VERSION
505 * This function is the same as _tracemouse(), but we cannot count on that
506 * being available in the non-debug library.
509 mouse_decode(MEVENT const *ep)
511 static char buf[80 + (5 * 10) + (32 * 15)];
513 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
514 "id %2d at (%2d, %2d, %d) state %4lx = {",
515 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
518 if ((ep->bstate & m)==m) { \
519 _nc_STRCAT(buf, s, sizeof(buf)); \
520 _nc_STRCAT(buf, ", ", sizeof(buf)); \
523 SHOW(BUTTON1_RELEASED, "release-1");
524 SHOW(BUTTON1_PRESSED, "press-1");
525 SHOW(BUTTON1_CLICKED, "click-1");
526 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
527 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
528 #if NCURSES_MOUSE_VERSION == 1
529 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
532 SHOW(BUTTON2_RELEASED, "release-2");
533 SHOW(BUTTON2_PRESSED, "press-2");
534 SHOW(BUTTON2_CLICKED, "click-2");
535 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
536 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
537 #if NCURSES_MOUSE_VERSION == 1
538 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
541 SHOW(BUTTON3_RELEASED, "release-3");
542 SHOW(BUTTON3_PRESSED, "press-3");
543 SHOW(BUTTON3_CLICKED, "click-3");
544 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
545 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
546 #if NCURSES_MOUSE_VERSION == 1
547 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
550 SHOW(BUTTON4_RELEASED, "release-4");
551 SHOW(BUTTON4_PRESSED, "press-4");
552 SHOW(BUTTON4_CLICKED, "click-4");
553 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
554 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
555 #if NCURSES_MOUSE_VERSION == 1
556 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
559 #if NCURSES_MOUSE_VERSION == 2
560 SHOW(BUTTON5_RELEASED, "release-5");
561 SHOW(BUTTON5_PRESSED, "press-5");
562 SHOW(BUTTON5_CLICKED, "click-5");
563 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
564 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
567 SHOW(BUTTON_CTRL, "ctrl");
568 SHOW(BUTTON_SHIFT, "shift");
569 SHOW(BUTTON_ALT, "alt");
570 SHOW(ALL_MOUSE_EVENTS, "all-events");
571 SHOW(REPORT_MOUSE_POSITION, "position");
575 if (buf[strlen(buf) - 1] == ' ')
576 buf[strlen(buf) - 2] = '\0';
577 _nc_STRCAT(buf, "}", sizeof(buf));
582 show_mouse(WINDOW *win)
589 outside = !wenclose(win, event.y, event.x);
592 (void) wstandout(win);
593 waddstr(win, "KEY_MOUSE");
594 (void) wstandend(win);
596 waddstr(win, "KEY_MOUSE");
598 wprintw(win, ", %s", mouse_decode(&event));
603 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
608 wmove(win, event.y, event.x);
616 #endif /* NCURSES_MOUSE_VERSION */
618 /****************************************************************************
620 * Character input test
622 ****************************************************************************/
624 #define NUM_GETCH_FLAGS 256
625 typedef bool GetchFlags[NUM_GETCH_FLAGS];
628 setup_getch(WINDOW *win, GetchFlags flags)
630 keypad(win, flags['k']); /* should be redundant, but for testing */
631 meta(win, flags['m']); /* force this to a known state */
639 init_getch(WINDOW *win, GetchFlags flags, int delay)
641 memset(flags, FALSE, NUM_GETCH_FLAGS);
642 flags[UChar('k')] = (win == stdscr);
643 flags[UChar('m')] = TRUE;
644 flags[UChar('t')] = (delay != 0);
646 setup_getch(win, flags);
650 blocking_getch(GetchFlags flags, int delay)
652 return ((delay < 0) && flags['t']);
655 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
658 wgetch_help(WINDOW *win, GetchFlags flags)
660 static const char *help[] =
662 "e -- toggle echo mode"
663 ,"g -- triggers a getstr test"
664 ,"k -- toggle keypad/literal mode"
665 ,"m -- toggle meta (7-bit/8-bit) mode"
668 ,"t -- toggle timeout"
669 ,"w -- create a new window"
671 ,"z -- suspend this process"
675 unsigned chk = ((SIZEOF(help) + 1) / 2);
680 printw("Type any key to see its %s value. Also:\n",
681 flags['k'] ? "keypad" : "literal");
682 for (n = 0; n < SIZEOF(help); ++n) {
683 const char *msg = help[n];
684 int row = 1 + (int) (n % chk);
685 int col = (n >= chk) ? COLS / 2 : 0;
686 int flg = ((strstr(msg, "toggle") != 0)
687 && (flags[UChar(*msg)] != FALSE));
688 if (*msg == '^' && ExitOnEscape())
689 msg = "^[,^q -- quit";
692 MvPrintw(row, col, "%s", msg);
703 wgetch_wrap(WINDOW *win, int first_y)
705 int last_y = getmaxy(win) - 1;
706 int y = getcury(win) + 1;
714 #if defined(KEY_RESIZE) && HAVE_WRESIZE
720 static WINSTACK *winstack = 0;
721 static unsigned len_winstack = 0;
734 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
736 unsigned need = (level + 1) * 2;
738 assert(level < (unsigned) COLS);
742 winstack = typeMalloc(WINSTACK, len_winstack);
743 } else if (need >= len_winstack) {
745 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
748 failed("remember_boxes");
749 winstack[level].text = txt_win;
750 winstack[level].frame = box_win;
753 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
757 /* this chunk is now done in resize_term() */
764 #define slk_repaint() /* nothing */
767 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
769 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
770 * Resize both and paint the box in the parent.
773 resize_boxes(unsigned level, WINDOW *win)
777 int high = LINES - base;
781 wnoutrefresh(stdscr);
785 for (n = 0; n < level; ++n) {
786 wresize(winstack[n].frame, high, wide);
787 wresize(winstack[n].text, high - 2, wide - 2);
790 werase(winstack[n].text);
791 box(winstack[n].frame, 0, 0);
792 wnoutrefresh(winstack[n].frame);
793 wprintw(winstack[n].text,
795 getmaxy(winstack[n].text),
796 getmaxx(winstack[n].text));
797 wnoutrefresh(winstack[n].text);
798 if (winstack[n].text == win)
803 #endif /* resize_boxes */
805 #define forget_boxes() /* nothing */
806 #define remember_boxes(level,text,frame) /* nothing */
810 * Return-code is OK/ERR or a keyname.
815 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
819 wgetch_test(unsigned level, WINDOW *win, int delay)
822 int first_y, first_x;
826 init_getch(win, flags, delay);
827 notimeout(win, FALSE);
828 wtimeout(win, delay);
829 getyx(win, first_y, first_x);
831 wgetch_help(win, flags);
832 wsetscrreg(win, first_y, getmaxy(win) - 1);
838 while ((c = wGetchar(win)) == ERR) {
840 if (blocking_getch(flags, delay)) {
841 (void) wprintw(win, "%05d: input error", incount);
844 (void) wprintw(win, "%05d: input timed out", incount);
846 wgetch_wrap(win, first_y);
848 if (c == ERR && blocking_getch(flags, delay)) {
850 wgetch_wrap(win, first_y);
851 } else if (isQuit(c, ExitOnEscape())) {
853 } else if (c == 'e') {
854 flags[UChar('e')] = !flags[UChar('e')];
855 setup_getch(win, flags);
856 wgetch_help(win, flags);
857 } else if (c == 'g') {
858 waddstr(win, "getstr test: ");
860 c = wgetnstr(win, buf, sizeof(buf) - 1);
862 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
863 (int) strlen(buf), buf,
866 wgetch_wrap(win, first_y);
867 } else if (c == 'k') {
868 flags[UChar('k')] = !flags[UChar('k')];
869 setup_getch(win, flags);
870 wgetch_help(win, flags);
871 } else if (c == 'm') {
872 flags[UChar('m')] = !flags[UChar('m')];
873 setup_getch(win, flags);
874 wgetch_help(win, flags);
875 } else if (c == 's') {
877 } else if (c == 't') {
878 notimeout(win, flags[UChar('t')]);
879 flags[UChar('t')] = !flags[UChar('t')];
880 wgetch_help(win, flags);
881 } else if (c == 'w') {
882 int high = getmaxy(win) - 1 - first_y + 1;
883 int wide = getmaxx(win) - first_x;
885 int new_y = first_y + getbegy(win);
886 int new_x = first_x + getbegx(win);
888 getyx(win, old_y, old_x);
889 if (high > 2 && wide > 2) {
890 WINDOW *wb = newwin(high, wide, new_y, new_x);
891 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
896 remember_boxes(level, wi, wb);
897 wgetch_test(level + 1, wi, delay);
901 wgetch_help(win, flags);
902 wmove(win, old_y, old_x);
908 } else if (c == 'z') {
909 kill(getpid(), SIGTSTP);
912 wprintw(win, "Key pressed: %04o ", c);
913 #ifdef NCURSES_MOUSE_VERSION
914 if (c == KEY_MOUSE) {
917 #endif /* NCURSES_MOUSE_VERSION */
919 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
920 if (c == KEY_RESIZE) {
921 resize_boxes(level, win);
924 (void) waddstr(win, keyname(c));
925 } else if (c >= 0x80) {
926 unsigned c2 = (unsigned) c;
927 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
928 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
932 (void) wprintw(win, "%c", UChar(c));
933 else if (c2 != UChar(c))
934 (void) wprintw(win, "M-%s", unctrl(c2));
936 (void) wprintw(win, "%s", unctrl(c2));
937 waddstr(win, " (high-half character)");
940 (void) wprintw(win, "%c (ASCII printable character)", c);
942 (void) wprintw(win, "%s (ASCII control character)",
945 wgetch_wrap(win, first_y);
952 init_getch(win, flags, delay);
956 begin_getch_test(void)
963 #ifdef NCURSES_MOUSE_VERSION
964 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
967 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
969 getnstr(buf, sizeof(buf) - 1);
973 if (isdigit(UChar(buf[0]))) {
974 delay = atoi(buf) * 100;
984 finish_getch_test(void)
986 #ifdef NCURSES_MOUSE_VERSION
987 mousemask(0, (mmask_t *) 0);
996 getch_test(bool recur GCC_UNUSED)
998 int delay = begin_getch_test();
1001 wgetch_test(0, stdscr, delay);
1003 finish_getch_test();
1008 #if USE_WIDEC_SUPPORT
1010 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1011 * Resize both and paint the box in the parent.
1013 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1015 resize_wide_boxes(unsigned level, WINDOW *win)
1019 int high = LINES - base;
1023 wnoutrefresh(stdscr);
1027 for (n = 0; n < level; ++n) {
1028 wresize(winstack[n].frame, high, wide);
1029 wresize(winstack[n].text, high - 2, wide - 2);
1032 werase(winstack[n].text);
1033 box_set(winstack[n].frame, 0, 0);
1034 wnoutrefresh(winstack[n].frame);
1035 wprintw(winstack[n].text,
1037 getmaxy(winstack[n].text),
1038 getmaxx(winstack[n].text));
1039 wnoutrefresh(winstack[n].text);
1040 if (winstack[n].text == win)
1045 #endif /* KEY_RESIZE */
1048 wcstos(const wchar_t *src)
1052 const wchar_t *tmp = src;
1053 #ifndef state_unused
1057 reset_wchars(state);
1058 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1059 unsigned have = (unsigned) need;
1060 if ((result = typeCalloc(char, have + 1)) != 0) {
1062 if (trans_wchars(result, tmp, have, &state) != have) {
1074 wget_wch_test(unsigned level, WINDOW *win, int delay)
1076 wchar_t wchar_buf[BUFSIZ];
1077 wint_t wint_buf[BUFSIZ];
1078 int first_y, first_x;
1084 init_getch(win, flags, delay);
1085 notimeout(win, FALSE);
1086 wtimeout(win, delay);
1087 getyx(win, first_y, first_x);
1089 wgetch_help(win, flags);
1090 wsetscrreg(win, first_y, getmaxy(win) - 1);
1091 scrollok(win, TRUE);
1096 while ((code = wGet_wchar(win, &c)) == ERR) {
1098 if (blocking_getch(flags, delay)) {
1099 (void) wprintw(win, "%05d: input error", incount);
1102 (void) wprintw(win, "%05d: input timed out", incount);
1104 wgetch_wrap(win, first_y);
1106 if (code == ERR && blocking_getch(flags, delay)) {
1107 wprintw(win, "ERR");
1108 wgetch_wrap(win, first_y);
1109 } else if (isQuit((int) c, ExitOnEscape())) {
1111 } else if (c == 'e') {
1112 flags[UChar('e')] = !flags[UChar('e')];
1113 setup_getch(win, flags);
1114 wgetch_help(win, flags);
1115 } else if (c == 'g') {
1116 waddstr(win, "getstr test: ");
1118 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1121 wprintw(win, "wgetn_wstr returns an error.");
1124 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1127 if ((temp = wcstos(wchar_buf)) != 0) {
1128 wprintw(win, "I saw %d characters:\n\t`%s'.",
1129 (int) wcslen(wchar_buf), temp);
1132 wprintw(win, "I saw %d characters (cannot convert).",
1133 (int) wcslen(wchar_buf));
1137 wgetch_wrap(win, first_y);
1138 } else if (c == 'k') {
1139 flags[UChar('k')] = !flags[UChar('k')];
1140 setup_getch(win, flags);
1141 wgetch_help(win, flags);
1142 } else if (c == 'm') {
1143 flags[UChar('m')] = !flags[UChar('m')];
1144 setup_getch(win, flags);
1145 wgetch_help(win, flags);
1146 } else if (c == 's') {
1148 } else if (c == 't') {
1149 notimeout(win, flags[UChar('t')]);
1150 flags[UChar('t')] = !flags[UChar('t')];
1151 wgetch_help(win, flags);
1152 } else if (c == 'w') {
1153 int high = getmaxy(win) - 1 - first_y + 1;
1154 int wide = getmaxx(win) - first_x;
1156 int new_y = first_y + getbegy(win);
1157 int new_x = first_x + getbegx(win);
1159 getyx(win, old_y, old_x);
1160 if (high > 2 && wide > 2) {
1161 WINDOW *wb = newwin(high, wide, new_y, new_x);
1162 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1167 remember_boxes(level, wi, wb);
1168 wget_wch_test(level + 1, wi, delay);
1172 wgetch_help(win, flags);
1173 wmove(win, old_y, old_x);
1178 } else if (c == 'z') {
1179 kill(getpid(), SIGTSTP);
1182 wprintw(win, "Key pressed: %04o ", (int) c);
1183 #ifdef NCURSES_MOUSE_VERSION
1184 if (c == KEY_MOUSE) {
1187 #endif /* NCURSES_MOUSE_VERSION */
1188 if (code == KEY_CODE_YES) {
1189 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1190 if (c == KEY_RESIZE) {
1191 resize_wide_boxes(level, win);
1194 (void) waddstr(win, keyname((wchar_t) c));
1196 (void) waddstr(win, key_name((wchar_t) c));
1197 if (c < 256 && iscntrl(c)) {
1198 (void) wprintw(win, " (control character)");
1200 (void) wprintw(win, " = %#x (printable character)",
1204 wgetch_wrap(win, first_y);
1211 init_getch(win, flags, delay);
1215 x_getch_test(bool recur GCC_UNUSED)
1217 int delay = begin_getch_test();
1220 wget_wch_test(0, stdscr, delay);
1222 finish_getch_test();
1228 /****************************************************************************
1230 * Character attributes test
1232 ****************************************************************************/
1234 #if HAVE_SETUPTERM || HAVE_TGETENT
1235 #define get_ncv() TIGETNUM("ncv","NC")
1236 #define get_xmc() TIGETNUM("xmc","sg")
1238 #define get_ncv() -1
1239 #define get_xmc() -1
1246 static int first = TRUE;
1247 static chtype result = 0;
1253 char *area_pointer = parsed;
1255 tgetent(buffer, getenv("TERM"));
1258 if (TIGETSTR("smso", "so"))
1259 result |= A_STANDOUT;
1260 if (TIGETSTR("smul", "us"))
1261 result |= A_UNDERLINE;
1262 if (TIGETSTR("rev", "mr"))
1263 result |= A_REVERSE;
1264 if (TIGETSTR("blink", "mb"))
1266 if (TIGETSTR("dim", "mh"))
1268 if (TIGETSTR("bold", "md"))
1270 if (TIGETSTR("smacs", "ac"))
1271 result |= A_ALTCHARSET;
1277 #define termattrs() my_termattrs()
1280 #define ATTRSTRING_1ST 32 /* ' ' */
1281 #define ATTRSTRING_END 126 /* '~' */
1283 #define COLS_PRE_ATTRS 5
1284 #define COLS_AFT_ATTRS 15
1285 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1286 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1287 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1289 static char attr_test_string[MAX_ATTRSTRING + 1];
1292 attr_legend(WINDOW *helpwin)
1297 MvWPrintw(helpwin, row++, col,
1299 MvWPrintw(helpwin, row++, col,
1302 MvWPrintw(helpwin, row++, col,
1303 "Modify the test strings:");
1304 MvWPrintw(helpwin, row++, col,
1305 " A digit sets gaps on each side of displayed attributes");
1306 MvWPrintw(helpwin, row++, col,
1307 " </> shifts the text left/right. ");
1309 MvWPrintw(helpwin, row++, col,
1312 MvWPrintw(helpwin, row++, col,
1313 " f/F/b/B toggle foreground/background background color");
1314 MvWPrintw(helpwin, row++, col,
1315 " t/T toggle text/background color attribute");
1317 MvWPrintw(helpwin, row++, col,
1318 " a/A toggle ACS (alternate character set) mapping");
1319 MvWPrintw(helpwin, row, col,
1320 " v/V toggle video attribute to combine with each line");
1321 #if USE_WIDEC_SUPPORT
1322 MvWPrintw(helpwin, row, col,
1323 " w/W toggle normal/wide (double-width) test-characters");
1328 show_color_attr(int fg, int bg, int tx)
1331 printw(" Colors (fg %d, bg %d", fg, bg);
1333 printw(", text %d", tx);
1339 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1346 *fg = (NCURSES_COLOR_T) (*fg + 1);
1349 *fg = (NCURSES_COLOR_T) (*fg - 1);
1352 *bg = (NCURSES_COLOR_T) (*bg + 1);
1355 *bg = (NCURSES_COLOR_T) (*bg - 1);
1358 *tx = (NCURSES_COLOR_T) (*tx + 1);
1361 *tx = (NCURSES_COLOR_T) (*tx - 1);
1369 *fg = (NCURSES_COLOR_T) MinColors;
1370 if (*fg < MinColors)
1371 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1373 *bg = (NCURSES_COLOR_T) MinColors;
1374 if (*bg < MinColors)
1375 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1379 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1388 adjust_attr_string(int adjust)
1390 char save = attr_test_string[0];
1391 int first = ((int) UChar(save)) + adjust;
1393 if (first >= ATTRSTRING_1ST) {
1396 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1397 if (k > ATTRSTRING_END)
1399 attr_test_string[j] = (char) k;
1400 if (((k + 1 - first) % 5) == 0) {
1401 if (++j >= MAX_ATTRSTRING)
1403 attr_test_string[j] = ' ';
1406 if ((LEN_ATTRSTRING - j) > 5) {
1407 attr_test_string[0] = save;
1408 adjust_attr_string(adjust - 1);
1410 while (j < MAX_ATTRSTRING)
1411 attr_test_string[j++] = ' ';
1412 attr_test_string[j] = '\0';
1418 * Prefer the right-end of the string for starting, since that maps to the
1419 * VT100 line-drawing.
1422 default_attr_string(void)
1424 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1425 result += (LEN_ATTRSTRING / 5);
1426 if (result < ATTRSTRING_1ST)
1427 result = ATTRSTRING_1ST;
1432 init_attr_string(void)
1434 attr_test_string[0] = (char) default_attr_string();
1435 adjust_attr_string(0);
1439 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1441 int ncv = get_ncv();
1442 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1445 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1446 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1447 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1449 printw("%*s", skip, " ");
1451 * Just for testing, write text using the alternate character set one
1452 * character at a time (to pass its rendition directly), and use the
1453 * string operation for the other attributes.
1457 if (attr & A_ALTCHARSET) {
1460 for (s = attr_test_string; *s != '\0'; ++s) {
1461 chtype ch = UChar(*s);
1462 (void) waddch(win, ch | attr);
1465 (void) wattrset(win, AttrArg(attr, 0));
1466 (void) waddstr(win, attr_test_string);
1467 (void) wattroff(win, (int) attr);
1470 printw("%*s", skip, " ");
1471 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1472 if (test != A_NORMAL) {
1473 if (!(termattrs() & test)) {
1476 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1477 static const chtype table[] =
1496 for (n = 0; n < SIZEOF(table); n++) {
1497 if ((table[n] & attr) != 0
1498 && ((1 << n) & ncv) != 0) {
1506 if ((termattrs() & test) != test) {
1516 NCURSES_CONST char *name;
1519 static const ATTR_TBL attrs_to_test[] = {
1520 { A_STANDOUT, "STANDOUT" },
1521 { A_REVERSE, "REVERSE" },
1523 { A_UNDERLINE, "UNDERLINE" },
1525 { A_BLINK, "BLINK" },
1526 { A_PROTECT, "PROTECT" },
1528 { A_INVIS, "INVISIBLE" },
1531 { A_ITALIC, "ITALIC" },
1533 { A_NORMAL, "NORMAL" },
1538 init_attr_list(ATTR_TBL * target, attr_t attrs)
1540 unsigned result = 0;
1543 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1544 attr_t test = attrs_to_test[n].attr;
1545 if (test == A_NORMAL || (test & attrs) != 0) {
1546 target[result++] = attrs_to_test[n];
1552 #if USE_WIDEC_SUPPORT
1555 NCURSES_CONST char *name;
1558 static const W_ATTR_TBL w_attrs_to_test[] = {
1559 { WA_STANDOUT, "STANDOUT" },
1560 { WA_REVERSE, "REVERSE" },
1561 { WA_BOLD, "BOLD" },
1562 { WA_UNDERLINE, "UNDERLINE" },
1564 { WA_BLINK, "BLINK" },
1565 { WA_PROTECT, "PROTECT" },
1567 { WA_INVIS, "INVISIBLE" },
1570 { WA_ITALIC, "ITALIC" },
1572 { WA_NORMAL, "NORMAL" },
1577 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1579 unsigned result = 0;
1582 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1583 attr_t test = w_attrs_to_test[n].attr;
1584 if (test == WA_NORMAL || (test & attrs) != 0) {
1585 target[result++] = w_attrs_to_test[n];
1593 attr_getc(int *skip,
1594 NCURSES_COLOR_T *fg,
1595 NCURSES_COLOR_T *bg,
1596 NCURSES_COLOR_T *tx,
1609 if (ch < 256 && isdigit(ch)) {
1617 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1619 attr_legend(helpwin);
1642 adjust_attr_string(-1);
1645 adjust_attr_string(1);
1651 error = cycle_color_attr(ch, fg, bg, tx);
1660 attr_test(bool recur GCC_UNUSED)
1661 /* test text attributes */
1664 int skip = get_xmc();
1665 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1666 NCURSES_COLOR_T bg = COLOR_BLACK;
1667 NCURSES_COLOR_T tx = -1;
1669 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1670 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1671 unsigned my_size = init_attr_list(my_list, termattrs());
1676 for (j = 0; j < my_size; ++j) {
1677 my_wins[j] = subwin(stdscr,
1679 2 + (int) (2 * j), COL_ATTRSTRING);
1680 scrollok(my_wins[j], FALSE);
1686 n = skip; /* make it easy */
1692 chtype normal = A_NORMAL | BLANK;
1693 chtype extras = (chtype) ac;
1696 NCURSES_PAIRS_T pair = 0;
1697 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1699 if (init_pair(pair, fg, bg) == ERR) {
1702 normal |= (chtype) COLOR_PAIR(pair);
1707 if (init_pair(pair, tx, bg) == ERR) {
1710 extras |= (chtype) COLOR_PAIR(pair);
1720 MvAddStr(0, 20, "Character attribute test display");
1722 for (j = 0; j < my_size; ++j) {
1723 bool arrow = (j == k);
1724 row = show_attr(my_wins[j], row, n, arrow,
1732 MvPrintw(row, COLS_PRE_ATTRS,
1733 "This terminal does %shave the magic-cookie glitch",
1734 get_xmc() > -1 ? "" : "not ");
1735 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1736 show_color_attr(fg, bg, tx);
1737 printw(" ACS (%d)", ac != 0);
1740 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1742 bkgdset(A_NORMAL | BLANK);
1747 Cannot("does not support video attributes.");
1752 #if USE_WIDEC_SUPPORT
1753 static bool use_fullwidth;
1754 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1756 #define FULL_LO 0xff00
1757 #define FULL_HI 0xff5e
1758 #define HALF_LO 0x20
1760 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1761 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1762 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1765 * Returns an ASCII code in [32..126]
1768 normal_wchar(int ch)
1770 wchar_t result = (wchar_t) ch;
1771 if (isFullWidth(ch))
1772 result = ToNormalWidth(ch);
1777 * Returns either an ASCII code in in [32..126] or full-width in
1778 * [0xff00..0xff5e], according to use_fullwidth setting.
1781 target_wchar(int ch)
1783 wchar_t result = (wchar_t) ch;
1784 if (use_fullwidth) {
1785 if (!isFullWidth(ch))
1786 result = ToFullWidth(ch);
1788 if (isFullWidth(ch))
1789 result = ToNormalWidth(ch);
1795 wide_adjust_attr_string(int adjust)
1797 wchar_t save = wide_attr_test_string[0];
1798 int first = ((int) normal_wchar(save)) + adjust;
1800 if (first >= ATTRSTRING_1ST) {
1803 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1804 if (k > ATTRSTRING_END)
1806 wide_attr_test_string[j] = target_wchar(k);
1807 if (((k + 1 - first) % 5) == 0) {
1808 if (++j >= MAX_ATTRSTRING)
1810 wide_attr_test_string[j] = ' ';
1813 if ((LEN_ATTRSTRING - j) > 5) {
1814 wide_attr_test_string[0] = save;
1815 wide_adjust_attr_string(adjust - 1);
1817 while (j < MAX_ATTRSTRING)
1818 wide_attr_test_string[j++] = ' ';
1819 wide_attr_test_string[j] = '\0';
1825 wide_init_attr_string(void)
1827 use_fullwidth = FALSE;
1828 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1829 wide_adjust_attr_string(0);
1833 set_wide_background(NCURSES_PAIRS_T pair)
1840 setcchar(&normal, blank, A_NORMAL, pair, 0);
1846 get_wide_background(void)
1848 attr_t result = WA_NORMAL;
1851 NCURSES_PAIRS_T pair;
1853 memset(&ch, 0, sizeof(ch));
1854 if (getbkgrnd(&ch) != ERR) {
1855 wchar_t wch[CCHARW_MAX];
1857 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1865 wide_show_attr(WINDOW *win,
1870 NCURSES_PAIRS_T pair,
1873 int ncv = get_ncv();
1874 attr_t test = attr & ~WA_ALTCHARSET;
1877 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1878 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1879 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1881 printw("%*s", skip, " ");
1884 * Just for testing, write text using the alternate character set one
1885 * character at a time (to pass its rendition directly), and use the
1886 * string operation for the other attributes.
1890 if (attr & WA_ALTCHARSET) {
1894 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1898 setcchar(&ch, fill, attr, pair, 0);
1899 (void) wadd_wch(win, &ch);
1902 attr_t old_attr = 0;
1903 NCURSES_PAIRS_T old_pair = 0;
1905 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1906 (void) wattr_set(win, attr, pair, 0);
1907 (void) waddwstr(win, wide_attr_test_string);
1908 (void) wattr_set(win, old_attr, old_pair, 0);
1911 printw("%*s", skip, " ");
1912 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1913 if (test != A_NORMAL) {
1914 if (!(term_attrs() & test)) {
1917 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1918 static const attr_t table[] =
1932 for (n = 0; n < SIZEOF(table); n++) {
1933 if ((table[n] & attr) != 0
1934 && ((1 << n) & ncv) != 0) {
1942 if ((term_attrs() & test) != test) {
1951 wide_attr_getc(int *skip,
1952 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1953 NCURSES_COLOR_T *tx, int *ac,
1954 unsigned *kc, unsigned limit)
1964 if (ch < 256 && isdigit(ch)) {
1972 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1973 box_set(helpwin, 0, 0);
1974 attr_legend(helpwin);
1997 use_fullwidth = FALSE;
1998 wide_adjust_attr_string(0);
2001 use_fullwidth = TRUE;
2002 wide_adjust_attr_string(0);
2005 wide_adjust_attr_string(-1);
2008 wide_adjust_attr_string(1);
2014 error = cycle_color_attr(ch, fg, bg, tx);
2023 x_attr_test(bool recur GCC_UNUSED)
2024 /* test text attributes using wide-character calls */
2027 int skip = get_xmc();
2028 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2029 NCURSES_COLOR_T bg = COLOR_BLACK;
2030 NCURSES_COLOR_T tx = -1;
2032 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2033 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2034 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2039 for (j = 0; j < my_size; ++j) {
2040 my_wins[j] = subwin(stdscr,
2042 2 + (int) (2 * j), COL_ATTRSTRING);
2043 scrollok(my_wins[j], FALSE);
2049 n = skip; /* make it easy */
2051 wide_init_attr_string();
2055 NCURSES_PAIRS_T pair = 0;
2056 NCURSES_PAIRS_T extras = 0;
2059 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2062 if (init_pair(pair, fg, bg) == ERR) {
2069 if (init_pair(extras, tx, bg) == ERR) {
2074 set_wide_background(pair);
2077 box_set(stdscr, 0, 0);
2078 MvAddStr(0, 20, "Character attribute test display");
2080 for (j = 0; j < my_size; ++j) {
2081 row = wide_show_attr(my_wins[j], row, n, (j == k),
2089 MvPrintw(row, COLS_PRE_ATTRS,
2090 "This terminal does %shave the magic-cookie glitch",
2091 get_xmc() > -1 ? "" : "not ");
2092 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2093 show_color_attr(fg, bg, tx);
2094 printw(" ACS (%d)", ac != 0);
2097 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2099 set_wide_background(0);
2104 Cannot("does not support extended video attributes.");
2110 /****************************************************************************
2112 * Color support tests
2114 ****************************************************************************/
2116 static NCURSES_CONST char *the_color_names[] =
2137 show_color_name(int y, int x, int color, bool wide, int zoom)
2139 if (move(y, x) != ERR) {
2144 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2148 if ((int) strlen(temp) >= width) {
2150 while ((1 << pwr2) < color)
2152 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2153 width > 4 ? "2^%d" : "^%d", pwr2);
2155 } else if (color >= 8) {
2156 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2158 } else if (color < 0) {
2159 _nc_STRCPY(temp, "default", sizeof(temp));
2161 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2162 "%.*s", 16, the_color_names[color]);
2164 printw("%-*.*s", width, width, temp);
2169 color_legend(WINDOW *helpwin, bool wide)
2174 MvWPrintw(helpwin, row++, col,
2177 MvWPrintw(helpwin, row++, col,
2178 "Use up/down arrow to scroll through the display if it is");
2179 MvWPrintw(helpwin, row++, col,
2180 "longer than one screen. Control/N and Control/P can be used");
2181 MvWPrintw(helpwin, row++, col,
2182 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2183 MvWPrintw(helpwin, row++, col,
2184 "full screen; control/B and control/F can be used here.");
2186 MvWPrintw(helpwin, row++, col,
2188 MvWPrintw(helpwin, row++, col,
2189 " a/A toggle altcharset off/on");
2190 MvWPrintw(helpwin, row++, col,
2191 " b/B toggle bold off/on");
2193 MvWPrintw(helpwin, row++, col,
2194 " c/C cycle used-colors through 8,16,...,COLORS");
2196 MvWPrintw(helpwin, row++, col,
2197 " n/N toggle text/number on/off");
2198 MvWPrintw(helpwin, row++, col,
2199 " r/R toggle reverse on/off");
2200 MvWPrintw(helpwin, row++, col,
2201 " w/W switch width between 4/8 columns");
2202 MvWPrintw(helpwin, row++, col,
2203 " z/Z zoom out (or in)");
2204 #if USE_WIDEC_SUPPORT
2206 MvWPrintw(helpwin, row++, col,
2207 "Wide characters:");
2208 MvWPrintw(helpwin, row, col,
2209 " x/X toggle text between ASCII and wide-character");
2216 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2219 color_cycle(int current, int step)
2221 int result = current;
2227 if ((result * 2) > COLORS) {
2230 while ((result * 2) < current) {
2236 if (current >= COLORS) {
2241 if (result > COLORS)
2247 /* generate a color test pattern */
2249 color_test(bool recur GCC_UNUSED)
2254 int grid_top = top + 3;
2255 int page_size = (LINES - grid_top);
2257 int colors_max = COLORS;
2264 bool opt_acsc = FALSE;
2265 bool opt_bold = FALSE;
2266 bool opt_revs = FALSE;
2267 bool opt_nums = FALSE;
2268 bool opt_wide = FALSE;
2273 Cannot("does not support color.");
2277 numbered = typeCalloc(char, COLS + 1);
2278 done = ((COLS < 16) || (numbered == 0));
2281 * Because the number of colors is usually a power of two, we also use
2282 * a power of two for the number of colors shown per line (to be tidy).
2284 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2289 int zoom_size = (1 << opt_zoom);
2290 int colors_max1 = colors_max / zoom_size;
2291 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2293 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2294 if (colors_max2 <= COLOR_PAIRS) {
2295 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2296 if (pairs_max > limit)
2299 if (pairs_max > COLOR_PAIRS)
2300 pairs_max = COLOR_PAIRS;
2301 if (pairs_max < colors_max1)
2302 pairs_max = colors_max1;
2304 /* this assumes an 80-column line */
2308 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2312 per_row = (col_limit / width);
2314 per_row -= MinColors;
2316 row_limit = (pairs_max + per_row - 1) / per_row;
2319 (void) printw("There are %d color pairs and %d colors",
2321 if (colors_max1 != COLORS)
2322 (void) printw(" (using %d colors)", colors_max1);
2324 (void) addstr(" besides 'default'");
2326 (void) printw(" zoom:%d", opt_zoom);
2329 MvPrintw(top + 1, 0,
2330 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2333 opt_bold ? "on" : "off");
2335 /* show color names/numbers across the top */
2336 for (i = 0; i < per_row; i++) {
2337 show_color_name(top + 2,
2339 (int) i * zoom_size + MinColors,
2344 /* show a grid of colors, with color names/ numbers on the left */
2345 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2346 int row = grid_top + (i / per_row) - base_row;
2347 int col = (i % per_row + 1) * width;
2348 NCURSES_PAIRS_T pair = i;
2350 if ((i / per_row) > row_limit)
2353 #define InxToFG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) % (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2354 #define InxToBG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) / (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2355 if (row >= 0 && move(row, col) != ERR) {
2356 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) InxToFG(i);
2357 NCURSES_COLOR_T bg = (NCURSES_COLOR_T) InxToBG(i);
2359 init_pair(pair, fg, bg);
2360 attron(COLOR_PAIR(pair));
2362 attron(A_ALTCHARSET);
2369 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2373 printw("%-*.*s", width, width, hello);
2374 (void) attrset(A_NORMAL);
2376 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2377 show_color_name(row, 0,
2388 switch (wGetchar(stdscr)) {
2402 colors_max = color_cycle(colors_max, -1);
2405 colors_max = color_cycle(colors_max, 1);
2423 set_color_test(opt_wide, FALSE);
2426 set_color_test(opt_wide, TRUE);
2429 if (opt_zoom <= 0) {
2437 if ((1 << opt_zoom) >= colors_max) {
2446 if (base_row <= 0) {
2454 if (base_row + page_size >= row_limit) {
2463 if (base_row <= 0) {
2466 base_row -= (page_size - 1);
2474 if (base_row + page_size >= row_limit) {
2477 base_row += page_size - 1;
2478 if (base_row + page_size >= row_limit) {
2479 base_row = row_limit - page_size - 1;
2484 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2486 color_legend(helpwin, FALSE);
2504 #if USE_WIDEC_SUPPORT
2506 #if USE_EXTENDED_COLOR
2507 #define InitExtendedPair(p,f,g) init_extended_pair((p),(f),(g))
2508 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), &(p))
2509 #define EXTENDED_PAIRS_T int
2511 #define InitExtendedPair(p,f,g) init_pair((NCURSES_PAIRS_T) (p),(NCURSES_COLOR_T)(f),(NCURSES_COLOR_T)(g))
2512 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), NULL)
2513 #define EXTENDED_PAIRS_T NCURSES_PAIRS_T
2516 /* generate a color test pattern */
2518 x_color_test(bool recur GCC_UNUSED)
2523 int grid_top = top + 3;
2524 int page_size = (LINES - grid_top);
2526 int colors_max = COLORS;
2533 bool opt_acsc = FALSE;
2534 bool opt_bold = FALSE;
2535 bool opt_revs = FALSE;
2536 bool opt_wide = FALSE;
2537 bool opt_nums = FALSE;
2538 bool opt_xchr = FALSE;
2540 wchar_t *buffer = 0;
2544 Cannot("does not support color.");
2547 numbered = typeCalloc(char, COLS + 1);
2548 buffer = typeCalloc(wchar_t, COLS + 1);
2549 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2552 * Because the number of colors is usually a power of two, we also use
2553 * a power of two for the number of colors shown per line (to be tidy).
2555 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2560 int zoom_size = (1 << opt_zoom);
2561 int colors_max1 = colors_max / zoom_size;
2562 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2564 pairs_max = ((unsigned) (-1)) / 2;
2565 if (colors_max2 <= COLOR_PAIRS) {
2566 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2567 if (pairs_max > limit)
2570 if (pairs_max > COLOR_PAIRS)
2571 pairs_max = COLOR_PAIRS;
2572 if (pairs_max < colors_max1)
2573 pairs_max = colors_max1;
2578 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2582 per_row = (col_limit / width);
2584 per_row -= MinColors;
2587 make_fullwidth_text(buffer, hello);
2591 make_narrow_text(buffer, hello);
2594 row_limit = (pairs_max + per_row - 1) / per_row;
2597 (void) printw("There are %d color pairs and %d colors",
2599 if (colors_max1 != COLORS)
2600 (void) printw(" (using %d colors)", colors_max1);
2602 (void) addstr(" besides 'default'");
2604 (void) printw(" zoom:%d", opt_zoom);
2607 MvPrintw(top + 1, 0,
2608 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2611 opt_bold ? "on" : "off");
2613 /* show color names/numbers across the top */
2614 for (i = 0; i < per_row; i++) {
2615 show_color_name(top + 2,
2616 ((int) i + 1) * width,
2617 (int) i * zoom_size + MinColors,
2622 /* show a grid of colors, with color names/ numbers on the left */
2623 for (i = (base_row * per_row); i < pairs_max; i++) {
2624 int row = grid_top + ((int) i / per_row) - base_row;
2625 int col = ((int) i % per_row + 1) * width;
2628 if ((i / per_row) > row_limit)
2631 if (row >= 0 && move(row, col) != ERR) {
2632 InitExtendedPair(pair, InxToFG(i), InxToBG(i));
2633 (void) ExtendedColorSet(pair);
2635 attr_on(WA_ALTCHARSET, NULL);
2637 attr_on(WA_BOLD, NULL);
2639 attr_on(WA_REVERSE, NULL);
2642 _nc_SPRINTF(numbered,
2643 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2644 "{%02X}", (unsigned) i);
2646 make_fullwidth_text(buffer, numbered);
2648 make_narrow_text(buffer, numbered);
2651 addnwstr(buffer, width);
2652 (void) attr_set(A_NORMAL, 0, NULL);
2654 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2655 show_color_name(row, 0,
2666 switch (wGetchar(stdscr)) {
2680 colors_max = color_cycle(colors_max, -1);
2683 colors_max = color_cycle(colors_max, 1);
2701 set_color_test(opt_wide, FALSE);
2704 set_color_test(opt_wide, TRUE);
2713 if (opt_zoom <= 0) {
2721 if ((1 << opt_zoom) >= colors_max) {
2730 if (base_row <= 0) {
2738 if (base_row + page_size >= row_limit) {
2747 if (base_row <= 0) {
2750 base_row -= (page_size - 1);
2758 if (base_row + page_size >= row_limit) {
2761 base_row += page_size - 1;
2762 if (base_row + page_size >= row_limit) {
2763 base_row = row_limit - page_size - 1;
2768 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2770 color_legend(helpwin, TRUE);
2788 #endif /* USE_WIDEC_SUPPORT */
2790 #if HAVE_COLOR_CONTENT
2792 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2794 NCURSES_COLOR_T red, green, blue;
2796 color_content(current, &red, &green, &blue);
2800 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2803 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2806 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2810 if (init_color(current, red, green, blue) == ERR)
2815 reset_all_colors(void)
2819 for (c = 0; c < COLORS; ++c)
2822 all_colors[c].green,
2823 all_colors[c].blue);
2826 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2827 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2828 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2831 init_all_colors(bool xterm_colors, char *palette_file)
2834 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2836 failed("all_colors");
2837 for (cp = 0; cp < MaxColors; ++cp) {
2839 &all_colors[cp].red,
2840 &all_colors[cp].green,
2841 &all_colors[cp].blue);
2843 /* xterm and compatible terminals can read results of an OSC string
2844 * asking for the current color palette.
2848 char result[BUFSIZ];
2850 unsigned check_r, check_g, check_b;
2855 for (n = 0; n < MaxColors; ++n) {
2858 fprintf(stderr, "\033]4;%d;?\007", n);
2859 got = (int) read(0, result, sizeof(result) - 1);
2863 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2869 all_colors[n].red = DecodeRGB(check_r);
2870 all_colors[n].green = DecodeRGB(check_g);
2871 all_colors[n].blue = DecodeRGB(check_b);
2878 if (palette_file != 0) {
2879 FILE *fp = fopen(palette_file, "r");
2881 char buffer[BUFSIZ];
2882 int red, green, blue;
2885 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2886 if (sscanf(buffer, "scale:%d", &c) == 1) {
2888 } else if (sscanf(buffer, "%d:%d %d %d",
2897 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2898 all_colors[c].red = Scaled(red);
2899 all_colors[c].green = Scaled(green);
2900 all_colors[c].blue = Scaled(blue);
2908 #define scaled_rgb(n) ((255 * (n)) / 1000)
2911 color_edit(bool recur GCC_UNUSED)
2912 /* display the color test pattern, without trying to edit colors */
2916 int this_c, value, field;
2922 Cannot("does not support color.");
2924 } else if (!can_change_color()) {
2925 Cannot("has hardwired color values.");
2938 page_size = (LINES - 6);
2941 for (i = 0; i < MaxColors; i++)
2942 init_pair((NCURSES_PAIRS_T) i,
2943 (NCURSES_COLOR_T) COLOR_WHITE,
2944 (NCURSES_COLOR_T) i);
2946 MvPrintw(LINES - 2, 0, "Number: %d", value);
2949 NCURSES_COLOR_T red, green, blue;
2952 MvAddStr(0, 20, "Color RGB Value Editing");
2955 for (i = (NCURSES_COLOR_T) top_color;
2956 (i - top_color < page_size)
2957 && (i < MaxColors); i++) {
2960 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2961 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2962 (i == current ? '>' : ' '),
2963 (i < (int) SIZEOF(the_color_names)
2964 ? the_color_names[i] : numeric));
2965 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2967 (void) attrset(A_NORMAL);
2969 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2971 if (current == i && field == 0)
2973 printw("%04d", (int) red);
2974 if (current == i && field == 0)
2975 (void) attrset(A_NORMAL);
2977 if (current == i && field == 1)
2979 printw("%04d", (int) green);
2980 if (current == i && field == 1)
2981 (void) attrset(A_NORMAL);
2983 if (current == i && field == 2)
2985 printw("%04d", (int) blue);
2986 if (current == i && field == 2)
2987 (void) attrset(A_NORMAL);
2988 (void) attrset(A_NORMAL);
2989 printw(" ( %3d %3d %3d )",
2990 (int) scaled_rgb(red),
2991 (int) scaled_rgb(green),
2992 (int) scaled_rgb(blue));
2995 MvAddStr(LINES - 3, 0,
2996 "Use up/down to select a color, left/right to change fields.");
2997 MvAddStr(LINES - 2, 0,
2998 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
3000 move(2 + current - top_color, 0);
3004 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
3026 current -= (page_size - 1);
3033 if (current < (MaxColors - 1))
3034 current += (page_size - 1);
3041 current = (current == 0 ? (MaxColors - 1) : current - 1);
3046 current = (current == (MaxColors - 1) ? 0 : current + 1);
3051 field = (field == 2 ? 0 : field + 1);
3056 field = (field == 0 ? 2 : field - 1);
3069 value = value * 10 + (this_c - '0');
3073 change_color((NCURSES_PAIRS_T) current, field, value, 1);
3077 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
3081 change_color((NCURSES_PAIRS_T) current, field, value, 0);
3086 P(" RGB Value Editing Help");
3088 P("You are in the RGB value editor. Use the arrow keys to select one of");
3089 P("the fields in one of the RGB triples of the current colors; the one");
3090 P("currently selected will be reverse-video highlighted.");
3092 P("To change a field, enter the digits of the new value; they are echoed");
3093 P("as entered. Finish by typing `='. The change will take effect instantly.");
3094 P("To increment or decrement a value, use the same procedure, but finish");
3095 P("with a `+' or `-'.");
3097 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3099 P("Press 'm' to invoke the top-level menu with the current color settings.");
3100 P("To quit, do ESC");
3109 for (i = 0; i < MaxColors; i++)
3110 init_pair((NCURSES_PAIRS_T) i,
3111 (NCURSES_COLOR_T) COLOR_WHITE,
3112 (NCURSES_COLOR_T) i);
3126 if (current >= MaxColors)
3127 current = MaxColors - 1;
3128 if (current < top_color)
3129 top_color = current;
3130 if (current - top_color >= page_size)
3131 top_color = current - (page_size - 1);
3133 MvPrintw(LINES - 1, 0, "Number: %d", value);
3136 (!isQuit(this_c, TRUE));
3141 * ncurses does not reset each color individually when calling endwin().
3148 #endif /* HAVE_COLOR_CONTENT */
3150 /****************************************************************************
3152 * Alternate character-set stuff
3154 ****************************************************************************/
3156 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3162 if ((*at_code += 1) >= limit)
3167 *at_code = limit - 1;
3176 *attr = list[*at_code].attr;
3180 #if USE_WIDEC_SUPPORT
3182 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3188 if ((*at_code += 1) >= limit)
3193 *at_code = limit - 1;
3202 *attr = list[*at_code].attr;
3208 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3210 bool result = FALSE;
3220 if ((*fg += 1) >= COLORS)
3228 if ((*bg += 1) >= COLORS)
3236 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3239 if (init_pair(*pair,
3240 (NCURSES_COLOR_T) *fg,
3241 (NCURSES_COLOR_T) *bg) == ERR) {
3250 /****************************************************************************
3252 * Soft-key label test
3254 ****************************************************************************/
3259 #define SLK_WORK (SLK_HELP + 3)
3264 static const char *table[] =
3266 "Available commands are:"
3268 ,"^L -- repaint this message and activate soft keys"
3269 ,"a/d -- activate/disable soft keys"
3270 ,"c -- set centered format for labels"
3271 ,"l -- set left-justified format for labels"
3272 ,"r -- set right-justified format for labels"
3273 ,"[12345678] -- set label; labels are numbered 1 through 8"
3274 ,"e -- erase stdscr (should not erase labels)"
3275 ,"s -- test scrolling of shortened screen"
3276 ,"v/V -- cycle through video attributes"
3278 ,"F/f/B/b -- cycle through foreground/background colors"
3280 ,"ESC -- return to main menu"
3282 ,"Note: if activating the soft keys causes your terminal to scroll up"
3283 ,"one line, your terminal auto-scrolls when anything is written to the"
3284 ,"last screen position. The ncurses code does not yet handle this"
3290 for (j = 0; j < SIZEOF(table); ++j) {
3298 call_slk_color(int fg, int bg)
3300 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3302 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3311 slk_test(bool recur GCC_UNUSED)
3312 /* exercise the soft keys */
3317 chtype attr = A_NORMAL;
3318 unsigned at_code = 0;
3320 int fg = COLOR_BLACK;
3321 int bg = COLOR_WHITE;
3322 NCURSES_PAIRS_T pair = 0;
3324 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3325 unsigned my_size = init_attr_list(my_list, termattrs());
3330 call_slk_color(fg, bg);
3340 MvAddStr(0, 20, "Soft Key Exerciser");
3355 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3356 while ((c = Getchar()) != 'Q' && (c != ERR))
3384 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3385 _nc_STRCPY(buf, "", sizeof(buf));
3386 if ((s = slk_label(c - '0')) != 0) {
3387 _nc_STRNCPY(buf, s, (size_t) 8);
3389 wGetstring(stdscr, buf, 8);
3390 slk_set((c - '0'), buf, fmt);
3399 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3401 wnoutrefresh(stdscr);
3406 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3413 if (cycle_colors(c, &fg, &bg, &pair)) {
3415 call_slk_color(fg, bg);
3425 } while (!isQuit(c = Getchar(), TRUE));
3434 #if USE_WIDEC_SUPPORT
3437 x_slk_test(bool recur GCC_UNUSED)
3438 /* exercise the soft keys */
3441 wchar_t buf[SLKLEN + 1];
3443 attr_t attr = WA_NORMAL;
3444 unsigned at_code = 0;
3445 int fg = COLOR_BLACK;
3446 int bg = COLOR_WHITE;
3447 NCURSES_PAIRS_T pair = 0;
3448 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3449 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3453 call_slk_color(fg, bg);
3460 attr_on(WA_BOLD, NULL);
3461 MvAddStr(0, 20, "Soft Key Exerciser");
3462 attr_off(WA_BOLD, NULL);
3476 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3477 while ((c = Getchar()) != 'Q' && (c != ERR))
3505 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3507 if ((s = slk_label(c - '0')) != 0) {
3508 char *temp = strdup(s);
3509 size_t used = strlen(temp);
3510 size_t want = SLKLEN;
3511 #ifndef state_unused
3516 while (want > 0 && used != 0) {
3518 const char *base = s;
3520 reset_mbytes(state);
3521 test = count_mbytes(base, 0, &state);
3522 if (test == (size_t) -1) {
3524 } else if (test > want) {
3527 reset_mbytes(state);
3528 trans_mbytes(buf, base, want, &state);
3534 wGet_wstring(stdscr, buf, SLKLEN);
3535 slk_wset((c - '0'), buf, fmt);
3546 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3547 call_slk_color(fg, bg);
3552 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3553 call_slk_color(fg, bg);
3556 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3558 wnoutrefresh(stdscr);
3562 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3563 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3569 if (cycle_colors(c, &fg, &bg, &pair)) {
3571 call_slk_color(fg, bg);
3581 } while (!isQuit(c = Getchar(), TRUE));
3590 #endif /* SLK_INIT */
3593 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3596 unsigned last = 255;
3602 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3607 for (code = first; code <= last; ++code) {
3608 int row = (int) (2 + (code / 16));
3609 int col = (int) (5 * (code % 16));
3610 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3611 for (count = 1; count < repeat; ++count) {
3612 AddCh(colored_chtype(code, attr, pair));
3619 * Show a slice of 32 characters, allowing those to be repeated up to the
3622 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3623 * terminal to perform functions. The remaining codes can be graphic.
3626 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3629 unsigned first = (unsigned) base;
3630 unsigned last = first + (unsigned) pagesize - 2;
3631 bool C1 = (first == 128);
3636 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3637 C1 ? "C1" : "GR", first, last);
3641 for (code = first; code <= last; code++) {
3643 int row = 2 + ((int) (code - first) % (pagesize / 2));
3644 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3646 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3647 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3651 nodelay(stdscr, TRUE);
3652 echochar(colored_chtype(code, attr, pair));
3654 /* (yes, this _is_ crude) */
3655 while ((reply = Getchar()) != ERR) {
3656 AddCh(UChar(reply));
3659 nodelay(stdscr, FALSE);
3661 } while (--count > 0);
3668 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3674 MvPrintw(0, 20, "Display of PC Character Codes");
3678 for (code = 0; code < 16; ++code) {
3679 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3681 for (code = 0; code < 256; code++) {
3683 int row = 3 + (int) (code / 16) + (code >= 128);
3684 int col = 8 + (int) (code % 16) * PC_COLS;
3685 if ((code % 16) == 0)
3686 MvPrintw(row, 0, "0x%02x:", code);
3697 * Skip the ones that do not work.
3701 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3704 } while (--count > 0);
3709 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3713 attr |= (attr_t) COLOR_PAIR(pair);
3717 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3722 colored_chtype(ACS_VLINE, attr, pair),
3723 colored_chtype(ACS_VLINE, attr, pair),
3724 colored_chtype(ACS_HLINE, attr, pair),
3725 colored_chtype(ACS_HLINE, attr, pair),
3726 colored_chtype(ACS_ULCORNER, attr, pair),
3727 colored_chtype(ACS_URCORNER, attr, pair),
3728 colored_chtype(ACS_LLCORNER, attr, pair),
3729 colored_chtype(ACS_LRCORNER, attr, pair));
3730 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3731 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3732 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3733 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3734 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3735 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3736 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3741 show_1_acs(int n, int repeat, const char *name, chtype code)
3743 const int height = 16;
3744 int row = 2 + (n % height);
3745 int col = (n / height) * COLS / 2;
3747 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3750 } while (--repeat > 0);
3755 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3756 /* display the ACS character set */
3760 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3764 MvAddStr(0, 20, "Display of the ACS Character Set");
3768 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3769 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3770 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3771 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3773 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3774 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3775 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3776 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3778 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3779 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3782 * HPUX's ACS definitions are broken here. Just give up.
3784 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3785 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3786 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3787 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3788 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3790 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3791 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3792 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3793 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3794 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3795 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3796 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3797 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3798 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3800 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3801 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3802 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3804 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3805 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3806 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3807 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3808 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3809 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3815 acs_test(bool recur GCC_UNUSED)
3819 char *term = getenv("TERM");
3820 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3823 chtype attr = A_NORMAL;
3826 int fg = COLOR_BLACK;
3827 int bg = COLOR_BLACK;
3828 unsigned at_code = 0;
3829 NCURSES_PAIRS_T pair = 0;
3830 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3831 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3832 unsigned my_size = init_attr_list(my_list, termattrs());
3840 ToggleAcs(last_show_acs, show_acs_chars);
3844 ToggleAcs(last_show_acs, show_pc_chars);
3849 if (pagesize == 32) {
3856 ToggleAcs(last_show_acs, show_box_chars);
3882 if (repeat < (COLS / 4))
3890 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3891 || cycle_colors(c, &fg, &bg, &pair)) {
3898 if (pagesize != 32) {
3899 show_256_chars(repeat, attr, pair);
3900 } else if (last_show_acs != 0) {
3901 last_show_acs(repeat, attr, pair);
3903 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3906 MvPrintw(LINES - 3, 0,
3907 "Note: ANSI terminals may not display C1 characters.");
3908 MvPrintw(LINES - 2, 0,
3909 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3912 MvPrintw(LINES - 1, 0,
3913 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3914 my_list[at_code].name,
3917 MvPrintw(LINES - 1, 0,
3918 "v/V cycles through video attributes (%s).",
3919 my_list[at_code].name);
3922 } while (!isQuit(c = Getchar(), TRUE));
3930 #if USE_WIDEC_SUPPORT
3932 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3938 TEST_CCHAR(src, count, {
3939 attr |= (test_attrs & A_ALTCHARSET);
3940 setcchar(dst, test_wch, attr, pair, NULL);
3949 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3950 * display. If there are no repeats, we could normally display 16 lines of 64
3951 * characters (1024 total). However, taking repeats and double-width cells
3952 * into account, use 256 characters for the page.
3955 show_paged_widechars(unsigned base,
3960 NCURSES_PAIRS_T pair)
3962 unsigned first = base * pagesize;
3963 unsigned last = first + pagesize - 1;
3971 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3974 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
3975 int row = (2 + (int) (code - (wchar_t) first) / per_line);
3976 int col = 5 * ((int) code % per_line);
3979 memset(&codes, 0, sizeof(codes));
3981 setcchar(&temp, codes, attr, pair, 0);
3983 if (wcwidth(code) == 0 && code != 0) {
3984 AddCh((chtype) space |
3985 (A_REVERSE ^ attr) |
3986 (attr_t) COLOR_PAIR(pair));
3989 for (count = 1; count < repeat; ++count) {
3996 show_upper_widechars(unsigned first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
4000 unsigned last = first + 31;
4004 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
4007 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
4008 int row = 2 + ((int) (code - (wchar_t) first) % 16);
4009 int col = ((int) (code - (wchar_t) first) / 16) * COLS / 2;
4014 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
4015 "%3ld (0x%lx)", (long) code, (long) code);
4016 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
4018 memset(&codes, 0, sizeof(codes));
4020 setcchar(&temp, codes, attr, pair, 0);
4026 * Give non-spacing characters something to combine with. If we
4027 * don't, they'll bunch up in a heap on the space after the ":".
4028 * Mark them with reverse-video to make them simpler to find on
4031 if (wcwidth(code) == 0) {
4032 AddCh((chtype) space |
4033 (A_REVERSE ^ attr) |
4034 (attr_t) COLOR_PAIR(pair));
4037 * This uses echo_wchar(), for comparison with the normal 'f'
4038 * test (and to make a test-case for echo_wchar()). The screen
4039 * may flicker because the erase() at the top of the function
4040 * is met by the builtin refresh() in echo_wchar().
4044 * The repeat-count may make text wrap - avoid that.
4046 getyx(stdscr, y, x);
4048 if (x >= col + (COLS / 2) - 2)
4050 } while (--count > 0);
4055 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
4057 const int height = 16;
4058 int row = 2 + (n % height);
4059 int col = (n / height) * COLS / 2;
4061 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4062 while (--repeat >= 0) {
4068 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
4071 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4072 /* display the wide-ACS character set */
4078 /*#define BOTH2(name) #name, &(name) */
4079 #define BOTH2(name) #name, MERGE_ATTR(name)
4083 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4087 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
4088 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
4089 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
4090 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
4092 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
4093 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
4094 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
4095 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
4097 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4098 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4100 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4101 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4102 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4103 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4105 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4106 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4107 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4108 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4109 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4110 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4111 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4115 #ifdef CURSES_WACS_ARRAY
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4117 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4118 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4120 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4121 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4122 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4123 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4124 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4125 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4131 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4132 /* display the wide-ACS character set */
4138 /*#define BOTH2(name) #name, &(name) */
4139 #define BOTH2(name) #name, MERGE_ATTR(name)
4143 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4147 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4148 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4149 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4150 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4152 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4153 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4154 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4155 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4157 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4158 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4160 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4161 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4162 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4163 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4165 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4166 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4167 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4168 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4169 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4170 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4171 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4172 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4173 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4175 #ifdef CURSES_WACS_ARRAY
4176 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4177 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4178 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4180 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4181 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4182 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4183 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4184 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4185 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4192 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4193 /* display the wide-ACS character set */
4199 /*#define BOTH2(name) #name, &(name) */
4200 #define BOTH2(name) #name, MERGE_ATTR(name)
4204 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4208 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4209 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4210 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4211 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4213 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4214 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4215 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4216 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4218 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4219 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4221 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4222 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4223 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4224 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4226 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4227 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4228 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4229 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4230 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4231 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4232 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4233 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4234 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4236 #ifdef CURSES_WACS_ARRAY
4237 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4238 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4239 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4241 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4242 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4243 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4244 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4245 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4246 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4253 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4256 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4263 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4268 MERGE_ATTR(0, WACS_VLINE),
4269 MERGE_ATTR(1, WACS_VLINE),
4270 MERGE_ATTR(2, WACS_HLINE),
4271 MERGE_ATTR(3, WACS_HLINE),
4272 MERGE_ATTR(4, WACS_ULCORNER),
4273 MERGE_ATTR(5, WACS_URCORNER),
4274 MERGE_ATTR(6, WACS_LLCORNER),
4275 MERGE_ATTR(7, WACS_LRCORNER));
4277 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4278 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4279 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4280 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4281 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4282 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4283 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4290 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4292 const int height = 16;
4293 int row = 2 + (n % height);
4294 int col = (n / height) * COLS / 2;
4297 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4298 (void) attr_set(attr, pair, 0);
4299 _nc_STRNCPY(temp, code, 20);
4301 (void) attr_set(A_NORMAL, 0, 0);
4305 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4308 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4315 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4319 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4320 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4321 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4322 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4324 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4325 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4326 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4327 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4329 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4330 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4332 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4333 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4334 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4335 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4337 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4338 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4339 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4340 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4341 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4342 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4343 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4344 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4345 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4346 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4347 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4348 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4350 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4351 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4352 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4353 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4354 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4355 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4359 /* display the wide-ACS character set */
4361 x_acs_test(bool recur GCC_UNUSED)
4367 unsigned pagesize = 32;
4368 attr_t attr = WA_NORMAL;
4369 int fg = COLOR_BLACK;
4370 int bg = COLOR_BLACK;
4371 unsigned at_code = 0;
4372 NCURSES_PAIRS_T pair = 0;
4373 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4374 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4375 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4377 bool pending_code = FALSE;
4386 ToggleAcs(last_show_wacs, show_wacs_chars);
4390 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4395 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4399 if (pagesize == 32) {
4406 ToggleAcs(last_show_wacs, show_wbox_chars);
4409 ToggleAcs(last_show_wacs, show_utf8_chars);
4412 pending_code = !pending_code;
4414 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4415 } else if (at_page[0] != '\0') {
4416 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%x", digit);
4420 if (pending_code && isxdigit(c)) {
4421 size_t len = strlen(at_page);
4422 if (len && at_page[0] == '0') {
4423 memmove(at_page, at_page + 1, len--);
4425 if (len < sizeof(at_page) - 1) {
4426 at_page[len++] = (char) c;
4427 at_page[len] = '\0';
4429 } else if (pending_code
4430 && (c == '\b' || c == KEY_BACKSPACE || c == KEY_DC)) {
4431 size_t len = strlen(at_page);
4433 at_page[--len] = '\0';
4434 } else if (c < 256 && isdigit(c)) {
4435 digit = (unsigned) (c - '0');
4437 } else if (c == '+') {
4439 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4441 } else if (c == '-' && digit > 0) {
4443 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x",
4446 } else if (c == '>' && repeat < (COLS / 4)) {
4448 } else if (c == '<' && repeat > 1) {
4450 } else if (c == '_') {
4451 space = (space == ' ') ? '_' : ' ';
4453 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4454 || cycle_colors(c, &fg, &bg, &pair)) {
4455 if (last_show_wacs != 0)
4463 if (pagesize != 32) {
4464 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4465 } else if (last_show_wacs != 0) {
4466 last_show_wacs(repeat, attr, pair);
4468 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4471 MvPrintw(LINES - 4, 0,
4472 "Select: a/d/t WACS, w=%d/page, @",
4475 pending_code ? at_page : "page");
4476 addstr(", x=box, u UTF-8, ^L repaint");
4477 MvPrintw(LINES - 3, 2,
4478 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4480 MvPrintw(LINES - 2, 2,
4481 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4482 my_list[at_code].name,
4485 MvPrintw(LINES - 2, 2,
4486 "v/V cycles through video attributes (%s).",
4487 my_list[at_code].name);
4490 } while (!isQuit(c = Getchar(), TRUE));
4501 * Graphic-rendition test (adapted from vttest)
4504 sgr_attr_test(bool recur GCC_UNUSED)
4508 for (pass = 0; pass < 2; pass++) {
4509 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4511 /* Use non-default colors if possible to exercise bce a little */
4513 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4514 normal |= (chtype) COLOR_PAIR(1);
4518 MvPrintw(1, 20, "Graphic rendition test pattern:");
4520 MvPrintw(4, 1, "vanilla");
4522 #define set_sgr(mask) bkgdset((normal^(mask)));
4524 MvPrintw(4, 40, "bold");
4526 set_sgr(A_UNDERLINE);
4527 MvPrintw(6, 6, "underline");
4529 set_sgr(A_BOLD | A_UNDERLINE);
4530 MvPrintw(6, 45, "bold underline");
4533 MvPrintw(8, 1, "blink");
4535 set_sgr(A_BLINK | A_BOLD);
4536 MvPrintw(8, 40, "bold blink");
4538 set_sgr(A_UNDERLINE | A_BLINK);
4539 MvPrintw(10, 6, "underline blink");
4541 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4542 MvPrintw(10, 45, "bold underline blink");
4545 MvPrintw(12, 1, "negative");
4547 set_sgr(A_BOLD | A_REVERSE);
4548 MvPrintw(12, 40, "bold negative");
4550 set_sgr(A_UNDERLINE | A_REVERSE);
4551 MvPrintw(14, 6, "underline negative");
4553 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4554 MvPrintw(14, 45, "bold underline negative");
4556 set_sgr(A_BLINK | A_REVERSE);
4557 MvPrintw(16, 1, "blink negative");
4559 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4560 MvPrintw(16, 40, "bold blink negative");
4562 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4563 MvPrintw(18, 6, "underline blink negative");
4565 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4566 MvPrintw(18, 45, "bold underline blink negative");
4569 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4575 bkgdset(A_NORMAL | BLANK);
4581 /****************************************************************************
4583 * Windows and scrolling tester.
4585 ****************************************************************************/
4587 #define BOTLINES 4 /* number of line stolen from screen bottom */
4593 #define FRAME struct frame
4602 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4603 #if (NCURSES_VERSION_PATCH < 20070331)
4604 #define is_keypad(win) (win)->_use_keypad
4605 #define is_scrollok(win) (win)->_scroll
4608 #define is_keypad(win) FALSE
4609 #define is_scrollok(win) FALSE
4613 frame_win(FRAME * curp)
4615 return (curp != 0) ? curp->wind : stdscr;
4618 /* We need to know if these flags are actually set, so don't look in FRAME.
4619 * These names are known to work with SVr4 curses as well as ncurses. The
4620 * _use_keypad name does not work with Solaris 8.
4623 HaveKeypad(FRAME * curp)
4625 WINDOW *win = frame_win(curp);
4627 return is_keypad(win);
4631 HaveScroll(FRAME * curp)
4633 WINDOW *win = frame_win(curp);
4635 return is_scrollok(win);
4639 newwin_legend(FRAME * curp)
4641 #define DATA(num, name) { name, num }
4642 static const struct {
4646 DATA(0, "^C = create window"),
4647 DATA(0, "^N = next window"),
4648 DATA(0, "^P = previous window"),
4649 DATA(0, "^F = scroll forward"),
4650 DATA(0, "^B = scroll backward"),
4651 DATA(1, "^K = keypad(%s)"),
4652 DATA(2, "^S = scrollok(%s)"),
4653 DATA(0, "^W = save window"),
4654 DATA(0, "^R = restore window"),
4656 DATA(0, "^X = resize"),
4658 DATA(3, "^Q%s = exit")
4662 bool do_keypad = HaveKeypad(curp);
4663 bool do_scroll = HaveScroll(curp);
4668 for (n = 0; n < SIZEOF(legend); n++) {
4671 switch (legend[n].code) {
4673 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4676 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4677 legend[n].msg, do_keypad ? "yes" : "no");
4680 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4681 legend[n].msg, do_scroll ? "yes" : "no");
4684 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4685 legend[n].msg, do_keypad ? "/ESC" : "");
4688 x = getcurx(stdscr);
4689 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4696 transient(FRAME * curp, NCURSES_CONST char *msg)
4698 newwin_legend(curp);
4700 MvAddStr(LINES - 1, 0, msg);
4706 printw("%s characters are echoed, window should %sscroll.",
4707 HaveKeypad(curp) ? "Non-arrow" : "All other",
4708 HaveScroll(curp) ? "" : "not ");
4713 newwin_report(FRAME * curp)
4714 /* report on the cursor's current position, then restore it */
4716 WINDOW *win = frame_win(curp);
4720 transient(curp, (char *) 0);
4722 move(LINES - 1, COLS - 17);
4723 printw("Y = %2d X = %2d", y, x);
4731 selectcell(int uli, int ulj, int lri, int lrj)
4732 /* arrows keys move cursor, return location at current on non-arrow key */
4734 static pair res; /* result cell */
4735 int si = lri - uli + 1; /* depth of the select area */
4736 int sj = lrj - ulj + 1; /* width of the select area */
4737 int i = 0, j = 0; /* offsets into the select area */
4742 move(uli + i, ulj + j);
4743 newwin_report((FRAME *) 0);
4745 switch (Getchar()) {
4759 return ((pair *) 0);
4760 #ifdef NCURSES_MOUSE_VERSION
4766 if (event.y > uli && event.x > ulj) {
4787 outerbox(pair ul, pair lr, bool onoff)
4788 /* draw or erase a box *outside* the given pair of corners */
4790 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4791 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4792 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4793 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4794 move(ul.y - 1, ul.x);
4795 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4796 move(ul.y, ul.x - 1);
4797 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4798 move(lr.y + 1, ul.x);
4799 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4800 move(ul.y, lr.x + 1);
4801 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4806 /* Ask user for a window definition */
4813 addstr("Use arrows to move cursor, anything else to mark corner 1");
4815 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4816 return ((WINDOW *) 0);
4817 memcpy(&ul, tmp, sizeof(pair));
4818 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4821 addstr("Use arrows to move cursor, anything else to mark corner 2");
4823 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4825 return ((WINDOW *) 0);
4826 memcpy(&lr, tmp, sizeof(pair));
4828 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4830 outerbox(ul, lr, TRUE);
4842 newwin_move(FRAME * curp, int dy, int dx)
4844 WINDOW *win = frame_win(curp);
4848 getyx(win, cur_y, cur_x);
4849 getmaxyx(win, max_y, max_x);
4850 if ((cur_x += dx) < 0)
4852 else if (cur_x >= max_x)
4854 if ((cur_y += dy) < 0)
4856 else if (cur_y >= max_y)
4858 wmove(win, cur_y, cur_x);
4862 delete_framed(FRAME * fp, bool showit)
4867 fp->last->next = fp->next;
4868 fp->next->last = fp->last;
4876 np = (fp == fp->next) ? NULL : fp->next;
4883 scroll_test(bool recur GCC_UNUSED)
4884 /* Demonstrate windows */
4887 FRAME *current = (FRAME *) 0, *neww;
4889 #if HAVE_PUTWIN && HAVE_GETWIN
4893 #define DUMPFILE "screendump"
4895 #ifdef NCURSES_MOUSE_VERSION
4896 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4901 transient((FRAME *) 0, (char *) 0);
4904 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4905 failed("scroll_test");
4908 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4909 failed("scroll_test");
4914 if (current == 0) { /* First element, */
4915 neww->next = neww; /* so point it at itself */
4918 neww->next = current->next;
4919 neww->last = current;
4920 neww->last->next = neww;
4921 neww->next->last = neww;
4924 /* SVr4 curses sets the keypad on all newly-created windows to
4925 * false. Someone reported that PDCurses makes new windows inherit
4926 * this flag. Remove the following 'keypad()' call to test this
4928 keypad(current->wind, TRUE);
4929 current->do_keypad = HaveKeypad(current);
4930 current->do_scroll = HaveScroll(current);
4933 case CTRL('N'): /* go to next window */
4935 current = current->next;
4938 case CTRL('P'): /* go to previous window */
4940 current = current->last;
4943 case CTRL('F'): /* scroll current window forward */
4945 wscrl(frame_win(current), 1);
4948 case CTRL('B'): /* scroll current window backwards */
4950 wscrl(frame_win(current), -1);
4953 case CTRL('K'): /* toggle keypad mode for current */
4955 current->do_keypad = !current->do_keypad;
4956 keypad(current->wind, current->do_keypad);
4962 current->do_scroll = !current->do_scroll;
4963 scrollok(current->wind, current->do_scroll);
4967 #if HAVE_PUTWIN && HAVE_GETWIN
4968 case CTRL('W'): /* save and delete window */
4969 if ((current != 0) && (current == current->next)) {
4970 transient(current, "Will not save/delete ONLY window");
4972 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4973 transient(current, "Can't open screen dump file");
4975 int rc = putwin(frame_win(current), fp);
4979 current = delete_framed(current, TRUE);
4981 transient(current, "Can't write screen dump file");
4986 case CTRL('R'): /* restore window */
4987 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4988 transient(current, "Can't open screen dump file");
4990 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4992 neww->next = current ? current->next : 0;
4993 neww->last = current;
4994 if (neww->last != 0)
4995 neww->last->next = neww;
4996 if (neww->next != 0)
4997 neww->next->last = neww;
4999 neww->wind = getwin(fp);
5001 wrefresh(neww->wind);
5003 failed("scroll_test");
5011 case CTRL('X'): /* resize window */
5018 addstr("Use arrows to move cursor, anything else to mark new corner");
5021 getbegyx(current->wind, ul.y, ul.x);
5023 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
5024 if (tmp == (pair *) 0) {
5029 getmaxyx(current->wind, lr.y, lr.x);
5032 outerbox(ul, lr, FALSE);
5033 wnoutrefresh(stdscr);
5035 /* strictly cosmetic hack for the test */
5036 getmaxyx(current->wind, my, mx);
5037 if (my > tmp->y - ul.y) {
5038 getyx(current->wind, lr.y, lr.x);
5039 wmove(current->wind, tmp->y - ul.y + 1, 0);
5040 wclrtobot(current->wind);
5041 wmove(current->wind, lr.y, lr.x);
5043 if (mx > tmp->x - ul.x) {
5045 for (i = 0; i < my; i++) {
5046 wmove(current->wind, i, tmp->x - ul.x + 1);
5047 wclrtoeol(current->wind);
5050 wnoutrefresh(current->wind);
5052 memcpy(&lr, tmp, sizeof(pair));
5053 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
5055 getbegyx(current->wind, ul.y, ul.x);
5056 getmaxyx(current->wind, lr.y, lr.x);
5059 outerbox(ul, lr, TRUE);
5060 wnoutrefresh(stdscr);
5062 wnoutrefresh(current->wind);
5068 #endif /* HAVE_WRESIZE */
5071 newwin_move(current, -1, 0);
5074 newwin_move(current, 1, 0);
5077 newwin_move(current, 0, -1);
5080 newwin_move(current, 0, 1);
5088 getyx(frame_win(current), y, x);
5092 x = getmaxx(frame_win(current)) - 1;
5094 (void) mvwdelch(frame_win(current), y, x);
5104 waddch(current->wind, (chtype) c);
5109 newwin_report(current);
5110 usescr = frame_win(current);
5113 (!isQuit(c = wGetchar(usescr), TRUE)
5117 while (current != 0)
5118 current = delete_framed(current, FALSE);
5120 scrollok(stdscr, TRUE); /* reset to driver's default */
5121 #ifdef NCURSES_MOUSE_VERSION
5122 mousemask(0, (mmask_t *) 0);
5130 /****************************************************************************
5134 ****************************************************************************/
5137 static int nap_msec = 1;
5139 static NCURSES_CONST char *mod[] =
5149 /*+-------------------------------------------------------------------------
5151 --------------------------------------------------------------------------*/
5153 wait_a_while(int msec GCC_UNUSED)
5163 else if (msec > 1000)
5164 sleep((unsigned) msec / 1000);
5168 } /* end of wait_a_while */
5170 /*+-------------------------------------------------------------------------
5172 --------------------------------------------------------------------------*/
5174 saywhat(NCURSES_CONST char *text)
5176 wmove(stdscr, LINES - 1, 0);
5178 if (text != 0 && *text != '\0') {
5179 waddstr(stdscr, text);
5180 waddstr(stdscr, "; ");
5182 waddstr(stdscr, "press any key to continue");
5183 } /* end of saywhat */
5185 /*+-------------------------------------------------------------------------
5186 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
5187 --------------------------------------------------------------------------*/
5189 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
5194 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
5195 if ((pan = new_panel(win)) == 0) {
5197 } else if (UseColors) {
5198 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
5201 NCURSES_COLOR_T bg = color;
5203 init_pair(color, fg, bg);
5204 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
5206 wbkgdset(win, A_BOLD | ' ');
5210 } /* end of mkpanel */
5212 /*+-------------------------------------------------------------------------
5214 --------------------------------------------------------------------------*/
5218 WINDOW *win = panel_window(pan);
5221 } /* end of rmpanel */
5223 /*+-------------------------------------------------------------------------
5225 --------------------------------------------------------------------------*/
5231 } /* end of pflush */
5233 /*+-------------------------------------------------------------------------
5235 --------------------------------------------------------------------------*/
5237 init_panel(WINDOW *win)
5241 for (y = 0; y < LINES - 1; y++) {
5242 for (x = 0; x < COLS; x++)
5243 wprintw(win, "%d", (y + x) % 10);
5248 fill_panel(PANEL *pan)
5250 WINDOW *win = panel_window(pan);
5251 const char *userptr = (const char *) panel_userptr(pan);
5252 int num = (userptr && *userptr) ? userptr[1] : '?';
5256 wprintw(win, "-pan%c-", num);
5259 for (y = 2; y < getmaxy(win) - 1; y++) {
5260 for (x = 1; x < getmaxx(win) - 1; x++) {
5262 waddch(win, UChar(num));
5267 #if USE_WIDEC_SUPPORT
5269 init_wide_panel(WINDOW *win)
5274 for (digit = 0; digit < 10; ++digit)
5275 make_fullwidth_digit(&temp[digit], digit);
5279 getyx(stdscr, y, x);
5280 digit = (y + x / 2) % 10;
5281 } while (wadd_wch(win, &temp[digit]) != ERR);
5285 fill_wide_panel(PANEL *pan)
5287 WINDOW *win = panel_window(pan);
5288 const char *userptr = (const char *) panel_userptr(pan);
5289 int num = (userptr && *userptr) ? userptr[1] : '?';
5293 wprintw(win, "-pan%c-", num);
5296 for (y = 2; y < getmaxy(win) - 1; y++) {
5297 for (x = 1; x < getmaxx(win) - 1; x++) {
5299 waddch(win, UChar(num));
5305 #define MAX_PANELS 5
5308 canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
5310 int which = cmd[1] - '0';
5315 hide_panel(px[which]);
5318 show_panel(px[which]);
5321 top_panel(px[which]);
5324 bottom_panel(px[which]);
5331 wait_a_while(nap_msec);
5335 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
5339 PANEL *px[MAX_PANELS + 1];
5341 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5345 for (count = 0; count < 5; count++) {
5346 px[1] = mkpanel(COLOR_RED,
5351 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
5353 px[2] = mkpanel(COLOR_GREEN,
5358 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5360 px[3] = mkpanel(COLOR_YELLOW,
5365 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5367 px[4] = mkpanel(COLOR_BLUE,
5372 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5374 px[5] = mkpanel(COLOR_MAGENTA,
5379 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5391 wait_a_while(nap_msec);
5393 saywhat("h3 s1 s2 s4 s5");
5394 move_panel(px[1], 0, 0);
5401 wait_a_while(nap_msec);
5403 canned_panel(px, "s1");
5404 canned_panel(px, "s2");
5407 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5409 wait_a_while(nap_msec);
5411 canned_panel(px, "s3");
5414 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5416 wait_a_while(nap_msec);
5418 canned_panel(px, "b3");
5419 canned_panel(px, "s4");
5420 canned_panel(px, "s5");
5421 canned_panel(px, "t3");
5422 canned_panel(px, "t1");
5423 canned_panel(px, "t2");
5424 canned_panel(px, "t3");
5425 canned_panel(px, "t4");
5427 for (itmp = 0; itmp < 6; itmp++) {
5428 WINDOW *w4 = panel_window(px[4]);
5429 WINDOW *w5 = panel_window(px[5]);
5432 wmove(w4, LINES / 8, 1);
5433 waddstr(w4, mod[itmp]);
5434 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5435 wmove(w5, LINES / 6, 1);
5436 waddstr(w5, mod[itmp]);
5438 wait_a_while(nap_msec);
5441 wmove(w4, LINES / 6, 1);
5442 waddstr(w4, mod[itmp]);
5443 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5444 wmove(w5, LINES / 8, 1);
5445 waddstr(w5, mod[itmp]);
5447 wait_a_while(nap_msec);
5451 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5453 wait_a_while(nap_msec);
5455 canned_panel(px, "t5");
5456 canned_panel(px, "t2");
5457 canned_panel(px, "t1");
5458 canned_panel(px, "d2");
5459 canned_panel(px, "h3");
5460 canned_panel(px, "d1");
5461 canned_panel(px, "d4");
5462 canned_panel(px, "d5");
5463 canned_panel(px, "d3");
5465 wait_a_while(nap_msec);
5478 panel_test(bool recur GCC_UNUSED)
5480 return demo_panels(init_panel, fill_panel);
5484 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
5486 x_panel_test(bool recur GCC_UNUSED)
5488 return demo_panels(init_wide_panel, fill_wide_panel);
5491 #endif /* USE_LIBPANEL */
5493 /****************************************************************************
5497 ****************************************************************************/
5501 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
5502 * though we can rely on negative x/y values to stop the macro.
5505 do_h_line(int y, int x, chtype c, int to)
5508 MvHLine(y, x, c, (to) - (x));
5512 do_v_line(int y, int x, chtype c, int to)
5515 MvVLine(y, x, c, (to) - (y));
5520 static bool pending_pan = FALSE;
5521 static bool show_panner_legend = TRUE;
5524 panner_legend(int line)
5526 static const char *const legend[] =
5528 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5529 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5530 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5531 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5533 int n = ((int) SIZEOF(legend) - (LINES - line));
5535 if (move(line, 0) != ERR) {
5536 if (show_panner_legend)
5537 printw("%s", legend[n]);
5539 return show_panner_legend;
5546 panner_h_cleanup(int from_y, int from_x, int to_x)
5548 if (!panner_legend(from_y))
5549 do_h_line(from_y, from_x, ' ', to_x);
5553 panner_v_cleanup(int from_y, int from_x, int to_y)
5555 if (!panner_legend(from_y))
5556 do_v_line(from_y, from_x, ' ', to_y);
5560 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5563 unsigned gridcount = 0;
5567 fill = (chtype) COLOR_PAIR(1);
5570 wmove(panpad, 0, 0);
5571 for (y = 0; y < getmaxy(panpad); y++) {
5572 for (x = 0; x < getmaxx(panpad); x++) {
5573 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5574 if (y == 0 && x == 0)
5575 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5577 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5578 else if (y == 0 || x == 0)
5579 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5581 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5582 (int) (gridcount++ % 26)) | fill);
5583 } else if (y % GRIDSIZE == 0)
5584 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5585 else if (x % GRIDSIZE == 0)
5586 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5588 waddch(panpad, ' ');
5595 int top_x, int top_y, int porty, int portx,
5596 int (*pgetc) (WINDOW *),
5599 #if HAVE_GETTIMEOFDAY
5600 struct timeval before, after;
5603 bool pan_lines = FALSE;
5604 bool scrollers = TRUE;
5607 int pxmax, pymax, lowend, highend, c;
5609 getmaxyx(pad, pymax, pxmax);
5610 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5614 #ifdef NCURSES_VERSION
5616 * During shell-out, the user may have resized the window. Adjust
5617 * the port size of the pad to accommodate this. Ncurses automatically
5618 * resizes all of the normal windows to fit on the new screen.
5635 if (c == HELP_KEY_1)
5636 show_panner_legend = !show_panner_legend;
5637 panner_legend(LINES - 4);
5638 panner_legend(LINES - 3);
5639 panner_legend(LINES - 2);
5640 panner_legend(LINES - 1);
5643 pan_lines = !pan_lines;
5644 fill_pad(pad, pan_lines, colored);
5645 pending_pan = FALSE;
5648 #if HAVE_GETTIMEOFDAY
5652 panner_legend(LINES - 1);
5656 scrollers = !scrollers;
5659 /* Move the top-left corner of the pad, keeping the bottom-right
5662 case 'h': /* increase-columns: move left edge to left */
5666 panner_v_cleanup(top_y, top_x, porty);
5671 case 'j': /* decrease-lines: move top-edge down */
5675 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5680 case 'k': /* increase-lines: move top-edge up */
5685 panner_h_cleanup(top_y, top_x, portx);
5689 case 'l': /* decrease-columns: move left-edge to right */
5693 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5698 /* Move the bottom-right corner of the pad, keeping the top-left
5701 case KEY_IC: /* increase-columns: move right-edge to right */
5702 if (portx >= pxmax || portx >= COLS)
5705 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5710 case KEY_IL: /* increase-lines: move bottom-edge down */
5711 if (porty >= pymax || porty >= LINES)
5714 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5719 case KEY_DC: /* decrease-columns: move bottom edge up */
5724 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5728 case KEY_DL: /* decrease-lines */
5733 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5737 case KEY_LEFT: /* pan leftwards */
5744 case KEY_RIGHT: /* pan rightwards */
5745 if (basex + portx - (pymax > porty) < pxmax)
5751 case KEY_UP: /* pan upwards */
5758 case KEY_DOWN: /* pan downwards */
5759 if (basey + porty - (pxmax > portx) < pymax)
5774 basey = pymax - porty;
5784 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5785 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5786 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5788 if (scrollers && (pxmax > portx - 1)) {
5789 int length = (portx - top_x - 1);
5790 float ratio = ((float) length) / ((float) pxmax);
5792 lowend = (int) ((float) top_x + ((float) basex * ratio));
5793 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5795 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5796 if (highend < portx) {
5798 do_h_line(porty - 1, lowend, ' ', highend + 1);
5800 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5803 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5805 if (scrollers && (pymax > porty - 1)) {
5806 int length = (porty - top_y - 1);
5807 float ratio = ((float) length) / ((float) pymax);
5809 lowend = (int) ((float) top_y + ((float) basey * ratio));
5810 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5812 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5813 if (highend < porty) {
5815 do_v_line(lowend, portx - 1, ' ', highend + 1);
5817 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5820 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5822 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5823 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5824 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5827 #if HAVE_GETTIMEOFDAY
5828 gettimeofday(&before, 0);
5830 wnoutrefresh(stdscr);
5835 porty - (pxmax > portx) - 1,
5836 portx - (pymax > porty) - 1);
5839 #if HAVE_GETTIMEOFDAY
5840 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5843 gettimeofday(&after, 0);
5844 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5845 move(LINES - 1, COLS - 12);
5846 printw("Secs: %2.03f", elapsed);
5853 ((c = pgetc(pad)) != KEY_EXIT);
5855 scrollok(stdscr, TRUE); /* reset to driver's default */
5859 padgetch(WINDOW *win)
5864 if ((pending_pan = (count > 0)) != FALSE) {
5866 pending_pan = (count != 0);
5870 switch (c = wGetchar(win)) {
5906 case ERR: /* FALLTHRU */
5912 if (c >= '0' && c <= '9') {
5913 count = count * 10 + (c - '0');
5927 #define PAD_HIGH 200
5928 #define PAD_WIDE 200
5931 pad_test(bool recur GCC_UNUSED)
5932 /* Demonstrate pads. */
5934 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5937 Cannot("cannot create requested pad");
5942 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5943 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5944 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5947 fill_pad(panpad, FALSE, TRUE);
5949 panner_legend(LINES - 4);
5950 panner_legend(LINES - 3);
5951 panner_legend(LINES - 2);
5952 panner_legend(LINES - 1);
5954 keypad(panpad, TRUE);
5956 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5957 * We'll still be able to widen it during a test, since that's required
5958 * for testing boundaries.
5960 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, TRUE);
5967 #endif /* HAVE_NEWPAD */
5969 /****************************************************************************
5971 * Tests from John Burnell's PDCurses tester
5973 ****************************************************************************/
5976 Continue(WINDOW *win)
5980 MvWAddStr(win, 10, 1, " Press any key to continue");
5986 flushinp_test(bool recur GCC_UNUSED)
5987 /* Input test, adapted from John Burnell's PDCurses tester */
5989 WINDOW *win = stdscr;
5990 int w, h, bx, by, sw, sh, i;
5995 getmaxyx(win, h, w);
5996 getbegyx(win, by, bx);
5999 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
6004 init_pair(2, COLOR_CYAN, COLOR_BLUE);
6005 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
6008 (void) wattrset(subWin, A_BOLD);
6009 box(subWin, ACS_VLINE, ACS_HLINE);
6010 MvWAddStr(subWin, 2, 1, "This is a subwindow");
6014 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
6015 * it only happened to "work" on SVr4 because that implementation does not
6016 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
6017 * test behavior, we're using 'cbreak()', which will allow a single
6018 * character to return without needing a newline. - T.Dickey 1997/10/11.
6021 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
6023 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
6024 MvWAddStr(win, 3, 1,
6025 "These should be discarded (not echoed) after the subwindow goes away.");
6028 for (i = 0; i < 5; i++) {
6029 MvWPrintw(subWin, 1, 1, "Time = %d", i);
6041 MvWAddStr(win, 2, 1,
6042 "If you were still typing when the window timer expired,");
6043 MvWAddStr(win, 3, 1,
6044 "or else you typed nothing at all while it was running,");
6045 MvWAddStr(win, 4, 1,
6046 "test was invalid. You'll see garbage or nothing at all. ");
6047 MvWAddStr(win, 6, 1, "Press a key");
6053 MvWAddStr(win, 12, 0,
6054 "If you see any key other than what you typed, flushinp() is broken.");
6063 "What you typed should now have been deleted; if not, wdelch() failed.");
6070 /****************************************************************************
6074 ****************************************************************************/
6082 menu_virtualize(int c)
6084 if (c == '\n' || c == KEY_EXIT)
6085 return (MAX_COMMAND + 1);
6087 return (REQ_SCR_ULINE);
6089 return (REQ_SCR_DLINE);
6090 else if (c == 'b' || c == KEY_NPAGE)
6091 return (REQ_SCR_UPAGE);
6092 else if (c == 'f' || c == KEY_PPAGE)
6093 return (REQ_SCR_DPAGE);
6094 else if (c == 'n' || c == KEY_DOWN)
6095 return (REQ_NEXT_ITEM);
6096 else if (c == 'p' || c == KEY_UP)
6097 return (REQ_PREV_ITEM);
6099 return (REQ_TOGGLE_ITEM);
6107 static CONST_MENUS char *animals[] =
6120 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6121 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6126 menu_test(bool recur GCC_UNUSED)
6129 ITEM *items[SIZEOF(animals)];
6131 CONST_MENUS char **ap;
6132 int mrows, mcols, c;
6135 #ifdef NCURSES_MOUSE_VERSION
6136 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6138 MvAddStr(0, 0, "This is the menu test:");
6139 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
6140 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
6142 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
6143 MvAddStr(5, 0, " Press return to exit.");
6146 for (ap = animals; *ap; ap++) {
6147 if ((*ip = new_item(*ap, "")) != 0)
6152 m = new_menu(items);
6154 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
6155 scale_menu(m, &mrows, &mcols);
6157 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6158 set_menu_win(m, menuwin);
6159 keypad(menuwin, TRUE);
6162 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6166 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
6167 if (c == E_NOT_POSTED)
6169 if (c == E_REQUEST_DENIED)
6174 MvPrintw(LINES - 2, 0,
6175 "You chose: %s\n", item_name(current_item(m)));
6176 (void) addstr("Press any key to continue...");
6183 for (ip = items; *ip; ip++)
6185 #ifdef NCURSES_MOUSE_VERSION
6186 mousemask(0, (mmask_t *) 0);
6192 #define T_TBL(name) { #name, name }
6198 T_TBL(TRACE_DISABLE),
6201 T_TBL(TRACE_UPDATE),
6203 T_TBL(TRACE_CHARPUT),
6204 T_TBL(TRACE_ORDINARY),
6206 T_TBL(TRACE_VIRTPUT),
6207 T_TBL(TRACE_IEVENT),
6209 T_TBL(TRACE_ICALLS),
6210 T_TBL(TRACE_CCALLS),
6211 T_TBL(TRACE_DATABASE),
6213 T_TBL(TRACE_MAXIMUM),
6220 tracetrace(unsigned tlevel)
6223 static size_t need = 12;
6227 for (n = 0; t_tbl[n].name != 0; n++)
6228 need += strlen(t_tbl[n].name) + 2;
6229 buf = typeMalloc(char, need);
6231 failed("tracetrace");
6233 _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
6235 _nc_STRCAT(buf, t_tbl[0].name, need);
6236 _nc_STRCAT(buf, ", ", need);
6238 for (n = 1; t_tbl[n].name != 0; n++)
6239 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
6240 _nc_STRCAT(buf, t_tbl[n].name, need);
6241 _nc_STRCAT(buf, ", ", need);
6244 if (buf[strlen(buf) - 2] == ',')
6245 buf[strlen(buf) - 2] = '\0';
6246 _nc_STRCAT(buf, "}", need);
6250 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
6254 run_trace_menu(MENU * m)
6260 bool changed = FALSE;
6261 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
6262 case E_UNKNOWN_COMMAND:
6265 items = menu_items(m);
6266 i = current_item(m);
6267 if (i == items[0]) {
6268 if (item_value(i)) {
6269 for (p = items + 1; *p != 0; p++)
6270 if (item_value(*p)) {
6271 set_item_value(*p, FALSE);
6276 for (p = items + 1; *p != 0; p++)
6277 if (item_value(*p)) {
6278 set_item_value(items[0], FALSE);
6290 trace_set(bool recur GCC_UNUSED)
6291 /* interactively set the trace level */
6294 ITEM *items[SIZEOF(t_tbl)];
6301 MvAddStr(0, 0, "Interactively set trace level:");
6302 MvAddStr(2, 0, " Press space bar to toggle a selection.");
6303 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
6304 MvAddStr(4, 0, " Press return to set the trace level.");
6305 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
6309 for (n = 0; t_tbl[n].name != 0; n++) {
6310 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
6316 m = new_menu(items);
6318 set_menu_format(m, 0, 2);
6319 scale_menu(m, &mrows, &mcols);
6321 menu_opts_off(m, O_ONEVALUE);
6322 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6323 set_menu_win(m, menuwin);
6324 keypad(menuwin, TRUE);
6327 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6331 for (ip = menu_items(m); *ip; ip++) {
6332 unsigned mask = t_tbl[item_index(*ip)].mask;
6334 set_item_value(*ip, _nc_tracing == 0);
6335 else if ((mask & _nc_tracing) == mask)
6336 set_item_value(*ip, TRUE);
6339 while (run_trace_menu(m))
6343 for (ip = menu_items(m); *ip; ip++)
6344 if (item_value(*ip))
6345 newtrace |= t_tbl[item_index(*ip)].mask;
6346 curses_trace(newtrace);
6347 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
6349 MvPrintw(LINES - 2, 0,
6350 "Trace level is %s\n", tracetrace(_nc_tracing));
6351 (void) addstr("Press any key to continue...");
6358 for (ip = items; *ip; ip++)
6364 #endif /* USE_LIBMENU */
6366 /****************************************************************************
6370 ****************************************************************************/
6373 make_label(int frow, int fcol, NCURSES_CONST char *label)
6375 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
6378 set_field_buffer(f, 0, label);
6379 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
6385 make_field(int frow, int fcol, int rows, int cols, bool secure)
6387 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
6390 set_field_back(f, A_UNDERLINE);
6391 set_field_userptr(f, (void *) 0);
6397 display_form(FORM *f)
6402 scale_form(f, &rows, &cols);
6404 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6406 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6409 if (post_form(f) != E_OK)
6417 WINDOW *w = form_win(f);
6418 WINDOW *s = form_sub(f);
6428 edit_secure(FIELD *me, int c)
6430 int rows, cols, frow, fcol, nrow, nbuf;
6432 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6434 char *source = field_buffer(me, 1);
6435 size_t have = (source ? strlen(source) : 0) + 1;
6436 size_t need = 80 + have;
6437 char *temp = malloc(need);
6441 _nc_STRNCPY(temp, source ? source : "", have + 1);
6442 len = (size_t) (char *) field_userptr(me);
6444 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6445 temp[len++] = (char) c;
6447 set_field_buffer(me, 1, temp);
6467 case REQ_RIGHT_CHAR:
6469 c = 0; /* we don't want to do inline editing */
6474 set_field_buffer(me, 1, temp);
6481 set_field_buffer(me, 1, temp);
6486 set_field_userptr(me, (void *) len);
6494 form_virtualize(FORM *f, WINDOW *w)
6497 static const struct {
6501 { CTRL('A'), REQ_NEXT_CHOICE },
6502 { CTRL('B'), REQ_PREV_WORD },
6503 { CTRL('C'), REQ_CLR_EOL },
6504 { CTRL('D'), REQ_DOWN_FIELD },
6505 { CTRL('E'), REQ_END_FIELD },
6506 { CTRL('F'), REQ_NEXT_PAGE },
6507 { CTRL('G'), REQ_DEL_WORD },
6508 { CTRL('H'), REQ_DEL_PREV },
6509 { CTRL('I'), REQ_INS_CHAR },
6510 { CTRL('K'), REQ_CLR_EOF },
6511 { CTRL('L'), REQ_LEFT_FIELD },
6512 { CTRL('M'), REQ_NEW_LINE },
6513 { CTRL('N'), REQ_NEXT_FIELD },
6514 { CTRL('O'), REQ_INS_LINE },
6515 { CTRL('P'), REQ_PREV_FIELD },
6516 { CTRL('R'), REQ_RIGHT_FIELD },
6517 { CTRL('S'), REQ_BEG_FIELD },
6518 { CTRL('U'), REQ_UP_FIELD },
6519 { CTRL('V'), REQ_DEL_CHAR },
6520 { CTRL('W'), REQ_NEXT_WORD },
6521 { CTRL('X'), REQ_CLR_FIELD },
6522 { CTRL('Y'), REQ_DEL_LINE },
6523 { CTRL('Z'), REQ_PREV_CHOICE },
6524 { ESCAPE, MAX_FORM_COMMAND + 1 },
6525 { KEY_BACKSPACE, REQ_DEL_PREV },
6526 { KEY_DOWN, REQ_DOWN_CHAR },
6527 { KEY_END, REQ_LAST_FIELD },
6528 { KEY_HOME, REQ_FIRST_FIELD },
6529 { KEY_LEFT, REQ_LEFT_CHAR },
6530 { KEY_LL, REQ_LAST_FIELD },
6531 { KEY_NEXT, REQ_NEXT_FIELD },
6532 { KEY_NPAGE, REQ_NEXT_PAGE },
6533 { KEY_PPAGE, REQ_PREV_PAGE },
6534 { KEY_PREVIOUS, REQ_PREV_FIELD },
6535 { KEY_RIGHT, REQ_RIGHT_CHAR },
6536 { KEY_UP, REQ_UP_CHAR },
6537 { QUIT, MAX_FORM_COMMAND + 1 }
6541 static int mode = REQ_INS_MODE;
6542 int c = wGetchar(w);
6543 FIELD *me = current_field(f);
6544 bool current = TRUE;
6546 if (c == CTRL(']')) {
6547 if (mode == REQ_INS_MODE) {
6548 mode = REQ_OVL_MODE;
6550 mode = REQ_INS_MODE;
6555 for (n = 0; n < SIZEOF(lookup); n++) {
6556 if (lookup[n].code == c) {
6557 c = lookup[n].result;
6562 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6565 * Force the field that the user is typing into to be in reverse video,
6566 * while the other fields are shown underlined.
6581 case REQ_LEFT_FIELD:
6583 case REQ_RIGHT_CHAR:
6587 current = (c < KEY_MAX);
6591 c = edit_secure(me, c);
6592 set_field_back(me, A_REVERSE);
6594 c = edit_secure(me, c);
6595 set_field_back(me, A_UNDERLINE);
6601 my_form_driver(FORM *form, int c)
6603 if (c == (MAX_FORM_COMMAND + 1)
6604 && form_driver(form, REQ_VALIDATION) == E_OK)
6612 #ifdef NCURSES_VERSION
6613 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6614 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6616 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6617 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6621 * Allow a middle initial, optionally with a '.' to end it.
6624 FIELDCHECK_CB(mi_field_check)
6626 char *s = field_buffer(fld, 0);
6630 for (n = 0; s[n] != '\0'; ++n) {
6637 } else if (isspace(UChar(s[n]))) {
6642 if (!isspace(UChar(s[n])))
6648 /* force the form to display a leading capital */
6649 if (islower(UChar(s[0]))) {
6650 s[0] = (char) toupper(UChar(s[0]));
6651 set_field_buffer(fld, 0, s);
6657 CHAR_CHECK_CB(mi_char_check)
6659 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6663 * Passwords should be at least 6 characters.
6666 FIELDCHECK_CB(pw_field_check)
6668 char *s = field_buffer(fld, 0);
6671 for (n = 0; s[n] != '\0'; ++n) {
6672 if (isspace(UChar(s[n]))) {
6681 CHAR_CHECK_CB(pw_char_check)
6683 return (isgraph(ch) ? TRUE : FALSE);
6687 form_test(bool recur GCC_UNUSED)
6690 FIELD *f[12], *secure;
6691 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6692 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6696 #ifdef NCURSES_MOUSE_VERSION
6697 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6701 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6702 addstr("^N -- go to next field ^P -- go to previous field\n");
6703 addstr("Home -- go to first field End -- go to last field\n");
6704 addstr("^L -- go to field to left ^R -- go to field to right\n");
6705 addstr("^U -- move upward to field ^D -- move downward to field\n");
6706 addstr("^W -- go to next word ^B -- go to previous word\n");
6707 addstr("^S -- go to start of field ^E -- go to end of field\n");
6708 addstr("^H -- delete previous char ^Y -- delete line\n");
6709 addstr("^G -- delete current word ^C -- clear to end of line\n");
6710 addstr("^K -- clear to end of field ^X -- clear field\n");
6711 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6713 MvAddStr(4, 57, "Forms Entry Test");
6717 /* describe the form */
6718 memset(f, 0, sizeof(f));
6719 f[n++] = make_label(0, 15, "Sample Form");
6721 f[n++] = make_label(2, 0, "Last Name");
6722 f[n++] = make_field(3, 0, 1, 18, FALSE);
6723 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6725 f[n++] = make_label(2, 20, "First Name");
6726 f[n++] = make_field(3, 20, 1, 12, FALSE);
6727 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6729 f[n++] = make_label(2, 34, "Middle Name");
6730 f[n++] = make_field(3, 34, 1, 12, FALSE);
6731 set_field_type(f[n - 1], fty_middle);
6733 f[n++] = make_label(5, 0, "Comments");
6734 f[n++] = make_field(6, 0, 4, 46, FALSE);
6736 f[n++] = make_label(5, 20, "Password:");
6738 f[n++] = make_field(5, 30, 1, 9, TRUE);
6739 set_field_type(f[n - 1], fty_passwd);
6742 if ((form = new_form(f)) != 0) {
6750 nonl(); /* lets us read ^M's */
6752 switch (form_driver(form, c = form_virtualize(form, w))) {
6754 MvAddStr(5, 57, field_buffer(secure, 1));
6758 case E_UNKNOWN_COMMAND:
6759 finished = my_form_driver(form, c);
6771 for (c = 0; f[c] != 0; c++)
6773 free_fieldtype(fty_middle);
6774 free_fieldtype(fty_passwd);
6778 #ifdef NCURSES_MOUSE_VERSION
6779 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6783 #endif /* USE_LIBFORM */
6785 /****************************************************************************
6789 ****************************************************************************/
6791 #if HAVE_COPYWIN /* ...and overlay, overwrite */
6793 static const int overlap_HEAD = 1;
6794 static const int overlap_FOOT = 6;
6802 getmaxyx(stdscr, y, x);
6803 if (y < 23 || x < 80) {
6804 Cannot("The screen is too small for this test");
6807 int ymax = y - (overlap_HEAD + overlap_FOOT);
6808 int high = ymax / 5; /* equal-sized parts for cross */
6809 int xmax = x - 2; /* margin */
6810 int wide = (xmax / 5) & ~1;
6819 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6820 lmar = (xmax - (5 * wide)) / 2;
6823 result = newwin(3 * high, 3 * wide, tmar, lmar);
6825 result = newwin(3 * high, 3 * wide, tmar + 2 * high, lmar + 2 * wide);
6836 for (row = overlap_HEAD; row < LINES - overlap_FOOT; ++row) {
6843 move_overlap(int shift, WINDOW *win1)
6845 int ymax = getmaxy(stdscr) - (overlap_HEAD + overlap_FOOT);
6846 int high = ymax / 5; /* equal-sized parts for cross */
6848 int xmax1 = getmaxx(win1) + 1;
6849 int lmar1 = (COLS - (5 * (xmax1) / 3)) / 2;
6854 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6856 rc = mvwin(win1, tmar, lmar1 + shift);
6861 fillwin(WINDOW *win, char ch)
6866 getmaxyx(win, y1, x1);
6867 for (y = 0; y < y1; y++) {
6869 for (x = 0; x < x1; x++)
6870 waddch(win, UChar(ch));
6874 #define InCross(x,y, x1,y1) \
6875 (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3)) \
6876 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3))))
6879 crosswin(WINDOW *win, char ch)
6885 getmaxyx(win, y1, x1);
6886 for (y = 0; y < y1; y++) {
6887 for (x = 0; x < x1; x += xw) {
6888 if (InCross(x, y, x1, y1)) {
6890 waddch(win, UChar(ch));
6897 * Match "crosswin()", but using line-drawing characters. This could be done
6898 * a little simpler using box(), but the reason for this example is to test
6899 * hline/vline and addch with line-drawing vs the copy/overlay functions.
6902 crossbox(WINDOW *win)
6907 getmaxyx(win, y1, x1);
6912 mvwhline(win, 0, (xmax / 3), ACS_HLINE, (xmax / 3));
6913 mvwhline(win, ymax / 3, 0, ACS_HLINE, xmax);
6914 mvwhline(win, ((2 * ymax) / 3) - 1, 0, ACS_HLINE, xmax);
6915 mvwhline(win, y1 - 1, (xmax / 3), ACS_HLINE, (xmax / 3));
6917 mvwvline(win, (ymax / 3), 0, ACS_VLINE, (ymax / 3));
6918 mvwvline(win, 0, xmax / 3, ACS_VLINE, ymax);
6919 mvwvline(win, 0, ((2 * xmax) / 3) - 1, ACS_VLINE, ymax);
6920 mvwvline(win, (ymax / 3), x1 - 1, ACS_VLINE, (ymax / 3));
6922 mvwaddch(win, 0, (xmax / 3), ACS_ULCORNER);
6923 mvwaddch(win, 0, ((2 * xmax) / 3) - 1, ACS_URCORNER);
6924 mvwaddch(win, y1 - 1, (xmax / 3), ACS_LLCORNER);
6925 mvwaddch(win, y1 - 1, ((2 * xmax) / 3) - 1, ACS_LRCORNER);
6927 mvwaddch(win, (ymax / 3), 0, ACS_ULCORNER);
6928 mvwaddch(win, ((2 * ymax) / 3) - 1, 0, ACS_LLCORNER);
6929 mvwaddch(win, (ymax / 3), x1 - 1, ACS_URCORNER);
6930 mvwaddch(win, ((2 * ymax) / 3) - 1, x1 - 1, ACS_LRCORNER);
6932 mvwaddch(win, (ymax / 3), (xmax / 3), ACS_PLUS);
6933 mvwaddch(win, (ymax / 3), ((2 * xmax) / 3) - 1, ACS_PLUS);
6934 mvwaddch(win, ((2 * ymax) / 3) - 1, ((2 * xmax) / 3) - 1, ACS_PLUS);
6935 mvwaddch(win, ((2 * ymax) / 3) - 1, (xmax / 3), ACS_PLUS);
6946 #define OVERLAP_FLAVORS 6
6955 #define LimitFILL() UseColors ? 4 : 2
6958 otDRAW_text_cross = 0
6965 #define LimitDRAW() UseColors ? 5 : 3
6968 otCOPY_overwrite = 0
6974 #define LimitCOPY() 4
6977 overlap_helpitem(int state, int item, char *message)
6979 int row = (item / 2);
6980 int col = ((item % 2) ? COLS / 2 : 0);
6982 move(LINES - 6 + row, col);
6983 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6988 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6990 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6992 switch ((otFILL) flavor) {
6994 (void) wattrset(win, A_NORMAL);
6997 (void) wattrset(win, A_BOLD);
7000 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
7001 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
7004 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
7005 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
7011 overlap_test_2_attr(WINDOW *win, int flavor, int col)
7013 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
7015 switch ((otDRAW) flavor) {
7016 case otDRAW_text_cross:
7019 case otDRAW_line_box:
7022 case otDRAW_line_cross:
7026 init_pair(cpair, COLOR_RED, COLOR_GREEN);
7027 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
7029 case otDRAW_reset_bg:
7030 wbkgdset(win, ' ' | A_NORMAL);
7036 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
7039 int limit[OVERLAP_FLAVORS];
7043 state += OVERLAP_FLAVORS;
7044 state = state % OVERLAP_FLAVORS;
7045 assert(state >= 0 && state < OVERLAP_FLAVORS);
7047 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
7050 const char *ths = col ? "B" : "A";
7051 const char *tht = col ? "A" : "B";
7053 switch ((otBASE) row) {
7054 case otBASE_refresh:
7057 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7058 "refresh %s, then %s, then doupdate.", ths, tht);
7061 limit[row] = LimitFILL();
7062 flavors[row] %= limit[row];
7063 overlap_test_1_attr(stdscr, flavors[row], col);
7064 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7065 "fill window %s with letter %s.", ths, ths);
7068 limit[row] = LimitDRAW();
7069 flavors[row] %= limit[row];
7070 switch ((otDRAW) flavors[row]) {
7071 case otDRAW_text_cross:
7072 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7073 "cross text-pattern in window %s.", ths);
7075 case otDRAW_line_box:
7076 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7077 "draw line-box in window %s.", ths);
7079 case otDRAW_line_cross:
7080 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7081 "draw line-cross in window %s.", ths);
7084 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7085 "set background of window %s.", ths);
7087 case otDRAW_reset_bg:
7088 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7089 "reset background of window %s.", ths);
7096 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7097 "clear window %s.", ths);
7100 limit[row] = LimitCOPY();
7101 flavors[row] %= limit[row];
7102 switch ((otCOPY) flavors[row]) {
7103 case otCOPY_overwrite:
7104 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7105 "overwrite %s onto %s.", ths, tht);
7108 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7109 "copywin(FALSE) %s onto %s.", ths, tht);
7112 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7113 "copywin(TRUE) %s onto %s.", ths, tht);
7115 case otCOPY_overlay:
7116 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7117 "overlay %s onto %s.", ths, tht);
7122 overlap_helpitem(state, item, msg);
7123 (void) wattrset(stdscr, A_NORMAL);
7124 wbkgdset(stdscr, ' ' | A_NORMAL);
7127 printw("^Q/ESC = terminate test. </> shift. Up/down/space select (row %d",
7129 if (limit[state] > 1)
7130 printw(" test %d:%d", 1 + flavors[state], limit[state]);
7138 overlap_test_0(WINDOW *a, WINDOW *b)
7148 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
7150 overlap_test_1_attr(a, flavor, col);
7152 (void) wattrset(a, A_NORMAL);
7156 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
7158 overlap_test_2_attr(a, flavor, col);
7159 switch ((otDRAW) flavor) {
7160 case otDRAW_text_cross:
7163 case otDRAW_line_box:
7166 case otDRAW_line_cross:
7170 /* done in overlap_test_2_attr */
7172 case otDRAW_reset_bg:
7173 /* done in overlap_test_2_attr */
7179 overlap_test_3(WINDOW *a)
7186 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
7188 switch ((otCOPY) flavor) {
7189 case otCOPY_overwrite:
7193 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
7196 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
7198 case otCOPY_overlay:
7204 /* test effects of overlapping windows */
7206 overlap_test(bool recur GCC_UNUSED)
7208 WINDOW *win1, *win2;
7210 int shift = 0, last_refresh = -1;
7211 int state, flavor[OVERLAP_FLAVORS];
7213 if ((win1 = make_overlap(0)) == 0) {
7215 } else if ((win2 = make_overlap(1)) == 0) {
7224 printw("Test wnoutrefresh() for two overlapping windows:");
7226 memset(flavor, 0, sizeof(flavor));
7227 state = overlap_help(0, flavor);
7229 while (!isQuit(ch = Getchar(), TRUE)) {
7231 case 'a': /* refresh window A first, then B */
7232 overlap_test_0(win1, win2);
7235 case 'b': /* refresh window B first, then A */
7236 overlap_test_0(win2, win1);
7239 case 'c': /* fill window A so it's visible */
7240 overlap_test_1(flavor[otBASE_fill], 0, win1, 'A');
7243 case 'd': /* fill window B so it's visible */
7244 overlap_test_1(flavor[otBASE_fill], 1, win2, 'B');
7247 case 'e': /* cross test pattern in window A */
7248 overlap_test_2(flavor[otBASE_draw], 0, win1, 'A');
7251 case 'f': /* cross test pattern in window A */
7252 overlap_test_2(flavor[otBASE_draw], 1, win2, 'B');
7255 case 'g': /* clear window A */
7256 overlap_test_3(win1);
7259 case 'h': /* clear window B */
7260 overlap_test_3(win2);
7263 case 'i': /* overwrite A onto B */
7264 overlap_test_4(flavor[otBASE_copy], win1, win2);
7267 case 'j': /* overwrite B onto A */
7268 overlap_test_4(flavor[otBASE_copy], win2, win1);
7273 state = overlap_help(state + 1, flavor);
7278 state = overlap_help(state - 1, flavor);
7283 state = overlap_help(state, flavor);
7287 state = overlap_help(state, flavor);
7312 if (move_overlap(shift, win1) != OK) {
7314 shift += (ch == '>') ? -1 : 1;
7315 } else if (last_refresh > 0) {
7317 wnoutrefresh(stdscr);
7318 if (last_refresh == 'a')
7319 overlap_test_0(win1, win2);
7321 overlap_test_0(win2, win1);
7337 #if USE_WIDEC_SUPPORT
7339 x_fillwin(WINDOW *win, wchar_t ch)
7344 getmaxyx(win, y1, x1);
7346 for (y = 0; y < y1; y++) {
7348 for (x = 0; x < x1; x++)
7349 waddnwstr(win, &ch, 1);
7354 x_crosswin(WINDOW *win, wchar_t ch)
7360 getmaxyx(win, y1, x1);
7361 for (y = 0; y < y1; y++) {
7362 for (x = 0; x < x1; x += xw) {
7363 if (InCross(x, y, x1, y1)) {
7365 waddnwstr(win, &ch, 1);
7372 x_overlap_test_1(int flavor, int col, WINDOW *a, wchar_t fill)
7374 overlap_test_1_attr(a, flavor, col);
7376 (void) wattrset(a, A_NORMAL);
7380 x_overlap_test_2(int flavor, int col, WINDOW *a, wchar_t fill)
7382 overlap_test_2_attr(a, flavor, col);
7383 switch ((otDRAW) flavor) {
7384 case otDRAW_text_cross:
7385 x_crosswin(a, fill);
7387 case otDRAW_line_box:
7390 case otDRAW_line_cross:
7394 /* done in overlap_test_2_attr */
7396 case otDRAW_reset_bg:
7397 /* done in overlap_test_2_attr */
7402 /* test effects of overlapping windows */
7404 x_overlap_test(bool recur GCC_UNUSED)
7406 const wchar_t WIDE_A = 0xff21;
7407 const wchar_t WIDE_B = 0xff22;
7408 WINDOW *win1, *win2;
7410 int shift = 0, last_refresh = -1;
7411 int state, flavor[OVERLAP_FLAVORS];
7413 if ((win1 = make_overlap(0)) == 0) {
7415 } else if ((win2 = make_overlap(1)) == 0) {
7424 printw("Test wnoutrefresh() for overlapping windows with double-cell characters:");
7426 memset(flavor, 0, sizeof(flavor));
7427 state = overlap_help(0, flavor);
7429 while (!isQuit(ch = Getchar(), TRUE)) {
7431 case 'a': /* refresh window A first, then B */
7432 overlap_test_0(win1, win2);
7435 case 'b': /* refresh window B first, then A */
7436 overlap_test_0(win2, win1);
7439 case 'c': /* fill window A so it's visible */
7440 x_overlap_test_1(flavor[otBASE_fill], 0, win1, WIDE_A);
7443 case 'd': /* fill window B so it's visible */
7444 x_overlap_test_1(flavor[otBASE_fill], 1, win2, WIDE_B);
7447 case 'e': /* cross test pattern in window A */
7448 x_overlap_test_2(flavor[otBASE_draw], 0, win1, WIDE_A);
7451 case 'f': /* cross test pattern in window A */
7452 x_overlap_test_2(flavor[otBASE_draw], 1, win2, WIDE_B);
7455 case 'g': /* clear window A */
7456 overlap_test_3(win1);
7459 case 'h': /* clear window B */
7460 overlap_test_3(win2);
7463 case 'i': /* overwrite A onto B */
7464 overlap_test_4(flavor[otBASE_copy], win1, win2);
7467 case 'j': /* overwrite B onto A */
7468 overlap_test_4(flavor[otBASE_copy], win2, win1);
7473 state = overlap_help(state + 1, flavor);
7478 state = overlap_help(state - 1, flavor);
7483 state = overlap_help(state, flavor);
7487 state = overlap_help(state, flavor);
7512 if (move_overlap(shift, win1) != OK) {
7514 shift += (ch == '>') ? -1 : 1;
7515 } else if (last_refresh > 0) {
7517 wnoutrefresh(stdscr);
7518 if (last_refresh == 'a')
7519 overlap_test_0(win1, win2);
7521 overlap_test_0(win2, win1);
7536 #endif /* USE_WIDEC_SUPPORT */
7538 #endif /* HAVE_COPYWIN */
7541 show_setting_name(const char *name)
7543 printw("%-25s ", name);
7547 show_string_setting(const char *name, const char *value)
7549 show_setting_name(name);
7551 printw("\"%s\"", value);
7561 show_number_setting(const char *name, int value)
7563 show_setting_name(name);
7565 printw("%d", value);
7568 printw("%d", value);
7575 show_boolean_setting(const char *name, int value)
7577 show_setting_name(name);
7579 printw("%s", value ? "TRUE" : "FALSE");
7582 printw("%d", value);
7589 settings_test(bool recur GCC_UNUSED)
7591 #if USE_WIDEC_SUPPORT
7596 show_string_setting("termname", termname());
7597 show_string_setting("longname", longname());
7598 show_number_setting("baudrate", baudrate());
7599 if (erasechar() > 0) {
7600 show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
7601 show_string_setting("keyname(erasechar)", keyname(erasechar()));
7603 if (killchar() > 0) {
7604 show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
7605 show_string_setting("keyname(killchar)", keyname(killchar()));
7607 #if USE_WIDEC_SUPPORT
7608 if (erasewchar(&ch) == OK) {
7609 show_string_setting("key_name(erasewchar)", key_name(ch));
7611 if (killwchar(&ch) == OK) {
7612 show_string_setting("key_name(killwchar)", key_name(ch));
7615 show_boolean_setting("has_ic", has_ic());
7616 show_boolean_setting("has_il", has_il());
7617 show_boolean_setting("has_colors", has_colors());
7618 #if HAVE_COLOR_CONTENT
7619 show_boolean_setting("can_change_color", can_change_color());
7621 show_setting_name("LINES"); printw("%d\n", LINES);
7622 show_setting_name("COLS"); printw("%d\n", COLS);
7629 /****************************************************************************
7633 ****************************************************************************/
7638 static const char *const tbl[] =
7640 "Usage: ncurses [options]"
7643 #ifdef NCURSES_VERSION
7644 ," -a f,b set default-colors (assumed white-on-black)"
7645 ," -d use default-colors if terminal supports them"
7648 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
7651 ," -e fmt specify format for soft-keys test (e)"
7654 ," -f rip-off footer line (can repeat)"
7655 ," -h rip-off header line (can repeat)"
7657 ," -m do not use colors"
7658 #if HAVE_COLOR_CONTENT
7659 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
7662 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
7664 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_NC_WINDOWS)
7665 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
7668 ," -t mask specify default trace-level (may toggle with ^T)"
7670 #if HAVE_COLOR_CONTENT
7671 ," -x use xterm-compatible control for reading color palette"
7675 for (n = 0; n < SIZEOF(tbl); n++)
7676 fprintf(stderr, "%s\n", tbl[n]);
7677 ExitProgram(EXIT_FAILURE);
7681 set_terminal_modes(void)
7686 scrollok(stdscr, TRUE);
7687 idlok(stdscr, TRUE);
7688 keypad(stdscr, TRUE);
7693 announce_sig(int sig)
7695 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
7701 rip_footer(WINDOW *win, int cols)
7703 wbkgd(win, A_REVERSE);
7706 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
7712 rip_header(WINDOW *win, int cols)
7714 wbkgd(win, A_REVERSE);
7717 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
7721 #endif /* HAVE_RIPOFFLINE */
7726 #if USE_WIDEC_SUPPORT
7729 int (*narrow_func) (bool);
7730 int (*wide_func) (bool);
7734 #define BOTH(a) a, x_ ## a
7735 #define ONLY(a) a, NULL
7736 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7740 int (*narrow_func) (bool);
7746 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7749 static MyCmds cmds[] =
7751 CMDS(TRUE, BOTH(getch_test), 'a', "keyboard and mouse input test"),
7752 CMDS(TRUE, BOTH(attr_test), 'b', "character attribute test"),
7753 CMDS(TRUE, BOTH(color_test), 'c', "color test pattern"),
7754 #if HAVE_COLOR_CONTENT
7755 CMDS(FALSE, ONLY(color_edit), 'd', "edit RGB color values"),
7758 CMDS(TRUE, BOTH(slk_test), 'e', "exercise soft keys"),
7760 CMDS(TRUE, BOTH(acs_test), 'f', "display ACS characters"),
7761 CMDS(TRUE, ONLY(scroll_test), 'g', "display windows and scrolling"),
7762 CMDS(TRUE, ONLY(flushinp_test), 'i', "test flushinp()"),
7763 CMDS(TRUE, ONLY(sgr_attr_test), 'k', "display character attributes"),
7765 CMDS(TRUE, ONLY(menu_test), 'm', "exercise menu library"),
7768 CMDS(TRUE, BOTH(panel_test), 'o', "exercise panel library"),
7771 CMDS(TRUE, ONLY(pad_test), 'p', "exercise pad features"),
7773 CMDS(TRUE, ONLY(NULL), 'q', "quit"),
7775 CMDS(TRUE, ONLY(form_test), 'r', "exercise form library"),
7778 CMDS(TRUE, BOTH(overlap_test), 's', "overlapping-refresh test"),
7780 #if USE_LIBMENU && defined(TRACE)
7781 CMDS(TRUE, ONLY(trace_set), 't', "set trace level"),
7783 CMDS(TRUE, ONLY(settings_test), 'v', "show terminal name and settings"),
7784 CMDS(FALSE, ONLY(NULL), '?', "repeat this command summary")
7792 printf("This is the ncurses main menu (uppercase for wide-characters)\n");
7793 for (n = 0; n < SIZEOF(cmds); ++n) {
7794 if (top || cmds[n].recur) {
7796 #if USE_WIDEC_SUPPORT
7797 if (cmds[n].wide_func) {
7798 printf("%c,", toupper(cmds[n].code));
7801 printf("%c\t= %s\n", cmds[n].code, cmds[n].help);
7805 (void) fputs("> ", stdout);
7806 (void) fflush(stdout); /* necessary under SVr4 curses */
7809 * This used to be an 'fgets()' call (until 1996/10). However with
7810 * some runtime libraries, mixing stream I/O and 'read()' causes the
7811 * input stream to be flushed when switching between the two.
7816 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7817 int save_err = errno;
7819 if (save_err == EINTR) {
7822 } else if (command == 0) {
7826 } else if (command == 0 && !isspace(UChar(ch))) {
7828 } else if (ch == '\n' || ch == '\r') {
7829 if ((command == 'd') && !top) {
7830 (void) fputs("Do not nest test-d\n", stdout);
7835 (void) fputs("> ", stdout);
7836 (void) fflush(stdout);
7841 for (n = 0; n < SIZEOF(cmds); ++n) {
7842 if (cmds[n].code == command) {
7843 doit = cmds[n].narrow_func;
7846 #if USE_WIDEC_SUPPORT
7847 if (toupper(cmds[n].code) == command) {
7848 doit = cmds[n].wide_func;
7854 if (doit != NULL && doit(FALSE) == OK) {
7856 * This may be overkill; it's intended to reset everything back
7857 * to the initial terminal modes so that tests don't get in
7861 set_terminal_modes();
7866 if (command == '?') {
7867 (void) puts("This is the ncurses capability tester.");
7869 puts("You may select a test from the main menu by typing the");
7871 puts("key letter of the choice (the letter to left of the =)");
7873 puts("at the > prompt. Type `q' to exit.");
7881 /*+-------------------------------------------------------------------------
7883 --------------------------------------------------------------------------*/
7886 main(int argc, char *argv[])
7890 #ifdef NCURSES_VERSION_PATCH
7891 #if HAVE_USE_DEFAULT_COLORS
7892 int default_fg = COLOR_WHITE;
7893 int default_bg = COLOR_BLACK;
7894 bool default_colors = FALSE;
7895 #if HAVE_ASSUME_DEFAULT_COLORS
7896 bool assumed_colors = FALSE;
7900 bool monochrome = FALSE;
7901 #if HAVE_COLOR_CONTENT
7902 bool xterm_colors = FALSE;
7903 char *palette_file = 0;
7906 setlocale(LC_ALL, "");
7908 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) {
7910 #ifdef NCURSES_VERSION_PATCH
7911 #if HAVE_USE_DEFAULT_COLORS
7912 #if HAVE_ASSUME_DEFAULT_COLORS
7914 assumed_colors = TRUE;
7915 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7917 default_fg = COLOR_WHITE;
7920 default_bg = COLOR_BLACK;
7926 default_colors = TRUE;
7936 my_e_param = atoi(optarg);
7937 #ifdef NCURSES_VERSION
7938 if (my_e_param > 3) /* allow extended layouts */
7947 ripoffline(-1, rip_footer);
7950 ripoffline(1, rip_header);
7952 #endif /* HAVE_RIPOFFLINE */
7956 #if HAVE_COLOR_CONTENT
7958 palette_file = optarg;
7963 nap_msec = (int) atol(optarg);
7966 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_NC_WINDOWS)
7973 save_trace = (unsigned) strtol(optarg, 0, 0);
7976 #if HAVE_COLOR_CONTENT
7978 xterm_colors = TRUE;
7987 * If there's no menus (unlikely for ncurses!), then we'll have to set
7988 * tracing on initially, just in case the user wants to test something that
7989 * doesn't involve wGetchar.
7992 /* enable debugging */
7994 curses_trace(save_trace);
7996 if (!isatty(fileno(stdin)))
7997 curses_trace(save_trace);
7998 #endif /* USE_LIBMENU */
8002 /* tell it we're going to play with soft keys */
8003 slk_init(my_e_param);
8007 /* set up null signal catcher so we can see what interrupts to getch do */
8008 signal(SIGUSR1, announce_sig);
8011 /* we must initialize the curses data structure only once */
8015 set_terminal_modes();
8018 /* tests, in general, will want these modes */
8019 UseColors = (bool) (monochrome ? FALSE : has_colors());
8023 #ifdef NCURSES_VERSION_PATCH
8024 MaxColors = COLORS; /* was > 16 ? 16 : COLORS */
8025 #if HAVE_USE_DEFAULT_COLORS
8026 if (default_colors) {
8027 use_default_colors();
8030 #if HAVE_ASSUME_DEFAULT_COLORS
8032 assume_default_colors(default_fg, default_bg);
8035 #else /* normal SVr4 curses */
8036 MaxColors = COLORS; /* was > 8 ? 8 : COLORS */
8038 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
8040 #if HAVE_COLOR_CONTENT
8041 if (can_change_color()) {
8042 init_all_colors(xterm_colors, palette_file);
8048 * Return to terminal mode, so we're guaranteed of being able to
8049 * select terminal commands even if the capabilities are wrong.
8053 #if HAVE_CURSES_VERSION
8054 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
8055 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
8056 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
8057 NCURSES_VERSION_MAJOR,
8058 NCURSES_VERSION_MINOR,
8059 NCURSES_VERSION_PATCH);
8061 (void) puts("Welcome to ncurses. Press ? for help.");
8066 ExitProgram(EXIT_SUCCESS);
8069 /* ncurses.c ends here */