1 /****************************************************************************
2 * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
28 /****************************************************************************
31 ncurses.c --- ncurses library exerciser
37 An interactive test module for the ncurses library.
40 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
41 Thomas E. Dickey (beginning revision 1.27 in 1996).
43 $Id: ncurses.c,v 1.469 2017/10/01 18:22:48 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
84 #define NCURSES_CONST_PARAM char
86 #define mmask_t chtype /* not specified in XSI */
89 #ifdef CURSES_ACS_ARRAY
90 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
91 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
92 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
93 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
94 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
95 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
96 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
98 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
99 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
100 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
101 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
102 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
103 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
104 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
109 #ifdef CURSES_WACS_ARRAY
110 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
111 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
112 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
113 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
114 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
115 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
116 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
123 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
124 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
125 #define reset_wchars(state) init_mb(state)
126 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
127 #define count_wchars(src, len, state) wcstombs(0, src, len)
128 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
129 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
134 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
135 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
136 #define reset_mbytes(state) init_mb(state)
137 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
138 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
139 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
140 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
144 #define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real)
146 #define P(string) printw("%s\n", string)
148 #define BLANK ' ' /* this is the background character */
150 static int MaxColors; /* the actual number of colors we'll use */
151 static int MinColors; /* the minimum color code */
152 static bool UseColors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
157 #if HAVE_COLOR_CONTENT
160 NCURSES_COLOR_T green;
161 NCURSES_COLOR_T blue;
164 static RGB_DATA *all_colors;
167 static void main_menu(bool);
168 static void failed(const char *s) GCC_NORETURN;
171 failed(const char *s)
175 ExitProgram(EXIT_FAILURE);
191 isQuit(int c, bool escape)
193 return ((c) == QUIT || (escape && ((c) == ESCAPE)));
195 #define case_QUIT QUIT: case ESCAPE
197 /* Common function to allow ^T to toggle trace-mode in the middle of a test
198 * so that trace-files can be made smaller.
201 wGetchar(WINDOW *win)
205 while ((c = wgetch(win)) == CTRL('T')) {
207 save_trace = _nc_tracing;
208 Trace(("TOGGLE-TRACING OFF"));
211 _nc_tracing = save_trace;
215 Trace(("TOGGLE-TRACING ON"));
222 #define Getchar() wGetchar(stdscr)
225 /* replaces wgetnstr(), since we want to be able to edit values */
227 wGetstring(WINDOW *win, char *buffer, int limit)
234 (void) wattrset(win, A_REVERSE);
236 x = (int) strlen(buffer);
238 if (x > (int) strlen(buffer))
239 x = (int) strlen(buffer);
241 wprintw(win, "%-*s", limit, buffer);
242 wmove(win, y0, x0 + x);
243 switch (ch = wGetchar(win)) {
256 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
274 if (!isprint(ch) || ch >= KEY_MIN) {
276 } else if ((int) strlen(buffer) < limit) {
278 for (j = (int) strlen(buffer) + 1; j > x; --j) {
279 buffer[j] = buffer[j - 1];
281 buffer[x++] = (char) ch;
288 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
296 fullwidth_digit(int ch)
298 return (wchar_t) (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_digit(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = (wchar_t) ch;
323 make_fullwidth_digit(cchar_t *target, int digit)
327 source[0] = fullwidth_digit(digit + '0');
329 setcchar(target, source, A_NORMAL, 0, 0);
334 wGet_wchar(WINDOW *win, wint_t *result)
338 while ((c = wget_wch(win, result)) == CTRL('T')) {
340 save_trace = _nc_tracing;
341 Trace(("TOGGLE-TRACING OFF"));
344 _nc_tracing = save_trace;
348 Trace(("TOGGLE-TRACING ON"));
351 c = wget_wch(win, result);
355 #define Get_wchar(result) wGet_wchar(stdscr, result)
357 /* replaces wgetn_wstr(), since we want to be able to edit values */
359 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
368 (void) wattrset(win, A_REVERSE);
370 x = (int) wcslen(buffer);
372 if (x > (int) wcslen(buffer))
373 x = (int) wcslen(buffer);
375 /* clear the "window' */
377 wprintw(win, "%*s", limit, " ");
379 /* write the existing buffer contents */
381 waddnwstr(win, buffer, limit);
383 /* positions the cursor past character 'x' */
385 waddnwstr(win, buffer, x);
387 switch (wGet_wchar(win, &ch)) {
427 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
447 } else if ((int) wcslen(buffer) < limit) {
449 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
450 buffer[j] = buffer[j - 1];
452 buffer[x++] = (wchar_t) ch;
459 wattroff(win, A_REVERSE);
470 addstr("Press any key to continue... ");
475 Cannot(const char *what)
477 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
482 ShellOut(bool message)
485 addstr("Shelling out...");
491 IGNORE_RC(system("sh"));
494 addstr("returned from shellout.\n");
498 #ifdef NCURSES_MOUSE_VERSION
500 * This function is the same as _tracemouse(), but we cannot count on that
501 * being available in the non-debug library.
504 mouse_decode(MEVENT const *ep)
506 static char buf[80 + (5 * 10) + (32 * 15)];
508 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
509 "id %2d at (%2d, %2d, %d) state %4lx = {",
510 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
513 if ((ep->bstate & m)==m) { \
514 _nc_STRCAT(buf, s, sizeof(buf)); \
515 _nc_STRCAT(buf, ", ", sizeof(buf)); \
518 SHOW(BUTTON1_RELEASED, "release-1");
519 SHOW(BUTTON1_PRESSED, "press-1");
520 SHOW(BUTTON1_CLICKED, "click-1");
521 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
522 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
523 #if NCURSES_MOUSE_VERSION == 1
524 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
527 SHOW(BUTTON2_RELEASED, "release-2");
528 SHOW(BUTTON2_PRESSED, "press-2");
529 SHOW(BUTTON2_CLICKED, "click-2");
530 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
531 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
532 #if NCURSES_MOUSE_VERSION == 1
533 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
536 SHOW(BUTTON3_RELEASED, "release-3");
537 SHOW(BUTTON3_PRESSED, "press-3");
538 SHOW(BUTTON3_CLICKED, "click-3");
539 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
540 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
541 #if NCURSES_MOUSE_VERSION == 1
542 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
545 SHOW(BUTTON4_RELEASED, "release-4");
546 SHOW(BUTTON4_PRESSED, "press-4");
547 SHOW(BUTTON4_CLICKED, "click-4");
548 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
549 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
550 #if NCURSES_MOUSE_VERSION == 1
551 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
554 #if NCURSES_MOUSE_VERSION == 2
555 SHOW(BUTTON5_RELEASED, "release-5");
556 SHOW(BUTTON5_PRESSED, "press-5");
557 SHOW(BUTTON5_CLICKED, "click-5");
558 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
559 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
562 SHOW(BUTTON_CTRL, "ctrl");
563 SHOW(BUTTON_SHIFT, "shift");
564 SHOW(BUTTON_ALT, "alt");
565 SHOW(ALL_MOUSE_EVENTS, "all-events");
566 SHOW(REPORT_MOUSE_POSITION, "position");
570 if (buf[strlen(buf) - 1] == ' ')
571 buf[strlen(buf) - 2] = '\0';
572 _nc_STRCAT(buf, "}", sizeof(buf));
577 show_mouse(WINDOW *win)
585 outside = !wenclose(win, event.y, event.x);
588 (void) wstandout(win);
589 waddstr(win, "KEY_MOUSE");
590 (void) wstandend(win);
592 waddstr(win, "KEY_MOUSE");
594 wprintw(win, ", %s", mouse_decode(&event));
599 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
603 wmove(win, event.y, event.x);
611 #endif /* NCURSES_MOUSE_VERSION */
613 /****************************************************************************
615 * Character input test
617 ****************************************************************************/
619 #define NUM_GETCH_FLAGS 256
620 typedef bool GetchFlags[NUM_GETCH_FLAGS];
623 setup_getch(WINDOW *win, GetchFlags flags)
625 keypad(win, flags['k']); /* should be redundant, but for testing */
626 meta(win, flags['m']); /* force this to a known state */
634 init_getch(WINDOW *win, GetchFlags flags, int delay)
636 memset(flags, FALSE, NUM_GETCH_FLAGS);
637 flags[UChar('k')] = (win == stdscr);
638 flags[UChar('m')] = TRUE;
639 flags[UChar('t')] = (delay != 0);
641 setup_getch(win, flags);
645 blocking_getch(GetchFlags flags, int delay)
647 return ((delay < 0) && flags['t']);
650 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
653 wgetch_help(WINDOW *win, GetchFlags flags)
655 static const char *help[] =
657 "e -- toggle echo mode"
658 ,"g -- triggers a getstr test"
659 ,"k -- toggle keypad/literal mode"
660 ,"m -- toggle meta (7-bit/8-bit) mode"
663 ,"t -- toggle timeout"
664 ,"w -- create a new window"
666 ,"z -- suspend this process"
670 unsigned chk = ((SIZEOF(help) + 1) / 2);
675 printw("Type any key to see its %s value. Also:\n",
676 flags['k'] ? "keypad" : "literal");
677 for (n = 0; n < SIZEOF(help); ++n) {
678 const char *msg = help[n];
679 int row = 1 + (int) (n % chk);
680 int col = (n >= chk) ? COLS / 2 : 0;
681 int flg = ((strstr(msg, "toggle") != 0)
682 && (flags[UChar(*msg)] != FALSE));
683 if (*msg == '^' && ExitOnEscape())
684 msg = "^[,^q -- quit";
687 MvPrintw(row, col, "%s", msg);
698 wgetch_wrap(WINDOW *win, int first_y)
700 int last_y = getmaxy(win) - 1;
701 int y = getcury(win) + 1;
709 #if defined(KEY_RESIZE) && HAVE_WRESIZE
715 static WINSTACK *winstack = 0;
716 static unsigned len_winstack = 0;
729 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
731 unsigned need = (level + 1) * 2;
733 assert(level < (unsigned) COLS);
737 winstack = typeMalloc(WINSTACK, len_winstack);
738 } else if (need >= len_winstack) {
740 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
743 failed("remember_boxes");
744 winstack[level].text = txt_win;
745 winstack[level].frame = box_win;
748 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
752 /* this chunk is now done in resize_term() */
759 #define slk_repaint() /* nothing */
762 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
764 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
765 * Resize both and paint the box in the parent.
768 resize_boxes(unsigned level, WINDOW *win)
772 int high = LINES - base;
776 wnoutrefresh(stdscr);
780 for (n = 0; n < level; ++n) {
781 wresize(winstack[n].frame, high, wide);
782 wresize(winstack[n].text, high - 2, wide - 2);
785 werase(winstack[n].text);
786 box(winstack[n].frame, 0, 0);
787 wnoutrefresh(winstack[n].frame);
788 wprintw(winstack[n].text,
790 getmaxy(winstack[n].text),
791 getmaxx(winstack[n].text));
792 wnoutrefresh(winstack[n].text);
793 if (winstack[n].text == win)
798 #endif /* resize_boxes */
800 #define forget_boxes() /* nothing */
801 #define remember_boxes(level,text,frame) /* nothing */
805 * Return-code is OK/ERR or a keyname.
810 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
814 wgetch_test(unsigned level, WINDOW *win, int delay)
817 int first_y, first_x;
822 init_getch(win, flags, delay);
823 notimeout(win, FALSE);
824 wtimeout(win, delay);
825 getyx(win, first_y, first_x);
827 wgetch_help(win, flags);
828 wsetscrreg(win, first_y, getmaxy(win) - 1);
832 while ((c = wGetchar(win)) == ERR) {
834 if (blocking_getch(flags, delay)) {
835 (void) wprintw(win, "%05d: input error", incount);
838 (void) wprintw(win, "%05d: input timed out", incount);
840 wgetch_wrap(win, first_y);
842 if (c == ERR && blocking_getch(flags, delay)) {
844 wgetch_wrap(win, first_y);
845 } else if (isQuit(c, ExitOnEscape())) {
847 } else if (c == 'e') {
848 flags[UChar('e')] = !flags[UChar('e')];
849 setup_getch(win, flags);
850 wgetch_help(win, flags);
851 } else if (c == 'g') {
852 waddstr(win, "getstr test: ");
854 c = wgetnstr(win, buf, sizeof(buf) - 1);
856 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
857 (int) strlen(buf), buf,
860 wgetch_wrap(win, first_y);
861 } else if (c == 'k') {
862 flags[UChar('k')] = !flags[UChar('k')];
863 setup_getch(win, flags);
864 wgetch_help(win, flags);
865 } else if (c == 'm') {
866 flags[UChar('m')] = !flags[UChar('m')];
867 setup_getch(win, flags);
868 wgetch_help(win, flags);
869 } else if (c == 's') {
871 } else if (c == 't') {
872 notimeout(win, flags[UChar('t')]);
873 flags[UChar('t')] = !flags[UChar('t')];
874 wgetch_help(win, flags);
875 } else if (c == 'w') {
876 int high = getmaxy(win) - 1 - first_y + 1;
877 int wide = getmaxx(win) - first_x;
879 int new_y = first_y + getbegy(win);
880 int new_x = first_x + getbegx(win);
882 getyx(win, old_y, old_x);
883 if (high > 2 && wide > 2) {
884 WINDOW *wb = newwin(high, wide, new_y, new_x);
885 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
890 remember_boxes(level, wi, wb);
891 wgetch_test(level + 1, wi, delay);
895 wgetch_help(win, flags);
896 wmove(win, old_y, old_x);
902 } else if (c == 'z') {
903 kill(getpid(), SIGTSTP);
906 wprintw(win, "Key pressed: %04o ", c);
907 #ifdef NCURSES_MOUSE_VERSION
908 if (c == KEY_MOUSE) {
911 #endif /* NCURSES_MOUSE_VERSION */
913 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
914 if (c == KEY_RESIZE) {
915 resize_boxes(level, win);
918 (void) waddstr(win, keyname(c));
919 } else if (c >= 0x80) {
920 unsigned c2 = (unsigned) c;
921 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
922 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
926 (void) wprintw(win, "%c", UChar(c));
927 else if (c2 != UChar(c))
928 (void) wprintw(win, "M-%s", unctrl(c2));
930 (void) wprintw(win, "%s", unctrl(c2));
931 waddstr(win, " (high-half character)");
934 (void) wprintw(win, "%c (ASCII printable character)", c);
936 (void) wprintw(win, "%s (ASCII control character)",
939 wgetch_wrap(win, first_y);
946 init_getch(win, flags, delay);
950 begin_getch_test(void)
957 #ifdef NCURSES_MOUSE_VERSION
958 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
961 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
963 getnstr(buf, sizeof(buf) - 1);
967 if (isdigit(UChar(buf[0]))) {
968 delay = atoi(buf) * 100;
978 finish_getch_test(void)
980 #ifdef NCURSES_MOUSE_VERSION
981 mousemask(0, (mmask_t *) 0);
990 getch_test(bool recur GCC_UNUSED)
992 int delay = begin_getch_test();
995 wgetch_test(0, stdscr, delay);
1002 #if USE_WIDEC_SUPPORT
1004 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1005 * Resize both and paint the box in the parent.
1007 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1009 resize_wide_boxes(unsigned level, WINDOW *win)
1013 int high = LINES - base;
1017 wnoutrefresh(stdscr);
1021 for (n = 0; n < level; ++n) {
1022 wresize(winstack[n].frame, high, wide);
1023 wresize(winstack[n].text, high - 2, wide - 2);
1026 werase(winstack[n].text);
1027 box_set(winstack[n].frame, 0, 0);
1028 wnoutrefresh(winstack[n].frame);
1029 wprintw(winstack[n].text,
1031 getmaxy(winstack[n].text),
1032 getmaxx(winstack[n].text));
1033 wnoutrefresh(winstack[n].text);
1034 if (winstack[n].text == win)
1039 #endif /* KEY_RESIZE */
1042 wcstos(const wchar_t *src)
1046 const wchar_t *tmp = src;
1047 #ifndef state_unused
1051 reset_wchars(state);
1052 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1053 unsigned have = (unsigned) need;
1054 if ((result = typeCalloc(char, have + 1)) != 0) {
1056 if (trans_wchars(result, tmp, have, &state) != have) {
1068 wget_wch_test(unsigned level, WINDOW *win, int delay)
1070 wchar_t wchar_buf[BUFSIZ];
1071 wint_t wint_buf[BUFSIZ];
1072 int first_y, first_x;
1079 init_getch(win, flags, delay);
1080 notimeout(win, FALSE);
1081 wtimeout(win, delay);
1082 getyx(win, first_y, first_x);
1084 wgetch_help(win, flags);
1085 wsetscrreg(win, first_y, getmaxy(win) - 1);
1086 scrollok(win, TRUE);
1089 while ((code = wGet_wchar(win, &c)) == ERR) {
1091 if (blocking_getch(flags, delay)) {
1092 (void) wprintw(win, "%05d: input error", incount);
1095 (void) wprintw(win, "%05d: input timed out", incount);
1097 wgetch_wrap(win, first_y);
1099 if (code == ERR && blocking_getch(flags, delay)) {
1100 wprintw(win, "ERR");
1101 wgetch_wrap(win, first_y);
1102 } else if (isQuit((int) c, ExitOnEscape())) {
1104 } else if (c == 'e') {
1105 flags[UChar('e')] = !flags[UChar('e')];
1106 setup_getch(win, flags);
1107 wgetch_help(win, flags);
1108 } else if (c == 'g') {
1109 waddstr(win, "getstr test: ");
1111 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1114 wprintw(win, "wgetn_wstr returns an error.");
1117 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1120 if ((temp = wcstos(wchar_buf)) != 0) {
1121 wprintw(win, "I saw %d characters:\n\t`%s'.",
1122 (int) wcslen(wchar_buf), temp);
1125 wprintw(win, "I saw %d characters (cannot convert).",
1126 (int) wcslen(wchar_buf));
1130 wgetch_wrap(win, first_y);
1131 } else if (c == 'k') {
1132 flags[UChar('k')] = !flags[UChar('k')];
1133 setup_getch(win, flags);
1134 wgetch_help(win, flags);
1135 } else if (c == 'm') {
1136 flags[UChar('m')] = !flags[UChar('m')];
1137 setup_getch(win, flags);
1138 wgetch_help(win, flags);
1139 } else if (c == 's') {
1141 } else if (c == 't') {
1142 notimeout(win, flags[UChar('t')]);
1143 flags[UChar('t')] = !flags[UChar('t')];
1144 wgetch_help(win, flags);
1145 } else if (c == 'w') {
1146 int high = getmaxy(win) - 1 - first_y + 1;
1147 int wide = getmaxx(win) - first_x;
1149 int new_y = first_y + getbegy(win);
1150 int new_x = first_x + getbegx(win);
1152 getyx(win, old_y, old_x);
1153 if (high > 2 && wide > 2) {
1154 WINDOW *wb = newwin(high, wide, new_y, new_x);
1155 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1160 remember_boxes(level, wi, wb);
1161 wget_wch_test(level + 1, wi, delay);
1165 wgetch_help(win, flags);
1166 wmove(win, old_y, old_x);
1171 } else if (c == 'z') {
1172 kill(getpid(), SIGTSTP);
1175 wprintw(win, "Key pressed: %04o ", (int) c);
1176 #ifdef NCURSES_MOUSE_VERSION
1177 if (c == KEY_MOUSE) {
1180 #endif /* NCURSES_MOUSE_VERSION */
1181 if (code == KEY_CODE_YES) {
1182 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1183 if (c == KEY_RESIZE) {
1184 resize_wide_boxes(level, win);
1187 (void) waddstr(win, keyname((wchar_t) c));
1189 (void) waddstr(win, key_name((wchar_t) c));
1190 if (c < 256 && iscntrl(c)) {
1191 (void) wprintw(win, " (control character)");
1193 (void) wprintw(win, " = %#x (printable character)",
1197 wgetch_wrap(win, first_y);
1204 init_getch(win, flags, delay);
1208 x_getch_test(bool recur GCC_UNUSED)
1210 int delay = begin_getch_test();
1213 wget_wch_test(0, stdscr, delay);
1215 finish_getch_test();
1221 /****************************************************************************
1223 * Character attributes test
1225 ****************************************************************************/
1227 #if HAVE_SETUPTERM || HAVE_TGETENT
1228 #define get_ncv() TIGETNUM("ncv","NC")
1229 #define get_xmc() TIGETNUM("xmc","sg")
1231 #define get_ncv() -1
1232 #define get_xmc() -1
1239 static int first = TRUE;
1240 static chtype result = 0;
1246 char *area_pointer = parsed;
1248 tgetent(buffer, getenv("TERM"));
1251 if (TIGETSTR("smso", "so"))
1252 result |= A_STANDOUT;
1253 if (TIGETSTR("smul", "us"))
1254 result |= A_UNDERLINE;
1255 if (TIGETSTR("rev", "mr"))
1256 result |= A_REVERSE;
1257 if (TIGETSTR("blink", "mb"))
1259 if (TIGETSTR("dim", "mh"))
1261 if (TIGETSTR("bold", "md"))
1263 if (TIGETSTR("smacs", "ac"))
1264 result |= A_ALTCHARSET;
1270 #define termattrs() my_termattrs()
1273 #define ATTRSTRING_1ST 32 /* ' ' */
1274 #define ATTRSTRING_END 126 /* '~' */
1276 #define COLS_PRE_ATTRS 5
1277 #define COLS_AFT_ATTRS 15
1278 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1279 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1280 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1282 static char attr_test_string[MAX_ATTRSTRING + 1];
1285 attr_legend(WINDOW *helpwin)
1290 MvWPrintw(helpwin, row++, col,
1292 MvWPrintw(helpwin, row++, col,
1295 MvWPrintw(helpwin, row++, col,
1296 "Modify the test strings:");
1297 MvWPrintw(helpwin, row++, col,
1298 " A digit sets gaps on each side of displayed attributes");
1299 MvWPrintw(helpwin, row++, col,
1300 " </> shifts the text left/right. ");
1302 MvWPrintw(helpwin, row++, col,
1305 MvWPrintw(helpwin, row++, col,
1306 " f/F/b/B toggle foreground/background background color");
1307 MvWPrintw(helpwin, row++, col,
1308 " t/T toggle text/background color attribute");
1310 MvWPrintw(helpwin, row++, col,
1311 " a/A toggle ACS (alternate character set) mapping");
1312 MvWPrintw(helpwin, row, col,
1313 " v/V toggle video attribute to combine with each line");
1314 #if USE_WIDEC_SUPPORT
1315 MvWPrintw(helpwin, row, col,
1316 " w/W toggle normal/wide (double-width) test-characters");
1321 show_color_attr(int fg, int bg, int tx)
1324 printw(" Colors (fg %d, bg %d", fg, bg);
1326 printw(", text %d", tx);
1332 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1339 *fg = (NCURSES_COLOR_T) (*fg + 1);
1342 *fg = (NCURSES_COLOR_T) (*fg - 1);
1345 *bg = (NCURSES_COLOR_T) (*bg + 1);
1348 *bg = (NCURSES_COLOR_T) (*bg - 1);
1351 *tx = (NCURSES_COLOR_T) (*tx + 1);
1354 *tx = (NCURSES_COLOR_T) (*tx - 1);
1362 *fg = (NCURSES_COLOR_T) MinColors;
1363 if (*fg < MinColors)
1364 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1366 *bg = (NCURSES_COLOR_T) MinColors;
1367 if (*bg < MinColors)
1368 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1372 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1381 adjust_attr_string(int adjust)
1383 char save = attr_test_string[0];
1384 int first = ((int) UChar(save)) + adjust;
1387 if (first >= ATTRSTRING_1ST) {
1388 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1389 if (k > ATTRSTRING_END)
1391 attr_test_string[j] = (char) k;
1392 if (((k + 1 - first) % 5) == 0) {
1393 if (++j >= MAX_ATTRSTRING)
1395 attr_test_string[j] = ' ';
1398 if ((LEN_ATTRSTRING - j) > 5) {
1399 attr_test_string[0] = save;
1400 adjust_attr_string(adjust - 1);
1402 while (j < MAX_ATTRSTRING)
1403 attr_test_string[j++] = ' ';
1404 attr_test_string[j] = '\0';
1410 * Prefer the right-end of the string for starting, since that maps to the
1411 * VT100 line-drawing.
1414 default_attr_string(void)
1416 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1417 result += (LEN_ATTRSTRING / 5);
1418 if (result < ATTRSTRING_1ST)
1419 result = ATTRSTRING_1ST;
1424 init_attr_string(void)
1426 attr_test_string[0] = (char) default_attr_string();
1427 adjust_attr_string(0);
1431 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1433 int ncv = get_ncv();
1434 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1437 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1438 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1439 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1441 printw("%*s", skip, " ");
1443 * Just for testing, write text using the alternate character set one
1444 * character at a time (to pass its rendition directly), and use the
1445 * string operation for the other attributes.
1449 if (attr & A_ALTCHARSET) {
1453 for (s = attr_test_string; *s != '\0'; ++s) {
1455 (void) waddch(win, ch | attr);
1458 (void) wattrset(win, AttrArg(attr, 0));
1459 (void) waddstr(win, attr_test_string);
1460 (void) wattroff(win, (int) attr);
1463 printw("%*s", skip, " ");
1464 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1465 if (test != A_NORMAL) {
1466 if (!(termattrs() & test)) {
1469 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1470 static const chtype table[] =
1489 for (n = 0; n < SIZEOF(table); n++) {
1490 if ((table[n] & attr) != 0
1491 && ((1 << n) & ncv) != 0) {
1499 if ((termattrs() & test) != test) {
1509 NCURSES_CONST char *name;
1512 static const ATTR_TBL attrs_to_test[] = {
1513 { A_STANDOUT, "STANDOUT" },
1514 { A_REVERSE, "REVERSE" },
1516 { A_UNDERLINE, "UNDERLINE" },
1518 { A_BLINK, "BLINK" },
1519 { A_PROTECT, "PROTECT" },
1521 { A_INVIS, "INVISIBLE" },
1524 { A_ITALIC, "ITALIC" },
1526 { A_NORMAL, "NORMAL" },
1531 init_attr_list(ATTR_TBL * target, attr_t attrs)
1533 unsigned result = 0;
1536 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1537 attr_t test = attrs_to_test[n].attr;
1538 if (test == A_NORMAL || (test & attrs) != 0) {
1539 target[result++] = attrs_to_test[n];
1545 #if USE_WIDEC_SUPPORT
1548 NCURSES_CONST char *name;
1551 static const W_ATTR_TBL w_attrs_to_test[] = {
1552 { WA_STANDOUT, "STANDOUT" },
1553 { WA_REVERSE, "REVERSE" },
1554 { WA_BOLD, "BOLD" },
1555 { WA_UNDERLINE, "UNDERLINE" },
1557 { WA_BLINK, "BLINK" },
1558 { WA_PROTECT, "PROTECT" },
1560 { WA_INVIS, "INVISIBLE" },
1563 { WA_ITALIC, "ITALIC" },
1565 { WA_NORMAL, "NORMAL" },
1570 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1572 unsigned result = 0;
1575 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1576 attr_t test = w_attrs_to_test[n].attr;
1577 if (test == WA_NORMAL || (test & attrs) != 0) {
1578 target[result++] = w_attrs_to_test[n];
1586 attr_getc(int *skip,
1587 NCURSES_COLOR_T *fg,
1588 NCURSES_COLOR_T *bg,
1589 NCURSES_COLOR_T *tx,
1602 if (ch < 256 && isdigit(ch)) {
1610 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1612 attr_legend(helpwin);
1635 adjust_attr_string(-1);
1638 adjust_attr_string(1);
1644 error = cycle_color_attr(ch, fg, bg, tx);
1653 attr_test(bool recur GCC_UNUSED)
1654 /* test text attributes */
1657 int skip = get_xmc();
1658 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1659 NCURSES_COLOR_T bg = COLOR_BLACK;
1660 NCURSES_COLOR_T tx = -1;
1663 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1664 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1665 unsigned my_size = init_attr_list(my_list, termattrs());
1668 for (j = 0; j < my_size; ++j) {
1669 my_wins[j] = subwin(stdscr,
1671 2 + (int) (2 * j), COL_ATTRSTRING);
1672 scrollok(my_wins[j], FALSE);
1678 n = skip; /* make it easy */
1684 chtype normal = A_NORMAL | BLANK;
1685 chtype extras = (chtype) ac;
1688 NCURSES_PAIRS_T pair = 0;
1689 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1691 if (init_pair(pair, fg, bg) == ERR) {
1694 normal |= (chtype) COLOR_PAIR(pair);
1699 if (init_pair(pair, tx, bg) == ERR) {
1702 extras |= (chtype) COLOR_PAIR(pair);
1712 MvAddStr(0, 20, "Character attribute test display");
1714 for (j = 0; j < my_size; ++j) {
1715 bool arrow = (j == k);
1716 row = show_attr(my_wins[j], row, n, arrow,
1724 MvPrintw(row, COLS_PRE_ATTRS,
1725 "This terminal does %shave the magic-cookie glitch",
1726 get_xmc() > -1 ? "" : "not ");
1727 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1728 show_color_attr(fg, bg, tx);
1729 printw(" ACS (%d)", ac != 0);
1732 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1734 bkgdset(A_NORMAL | BLANK);
1739 Cannot("does not support video attributes.");
1744 #if USE_WIDEC_SUPPORT
1745 static bool use_fullwidth;
1746 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1748 #define FULL_LO 0xff00
1749 #define FULL_HI 0xff5e
1750 #define HALF_LO 0x20
1752 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1753 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1754 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1757 * Returns an ASCII code in [32..126]
1760 normal_wchar(int ch)
1762 wchar_t result = (wchar_t) ch;
1763 if (isFullWidth(ch))
1764 result = ToNormalWidth(ch);
1769 * Returns either an ASCII code in in [32..126] or full-width in
1770 * [0xff00..0xff5e], according to use_fullwidth setting.
1773 target_wchar(int ch)
1775 wchar_t result = (wchar_t) ch;
1776 if (use_fullwidth) {
1777 if (!isFullWidth(ch))
1778 result = ToFullWidth(ch);
1780 if (isFullWidth(ch))
1781 result = ToNormalWidth(ch);
1787 wide_adjust_attr_string(int adjust)
1789 wchar_t save = wide_attr_test_string[0];
1790 int first = ((int) normal_wchar(save)) + adjust;
1793 if (first >= ATTRSTRING_1ST) {
1794 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1795 if (k > ATTRSTRING_END)
1797 wide_attr_test_string[j] = target_wchar(k);
1798 if (((k + 1 - first) % 5) == 0) {
1799 if (++j >= MAX_ATTRSTRING)
1801 wide_attr_test_string[j] = ' ';
1804 if ((LEN_ATTRSTRING - j) > 5) {
1805 wide_attr_test_string[0] = save;
1806 wide_adjust_attr_string(adjust - 1);
1808 while (j < MAX_ATTRSTRING)
1809 wide_attr_test_string[j++] = ' ';
1810 wide_attr_test_string[j] = '\0';
1816 wide_init_attr_string(void)
1818 use_fullwidth = FALSE;
1819 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1820 wide_adjust_attr_string(0);
1824 set_wide_background(NCURSES_PAIRS_T pair)
1831 setcchar(&normal, blank, A_NORMAL, pair, 0);
1837 get_wide_background(void)
1839 attr_t result = WA_NORMAL;
1842 NCURSES_PAIRS_T pair;
1845 memset(&ch, 0, sizeof(ch));
1846 if (getbkgrnd(&ch) != ERR) {
1847 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1855 wide_show_attr(WINDOW *win,
1860 NCURSES_PAIRS_T pair,
1863 int ncv = get_ncv();
1864 attr_t test = attr & ~WA_ALTCHARSET;
1867 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1868 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1869 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1871 printw("%*s", skip, " ");
1874 * Just for testing, write text using the alternate character set one
1875 * character at a time (to pass its rendition directly), and use the
1876 * string operation for the other attributes.
1880 if (attr & WA_ALTCHARSET) {
1884 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1888 setcchar(&ch, fill, attr, pair, 0);
1889 (void) wadd_wch(win, &ch);
1892 attr_t old_attr = 0;
1893 NCURSES_PAIRS_T old_pair = 0;
1895 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1896 (void) wattr_set(win, attr, pair, 0);
1897 (void) waddwstr(win, wide_attr_test_string);
1898 (void) wattr_set(win, old_attr, old_pair, 0);
1901 printw("%*s", skip, " ");
1902 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1903 if (test != A_NORMAL) {
1904 if (!(term_attrs() & test)) {
1907 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1908 static const attr_t table[] =
1922 for (n = 0; n < SIZEOF(table); n++) {
1923 if ((table[n] & attr) != 0
1924 && ((1 << n) & ncv) != 0) {
1932 if ((term_attrs() & test) != test) {
1941 wide_attr_getc(int *skip,
1942 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1943 NCURSES_COLOR_T *tx, int *ac,
1944 unsigned *kc, unsigned limit)
1954 if (ch < 256 && isdigit(ch)) {
1962 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1963 box_set(helpwin, 0, 0);
1964 attr_legend(helpwin);
1987 use_fullwidth = FALSE;
1988 wide_adjust_attr_string(0);
1991 use_fullwidth = TRUE;
1992 wide_adjust_attr_string(0);
1995 wide_adjust_attr_string(-1);
1998 wide_adjust_attr_string(1);
2004 error = cycle_color_attr(ch, fg, bg, tx);
2013 x_attr_test(bool recur GCC_UNUSED)
2014 /* test text attributes using wide-character calls */
2017 int skip = get_xmc();
2018 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2019 NCURSES_COLOR_T bg = COLOR_BLACK;
2020 NCURSES_COLOR_T tx = -1;
2023 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2024 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2025 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2028 for (j = 0; j < my_size; ++j) {
2029 my_wins[j] = subwin(stdscr,
2031 2 + (int) (2 * j), COL_ATTRSTRING);
2032 scrollok(my_wins[j], FALSE);
2038 n = skip; /* make it easy */
2040 wide_init_attr_string();
2044 NCURSES_PAIRS_T pair = 0;
2045 NCURSES_PAIRS_T extras = 0;
2048 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2051 if (init_pair(pair, fg, bg) == ERR) {
2058 if (init_pair(extras, tx, bg) == ERR) {
2063 set_wide_background(pair);
2066 box_set(stdscr, 0, 0);
2067 MvAddStr(0, 20, "Character attribute test display");
2069 for (j = 0; j < my_size; ++j) {
2070 row = wide_show_attr(my_wins[j], row, n, (j == k),
2078 MvPrintw(row, COLS_PRE_ATTRS,
2079 "This terminal does %shave the magic-cookie glitch",
2080 get_xmc() > -1 ? "" : "not ");
2081 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2082 show_color_attr(fg, bg, tx);
2083 printw(" ACS (%d)", ac != 0);
2086 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2088 set_wide_background(0);
2093 Cannot("does not support extended video attributes.");
2099 /****************************************************************************
2101 * Color support tests
2103 ****************************************************************************/
2105 static NCURSES_CONST char *the_color_names[] =
2126 show_color_name(int y, int x, int color, bool wide)
2128 if (move(y, x) != ERR) {
2133 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2136 } else if (color >= 8) {
2137 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2139 } else if (color < 0) {
2140 _nc_STRCPY(temp, "default", sizeof(temp));
2142 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2143 "%.*s", 16, the_color_names[color]);
2145 printw("%-*.*s", width, width, temp);
2150 color_legend(WINDOW *helpwin, bool wide)
2155 MvWPrintw(helpwin, row++, col,
2158 MvWPrintw(helpwin, row++, col,
2159 "Use up/down arrow to scroll through the display if it is");
2160 MvWPrintw(helpwin, row++, col,
2161 "longer than one screen. Control/N and Control/P can be used");
2162 MvWPrintw(helpwin, row++, col,
2163 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2164 MvWPrintw(helpwin, row++, col,
2165 "full screen; control/B and control/F can be used here.");
2167 MvWPrintw(helpwin, row++, col,
2169 MvWPrintw(helpwin, row++, col,
2170 " a/A toggle altcharset off/on");
2171 MvWPrintw(helpwin, row++, col,
2172 " b/B toggle bold off/on");
2174 MvWPrintw(helpwin, row++, col,
2175 " c/C cycle used-colors through 8,16,...,COLORS");
2177 MvWPrintw(helpwin, row++, col,
2178 " n/N toggle text/number on/off");
2179 MvWPrintw(helpwin, row++, col,
2180 " r/R toggle reverse on/off");
2181 MvWPrintw(helpwin, row++, col,
2182 " w/W toggle width between 8/16 colors");
2183 #if USE_WIDEC_SUPPORT
2185 MvWPrintw(helpwin, row++, col,
2186 "Wide characters:");
2187 MvWPrintw(helpwin, row, col,
2188 " x/X toggle text between ASCII and wide-character");
2195 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2198 color_cycle(int current, int step)
2200 int result = current;
2206 if ((result * 2) > COLORS) {
2209 while ((result * 2) < current) {
2215 if (current >= COLORS) {
2220 if (result > COLORS)
2226 /* generate a color test pattern */
2228 color_test(bool recur GCC_UNUSED)
2233 int grid_top = top + 3;
2234 int page_size = (LINES - grid_top);
2236 int colors_max = COLORS;
2243 bool opt_acsc = FALSE;
2244 bool opt_bold = FALSE;
2245 bool opt_revs = FALSE;
2246 bool opt_nums = FALSE;
2247 bool opt_wide = FALSE;
2251 Cannot("does not support color.");
2255 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2256 done = ((COLS < 16) || (numbered == 0));
2259 * Because the number of colors is usually a power of two, we also use
2260 * a power of two for the number of colors shown per line (to be tidy).
2262 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2267 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2268 if (colors_max * colors_max <= COLOR_PAIRS) {
2269 int limit = (colors_max - MinColors) * (colors_max - MinColors);
2270 if (pairs_max > limit)
2273 if (pairs_max > COLOR_PAIRS)
2274 pairs_max = COLOR_PAIRS;
2277 /* this assumes an 80-column line */
2281 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2285 per_row = (col_limit / 8);
2287 per_row -= MinColors;
2289 row_limit = (pairs_max + per_row - 1) / per_row;
2292 (void) printw("There are %d color pairs and %d colors",
2294 if (colors_max != COLORS)
2295 (void) printw(" (using %d colors)", colors_max);
2297 (void) addstr(" besides 'default'");
2300 MvPrintw(top + 1, 0,
2301 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2304 opt_bold ? "on" : "off");
2306 /* show color names/numbers across the top */
2307 for (i = 0; i < per_row; i++)
2308 show_color_name(top + 2, (i + 1) * width, i + MinColors, opt_wide);
2310 /* show a grid of colors, with color names/ numbers on the left */
2311 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2312 int row = grid_top + (i / per_row) - base_row;
2313 int col = (i % per_row + 1) * width;
2314 NCURSES_PAIRS_T pair = i;
2316 if ((i / per_row) > row_limit)
2319 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - MinColors)) + MinColors)
2320 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - MinColors)) + MinColors)
2321 if (row >= 0 && move(row, col) != ERR) {
2322 NCURSES_COLOR_T fg = InxToFG(i);
2323 NCURSES_COLOR_T bg = InxToBG(i);
2325 init_pair(pair, fg, bg);
2326 attron(COLOR_PAIR(pair));
2328 attron(A_ALTCHARSET);
2335 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2339 printw("%-*.*s", width, width, hello);
2340 (void) attrset(A_NORMAL);
2342 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2343 show_color_name(row, 0, InxToBG(i), opt_wide);
2351 switch (wGetchar(stdscr)) {
2365 colors_max = color_cycle(colors_max, -1);
2368 colors_max = color_cycle(colors_max, 1);
2386 set_color_test(opt_wide, FALSE);
2389 set_color_test(opt_wide, TRUE);
2393 if (base_row <= 0) {
2401 if (base_row + page_size >= row_limit) {
2410 if (base_row <= 0) {
2413 base_row -= (page_size - 1);
2421 if (base_row + page_size >= row_limit) {
2424 base_row += page_size - 1;
2425 if (base_row + page_size >= row_limit) {
2426 base_row = row_limit - page_size - 1;
2431 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2433 color_legend(helpwin, FALSE);
2451 #if USE_WIDEC_SUPPORT
2452 /* generate a color test pattern */
2454 x_color_test(bool recur GCC_UNUSED)
2459 int grid_top = top + 3;
2460 int page_size = (LINES - grid_top);
2461 int pairs_max = (unsigned short) (-1);
2462 int colors_max = COLORS;
2469 bool opt_acsc = FALSE;
2470 bool opt_bold = FALSE;
2471 bool opt_revs = FALSE;
2472 bool opt_wide = FALSE;
2473 bool opt_nums = FALSE;
2474 bool opt_xchr = FALSE;
2475 wchar_t *buffer = 0;
2479 Cannot("does not support color.");
2482 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2483 buffer = (wchar_t *) calloc((size_t) (COLS + 1), sizeof(wchar_t));
2484 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2487 * Because the number of colors is usually a power of two, we also use
2488 * a power of two for the number of colors shown per line (to be tidy).
2490 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2495 pairs_max = (unsigned short) (-1);
2496 if (colors_max * colors_max <= COLOR_PAIRS) {
2497 int limit = (colors_max - MinColors) * (colors_max - MinColors);
2498 if (pairs_max > limit)
2501 if (pairs_max > COLOR_PAIRS)
2502 pairs_max = COLOR_PAIRS;
2508 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2512 per_row = (col_limit / 8);
2514 per_row -= MinColors;
2517 make_fullwidth_text(buffer, hello);
2521 make_narrow_text(buffer, hello);
2524 row_limit = (pairs_max + per_row - 1) / per_row;
2527 (void) printw("There are %d color pairs and %d colors",
2529 if (colors_max != COLORS)
2530 (void) printw(" (using %d colors)", colors_max);
2532 (void) addstr(" besides 'default'");
2535 MvPrintw(top + 1, 0,
2536 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2539 opt_bold ? "on" : "off");
2541 /* show color names/numbers across the top */
2542 for (i = 0; i < per_row; i++)
2543 show_color_name(top + 2, (i + 1) * width, i + MinColors, opt_wide);
2545 /* show a grid of colors, with color names/ numbers on the left */
2546 for (i = (base_row * per_row); i < pairs_max; i++) {
2547 int row = grid_top + (i / per_row) - base_row;
2548 int col = (i % per_row + 1) * width;
2549 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2551 if ((i / per_row) > row_limit)
2554 if (row >= 0 && move(row, col) != ERR) {
2555 init_pair(pair, InxToFG(i), InxToBG(i));
2556 (void) color_set(pair, NULL);
2558 attr_on(WA_ALTCHARSET, NULL);
2560 attr_on(WA_BOLD, NULL);
2562 attr_on(WA_REVERSE, NULL);
2565 _nc_SPRINTF(numbered,
2566 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2569 make_fullwidth_text(buffer, numbered);
2571 make_narrow_text(buffer, numbered);
2574 addnwstr(buffer, width);
2575 (void) attr_set(A_NORMAL, 0, NULL);
2577 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2578 show_color_name(row, 0, InxToBG(i), opt_wide);
2586 switch (wGetchar(stdscr)) {
2600 colors_max = color_cycle(colors_max, -1);
2603 colors_max = color_cycle(colors_max, 1);
2621 set_color_test(opt_wide, FALSE);
2624 set_color_test(opt_wide, TRUE);
2634 if (base_row <= 0) {
2642 if (base_row + page_size >= row_limit) {
2651 if (base_row <= 0) {
2654 base_row -= (page_size - 1);
2662 if (base_row + page_size >= row_limit) {
2665 base_row += page_size - 1;
2666 if (base_row + page_size >= row_limit) {
2667 base_row = row_limit - page_size - 1;
2672 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2674 color_legend(helpwin, TRUE);
2692 #endif /* USE_WIDEC_SUPPORT */
2694 #if HAVE_COLOR_CONTENT
2696 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2698 NCURSES_COLOR_T red, green, blue;
2700 color_content(current, &red, &green, &blue);
2704 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2707 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2710 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2714 if (init_color(current, red, green, blue) == ERR)
2719 reset_all_colors(void)
2723 for (c = 0; c < COLORS; ++c)
2726 all_colors[c].green,
2727 all_colors[c].blue);
2730 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2731 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2732 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2735 init_all_colors(bool xterm_colors, char *palette_file)
2738 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2740 failed("all_colors");
2741 for (cp = 0; cp < MaxColors; ++cp) {
2743 &all_colors[cp].red,
2744 &all_colors[cp].green,
2745 &all_colors[cp].blue);
2747 /* xterm and compatible terminals can read results of an OSC string
2748 * asking for the current color palette.
2753 char result[BUFSIZ];
2755 unsigned check_r, check_g, check_b;
2759 for (n = 0; n < MaxColors; ++n) {
2760 fprintf(stderr, "\033]4;%d;?\007", n);
2761 got = (int) read(0, result, sizeof(result) - 1);
2765 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2771 all_colors[n].red = DecodeRGB(check_r);
2772 all_colors[n].green = DecodeRGB(check_g);
2773 all_colors[n].blue = DecodeRGB(check_b);
2780 if (palette_file != 0) {
2781 FILE *fp = fopen(palette_file, "r");
2783 char buffer[BUFSIZ];
2784 int red, green, blue;
2787 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2788 if (sscanf(buffer, "scale:%d", &c) == 1) {
2790 } else if (sscanf(buffer, "%d:%d %d %d",
2799 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2800 all_colors[c].red = Scaled(red);
2801 all_colors[c].green = Scaled(green);
2802 all_colors[c].blue = Scaled(blue);
2810 #define scaled_rgb(n) ((255 * (n)) / 1000)
2813 color_edit(bool recur GCC_UNUSED)
2814 /* display the color test pattern, without trying to edit colors */
2818 int this_c, value, field;
2824 Cannot("does not support color.");
2826 } else if (!can_change_color()) {
2827 Cannot("has hardwired color values.");
2840 page_size = (LINES - 6);
2843 for (i = 0; i < MaxColors; i++)
2844 init_pair((NCURSES_PAIRS_T) i,
2845 (NCURSES_COLOR_T) COLOR_WHITE,
2846 (NCURSES_COLOR_T) i);
2848 MvPrintw(LINES - 2, 0, "Number: %d", value);
2851 NCURSES_COLOR_T red, green, blue;
2854 MvAddStr(0, 20, "Color RGB Value Editing");
2857 for (i = (NCURSES_COLOR_T) top_color;
2858 (i - top_color < page_size)
2859 && (i < MaxColors); i++) {
2862 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2863 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2864 (i == current ? '>' : ' '),
2865 (i < (int) SIZEOF(the_color_names)
2866 ? the_color_names[i] : numeric));
2867 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2869 (void) attrset(A_NORMAL);
2871 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2873 if (current == i && field == 0)
2875 printw("%04d", (int) red);
2876 if (current == i && field == 0)
2877 (void) attrset(A_NORMAL);
2879 if (current == i && field == 1)
2881 printw("%04d", (int) green);
2882 if (current == i && field == 1)
2883 (void) attrset(A_NORMAL);
2885 if (current == i && field == 2)
2887 printw("%04d", (int) blue);
2888 if (current == i && field == 2)
2889 (void) attrset(A_NORMAL);
2890 (void) attrset(A_NORMAL);
2891 printw(" ( %3d %3d %3d )",
2892 (int) scaled_rgb(red),
2893 (int) scaled_rgb(green),
2894 (int) scaled_rgb(blue));
2897 MvAddStr(LINES - 3, 0,
2898 "Use up/down to select a color, left/right to change fields.");
2899 MvAddStr(LINES - 2, 0,
2900 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2902 move(2 + current - top_color, 0);
2906 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2928 current -= (page_size - 1);
2935 if (current < (MaxColors - 1))
2936 current += (page_size - 1);
2943 current = (current == 0 ? (MaxColors - 1) : current - 1);
2948 current = (current == (MaxColors - 1) ? 0 : current + 1);
2953 field = (field == 2 ? 0 : field + 1);
2958 field = (field == 0 ? 2 : field - 1);
2971 value = value * 10 + (this_c - '0');
2975 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2979 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2983 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2988 P(" RGB Value Editing Help");
2990 P("You are in the RGB value editor. Use the arrow keys to select one of");
2991 P("the fields in one of the RGB triples of the current colors; the one");
2992 P("currently selected will be reverse-video highlighted.");
2994 P("To change a field, enter the digits of the new value; they are echoed");
2995 P("as entered. Finish by typing `='. The change will take effect instantly.");
2996 P("To increment or decrement a value, use the same procedure, but finish");
2997 P("with a `+' or `-'.");
2999 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3001 P("Press 'm' to invoke the top-level menu with the current color settings.");
3002 P("To quit, do ESC");
3011 for (i = 0; i < MaxColors; i++)
3012 init_pair((NCURSES_PAIRS_T) i,
3013 (NCURSES_COLOR_T) COLOR_WHITE,
3014 (NCURSES_COLOR_T) i);
3028 if (current >= MaxColors)
3029 current = MaxColors - 1;
3030 if (current < top_color)
3031 top_color = current;
3032 if (current - top_color >= page_size)
3033 top_color = current - (page_size - 1);
3035 MvPrintw(LINES - 1, 0, "Number: %d", value);
3038 (!isQuit(this_c, TRUE));
3043 * ncurses does not reset each color individually when calling endwin().
3050 #endif /* HAVE_COLOR_CONTENT */
3052 /****************************************************************************
3054 * Alternate character-set stuff
3056 ****************************************************************************/
3058 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3064 if ((*at_code += 1) >= limit)
3069 *at_code = limit - 1;
3078 *attr = list[*at_code].attr;
3082 #if USE_WIDEC_SUPPORT
3084 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3090 if ((*at_code += 1) >= limit)
3095 *at_code = limit - 1;
3104 *attr = list[*at_code].attr;
3110 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3112 bool result = FALSE;
3122 if ((*fg += 1) >= COLORS)
3130 if ((*bg += 1) >= COLORS)
3138 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3141 if (init_pair(*pair,
3142 (NCURSES_COLOR_T) *fg,
3143 (NCURSES_COLOR_T) *bg) == ERR) {
3152 /****************************************************************************
3154 * Soft-key label test
3156 ****************************************************************************/
3161 #define SLK_WORK (SLK_HELP + 3)
3166 static const char *table[] =
3168 "Available commands are:"
3170 ,"^L -- repaint this message and activate soft keys"
3171 ,"a/d -- activate/disable soft keys"
3172 ,"c -- set centered format for labels"
3173 ,"l -- set left-justified format for labels"
3174 ,"r -- set right-justified format for labels"
3175 ,"[12345678] -- set label; labels are numbered 1 through 8"
3176 ,"e -- erase stdscr (should not erase labels)"
3177 ,"s -- test scrolling of shortened screen"
3178 ,"v/V -- cycle through video attributes"
3180 ,"F/f/B/b -- cycle through foreground/background colors"
3182 ,"ESC -- return to main menu"
3184 ,"Note: if activating the soft keys causes your terminal to scroll up"
3185 ,"one line, your terminal auto-scrolls when anything is written to the"
3186 ,"last screen position. The ncurses code does not yet handle this"
3192 for (j = 0; j < SIZEOF(table); ++j) {
3200 call_slk_color(int fg, int bg)
3202 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3204 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3213 slk_test(bool recur GCC_UNUSED)
3214 /* exercise the soft keys */
3219 chtype attr = A_NORMAL;
3220 unsigned at_code = 0;
3222 int fg = COLOR_BLACK;
3223 int bg = COLOR_WHITE;
3224 NCURSES_PAIRS_T pair = 0;
3226 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3227 unsigned my_size = init_attr_list(my_list, termattrs());
3232 call_slk_color(fg, bg);
3242 MvAddStr(0, 20, "Soft Key Exerciser");
3257 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3258 while ((c = Getchar()) != 'Q' && (c != ERR))
3286 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3287 _nc_STRCPY(buf, "", sizeof(buf));
3288 if ((s = slk_label(c - '0')) != 0) {
3289 _nc_STRNCPY(buf, s, (size_t) 8);
3291 wGetstring(stdscr, buf, 8);
3292 slk_set((c - '0'), buf, fmt);
3301 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3303 wnoutrefresh(stdscr);
3308 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3315 if (cycle_colors(c, &fg, &bg, &pair)) {
3317 call_slk_color(fg, bg);
3327 } while (!isQuit(c = Getchar(), TRUE));
3336 #if USE_WIDEC_SUPPORT
3339 x_slk_test(bool recur GCC_UNUSED)
3340 /* exercise the soft keys */
3343 wchar_t buf[SLKLEN + 1];
3345 attr_t attr = WA_NORMAL;
3346 unsigned at_code = 0;
3347 int fg = COLOR_BLACK;
3348 int bg = COLOR_WHITE;
3349 NCURSES_PAIRS_T pair = 0;
3350 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3351 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3355 call_slk_color(fg, bg);
3362 attr_on(WA_BOLD, NULL);
3363 MvAddStr(0, 20, "Soft Key Exerciser");
3364 attr_off(WA_BOLD, NULL);
3378 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3379 while ((c = Getchar()) != 'Q' && (c != ERR))
3407 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3409 if ((s = slk_label(c - '0')) != 0) {
3410 char *temp = strdup(s);
3411 size_t used = strlen(temp);
3412 size_t want = SLKLEN;
3414 #ifndef state_unused
3419 while (want > 0 && used != 0) {
3420 const char *base = s;
3421 reset_mbytes(state);
3422 test = count_mbytes(base, 0, &state);
3423 if (test == (size_t) -1) {
3425 } else if (test > want) {
3428 reset_mbytes(state);
3429 trans_mbytes(buf, base, want, &state);
3435 wGet_wstring(stdscr, buf, SLKLEN);
3436 slk_wset((c - '0'), buf, fmt);
3447 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3448 call_slk_color(fg, bg);
3453 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3454 call_slk_color(fg, bg);
3457 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3459 wnoutrefresh(stdscr);
3463 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3464 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3470 if (cycle_colors(c, &fg, &bg, &pair)) {
3472 call_slk_color(fg, bg);
3482 } while (!isQuit(c = Getchar(), TRUE));
3491 #endif /* SLK_INIT */
3494 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3497 unsigned last = 255;
3503 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3508 for (code = first; code <= last; ++code) {
3509 int row = (int) (2 + (code / 16));
3510 int col = (int) (5 * (code % 16));
3511 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3512 for (count = 1; count < repeat; ++count) {
3513 AddCh(colored_chtype(code, attr, pair));
3520 * Show a slice of 32 characters, allowing those to be repeated up to the
3523 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3524 * terminal to perform functions. The remaining codes can be graphic.
3527 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3530 unsigned first = (unsigned) base;
3531 unsigned last = first + (unsigned) pagesize - 2;
3532 bool C1 = (first == 128);
3537 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3538 C1 ? "C1" : "GR", first, last);
3542 for (code = first; code <= last; code++) {
3544 int row = 2 + ((int) (code - first) % (pagesize / 2));
3545 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3547 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3548 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3552 nodelay(stdscr, TRUE);
3553 echochar(colored_chtype(code, attr, pair));
3555 /* (yes, this _is_ crude) */
3556 while ((reply = Getchar()) != ERR) {
3557 AddCh(UChar(reply));
3560 nodelay(stdscr, FALSE);
3562 } while (--count > 0);
3569 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3575 MvPrintw(0, 20, "Display of PC Character Codes");
3579 for (code = 0; code < 16; ++code) {
3580 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3582 for (code = 0; code < 256; code++) {
3584 int row = 3 + (int) (code / 16) + (code >= 128);
3585 int col = 8 + (int) (code % 16) * PC_COLS;
3586 if ((code % 16) == 0)
3587 MvPrintw(row, 0, "0x%02x:", code);
3598 * Skip the ones that do not work.
3602 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3605 } while (--count > 0);
3610 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3614 attr |= (attr_t) COLOR_PAIR(pair);
3618 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3623 colored_chtype(ACS_VLINE, attr, pair),
3624 colored_chtype(ACS_VLINE, attr, pair),
3625 colored_chtype(ACS_HLINE, attr, pair),
3626 colored_chtype(ACS_HLINE, attr, pair),
3627 colored_chtype(ACS_ULCORNER, attr, pair),
3628 colored_chtype(ACS_URCORNER, attr, pair),
3629 colored_chtype(ACS_LLCORNER, attr, pair),
3630 colored_chtype(ACS_LRCORNER, attr, pair));
3631 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3632 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3633 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3634 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3635 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3636 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3637 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3643 show_1_acs(int n, int repeat, const char *name, chtype code)
3645 const int height = 16;
3646 int row = 2 + (n % height);
3647 int col = (n / height) * COLS / 2;
3649 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3652 } while (--repeat > 0);
3657 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3658 /* display the ACS character set */
3662 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3666 MvAddStr(0, 20, "Display of the ACS Character Set");
3670 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3671 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3672 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3673 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3675 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3676 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3677 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3678 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3680 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3681 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3684 * HPUX's ACS definitions are broken here. Just give up.
3686 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3687 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3688 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3689 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3690 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3692 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3693 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3694 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3695 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3696 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3697 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3698 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3699 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3700 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3702 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3703 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3704 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3706 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3707 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3708 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3709 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3710 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3711 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3717 acs_test(bool recur GCC_UNUSED)
3721 char *term = getenv("TERM");
3722 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3725 chtype attr = A_NORMAL;
3728 int fg = COLOR_BLACK;
3729 int bg = COLOR_BLACK;
3730 unsigned at_code = 0;
3731 NCURSES_PAIRS_T pair = 0;
3732 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3733 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3734 unsigned my_size = init_attr_list(my_list, termattrs());
3742 ToggleAcs(last_show_acs, show_acs_chars);
3746 ToggleAcs(last_show_acs, show_pc_chars);
3751 if (pagesize == 32) {
3758 ToggleAcs(last_show_acs, show_box_chars);
3784 if (repeat < (COLS / 4))
3792 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3793 || cycle_colors(c, &fg, &bg, &pair)) {
3800 if (pagesize != 32) {
3801 show_256_chars(repeat, attr, pair);
3802 } else if (last_show_acs != 0) {
3803 last_show_acs(repeat, attr, pair);
3805 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3808 MvPrintw(LINES - 3, 0,
3809 "Note: ANSI terminals may not display C1 characters.");
3810 MvPrintw(LINES - 2, 0,
3811 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3814 MvPrintw(LINES - 1, 0,
3815 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3816 my_list[at_code].name,
3819 MvPrintw(LINES - 1, 0,
3820 "v/V cycles through video attributes (%s).",
3821 my_list[at_code].name);
3824 } while (!isQuit(c = Getchar(), TRUE));
3832 #if USE_WIDEC_SUPPORT
3834 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3840 TEST_CCHAR(src, count, {
3841 attr |= (test_attrs & A_ALTCHARSET);
3842 setcchar(dst, test_wch, attr, pair, NULL);
3852 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3853 * display. If there are no repeats, we could normally display 16 lines of 64
3854 * characters (1024 total). However, taking repeats and double-width cells
3855 * into account, use 256 characters for the page.
3858 show_paged_widechars(int base,
3863 NCURSES_PAIRS_T pair)
3865 int first = base * pagesize;
3866 int last = first + pagesize - 1;
3874 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3877 for (code = (wchar_t) first; (int) code <= last; code++) {
3878 int row = (2 + ((int) code - first) / per_line);
3879 int col = 5 * ((int) code % per_line);
3882 memset(&codes, 0, sizeof(codes));
3884 setcchar(&temp, codes, attr, pair, 0);
3886 if (wcwidth(code) == 0 && code != 0) {
3887 AddCh((chtype) space |
3888 (A_REVERSE ^ attr) |
3889 (attr_t) COLOR_PAIR(pair));
3892 for (count = 1; count < repeat; ++count) {
3899 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3903 int last = first + 31;
3907 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3910 for (code = (wchar_t) first; (int) code <= last; code++) {
3911 int row = 2 + ((code - first) % 16);
3912 int col = ((code - first) / 16) * COLS / 2;
3918 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
3919 "%3ld (0x%lx)", (long) code, (long) code);
3920 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3922 memset(&codes, 0, sizeof(codes));
3924 setcchar(&temp, codes, attr, pair, 0);
3928 * Give non-spacing characters something to combine with. If we
3929 * don't, they'll bunch up in a heap on the space after the ":".
3930 * Mark them with reverse-video to make them simpler to find on
3933 if (wcwidth(code) == 0) {
3934 AddCh((chtype) space |
3935 (A_REVERSE ^ attr) |
3936 (attr_t) COLOR_PAIR(pair));
3939 * This uses echo_wchar(), for comparison with the normal 'f'
3940 * test (and to make a test-case for echo_wchar()). The screen
3941 * may flicker because the erase() at the top of the function
3942 * is met by the builtin refresh() in echo_wchar().
3946 * The repeat-count may make text wrap - avoid that.
3948 getyx(stdscr, y, x);
3950 if (x >= col + (COLS / 2) - 2)
3952 } while (--count > 0);
3957 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3959 const int height = 16;
3960 int row = 2 + (n % height);
3961 int col = (n / height) * COLS / 2;
3963 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3964 while (--repeat >= 0) {
3970 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3973 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3974 /* display the wide-ACS character set */
3980 /*#define BOTH2(name) #name, &(name) */
3981 #define BOTH2(name) #name, MERGE_ATTR(name)
3985 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3989 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3990 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3991 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3992 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3994 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3995 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3996 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3997 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3999 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4000 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4002 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4003 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4004 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4005 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4007 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4008 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4009 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4010 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4011 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4012 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4013 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4014 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4015 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4017 #ifdef CURSES_WACS_ARRAY
4018 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4019 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4020 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4022 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4023 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4024 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4025 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4026 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4027 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4033 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4034 /* display the wide-ACS character set */
4040 /*#define BOTH2(name) #name, &(name) */
4041 #define BOTH2(name) #name, MERGE_ATTR(name)
4045 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4049 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4050 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4051 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4052 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4054 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4055 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4056 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4057 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4059 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4060 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4062 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4063 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4064 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4065 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4067 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4068 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4069 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4070 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4071 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4072 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4073 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4074 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4075 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4077 #ifdef CURSES_WACS_ARRAY
4078 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4079 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4080 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4082 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4083 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4084 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4085 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4086 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4087 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4094 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4095 /* display the wide-ACS character set */
4101 /*#define BOTH2(name) #name, &(name) */
4102 #define BOTH2(name) #name, MERGE_ATTR(name)
4106 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4110 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4111 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4115 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4117 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4118 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4120 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4121 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4123 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4124 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4125 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4126 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4128 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4129 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4130 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4131 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4132 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4133 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4134 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4135 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4136 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4138 #ifdef CURSES_WACS_ARRAY
4139 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4140 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4141 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4143 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4144 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4145 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4146 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4147 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4148 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4155 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4158 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4165 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4170 MERGE_ATTR(0, WACS_VLINE),
4171 MERGE_ATTR(1, WACS_VLINE),
4172 MERGE_ATTR(2, WACS_HLINE),
4173 MERGE_ATTR(3, WACS_HLINE),
4174 MERGE_ATTR(4, WACS_ULCORNER),
4175 MERGE_ATTR(5, WACS_URCORNER),
4176 MERGE_ATTR(6, WACS_LLCORNER),
4177 MERGE_ATTR(7, WACS_LRCORNER));
4179 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4180 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4181 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4182 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4183 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4184 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4185 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4193 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4195 const int height = 16;
4196 int row = 2 + (n % height);
4197 int col = (n / height) * COLS / 2;
4200 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4201 (void) attr_set(attr, pair, 0);
4202 _nc_STRNCPY(temp, code, 20);
4204 (void) attr_set(A_NORMAL, 0, 0);
4208 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4211 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4218 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4222 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4223 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4224 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4225 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4227 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4228 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4229 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4230 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4232 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4233 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4235 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4236 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4237 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4238 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4240 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4241 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4242 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4243 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4244 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4245 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4246 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4247 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4248 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4249 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4250 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4251 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4253 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4254 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4255 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4256 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4257 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4258 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4263 /* display the wide-ACS character set */
4265 x_acs_test(bool recur GCC_UNUSED)
4272 attr_t attr = WA_NORMAL;
4273 int fg = COLOR_BLACK;
4274 int bg = COLOR_BLACK;
4275 unsigned at_code = 0;
4276 NCURSES_PAIRS_T pair = 0;
4277 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4278 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4279 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4287 ToggleAcs(last_show_wacs, show_wacs_chars);
4291 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4296 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4300 if (pagesize == 32) {
4307 ToggleAcs(last_show_wacs, show_wbox_chars);
4310 ToggleAcs(last_show_wacs, show_utf8_chars);
4313 if (c < 256 && isdigit(c)) {
4316 } else if (c == '+') {
4319 } else if (c == '-' && digit > 0) {
4322 } else if (c == '>' && repeat < (COLS / 4)) {
4324 } else if (c == '<' && repeat > 1) {
4326 } else if (c == '_') {
4327 space = (space == ' ') ? '_' : ' ';
4329 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4330 || cycle_colors(c, &fg, &bg, &pair)) {
4331 if (last_show_wacs != 0)
4339 if (pagesize != 32) {
4340 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4341 } else if (last_show_wacs != 0) {
4342 last_show_wacs(repeat, attr, pair);
4344 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4347 MvPrintw(LINES - 4, 0,
4348 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
4349 MvPrintw(LINES - 3, 2,
4350 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4352 MvPrintw(LINES - 2, 2,
4353 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4354 my_list[at_code].name,
4357 MvPrintw(LINES - 2, 2,
4358 "v/V cycles through video attributes (%s).",
4359 my_list[at_code].name);
4362 } while (!isQuit(c = Getchar(), TRUE));
4373 * Graphic-rendition test (adapted from vttest)
4376 sgr_attr_test(bool recur GCC_UNUSED)
4380 for (pass = 0; pass < 2; pass++) {
4381 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4383 /* Use non-default colors if possible to exercise bce a little */
4385 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4386 normal |= (chtype) COLOR_PAIR(1);
4390 MvPrintw(1, 20, "Graphic rendition test pattern:");
4392 MvPrintw(4, 1, "vanilla");
4394 #define set_sgr(mask) bkgdset((normal^(mask)));
4396 MvPrintw(4, 40, "bold");
4398 set_sgr(A_UNDERLINE);
4399 MvPrintw(6, 6, "underline");
4401 set_sgr(A_BOLD | A_UNDERLINE);
4402 MvPrintw(6, 45, "bold underline");
4405 MvPrintw(8, 1, "blink");
4407 set_sgr(A_BLINK | A_BOLD);
4408 MvPrintw(8, 40, "bold blink");
4410 set_sgr(A_UNDERLINE | A_BLINK);
4411 MvPrintw(10, 6, "underline blink");
4413 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4414 MvPrintw(10, 45, "bold underline blink");
4417 MvPrintw(12, 1, "negative");
4419 set_sgr(A_BOLD | A_REVERSE);
4420 MvPrintw(12, 40, "bold negative");
4422 set_sgr(A_UNDERLINE | A_REVERSE);
4423 MvPrintw(14, 6, "underline negative");
4425 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4426 MvPrintw(14, 45, "bold underline negative");
4428 set_sgr(A_BLINK | A_REVERSE);
4429 MvPrintw(16, 1, "blink negative");
4431 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4432 MvPrintw(16, 40, "bold blink negative");
4434 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4435 MvPrintw(18, 6, "underline blink negative");
4437 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4438 MvPrintw(18, 45, "bold underline blink negative");
4441 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4447 bkgdset(A_NORMAL | BLANK);
4453 /****************************************************************************
4455 * Windows and scrolling tester.
4457 ****************************************************************************/
4459 #define BOTLINES 4 /* number of line stolen from screen bottom */
4465 #define FRAME struct frame
4474 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4475 #if (NCURSES_VERSION_PATCH < 20070331)
4476 #define is_keypad(win) (win)->_use_keypad
4477 #define is_scrollok(win) (win)->_scroll
4480 #define is_keypad(win) FALSE
4481 #define is_scrollok(win) FALSE
4485 frame_win(FRAME * curp)
4487 return (curp != 0) ? curp->wind : stdscr;
4490 /* We need to know if these flags are actually set, so don't look in FRAME.
4491 * These names are known to work with SVr4 curses as well as ncurses. The
4492 * _use_keypad name does not work with Solaris 8.
4495 HaveKeypad(FRAME * curp)
4497 WINDOW *win = frame_win(curp);
4499 return is_keypad(win);
4503 HaveScroll(FRAME * curp)
4505 WINDOW *win = frame_win(curp);
4507 return is_scrollok(win);
4511 newwin_legend(FRAME * curp)
4513 #define DATA(num, name) { name, num }
4514 static const struct {
4518 DATA(0, "^C = create window"),
4519 DATA(0, "^N = next window"),
4520 DATA(0, "^P = previous window"),
4521 DATA(0, "^F = scroll forward"),
4522 DATA(0, "^B = scroll backward"),
4523 DATA(1, "^K = keypad(%s)"),
4524 DATA(2, "^S = scrollok(%s)"),
4525 DATA(0, "^W = save window"),
4526 DATA(0, "^R = restore window"),
4528 DATA(0, "^X = resize"),
4530 DATA(3, "^Q%s = exit")
4535 bool do_keypad = HaveKeypad(curp);
4536 bool do_scroll = HaveScroll(curp);
4540 for (n = 0; n < SIZEOF(legend); n++) {
4541 switch (legend[n].code) {
4543 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4546 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4547 legend[n].msg, do_keypad ? "yes" : "no");
4550 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4551 legend[n].msg, do_scroll ? "yes" : "no");
4554 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4555 legend[n].msg, do_keypad ? "/ESC" : "");
4558 x = getcurx(stdscr);
4559 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4566 transient(FRAME * curp, NCURSES_CONST char *msg)
4568 newwin_legend(curp);
4570 MvAddStr(LINES - 1, 0, msg);
4576 printw("%s characters are echoed, window should %sscroll.",
4577 HaveKeypad(curp) ? "Non-arrow" : "All other",
4578 HaveScroll(curp) ? "" : "not ");
4583 newwin_report(FRAME * curp)
4584 /* report on the cursor's current position, then restore it */
4586 WINDOW *win = frame_win(curp);
4590 transient(curp, (char *) 0);
4592 move(LINES - 1, COLS - 17);
4593 printw("Y = %2d X = %2d", y, x);
4601 selectcell(int uli, int ulj, int lri, int lrj)
4602 /* arrows keys move cursor, return location at current on non-arrow key */
4604 static pair res; /* result cell */
4605 int si = lri - uli + 1; /* depth of the select area */
4606 int sj = lrj - ulj + 1; /* width of the select area */
4607 int i = 0, j = 0; /* offsets into the select area */
4612 move(uli + i, ulj + j);
4613 newwin_report((FRAME *) 0);
4615 switch (Getchar()) {
4629 return ((pair *) 0);
4630 #ifdef NCURSES_MOUSE_VERSION
4636 if (event.y > uli && event.x > ulj) {
4657 outerbox(pair ul, pair lr, bool onoff)
4658 /* draw or erase a box *outside* the given pair of corners */
4660 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4661 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4662 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4663 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4664 move(ul.y - 1, ul.x);
4665 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4666 move(ul.y, ul.x - 1);
4667 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4668 move(lr.y + 1, ul.x);
4669 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4670 move(ul.y, lr.x + 1);
4671 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4676 /* Ask user for a window definition */
4683 addstr("Use arrows to move cursor, anything else to mark corner 1");
4685 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4686 return ((WINDOW *) 0);
4687 memcpy(&ul, tmp, sizeof(pair));
4688 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4691 addstr("Use arrows to move cursor, anything else to mark corner 2");
4693 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4695 return ((WINDOW *) 0);
4696 memcpy(&lr, tmp, sizeof(pair));
4698 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4700 outerbox(ul, lr, TRUE);
4712 newwin_move(FRAME * curp, int dy, int dx)
4714 WINDOW *win = frame_win(curp);
4718 getyx(win, cur_y, cur_x);
4719 getmaxyx(win, max_y, max_x);
4720 if ((cur_x += dx) < 0)
4722 else if (cur_x >= max_x)
4724 if ((cur_y += dy) < 0)
4726 else if (cur_y >= max_y)
4728 wmove(win, cur_y, cur_x);
4732 delete_framed(FRAME * fp, bool showit)
4737 fp->last->next = fp->next;
4738 fp->next->last = fp->last;
4746 np = (fp == fp->next) ? NULL : fp->next;
4753 scroll_test(bool recur GCC_UNUSED)
4754 /* Demonstrate windows */
4757 FRAME *current = (FRAME *) 0, *neww;
4759 #if HAVE_PUTWIN && HAVE_GETWIN
4763 #define DUMPFILE "screendump"
4765 #ifdef NCURSES_MOUSE_VERSION
4766 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4771 transient((FRAME *) 0, (char *) 0);
4774 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4775 failed("scroll_test");
4778 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4779 failed("scroll_test");
4784 if (current == 0) { /* First element, */
4785 neww->next = neww; /* so point it at itself */
4788 neww->next = current->next;
4789 neww->last = current;
4790 neww->last->next = neww;
4791 neww->next->last = neww;
4794 /* SVr4 curses sets the keypad on all newly-created windows to
4795 * false. Someone reported that PDCurses makes new windows inherit
4796 * this flag. Remove the following 'keypad()' call to test this
4798 keypad(current->wind, TRUE);
4799 current->do_keypad = HaveKeypad(current);
4800 current->do_scroll = HaveScroll(current);
4803 case CTRL('N'): /* go to next window */
4805 current = current->next;
4808 case CTRL('P'): /* go to previous window */
4810 current = current->last;
4813 case CTRL('F'): /* scroll current window forward */
4815 wscrl(frame_win(current), 1);
4818 case CTRL('B'): /* scroll current window backwards */
4820 wscrl(frame_win(current), -1);
4823 case CTRL('K'): /* toggle keypad mode for current */
4825 current->do_keypad = !current->do_keypad;
4826 keypad(current->wind, current->do_keypad);
4832 current->do_scroll = !current->do_scroll;
4833 scrollok(current->wind, current->do_scroll);
4837 #if HAVE_PUTWIN && HAVE_GETWIN
4838 case CTRL('W'): /* save and delete window */
4839 if ((current != 0) && (current == current->next)) {
4840 transient(current, "Will not save/delete ONLY window");
4842 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4843 transient(current, "Can't open screen dump file");
4845 int rc = putwin(frame_win(current), fp);
4849 current = delete_framed(current, TRUE);
4851 transient(current, "Can't write screen dump file");
4856 case CTRL('R'): /* restore window */
4857 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4858 transient(current, "Can't open screen dump file");
4860 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4862 neww->next = current ? current->next : 0;
4863 neww->last = current;
4864 if (neww->last != 0)
4865 neww->last->next = neww;
4866 if (neww->next != 0)
4867 neww->next->last = neww;
4869 neww->wind = getwin(fp);
4871 wrefresh(neww->wind);
4873 failed("scroll_test");
4881 case CTRL('X'): /* resize window */
4888 addstr("Use arrows to move cursor, anything else to mark new corner");
4891 getbegyx(current->wind, ul.y, ul.x);
4893 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4894 if (tmp == (pair *) 0) {
4899 getmaxyx(current->wind, lr.y, lr.x);
4902 outerbox(ul, lr, FALSE);
4903 wnoutrefresh(stdscr);
4905 /* strictly cosmetic hack for the test */
4906 getmaxyx(current->wind, my, mx);
4907 if (my > tmp->y - ul.y) {
4908 getyx(current->wind, lr.y, lr.x);
4909 wmove(current->wind, tmp->y - ul.y + 1, 0);
4910 wclrtobot(current->wind);
4911 wmove(current->wind, lr.y, lr.x);
4913 if (mx > tmp->x - ul.x)
4914 for (i = 0; i < my; i++) {
4915 wmove(current->wind, i, tmp->x - ul.x + 1);
4916 wclrtoeol(current->wind);
4918 wnoutrefresh(current->wind);
4920 memcpy(&lr, tmp, sizeof(pair));
4921 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4923 getbegyx(current->wind, ul.y, ul.x);
4924 getmaxyx(current->wind, lr.y, lr.x);
4927 outerbox(ul, lr, TRUE);
4928 wnoutrefresh(stdscr);
4930 wnoutrefresh(current->wind);
4936 #endif /* HAVE_WRESIZE */
4939 newwin_move(current, -1, 0);
4942 newwin_move(current, 1, 0);
4945 newwin_move(current, 0, -1);
4948 newwin_move(current, 0, 1);
4956 getyx(frame_win(current), y, x);
4960 x = getmaxx(frame_win(current)) - 1;
4962 (void) mvwdelch(frame_win(current), y, x);
4972 waddch(current->wind, (chtype) c);
4977 newwin_report(current);
4978 usescr = frame_win(current);
4981 (!isQuit(c = wGetchar(usescr), TRUE)
4985 while (current != 0)
4986 current = delete_framed(current, FALSE);
4988 scrollok(stdscr, TRUE); /* reset to driver's default */
4989 #ifdef NCURSES_MOUSE_VERSION
4990 mousemask(0, (mmask_t *) 0);
4998 /****************************************************************************
5002 ****************************************************************************/
5005 static int nap_msec = 1;
5007 static NCURSES_CONST char *mod[] =
5017 /*+-------------------------------------------------------------------------
5019 --------------------------------------------------------------------------*/
5021 wait_a_while(int msec GCC_UNUSED)
5031 else if (msec > 1000)
5032 sleep((unsigned) msec / 1000);
5036 } /* end of wait_a_while */
5038 /*+-------------------------------------------------------------------------
5040 --------------------------------------------------------------------------*/
5042 saywhat(NCURSES_CONST char *text)
5044 wmove(stdscr, LINES - 1, 0);
5046 if (text != 0 && *text != '\0') {
5047 waddstr(stdscr, text);
5048 waddstr(stdscr, "; ");
5050 waddstr(stdscr, "press any key to continue");
5051 } /* end of saywhat */
5053 /*+-------------------------------------------------------------------------
5054 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
5055 --------------------------------------------------------------------------*/
5057 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
5062 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
5063 if ((pan = new_panel(win)) == 0) {
5065 } else if (UseColors) {
5066 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
5069 NCURSES_COLOR_T bg = color;
5071 init_pair(color, fg, bg);
5072 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
5074 wbkgdset(win, A_BOLD | ' ');
5078 } /* end of mkpanel */
5080 /*+-------------------------------------------------------------------------
5082 --------------------------------------------------------------------------*/
5086 WINDOW *win = panel_window(pan);
5089 } /* end of rmpanel */
5091 /*+-------------------------------------------------------------------------
5093 --------------------------------------------------------------------------*/
5099 } /* end of pflush */
5101 /*+-------------------------------------------------------------------------
5103 --------------------------------------------------------------------------*/
5105 init_panel(WINDOW *win)
5109 for (y = 0; y < LINES - 1; y++) {
5110 for (x = 0; x < COLS; x++)
5111 wprintw(win, "%d", (y + x) % 10);
5116 fill_panel(PANEL *pan)
5118 WINDOW *win = panel_window(pan);
5119 const char *userptr = (const char *) panel_userptr(pan);
5120 int num = (userptr && *userptr) ? userptr[1] : '?';
5124 wprintw(win, "-pan%c-", num);
5127 for (y = 2; y < getmaxy(win) - 1; y++) {
5128 for (x = 1; x < getmaxx(win) - 1; x++) {
5130 waddch(win, UChar(num));
5135 #if USE_WIDEC_SUPPORT
5137 init_wide_panel(WINDOW *win)
5142 for (digit = 0; digit < 10; ++digit)
5143 make_fullwidth_digit(&temp[digit], digit);
5147 getyx(stdscr, y, x);
5148 digit = (y + x / 2) % 10;
5149 } while (wadd_wch(win, &temp[digit]) != ERR);
5153 fill_wide_panel(PANEL *pan)
5155 WINDOW *win = panel_window(pan);
5156 const char *userptr = (const char *) panel_userptr(pan);
5157 int num = (userptr && *userptr) ? userptr[1] : '?';
5161 wprintw(win, "-pan%c-", num);
5164 for (y = 2; y < getmaxy(win) - 1; y++) {
5165 for (x = 1; x < getmaxx(win) - 1; x++) {
5167 waddch(win, UChar(num));
5173 #define MAX_PANELS 5
5176 canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
5178 int which = cmd[1] - '0';
5183 hide_panel(px[which]);
5186 show_panel(px[which]);
5189 top_panel(px[which]);
5192 bottom_panel(px[which]);
5199 wait_a_while(nap_msec);
5203 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
5207 PANEL *px[MAX_PANELS + 1];
5209 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5213 for (count = 0; count < 5; count++) {
5214 px[1] = mkpanel(COLOR_RED,
5219 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
5221 px[2] = mkpanel(COLOR_GREEN,
5226 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5228 px[3] = mkpanel(COLOR_YELLOW,
5233 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5235 px[4] = mkpanel(COLOR_BLUE,
5240 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5242 px[5] = mkpanel(COLOR_MAGENTA,
5247 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5259 wait_a_while(nap_msec);
5261 saywhat("h3 s1 s2 s4 s5");
5262 move_panel(px[1], 0, 0);
5269 wait_a_while(nap_msec);
5271 canned_panel(px, "s1");
5272 canned_panel(px, "s2");
5275 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5277 wait_a_while(nap_msec);
5279 canned_panel(px, "s3");
5282 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5284 wait_a_while(nap_msec);
5286 canned_panel(px, "b3");
5287 canned_panel(px, "s4");
5288 canned_panel(px, "s5");
5289 canned_panel(px, "t3");
5290 canned_panel(px, "t1");
5291 canned_panel(px, "t2");
5292 canned_panel(px, "t3");
5293 canned_panel(px, "t4");
5295 for (itmp = 0; itmp < 6; itmp++) {
5296 WINDOW *w4 = panel_window(px[4]);
5297 WINDOW *w5 = panel_window(px[5]);
5300 wmove(w4, LINES / 8, 1);
5301 waddstr(w4, mod[itmp]);
5302 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5303 wmove(w5, LINES / 6, 1);
5304 waddstr(w5, mod[itmp]);
5306 wait_a_while(nap_msec);
5309 wmove(w4, LINES / 6, 1);
5310 waddstr(w4, mod[itmp]);
5311 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5312 wmove(w5, LINES / 8, 1);
5313 waddstr(w5, mod[itmp]);
5315 wait_a_while(nap_msec);
5319 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5321 wait_a_while(nap_msec);
5323 canned_panel(px, "t5");
5324 canned_panel(px, "t2");
5325 canned_panel(px, "t1");
5326 canned_panel(px, "d2");
5327 canned_panel(px, "h3");
5328 canned_panel(px, "d1");
5329 canned_panel(px, "d4");
5330 canned_panel(px, "d5");
5331 canned_panel(px, "d3");
5333 wait_a_while(nap_msec);
5346 panel_test(bool recur GCC_UNUSED)
5348 return demo_panels(init_panel, fill_panel);
5352 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
5354 x_panel_test(bool recur GCC_UNUSED)
5356 return demo_panels(init_wide_panel, fill_wide_panel);
5359 #endif /* USE_LIBPANEL */
5361 /****************************************************************************
5365 ****************************************************************************/
5369 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
5370 * though we can rely on negative x/y values to stop the macro.
5373 do_h_line(int y, int x, chtype c, int to)
5376 MvHLine(y, x, c, (to) - (x));
5380 do_v_line(int y, int x, chtype c, int to)
5383 MvVLine(y, x, c, (to) - (y));
5388 static bool pending_pan = FALSE;
5389 static bool show_panner_legend = TRUE;
5392 panner_legend(int line)
5394 static const char *const legend[] =
5396 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5397 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5398 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5399 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5401 int n = ((int) SIZEOF(legend) - (LINES - line));
5403 if (move(line, 0) != ERR) {
5404 if (show_panner_legend)
5405 printw("%s", legend[n]);
5407 return show_panner_legend;
5414 panner_h_cleanup(int from_y, int from_x, int to_x)
5416 if (!panner_legend(from_y))
5417 do_h_line(from_y, from_x, ' ', to_x);
5421 panner_v_cleanup(int from_y, int from_x, int to_y)
5423 if (!panner_legend(from_y))
5424 do_v_line(from_y, from_x, ' ', to_y);
5428 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5431 unsigned gridcount = 0;
5435 fill = (chtype) COLOR_PAIR(1);
5438 wmove(panpad, 0, 0);
5439 for (y = 0; y < getmaxy(panpad); y++) {
5440 for (x = 0; x < getmaxx(panpad); x++) {
5441 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5442 if (y == 0 && x == 0)
5443 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5445 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5446 else if (y == 0 || x == 0)
5447 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5449 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5450 (int) (gridcount++ % 26)) | fill);
5451 } else if (y % GRIDSIZE == 0)
5452 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5453 else if (x % GRIDSIZE == 0)
5454 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5456 waddch(panpad, ' ');
5463 int top_x, int top_y, int porty, int portx,
5464 int (*pgetc) (WINDOW *),
5467 #if HAVE_GETTIMEOFDAY
5468 struct timeval before, after;
5471 bool pan_lines = FALSE;
5472 bool scrollers = TRUE;
5475 int pxmax, pymax, lowend, highend, c;
5477 getmaxyx(pad, pymax, pxmax);
5478 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5482 #ifdef NCURSES_VERSION
5484 * During shell-out, the user may have resized the window. Adjust
5485 * the port size of the pad to accommodate this. Ncurses automatically
5486 * resizes all of the normal windows to fit on the new screen.
5503 if (c == HELP_KEY_1)
5504 show_panner_legend = !show_panner_legend;
5505 panner_legend(LINES - 4);
5506 panner_legend(LINES - 3);
5507 panner_legend(LINES - 2);
5508 panner_legend(LINES - 1);
5511 pan_lines = !pan_lines;
5512 fill_pad(pad, pan_lines, colored);
5513 pending_pan = FALSE;
5516 #if HAVE_GETTIMEOFDAY
5520 panner_legend(LINES - 1);
5524 scrollers = !scrollers;
5527 /* Move the top-left corner of the pad, keeping the bottom-right
5530 case 'h': /* increase-columns: move left edge to left */
5534 panner_v_cleanup(top_y, top_x, porty);
5539 case 'j': /* decrease-lines: move top-edge down */
5543 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5548 case 'k': /* increase-lines: move top-edge up */
5553 panner_h_cleanup(top_y, top_x, portx);
5557 case 'l': /* decrease-columns: move left-edge to right */
5561 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5566 /* Move the bottom-right corner of the pad, keeping the top-left
5569 case KEY_IC: /* increase-columns: move right-edge to right */
5570 if (portx >= pxmax || portx >= COLS)
5573 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5578 case KEY_IL: /* increase-lines: move bottom-edge down */
5579 if (porty >= pymax || porty >= LINES)
5582 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5587 case KEY_DC: /* decrease-columns: move bottom edge up */
5592 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5596 case KEY_DL: /* decrease-lines */
5601 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5605 case KEY_LEFT: /* pan leftwards */
5612 case KEY_RIGHT: /* pan rightwards */
5613 if (basex + portx - (pymax > porty) < pxmax)
5619 case KEY_UP: /* pan upwards */
5626 case KEY_DOWN: /* pan downwards */
5627 if (basey + porty - (pxmax > portx) < pymax)
5642 basey = pymax - porty;
5652 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5653 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5654 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5656 if (scrollers && (pxmax > portx - 1)) {
5657 int length = (portx - top_x - 1);
5658 float ratio = ((float) length) / ((float) pxmax);
5660 lowend = (int) ((float) top_x + ((float) basex * ratio));
5661 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5663 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5664 if (highend < portx) {
5666 do_h_line(porty - 1, lowend, ' ', highend + 1);
5668 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5671 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5673 if (scrollers && (pymax > porty - 1)) {
5674 int length = (porty - top_y - 1);
5675 float ratio = ((float) length) / ((float) pymax);
5677 lowend = (int) ((float) top_y + ((float) basey * ratio));
5678 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5680 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5681 if (highend < porty) {
5683 do_v_line(lowend, portx - 1, ' ', highend + 1);
5685 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5688 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5690 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5691 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5692 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5695 #if HAVE_GETTIMEOFDAY
5696 gettimeofday(&before, 0);
5698 wnoutrefresh(stdscr);
5703 porty - (pxmax > portx) - 1,
5704 portx - (pymax > porty) - 1);
5707 #if HAVE_GETTIMEOFDAY
5708 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5711 gettimeofday(&after, 0);
5712 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5713 move(LINES - 1, COLS - 12);
5714 printw("Secs: %2.03f", elapsed);
5721 ((c = pgetc(pad)) != KEY_EXIT);
5723 scrollok(stdscr, TRUE); /* reset to driver's default */
5727 padgetch(WINDOW *win)
5733 if ((pending_pan = (count > 0)) != FALSE) {
5735 pending_pan = (count != 0);
5738 switch (c = wGetchar(win)) {
5774 case ERR: /* FALLTHRU */
5780 if (c >= '0' && c <= '9') {
5781 count = count * 10 + (c - '0');
5795 #define PAD_HIGH 200
5796 #define PAD_WIDE 200
5799 pad_test(bool recur GCC_UNUSED)
5800 /* Demonstrate pads. */
5802 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5805 Cannot("cannot create requested pad");
5810 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5811 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5812 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5815 fill_pad(panpad, FALSE, TRUE);
5817 panner_legend(LINES - 4);
5818 panner_legend(LINES - 3);
5819 panner_legend(LINES - 2);
5820 panner_legend(LINES - 1);
5822 keypad(panpad, TRUE);
5824 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5825 * We'll still be able to widen it during a test, since that's required
5826 * for testing boundaries.
5828 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, TRUE);
5835 #endif /* HAVE_NEWPAD */
5837 /****************************************************************************
5839 * Tests from John Burnell's PDCurses tester
5841 ****************************************************************************/
5844 Continue(WINDOW *win)
5848 MvWAddStr(win, 10, 1, " Press any key to continue");
5854 flushinp_test(bool recur GCC_UNUSED)
5855 /* Input test, adapted from John Burnell's PDCurses tester */
5857 WINDOW *win = stdscr;
5858 int w, h, bx, by, sw, sh, i;
5863 getmaxyx(win, h, w);
5864 getbegyx(win, by, bx);
5867 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5872 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5873 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
5876 (void) wattrset(subWin, A_BOLD);
5877 box(subWin, ACS_VLINE, ACS_HLINE);
5878 MvWAddStr(subWin, 2, 1, "This is a subwindow");
5882 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5883 * it only happened to "work" on SVr4 because that implementation does not
5884 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5885 * test behavior, we're using 'cbreak()', which will allow a single
5886 * character to return without needing a newline. - T.Dickey 1997/10/11.
5889 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
5891 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
5892 MvWAddStr(win, 3, 1,
5893 "These should be discarded (not echoed) after the subwindow goes away.");
5896 for (i = 0; i < 5; i++) {
5897 MvWPrintw(subWin, 1, 1, "Time = %d", i);
5909 MvWAddStr(win, 2, 1,
5910 "If you were still typing when the window timer expired,");
5911 MvWAddStr(win, 3, 1,
5912 "or else you typed nothing at all while it was running,");
5913 MvWAddStr(win, 4, 1,
5914 "test was invalid. You'll see garbage or nothing at all. ");
5915 MvWAddStr(win, 6, 1, "Press a key");
5921 MvWAddStr(win, 12, 0,
5922 "If you see any key other than what you typed, flushinp() is broken.");
5931 "What you typed should now have been deleted; if not, wdelch() failed.");
5938 /****************************************************************************
5942 ****************************************************************************/
5950 menu_virtualize(int c)
5952 if (c == '\n' || c == KEY_EXIT)
5953 return (MAX_COMMAND + 1);
5955 return (REQ_SCR_ULINE);
5957 return (REQ_SCR_DLINE);
5958 else if (c == 'b' || c == KEY_NPAGE)
5959 return (REQ_SCR_UPAGE);
5960 else if (c == 'f' || c == KEY_PPAGE)
5961 return (REQ_SCR_DPAGE);
5962 else if (c == 'n' || c == KEY_DOWN)
5963 return (REQ_NEXT_ITEM);
5964 else if (c == 'p' || c == KEY_UP)
5965 return (REQ_PREV_ITEM);
5967 return (REQ_TOGGLE_ITEM);
5975 static CONST_MENUS char *animals[] =
5988 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5989 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5994 menu_test(bool recur GCC_UNUSED)
5997 ITEM *items[SIZEOF(animals)];
5999 CONST_MENUS char **ap;
6000 int mrows, mcols, c;
6003 #ifdef NCURSES_MOUSE_VERSION
6004 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6006 MvAddStr(0, 0, "This is the menu test:");
6007 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
6008 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
6010 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
6011 MvAddStr(5, 0, " Press return to exit.");
6014 for (ap = animals; *ap; ap++) {
6015 if ((*ip = new_item(*ap, "")) != 0)
6020 m = new_menu(items);
6022 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
6023 scale_menu(m, &mrows, &mcols);
6025 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6026 set_menu_win(m, menuwin);
6027 keypad(menuwin, TRUE);
6030 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6034 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
6035 if (c == E_NOT_POSTED)
6037 if (c == E_REQUEST_DENIED)
6042 MvPrintw(LINES - 2, 0,
6043 "You chose: %s\n", item_name(current_item(m)));
6044 (void) addstr("Press any key to continue...");
6051 for (ip = items; *ip; ip++)
6053 #ifdef NCURSES_MOUSE_VERSION
6054 mousemask(0, (mmask_t *) 0);
6060 #define T_TBL(name) { #name, name }
6066 T_TBL(TRACE_DISABLE),
6069 T_TBL(TRACE_UPDATE),
6071 T_TBL(TRACE_CHARPUT),
6072 T_TBL(TRACE_ORDINARY),
6074 T_TBL(TRACE_VIRTPUT),
6075 T_TBL(TRACE_IEVENT),
6077 T_TBL(TRACE_ICALLS),
6078 T_TBL(TRACE_CCALLS),
6079 T_TBL(TRACE_DATABASE),
6081 T_TBL(TRACE_MAXIMUM),
6088 tracetrace(unsigned tlevel)
6091 static size_t need = 12;
6095 for (n = 0; t_tbl[n].name != 0; n++)
6096 need += strlen(t_tbl[n].name) + 2;
6097 buf = typeMalloc(char, need);
6099 failed("tracetrace");
6101 _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
6103 _nc_STRCAT(buf, t_tbl[0].name, need);
6104 _nc_STRCAT(buf, ", ", need);
6106 for (n = 1; t_tbl[n].name != 0; n++)
6107 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
6108 _nc_STRCAT(buf, t_tbl[n].name, need);
6109 _nc_STRCAT(buf, ", ", need);
6112 if (buf[strlen(buf) - 2] == ',')
6113 buf[strlen(buf) - 2] = '\0';
6114 _nc_STRCAT(buf, "}", need);
6118 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
6122 run_trace_menu(MENU * m)
6128 bool changed = FALSE;
6129 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
6130 case E_UNKNOWN_COMMAND:
6133 items = menu_items(m);
6134 i = current_item(m);
6135 if (i == items[0]) {
6136 if (item_value(i)) {
6137 for (p = items + 1; *p != 0; p++)
6138 if (item_value(*p)) {
6139 set_item_value(*p, FALSE);
6144 for (p = items + 1; *p != 0; p++)
6145 if (item_value(*p)) {
6146 set_item_value(items[0], FALSE);
6158 trace_set(bool recur GCC_UNUSED)
6159 /* interactively set the trace level */
6162 ITEM *items[SIZEOF(t_tbl)];
6169 MvAddStr(0, 0, "Interactively set trace level:");
6170 MvAddStr(2, 0, " Press space bar to toggle a selection.");
6171 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
6172 MvAddStr(4, 0, " Press return to set the trace level.");
6173 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
6177 for (n = 0; t_tbl[n].name != 0; n++) {
6178 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
6184 m = new_menu(items);
6186 set_menu_format(m, 0, 2);
6187 scale_menu(m, &mrows, &mcols);
6189 menu_opts_off(m, O_ONEVALUE);
6190 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6191 set_menu_win(m, menuwin);
6192 keypad(menuwin, TRUE);
6195 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6199 for (ip = menu_items(m); *ip; ip++) {
6200 unsigned mask = t_tbl[item_index(*ip)].mask;
6202 set_item_value(*ip, _nc_tracing == 0);
6203 else if ((mask & _nc_tracing) == mask)
6204 set_item_value(*ip, TRUE);
6207 while (run_trace_menu(m))
6211 for (ip = menu_items(m); *ip; ip++)
6212 if (item_value(*ip))
6213 newtrace |= t_tbl[item_index(*ip)].mask;
6215 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
6217 MvPrintw(LINES - 2, 0,
6218 "Trace level is %s\n", tracetrace(_nc_tracing));
6219 (void) addstr("Press any key to continue...");
6226 for (ip = items; *ip; ip++)
6232 #endif /* USE_LIBMENU */
6234 /****************************************************************************
6238 ****************************************************************************/
6241 make_label(int frow, int fcol, NCURSES_CONST char *label)
6243 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
6246 set_field_buffer(f, 0, label);
6247 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
6253 make_field(int frow, int fcol, int rows, int cols, bool secure)
6255 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
6258 set_field_back(f, A_UNDERLINE);
6259 set_field_userptr(f, (void *) 0);
6265 display_form(FORM *f)
6270 scale_form(f, &rows, &cols);
6272 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6274 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6277 if (post_form(f) != E_OK)
6285 WINDOW *w = form_win(f);
6286 WINDOW *s = form_sub(f);
6296 edit_secure(FIELD *me, int c)
6298 int rows, cols, frow, fcol, nrow, nbuf;
6300 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6302 char *source = field_buffer(me, 1);
6303 size_t have = (source ? strlen(source) : 0) + 1;
6304 size_t need = 80 + have;
6305 char *temp = malloc(need);
6309 _nc_STRNCPY(temp, source ? source : "", have + 1);
6310 len = (size_t) (char *) field_userptr(me);
6312 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6313 temp[len++] = (char) c;
6315 set_field_buffer(me, 1, temp);
6335 case REQ_RIGHT_CHAR:
6337 c = 0; /* we don't want to do inline editing */
6342 set_field_buffer(me, 1, temp);
6349 set_field_buffer(me, 1, temp);
6354 set_field_userptr(me, (void *) len);
6362 form_virtualize(FORM *f, WINDOW *w)
6365 static const struct {
6369 { CTRL('A'), REQ_NEXT_CHOICE },
6370 { CTRL('B'), REQ_PREV_WORD },
6371 { CTRL('C'), REQ_CLR_EOL },
6372 { CTRL('D'), REQ_DOWN_FIELD },
6373 { CTRL('E'), REQ_END_FIELD },
6374 { CTRL('F'), REQ_NEXT_PAGE },
6375 { CTRL('G'), REQ_DEL_WORD },
6376 { CTRL('H'), REQ_DEL_PREV },
6377 { CTRL('I'), REQ_INS_CHAR },
6378 { CTRL('K'), REQ_CLR_EOF },
6379 { CTRL('L'), REQ_LEFT_FIELD },
6380 { CTRL('M'), REQ_NEW_LINE },
6381 { CTRL('N'), REQ_NEXT_FIELD },
6382 { CTRL('O'), REQ_INS_LINE },
6383 { CTRL('P'), REQ_PREV_FIELD },
6384 { CTRL('R'), REQ_RIGHT_FIELD },
6385 { CTRL('S'), REQ_BEG_FIELD },
6386 { CTRL('U'), REQ_UP_FIELD },
6387 { CTRL('V'), REQ_DEL_CHAR },
6388 { CTRL('W'), REQ_NEXT_WORD },
6389 { CTRL('X'), REQ_CLR_FIELD },
6390 { CTRL('Y'), REQ_DEL_LINE },
6391 { CTRL('Z'), REQ_PREV_CHOICE },
6392 { ESCAPE, MAX_FORM_COMMAND + 1 },
6393 { KEY_BACKSPACE, REQ_DEL_PREV },
6394 { KEY_DOWN, REQ_DOWN_CHAR },
6395 { KEY_END, REQ_LAST_FIELD },
6396 { KEY_HOME, REQ_FIRST_FIELD },
6397 { KEY_LEFT, REQ_LEFT_CHAR },
6398 { KEY_LL, REQ_LAST_FIELD },
6399 { KEY_NEXT, REQ_NEXT_FIELD },
6400 { KEY_NPAGE, REQ_NEXT_PAGE },
6401 { KEY_PPAGE, REQ_PREV_PAGE },
6402 { KEY_PREVIOUS, REQ_PREV_FIELD },
6403 { KEY_RIGHT, REQ_RIGHT_CHAR },
6404 { KEY_UP, REQ_UP_CHAR },
6405 { QUIT, MAX_FORM_COMMAND + 1 }
6409 static int mode = REQ_INS_MODE;
6410 int c = wGetchar(w);
6412 FIELD *me = current_field(f);
6413 bool current = TRUE;
6415 if (c == CTRL(']')) {
6416 if (mode == REQ_INS_MODE) {
6417 mode = REQ_OVL_MODE;
6419 mode = REQ_INS_MODE;
6423 for (n = 0; n < SIZEOF(lookup); n++) {
6424 if (lookup[n].code == c) {
6425 c = lookup[n].result;
6430 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6433 * Force the field that the user is typing into to be in reverse video,
6434 * while the other fields are shown underlined.
6449 case REQ_LEFT_FIELD:
6451 case REQ_RIGHT_CHAR:
6455 current = (c < KEY_MAX);
6459 c = edit_secure(me, c);
6460 set_field_back(me, A_REVERSE);
6462 c = edit_secure(me, c);
6463 set_field_back(me, A_UNDERLINE);
6469 my_form_driver(FORM *form, int c)
6471 if (c == (MAX_FORM_COMMAND + 1)
6472 && form_driver(form, REQ_VALIDATION) == E_OK)
6480 #ifdef NCURSES_VERSION
6481 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6482 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6484 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6485 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6489 * Allow a middle initial, optionally with a '.' to end it.
6492 FIELDCHECK_CB(mi_field_check)
6494 char *s = field_buffer(fld, 0);
6498 for (n = 0; s[n] != '\0'; ++n) {
6505 } else if (isspace(UChar(s[n]))) {
6510 if (!isspace(UChar(s[n])))
6516 /* force the form to display a leading capital */
6517 if (islower(UChar(s[0]))) {
6518 s[0] = (char) toupper(UChar(s[0]));
6519 set_field_buffer(fld, 0, s);
6525 CHAR_CHECK_CB(mi_char_check)
6527 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6531 * Passwords should be at least 6 characters.
6534 FIELDCHECK_CB(pw_field_check)
6536 char *s = field_buffer(fld, 0);
6539 for (n = 0; s[n] != '\0'; ++n) {
6540 if (isspace(UChar(s[n]))) {
6549 CHAR_CHECK_CB(pw_char_check)
6551 return (isgraph(ch) ? TRUE : FALSE);
6555 form_test(bool recur GCC_UNUSED)
6559 FIELD *f[12], *secure;
6560 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6561 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6562 int finished = 0, c;
6565 #ifdef NCURSES_MOUSE_VERSION
6566 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6570 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6571 addstr("^N -- go to next field ^P -- go to previous field\n");
6572 addstr("Home -- go to first field End -- go to last field\n");
6573 addstr("^L -- go to field to left ^R -- go to field to right\n");
6574 addstr("^U -- move upward to field ^D -- move downward to field\n");
6575 addstr("^W -- go to next word ^B -- go to previous word\n");
6576 addstr("^S -- go to start of field ^E -- go to end of field\n");
6577 addstr("^H -- delete previous char ^Y -- delete line\n");
6578 addstr("^G -- delete current word ^C -- clear to end of line\n");
6579 addstr("^K -- clear to end of field ^X -- clear field\n");
6580 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6582 MvAddStr(4, 57, "Forms Entry Test");
6586 /* describe the form */
6587 memset(f, 0, sizeof(f));
6588 f[n++] = make_label(0, 15, "Sample Form");
6590 f[n++] = make_label(2, 0, "Last Name");
6591 f[n++] = make_field(3, 0, 1, 18, FALSE);
6592 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6594 f[n++] = make_label(2, 20, "First Name");
6595 f[n++] = make_field(3, 20, 1, 12, FALSE);
6596 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6598 f[n++] = make_label(2, 34, "Middle Name");
6599 f[n++] = make_field(3, 34, 1, 12, FALSE);
6600 set_field_type(f[n - 1], fty_middle);
6602 f[n++] = make_label(5, 0, "Comments");
6603 f[n++] = make_field(6, 0, 4, 46, FALSE);
6605 f[n++] = make_label(5, 20, "Password:");
6607 f[n++] = make_field(5, 30, 1, 9, TRUE);
6608 set_field_type(f[n - 1], fty_passwd);
6611 if ((form = new_form(f)) != 0) {
6617 nonl(); /* lets us read ^M's */
6619 switch (form_driver(form, c = form_virtualize(form, w))) {
6621 MvAddStr(5, 57, field_buffer(secure, 1));
6625 case E_UNKNOWN_COMMAND:
6626 finished = my_form_driver(form, c);
6638 for (c = 0; f[c] != 0; c++)
6640 free_fieldtype(fty_middle);
6641 free_fieldtype(fty_passwd);
6645 #ifdef NCURSES_MOUSE_VERSION
6646 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6650 #endif /* USE_LIBFORM */
6652 /****************************************************************************
6656 ****************************************************************************/
6658 #if HAVE_COPYWIN /* ...and overlay, overwrite */
6660 fillwin(WINDOW *win, char ch)
6665 getmaxyx(win, y1, x1);
6666 for (y = 0; y < y1; y++) {
6668 for (x = 0; x < x1; x++)
6669 waddch(win, UChar(ch));
6674 crosswin(WINDOW *win, char ch)
6679 getmaxyx(win, y1, x1);
6680 for (y = 0; y < y1; y++) {
6681 for (x = 0; x < x1; x++)
6682 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
6683 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
6685 waddch(win, UChar(ch));
6690 #define OVERLAP_FLAVORS 5
6693 overlap_helpitem(int state, int item, char *message)
6695 int row = (item / 2);
6696 int col = ((item % 2) ? COLS / 2 : 0);
6698 move(LINES - 6 + row, col);
6699 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6704 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6706 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6710 (void) wattrset(win, A_NORMAL);
6713 (void) wattrset(win, A_BOLD);
6716 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6717 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
6720 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6721 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
6727 overlap_test_2_attr(WINDOW *win, int flavor, int col)
6729 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
6739 init_pair(cpair, COLOR_RED, COLOR_GREEN);
6740 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
6743 wbkgdset(win, ' ' | A_NORMAL);
6749 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
6754 const char *ths, *tht;
6758 state += OVERLAP_FLAVORS;
6759 state = state % OVERLAP_FLAVORS;
6760 assert(state >= 0 && state < OVERLAP_FLAVORS);
6762 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
6765 ths = col ? "B" : "A";
6766 tht = col ? "A" : "B";
6771 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6772 "refresh %s, then %s, then doupdate.", ths, tht);
6780 overlap_test_1_attr(stdscr, flavors[row], col);
6781 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6782 "fill window %s with letter %s.", ths, ths);
6790 switch (flavors[row]) {
6792 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6793 "cross pattern in window %s.", ths);
6796 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6797 "draw box in window %s.", ths);
6800 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6801 "set background of window %s.", ths);
6804 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6805 "reset background of window %s.", ths);
6811 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6812 "clear window %s.", ths);
6816 switch (flavors[row]) {
6818 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6819 "overwrite %s onto %s.", ths, tht);
6822 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6823 "copywin(FALSE) %s onto %s.", ths, tht);
6826 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6827 "copywin(TRUE) %s onto %s.", ths, tht);
6830 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6831 "overlay %s onto %s.", ths, tht);
6836 overlap_helpitem(state, item, msg);
6837 (void) wattrset(stdscr, A_NORMAL);
6838 wbkgdset(stdscr, ' ' | A_NORMAL);
6841 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
6842 state, flavors[state]);
6848 overlap_test_0(WINDOW *a, WINDOW *b)
6858 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
6860 overlap_test_1_attr(a, flavor, col);
6862 (void) wattrset(a, A_NORMAL);
6866 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6868 overlap_test_2_attr(a, flavor, col);
6877 /* done in overlap_test_2_attr */
6880 /* done in overlap_test_2_attr */
6886 overlap_test_3(WINDOW *a)
6893 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
6900 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
6903 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
6911 /* test effects of overlapping windows */
6913 overlap_test(bool recur GCC_UNUSED)
6916 int state, flavor[OVERLAP_FLAVORS];
6918 WINDOW *win1 = newwin(9, 20, 3, 3);
6919 WINDOW *win2 = newwin(9, 20, 9, 16);
6925 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
6926 printw("the shared region of two overlapping windows A and B. The cross\n");
6927 printw("pattern in each window does not overlap the other.\n");
6929 memset(flavor, 0, sizeof(flavor));
6930 state = overlap_help(0, flavor);
6932 while (!isQuit(ch = Getchar(), TRUE))
6934 case 'a': /* refresh window A first, then B */
6935 overlap_test_0(win1, win2);
6938 case 'b': /* refresh window B first, then A */
6939 overlap_test_0(win2, win1);
6942 case 'c': /* fill window A so it's visible */
6943 overlap_test_1(flavor[1], 0, win1, 'A');
6946 case 'd': /* fill window B so it's visible */
6947 overlap_test_1(flavor[1], 1, win2, 'B');
6950 case 'e': /* cross test pattern in window A */
6951 overlap_test_2(flavor[2], 0, win1, 'A');
6954 case 'f': /* cross test pattern in window A */
6955 overlap_test_2(flavor[2], 1, win2, 'B');
6958 case 'g': /* clear window A */
6959 overlap_test_3(win1);
6962 case 'h': /* clear window B */
6963 overlap_test_3(win2);
6966 case 'i': /* overwrite A onto B */
6967 overlap_test_4(flavor[4], win1, win2);
6970 case 'j': /* overwrite B onto A */
6971 overlap_test_4(flavor[4], win2, win1);
6976 state = overlap_help(state + 1, flavor);
6981 state = overlap_help(state - 1, flavor);
6986 state = overlap_help(state, flavor);
6990 state = overlap_help(state, flavor);
7005 #endif /* HAVE_COPYWIN */
7008 show_setting_name(const char *name)
7010 printw("%-25s ", name);
7014 show_string_setting(const char *name, const char *value)
7016 show_setting_name(name);
7018 printw("\"%s\"", value);
7028 show_number_setting(const char *name, int value)
7030 show_setting_name(name);
7032 printw("%d", value);
7035 printw("%d", value);
7042 show_boolean_setting(const char *name, int value)
7044 show_setting_name(name);
7046 printw("%s", value ? "TRUE" : "FALSE");
7049 printw("%d", value);
7056 settings_test(bool recur GCC_UNUSED)
7058 #if USE_WIDEC_SUPPORT
7063 show_string_setting("termname", termname());
7064 show_string_setting("longname", longname());
7065 show_number_setting("baudrate", baudrate());
7066 if (erasechar() > 0) {
7067 show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
7068 show_string_setting("keyname(erasechar)", keyname(erasechar()));
7070 if (killchar() > 0) {
7071 show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
7072 show_string_setting("keyname(killchar)", keyname(killchar()));
7074 #if USE_WIDEC_SUPPORT
7075 if (erasewchar(&ch) == OK) {
7076 show_string_setting("key_name(erasewchar)", key_name(ch));
7078 if (killwchar(&ch) == OK) {
7079 show_string_setting("key_name(killwchar)", key_name(ch));
7082 show_boolean_setting("has_ic", has_ic());
7083 show_boolean_setting("has_il", has_il());
7084 show_boolean_setting("has_colors", has_colors());
7085 #if HAVE_COLOR_CONTENT
7086 show_boolean_setting("can_change_color", can_change_color());
7094 /****************************************************************************
7098 ****************************************************************************/
7103 static const char *const tbl[] =
7105 "Usage: ncurses [options]"
7108 #ifdef NCURSES_VERSION
7109 ," -a f,b set default-colors (assumed white-on-black)"
7110 ," -d use default-colors if terminal supports them"
7113 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
7116 ," -e fmt specify format for soft-keys test (e)"
7119 ," -f rip-off footer line (can repeat)"
7120 ," -h rip-off header line (can repeat)"
7122 ," -m do not use colors"
7123 #if HAVE_COLOR_CONTENT
7124 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
7127 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
7129 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(__MINGW32__)
7130 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
7133 ," -t mask specify default trace-level (may toggle with ^T)"
7135 #if HAVE_COLOR_CONTENT
7136 ," -x use xterm-compatible control for reading color palette"
7140 for (n = 0; n < SIZEOF(tbl); n++)
7141 fprintf(stderr, "%s\n", tbl[n]);
7142 ExitProgram(EXIT_FAILURE);
7146 set_terminal_modes(void)
7151 scrollok(stdscr, TRUE);
7152 idlok(stdscr, TRUE);
7153 keypad(stdscr, TRUE);
7158 announce_sig(int sig)
7160 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
7166 rip_footer(WINDOW *win, int cols)
7168 wbkgd(win, A_REVERSE);
7171 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
7177 rip_header(WINDOW *win, int cols)
7179 wbkgd(win, A_REVERSE);
7182 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
7186 #endif /* HAVE_RIPOFFLINE */
7191 #if USE_WIDEC_SUPPORT
7194 int (*narrow_func) (bool);
7195 int (*wide_func) (bool);
7199 #define BOTH(a) a, x_ ## a
7200 #define ONLY(a) a, NULL
7201 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7205 int (*narrow_func) (bool);
7211 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7214 static MyCmds cmds[] =
7216 CMDS(TRUE, BOTH(getch_test), 'a', "keyboard and mouse input test"),
7217 CMDS(TRUE, BOTH(attr_test), 'b', "character attribute test"),
7218 CMDS(TRUE, BOTH(color_test), 'c', "color test pattern"),
7219 #if HAVE_COLOR_CONTENT
7220 CMDS(FALSE, ONLY(color_edit), 'd', "edit RGB color values"),
7223 CMDS(TRUE, BOTH(slk_test), 'e', "exercise soft keys"),
7225 CMDS(TRUE, BOTH(acs_test), 'f', "display ACS characters"),
7226 CMDS(TRUE, ONLY(scroll_test), 'g', "display windows and scrolling"),
7227 CMDS(TRUE, ONLY(flushinp_test), 'i', "test flushinp()"),
7228 CMDS(TRUE, ONLY(sgr_attr_test), 'k', "display character attributes"),
7230 CMDS(TRUE, ONLY(menu_test), 'm', "exercise menu library"),
7233 CMDS(TRUE, BOTH(panel_test), 'o', "exercise panel library"),
7236 CMDS(TRUE, ONLY(pad_test), 'p', "exercise pad features"),
7238 CMDS(TRUE, ONLY(NULL), 'q', "quit"),
7240 CMDS(TRUE, ONLY(form_test), 'r', "exercise form library"),
7243 CMDS(TRUE, ONLY(overlap_test), 's', "overlapping-refresh test"),
7245 #if USE_LIBMENU && defined(TRACE)
7246 CMDS(TRUE, ONLY(trace_set), 't', "set trace level"),
7248 CMDS(TRUE, ONLY(settings_test), 'v', "show terminal name and settings"),
7249 CMDS(FALSE, ONLY(NULL), '?', "repeat this command summary")
7258 printf("This is the ncurses main menu (uppercase for wide-characters)\n");
7259 for (n = 0; n < SIZEOF(cmds); ++n) {
7260 if (top || cmds[n].recur) {
7262 #if USE_WIDEC_SUPPORT
7263 if (cmds[n].wide_func) {
7264 printf("%c,", toupper(cmds[n].code));
7267 printf("%c\t= %s\n", cmds[n].code, cmds[n].help);
7271 (void) fputs("> ", stdout);
7272 (void) fflush(stdout); /* necessary under SVr4 curses */
7275 * This used to be an 'fgets()' call (until 1996/10). However with
7276 * some runtime libraries, mixing stream I/O and 'read()' causes the
7277 * input stream to be flushed when switching between the two.
7282 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7286 } else if (command == 0 && !isspace(UChar(ch))) {
7288 } else if (ch == '\n' || ch == '\r') {
7289 if ((command == 'd') && !top) {
7290 (void) fputs("Do not nest test-d\n", stdout);
7295 (void) fputs("> ", stdout);
7296 (void) fflush(stdout);
7301 for (n = 0; n < SIZEOF(cmds); ++n) {
7302 if (cmds[n].code == command) {
7303 doit = cmds[n].narrow_func;
7306 #if USE_WIDEC_SUPPORT
7307 if (toupper(cmds[n].code) == command) {
7308 doit = cmds[n].wide_func;
7314 if (doit != NULL && doit(FALSE) == OK) {
7316 * This may be overkill; it's intended to reset everything back
7317 * to the initial terminal modes so that tests don't get in
7321 set_terminal_modes();
7326 if (command == '?') {
7327 (void) puts("This is the ncurses capability tester.");
7329 puts("You may select a test from the main menu by typing the");
7331 puts("key letter of the choice (the letter to left of the =)");
7333 puts("at the > prompt. Type `q' to exit.");
7341 /*+-------------------------------------------------------------------------
7343 --------------------------------------------------------------------------*/
7346 main(int argc, char *argv[])
7350 #ifdef NCURSES_VERSION
7351 int default_fg = COLOR_WHITE;
7352 int default_bg = COLOR_BLACK;
7353 bool assumed_colors = FALSE;
7354 bool default_colors = FALSE;
7356 bool monochrome = FALSE;
7357 #if HAVE_COLOR_CONTENT
7358 bool xterm_colors = FALSE;
7359 char *palette_file = 0;
7362 setlocale(LC_ALL, "");
7364 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) {
7366 #ifdef NCURSES_VERSION
7368 assumed_colors = TRUE;
7369 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7371 default_fg = COLOR_WHITE;
7374 default_bg = COLOR_BLACK;
7379 default_colors = TRUE;
7388 my_e_param = atoi(optarg);
7389 #ifdef NCURSES_VERSION
7390 if (my_e_param > 3) /* allow extended layouts */
7399 ripoffline(-1, rip_footer);
7402 ripoffline(1, rip_header);
7404 #endif /* HAVE_RIPOFFLINE */
7408 #if HAVE_COLOR_CONTENT
7410 palette_file = optarg;
7415 nap_msec = (int) atol(optarg);
7418 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(__MINGW32__)
7425 save_trace = (unsigned) strtol(optarg, 0, 0);
7428 #if HAVE_COLOR_CONTENT
7430 xterm_colors = TRUE;
7439 * If there's no menus (unlikely for ncurses!), then we'll have to set
7440 * tracing on initially, just in case the user wants to test something that
7441 * doesn't involve wGetchar.
7444 /* enable debugging */
7448 if (!isatty(fileno(stdin)))
7450 #endif /* USE_LIBMENU */
7454 /* tell it we're going to play with soft keys */
7455 slk_init(my_e_param);
7459 /* set up null signal catcher so we can see what interrupts to getch do */
7460 signal(SIGUSR1, announce_sig);
7463 /* we must initialize the curses data structure only once */
7467 set_terminal_modes();
7470 /* tests, in general, will want these modes */
7471 UseColors = (bool) (monochrome ? FALSE : has_colors());
7475 #ifdef NCURSES_VERSION_PATCH
7476 MaxColors = COLORS; /* was > 16 ? 16 : COLORS */
7477 #if HAVE_USE_DEFAULT_COLORS
7478 if (default_colors) {
7479 use_default_colors();
7482 #if HAVE_ASSUME_DEFAULT_COLORS
7484 assume_default_colors(default_fg, default_bg);
7487 #else /* normal SVr4 curses */
7488 MaxColors = COLORS; /* was > 8 ? 8 : COLORS */
7490 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
7492 #if HAVE_COLOR_CONTENT
7493 if (can_change_color()) {
7494 init_all_colors(xterm_colors, palette_file);
7500 * Return to terminal mode, so we're guaranteed of being able to
7501 * select terminal commands even if the capabilities are wrong.
7505 #if HAVE_CURSES_VERSION
7506 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
7507 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
7508 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
7509 NCURSES_VERSION_MAJOR,
7510 NCURSES_VERSION_MINOR,
7511 NCURSES_VERSION_PATCH);
7513 (void) puts("Welcome to ncurses. Press ? for help.");
7518 ExitProgram(EXIT_SUCCESS);
7521 /* ncurses.c ends here */