1 /****************************************************************************
2 * Copyright 2018-2021,2022 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.528 2022/02/26 22:41:02 tom 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 GCC_NORETURN void failed(const char *s);
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, "wgetnstr 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, "wgetn_str 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) {
2892 } else if (sscanf(buffer, "%d:%d %d %d",
2901 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2902 all_colors[c].red = Scaled(red);
2903 all_colors[c].green = Scaled(green);
2904 all_colors[c].blue = Scaled(blue);
2912 #define scaled_rgb(n) ((255 * (n)) / 1000)
2915 color_edit(bool recur GCC_UNUSED)
2916 /* display the color test pattern, without trying to edit colors */
2920 int this_c, value, field;
2926 Cannot("does not support color.");
2928 } else if (!can_change_color()) {
2929 Cannot("has hardwired color values.");
2942 page_size = (LINES - 6);
2945 for (i = 0; i < MaxColors; i++)
2946 init_pair((NCURSES_PAIRS_T) i,
2947 (NCURSES_COLOR_T) COLOR_WHITE,
2948 (NCURSES_COLOR_T) i);
2950 MvPrintw(LINES - 2, 0, "Number: %d", value);
2953 NCURSES_COLOR_T red, green, blue;
2956 MvAddStr(0, 20, "Color RGB Value Editing");
2959 for (i = (NCURSES_COLOR_T) top_color;
2960 (i - top_color < page_size)
2961 && (i < MaxColors); i++) {
2964 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2965 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2966 (i == current ? '>' : ' '),
2967 (i < (int) SIZEOF(the_color_names)
2968 ? the_color_names[i] : numeric));
2969 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2971 (void) attrset(A_NORMAL);
2973 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2975 if (current == i && field == 0)
2977 printw("%04d", (int) red);
2978 if (current == i && field == 0)
2979 (void) attrset(A_NORMAL);
2981 if (current == i && field == 1)
2983 printw("%04d", (int) green);
2984 if (current == i && field == 1)
2985 (void) attrset(A_NORMAL);
2987 if (current == i && field == 2)
2989 printw("%04d", (int) blue);
2990 if (current == i && field == 2)
2991 (void) attrset(A_NORMAL);
2992 (void) attrset(A_NORMAL);
2993 printw(" ( %3d %3d %3d )",
2994 (int) scaled_rgb(red),
2995 (int) scaled_rgb(green),
2996 (int) scaled_rgb(blue));
2999 MvAddStr(LINES - 3, 0,
3000 "Use up/down to select a color, left/right to change fields.");
3001 MvAddStr(LINES - 2, 0,
3002 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
3004 move(2 + current - top_color, 0);
3008 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
3030 current -= (page_size - 1);
3037 if (current < (MaxColors - 1))
3038 current += (page_size - 1);
3045 current = (current == 0 ? (MaxColors - 1) : current - 1);
3050 current = (current == (MaxColors - 1) ? 0 : current + 1);
3055 field = (field == 2 ? 0 : field + 1);
3060 field = (field == 0 ? 2 : field - 1);
3073 value = value * 10 + (this_c - '0');
3077 change_color((NCURSES_PAIRS_T) current, field, value, 1);
3081 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
3085 change_color((NCURSES_PAIRS_T) current, field, value, 0);
3090 P(" RGB Value Editing Help");
3092 P("You are in the RGB value editor. Use the arrow keys to select one of");
3093 P("the fields in one of the RGB triples of the current colors; the one");
3094 P("currently selected will be reverse-video highlighted.");
3096 P("To change a field, enter the digits of the new value; they are echoed");
3097 P("as entered. Finish by typing `='. The change will take effect instantly.");
3098 P("To increment or decrement a value, use the same procedure, but finish");
3099 P("with a `+' or `-'.");
3101 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3103 P("Press 'm' to invoke the top-level menu with the current color settings.");
3104 P("To quit, do ESC");
3113 for (i = 0; i < MaxColors; i++)
3114 init_pair((NCURSES_PAIRS_T) i,
3115 (NCURSES_COLOR_T) COLOR_WHITE,
3116 (NCURSES_COLOR_T) i);
3130 if (current >= MaxColors)
3131 current = MaxColors - 1;
3132 if (current < top_color)
3133 top_color = current;
3134 if (current - top_color >= page_size)
3135 top_color = current - (page_size - 1);
3137 MvPrintw(LINES - 1, 0, "Number: %d", value);
3140 (!isQuit(this_c, TRUE));
3145 * ncurses does not reset each color individually when calling endwin().
3152 #endif /* HAVE_COLOR_CONTENT */
3154 /****************************************************************************
3156 * Alternate character-set stuff
3158 ****************************************************************************/
3160 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3166 if ((*at_code += 1) >= limit)
3171 *at_code = limit - 1;
3180 *attr = list[*at_code].attr;
3184 #if USE_WIDEC_SUPPORT
3186 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3192 if ((*at_code += 1) >= limit)
3197 *at_code = limit - 1;
3206 *attr = list[*at_code].attr;
3212 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3214 bool result = FALSE;
3224 if ((*fg += 1) >= COLORS)
3232 if ((*bg += 1) >= COLORS)
3240 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3243 if (init_pair(*pair,
3244 (NCURSES_COLOR_T) *fg,
3245 (NCURSES_COLOR_T) *bg) == ERR) {
3254 /****************************************************************************
3256 * Soft-key label test
3258 ****************************************************************************/
3263 #define SLK_WORK (SLK_HELP + 3)
3268 static const char *table[] =
3270 "Available commands are:"
3272 ,"^L -- repaint this message and activate soft keys"
3273 ,"a/d -- activate/disable soft keys"
3274 ,"c -- set centered format for labels"
3275 ,"l -- set left-justified format for labels"
3276 ,"r -- set right-justified format for labels"
3277 ,"[12345678] -- set label; labels are numbered 1 through 8"
3278 ,"e -- erase stdscr (should not erase labels)"
3279 ,"s -- test scrolling of shortened screen"
3280 ,"v/V -- cycle through video attributes"
3282 ,"F/f/B/b -- cycle through foreground/background colors"
3284 ,"ESC -- return to main menu"
3286 ,"Note: if activating the soft keys causes your terminal to scroll up"
3287 ,"one line, your terminal auto-scrolls when anything is written to the"
3288 ,"last screen position. The ncurses code does not yet handle this"
3294 for (j = 0; j < SIZEOF(table); ++j) {
3302 call_slk_color(int fg, int bg)
3304 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3306 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3315 slk_test(bool recur GCC_UNUSED)
3316 /* exercise the soft keys */
3321 chtype attr = A_NORMAL;
3322 unsigned at_code = 0;
3324 int fg = COLOR_BLACK;
3325 int bg = COLOR_WHITE;
3326 NCURSES_PAIRS_T pair = 0;
3328 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3329 unsigned my_size = init_attr_list(my_list, termattrs());
3334 call_slk_color(fg, bg);
3344 MvAddStr(0, 20, "Soft Key Exerciser");
3359 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3360 while ((c = Getchar()) != 'Q' && (c != ERR))
3388 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3389 _nc_STRCPY(buf, "", sizeof(buf));
3390 if ((s = slk_label(c - '0')) != 0) {
3391 _nc_STRNCPY(buf, s, (size_t) 8);
3393 wGetstring(stdscr, buf, 8);
3394 slk_set((c - '0'), buf, fmt);
3403 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3405 wnoutrefresh(stdscr);
3410 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3417 if (cycle_colors(c, &fg, &bg, &pair)) {
3419 call_slk_color(fg, bg);
3429 } while (!isQuit(c = Getchar(), TRUE));
3438 #if USE_WIDEC_SUPPORT
3441 x_slk_test(bool recur GCC_UNUSED)
3442 /* exercise the soft keys */
3445 wchar_t buf[SLKLEN + 1];
3447 attr_t attr = WA_NORMAL;
3448 unsigned at_code = 0;
3449 int fg = COLOR_BLACK;
3450 int bg = COLOR_WHITE;
3451 NCURSES_PAIRS_T pair = 0;
3452 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3453 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3457 call_slk_color(fg, bg);
3464 attr_on(WA_BOLD, NULL);
3465 MvAddStr(0, 20, "Soft Key Exerciser");
3466 attr_off(WA_BOLD, NULL);
3480 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3481 while ((c = Getchar()) != 'Q' && (c != ERR))
3509 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3511 if ((s = slk_label(c - '0')) != 0) {
3512 char *temp = strdup(s);
3513 size_t used = strlen(temp);
3514 size_t want = SLKLEN;
3515 #ifndef state_unused
3520 while (want > 0 && used != 0) {
3522 const char *base = s;
3524 reset_mbytes(state);
3525 test = count_mbytes(base, 0, &state);
3526 if (test == (size_t) -1) {
3528 } else if (test > want) {
3531 reset_mbytes(state);
3532 trans_mbytes(buf, base, want, &state);
3538 wGet_wstring(stdscr, buf, SLKLEN);
3539 slk_wset((c - '0'), buf, fmt);
3550 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3551 call_slk_color(fg, bg);
3556 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3557 call_slk_color(fg, bg);
3560 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3562 wnoutrefresh(stdscr);
3566 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3567 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3573 if (cycle_colors(c, &fg, &bg, &pair)) {
3575 call_slk_color(fg, bg);
3585 } while (!isQuit(c = Getchar(), TRUE));
3594 #endif /* SLK_INIT */
3597 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3600 unsigned last = 255;
3606 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3611 for (code = first; code <= last; ++code) {
3612 int row = (int) (2 + (code / 16));
3613 int col = (int) (5 * (code % 16));
3614 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3615 for (count = 1; count < repeat; ++count) {
3616 AddCh(colored_chtype(code, attr, pair));
3623 * Show a slice of 32 characters, allowing those to be repeated up to the
3626 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3627 * terminal to perform functions. The remaining codes can be graphic.
3630 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3633 unsigned first = (unsigned) base;
3634 unsigned last = first + (unsigned) pagesize - 2;
3635 bool C1 = (first == 128);
3640 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3641 C1 ? "C1" : "GR", first, last);
3645 for (code = first; code <= last; code++) {
3647 int row = 2 + ((int) (code - first) % (pagesize / 2));
3648 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3650 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3651 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3655 nodelay(stdscr, TRUE);
3656 echochar(colored_chtype(code, attr, pair));
3658 /* (yes, this _is_ crude) */
3659 while ((reply = Getchar()) != ERR) {
3660 AddCh(UChar(reply));
3663 nodelay(stdscr, FALSE);
3665 } while (--count > 0);
3672 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3678 MvPrintw(0, 20, "Display of PC Character Codes");
3682 for (code = 0; code < 16; ++code) {
3683 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3685 for (code = 0; code < 256; code++) {
3687 int row = 3 + (int) (code / 16) + (code >= 128);
3688 int col = 8 + (int) (code % 16) * PC_COLS;
3689 if ((code % 16) == 0)
3690 MvPrintw(row, 0, "0x%02x:", code);
3701 * Skip the ones that do not work.
3705 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3708 } while (--count > 0);
3713 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3717 attr |= (attr_t) COLOR_PAIR(pair);
3721 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3726 colored_chtype(ACS_VLINE, attr, pair),
3727 colored_chtype(ACS_VLINE, attr, pair),
3728 colored_chtype(ACS_HLINE, attr, pair),
3729 colored_chtype(ACS_HLINE, attr, pair),
3730 colored_chtype(ACS_ULCORNER, attr, pair),
3731 colored_chtype(ACS_URCORNER, attr, pair),
3732 colored_chtype(ACS_LLCORNER, attr, pair),
3733 colored_chtype(ACS_LRCORNER, attr, pair));
3734 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3735 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3736 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3737 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3738 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3739 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3740 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3745 show_1_acs(int n, int repeat, const char *name, chtype code)
3747 const int height = 16;
3748 int row = 2 + (n % height);
3749 int col = (n / height) * COLS / 2;
3751 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3754 } while (--repeat > 0);
3759 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3760 /* display the ACS character set */
3764 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3768 MvAddStr(0, 20, "Display of the ACS Character Set");
3772 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3773 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3774 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3775 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3777 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3778 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3779 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3780 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3782 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3783 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3786 * HPUX's ACS definitions are broken here. Just give up.
3788 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3789 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3790 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3791 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3792 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3794 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3795 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3796 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3797 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3798 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3799 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3800 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3801 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3802 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3804 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3805 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3806 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3808 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3809 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3810 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3811 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3812 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3813 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3819 acs_test(bool recur GCC_UNUSED)
3823 char *term = getenv("TERM");
3824 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3827 chtype attr = A_NORMAL;
3830 int fg = COLOR_BLACK;
3831 int bg = COLOR_BLACK;
3832 unsigned at_code = 0;
3833 NCURSES_PAIRS_T pair = 0;
3834 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3835 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3836 unsigned my_size = init_attr_list(my_list, termattrs());
3844 ToggleAcs(last_show_acs, show_acs_chars);
3848 ToggleAcs(last_show_acs, show_pc_chars);
3853 if (pagesize == 32) {
3860 ToggleAcs(last_show_acs, show_box_chars);
3886 if (repeat < (COLS / 4))
3894 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3895 || cycle_colors(c, &fg, &bg, &pair)) {
3902 if (pagesize != 32) {
3903 show_256_chars(repeat, attr, pair);
3904 } else if (last_show_acs != 0) {
3905 last_show_acs(repeat, attr, pair);
3907 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3910 MvPrintw(LINES - 3, 0,
3911 "Note: ANSI terminals may not display C1 characters.");
3912 MvPrintw(LINES - 2, 0,
3913 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3916 MvPrintw(LINES - 1, 0,
3917 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3918 my_list[at_code].name,
3921 MvPrintw(LINES - 1, 0,
3922 "v/V cycles through video attributes (%s).",
3923 my_list[at_code].name);
3926 } while (!isQuit(c = Getchar(), TRUE));
3934 #if USE_WIDEC_SUPPORT
3936 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3942 TEST_CCHAR(src, count, {
3943 attr |= (test_attrs & A_ALTCHARSET);
3944 setcchar(dst, test_wch, attr, pair, NULL);
3953 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3954 * display. If there are no repeats, we could normally display 16 lines of 64
3955 * characters (1024 total). However, taking repeats and double-width cells
3956 * into account, use 256 characters for the page.
3959 show_paged_widechars(unsigned base,
3964 NCURSES_PAIRS_T pair)
3966 unsigned first = base * pagesize;
3967 unsigned last = first + pagesize - 1;
3975 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3978 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
3979 int row = (2 + (int) (code - (wchar_t) first) / per_line);
3980 int col = 5 * ((int) code % per_line);
3983 memset(&codes, 0, sizeof(codes));
3985 setcchar(&temp, codes, attr, pair, 0);
3987 if (wcwidth(code) == 0 && code != 0) {
3988 AddCh((chtype) space |
3989 (A_REVERSE ^ attr) |
3990 (attr_t) COLOR_PAIR(pair));
3993 for (count = 1; count < repeat; ++count) {
4000 show_upper_widechars(unsigned first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
4004 unsigned last = first + 31;
4008 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
4011 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
4012 int row = 2 + ((int) (code - (wchar_t) first) % 16);
4013 int col = ((int) (code - (wchar_t) first) / 16) * COLS / 2;
4018 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
4019 "%3ld (0x%lx)", (long) code, (long) code);
4020 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
4022 memset(&codes, 0, sizeof(codes));
4024 setcchar(&temp, codes, attr, pair, 0);
4030 * Give non-spacing characters something to combine with. If we
4031 * don't, they'll bunch up in a heap on the space after the ":".
4032 * Mark them with reverse-video to make them simpler to find on
4035 if (wcwidth(code) == 0) {
4036 AddCh((chtype) space |
4037 (A_REVERSE ^ attr) |
4038 (attr_t) COLOR_PAIR(pair));
4041 * This uses echo_wchar(), for comparison with the normal 'f'
4042 * test (and to make a test-case for echo_wchar()). The screen
4043 * may flicker because the erase() at the top of the function
4044 * is met by the builtin refresh() in echo_wchar().
4048 * The repeat-count may make text wrap - avoid that.
4050 getyx(stdscr, y, x);
4052 if (x >= col + (COLS / 2) - 2)
4054 } while (--count > 0);
4059 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
4061 const int height = 16;
4062 int row = 2 + (n % height);
4063 int col = (n / height) * COLS / 2;
4065 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4066 while (--repeat >= 0) {
4072 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
4075 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4076 /* display the wide-ACS character set */
4082 /*#define BOTH2(name) #name, &(name) */
4083 #define BOTH2(name) #name, MERGE_ATTR(name)
4087 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4091 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
4092 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
4093 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
4094 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
4096 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
4097 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
4098 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
4099 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
4101 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4102 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4104 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4105 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4106 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4107 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4109 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4110 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4111 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4114 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4115 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4117 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4119 #ifdef CURSES_WACS_ARRAY
4120 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4121 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4122 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4124 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4125 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4126 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4127 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4128 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4129 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4135 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4136 /* display the wide-ACS character set */
4142 /*#define BOTH2(name) #name, &(name) */
4143 #define BOTH2(name) #name, MERGE_ATTR(name)
4147 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4151 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4152 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4153 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4154 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4156 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4157 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4158 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4159 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4161 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4162 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4164 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4165 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4166 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4167 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4169 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4170 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4171 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4172 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4173 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4174 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4175 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4176 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4177 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4179 #ifdef CURSES_WACS_ARRAY
4180 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4181 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4182 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4184 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4185 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4186 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4187 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4188 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4189 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4196 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4197 /* display the wide-ACS character set */
4203 /*#define BOTH2(name) #name, &(name) */
4204 #define BOTH2(name) #name, MERGE_ATTR(name)
4208 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4212 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4213 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4214 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4215 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4217 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4218 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4219 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4220 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4222 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4223 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4225 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4226 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4227 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4228 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4230 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4231 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4232 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4233 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4234 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4235 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4236 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4237 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4238 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4240 #ifdef CURSES_WACS_ARRAY
4241 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4242 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4243 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4245 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4246 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4247 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4248 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4249 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4250 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4257 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4260 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4267 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4272 MERGE_ATTR(0, WACS_VLINE),
4273 MERGE_ATTR(1, WACS_VLINE),
4274 MERGE_ATTR(2, WACS_HLINE),
4275 MERGE_ATTR(3, WACS_HLINE),
4276 MERGE_ATTR(4, WACS_ULCORNER),
4277 MERGE_ATTR(5, WACS_URCORNER),
4278 MERGE_ATTR(6, WACS_LLCORNER),
4279 MERGE_ATTR(7, WACS_LRCORNER));
4281 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4282 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4283 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4284 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4285 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4286 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4287 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4294 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4296 const int height = 16;
4297 int row = 2 + (n % height);
4298 int col = (n / height) * COLS / 2;
4301 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4302 (void) attr_set(attr, pair, 0);
4303 _nc_STRNCPY(temp, code, 20);
4305 (void) attr_set(A_NORMAL, 0, 0);
4309 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4312 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4319 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4323 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4324 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4325 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4326 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4328 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4329 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4330 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4331 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4333 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4334 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4336 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4337 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4338 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4339 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4341 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4342 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4343 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4344 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4345 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4346 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4347 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4348 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4349 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4350 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4351 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4352 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4354 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4355 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4356 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4357 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4358 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4359 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4363 /* display the wide-ACS character set */
4365 x_acs_test(bool recur GCC_UNUSED)
4371 unsigned pagesize = 32;
4372 attr_t attr = WA_NORMAL;
4373 int fg = COLOR_BLACK;
4374 int bg = COLOR_BLACK;
4375 unsigned at_code = 0;
4376 NCURSES_PAIRS_T pair = 0;
4377 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4378 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4379 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4381 bool pending_code = FALSE;
4390 ToggleAcs(last_show_wacs, show_wacs_chars);
4394 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4399 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4403 if (pagesize == 32) {
4410 ToggleAcs(last_show_wacs, show_wbox_chars);
4413 ToggleAcs(last_show_wacs, show_utf8_chars);
4416 pending_code = !pending_code;
4418 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4419 } else if (at_page[0] != '\0') {
4420 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%x", digit);
4424 if (pending_code && isxdigit(c)) {
4425 size_t len = strlen(at_page);
4426 if (len && at_page[0] == '0') {
4427 memmove(at_page, at_page + 1, len--);
4429 if (len < sizeof(at_page) - 1) {
4430 at_page[len++] = (char) c;
4431 at_page[len] = '\0';
4433 } else if (pending_code
4434 && (c == '\b' || c == KEY_BACKSPACE || c == KEY_DC)) {
4435 size_t len = strlen(at_page);
4437 at_page[--len] = '\0';
4438 } else if (c < 256 && isdigit(c)) {
4439 digit = (unsigned) (c - '0');
4441 } else if (c == '+') {
4443 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4445 } else if (c == '-' && digit > 0) {
4447 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x",
4450 } else if (c == '>' && repeat < (COLS / 4)) {
4452 } else if (c == '<' && repeat > 1) {
4454 } else if (c == '_') {
4455 space = (space == ' ') ? '_' : ' ';
4457 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4458 || cycle_colors(c, &fg, &bg, &pair)) {
4459 if (last_show_wacs != 0)
4467 if (pagesize != 32) {
4468 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4469 } else if (last_show_wacs != 0) {
4470 last_show_wacs(repeat, attr, pair);
4472 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4475 MvPrintw(LINES - 4, 0,
4476 "Select: a/d/t WACS, w=%d/page, @",
4479 pending_code ? at_page : "page");
4480 addstr(", x=box, u UTF-8, ^L repaint");
4481 MvPrintw(LINES - 3, 2,
4482 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4484 MvPrintw(LINES - 2, 2,
4485 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4486 my_list[at_code].name,
4489 MvPrintw(LINES - 2, 2,
4490 "v/V cycles through video attributes (%s).",
4491 my_list[at_code].name);
4494 } while (!isQuit(c = Getchar(), TRUE));
4505 * Graphic-rendition test (adapted from vttest)
4508 sgr_attr_test(bool recur GCC_UNUSED)
4512 for (pass = 0; pass < 2; pass++) {
4513 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4515 /* Use non-default colors if possible to exercise bce a little */
4517 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4518 normal |= (chtype) COLOR_PAIR(1);
4522 MvPrintw(1, 20, "Graphic rendition test pattern:");
4524 MvPrintw(4, 1, "vanilla");
4526 #define set_sgr(mask) bkgdset((normal^(mask)));
4528 MvPrintw(4, 40, "bold");
4530 set_sgr(A_UNDERLINE);
4531 MvPrintw(6, 6, "underline");
4533 set_sgr(A_BOLD | A_UNDERLINE);
4534 MvPrintw(6, 45, "bold underline");
4537 MvPrintw(8, 1, "blink");
4539 set_sgr(A_BLINK | A_BOLD);
4540 MvPrintw(8, 40, "bold blink");
4542 set_sgr(A_UNDERLINE | A_BLINK);
4543 MvPrintw(10, 6, "underline blink");
4545 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4546 MvPrintw(10, 45, "bold underline blink");
4549 MvPrintw(12, 1, "negative");
4551 set_sgr(A_BOLD | A_REVERSE);
4552 MvPrintw(12, 40, "bold negative");
4554 set_sgr(A_UNDERLINE | A_REVERSE);
4555 MvPrintw(14, 6, "underline negative");
4557 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4558 MvPrintw(14, 45, "bold underline negative");
4560 set_sgr(A_BLINK | A_REVERSE);
4561 MvPrintw(16, 1, "blink negative");
4563 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4564 MvPrintw(16, 40, "bold blink negative");
4566 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4567 MvPrintw(18, 6, "underline blink negative");
4569 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4570 MvPrintw(18, 45, "bold underline blink negative");
4573 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4579 bkgdset(A_NORMAL | BLANK);
4585 /****************************************************************************
4587 * Windows and scrolling tester.
4589 ****************************************************************************/
4591 #define BOTLINES 4 /* number of line stolen from screen bottom */
4597 #define FRAME struct frame
4606 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4607 #if (NCURSES_VERSION_PATCH < 20070331)
4608 #define is_keypad(win) (win)->_use_keypad
4609 #define is_scrollok(win) (win)->_scroll
4612 #define is_keypad(win) FALSE
4613 #define is_scrollok(win) FALSE
4617 frame_win(FRAME * curp)
4619 return (curp != 0) ? curp->wind : stdscr;
4622 /* We need to know if these flags are actually set, so don't look in FRAME.
4623 * These names are known to work with SVr4 curses as well as ncurses. The
4624 * _use_keypad name does not work with Solaris 8.
4627 HaveKeypad(FRAME * curp)
4629 WINDOW *win = frame_win(curp);
4631 return is_keypad(win);
4635 HaveScroll(FRAME * curp)
4637 WINDOW *win = frame_win(curp);
4639 return is_scrollok(win);
4643 newwin_legend(FRAME * curp)
4645 #define DATA(num, name) { name, num }
4646 static const struct {
4650 DATA(0, "^C = create window"),
4651 DATA(0, "^N = next window"),
4652 DATA(0, "^P = previous window"),
4653 DATA(0, "^F = scroll forward"),
4654 DATA(0, "^B = scroll backward"),
4655 DATA(1, "^K = keypad(%s)"),
4656 DATA(2, "^S = scrollok(%s)"),
4657 DATA(0, "^W = save window"),
4658 DATA(0, "^R = restore window"),
4660 DATA(0, "^X = resize"),
4662 DATA(3, "^Q%s = exit")
4666 bool do_keypad = HaveKeypad(curp);
4667 bool do_scroll = HaveScroll(curp);
4672 for (n = 0; n < SIZEOF(legend); n++) {
4675 switch (legend[n].code) {
4677 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4680 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4681 legend[n].msg, do_keypad ? "yes" : "no");
4684 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4685 legend[n].msg, do_scroll ? "yes" : "no");
4688 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4689 legend[n].msg, do_keypad ? "/ESC" : "");
4692 x = getcurx(stdscr);
4693 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4700 transient(FRAME * curp, NCURSES_CONST char *msg)
4702 newwin_legend(curp);
4704 MvAddStr(LINES - 1, 0, msg);
4710 printw("%s characters are echoed, window should %sscroll.",
4711 HaveKeypad(curp) ? "Non-arrow" : "All other",
4712 HaveScroll(curp) ? "" : "not ");
4717 newwin_report(FRAME * curp)
4718 /* report on the cursor's current position, then restore it */
4720 WINDOW *win = frame_win(curp);
4724 transient(curp, (char *) 0);
4726 move(LINES - 1, COLS - 17);
4727 printw("Y = %2d X = %2d", y, x);
4735 selectcell(int uli, int ulj, int lri, int lrj)
4736 /* arrows keys move cursor, return location at current on non-arrow key */
4738 static pair res; /* result cell */
4739 int si = lri - uli + 1; /* depth of the select area */
4740 int sj = lrj - ulj + 1; /* width of the select area */
4741 int i = 0, j = 0; /* offsets into the select area */
4746 move(uli + i, ulj + j);
4747 newwin_report((FRAME *) 0);
4749 switch (Getchar()) {
4763 return ((pair *) 0);
4764 #ifdef NCURSES_MOUSE_VERSION
4770 if (event.y > uli && event.x > ulj) {
4791 outerbox(pair ul, pair lr, bool onoff)
4792 /* draw or erase a box *outside* the given pair of corners */
4794 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4795 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4796 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4797 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4798 move(ul.y - 1, ul.x);
4799 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4800 move(ul.y, ul.x - 1);
4801 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4802 move(lr.y + 1, ul.x);
4803 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4804 move(ul.y, lr.x + 1);
4805 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4810 /* Ask user for a window definition */
4817 addstr("Use arrows to move cursor, anything else to mark corner 1");
4819 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4820 return ((WINDOW *) 0);
4821 memcpy(&ul, tmp, sizeof(pair));
4822 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4825 addstr("Use arrows to move cursor, anything else to mark corner 2");
4827 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4829 return ((WINDOW *) 0);
4830 memcpy(&lr, tmp, sizeof(pair));
4832 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4834 outerbox(ul, lr, TRUE);
4846 newwin_move(FRAME * curp, int dy, int dx)
4848 WINDOW *win = frame_win(curp);
4852 getyx(win, cur_y, cur_x);
4853 getmaxyx(win, max_y, max_x);
4854 if ((cur_x += dx) < 0)
4856 else if (cur_x >= max_x)
4858 if ((cur_y += dy) < 0)
4860 else if (cur_y >= max_y)
4862 wmove(win, cur_y, cur_x);
4866 delete_framed(FRAME * fp, bool showit)
4871 fp->last->next = fp->next;
4872 fp->next->last = fp->last;
4880 np = (fp == fp->next) ? NULL : fp->next;
4887 scroll_test(bool recur GCC_UNUSED)
4888 /* Demonstrate windows */
4891 FRAME *current = (FRAME *) 0, *neww;
4893 #if HAVE_PUTWIN && HAVE_GETWIN
4897 #define DUMPFILE "screendump"
4899 #ifdef NCURSES_MOUSE_VERSION
4900 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4905 transient((FRAME *) 0, (char *) 0);
4908 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4909 failed("scroll_test");
4912 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4913 failed("scroll_test");
4918 if (current == 0) { /* First element, */
4919 neww->next = neww; /* so point it at itself */
4922 neww->next = current->next;
4923 neww->last = current;
4924 neww->last->next = neww;
4925 neww->next->last = neww;
4928 /* SVr4 curses sets the keypad on all newly-created windows to
4929 * false. Someone reported that PDCurses makes new windows inherit
4930 * this flag. Remove the following 'keypad()' call to test this
4932 keypad(current->wind, TRUE);
4933 current->do_keypad = HaveKeypad(current);
4934 current->do_scroll = HaveScroll(current);
4937 case CTRL('N'): /* go to next window */
4939 current = current->next;
4942 case CTRL('P'): /* go to previous window */
4944 current = current->last;
4947 case CTRL('F'): /* scroll current window forward */
4949 wscrl(frame_win(current), 1);
4952 case CTRL('B'): /* scroll current window backwards */
4954 wscrl(frame_win(current), -1);
4957 case CTRL('K'): /* toggle keypad mode for current */
4959 current->do_keypad = !current->do_keypad;
4960 keypad(current->wind, current->do_keypad);
4966 current->do_scroll = !current->do_scroll;
4967 scrollok(current->wind, current->do_scroll);
4971 #if HAVE_PUTWIN && HAVE_GETWIN
4972 case CTRL('W'): /* save and delete window */
4973 if ((current != 0) && (current == current->next)) {
4974 transient(current, "Will not save/delete ONLY window");
4976 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4977 transient(current, "Can't open screen dump file");
4979 int rc = putwin(frame_win(current), fp);
4983 current = delete_framed(current, TRUE);
4985 transient(current, "Can't write screen dump file");
4990 case CTRL('R'): /* restore window */
4991 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4992 transient(current, "Can't open screen dump file");
4994 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4996 neww->next = current ? current->next : 0;
4997 neww->last = current;
4998 if (neww->last != 0)
4999 neww->last->next = neww;
5000 if (neww->next != 0)
5001 neww->next->last = neww;
5003 neww->wind = getwin(fp);
5005 wrefresh(neww->wind);
5007 failed("scroll_test");
5015 case CTRL('X'): /* resize window */
5022 addstr("Use arrows to move cursor, anything else to mark new corner");
5025 getbegyx(current->wind, ul.y, ul.x);
5027 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
5028 if (tmp == (pair *) 0) {
5033 getmaxyx(current->wind, lr.y, lr.x);
5036 outerbox(ul, lr, FALSE);
5037 wnoutrefresh(stdscr);
5039 /* strictly cosmetic hack for the test */
5040 getmaxyx(current->wind, my, mx);
5041 if (my > tmp->y - ul.y) {
5042 getyx(current->wind, lr.y, lr.x);
5043 wmove(current->wind, tmp->y - ul.y + 1, 0);
5044 wclrtobot(current->wind);
5045 wmove(current->wind, lr.y, lr.x);
5047 if (mx > tmp->x - ul.x) {
5049 for (i = 0; i < my; i++) {
5050 wmove(current->wind, i, tmp->x - ul.x + 1);
5051 wclrtoeol(current->wind);
5054 wnoutrefresh(current->wind);
5056 memcpy(&lr, tmp, sizeof(pair));
5057 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
5059 getbegyx(current->wind, ul.y, ul.x);
5060 getmaxyx(current->wind, lr.y, lr.x);
5063 outerbox(ul, lr, TRUE);
5064 wnoutrefresh(stdscr);
5066 wnoutrefresh(current->wind);
5072 #endif /* HAVE_WRESIZE */
5075 newwin_move(current, -1, 0);
5078 newwin_move(current, 1, 0);
5081 newwin_move(current, 0, -1);
5084 newwin_move(current, 0, 1);
5092 getyx(frame_win(current), y, x);
5096 x = getmaxx(frame_win(current)) - 1;
5098 (void) mvwdelch(frame_win(current), y, x);
5108 waddch(current->wind, (chtype) c);
5113 newwin_report(current);
5114 usescr = frame_win(current);
5117 (!isQuit(c = wGetchar(usescr), TRUE)
5121 while (current != 0)
5122 current = delete_framed(current, FALSE);
5124 scrollok(stdscr, TRUE); /* reset to driver's default */
5125 #ifdef NCURSES_MOUSE_VERSION
5126 mousemask(0, (mmask_t *) 0);
5134 /****************************************************************************
5138 ****************************************************************************/
5141 static int nap_msec = 1;
5143 static NCURSES_CONST char *mod[] =
5153 /*+-------------------------------------------------------------------------
5155 --------------------------------------------------------------------------*/
5157 wait_a_while(int msec GCC_UNUSED)
5167 else if (msec > 1000)
5168 sleep((unsigned) msec / 1000);
5172 } /* end of wait_a_while */
5174 /*+-------------------------------------------------------------------------
5176 --------------------------------------------------------------------------*/
5178 saywhat(NCURSES_CONST char *text)
5180 wmove(stdscr, LINES - 1, 0);
5182 if (text != 0 && *text != '\0') {
5183 waddstr(stdscr, text);
5184 waddstr(stdscr, "; ");
5186 waddstr(stdscr, "press any key to continue");
5187 } /* end of saywhat */
5189 /*+-------------------------------------------------------------------------
5190 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
5191 --------------------------------------------------------------------------*/
5193 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
5198 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
5199 if ((pan = new_panel(win)) == 0) {
5201 } else if (UseColors) {
5202 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
5205 NCURSES_COLOR_T bg = color;
5207 init_pair(color, fg, bg);
5208 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
5210 wbkgdset(win, A_BOLD | ' ');
5214 } /* end of mkpanel */
5216 /*+-------------------------------------------------------------------------
5218 --------------------------------------------------------------------------*/
5222 WINDOW *win = panel_window(pan);
5225 } /* end of rmpanel */
5227 /*+-------------------------------------------------------------------------
5229 --------------------------------------------------------------------------*/
5235 } /* end of pflush */
5237 /*+-------------------------------------------------------------------------
5239 --------------------------------------------------------------------------*/
5241 init_panel(WINDOW *win)
5245 for (y = 0; y < LINES - 1; y++) {
5246 for (x = 0; x < COLS; x++)
5247 wprintw(win, "%d", (y + x) % 10);
5252 fill_panel(PANEL *pan)
5254 WINDOW *win = panel_window(pan);
5255 const char *userptr = (const char *) panel_userptr(pan);
5256 int num = (userptr && *userptr) ? userptr[1] : '?';
5260 wprintw(win, "-pan%c-", num);
5263 for (y = 2; y < getmaxy(win) - 1; y++) {
5264 for (x = 1; x < getmaxx(win) - 1; x++) {
5266 waddch(win, UChar(num));
5271 #if USE_WIDEC_SUPPORT
5273 init_wide_panel(WINDOW *win)
5278 for (digit = 0; digit < 10; ++digit)
5279 make_fullwidth_digit(&temp[digit], digit);
5283 getyx(stdscr, y, x);
5284 digit = (y + x / 2) % 10;
5285 } while (wadd_wch(win, &temp[digit]) != ERR);
5289 fill_wide_panel(PANEL *pan)
5291 WINDOW *win = panel_window(pan);
5292 const char *userptr = (const char *) panel_userptr(pan);
5293 int num = (userptr && *userptr) ? userptr[1] : '?';
5297 wprintw(win, "-pan%c-", num);
5300 for (y = 2; y < getmaxy(win) - 1; y++) {
5301 for (x = 1; x < getmaxx(win) - 1; x++) {
5303 waddch(win, UChar(num));
5309 #define MAX_PANELS 5
5312 canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
5314 int which = cmd[1] - '0';
5319 hide_panel(px[which]);
5322 show_panel(px[which]);
5325 top_panel(px[which]);
5328 bottom_panel(px[which]);
5335 wait_a_while(nap_msec);
5339 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
5343 PANEL *px[MAX_PANELS + 1];
5345 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5349 for (count = 0; count < 5; count++) {
5350 px[1] = mkpanel(COLOR_RED,
5355 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
5357 px[2] = mkpanel(COLOR_GREEN,
5362 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5364 px[3] = mkpanel(COLOR_YELLOW,
5369 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5371 px[4] = mkpanel(COLOR_BLUE,
5376 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5378 px[5] = mkpanel(COLOR_MAGENTA,
5383 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5395 wait_a_while(nap_msec);
5397 saywhat("h3 s1 s2 s4 s5");
5398 move_panel(px[1], 0, 0);
5405 wait_a_while(nap_msec);
5407 canned_panel(px, "s1");
5408 canned_panel(px, "s2");
5411 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5413 wait_a_while(nap_msec);
5415 canned_panel(px, "s3");
5418 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5420 wait_a_while(nap_msec);
5422 canned_panel(px, "b3");
5423 canned_panel(px, "s4");
5424 canned_panel(px, "s5");
5425 canned_panel(px, "t3");
5426 canned_panel(px, "t1");
5427 canned_panel(px, "t2");
5428 canned_panel(px, "t3");
5429 canned_panel(px, "t4");
5431 for (itmp = 0; itmp < 6; itmp++) {
5432 WINDOW *w4 = panel_window(px[4]);
5433 WINDOW *w5 = panel_window(px[5]);
5436 wmove(w4, LINES / 8, 1);
5437 waddstr(w4, mod[itmp]);
5438 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5439 wmove(w5, LINES / 6, 1);
5440 waddstr(w5, mod[itmp]);
5442 wait_a_while(nap_msec);
5445 wmove(w4, LINES / 6, 1);
5446 waddstr(w4, mod[itmp]);
5447 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5448 wmove(w5, LINES / 8, 1);
5449 waddstr(w5, mod[itmp]);
5451 wait_a_while(nap_msec);
5455 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5457 wait_a_while(nap_msec);
5459 canned_panel(px, "t5");
5460 canned_panel(px, "t2");
5461 canned_panel(px, "t1");
5462 canned_panel(px, "d2");
5463 canned_panel(px, "h3");
5464 canned_panel(px, "d1");
5465 canned_panel(px, "d4");
5466 canned_panel(px, "d5");
5467 canned_panel(px, "d3");
5469 wait_a_while(nap_msec);
5482 panel_test(bool recur GCC_UNUSED)
5484 return demo_panels(init_panel, fill_panel);
5488 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
5490 x_panel_test(bool recur GCC_UNUSED)
5492 return demo_panels(init_wide_panel, fill_wide_panel);
5495 #endif /* USE_LIBPANEL */
5497 /****************************************************************************
5501 ****************************************************************************/
5505 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
5506 * though we can rely on negative x/y values to stop the macro.
5509 do_h_line(int y, int x, chtype c, int to)
5512 MvHLine(y, x, c, (to) - (x));
5516 do_v_line(int y, int x, chtype c, int to)
5519 MvVLine(y, x, c, (to) - (y));
5524 static bool pending_pan = FALSE;
5525 static bool show_panner_legend = TRUE;
5528 panner_legend(int line)
5530 static const char *const legend[] =
5532 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5533 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5534 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5535 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5537 int n = ((int) SIZEOF(legend) - (LINES - line));
5538 if (n >= 0 && n < (int) SIZEOF(legend)) {
5539 if (move(line, 0) != ERR) {
5540 if (show_panner_legend)
5541 printw("%s", legend[n]);
5543 return show_panner_legend;
5550 panner_h_cleanup(int from_y, int from_x, int to_x)
5552 if (!panner_legend(from_y))
5553 do_h_line(from_y, from_x, ' ', to_x);
5557 panner_v_cleanup(int from_y, int from_x, int to_y)
5559 if (!panner_legend(from_y))
5560 do_v_line(from_y, from_x, ' ', to_y);
5564 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5567 unsigned gridcount = 0;
5571 fill = (chtype) COLOR_PAIR(1);
5574 wmove(panpad, 0, 0);
5575 for (y = 0; y < getmaxy(panpad); y++) {
5576 for (x = 0; x < getmaxx(panpad); x++) {
5577 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5578 if (y == 0 && x == 0)
5579 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5581 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5582 else if (y == 0 || x == 0)
5583 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5585 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5586 (int) (gridcount++ % 26)) | fill);
5587 } else if (y % GRIDSIZE == 0)
5588 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5589 else if (x % GRIDSIZE == 0)
5590 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5592 waddch(panpad, ' ');
5599 int top_x, int top_y, int porty, int portx,
5600 int (*pgetc) (WINDOW *),
5603 #if HAVE_GETTIMEOFDAY
5604 struct timeval before, after;
5607 bool pan_lines = FALSE;
5608 bool scrollers = TRUE;
5611 int pxmax, pymax, lowend, highend, c;
5613 getmaxyx(pad, pymax, pxmax);
5614 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5618 #ifdef NCURSES_VERSION
5620 * During shell-out, the user may have resized the window. Adjust
5621 * the port size of the pad to accommodate this. Ncurses automatically
5622 * resizes all of the normal windows to fit on the new screen.
5639 if (c == HELP_KEY_1)
5640 show_panner_legend = !show_panner_legend;
5641 panner_legend(LINES - 4);
5642 panner_legend(LINES - 3);
5643 panner_legend(LINES - 2);
5644 panner_legend(LINES - 1);
5647 pan_lines = !pan_lines;
5648 fill_pad(pad, pan_lines, colored);
5649 pending_pan = FALSE;
5652 #if HAVE_GETTIMEOFDAY
5656 panner_legend(LINES - 1);
5660 scrollers = !scrollers;
5663 /* Move the top-left corner of the pad, keeping the bottom-right
5666 case 'h': /* increase-columns: move left edge to left */
5670 panner_v_cleanup(top_y, top_x, porty);
5675 case 'j': /* decrease-lines: move top-edge down */
5679 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5684 case 'k': /* increase-lines: move top-edge up */
5689 panner_h_cleanup(top_y, top_x, portx);
5693 case 'l': /* decrease-columns: move left-edge to right */
5697 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5702 /* Move the bottom-right corner of the pad, keeping the top-left
5705 case KEY_IC: /* increase-columns: move right-edge to right */
5706 if (portx >= pxmax || portx >= COLS)
5709 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5714 case KEY_IL: /* increase-lines: move bottom-edge down */
5715 if (porty >= pymax || porty >= LINES)
5718 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5723 case KEY_DC: /* decrease-columns: move bottom edge up */
5728 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5732 case KEY_DL: /* decrease-lines */
5737 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5741 case KEY_LEFT: /* pan leftwards */
5748 case KEY_RIGHT: /* pan rightwards */
5749 if (basex + portx - (pymax > porty) < pxmax)
5755 case KEY_UP: /* pan upwards */
5762 case KEY_DOWN: /* pan downwards */
5763 if (basey + porty - (pxmax > portx) < pymax)
5778 basey = pymax - porty;
5788 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5789 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5790 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5792 if (scrollers && (pxmax > portx - 1)) {
5793 int length = (portx - top_x - 1);
5794 float ratio = ((float) length) / ((float) pxmax);
5796 lowend = (int) ((float) top_x + ((float) basex * ratio));
5797 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5799 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5800 if (highend < portx) {
5802 do_h_line(porty - 1, lowend, ' ', highend + 1);
5804 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5807 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5809 if (scrollers && (pymax > porty - 1)) {
5810 int length = (porty - top_y - 1);
5811 float ratio = ((float) length) / ((float) pymax);
5813 lowend = (int) ((float) top_y + ((float) basey * ratio));
5814 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5816 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5817 if (highend < porty) {
5819 do_v_line(lowend, portx - 1, ' ', highend + 1);
5821 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5824 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5826 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5827 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5828 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5831 #if HAVE_GETTIMEOFDAY
5832 gettimeofday(&before, 0);
5834 wnoutrefresh(stdscr);
5839 porty - (pxmax > portx) - 1,
5840 portx - (pymax > porty) - 1);
5843 #if HAVE_GETTIMEOFDAY
5844 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5847 gettimeofday(&after, 0);
5848 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5849 move(LINES - 1, COLS - 12);
5850 printw("Secs: %2.03f", elapsed);
5857 ((c = pgetc(pad)) != KEY_EXIT);
5859 scrollok(stdscr, TRUE); /* reset to driver's default */
5863 padgetch(WINDOW *win)
5868 if ((pending_pan = (count > 0)) != FALSE) {
5870 pending_pan = (count != 0);
5874 switch (c = wGetchar(win)) {
5910 case ERR: /* FALLTHRU */
5916 if (c >= '0' && c <= '9') {
5917 count = count * 10 + (c - '0');
5931 #define PAD_HIGH 200
5932 #define PAD_WIDE 200
5935 pad_test(bool recur GCC_UNUSED)
5936 /* Demonstrate pads. */
5938 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5941 Cannot("cannot create requested pad");
5946 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5947 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5948 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5951 fill_pad(panpad, FALSE, TRUE);
5953 panner_legend(LINES - 4);
5954 panner_legend(LINES - 3);
5955 panner_legend(LINES - 2);
5956 panner_legend(LINES - 1);
5958 keypad(panpad, TRUE);
5960 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5961 * We'll still be able to widen it during a test, since that's required
5962 * for testing boundaries.
5964 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, TRUE);
5971 #endif /* HAVE_NEWPAD */
5973 /****************************************************************************
5975 * Tests from John Burnell's PDCurses tester
5977 ****************************************************************************/
5980 Continue(WINDOW *win)
5984 MvWAddStr(win, 10, 1, " Press any key to continue");
5990 flushinp_test(bool recur GCC_UNUSED)
5991 /* Input test, adapted from John Burnell's PDCurses tester */
5993 WINDOW *win = stdscr;
5994 int w, h, bx, by, sw, sh, i;
5999 getmaxyx(win, h, w);
6000 getbegyx(win, by, bx);
6003 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
6008 init_pair(2, COLOR_CYAN, COLOR_BLUE);
6009 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
6012 (void) wattrset(subWin, A_BOLD);
6013 box(subWin, ACS_VLINE, ACS_HLINE);
6014 MvWAddStr(subWin, 2, 1, "This is a subwindow");
6018 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
6019 * it only happened to "work" on SVr4 because that implementation does not
6020 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
6021 * test behavior, we're using 'cbreak()', which will allow a single
6022 * character to return without needing a newline. - T.Dickey 1997/10/11.
6025 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
6027 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
6028 MvWAddStr(win, 3, 1,
6029 "These should be discarded (not echoed) after the subwindow goes away.");
6032 for (i = 0; i < 5; i++) {
6033 MvWPrintw(subWin, 1, 1, "Time = %d", i);
6045 MvWAddStr(win, 2, 1,
6046 "If you were still typing when the window timer expired,");
6047 MvWAddStr(win, 3, 1,
6048 "or else you typed nothing at all while it was running,");
6049 MvWAddStr(win, 4, 1,
6050 "test was invalid. You'll see garbage or nothing at all. ");
6051 MvWAddStr(win, 6, 1, "Press a key");
6057 MvWAddStr(win, 12, 0,
6058 "If you see any key other than what you typed, flushinp() is broken.");
6067 "What you typed should now have been deleted; if not, wdelch() failed.");
6074 /****************************************************************************
6078 ****************************************************************************/
6086 menu_virtualize(int c)
6088 if (c == '\n' || c == KEY_EXIT)
6089 return (MAX_COMMAND + 1);
6091 return (REQ_SCR_ULINE);
6093 return (REQ_SCR_DLINE);
6094 else if (c == 'b' || c == KEY_NPAGE)
6095 return (REQ_SCR_UPAGE);
6096 else if (c == 'f' || c == KEY_PPAGE)
6097 return (REQ_SCR_DPAGE);
6098 else if (c == 'n' || c == KEY_DOWN)
6099 return (REQ_NEXT_ITEM);
6100 else if (c == 'p' || c == KEY_UP)
6101 return (REQ_PREV_ITEM);
6103 return (REQ_TOGGLE_ITEM);
6111 static CONST_MENUS char *animals[] =
6124 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6125 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6130 menu_test(bool recur GCC_UNUSED)
6133 ITEM *items[SIZEOF(animals)];
6135 CONST_MENUS char **ap;
6136 int mrows, mcols, c;
6139 #ifdef NCURSES_MOUSE_VERSION
6140 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6142 MvAddStr(0, 0, "This is the menu test:");
6143 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
6144 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
6146 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
6147 MvAddStr(5, 0, " Press return to exit.");
6150 for (ap = animals; *ap; ap++) {
6151 if ((*ip = new_item(*ap, "")) != 0)
6156 m = new_menu(items);
6158 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
6159 scale_menu(m, &mrows, &mcols);
6161 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6162 set_menu_win(m, menuwin);
6163 keypad(menuwin, TRUE);
6166 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6170 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
6171 if (c == E_NOT_POSTED)
6173 if (c == E_REQUEST_DENIED)
6178 MvPrintw(LINES - 2, 0,
6179 "You chose: %s\n", item_name(current_item(m)));
6180 (void) addstr("Press any key to continue...");
6187 for (ip = items; *ip; ip++)
6189 #ifdef NCURSES_MOUSE_VERSION
6190 mousemask(0, (mmask_t *) 0);
6196 #define T_TBL(name) { #name, name }
6202 T_TBL(TRACE_DISABLE),
6205 T_TBL(TRACE_UPDATE),
6207 T_TBL(TRACE_CHARPUT),
6208 T_TBL(TRACE_ORDINARY),
6210 T_TBL(TRACE_VIRTPUT),
6211 T_TBL(TRACE_IEVENT),
6213 T_TBL(TRACE_ICALLS),
6214 T_TBL(TRACE_CCALLS),
6215 T_TBL(TRACE_DATABASE),
6217 T_TBL(TRACE_MAXIMUM),
6224 tracetrace(unsigned tlevel)
6227 static size_t need = 12;
6231 for (n = 0; t_tbl[n].name != 0; n++)
6232 need += strlen(t_tbl[n].name) + 2;
6233 buf = typeMalloc(char, need);
6235 failed("tracetrace");
6237 _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
6239 _nc_STRCAT(buf, t_tbl[0].name ? t_tbl[0].name : "", need);
6240 _nc_STRCAT(buf, ", ", need);
6242 for (n = 1; t_tbl[n].name != 0; n++)
6243 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
6244 _nc_STRCAT(buf, t_tbl[n].name, need);
6245 _nc_STRCAT(buf, ", ", need);
6248 if (buf[strlen(buf) - 2] == ',')
6249 buf[strlen(buf) - 2] = '\0';
6250 _nc_STRCAT(buf, "}", need);
6254 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
6258 run_trace_menu(MENU * m)
6264 bool changed = FALSE;
6265 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
6266 case E_UNKNOWN_COMMAND:
6269 items = menu_items(m);
6270 i = current_item(m);
6271 if (i == items[0]) {
6272 if (item_value(i)) {
6273 for (p = items + 1; *p != 0; p++)
6274 if (item_value(*p)) {
6275 set_item_value(*p, FALSE);
6280 for (p = items + 1; *p != 0; p++)
6281 if (item_value(*p)) {
6282 set_item_value(items[0], FALSE);
6294 trace_set(bool recur GCC_UNUSED)
6295 /* interactively set the trace level */
6298 ITEM *items[SIZEOF(t_tbl)];
6305 MvAddStr(0, 0, "Interactively set trace level:");
6306 MvAddStr(2, 0, " Press space bar to toggle a selection.");
6307 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
6308 MvAddStr(4, 0, " Press return to set the trace level.");
6309 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
6313 for (n = 0; t_tbl[n].name != 0; n++) {
6314 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
6320 m = new_menu(items);
6322 set_menu_format(m, 0, 2);
6323 scale_menu(m, &mrows, &mcols);
6325 menu_opts_off(m, O_ONEVALUE);
6326 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6327 set_menu_win(m, menuwin);
6328 keypad(menuwin, TRUE);
6331 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6335 for (ip = menu_items(m); *ip; ip++) {
6336 unsigned mask = t_tbl[item_index(*ip)].mask;
6338 set_item_value(*ip, _nc_tracing == 0);
6339 else if ((mask & _nc_tracing) == mask)
6340 set_item_value(*ip, TRUE);
6343 while (run_trace_menu(m))
6347 for (ip = menu_items(m); *ip; ip++)
6348 if (item_value(*ip))
6349 newtrace |= t_tbl[item_index(*ip)].mask;
6350 curses_trace(newtrace);
6351 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
6353 MvPrintw(LINES - 2, 0,
6354 "Trace level is %s\n", tracetrace(_nc_tracing));
6355 (void) addstr("Press any key to continue...");
6362 for (ip = items; *ip; ip++)
6368 #endif /* USE_LIBMENU */
6370 /****************************************************************************
6374 ****************************************************************************/
6377 make_label(int frow, int fcol, NCURSES_CONST char *label)
6379 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
6382 set_field_buffer(f, 0, label);
6383 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
6389 make_field(int frow, int fcol, int rows, int cols, bool secure)
6391 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
6394 set_field_back(f, A_UNDERLINE);
6395 set_field_userptr(f, (void *) 0);
6401 display_form(FORM *f)
6406 scale_form(f, &rows, &cols);
6408 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6410 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6413 if (post_form(f) != E_OK)
6421 WINDOW *w = form_win(f);
6422 WINDOW *s = form_sub(f);
6432 edit_secure(FIELD *me, int c)
6434 int rows, cols, frow, fcol, nrow, nbuf;
6436 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6438 char *source = field_buffer(me, 1);
6439 size_t have = (source ? strlen(source) : 0) + 1;
6440 size_t need = 80 + have;
6441 char *temp = malloc(need);
6445 _nc_STRNCPY(temp, source ? source : "", have + 1);
6446 len = (size_t) (char *) field_userptr(me);
6448 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6449 temp[len++] = (char) c;
6451 set_field_buffer(me, 1, temp);
6471 case REQ_RIGHT_CHAR:
6473 c = 0; /* we don't want to do inline editing */
6478 set_field_buffer(me, 1, temp);
6485 set_field_buffer(me, 1, temp);
6490 set_field_userptr(me, (void *) len);
6498 form_virtualize(FORM *f, WINDOW *w)
6501 static const struct {
6505 { CTRL('A'), REQ_NEXT_CHOICE },
6506 { CTRL('B'), REQ_PREV_WORD },
6507 { CTRL('C'), REQ_CLR_EOL },
6508 { CTRL('D'), REQ_DOWN_FIELD },
6509 { CTRL('E'), REQ_END_FIELD },
6510 { CTRL('F'), REQ_NEXT_PAGE },
6511 { CTRL('G'), REQ_DEL_WORD },
6512 { CTRL('H'), REQ_DEL_PREV },
6513 { CTRL('I'), REQ_INS_CHAR },
6514 { CTRL('K'), REQ_CLR_EOF },
6515 { CTRL('L'), REQ_LEFT_FIELD },
6516 { CTRL('M'), REQ_NEW_LINE },
6517 { CTRL('N'), REQ_NEXT_FIELD },
6518 { CTRL('O'), REQ_INS_LINE },
6519 { CTRL('P'), REQ_PREV_FIELD },
6520 { CTRL('R'), REQ_RIGHT_FIELD },
6521 { CTRL('S'), REQ_BEG_FIELD },
6522 { CTRL('U'), REQ_UP_FIELD },
6523 { CTRL('V'), REQ_DEL_CHAR },
6524 { CTRL('W'), REQ_NEXT_WORD },
6525 { CTRL('X'), REQ_CLR_FIELD },
6526 { CTRL('Y'), REQ_DEL_LINE },
6527 { CTRL('Z'), REQ_PREV_CHOICE },
6528 { ESCAPE, MAX_FORM_COMMAND + 1 },
6529 { KEY_BACKSPACE, REQ_DEL_PREV },
6530 { KEY_DOWN, REQ_DOWN_CHAR },
6531 { KEY_END, REQ_LAST_FIELD },
6532 { KEY_HOME, REQ_FIRST_FIELD },
6533 { KEY_LEFT, REQ_LEFT_CHAR },
6534 { KEY_LL, REQ_LAST_FIELD },
6535 { KEY_NEXT, REQ_NEXT_FIELD },
6536 { KEY_NPAGE, REQ_NEXT_PAGE },
6537 { KEY_PPAGE, REQ_PREV_PAGE },
6538 { KEY_PREVIOUS, REQ_PREV_FIELD },
6539 { KEY_RIGHT, REQ_RIGHT_CHAR },
6540 { KEY_UP, REQ_UP_CHAR },
6541 { QUIT, MAX_FORM_COMMAND + 1 }
6545 static int mode = REQ_INS_MODE;
6546 int c = wGetchar(w);
6547 FIELD *me = current_field(f);
6548 bool current = TRUE;
6550 if (c == CTRL(']')) {
6551 if (mode == REQ_INS_MODE) {
6552 mode = REQ_OVL_MODE;
6554 mode = REQ_INS_MODE;
6559 for (n = 0; n < SIZEOF(lookup); n++) {
6560 if (lookup[n].code == c) {
6561 c = lookup[n].result;
6566 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6569 * Force the field that the user is typing into to be in reverse video,
6570 * while the other fields are shown underlined.
6585 case REQ_LEFT_FIELD:
6587 case REQ_RIGHT_CHAR:
6591 current = (c < KEY_MAX);
6595 c = edit_secure(me, c);
6596 set_field_back(me, A_REVERSE);
6598 c = edit_secure(me, c);
6599 set_field_back(me, A_UNDERLINE);
6605 my_form_driver(FORM *form, int c)
6607 if (c == (MAX_FORM_COMMAND + 1)
6608 && form_driver(form, REQ_VALIDATION) == E_OK)
6616 #ifdef NCURSES_VERSION
6617 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6618 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6620 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6621 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6625 * Allow a middle initial, optionally with a '.' to end it.
6628 FIELDCHECK_CB(mi_field_check)
6630 char *s = field_buffer(fld, 0);
6634 for (n = 0; s[n] != '\0'; ++n) {
6641 } else if (isspace(UChar(s[n]))) {
6646 if (!isspace(UChar(s[n])))
6652 /* force the form to display a leading capital */
6653 if (islower(UChar(s[0]))) {
6654 s[0] = (char) toupper(UChar(s[0]));
6655 set_field_buffer(fld, 0, s);
6661 CHAR_CHECK_CB(mi_char_check)
6663 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6667 * Passwords should be at least 6 characters.
6670 FIELDCHECK_CB(pw_field_check)
6672 char *s = field_buffer(fld, 0);
6675 for (n = 0; s[n] != '\0'; ++n) {
6676 if (isspace(UChar(s[n]))) {
6685 CHAR_CHECK_CB(pw_char_check)
6687 return (isgraph(ch) ? TRUE : FALSE);
6691 form_test(bool recur GCC_UNUSED)
6694 FIELD *f[12], *secure;
6695 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6696 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6700 #ifdef NCURSES_MOUSE_VERSION
6701 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6705 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6706 addstr("^N -- go to next field ^P -- go to previous field\n");
6707 addstr("Home -- go to first field End -- go to last field\n");
6708 addstr("^L -- go to field to left ^R -- go to field to right\n");
6709 addstr("^U -- move upward to field ^D -- move downward to field\n");
6710 addstr("^W -- go to next word ^B -- go to previous word\n");
6711 addstr("^S -- go to start of field ^E -- go to end of field\n");
6712 addstr("^H -- delete previous char ^Y -- delete line\n");
6713 addstr("^G -- delete current word ^C -- clear to end of line\n");
6714 addstr("^K -- clear to end of field ^X -- clear field\n");
6715 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6717 MvAddStr(4, 57, "Forms Entry Test");
6721 /* describe the form */
6722 memset(f, 0, sizeof(f));
6723 f[n++] = make_label(0, 15, "Sample Form");
6725 f[n++] = make_label(2, 0, "Last Name");
6726 f[n++] = make_field(3, 0, 1, 18, FALSE);
6727 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6729 f[n++] = make_label(2, 20, "First Name");
6730 f[n++] = make_field(3, 20, 1, 12, FALSE);
6731 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6733 f[n++] = make_label(2, 34, "Middle Name");
6734 f[n++] = make_field(3, 34, 1, 12, FALSE);
6735 set_field_type(f[n - 1], fty_middle);
6737 f[n++] = make_label(5, 0, "Comments");
6738 f[n++] = make_field(6, 0, 4, 46, FALSE);
6740 f[n++] = make_label(5, 20, "Password:");
6742 f[n++] = make_field(5, 30, 1, 9, TRUE);
6743 set_field_type(f[n - 1], fty_passwd);
6746 if ((form = new_form(f)) != 0) {
6754 nonl(); /* lets us read ^M's */
6756 switch (form_driver(form, c = form_virtualize(form, w))) {
6758 MvAddStr(5, 57, field_buffer(secure, 1));
6762 case E_UNKNOWN_COMMAND:
6763 finished = my_form_driver(form, c);
6775 for (c = 0; f[c] != 0; c++)
6777 free_fieldtype(fty_middle);
6778 free_fieldtype(fty_passwd);
6782 #ifdef NCURSES_MOUSE_VERSION
6783 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6787 #endif /* USE_LIBFORM */
6789 /****************************************************************************
6793 ****************************************************************************/
6795 #if HAVE_COPYWIN /* ...and overlay, overwrite */
6797 static const int overlap_HEAD = 1;
6798 static const int overlap_FOOT = 6;
6806 getmaxyx(stdscr, y, x);
6807 if (y < 23 || x < 80) {
6808 Cannot("The screen is too small for this test");
6811 int ymax = y - (overlap_HEAD + overlap_FOOT);
6812 int high = ymax / 5; /* equal-sized parts for cross */
6813 int xmax = x - 2; /* margin */
6814 int wide = (xmax / 5) & ~1;
6823 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6824 lmar = (xmax - (5 * wide)) / 2;
6827 result = newwin(3 * high, 3 * wide, tmar, lmar);
6829 result = newwin(3 * high, 3 * wide, tmar + 2 * high, lmar + 2 * wide);
6840 for (row = overlap_HEAD; row < LINES - overlap_FOOT; ++row) {
6847 move_overlap(int shift, WINDOW *win1)
6849 int ymax = getmaxy(stdscr) - (overlap_HEAD + overlap_FOOT);
6850 int high = ymax / 5; /* equal-sized parts for cross */
6852 int xmax1 = getmaxx(win1) + 1;
6853 int lmar1 = (COLS - (5 * (xmax1) / 3)) / 2;
6858 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6860 rc = mvwin(win1, tmar, lmar1 + shift);
6865 fillwin(WINDOW *win, char ch)
6870 getmaxyx(win, y1, x1);
6871 for (y = 0; y < y1; y++) {
6873 for (x = 0; x < x1; x++)
6874 waddch(win, UChar(ch));
6878 #define InCross(x,y, x1,y1) \
6879 (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3)) \
6880 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3))))
6883 crosswin(WINDOW *win, char ch)
6889 getmaxyx(win, y1, x1);
6890 for (y = 0; y < y1; y++) {
6891 for (x = 0; x < x1; x += xw) {
6892 if (InCross(x, y, x1, y1)) {
6894 waddch(win, UChar(ch));
6901 * Match "crosswin()", but using line-drawing characters. This could be done
6902 * a little simpler using box(), but the reason for this example is to test
6903 * hline/vline and addch with line-drawing vs the copy/overlay functions.
6906 crossbox(WINDOW *win)
6911 getmaxyx(win, y1, x1);
6916 mvwhline(win, 0, (xmax / 3), ACS_HLINE, (xmax / 3));
6917 mvwhline(win, ymax / 3, 0, ACS_HLINE, xmax);
6918 mvwhline(win, ((2 * ymax) / 3) - 1, 0, ACS_HLINE, xmax);
6919 mvwhline(win, y1 - 1, (xmax / 3), ACS_HLINE, (xmax / 3));
6921 mvwvline(win, (ymax / 3), 0, ACS_VLINE, (ymax / 3));
6922 mvwvline(win, 0, xmax / 3, ACS_VLINE, ymax);
6923 mvwvline(win, 0, ((2 * xmax) / 3) - 1, ACS_VLINE, ymax);
6924 mvwvline(win, (ymax / 3), x1 - 1, ACS_VLINE, (ymax / 3));
6926 mvwaddch(win, 0, (xmax / 3), ACS_ULCORNER);
6927 mvwaddch(win, 0, ((2 * xmax) / 3) - 1, ACS_URCORNER);
6928 mvwaddch(win, y1 - 1, (xmax / 3), ACS_LLCORNER);
6929 mvwaddch(win, y1 - 1, ((2 * xmax) / 3) - 1, ACS_LRCORNER);
6931 mvwaddch(win, (ymax / 3), 0, ACS_ULCORNER);
6932 mvwaddch(win, ((2 * ymax) / 3) - 1, 0, ACS_LLCORNER);
6933 mvwaddch(win, (ymax / 3), x1 - 1, ACS_URCORNER);
6934 mvwaddch(win, ((2 * ymax) / 3) - 1, x1 - 1, ACS_LRCORNER);
6936 mvwaddch(win, (ymax / 3), (xmax / 3), ACS_PLUS);
6937 mvwaddch(win, (ymax / 3), ((2 * xmax) / 3) - 1, ACS_PLUS);
6938 mvwaddch(win, ((2 * ymax) / 3) - 1, ((2 * xmax) / 3) - 1, ACS_PLUS);
6939 mvwaddch(win, ((2 * ymax) / 3) - 1, (xmax / 3), ACS_PLUS);
6950 #define OVERLAP_FLAVORS 6
6959 #define LimitFILL() UseColors ? 4 : 2
6962 otDRAW_text_cross = 0
6969 #define LimitDRAW() UseColors ? 5 : 3
6972 otCOPY_overwrite = 0
6978 #define LimitCOPY() 4
6981 overlap_helpitem(int state, int item, char *message)
6983 int row = (item / 2);
6984 int col = ((item % 2) ? COLS / 2 : 0);
6986 move(LINES - 6 + row, col);
6987 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6992 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6994 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6996 switch ((otFILL) flavor) {
6998 (void) wattrset(win, A_NORMAL);
7001 (void) wattrset(win, A_BOLD);
7004 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
7005 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
7008 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
7009 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
7015 overlap_test_2_attr(WINDOW *win, int flavor, int col)
7017 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
7019 switch ((otDRAW) flavor) {
7020 case otDRAW_text_cross:
7023 case otDRAW_line_box:
7026 case otDRAW_line_cross:
7030 init_pair(cpair, COLOR_RED, COLOR_GREEN);
7031 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
7033 case otDRAW_reset_bg:
7034 wbkgdset(win, ' ' | A_NORMAL);
7040 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
7043 int limit[OVERLAP_FLAVORS];
7047 state += OVERLAP_FLAVORS;
7048 state = state % OVERLAP_FLAVORS;
7049 assert(state >= 0 && state < OVERLAP_FLAVORS);
7051 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
7054 const char *ths = col ? "B" : "A";
7055 const char *tht = col ? "A" : "B";
7057 switch ((otBASE) row) {
7058 case otBASE_refresh:
7061 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7062 "refresh %s, then %s, then doupdate.", ths, tht);
7065 limit[row] = LimitFILL();
7066 flavors[row] %= limit[row];
7067 overlap_test_1_attr(stdscr, flavors[row], col);
7068 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7069 "fill window %s with letter %s.", ths, ths);
7072 limit[row] = LimitDRAW();
7073 flavors[row] %= limit[row];
7074 switch ((otDRAW) flavors[row]) {
7075 case otDRAW_text_cross:
7076 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7077 "cross text-pattern in window %s.", ths);
7079 case otDRAW_line_box:
7080 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7081 "draw line-box in window %s.", ths);
7083 case otDRAW_line_cross:
7084 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7085 "draw line-cross in window %s.", ths);
7088 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7089 "set background of window %s.", ths);
7091 case otDRAW_reset_bg:
7092 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7093 "reset background of window %s.", ths);
7100 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7101 "clear window %s.", ths);
7104 limit[row] = LimitCOPY();
7105 flavors[row] %= limit[row];
7106 switch ((otCOPY) flavors[row]) {
7107 case otCOPY_overwrite:
7108 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7109 "overwrite %s onto %s.", ths, tht);
7112 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7113 "copywin(FALSE) %s onto %s.", ths, tht);
7116 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7117 "copywin(TRUE) %s onto %s.", ths, tht);
7119 case otCOPY_overlay:
7120 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7121 "overlay %s onto %s.", ths, tht);
7126 overlap_helpitem(state, item, msg);
7127 (void) wattrset(stdscr, A_NORMAL);
7128 wbkgdset(stdscr, ' ' | A_NORMAL);
7131 printw("^Q/ESC = terminate test. </> shift. Up/down/space select (row %d",
7133 if (limit[state] > 1)
7134 printw(" test %d:%d", 1 + flavors[state], limit[state]);
7142 overlap_test_0(WINDOW *a, WINDOW *b)
7152 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
7154 overlap_test_1_attr(a, flavor, col);
7156 (void) wattrset(a, A_NORMAL);
7160 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
7162 overlap_test_2_attr(a, flavor, col);
7163 switch ((otDRAW) flavor) {
7164 case otDRAW_text_cross:
7167 case otDRAW_line_box:
7170 case otDRAW_line_cross:
7174 /* done in overlap_test_2_attr */
7176 case otDRAW_reset_bg:
7177 /* done in overlap_test_2_attr */
7183 overlap_test_3(WINDOW *a)
7190 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
7192 switch ((otCOPY) flavor) {
7193 case otCOPY_overwrite:
7197 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
7200 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
7202 case otCOPY_overlay:
7208 /* test effects of overlapping windows */
7210 overlap_test(bool recur GCC_UNUSED)
7212 WINDOW *win1, *win2;
7214 int shift = 0, last_refresh = -1;
7215 int state, flavor[OVERLAP_FLAVORS];
7217 if ((win1 = make_overlap(0)) == 0) {
7219 } else if ((win2 = make_overlap(1)) == 0) {
7228 printw("Test wnoutrefresh() for two overlapping windows:");
7230 memset(flavor, 0, sizeof(flavor));
7231 state = overlap_help(0, flavor);
7233 while (!isQuit(ch = Getchar(), TRUE)) {
7235 case 'a': /* refresh window A first, then B */
7236 overlap_test_0(win1, win2);
7239 case 'b': /* refresh window B first, then A */
7240 overlap_test_0(win2, win1);
7243 case 'c': /* fill window A so it is visible */
7244 overlap_test_1(flavor[otBASE_fill], 0, win1, 'A');
7247 case 'd': /* fill window B so it is visible */
7248 overlap_test_1(flavor[otBASE_fill], 1, win2, 'B');
7251 case 'e': /* cross test pattern in window A */
7252 overlap_test_2(flavor[otBASE_draw], 0, win1, 'A');
7255 case 'f': /* cross test pattern in window A */
7256 overlap_test_2(flavor[otBASE_draw], 1, win2, 'B');
7259 case 'g': /* clear window A */
7260 overlap_test_3(win1);
7263 case 'h': /* clear window B */
7264 overlap_test_3(win2);
7267 case 'i': /* overwrite A onto B */
7268 overlap_test_4(flavor[otBASE_copy], win1, win2);
7271 case 'j': /* overwrite B onto A */
7272 overlap_test_4(flavor[otBASE_copy], win2, win1);
7277 state = overlap_help(state + 1, flavor);
7282 state = overlap_help(state - 1, flavor);
7287 state = overlap_help(state, flavor);
7291 state = overlap_help(state, flavor);
7316 if (move_overlap(shift, win1) != OK) {
7318 shift += (ch == '>') ? -1 : 1;
7319 } else if (last_refresh > 0) {
7321 wnoutrefresh(stdscr);
7322 if (last_refresh == 'a')
7323 overlap_test_0(win1, win2);
7325 overlap_test_0(win2, win1);
7341 #if USE_WIDEC_SUPPORT
7343 x_fillwin(WINDOW *win, wchar_t ch)
7348 getmaxyx(win, y1, x1);
7350 for (y = 0; y < y1; y++) {
7352 for (x = 0; x < x1; x++)
7353 waddnwstr(win, &ch, 1);
7358 x_crosswin(WINDOW *win, wchar_t ch)
7364 getmaxyx(win, y1, x1);
7365 for (y = 0; y < y1; y++) {
7366 for (x = 0; x < x1; x += xw) {
7367 if (InCross(x, y, x1, y1)) {
7369 waddnwstr(win, &ch, 1);
7376 x_overlap_test_1(int flavor, int col, WINDOW *a, wchar_t fill)
7378 overlap_test_1_attr(a, flavor, col);
7380 (void) wattrset(a, A_NORMAL);
7384 x_overlap_test_2(int flavor, int col, WINDOW *a, wchar_t fill)
7386 overlap_test_2_attr(a, flavor, col);
7387 switch ((otDRAW) flavor) {
7388 case otDRAW_text_cross:
7389 x_crosswin(a, fill);
7391 case otDRAW_line_box:
7394 case otDRAW_line_cross:
7398 /* done in overlap_test_2_attr */
7400 case otDRAW_reset_bg:
7401 /* done in overlap_test_2_attr */
7406 /* test effects of overlapping windows */
7408 x_overlap_test(bool recur GCC_UNUSED)
7410 const wchar_t WIDE_A = 0xff21;
7411 const wchar_t WIDE_B = 0xff22;
7412 WINDOW *win1, *win2;
7414 int shift = 0, last_refresh = -1;
7415 int state, flavor[OVERLAP_FLAVORS];
7417 if ((win1 = make_overlap(0)) == 0) {
7419 } else if ((win2 = make_overlap(1)) == 0) {
7428 printw("Test wnoutrefresh() for overlapping windows with double-cell characters:");
7430 memset(flavor, 0, sizeof(flavor));
7431 state = overlap_help(0, flavor);
7433 while (!isQuit(ch = Getchar(), TRUE)) {
7435 case 'a': /* refresh window A first, then B */
7436 overlap_test_0(win1, win2);
7439 case 'b': /* refresh window B first, then A */
7440 overlap_test_0(win2, win1);
7443 case 'c': /* fill window A so it is visible */
7444 x_overlap_test_1(flavor[otBASE_fill], 0, win1, WIDE_A);
7447 case 'd': /* fill window B so it is visible */
7448 x_overlap_test_1(flavor[otBASE_fill], 1, win2, WIDE_B);
7451 case 'e': /* cross test pattern in window A */
7452 x_overlap_test_2(flavor[otBASE_draw], 0, win1, WIDE_A);
7455 case 'f': /* cross test pattern in window A */
7456 x_overlap_test_2(flavor[otBASE_draw], 1, win2, WIDE_B);
7459 case 'g': /* clear window A */
7460 overlap_test_3(win1);
7463 case 'h': /* clear window B */
7464 overlap_test_3(win2);
7467 case 'i': /* overwrite A onto B */
7468 overlap_test_4(flavor[otBASE_copy], win1, win2);
7471 case 'j': /* overwrite B onto A */
7472 overlap_test_4(flavor[otBASE_copy], win2, win1);
7477 state = overlap_help(state + 1, flavor);
7482 state = overlap_help(state - 1, flavor);
7487 state = overlap_help(state, flavor);
7491 state = overlap_help(state, flavor);
7516 if (move_overlap(shift, win1) != OK) {
7518 shift += (ch == '>') ? -1 : 1;
7519 } else if (last_refresh > 0) {
7521 wnoutrefresh(stdscr);
7522 if (last_refresh == 'a')
7523 overlap_test_0(win1, win2);
7525 overlap_test_0(win2, win1);
7540 #endif /* USE_WIDEC_SUPPORT */
7542 #endif /* HAVE_COPYWIN */
7545 show_setting_name(const char *name)
7547 printw("%-25s ", name);
7551 show_string_setting(const char *name, const char *value)
7553 show_setting_name(name);
7555 printw("\"%s\"", value);
7565 show_number_setting(const char *name, int value)
7567 show_setting_name(name);
7569 printw("%d", value);
7572 printw("%d", value);
7579 show_boolean_setting(const char *name, int value)
7581 show_setting_name(name);
7583 printw("%s", value ? "TRUE" : "FALSE");
7586 printw("%d", value);
7593 settings_test(bool recur GCC_UNUSED)
7595 #if USE_WIDEC_SUPPORT
7600 show_string_setting("termname", termname());
7601 show_string_setting("longname", longname());
7602 show_number_setting("baudrate", baudrate());
7603 if (erasechar() > 0) {
7604 show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
7605 show_string_setting("keyname(erasechar)", keyname(erasechar()));
7607 if (killchar() > 0) {
7608 show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
7609 show_string_setting("keyname(killchar)", keyname(killchar()));
7611 #if USE_WIDEC_SUPPORT
7612 if (erasewchar(&ch) == OK) {
7613 show_string_setting("key_name(erasewchar)", key_name(ch));
7615 if (killwchar(&ch) == OK) {
7616 show_string_setting("key_name(killwchar)", key_name(ch));
7619 show_boolean_setting("has_ic", has_ic());
7620 show_boolean_setting("has_il", has_il());
7621 show_boolean_setting("has_colors", has_colors());
7622 #if HAVE_COLOR_CONTENT
7623 show_boolean_setting("can_change_color", can_change_color());
7625 show_setting_name("LINES");
7626 printw("%d\n", LINES);
7627 show_setting_name("COLS");
7628 printw("%d\n", COLS);
7635 /****************************************************************************
7639 ****************************************************************************/
7644 static const char *const tbl[] =
7646 "Usage: ncurses [options]"
7649 #ifdef NCURSES_VERSION
7650 ," -a f,b set default-colors (assumed white-on-black)"
7651 ," -d use default-colors if terminal supports them"
7654 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
7657 ," -e fmt specify format for soft-keys test (e)"
7660 ," -f rip-off footer line (can repeat)"
7661 ," -h rip-off header line (can repeat)"
7663 ," -m do not use colors"
7664 #if HAVE_COLOR_CONTENT
7665 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
7668 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
7670 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_NC_WINDOWS)
7671 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
7674 ," -t mask specify default trace-level (may toggle with ^T)"
7676 #if HAVE_COLOR_CONTENT
7677 ," -x use xterm-compatible control for reading color palette"
7681 for (n = 0; n < SIZEOF(tbl); n++)
7682 fprintf(stderr, "%s\n", tbl[n]);
7683 ExitProgram(EXIT_FAILURE);
7687 set_terminal_modes(void)
7692 scrollok(stdscr, TRUE);
7693 idlok(stdscr, TRUE);
7694 keypad(stdscr, TRUE);
7699 announce_sig(int sig)
7701 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
7707 rip_footer(WINDOW *win, int cols)
7709 wbkgd(win, A_REVERSE);
7712 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
7718 rip_header(WINDOW *win, int cols)
7720 wbkgd(win, A_REVERSE);
7723 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
7727 #endif /* HAVE_RIPOFFLINE */
7732 #if USE_WIDEC_SUPPORT
7735 int (*narrow_func) (bool);
7736 int (*wide_func) (bool);
7740 #define BOTH(a) a, x_ ## a
7741 #define ONLY(a) a, NULL
7742 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7746 int (*narrow_func) (bool);
7752 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7755 static MyCmds cmds[] =
7757 CMDS(TRUE, BOTH(getch_test), 'a', "keyboard and mouse input test"),
7758 CMDS(TRUE, BOTH(attr_test), 'b', "character attribute test"),
7759 CMDS(TRUE, BOTH(color_test), 'c', "color test pattern"),
7760 #if HAVE_COLOR_CONTENT
7761 CMDS(FALSE, ONLY(color_edit), 'd', "edit RGB color values"),
7764 CMDS(TRUE, BOTH(slk_test), 'e', "exercise soft keys"),
7766 CMDS(TRUE, BOTH(acs_test), 'f', "display ACS characters"),
7767 CMDS(TRUE, ONLY(scroll_test), 'g', "display windows and scrolling"),
7768 CMDS(TRUE, ONLY(flushinp_test), 'i', "test flushinp()"),
7769 CMDS(TRUE, ONLY(sgr_attr_test), 'k', "display character attributes"),
7771 CMDS(TRUE, ONLY(menu_test), 'm', "exercise menu library"),
7774 CMDS(TRUE, BOTH(panel_test), 'o', "exercise panel library"),
7777 CMDS(TRUE, ONLY(pad_test), 'p', "exercise pad features"),
7779 CMDS(TRUE, ONLY(NULL), 'q', "quit"),
7781 CMDS(TRUE, ONLY(form_test), 'r', "exercise form library"),
7784 CMDS(TRUE, BOTH(overlap_test), 's', "overlapping-refresh test"),
7786 #if USE_LIBMENU && defined(TRACE)
7787 CMDS(TRUE, ONLY(trace_set), 't', "set trace level"),
7789 CMDS(TRUE, ONLY(settings_test), 'v', "show terminal name and settings"),
7790 CMDS(FALSE, ONLY(NULL), '?', "repeat this command summary")
7798 printf("This is the ncurses main menu (uppercase for wide-characters)\n");
7799 for (n = 0; n < SIZEOF(cmds); ++n) {
7800 if (top || cmds[n].recur) {
7802 #if USE_WIDEC_SUPPORT
7803 if (cmds[n].wide_func) {
7804 printf("%c,", toupper(cmds[n].code));
7807 printf("%c\t= %s\n", cmds[n].code, cmds[n].help);
7811 (void) fputs("> ", stdout);
7812 (void) fflush(stdout); /* necessary under SVr4 curses */
7815 * This used to be an 'fgets()' call (until 1996/10). However with
7816 * some runtime libraries, mixing stream I/O and 'read()' causes the
7817 * input stream to be flushed when switching between the two.
7822 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7823 int save_err = errno;
7825 if (save_err == EINTR) {
7828 } else if (command == 0) {
7832 } else if (command == 0 && !isspace(UChar(ch))) {
7834 } else if (ch == '\n' || ch == '\r') {
7835 if ((command == 'd') && !top) {
7836 (void) fputs("Do not nest test-d\n", stdout);
7841 (void) fputs("> ", stdout);
7842 (void) fflush(stdout);
7847 for (n = 0; n < SIZEOF(cmds); ++n) {
7848 if (cmds[n].code == command) {
7849 doit = cmds[n].narrow_func;
7852 #if USE_WIDEC_SUPPORT
7853 if (toupper(cmds[n].code) == command) {
7854 doit = cmds[n].wide_func;
7860 if (doit != NULL && doit(FALSE) == OK) {
7862 * This may be overkill; it is intended to reset everything back
7863 * to the initial terminal modes so that tests don't get in
7867 set_terminal_modes();
7872 if (command == '?') {
7873 (void) puts("This is the ncurses capability tester.");
7875 puts("You may select a test from the main menu by typing the");
7877 puts("key letter of the choice (the letter to left of the =)");
7879 puts("at the > prompt. Type `q' to exit.");
7887 /*+-------------------------------------------------------------------------
7889 --------------------------------------------------------------------------*/
7892 main(int argc, char *argv[])
7896 #ifdef NCURSES_VERSION_PATCH
7897 #if HAVE_USE_DEFAULT_COLORS
7898 int default_fg = COLOR_WHITE;
7899 int default_bg = COLOR_BLACK;
7900 bool default_colors = FALSE;
7901 #if HAVE_ASSUME_DEFAULT_COLORS
7902 bool assumed_colors = FALSE;
7906 bool monochrome = FALSE;
7907 #if HAVE_COLOR_CONTENT
7908 bool xterm_colors = FALSE;
7909 char *palette_file = 0;
7912 setlocale(LC_ALL, "");
7914 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) {
7916 #ifdef NCURSES_VERSION_PATCH
7917 #if HAVE_USE_DEFAULT_COLORS
7918 #if HAVE_ASSUME_DEFAULT_COLORS
7920 assumed_colors = TRUE;
7921 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7923 default_fg = COLOR_WHITE;
7926 default_bg = COLOR_BLACK;
7932 default_colors = TRUE;
7942 my_e_param = atoi(optarg);
7943 #ifdef NCURSES_VERSION
7944 if (my_e_param > 3) /* allow extended layouts */
7953 ripoffline(-1, rip_footer);
7956 ripoffline(1, rip_header);
7958 #endif /* HAVE_RIPOFFLINE */
7962 #if HAVE_COLOR_CONTENT
7964 palette_file = optarg;
7969 nap_msec = (int) atol(optarg);
7972 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(_NC_WINDOWS)
7979 save_trace = (unsigned) strtol(optarg, 0, 0);
7982 #if HAVE_COLOR_CONTENT
7984 xterm_colors = TRUE;
7993 * If there's no menus (unlikely for ncurses!), then we'll have to set
7994 * tracing on initially, just in case the user wants to test something that
7995 * doesn't involve wGetchar.
7998 /* enable debugging */
8000 curses_trace(save_trace);
8002 if (!isatty(fileno(stdin)))
8003 curses_trace(save_trace);
8004 #endif /* USE_LIBMENU */
8008 /* tell it we're going to play with soft keys */
8009 slk_init(my_e_param);
8013 /* set up null signal catcher so we can see what interrupts to getch do */
8014 signal(SIGUSR1, announce_sig);
8017 /* we must initialize the curses data structure only once */
8021 set_terminal_modes();
8024 /* tests, in general, will want these modes */
8025 UseColors = (bool) (monochrome ? FALSE : has_colors());
8029 #ifdef NCURSES_VERSION_PATCH
8030 MaxColors = COLORS; /* was > 16 ? 16 : COLORS */
8031 #if HAVE_USE_DEFAULT_COLORS
8032 if (default_colors) {
8033 use_default_colors();
8036 #if HAVE_ASSUME_DEFAULT_COLORS
8038 assume_default_colors(default_fg, default_bg);
8041 #else /* normal SVr4 curses */
8042 MaxColors = COLORS; /* was > 8 ? 8 : COLORS */
8044 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
8046 #if HAVE_COLOR_CONTENT
8047 if (can_change_color()) {
8048 init_all_colors(xterm_colors, palette_file);
8054 * Return to terminal mode, so we're guaranteed of being able to
8055 * select terminal commands even if the capabilities are wrong.
8059 #if HAVE_CURSES_VERSION
8060 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
8061 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
8062 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
8063 NCURSES_VERSION_MAJOR,
8064 NCURSES_VERSION_MINOR,
8065 NCURSES_VERSION_PATCH);
8067 (void) puts("Welcome to ncurses. Press ? for help.");
8072 ExitProgram(EXIT_SUCCESS);
8075 /* ncurses.c ends here */