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.487 2017/10/28 00:54:41 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);
483 ShellOut(bool message)
486 addstr("Shelling out...");
492 IGNORE_RC(system("sh"));
495 addstr("returned from shellout.\n");
499 #ifdef NCURSES_MOUSE_VERSION
501 * This function is the same as _tracemouse(), but we cannot count on that
502 * being available in the non-debug library.
505 mouse_decode(MEVENT const *ep)
507 static char buf[80 + (5 * 10) + (32 * 15)];
509 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
510 "id %2d at (%2d, %2d, %d) state %4lx = {",
511 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
514 if ((ep->bstate & m)==m) { \
515 _nc_STRCAT(buf, s, sizeof(buf)); \
516 _nc_STRCAT(buf, ", ", sizeof(buf)); \
519 SHOW(BUTTON1_RELEASED, "release-1");
520 SHOW(BUTTON1_PRESSED, "press-1");
521 SHOW(BUTTON1_CLICKED, "click-1");
522 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
523 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
524 #if NCURSES_MOUSE_VERSION == 1
525 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
528 SHOW(BUTTON2_RELEASED, "release-2");
529 SHOW(BUTTON2_PRESSED, "press-2");
530 SHOW(BUTTON2_CLICKED, "click-2");
531 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
532 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
533 #if NCURSES_MOUSE_VERSION == 1
534 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
537 SHOW(BUTTON3_RELEASED, "release-3");
538 SHOW(BUTTON3_PRESSED, "press-3");
539 SHOW(BUTTON3_CLICKED, "click-3");
540 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
541 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
542 #if NCURSES_MOUSE_VERSION == 1
543 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
546 SHOW(BUTTON4_RELEASED, "release-4");
547 SHOW(BUTTON4_PRESSED, "press-4");
548 SHOW(BUTTON4_CLICKED, "click-4");
549 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
550 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
551 #if NCURSES_MOUSE_VERSION == 1
552 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
555 #if NCURSES_MOUSE_VERSION == 2
556 SHOW(BUTTON5_RELEASED, "release-5");
557 SHOW(BUTTON5_PRESSED, "press-5");
558 SHOW(BUTTON5_CLICKED, "click-5");
559 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
560 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
563 SHOW(BUTTON_CTRL, "ctrl");
564 SHOW(BUTTON_SHIFT, "shift");
565 SHOW(BUTTON_ALT, "alt");
566 SHOW(ALL_MOUSE_EVENTS, "all-events");
567 SHOW(REPORT_MOUSE_POSITION, "position");
571 if (buf[strlen(buf) - 1] == ' ')
572 buf[strlen(buf) - 2] = '\0';
573 _nc_STRCAT(buf, "}", sizeof(buf));
578 show_mouse(WINDOW *win)
586 outside = !wenclose(win, event.y, event.x);
589 (void) wstandout(win);
590 waddstr(win, "KEY_MOUSE");
591 (void) wstandend(win);
593 waddstr(win, "KEY_MOUSE");
595 wprintw(win, ", %s", mouse_decode(&event));
600 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
604 wmove(win, event.y, event.x);
612 #endif /* NCURSES_MOUSE_VERSION */
614 /****************************************************************************
616 * Character input test
618 ****************************************************************************/
620 #define NUM_GETCH_FLAGS 256
621 typedef bool GetchFlags[NUM_GETCH_FLAGS];
624 setup_getch(WINDOW *win, GetchFlags flags)
626 keypad(win, flags['k']); /* should be redundant, but for testing */
627 meta(win, flags['m']); /* force this to a known state */
635 init_getch(WINDOW *win, GetchFlags flags, int delay)
637 memset(flags, FALSE, NUM_GETCH_FLAGS);
638 flags[UChar('k')] = (win == stdscr);
639 flags[UChar('m')] = TRUE;
640 flags[UChar('t')] = (delay != 0);
642 setup_getch(win, flags);
646 blocking_getch(GetchFlags flags, int delay)
648 return ((delay < 0) && flags['t']);
651 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
654 wgetch_help(WINDOW *win, GetchFlags flags)
656 static const char *help[] =
658 "e -- toggle echo mode"
659 ,"g -- triggers a getstr test"
660 ,"k -- toggle keypad/literal mode"
661 ,"m -- toggle meta (7-bit/8-bit) mode"
664 ,"t -- toggle timeout"
665 ,"w -- create a new window"
667 ,"z -- suspend this process"
671 unsigned chk = ((SIZEOF(help) + 1) / 2);
676 printw("Type any key to see its %s value. Also:\n",
677 flags['k'] ? "keypad" : "literal");
678 for (n = 0; n < SIZEOF(help); ++n) {
679 const char *msg = help[n];
680 int row = 1 + (int) (n % chk);
681 int col = (n >= chk) ? COLS / 2 : 0;
682 int flg = ((strstr(msg, "toggle") != 0)
683 && (flags[UChar(*msg)] != FALSE));
684 if (*msg == '^' && ExitOnEscape())
685 msg = "^[,^q -- quit";
688 MvPrintw(row, col, "%s", msg);
699 wgetch_wrap(WINDOW *win, int first_y)
701 int last_y = getmaxy(win) - 1;
702 int y = getcury(win) + 1;
710 #if defined(KEY_RESIZE) && HAVE_WRESIZE
716 static WINSTACK *winstack = 0;
717 static unsigned len_winstack = 0;
730 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
732 unsigned need = (level + 1) * 2;
734 assert(level < (unsigned) COLS);
738 winstack = typeMalloc(WINSTACK, len_winstack);
739 } else if (need >= len_winstack) {
741 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
744 failed("remember_boxes");
745 winstack[level].text = txt_win;
746 winstack[level].frame = box_win;
749 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
753 /* this chunk is now done in resize_term() */
760 #define slk_repaint() /* nothing */
763 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
765 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
766 * Resize both and paint the box in the parent.
769 resize_boxes(unsigned level, WINDOW *win)
773 int high = LINES - base;
777 wnoutrefresh(stdscr);
781 for (n = 0; n < level; ++n) {
782 wresize(winstack[n].frame, high, wide);
783 wresize(winstack[n].text, high - 2, wide - 2);
786 werase(winstack[n].text);
787 box(winstack[n].frame, 0, 0);
788 wnoutrefresh(winstack[n].frame);
789 wprintw(winstack[n].text,
791 getmaxy(winstack[n].text),
792 getmaxx(winstack[n].text));
793 wnoutrefresh(winstack[n].text);
794 if (winstack[n].text == win)
799 #endif /* resize_boxes */
801 #define forget_boxes() /* nothing */
802 #define remember_boxes(level,text,frame) /* nothing */
806 * Return-code is OK/ERR or a keyname.
811 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
815 wgetch_test(unsigned level, WINDOW *win, int delay)
818 int first_y, first_x;
823 init_getch(win, flags, delay);
824 notimeout(win, FALSE);
825 wtimeout(win, delay);
826 getyx(win, first_y, first_x);
828 wgetch_help(win, flags);
829 wsetscrreg(win, first_y, getmaxy(win) - 1);
833 while ((c = wGetchar(win)) == ERR) {
835 if (blocking_getch(flags, delay)) {
836 (void) wprintw(win, "%05d: input error", incount);
839 (void) wprintw(win, "%05d: input timed out", incount);
841 wgetch_wrap(win, first_y);
843 if (c == ERR && blocking_getch(flags, delay)) {
845 wgetch_wrap(win, first_y);
846 } else if (isQuit(c, ExitOnEscape())) {
848 } else if (c == 'e') {
849 flags[UChar('e')] = !flags[UChar('e')];
850 setup_getch(win, flags);
851 wgetch_help(win, flags);
852 } else if (c == 'g') {
853 waddstr(win, "getstr test: ");
855 c = wgetnstr(win, buf, sizeof(buf) - 1);
857 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
858 (int) strlen(buf), buf,
861 wgetch_wrap(win, first_y);
862 } else if (c == 'k') {
863 flags[UChar('k')] = !flags[UChar('k')];
864 setup_getch(win, flags);
865 wgetch_help(win, flags);
866 } else if (c == 'm') {
867 flags[UChar('m')] = !flags[UChar('m')];
868 setup_getch(win, flags);
869 wgetch_help(win, flags);
870 } else if (c == 's') {
872 } else if (c == 't') {
873 notimeout(win, flags[UChar('t')]);
874 flags[UChar('t')] = !flags[UChar('t')];
875 wgetch_help(win, flags);
876 } else if (c == 'w') {
877 int high = getmaxy(win) - 1 - first_y + 1;
878 int wide = getmaxx(win) - first_x;
880 int new_y = first_y + getbegy(win);
881 int new_x = first_x + getbegx(win);
883 getyx(win, old_y, old_x);
884 if (high > 2 && wide > 2) {
885 WINDOW *wb = newwin(high, wide, new_y, new_x);
886 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
891 remember_boxes(level, wi, wb);
892 wgetch_test(level + 1, wi, delay);
896 wgetch_help(win, flags);
897 wmove(win, old_y, old_x);
903 } else if (c == 'z') {
904 kill(getpid(), SIGTSTP);
907 wprintw(win, "Key pressed: %04o ", c);
908 #ifdef NCURSES_MOUSE_VERSION
909 if (c == KEY_MOUSE) {
912 #endif /* NCURSES_MOUSE_VERSION */
914 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
915 if (c == KEY_RESIZE) {
916 resize_boxes(level, win);
919 (void) waddstr(win, keyname(c));
920 } else if (c >= 0x80) {
921 unsigned c2 = (unsigned) c;
922 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
923 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
927 (void) wprintw(win, "%c", UChar(c));
928 else if (c2 != UChar(c))
929 (void) wprintw(win, "M-%s", unctrl(c2));
931 (void) wprintw(win, "%s", unctrl(c2));
932 waddstr(win, " (high-half character)");
935 (void) wprintw(win, "%c (ASCII printable character)", c);
937 (void) wprintw(win, "%s (ASCII control character)",
940 wgetch_wrap(win, first_y);
947 init_getch(win, flags, delay);
951 begin_getch_test(void)
958 #ifdef NCURSES_MOUSE_VERSION
959 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
962 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
964 getnstr(buf, sizeof(buf) - 1);
968 if (isdigit(UChar(buf[0]))) {
969 delay = atoi(buf) * 100;
979 finish_getch_test(void)
981 #ifdef NCURSES_MOUSE_VERSION
982 mousemask(0, (mmask_t *) 0);
991 getch_test(bool recur GCC_UNUSED)
993 int delay = begin_getch_test();
996 wgetch_test(0, stdscr, delay);
1003 #if USE_WIDEC_SUPPORT
1005 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1006 * Resize both and paint the box in the parent.
1008 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1010 resize_wide_boxes(unsigned level, WINDOW *win)
1014 int high = LINES - base;
1018 wnoutrefresh(stdscr);
1022 for (n = 0; n < level; ++n) {
1023 wresize(winstack[n].frame, high, wide);
1024 wresize(winstack[n].text, high - 2, wide - 2);
1027 werase(winstack[n].text);
1028 box_set(winstack[n].frame, 0, 0);
1029 wnoutrefresh(winstack[n].frame);
1030 wprintw(winstack[n].text,
1032 getmaxy(winstack[n].text),
1033 getmaxx(winstack[n].text));
1034 wnoutrefresh(winstack[n].text);
1035 if (winstack[n].text == win)
1040 #endif /* KEY_RESIZE */
1043 wcstos(const wchar_t *src)
1047 const wchar_t *tmp = src;
1048 #ifndef state_unused
1052 reset_wchars(state);
1053 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1054 unsigned have = (unsigned) need;
1055 if ((result = typeCalloc(char, have + 1)) != 0) {
1057 if (trans_wchars(result, tmp, have, &state) != have) {
1069 wget_wch_test(unsigned level, WINDOW *win, int delay)
1071 wchar_t wchar_buf[BUFSIZ];
1072 wint_t wint_buf[BUFSIZ];
1073 int first_y, first_x;
1080 init_getch(win, flags, delay);
1081 notimeout(win, FALSE);
1082 wtimeout(win, delay);
1083 getyx(win, first_y, first_x);
1085 wgetch_help(win, flags);
1086 wsetscrreg(win, first_y, getmaxy(win) - 1);
1087 scrollok(win, TRUE);
1090 while ((code = wGet_wchar(win, &c)) == ERR) {
1092 if (blocking_getch(flags, delay)) {
1093 (void) wprintw(win, "%05d: input error", incount);
1096 (void) wprintw(win, "%05d: input timed out", incount);
1098 wgetch_wrap(win, first_y);
1100 if (code == ERR && blocking_getch(flags, delay)) {
1101 wprintw(win, "ERR");
1102 wgetch_wrap(win, first_y);
1103 } else if (isQuit((int) c, ExitOnEscape())) {
1105 } else if (c == 'e') {
1106 flags[UChar('e')] = !flags[UChar('e')];
1107 setup_getch(win, flags);
1108 wgetch_help(win, flags);
1109 } else if (c == 'g') {
1110 waddstr(win, "getstr test: ");
1112 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1115 wprintw(win, "wgetn_wstr returns an error.");
1118 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1121 if ((temp = wcstos(wchar_buf)) != 0) {
1122 wprintw(win, "I saw %d characters:\n\t`%s'.",
1123 (int) wcslen(wchar_buf), temp);
1126 wprintw(win, "I saw %d characters (cannot convert).",
1127 (int) wcslen(wchar_buf));
1131 wgetch_wrap(win, first_y);
1132 } else if (c == 'k') {
1133 flags[UChar('k')] = !flags[UChar('k')];
1134 setup_getch(win, flags);
1135 wgetch_help(win, flags);
1136 } else if (c == 'm') {
1137 flags[UChar('m')] = !flags[UChar('m')];
1138 setup_getch(win, flags);
1139 wgetch_help(win, flags);
1140 } else if (c == 's') {
1142 } else if (c == 't') {
1143 notimeout(win, flags[UChar('t')]);
1144 flags[UChar('t')] = !flags[UChar('t')];
1145 wgetch_help(win, flags);
1146 } else if (c == 'w') {
1147 int high = getmaxy(win) - 1 - first_y + 1;
1148 int wide = getmaxx(win) - first_x;
1150 int new_y = first_y + getbegy(win);
1151 int new_x = first_x + getbegx(win);
1153 getyx(win, old_y, old_x);
1154 if (high > 2 && wide > 2) {
1155 WINDOW *wb = newwin(high, wide, new_y, new_x);
1156 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1161 remember_boxes(level, wi, wb);
1162 wget_wch_test(level + 1, wi, delay);
1166 wgetch_help(win, flags);
1167 wmove(win, old_y, old_x);
1172 } else if (c == 'z') {
1173 kill(getpid(), SIGTSTP);
1176 wprintw(win, "Key pressed: %04o ", (int) c);
1177 #ifdef NCURSES_MOUSE_VERSION
1178 if (c == KEY_MOUSE) {
1181 #endif /* NCURSES_MOUSE_VERSION */
1182 if (code == KEY_CODE_YES) {
1183 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1184 if (c == KEY_RESIZE) {
1185 resize_wide_boxes(level, win);
1188 (void) waddstr(win, keyname((wchar_t) c));
1190 (void) waddstr(win, key_name((wchar_t) c));
1191 if (c < 256 && iscntrl(c)) {
1192 (void) wprintw(win, " (control character)");
1194 (void) wprintw(win, " = %#x (printable character)",
1198 wgetch_wrap(win, first_y);
1205 init_getch(win, flags, delay);
1209 x_getch_test(bool recur GCC_UNUSED)
1211 int delay = begin_getch_test();
1214 wget_wch_test(0, stdscr, delay);
1216 finish_getch_test();
1222 /****************************************************************************
1224 * Character attributes test
1226 ****************************************************************************/
1228 #if HAVE_SETUPTERM || HAVE_TGETENT
1229 #define get_ncv() TIGETNUM("ncv","NC")
1230 #define get_xmc() TIGETNUM("xmc","sg")
1232 #define get_ncv() -1
1233 #define get_xmc() -1
1240 static int first = TRUE;
1241 static chtype result = 0;
1247 char *area_pointer = parsed;
1249 tgetent(buffer, getenv("TERM"));
1252 if (TIGETSTR("smso", "so"))
1253 result |= A_STANDOUT;
1254 if (TIGETSTR("smul", "us"))
1255 result |= A_UNDERLINE;
1256 if (TIGETSTR("rev", "mr"))
1257 result |= A_REVERSE;
1258 if (TIGETSTR("blink", "mb"))
1260 if (TIGETSTR("dim", "mh"))
1262 if (TIGETSTR("bold", "md"))
1264 if (TIGETSTR("smacs", "ac"))
1265 result |= A_ALTCHARSET;
1271 #define termattrs() my_termattrs()
1274 #define ATTRSTRING_1ST 32 /* ' ' */
1275 #define ATTRSTRING_END 126 /* '~' */
1277 #define COLS_PRE_ATTRS 5
1278 #define COLS_AFT_ATTRS 15
1279 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1280 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1281 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1283 static char attr_test_string[MAX_ATTRSTRING + 1];
1286 attr_legend(WINDOW *helpwin)
1291 MvWPrintw(helpwin, row++, col,
1293 MvWPrintw(helpwin, row++, col,
1296 MvWPrintw(helpwin, row++, col,
1297 "Modify the test strings:");
1298 MvWPrintw(helpwin, row++, col,
1299 " A digit sets gaps on each side of displayed attributes");
1300 MvWPrintw(helpwin, row++, col,
1301 " </> shifts the text left/right. ");
1303 MvWPrintw(helpwin, row++, col,
1306 MvWPrintw(helpwin, row++, col,
1307 " f/F/b/B toggle foreground/background background color");
1308 MvWPrintw(helpwin, row++, col,
1309 " t/T toggle text/background color attribute");
1311 MvWPrintw(helpwin, row++, col,
1312 " a/A toggle ACS (alternate character set) mapping");
1313 MvWPrintw(helpwin, row, col,
1314 " v/V toggle video attribute to combine with each line");
1315 #if USE_WIDEC_SUPPORT
1316 MvWPrintw(helpwin, row, col,
1317 " w/W toggle normal/wide (double-width) test-characters");
1322 show_color_attr(int fg, int bg, int tx)
1325 printw(" Colors (fg %d, bg %d", fg, bg);
1327 printw(", text %d", tx);
1333 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1340 *fg = (NCURSES_COLOR_T) (*fg + 1);
1343 *fg = (NCURSES_COLOR_T) (*fg - 1);
1346 *bg = (NCURSES_COLOR_T) (*bg + 1);
1349 *bg = (NCURSES_COLOR_T) (*bg - 1);
1352 *tx = (NCURSES_COLOR_T) (*tx + 1);
1355 *tx = (NCURSES_COLOR_T) (*tx - 1);
1363 *fg = (NCURSES_COLOR_T) MinColors;
1364 if (*fg < MinColors)
1365 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1367 *bg = (NCURSES_COLOR_T) MinColors;
1368 if (*bg < MinColors)
1369 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1373 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1382 adjust_attr_string(int adjust)
1384 char save = attr_test_string[0];
1385 int first = ((int) UChar(save)) + adjust;
1388 if (first >= ATTRSTRING_1ST) {
1389 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1390 if (k > ATTRSTRING_END)
1392 attr_test_string[j] = (char) k;
1393 if (((k + 1 - first) % 5) == 0) {
1394 if (++j >= MAX_ATTRSTRING)
1396 attr_test_string[j] = ' ';
1399 if ((LEN_ATTRSTRING - j) > 5) {
1400 attr_test_string[0] = save;
1401 adjust_attr_string(adjust - 1);
1403 while (j < MAX_ATTRSTRING)
1404 attr_test_string[j++] = ' ';
1405 attr_test_string[j] = '\0';
1411 * Prefer the right-end of the string for starting, since that maps to the
1412 * VT100 line-drawing.
1415 default_attr_string(void)
1417 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1418 result += (LEN_ATTRSTRING / 5);
1419 if (result < ATTRSTRING_1ST)
1420 result = ATTRSTRING_1ST;
1425 init_attr_string(void)
1427 attr_test_string[0] = (char) default_attr_string();
1428 adjust_attr_string(0);
1432 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1434 int ncv = get_ncv();
1435 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1438 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1439 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1440 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1442 printw("%*s", skip, " ");
1444 * Just for testing, write text using the alternate character set one
1445 * character at a time (to pass its rendition directly), and use the
1446 * string operation for the other attributes.
1450 if (attr & A_ALTCHARSET) {
1454 for (s = attr_test_string; *s != '\0'; ++s) {
1456 (void) waddch(win, ch | attr);
1459 (void) wattrset(win, AttrArg(attr, 0));
1460 (void) waddstr(win, attr_test_string);
1461 (void) wattroff(win, (int) attr);
1464 printw("%*s", skip, " ");
1465 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1466 if (test != A_NORMAL) {
1467 if (!(termattrs() & test)) {
1470 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1471 static const chtype table[] =
1490 for (n = 0; n < SIZEOF(table); n++) {
1491 if ((table[n] & attr) != 0
1492 && ((1 << n) & ncv) != 0) {
1500 if ((termattrs() & test) != test) {
1510 NCURSES_CONST char *name;
1513 static const ATTR_TBL attrs_to_test[] = {
1514 { A_STANDOUT, "STANDOUT" },
1515 { A_REVERSE, "REVERSE" },
1517 { A_UNDERLINE, "UNDERLINE" },
1519 { A_BLINK, "BLINK" },
1520 { A_PROTECT, "PROTECT" },
1522 { A_INVIS, "INVISIBLE" },
1525 { A_ITALIC, "ITALIC" },
1527 { A_NORMAL, "NORMAL" },
1532 init_attr_list(ATTR_TBL * target, attr_t attrs)
1534 unsigned result = 0;
1537 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1538 attr_t test = attrs_to_test[n].attr;
1539 if (test == A_NORMAL || (test & attrs) != 0) {
1540 target[result++] = attrs_to_test[n];
1546 #if USE_WIDEC_SUPPORT
1549 NCURSES_CONST char *name;
1552 static const W_ATTR_TBL w_attrs_to_test[] = {
1553 { WA_STANDOUT, "STANDOUT" },
1554 { WA_REVERSE, "REVERSE" },
1555 { WA_BOLD, "BOLD" },
1556 { WA_UNDERLINE, "UNDERLINE" },
1558 { WA_BLINK, "BLINK" },
1559 { WA_PROTECT, "PROTECT" },
1561 { WA_INVIS, "INVISIBLE" },
1564 { WA_ITALIC, "ITALIC" },
1566 { WA_NORMAL, "NORMAL" },
1571 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1573 unsigned result = 0;
1576 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1577 attr_t test = w_attrs_to_test[n].attr;
1578 if (test == WA_NORMAL || (test & attrs) != 0) {
1579 target[result++] = w_attrs_to_test[n];
1587 attr_getc(int *skip,
1588 NCURSES_COLOR_T *fg,
1589 NCURSES_COLOR_T *bg,
1590 NCURSES_COLOR_T *tx,
1603 if (ch < 256 && isdigit(ch)) {
1611 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1613 attr_legend(helpwin);
1636 adjust_attr_string(-1);
1639 adjust_attr_string(1);
1645 error = cycle_color_attr(ch, fg, bg, tx);
1654 attr_test(bool recur GCC_UNUSED)
1655 /* test text attributes */
1658 int skip = get_xmc();
1659 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1660 NCURSES_COLOR_T bg = COLOR_BLACK;
1661 NCURSES_COLOR_T tx = -1;
1664 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1665 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1666 unsigned my_size = init_attr_list(my_list, termattrs());
1669 for (j = 0; j < my_size; ++j) {
1670 my_wins[j] = subwin(stdscr,
1672 2 + (int) (2 * j), COL_ATTRSTRING);
1673 scrollok(my_wins[j], FALSE);
1679 n = skip; /* make it easy */
1685 chtype normal = A_NORMAL | BLANK;
1686 chtype extras = (chtype) ac;
1689 NCURSES_PAIRS_T pair = 0;
1690 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1692 if (init_pair(pair, fg, bg) == ERR) {
1695 normal |= (chtype) COLOR_PAIR(pair);
1700 if (init_pair(pair, tx, bg) == ERR) {
1703 extras |= (chtype) COLOR_PAIR(pair);
1713 MvAddStr(0, 20, "Character attribute test display");
1715 for (j = 0; j < my_size; ++j) {
1716 bool arrow = (j == k);
1717 row = show_attr(my_wins[j], row, n, arrow,
1725 MvPrintw(row, COLS_PRE_ATTRS,
1726 "This terminal does %shave the magic-cookie glitch",
1727 get_xmc() > -1 ? "" : "not ");
1728 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1729 show_color_attr(fg, bg, tx);
1730 printw(" ACS (%d)", ac != 0);
1733 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1735 bkgdset(A_NORMAL | BLANK);
1740 Cannot("does not support video attributes.");
1745 #if USE_WIDEC_SUPPORT
1746 static bool use_fullwidth;
1747 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1749 #define FULL_LO 0xff00
1750 #define FULL_HI 0xff5e
1751 #define HALF_LO 0x20
1753 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1754 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1755 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1758 * Returns an ASCII code in [32..126]
1761 normal_wchar(int ch)
1763 wchar_t result = (wchar_t) ch;
1764 if (isFullWidth(ch))
1765 result = ToNormalWidth(ch);
1770 * Returns either an ASCII code in in [32..126] or full-width in
1771 * [0xff00..0xff5e], according to use_fullwidth setting.
1774 target_wchar(int ch)
1776 wchar_t result = (wchar_t) ch;
1777 if (use_fullwidth) {
1778 if (!isFullWidth(ch))
1779 result = ToFullWidth(ch);
1781 if (isFullWidth(ch))
1782 result = ToNormalWidth(ch);
1788 wide_adjust_attr_string(int adjust)
1790 wchar_t save = wide_attr_test_string[0];
1791 int first = ((int) normal_wchar(save)) + adjust;
1794 if (first >= ATTRSTRING_1ST) {
1795 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1796 if (k > ATTRSTRING_END)
1798 wide_attr_test_string[j] = target_wchar(k);
1799 if (((k + 1 - first) % 5) == 0) {
1800 if (++j >= MAX_ATTRSTRING)
1802 wide_attr_test_string[j] = ' ';
1805 if ((LEN_ATTRSTRING - j) > 5) {
1806 wide_attr_test_string[0] = save;
1807 wide_adjust_attr_string(adjust - 1);
1809 while (j < MAX_ATTRSTRING)
1810 wide_attr_test_string[j++] = ' ';
1811 wide_attr_test_string[j] = '\0';
1817 wide_init_attr_string(void)
1819 use_fullwidth = FALSE;
1820 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1821 wide_adjust_attr_string(0);
1825 set_wide_background(NCURSES_PAIRS_T pair)
1832 setcchar(&normal, blank, A_NORMAL, pair, 0);
1838 get_wide_background(void)
1840 attr_t result = WA_NORMAL;
1843 NCURSES_PAIRS_T pair;
1844 wchar_t wch[CCHARW_MAX];
1846 memset(&ch, 0, sizeof(ch));
1847 if (getbkgrnd(&ch) != ERR) {
1848 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1856 wide_show_attr(WINDOW *win,
1861 NCURSES_PAIRS_T pair,
1864 int ncv = get_ncv();
1865 attr_t test = attr & ~WA_ALTCHARSET;
1868 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1869 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1870 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1872 printw("%*s", skip, " ");
1875 * Just for testing, write text using the alternate character set one
1876 * character at a time (to pass its rendition directly), and use the
1877 * string operation for the other attributes.
1881 if (attr & WA_ALTCHARSET) {
1885 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1889 setcchar(&ch, fill, attr, pair, 0);
1890 (void) wadd_wch(win, &ch);
1893 attr_t old_attr = 0;
1894 NCURSES_PAIRS_T old_pair = 0;
1896 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1897 (void) wattr_set(win, attr, pair, 0);
1898 (void) waddwstr(win, wide_attr_test_string);
1899 (void) wattr_set(win, old_attr, old_pair, 0);
1902 printw("%*s", skip, " ");
1903 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1904 if (test != A_NORMAL) {
1905 if (!(term_attrs() & test)) {
1908 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1909 static const attr_t table[] =
1923 for (n = 0; n < SIZEOF(table); n++) {
1924 if ((table[n] & attr) != 0
1925 && ((1 << n) & ncv) != 0) {
1933 if ((term_attrs() & test) != test) {
1942 wide_attr_getc(int *skip,
1943 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1944 NCURSES_COLOR_T *tx, int *ac,
1945 unsigned *kc, unsigned limit)
1955 if (ch < 256 && isdigit(ch)) {
1963 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1964 box_set(helpwin, 0, 0);
1965 attr_legend(helpwin);
1988 use_fullwidth = FALSE;
1989 wide_adjust_attr_string(0);
1992 use_fullwidth = TRUE;
1993 wide_adjust_attr_string(0);
1996 wide_adjust_attr_string(-1);
1999 wide_adjust_attr_string(1);
2005 error = cycle_color_attr(ch, fg, bg, tx);
2014 x_attr_test(bool recur GCC_UNUSED)
2015 /* test text attributes using wide-character calls */
2018 int skip = get_xmc();
2019 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2020 NCURSES_COLOR_T bg = COLOR_BLACK;
2021 NCURSES_COLOR_T tx = -1;
2024 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2025 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2026 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2029 for (j = 0; j < my_size; ++j) {
2030 my_wins[j] = subwin(stdscr,
2032 2 + (int) (2 * j), COL_ATTRSTRING);
2033 scrollok(my_wins[j], FALSE);
2039 n = skip; /* make it easy */
2041 wide_init_attr_string();
2045 NCURSES_PAIRS_T pair = 0;
2046 NCURSES_PAIRS_T extras = 0;
2049 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2052 if (init_pair(pair, fg, bg) == ERR) {
2059 if (init_pair(extras, tx, bg) == ERR) {
2064 set_wide_background(pair);
2067 box_set(stdscr, 0, 0);
2068 MvAddStr(0, 20, "Character attribute test display");
2070 for (j = 0; j < my_size; ++j) {
2071 row = wide_show_attr(my_wins[j], row, n, (j == k),
2079 MvPrintw(row, COLS_PRE_ATTRS,
2080 "This terminal does %shave the magic-cookie glitch",
2081 get_xmc() > -1 ? "" : "not ");
2082 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2083 show_color_attr(fg, bg, tx);
2084 printw(" ACS (%d)", ac != 0);
2087 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2089 set_wide_background(0);
2094 Cannot("does not support extended video attributes.");
2100 /****************************************************************************
2102 * Color support tests
2104 ****************************************************************************/
2106 static NCURSES_CONST char *the_color_names[] =
2127 show_color_name(int y, int x, int color, bool wide)
2129 if (move(y, x) != ERR) {
2134 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2137 } else if (color >= 8) {
2138 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2140 } else if (color < 0) {
2141 _nc_STRCPY(temp, "default", sizeof(temp));
2143 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2144 "%.*s", 16, the_color_names[color]);
2146 printw("%-*.*s", width, width, temp);
2151 color_legend(WINDOW *helpwin, bool wide)
2156 MvWPrintw(helpwin, row++, col,
2159 MvWPrintw(helpwin, row++, col,
2160 "Use up/down arrow to scroll through the display if it is");
2161 MvWPrintw(helpwin, row++, col,
2162 "longer than one screen. Control/N and Control/P can be used");
2163 MvWPrintw(helpwin, row++, col,
2164 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2165 MvWPrintw(helpwin, row++, col,
2166 "full screen; control/B and control/F can be used here.");
2168 MvWPrintw(helpwin, row++, col,
2170 MvWPrintw(helpwin, row++, col,
2171 " a/A toggle altcharset off/on");
2172 MvWPrintw(helpwin, row++, col,
2173 " b/B toggle bold off/on");
2175 MvWPrintw(helpwin, row++, col,
2176 " c/C cycle used-colors through 8,16,...,COLORS");
2178 MvWPrintw(helpwin, row++, col,
2179 " n/N toggle text/number on/off");
2180 MvWPrintw(helpwin, row++, col,
2181 " r/R toggle reverse on/off");
2182 MvWPrintw(helpwin, row++, col,
2183 " w/W toggle width between 8/16 colors");
2184 #if USE_WIDEC_SUPPORT
2186 MvWPrintw(helpwin, row++, col,
2187 "Wide characters:");
2188 MvWPrintw(helpwin, row, col,
2189 " x/X toggle text between ASCII and wide-character");
2196 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2199 color_cycle(int current, int step)
2201 int result = current;
2207 if ((result * 2) > COLORS) {
2210 while ((result * 2) < current) {
2216 if (current >= COLORS) {
2221 if (result > COLORS)
2227 /* generate a color test pattern */
2229 color_test(bool recur GCC_UNUSED)
2234 int grid_top = top + 3;
2235 int page_size = (LINES - grid_top);
2237 int colors_max = COLORS;
2244 bool opt_acsc = FALSE;
2245 bool opt_bold = FALSE;
2246 bool opt_revs = FALSE;
2247 bool opt_nums = FALSE;
2248 bool opt_wide = FALSE;
2252 Cannot("does not support color.");
2256 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2257 done = ((COLS < 16) || (numbered == 0));
2260 * Because the number of colors is usually a power of two, we also use
2261 * a power of two for the number of colors shown per line (to be tidy).
2263 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2267 double colors_max2 = (double) colors_max * (double) colors_max;
2269 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2270 if (colors_max2 <= COLOR_PAIRS) {
2271 int limit = (colors_max - MinColors) * (colors_max - MinColors);
2272 if (pairs_max > limit)
2275 if (pairs_max < COLOR_PAIRS)
2276 pairs_max = COLOR_PAIRS;
2278 /* this assumes an 80-column line */
2282 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2286 per_row = (col_limit / 8);
2288 per_row -= MinColors;
2290 row_limit = (pairs_max + per_row - 1) / per_row;
2293 (void) printw("There are %d color pairs and %d colors",
2295 if (colors_max != COLORS)
2296 (void) printw(" (using %d colors)", colors_max);
2298 (void) addstr(" besides 'default'");
2301 MvPrintw(top + 1, 0,
2302 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2305 opt_bold ? "on" : "off");
2307 /* show color names/numbers across the top */
2308 for (i = 0; i < per_row; i++)
2309 show_color_name(top + 2, (i + 1) * width, i + MinColors, opt_wide);
2311 /* show a grid of colors, with color names/ numbers on the left */
2312 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2313 int row = grid_top + (i / per_row) - base_row;
2314 int col = (i % per_row + 1) * width;
2315 NCURSES_PAIRS_T pair = i;
2317 if ((i / per_row) > row_limit)
2320 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - MinColors)) + MinColors)
2321 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - MinColors)) + MinColors)
2322 if (row >= 0 && move(row, col) != ERR) {
2323 NCURSES_COLOR_T fg = InxToFG(i);
2324 NCURSES_COLOR_T bg = InxToBG(i);
2326 init_pair(pair, fg, bg);
2327 attron(COLOR_PAIR(pair));
2329 attron(A_ALTCHARSET);
2336 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2340 printw("%-*.*s", width, width, hello);
2341 (void) attrset(A_NORMAL);
2343 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2344 show_color_name(row, 0, InxToBG(i), opt_wide);
2352 switch (wGetchar(stdscr)) {
2366 colors_max = color_cycle(colors_max, -1);
2369 colors_max = color_cycle(colors_max, 1);
2387 set_color_test(opt_wide, FALSE);
2390 set_color_test(opt_wide, TRUE);
2394 if (base_row <= 0) {
2402 if (base_row + page_size >= row_limit) {
2411 if (base_row <= 0) {
2414 base_row -= (page_size - 1);
2422 if (base_row + page_size >= row_limit) {
2425 base_row += page_size - 1;
2426 if (base_row + page_size >= row_limit) {
2427 base_row = row_limit - page_size - 1;
2432 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2434 color_legend(helpwin, FALSE);
2452 #if USE_WIDEC_SUPPORT
2453 /* generate a color test pattern */
2455 x_color_test(bool recur GCC_UNUSED)
2460 int grid_top = top + 3;
2461 int page_size = (LINES - grid_top);
2462 int pairs_max = (unsigned short) (-1);
2463 int colors_max = COLORS;
2470 bool opt_acsc = FALSE;
2471 bool opt_bold = FALSE;
2472 bool opt_revs = FALSE;
2473 bool opt_wide = FALSE;
2474 bool opt_nums = FALSE;
2475 bool opt_xchr = FALSE;
2476 wchar_t *buffer = 0;
2480 Cannot("does not support color.");
2483 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2484 buffer = (wchar_t *) calloc((size_t) (COLS + 1), sizeof(wchar_t));
2485 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2488 * Because the number of colors is usually a power of two, we also use
2489 * a power of two for the number of colors shown per line (to be tidy).
2491 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2495 double colors_max2 = (double) colors_max * (double) colors_max;
2497 pairs_max = ((unsigned) (-1)) / 2;
2498 if (colors_max2 <= COLOR_PAIRS) {
2499 int limit = (colors_max - MinColors) * (colors_max - MinColors);
2500 if (pairs_max > limit)
2503 if (pairs_max > COLOR_PAIRS)
2504 pairs_max = COLOR_PAIRS;
2509 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2513 per_row = (col_limit / 8);
2515 per_row -= MinColors;
2518 make_fullwidth_text(buffer, hello);
2522 make_narrow_text(buffer, hello);
2525 row_limit = (pairs_max + per_row - 1) / per_row;
2528 (void) printw("There are %d color pairs and %d colors",
2530 if (colors_max != COLORS)
2531 (void) printw(" (using %d colors)", colors_max);
2533 (void) addstr(" besides 'default'");
2536 MvPrintw(top + 1, 0,
2537 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2540 opt_bold ? "on" : "off");
2542 /* show color names/numbers across the top */
2543 for (i = 0; i < per_row; i++)
2544 show_color_name(top + 2, (i + 1) * width, i + MinColors, opt_wide);
2546 /* show a grid of colors, with color names/ numbers on the left */
2547 for (i = (base_row * per_row); i < pairs_max; i++) {
2548 int row = grid_top + (i / per_row) - base_row;
2549 int col = (i % per_row + 1) * width;
2550 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2552 if ((i / per_row) > row_limit)
2555 if (row >= 0 && move(row, col) != ERR) {
2556 init_pair(pair, InxToFG(i), InxToBG(i));
2557 (void) color_set(pair, NULL);
2559 attr_on(WA_ALTCHARSET, NULL);
2561 attr_on(WA_BOLD, NULL);
2563 attr_on(WA_REVERSE, NULL);
2566 _nc_SPRINTF(numbered,
2567 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2570 make_fullwidth_text(buffer, numbered);
2572 make_narrow_text(buffer, numbered);
2575 addnwstr(buffer, width);
2576 (void) attr_set(A_NORMAL, 0, NULL);
2578 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2579 show_color_name(row, 0, InxToBG(i), opt_wide);
2587 switch (wGetchar(stdscr)) {
2601 colors_max = color_cycle(colors_max, -1);
2604 colors_max = color_cycle(colors_max, 1);
2622 set_color_test(opt_wide, FALSE);
2625 set_color_test(opt_wide, TRUE);
2635 if (base_row <= 0) {
2643 if (base_row + page_size >= row_limit) {
2652 if (base_row <= 0) {
2655 base_row -= (page_size - 1);
2663 if (base_row + page_size >= row_limit) {
2666 base_row += page_size - 1;
2667 if (base_row + page_size >= row_limit) {
2668 base_row = row_limit - page_size - 1;
2673 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2675 color_legend(helpwin, TRUE);
2693 #endif /* USE_WIDEC_SUPPORT */
2695 #if HAVE_COLOR_CONTENT
2697 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2699 NCURSES_COLOR_T red, green, blue;
2701 color_content(current, &red, &green, &blue);
2705 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2708 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2711 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2715 if (init_color(current, red, green, blue) == ERR)
2720 reset_all_colors(void)
2724 for (c = 0; c < COLORS; ++c)
2727 all_colors[c].green,
2728 all_colors[c].blue);
2731 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2732 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2733 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2736 init_all_colors(bool xterm_colors, char *palette_file)
2739 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2741 failed("all_colors");
2742 for (cp = 0; cp < MaxColors; ++cp) {
2744 &all_colors[cp].red,
2745 &all_colors[cp].green,
2746 &all_colors[cp].blue);
2748 /* xterm and compatible terminals can read results of an OSC string
2749 * asking for the current color palette.
2754 char result[BUFSIZ];
2756 unsigned check_r, check_g, check_b;
2760 for (n = 0; n < MaxColors; ++n) {
2761 fprintf(stderr, "\033]4;%d;?\007", n);
2762 got = (int) read(0, result, sizeof(result) - 1);
2766 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2772 all_colors[n].red = DecodeRGB(check_r);
2773 all_colors[n].green = DecodeRGB(check_g);
2774 all_colors[n].blue = DecodeRGB(check_b);
2781 if (palette_file != 0) {
2782 FILE *fp = fopen(palette_file, "r");
2784 char buffer[BUFSIZ];
2785 int red, green, blue;
2788 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2789 if (sscanf(buffer, "scale:%d", &c) == 1) {
2791 } else if (sscanf(buffer, "%d:%d %d %d",
2800 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2801 all_colors[c].red = Scaled(red);
2802 all_colors[c].green = Scaled(green);
2803 all_colors[c].blue = Scaled(blue);
2811 #define scaled_rgb(n) ((255 * (n)) / 1000)
2814 color_edit(bool recur GCC_UNUSED)
2815 /* display the color test pattern, without trying to edit colors */
2819 int this_c, value, field;
2825 Cannot("does not support color.");
2827 } else if (!can_change_color()) {
2828 Cannot("has hardwired color values.");
2841 page_size = (LINES - 6);
2844 for (i = 0; i < MaxColors; i++)
2845 init_pair((NCURSES_PAIRS_T) i,
2846 (NCURSES_COLOR_T) COLOR_WHITE,
2847 (NCURSES_COLOR_T) i);
2849 MvPrintw(LINES - 2, 0, "Number: %d", value);
2852 NCURSES_COLOR_T red, green, blue;
2855 MvAddStr(0, 20, "Color RGB Value Editing");
2858 for (i = (NCURSES_COLOR_T) top_color;
2859 (i - top_color < page_size)
2860 && (i < MaxColors); i++) {
2863 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2864 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2865 (i == current ? '>' : ' '),
2866 (i < (int) SIZEOF(the_color_names)
2867 ? the_color_names[i] : numeric));
2868 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2870 (void) attrset(A_NORMAL);
2872 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2874 if (current == i && field == 0)
2876 printw("%04d", (int) red);
2877 if (current == i && field == 0)
2878 (void) attrset(A_NORMAL);
2880 if (current == i && field == 1)
2882 printw("%04d", (int) green);
2883 if (current == i && field == 1)
2884 (void) attrset(A_NORMAL);
2886 if (current == i && field == 2)
2888 printw("%04d", (int) blue);
2889 if (current == i && field == 2)
2890 (void) attrset(A_NORMAL);
2891 (void) attrset(A_NORMAL);
2892 printw(" ( %3d %3d %3d )",
2893 (int) scaled_rgb(red),
2894 (int) scaled_rgb(green),
2895 (int) scaled_rgb(blue));
2898 MvAddStr(LINES - 3, 0,
2899 "Use up/down to select a color, left/right to change fields.");
2900 MvAddStr(LINES - 2, 0,
2901 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2903 move(2 + current - top_color, 0);
2907 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2929 current -= (page_size - 1);
2936 if (current < (MaxColors - 1))
2937 current += (page_size - 1);
2944 current = (current == 0 ? (MaxColors - 1) : current - 1);
2949 current = (current == (MaxColors - 1) ? 0 : current + 1);
2954 field = (field == 2 ? 0 : field + 1);
2959 field = (field == 0 ? 2 : field - 1);
2972 value = value * 10 + (this_c - '0');
2976 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2980 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2984 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2989 P(" RGB Value Editing Help");
2991 P("You are in the RGB value editor. Use the arrow keys to select one of");
2992 P("the fields in one of the RGB triples of the current colors; the one");
2993 P("currently selected will be reverse-video highlighted.");
2995 P("To change a field, enter the digits of the new value; they are echoed");
2996 P("as entered. Finish by typing `='. The change will take effect instantly.");
2997 P("To increment or decrement a value, use the same procedure, but finish");
2998 P("with a `+' or `-'.");
3000 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3002 P("Press 'm' to invoke the top-level menu with the current color settings.");
3003 P("To quit, do ESC");
3012 for (i = 0; i < MaxColors; i++)
3013 init_pair((NCURSES_PAIRS_T) i,
3014 (NCURSES_COLOR_T) COLOR_WHITE,
3015 (NCURSES_COLOR_T) i);
3029 if (current >= MaxColors)
3030 current = MaxColors - 1;
3031 if (current < top_color)
3032 top_color = current;
3033 if (current - top_color >= page_size)
3034 top_color = current - (page_size - 1);
3036 MvPrintw(LINES - 1, 0, "Number: %d", value);
3039 (!isQuit(this_c, TRUE));
3044 * ncurses does not reset each color individually when calling endwin().
3051 #endif /* HAVE_COLOR_CONTENT */
3053 /****************************************************************************
3055 * Alternate character-set stuff
3057 ****************************************************************************/
3059 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3065 if ((*at_code += 1) >= limit)
3070 *at_code = limit - 1;
3079 *attr = list[*at_code].attr;
3083 #if USE_WIDEC_SUPPORT
3085 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3091 if ((*at_code += 1) >= limit)
3096 *at_code = limit - 1;
3105 *attr = list[*at_code].attr;
3111 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3113 bool result = FALSE;
3123 if ((*fg += 1) >= COLORS)
3131 if ((*bg += 1) >= COLORS)
3139 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3142 if (init_pair(*pair,
3143 (NCURSES_COLOR_T) *fg,
3144 (NCURSES_COLOR_T) *bg) == ERR) {
3153 /****************************************************************************
3155 * Soft-key label test
3157 ****************************************************************************/
3162 #define SLK_WORK (SLK_HELP + 3)
3167 static const char *table[] =
3169 "Available commands are:"
3171 ,"^L -- repaint this message and activate soft keys"
3172 ,"a/d -- activate/disable soft keys"
3173 ,"c -- set centered format for labels"
3174 ,"l -- set left-justified format for labels"
3175 ,"r -- set right-justified format for labels"
3176 ,"[12345678] -- set label; labels are numbered 1 through 8"
3177 ,"e -- erase stdscr (should not erase labels)"
3178 ,"s -- test scrolling of shortened screen"
3179 ,"v/V -- cycle through video attributes"
3181 ,"F/f/B/b -- cycle through foreground/background colors"
3183 ,"ESC -- return to main menu"
3185 ,"Note: if activating the soft keys causes your terminal to scroll up"
3186 ,"one line, your terminal auto-scrolls when anything is written to the"
3187 ,"last screen position. The ncurses code does not yet handle this"
3193 for (j = 0; j < SIZEOF(table); ++j) {
3201 call_slk_color(int fg, int bg)
3203 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3205 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3214 slk_test(bool recur GCC_UNUSED)
3215 /* exercise the soft keys */
3220 chtype attr = A_NORMAL;
3221 unsigned at_code = 0;
3223 int fg = COLOR_BLACK;
3224 int bg = COLOR_WHITE;
3225 NCURSES_PAIRS_T pair = 0;
3227 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3228 unsigned my_size = init_attr_list(my_list, termattrs());
3233 call_slk_color(fg, bg);
3243 MvAddStr(0, 20, "Soft Key Exerciser");
3258 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3259 while ((c = Getchar()) != 'Q' && (c != ERR))
3287 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3288 _nc_STRCPY(buf, "", sizeof(buf));
3289 if ((s = slk_label(c - '0')) != 0) {
3290 _nc_STRNCPY(buf, s, (size_t) 8);
3292 wGetstring(stdscr, buf, 8);
3293 slk_set((c - '0'), buf, fmt);
3302 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3304 wnoutrefresh(stdscr);
3309 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3316 if (cycle_colors(c, &fg, &bg, &pair)) {
3318 call_slk_color(fg, bg);
3328 } while (!isQuit(c = Getchar(), TRUE));
3337 #if USE_WIDEC_SUPPORT
3340 x_slk_test(bool recur GCC_UNUSED)
3341 /* exercise the soft keys */
3344 wchar_t buf[SLKLEN + 1];
3346 attr_t attr = WA_NORMAL;
3347 unsigned at_code = 0;
3348 int fg = COLOR_BLACK;
3349 int bg = COLOR_WHITE;
3350 NCURSES_PAIRS_T pair = 0;
3351 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3352 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3356 call_slk_color(fg, bg);
3363 attr_on(WA_BOLD, NULL);
3364 MvAddStr(0, 20, "Soft Key Exerciser");
3365 attr_off(WA_BOLD, NULL);
3379 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3380 while ((c = Getchar()) != 'Q' && (c != ERR))
3408 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3410 if ((s = slk_label(c - '0')) != 0) {
3411 char *temp = strdup(s);
3412 size_t used = strlen(temp);
3413 size_t want = SLKLEN;
3415 #ifndef state_unused
3420 while (want > 0 && used != 0) {
3421 const char *base = s;
3422 reset_mbytes(state);
3423 test = count_mbytes(base, 0, &state);
3424 if (test == (size_t) -1) {
3426 } else if (test > want) {
3429 reset_mbytes(state);
3430 trans_mbytes(buf, base, want, &state);
3436 wGet_wstring(stdscr, buf, SLKLEN);
3437 slk_wset((c - '0'), buf, fmt);
3448 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3449 call_slk_color(fg, bg);
3454 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3455 call_slk_color(fg, bg);
3458 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3460 wnoutrefresh(stdscr);
3464 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3465 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3471 if (cycle_colors(c, &fg, &bg, &pair)) {
3473 call_slk_color(fg, bg);
3483 } while (!isQuit(c = Getchar(), TRUE));
3492 #endif /* SLK_INIT */
3495 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3498 unsigned last = 255;
3504 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3509 for (code = first; code <= last; ++code) {
3510 int row = (int) (2 + (code / 16));
3511 int col = (int) (5 * (code % 16));
3512 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3513 for (count = 1; count < repeat; ++count) {
3514 AddCh(colored_chtype(code, attr, pair));
3521 * Show a slice of 32 characters, allowing those to be repeated up to the
3524 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3525 * terminal to perform functions. The remaining codes can be graphic.
3528 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3531 unsigned first = (unsigned) base;
3532 unsigned last = first + (unsigned) pagesize - 2;
3533 bool C1 = (first == 128);
3538 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3539 C1 ? "C1" : "GR", first, last);
3543 for (code = first; code <= last; code++) {
3545 int row = 2 + ((int) (code - first) % (pagesize / 2));
3546 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3548 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3549 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3553 nodelay(stdscr, TRUE);
3554 echochar(colored_chtype(code, attr, pair));
3556 /* (yes, this _is_ crude) */
3557 while ((reply = Getchar()) != ERR) {
3558 AddCh(UChar(reply));
3561 nodelay(stdscr, FALSE);
3563 } while (--count > 0);
3570 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3576 MvPrintw(0, 20, "Display of PC Character Codes");
3580 for (code = 0; code < 16; ++code) {
3581 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3583 for (code = 0; code < 256; code++) {
3585 int row = 3 + (int) (code / 16) + (code >= 128);
3586 int col = 8 + (int) (code % 16) * PC_COLS;
3587 if ((code % 16) == 0)
3588 MvPrintw(row, 0, "0x%02x:", code);
3599 * Skip the ones that do not work.
3603 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3606 } while (--count > 0);
3611 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3615 attr |= (attr_t) COLOR_PAIR(pair);
3619 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3624 colored_chtype(ACS_VLINE, attr, pair),
3625 colored_chtype(ACS_VLINE, attr, pair),
3626 colored_chtype(ACS_HLINE, attr, pair),
3627 colored_chtype(ACS_HLINE, attr, pair),
3628 colored_chtype(ACS_ULCORNER, attr, pair),
3629 colored_chtype(ACS_URCORNER, attr, pair),
3630 colored_chtype(ACS_LLCORNER, attr, pair),
3631 colored_chtype(ACS_LRCORNER, attr, pair));
3632 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3633 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3634 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3635 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3636 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3637 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3638 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3644 show_1_acs(int n, int repeat, const char *name, chtype code)
3646 const int height = 16;
3647 int row = 2 + (n % height);
3648 int col = (n / height) * COLS / 2;
3650 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3653 } while (--repeat > 0);
3658 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3659 /* display the ACS character set */
3663 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3667 MvAddStr(0, 20, "Display of the ACS Character Set");
3671 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3672 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3673 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3674 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3676 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3677 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3678 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3679 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3681 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3682 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3685 * HPUX's ACS definitions are broken here. Just give up.
3687 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3688 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3689 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3690 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3691 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3693 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3694 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3695 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3696 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3697 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3698 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3699 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3700 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3701 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3703 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3704 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3705 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3707 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3708 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3709 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3710 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3711 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3712 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3718 acs_test(bool recur GCC_UNUSED)
3722 char *term = getenv("TERM");
3723 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3726 chtype attr = A_NORMAL;
3729 int fg = COLOR_BLACK;
3730 int bg = COLOR_BLACK;
3731 unsigned at_code = 0;
3732 NCURSES_PAIRS_T pair = 0;
3733 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3734 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3735 unsigned my_size = init_attr_list(my_list, termattrs());
3743 ToggleAcs(last_show_acs, show_acs_chars);
3747 ToggleAcs(last_show_acs, show_pc_chars);
3752 if (pagesize == 32) {
3759 ToggleAcs(last_show_acs, show_box_chars);
3785 if (repeat < (COLS / 4))
3793 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3794 || cycle_colors(c, &fg, &bg, &pair)) {
3801 if (pagesize != 32) {
3802 show_256_chars(repeat, attr, pair);
3803 } else if (last_show_acs != 0) {
3804 last_show_acs(repeat, attr, pair);
3806 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3809 MvPrintw(LINES - 3, 0,
3810 "Note: ANSI terminals may not display C1 characters.");
3811 MvPrintw(LINES - 2, 0,
3812 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3815 MvPrintw(LINES - 1, 0,
3816 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3817 my_list[at_code].name,
3820 MvPrintw(LINES - 1, 0,
3821 "v/V cycles through video attributes (%s).",
3822 my_list[at_code].name);
3825 } while (!isQuit(c = Getchar(), TRUE));
3833 #if USE_WIDEC_SUPPORT
3835 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3841 TEST_CCHAR(src, count, {
3842 attr |= (test_attrs & A_ALTCHARSET);
3843 setcchar(dst, test_wch, attr, pair, NULL);
3853 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3854 * display. If there are no repeats, we could normally display 16 lines of 64
3855 * characters (1024 total). However, taking repeats and double-width cells
3856 * into account, use 256 characters for the page.
3859 show_paged_widechars(int base,
3864 NCURSES_PAIRS_T pair)
3866 int first = base * pagesize;
3867 int last = first + pagesize - 1;
3875 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3878 for (code = (wchar_t) first; (int) code <= last; code++) {
3879 int row = (2 + ((int) code - first) / per_line);
3880 int col = 5 * ((int) code % per_line);
3883 memset(&codes, 0, sizeof(codes));
3885 setcchar(&temp, codes, attr, pair, 0);
3887 if (wcwidth(code) == 0 && code != 0) {
3888 AddCh((chtype) space |
3889 (A_REVERSE ^ attr) |
3890 (attr_t) COLOR_PAIR(pair));
3893 for (count = 1; count < repeat; ++count) {
3900 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3904 int last = first + 31;
3908 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3911 for (code = (wchar_t) first; (int) code <= last; code++) {
3912 int row = 2 + ((code - first) % 16);
3913 int col = ((code - first) / 16) * COLS / 2;
3919 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
3920 "%3ld (0x%lx)", (long) code, (long) code);
3921 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3923 memset(&codes, 0, sizeof(codes));
3925 setcchar(&temp, codes, attr, pair, 0);
3929 * Give non-spacing characters something to combine with. If we
3930 * don't, they'll bunch up in a heap on the space after the ":".
3931 * Mark them with reverse-video to make them simpler to find on
3934 if (wcwidth(code) == 0) {
3935 AddCh((chtype) space |
3936 (A_REVERSE ^ attr) |
3937 (attr_t) COLOR_PAIR(pair));
3940 * This uses echo_wchar(), for comparison with the normal 'f'
3941 * test (and to make a test-case for echo_wchar()). The screen
3942 * may flicker because the erase() at the top of the function
3943 * is met by the builtin refresh() in echo_wchar().
3947 * The repeat-count may make text wrap - avoid that.
3949 getyx(stdscr, y, x);
3951 if (x >= col + (COLS / 2) - 2)
3953 } while (--count > 0);
3958 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3960 const int height = 16;
3961 int row = 2 + (n % height);
3962 int col = (n / height) * COLS / 2;
3964 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3965 while (--repeat >= 0) {
3971 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3974 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3975 /* display the wide-ACS character set */
3981 /*#define BOTH2(name) #name, &(name) */
3982 #define BOTH2(name) #name, MERGE_ATTR(name)
3986 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3990 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3991 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3992 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3993 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3995 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3996 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3997 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3998 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
4000 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4001 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4003 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4004 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4005 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4006 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4008 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4009 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4010 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4011 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4012 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4013 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4014 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4015 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4016 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4018 #ifdef CURSES_WACS_ARRAY
4019 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4020 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4021 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4023 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4024 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4025 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4026 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4027 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4028 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4034 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4035 /* display the wide-ACS character set */
4041 /*#define BOTH2(name) #name, &(name) */
4042 #define BOTH2(name) #name, MERGE_ATTR(name)
4046 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4050 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4051 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4052 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4053 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4055 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4056 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4057 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4058 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4060 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4061 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4063 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4064 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4065 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4066 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4068 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4069 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4070 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4071 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4072 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4073 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4074 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4075 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4076 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4078 #ifdef CURSES_WACS_ARRAY
4079 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4080 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4081 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4083 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4084 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4085 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4086 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4087 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4088 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4095 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4096 /* display the wide-ACS character set */
4102 /*#define BOTH2(name) #name, &(name) */
4103 #define BOTH2(name) #name, MERGE_ATTR(name)
4107 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4111 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4114 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4117 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4118 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4119 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4121 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4122 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4124 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4125 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4126 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4127 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4129 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4130 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4131 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4132 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4133 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4134 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4135 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4136 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4137 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4139 #ifdef CURSES_WACS_ARRAY
4140 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4141 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4142 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4144 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4145 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4146 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4147 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4148 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4149 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4156 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4159 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4166 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4171 MERGE_ATTR(0, WACS_VLINE),
4172 MERGE_ATTR(1, WACS_VLINE),
4173 MERGE_ATTR(2, WACS_HLINE),
4174 MERGE_ATTR(3, WACS_HLINE),
4175 MERGE_ATTR(4, WACS_ULCORNER),
4176 MERGE_ATTR(5, WACS_URCORNER),
4177 MERGE_ATTR(6, WACS_LLCORNER),
4178 MERGE_ATTR(7, WACS_LRCORNER));
4180 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4181 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4182 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4183 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4184 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4185 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4186 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4194 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4196 const int height = 16;
4197 int row = 2 + (n % height);
4198 int col = (n / height) * COLS / 2;
4201 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4202 (void) attr_set(attr, pair, 0);
4203 _nc_STRNCPY(temp, code, 20);
4205 (void) attr_set(A_NORMAL, 0, 0);
4209 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4212 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4219 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4223 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4224 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4225 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4226 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4228 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4229 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4230 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4231 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4233 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4234 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4236 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4237 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4238 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4239 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4241 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4242 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4243 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4244 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4245 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4246 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4247 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4248 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4249 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4250 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4251 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4252 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4254 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4255 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4256 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4257 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4258 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4259 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4264 /* display the wide-ACS character set */
4266 x_acs_test(bool recur GCC_UNUSED)
4273 attr_t attr = WA_NORMAL;
4274 int fg = COLOR_BLACK;
4275 int bg = COLOR_BLACK;
4276 unsigned at_code = 0;
4277 NCURSES_PAIRS_T pair = 0;
4278 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4279 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4280 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4288 ToggleAcs(last_show_wacs, show_wacs_chars);
4292 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4297 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4301 if (pagesize == 32) {
4308 ToggleAcs(last_show_wacs, show_wbox_chars);
4311 ToggleAcs(last_show_wacs, show_utf8_chars);
4314 if (c < 256 && isdigit(c)) {
4317 } else if (c == '+') {
4320 } else if (c == '-' && digit > 0) {
4323 } else if (c == '>' && repeat < (COLS / 4)) {
4325 } else if (c == '<' && repeat > 1) {
4327 } else if (c == '_') {
4328 space = (space == ' ') ? '_' : ' ';
4330 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4331 || cycle_colors(c, &fg, &bg, &pair)) {
4332 if (last_show_wacs != 0)
4340 if (pagesize != 32) {
4341 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4342 } else if (last_show_wacs != 0) {
4343 last_show_wacs(repeat, attr, pair);
4345 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4348 MvPrintw(LINES - 4, 0,
4349 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
4350 MvPrintw(LINES - 3, 2,
4351 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4353 MvPrintw(LINES - 2, 2,
4354 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4355 my_list[at_code].name,
4358 MvPrintw(LINES - 2, 2,
4359 "v/V cycles through video attributes (%s).",
4360 my_list[at_code].name);
4363 } while (!isQuit(c = Getchar(), TRUE));
4374 * Graphic-rendition test (adapted from vttest)
4377 sgr_attr_test(bool recur GCC_UNUSED)
4381 for (pass = 0; pass < 2; pass++) {
4382 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4384 /* Use non-default colors if possible to exercise bce a little */
4386 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4387 normal |= (chtype) COLOR_PAIR(1);
4391 MvPrintw(1, 20, "Graphic rendition test pattern:");
4393 MvPrintw(4, 1, "vanilla");
4395 #define set_sgr(mask) bkgdset((normal^(mask)));
4397 MvPrintw(4, 40, "bold");
4399 set_sgr(A_UNDERLINE);
4400 MvPrintw(6, 6, "underline");
4402 set_sgr(A_BOLD | A_UNDERLINE);
4403 MvPrintw(6, 45, "bold underline");
4406 MvPrintw(8, 1, "blink");
4408 set_sgr(A_BLINK | A_BOLD);
4409 MvPrintw(8, 40, "bold blink");
4411 set_sgr(A_UNDERLINE | A_BLINK);
4412 MvPrintw(10, 6, "underline blink");
4414 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4415 MvPrintw(10, 45, "bold underline blink");
4418 MvPrintw(12, 1, "negative");
4420 set_sgr(A_BOLD | A_REVERSE);
4421 MvPrintw(12, 40, "bold negative");
4423 set_sgr(A_UNDERLINE | A_REVERSE);
4424 MvPrintw(14, 6, "underline negative");
4426 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4427 MvPrintw(14, 45, "bold underline negative");
4429 set_sgr(A_BLINK | A_REVERSE);
4430 MvPrintw(16, 1, "blink negative");
4432 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4433 MvPrintw(16, 40, "bold blink negative");
4435 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4436 MvPrintw(18, 6, "underline blink negative");
4438 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4439 MvPrintw(18, 45, "bold underline blink negative");
4442 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4448 bkgdset(A_NORMAL | BLANK);
4454 /****************************************************************************
4456 * Windows and scrolling tester.
4458 ****************************************************************************/
4460 #define BOTLINES 4 /* number of line stolen from screen bottom */
4466 #define FRAME struct frame
4475 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4476 #if (NCURSES_VERSION_PATCH < 20070331)
4477 #define is_keypad(win) (win)->_use_keypad
4478 #define is_scrollok(win) (win)->_scroll
4481 #define is_keypad(win) FALSE
4482 #define is_scrollok(win) FALSE
4486 frame_win(FRAME * curp)
4488 return (curp != 0) ? curp->wind : stdscr;
4491 /* We need to know if these flags are actually set, so don't look in FRAME.
4492 * These names are known to work with SVr4 curses as well as ncurses. The
4493 * _use_keypad name does not work with Solaris 8.
4496 HaveKeypad(FRAME * curp)
4498 WINDOW *win = frame_win(curp);
4500 return is_keypad(win);
4504 HaveScroll(FRAME * curp)
4506 WINDOW *win = frame_win(curp);
4508 return is_scrollok(win);
4512 newwin_legend(FRAME * curp)
4514 #define DATA(num, name) { name, num }
4515 static const struct {
4519 DATA(0, "^C = create window"),
4520 DATA(0, "^N = next window"),
4521 DATA(0, "^P = previous window"),
4522 DATA(0, "^F = scroll forward"),
4523 DATA(0, "^B = scroll backward"),
4524 DATA(1, "^K = keypad(%s)"),
4525 DATA(2, "^S = scrollok(%s)"),
4526 DATA(0, "^W = save window"),
4527 DATA(0, "^R = restore window"),
4529 DATA(0, "^X = resize"),
4531 DATA(3, "^Q%s = exit")
4536 bool do_keypad = HaveKeypad(curp);
4537 bool do_scroll = HaveScroll(curp);
4541 for (n = 0; n < SIZEOF(legend); n++) {
4542 switch (legend[n].code) {
4544 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4547 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4548 legend[n].msg, do_keypad ? "yes" : "no");
4551 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4552 legend[n].msg, do_scroll ? "yes" : "no");
4555 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4556 legend[n].msg, do_keypad ? "/ESC" : "");
4559 x = getcurx(stdscr);
4560 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4567 transient(FRAME * curp, NCURSES_CONST char *msg)
4569 newwin_legend(curp);
4571 MvAddStr(LINES - 1, 0, msg);
4577 printw("%s characters are echoed, window should %sscroll.",
4578 HaveKeypad(curp) ? "Non-arrow" : "All other",
4579 HaveScroll(curp) ? "" : "not ");
4584 newwin_report(FRAME * curp)
4585 /* report on the cursor's current position, then restore it */
4587 WINDOW *win = frame_win(curp);
4591 transient(curp, (char *) 0);
4593 move(LINES - 1, COLS - 17);
4594 printw("Y = %2d X = %2d", y, x);
4602 selectcell(int uli, int ulj, int lri, int lrj)
4603 /* arrows keys move cursor, return location at current on non-arrow key */
4605 static pair res; /* result cell */
4606 int si = lri - uli + 1; /* depth of the select area */
4607 int sj = lrj - ulj + 1; /* width of the select area */
4608 int i = 0, j = 0; /* offsets into the select area */
4613 move(uli + i, ulj + j);
4614 newwin_report((FRAME *) 0);
4616 switch (Getchar()) {
4630 return ((pair *) 0);
4631 #ifdef NCURSES_MOUSE_VERSION
4637 if (event.y > uli && event.x > ulj) {
4658 outerbox(pair ul, pair lr, bool onoff)
4659 /* draw or erase a box *outside* the given pair of corners */
4661 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4662 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4663 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4664 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4665 move(ul.y - 1, ul.x);
4666 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4667 move(ul.y, ul.x - 1);
4668 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4669 move(lr.y + 1, ul.x);
4670 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4671 move(ul.y, lr.x + 1);
4672 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4677 /* Ask user for a window definition */
4684 addstr("Use arrows to move cursor, anything else to mark corner 1");
4686 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4687 return ((WINDOW *) 0);
4688 memcpy(&ul, tmp, sizeof(pair));
4689 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4692 addstr("Use arrows to move cursor, anything else to mark corner 2");
4694 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4696 return ((WINDOW *) 0);
4697 memcpy(&lr, tmp, sizeof(pair));
4699 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4701 outerbox(ul, lr, TRUE);
4713 newwin_move(FRAME * curp, int dy, int dx)
4715 WINDOW *win = frame_win(curp);
4719 getyx(win, cur_y, cur_x);
4720 getmaxyx(win, max_y, max_x);
4721 if ((cur_x += dx) < 0)
4723 else if (cur_x >= max_x)
4725 if ((cur_y += dy) < 0)
4727 else if (cur_y >= max_y)
4729 wmove(win, cur_y, cur_x);
4733 delete_framed(FRAME * fp, bool showit)
4738 fp->last->next = fp->next;
4739 fp->next->last = fp->last;
4747 np = (fp == fp->next) ? NULL : fp->next;
4754 scroll_test(bool recur GCC_UNUSED)
4755 /* Demonstrate windows */
4758 FRAME *current = (FRAME *) 0, *neww;
4760 #if HAVE_PUTWIN && HAVE_GETWIN
4764 #define DUMPFILE "screendump"
4766 #ifdef NCURSES_MOUSE_VERSION
4767 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4772 transient((FRAME *) 0, (char *) 0);
4775 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4776 failed("scroll_test");
4779 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4780 failed("scroll_test");
4785 if (current == 0) { /* First element, */
4786 neww->next = neww; /* so point it at itself */
4789 neww->next = current->next;
4790 neww->last = current;
4791 neww->last->next = neww;
4792 neww->next->last = neww;
4795 /* SVr4 curses sets the keypad on all newly-created windows to
4796 * false. Someone reported that PDCurses makes new windows inherit
4797 * this flag. Remove the following 'keypad()' call to test this
4799 keypad(current->wind, TRUE);
4800 current->do_keypad = HaveKeypad(current);
4801 current->do_scroll = HaveScroll(current);
4804 case CTRL('N'): /* go to next window */
4806 current = current->next;
4809 case CTRL('P'): /* go to previous window */
4811 current = current->last;
4814 case CTRL('F'): /* scroll current window forward */
4816 wscrl(frame_win(current), 1);
4819 case CTRL('B'): /* scroll current window backwards */
4821 wscrl(frame_win(current), -1);
4824 case CTRL('K'): /* toggle keypad mode for current */
4826 current->do_keypad = !current->do_keypad;
4827 keypad(current->wind, current->do_keypad);
4833 current->do_scroll = !current->do_scroll;
4834 scrollok(current->wind, current->do_scroll);
4838 #if HAVE_PUTWIN && HAVE_GETWIN
4839 case CTRL('W'): /* save and delete window */
4840 if ((current != 0) && (current == current->next)) {
4841 transient(current, "Will not save/delete ONLY window");
4843 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4844 transient(current, "Can't open screen dump file");
4846 int rc = putwin(frame_win(current), fp);
4850 current = delete_framed(current, TRUE);
4852 transient(current, "Can't write screen dump file");
4857 case CTRL('R'): /* restore window */
4858 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4859 transient(current, "Can't open screen dump file");
4861 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4863 neww->next = current ? current->next : 0;
4864 neww->last = current;
4865 if (neww->last != 0)
4866 neww->last->next = neww;
4867 if (neww->next != 0)
4868 neww->next->last = neww;
4870 neww->wind = getwin(fp);
4872 wrefresh(neww->wind);
4874 failed("scroll_test");
4882 case CTRL('X'): /* resize window */
4889 addstr("Use arrows to move cursor, anything else to mark new corner");
4892 getbegyx(current->wind, ul.y, ul.x);
4894 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4895 if (tmp == (pair *) 0) {
4900 getmaxyx(current->wind, lr.y, lr.x);
4903 outerbox(ul, lr, FALSE);
4904 wnoutrefresh(stdscr);
4906 /* strictly cosmetic hack for the test */
4907 getmaxyx(current->wind, my, mx);
4908 if (my > tmp->y - ul.y) {
4909 getyx(current->wind, lr.y, lr.x);
4910 wmove(current->wind, tmp->y - ul.y + 1, 0);
4911 wclrtobot(current->wind);
4912 wmove(current->wind, lr.y, lr.x);
4914 if (mx > tmp->x - ul.x)
4915 for (i = 0; i < my; i++) {
4916 wmove(current->wind, i, tmp->x - ul.x + 1);
4917 wclrtoeol(current->wind);
4919 wnoutrefresh(current->wind);
4921 memcpy(&lr, tmp, sizeof(pair));
4922 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4924 getbegyx(current->wind, ul.y, ul.x);
4925 getmaxyx(current->wind, lr.y, lr.x);
4928 outerbox(ul, lr, TRUE);
4929 wnoutrefresh(stdscr);
4931 wnoutrefresh(current->wind);
4937 #endif /* HAVE_WRESIZE */
4940 newwin_move(current, -1, 0);
4943 newwin_move(current, 1, 0);
4946 newwin_move(current, 0, -1);
4949 newwin_move(current, 0, 1);
4957 getyx(frame_win(current), y, x);
4961 x = getmaxx(frame_win(current)) - 1;
4963 (void) mvwdelch(frame_win(current), y, x);
4973 waddch(current->wind, (chtype) c);
4978 newwin_report(current);
4979 usescr = frame_win(current);
4982 (!isQuit(c = wGetchar(usescr), TRUE)
4986 while (current != 0)
4987 current = delete_framed(current, FALSE);
4989 scrollok(stdscr, TRUE); /* reset to driver's default */
4990 #ifdef NCURSES_MOUSE_VERSION
4991 mousemask(0, (mmask_t *) 0);
4999 /****************************************************************************
5003 ****************************************************************************/
5006 static int nap_msec = 1;
5008 static NCURSES_CONST char *mod[] =
5018 /*+-------------------------------------------------------------------------
5020 --------------------------------------------------------------------------*/
5022 wait_a_while(int msec GCC_UNUSED)
5032 else if (msec > 1000)
5033 sleep((unsigned) msec / 1000);
5037 } /* end of wait_a_while */
5039 /*+-------------------------------------------------------------------------
5041 --------------------------------------------------------------------------*/
5043 saywhat(NCURSES_CONST char *text)
5045 wmove(stdscr, LINES - 1, 0);
5047 if (text != 0 && *text != '\0') {
5048 waddstr(stdscr, text);
5049 waddstr(stdscr, "; ");
5051 waddstr(stdscr, "press any key to continue");
5052 } /* end of saywhat */
5054 /*+-------------------------------------------------------------------------
5055 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
5056 --------------------------------------------------------------------------*/
5058 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
5063 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
5064 if ((pan = new_panel(win)) == 0) {
5066 } else if (UseColors) {
5067 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
5070 NCURSES_COLOR_T bg = color;
5072 init_pair(color, fg, bg);
5073 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
5075 wbkgdset(win, A_BOLD | ' ');
5079 } /* end of mkpanel */
5081 /*+-------------------------------------------------------------------------
5083 --------------------------------------------------------------------------*/
5087 WINDOW *win = panel_window(pan);
5090 } /* end of rmpanel */
5092 /*+-------------------------------------------------------------------------
5094 --------------------------------------------------------------------------*/
5100 } /* end of pflush */
5102 /*+-------------------------------------------------------------------------
5104 --------------------------------------------------------------------------*/
5106 init_panel(WINDOW *win)
5110 for (y = 0; y < LINES - 1; y++) {
5111 for (x = 0; x < COLS; x++)
5112 wprintw(win, "%d", (y + x) % 10);
5117 fill_panel(PANEL *pan)
5119 WINDOW *win = panel_window(pan);
5120 const char *userptr = (const char *) panel_userptr(pan);
5121 int num = (userptr && *userptr) ? userptr[1] : '?';
5125 wprintw(win, "-pan%c-", num);
5128 for (y = 2; y < getmaxy(win) - 1; y++) {
5129 for (x = 1; x < getmaxx(win) - 1; x++) {
5131 waddch(win, UChar(num));
5136 #if USE_WIDEC_SUPPORT
5138 init_wide_panel(WINDOW *win)
5143 for (digit = 0; digit < 10; ++digit)
5144 make_fullwidth_digit(&temp[digit], digit);
5148 getyx(stdscr, y, x);
5149 digit = (y + x / 2) % 10;
5150 } while (wadd_wch(win, &temp[digit]) != ERR);
5154 fill_wide_panel(PANEL *pan)
5156 WINDOW *win = panel_window(pan);
5157 const char *userptr = (const char *) panel_userptr(pan);
5158 int num = (userptr && *userptr) ? userptr[1] : '?';
5162 wprintw(win, "-pan%c-", num);
5165 for (y = 2; y < getmaxy(win) - 1; y++) {
5166 for (x = 1; x < getmaxx(win) - 1; x++) {
5168 waddch(win, UChar(num));
5174 #define MAX_PANELS 5
5177 canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
5179 int which = cmd[1] - '0';
5184 hide_panel(px[which]);
5187 show_panel(px[which]);
5190 top_panel(px[which]);
5193 bottom_panel(px[which]);
5200 wait_a_while(nap_msec);
5204 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
5208 PANEL *px[MAX_PANELS + 1];
5210 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5214 for (count = 0; count < 5; count++) {
5215 px[1] = mkpanel(COLOR_RED,
5220 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
5222 px[2] = mkpanel(COLOR_GREEN,
5227 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5229 px[3] = mkpanel(COLOR_YELLOW,
5234 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5236 px[4] = mkpanel(COLOR_BLUE,
5241 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5243 px[5] = mkpanel(COLOR_MAGENTA,
5248 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5260 wait_a_while(nap_msec);
5262 saywhat("h3 s1 s2 s4 s5");
5263 move_panel(px[1], 0, 0);
5270 wait_a_while(nap_msec);
5272 canned_panel(px, "s1");
5273 canned_panel(px, "s2");
5276 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5278 wait_a_while(nap_msec);
5280 canned_panel(px, "s3");
5283 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5285 wait_a_while(nap_msec);
5287 canned_panel(px, "b3");
5288 canned_panel(px, "s4");
5289 canned_panel(px, "s5");
5290 canned_panel(px, "t3");
5291 canned_panel(px, "t1");
5292 canned_panel(px, "t2");
5293 canned_panel(px, "t3");
5294 canned_panel(px, "t4");
5296 for (itmp = 0; itmp < 6; itmp++) {
5297 WINDOW *w4 = panel_window(px[4]);
5298 WINDOW *w5 = panel_window(px[5]);
5301 wmove(w4, LINES / 8, 1);
5302 waddstr(w4, mod[itmp]);
5303 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5304 wmove(w5, LINES / 6, 1);
5305 waddstr(w5, mod[itmp]);
5307 wait_a_while(nap_msec);
5310 wmove(w4, LINES / 6, 1);
5311 waddstr(w4, mod[itmp]);
5312 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5313 wmove(w5, LINES / 8, 1);
5314 waddstr(w5, mod[itmp]);
5316 wait_a_while(nap_msec);
5320 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5322 wait_a_while(nap_msec);
5324 canned_panel(px, "t5");
5325 canned_panel(px, "t2");
5326 canned_panel(px, "t1");
5327 canned_panel(px, "d2");
5328 canned_panel(px, "h3");
5329 canned_panel(px, "d1");
5330 canned_panel(px, "d4");
5331 canned_panel(px, "d5");
5332 canned_panel(px, "d3");
5334 wait_a_while(nap_msec);
5347 panel_test(bool recur GCC_UNUSED)
5349 return demo_panels(init_panel, fill_panel);
5353 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
5355 x_panel_test(bool recur GCC_UNUSED)
5357 return demo_panels(init_wide_panel, fill_wide_panel);
5360 #endif /* USE_LIBPANEL */
5362 /****************************************************************************
5366 ****************************************************************************/
5370 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
5371 * though we can rely on negative x/y values to stop the macro.
5374 do_h_line(int y, int x, chtype c, int to)
5377 MvHLine(y, x, c, (to) - (x));
5381 do_v_line(int y, int x, chtype c, int to)
5384 MvVLine(y, x, c, (to) - (y));
5389 static bool pending_pan = FALSE;
5390 static bool show_panner_legend = TRUE;
5393 panner_legend(int line)
5395 static const char *const legend[] =
5397 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5398 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5399 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5400 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5402 int n = ((int) SIZEOF(legend) - (LINES - line));
5404 if (move(line, 0) != ERR) {
5405 if (show_panner_legend)
5406 printw("%s", legend[n]);
5408 return show_panner_legend;
5415 panner_h_cleanup(int from_y, int from_x, int to_x)
5417 if (!panner_legend(from_y))
5418 do_h_line(from_y, from_x, ' ', to_x);
5422 panner_v_cleanup(int from_y, int from_x, int to_y)
5424 if (!panner_legend(from_y))
5425 do_v_line(from_y, from_x, ' ', to_y);
5429 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5432 unsigned gridcount = 0;
5436 fill = (chtype) COLOR_PAIR(1);
5439 wmove(panpad, 0, 0);
5440 for (y = 0; y < getmaxy(panpad); y++) {
5441 for (x = 0; x < getmaxx(panpad); x++) {
5442 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5443 if (y == 0 && x == 0)
5444 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5446 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5447 else if (y == 0 || x == 0)
5448 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5450 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5451 (int) (gridcount++ % 26)) | fill);
5452 } else if (y % GRIDSIZE == 0)
5453 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5454 else if (x % GRIDSIZE == 0)
5455 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5457 waddch(panpad, ' ');
5464 int top_x, int top_y, int porty, int portx,
5465 int (*pgetc) (WINDOW *),
5468 #if HAVE_GETTIMEOFDAY
5469 struct timeval before, after;
5472 bool pan_lines = FALSE;
5473 bool scrollers = TRUE;
5476 int pxmax, pymax, lowend, highend, c;
5478 getmaxyx(pad, pymax, pxmax);
5479 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5483 #ifdef NCURSES_VERSION
5485 * During shell-out, the user may have resized the window. Adjust
5486 * the port size of the pad to accommodate this. Ncurses automatically
5487 * resizes all of the normal windows to fit on the new screen.
5504 if (c == HELP_KEY_1)
5505 show_panner_legend = !show_panner_legend;
5506 panner_legend(LINES - 4);
5507 panner_legend(LINES - 3);
5508 panner_legend(LINES - 2);
5509 panner_legend(LINES - 1);
5512 pan_lines = !pan_lines;
5513 fill_pad(pad, pan_lines, colored);
5514 pending_pan = FALSE;
5517 #if HAVE_GETTIMEOFDAY
5521 panner_legend(LINES - 1);
5525 scrollers = !scrollers;
5528 /* Move the top-left corner of the pad, keeping the bottom-right
5531 case 'h': /* increase-columns: move left edge to left */
5535 panner_v_cleanup(top_y, top_x, porty);
5540 case 'j': /* decrease-lines: move top-edge down */
5544 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5549 case 'k': /* increase-lines: move top-edge up */
5554 panner_h_cleanup(top_y, top_x, portx);
5558 case 'l': /* decrease-columns: move left-edge to right */
5562 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5567 /* Move the bottom-right corner of the pad, keeping the top-left
5570 case KEY_IC: /* increase-columns: move right-edge to right */
5571 if (portx >= pxmax || portx >= COLS)
5574 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5579 case KEY_IL: /* increase-lines: move bottom-edge down */
5580 if (porty >= pymax || porty >= LINES)
5583 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5588 case KEY_DC: /* decrease-columns: move bottom edge up */
5593 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5597 case KEY_DL: /* decrease-lines */
5602 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5606 case KEY_LEFT: /* pan leftwards */
5613 case KEY_RIGHT: /* pan rightwards */
5614 if (basex + portx - (pymax > porty) < pxmax)
5620 case KEY_UP: /* pan upwards */
5627 case KEY_DOWN: /* pan downwards */
5628 if (basey + porty - (pxmax > portx) < pymax)
5643 basey = pymax - porty;
5653 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5654 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5655 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5657 if (scrollers && (pxmax > portx - 1)) {
5658 int length = (portx - top_x - 1);
5659 float ratio = ((float) length) / ((float) pxmax);
5661 lowend = (int) ((float) top_x + ((float) basex * ratio));
5662 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5664 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5665 if (highend < portx) {
5667 do_h_line(porty - 1, lowend, ' ', highend + 1);
5669 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5672 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5674 if (scrollers && (pymax > porty - 1)) {
5675 int length = (porty - top_y - 1);
5676 float ratio = ((float) length) / ((float) pymax);
5678 lowend = (int) ((float) top_y + ((float) basey * ratio));
5679 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5681 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5682 if (highend < porty) {
5684 do_v_line(lowend, portx - 1, ' ', highend + 1);
5686 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5689 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5691 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5692 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5693 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5696 #if HAVE_GETTIMEOFDAY
5697 gettimeofday(&before, 0);
5699 wnoutrefresh(stdscr);
5704 porty - (pxmax > portx) - 1,
5705 portx - (pymax > porty) - 1);
5708 #if HAVE_GETTIMEOFDAY
5709 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5712 gettimeofday(&after, 0);
5713 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5714 move(LINES - 1, COLS - 12);
5715 printw("Secs: %2.03f", elapsed);
5722 ((c = pgetc(pad)) != KEY_EXIT);
5724 scrollok(stdscr, TRUE); /* reset to driver's default */
5728 padgetch(WINDOW *win)
5734 if ((pending_pan = (count > 0)) != FALSE) {
5736 pending_pan = (count != 0);
5739 switch (c = wGetchar(win)) {
5775 case ERR: /* FALLTHRU */
5781 if (c >= '0' && c <= '9') {
5782 count = count * 10 + (c - '0');
5796 #define PAD_HIGH 200
5797 #define PAD_WIDE 200
5800 pad_test(bool recur GCC_UNUSED)
5801 /* Demonstrate pads. */
5803 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5806 Cannot("cannot create requested pad");
5811 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5812 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5813 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5816 fill_pad(panpad, FALSE, TRUE);
5818 panner_legend(LINES - 4);
5819 panner_legend(LINES - 3);
5820 panner_legend(LINES - 2);
5821 panner_legend(LINES - 1);
5823 keypad(panpad, TRUE);
5825 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5826 * We'll still be able to widen it during a test, since that's required
5827 * for testing boundaries.
5829 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, TRUE);
5836 #endif /* HAVE_NEWPAD */
5838 /****************************************************************************
5840 * Tests from John Burnell's PDCurses tester
5842 ****************************************************************************/
5845 Continue(WINDOW *win)
5849 MvWAddStr(win, 10, 1, " Press any key to continue");
5855 flushinp_test(bool recur GCC_UNUSED)
5856 /* Input test, adapted from John Burnell's PDCurses tester */
5858 WINDOW *win = stdscr;
5859 int w, h, bx, by, sw, sh, i;
5864 getmaxyx(win, h, w);
5865 getbegyx(win, by, bx);
5868 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5873 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5874 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
5877 (void) wattrset(subWin, A_BOLD);
5878 box(subWin, ACS_VLINE, ACS_HLINE);
5879 MvWAddStr(subWin, 2, 1, "This is a subwindow");
5883 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5884 * it only happened to "work" on SVr4 because that implementation does not
5885 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5886 * test behavior, we're using 'cbreak()', which will allow a single
5887 * character to return without needing a newline. - T.Dickey 1997/10/11.
5890 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
5892 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
5893 MvWAddStr(win, 3, 1,
5894 "These should be discarded (not echoed) after the subwindow goes away.");
5897 for (i = 0; i < 5; i++) {
5898 MvWPrintw(subWin, 1, 1, "Time = %d", i);
5910 MvWAddStr(win, 2, 1,
5911 "If you were still typing when the window timer expired,");
5912 MvWAddStr(win, 3, 1,
5913 "or else you typed nothing at all while it was running,");
5914 MvWAddStr(win, 4, 1,
5915 "test was invalid. You'll see garbage or nothing at all. ");
5916 MvWAddStr(win, 6, 1, "Press a key");
5922 MvWAddStr(win, 12, 0,
5923 "If you see any key other than what you typed, flushinp() is broken.");
5932 "What you typed should now have been deleted; if not, wdelch() failed.");
5939 /****************************************************************************
5943 ****************************************************************************/
5951 menu_virtualize(int c)
5953 if (c == '\n' || c == KEY_EXIT)
5954 return (MAX_COMMAND + 1);
5956 return (REQ_SCR_ULINE);
5958 return (REQ_SCR_DLINE);
5959 else if (c == 'b' || c == KEY_NPAGE)
5960 return (REQ_SCR_UPAGE);
5961 else if (c == 'f' || c == KEY_PPAGE)
5962 return (REQ_SCR_DPAGE);
5963 else if (c == 'n' || c == KEY_DOWN)
5964 return (REQ_NEXT_ITEM);
5965 else if (c == 'p' || c == KEY_UP)
5966 return (REQ_PREV_ITEM);
5968 return (REQ_TOGGLE_ITEM);
5976 static CONST_MENUS char *animals[] =
5989 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5990 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5995 menu_test(bool recur GCC_UNUSED)
5998 ITEM *items[SIZEOF(animals)];
6000 CONST_MENUS char **ap;
6001 int mrows, mcols, c;
6004 #ifdef NCURSES_MOUSE_VERSION
6005 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6007 MvAddStr(0, 0, "This is the menu test:");
6008 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
6009 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
6011 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
6012 MvAddStr(5, 0, " Press return to exit.");
6015 for (ap = animals; *ap; ap++) {
6016 if ((*ip = new_item(*ap, "")) != 0)
6021 m = new_menu(items);
6023 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
6024 scale_menu(m, &mrows, &mcols);
6026 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6027 set_menu_win(m, menuwin);
6028 keypad(menuwin, TRUE);
6031 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6035 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
6036 if (c == E_NOT_POSTED)
6038 if (c == E_REQUEST_DENIED)
6043 MvPrintw(LINES - 2, 0,
6044 "You chose: %s\n", item_name(current_item(m)));
6045 (void) addstr("Press any key to continue...");
6052 for (ip = items; *ip; ip++)
6054 #ifdef NCURSES_MOUSE_VERSION
6055 mousemask(0, (mmask_t *) 0);
6061 #define T_TBL(name) { #name, name }
6067 T_TBL(TRACE_DISABLE),
6070 T_TBL(TRACE_UPDATE),
6072 T_TBL(TRACE_CHARPUT),
6073 T_TBL(TRACE_ORDINARY),
6075 T_TBL(TRACE_VIRTPUT),
6076 T_TBL(TRACE_IEVENT),
6078 T_TBL(TRACE_ICALLS),
6079 T_TBL(TRACE_CCALLS),
6080 T_TBL(TRACE_DATABASE),
6082 T_TBL(TRACE_MAXIMUM),
6089 tracetrace(unsigned tlevel)
6092 static size_t need = 12;
6096 for (n = 0; t_tbl[n].name != 0; n++)
6097 need += strlen(t_tbl[n].name) + 2;
6098 buf = typeMalloc(char, need);
6100 failed("tracetrace");
6102 _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
6104 _nc_STRCAT(buf, t_tbl[0].name, need);
6105 _nc_STRCAT(buf, ", ", need);
6107 for (n = 1; t_tbl[n].name != 0; n++)
6108 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
6109 _nc_STRCAT(buf, t_tbl[n].name, need);
6110 _nc_STRCAT(buf, ", ", need);
6113 if (buf[strlen(buf) - 2] == ',')
6114 buf[strlen(buf) - 2] = '\0';
6115 _nc_STRCAT(buf, "}", need);
6119 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
6123 run_trace_menu(MENU * m)
6129 bool changed = FALSE;
6130 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
6131 case E_UNKNOWN_COMMAND:
6134 items = menu_items(m);
6135 i = current_item(m);
6136 if (i == items[0]) {
6137 if (item_value(i)) {
6138 for (p = items + 1; *p != 0; p++)
6139 if (item_value(*p)) {
6140 set_item_value(*p, FALSE);
6145 for (p = items + 1; *p != 0; p++)
6146 if (item_value(*p)) {
6147 set_item_value(items[0], FALSE);
6159 trace_set(bool recur GCC_UNUSED)
6160 /* interactively set the trace level */
6163 ITEM *items[SIZEOF(t_tbl)];
6170 MvAddStr(0, 0, "Interactively set trace level:");
6171 MvAddStr(2, 0, " Press space bar to toggle a selection.");
6172 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
6173 MvAddStr(4, 0, " Press return to set the trace level.");
6174 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
6178 for (n = 0; t_tbl[n].name != 0; n++) {
6179 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
6185 m = new_menu(items);
6187 set_menu_format(m, 0, 2);
6188 scale_menu(m, &mrows, &mcols);
6190 menu_opts_off(m, O_ONEVALUE);
6191 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6192 set_menu_win(m, menuwin);
6193 keypad(menuwin, TRUE);
6196 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6200 for (ip = menu_items(m); *ip; ip++) {
6201 unsigned mask = t_tbl[item_index(*ip)].mask;
6203 set_item_value(*ip, _nc_tracing == 0);
6204 else if ((mask & _nc_tracing) == mask)
6205 set_item_value(*ip, TRUE);
6208 while (run_trace_menu(m))
6212 for (ip = menu_items(m); *ip; ip++)
6213 if (item_value(*ip))
6214 newtrace |= t_tbl[item_index(*ip)].mask;
6216 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
6218 MvPrintw(LINES - 2, 0,
6219 "Trace level is %s\n", tracetrace(_nc_tracing));
6220 (void) addstr("Press any key to continue...");
6227 for (ip = items; *ip; ip++)
6233 #endif /* USE_LIBMENU */
6235 /****************************************************************************
6239 ****************************************************************************/
6242 make_label(int frow, int fcol, NCURSES_CONST char *label)
6244 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
6247 set_field_buffer(f, 0, label);
6248 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
6254 make_field(int frow, int fcol, int rows, int cols, bool secure)
6256 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
6259 set_field_back(f, A_UNDERLINE);
6260 set_field_userptr(f, (void *) 0);
6266 display_form(FORM *f)
6271 scale_form(f, &rows, &cols);
6273 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6275 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6278 if (post_form(f) != E_OK)
6286 WINDOW *w = form_win(f);
6287 WINDOW *s = form_sub(f);
6297 edit_secure(FIELD *me, int c)
6299 int rows, cols, frow, fcol, nrow, nbuf;
6301 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6303 char *source = field_buffer(me, 1);
6304 size_t have = (source ? strlen(source) : 0) + 1;
6305 size_t need = 80 + have;
6306 char *temp = malloc(need);
6310 _nc_STRNCPY(temp, source ? source : "", have + 1);
6311 len = (size_t) (char *) field_userptr(me);
6313 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6314 temp[len++] = (char) c;
6316 set_field_buffer(me, 1, temp);
6336 case REQ_RIGHT_CHAR:
6338 c = 0; /* we don't want to do inline editing */
6343 set_field_buffer(me, 1, temp);
6350 set_field_buffer(me, 1, temp);
6355 set_field_userptr(me, (void *) len);
6363 form_virtualize(FORM *f, WINDOW *w)
6366 static const struct {
6370 { CTRL('A'), REQ_NEXT_CHOICE },
6371 { CTRL('B'), REQ_PREV_WORD },
6372 { CTRL('C'), REQ_CLR_EOL },
6373 { CTRL('D'), REQ_DOWN_FIELD },
6374 { CTRL('E'), REQ_END_FIELD },
6375 { CTRL('F'), REQ_NEXT_PAGE },
6376 { CTRL('G'), REQ_DEL_WORD },
6377 { CTRL('H'), REQ_DEL_PREV },
6378 { CTRL('I'), REQ_INS_CHAR },
6379 { CTRL('K'), REQ_CLR_EOF },
6380 { CTRL('L'), REQ_LEFT_FIELD },
6381 { CTRL('M'), REQ_NEW_LINE },
6382 { CTRL('N'), REQ_NEXT_FIELD },
6383 { CTRL('O'), REQ_INS_LINE },
6384 { CTRL('P'), REQ_PREV_FIELD },
6385 { CTRL('R'), REQ_RIGHT_FIELD },
6386 { CTRL('S'), REQ_BEG_FIELD },
6387 { CTRL('U'), REQ_UP_FIELD },
6388 { CTRL('V'), REQ_DEL_CHAR },
6389 { CTRL('W'), REQ_NEXT_WORD },
6390 { CTRL('X'), REQ_CLR_FIELD },
6391 { CTRL('Y'), REQ_DEL_LINE },
6392 { CTRL('Z'), REQ_PREV_CHOICE },
6393 { ESCAPE, MAX_FORM_COMMAND + 1 },
6394 { KEY_BACKSPACE, REQ_DEL_PREV },
6395 { KEY_DOWN, REQ_DOWN_CHAR },
6396 { KEY_END, REQ_LAST_FIELD },
6397 { KEY_HOME, REQ_FIRST_FIELD },
6398 { KEY_LEFT, REQ_LEFT_CHAR },
6399 { KEY_LL, REQ_LAST_FIELD },
6400 { KEY_NEXT, REQ_NEXT_FIELD },
6401 { KEY_NPAGE, REQ_NEXT_PAGE },
6402 { KEY_PPAGE, REQ_PREV_PAGE },
6403 { KEY_PREVIOUS, REQ_PREV_FIELD },
6404 { KEY_RIGHT, REQ_RIGHT_CHAR },
6405 { KEY_UP, REQ_UP_CHAR },
6406 { QUIT, MAX_FORM_COMMAND + 1 }
6410 static int mode = REQ_INS_MODE;
6411 int c = wGetchar(w);
6413 FIELD *me = current_field(f);
6414 bool current = TRUE;
6416 if (c == CTRL(']')) {
6417 if (mode == REQ_INS_MODE) {
6418 mode = REQ_OVL_MODE;
6420 mode = REQ_INS_MODE;
6424 for (n = 0; n < SIZEOF(lookup); n++) {
6425 if (lookup[n].code == c) {
6426 c = lookup[n].result;
6431 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6434 * Force the field that the user is typing into to be in reverse video,
6435 * while the other fields are shown underlined.
6450 case REQ_LEFT_FIELD:
6452 case REQ_RIGHT_CHAR:
6456 current = (c < KEY_MAX);
6460 c = edit_secure(me, c);
6461 set_field_back(me, A_REVERSE);
6463 c = edit_secure(me, c);
6464 set_field_back(me, A_UNDERLINE);
6470 my_form_driver(FORM *form, int c)
6472 if (c == (MAX_FORM_COMMAND + 1)
6473 && form_driver(form, REQ_VALIDATION) == E_OK)
6481 #ifdef NCURSES_VERSION
6482 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6483 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6485 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6486 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6490 * Allow a middle initial, optionally with a '.' to end it.
6493 FIELDCHECK_CB(mi_field_check)
6495 char *s = field_buffer(fld, 0);
6499 for (n = 0; s[n] != '\0'; ++n) {
6506 } else if (isspace(UChar(s[n]))) {
6511 if (!isspace(UChar(s[n])))
6517 /* force the form to display a leading capital */
6518 if (islower(UChar(s[0]))) {
6519 s[0] = (char) toupper(UChar(s[0]));
6520 set_field_buffer(fld, 0, s);
6526 CHAR_CHECK_CB(mi_char_check)
6528 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6532 * Passwords should be at least 6 characters.
6535 FIELDCHECK_CB(pw_field_check)
6537 char *s = field_buffer(fld, 0);
6540 for (n = 0; s[n] != '\0'; ++n) {
6541 if (isspace(UChar(s[n]))) {
6550 CHAR_CHECK_CB(pw_char_check)
6552 return (isgraph(ch) ? TRUE : FALSE);
6556 form_test(bool recur GCC_UNUSED)
6560 FIELD *f[12], *secure;
6561 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6562 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6563 int finished = 0, c;
6566 #ifdef NCURSES_MOUSE_VERSION
6567 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6571 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6572 addstr("^N -- go to next field ^P -- go to previous field\n");
6573 addstr("Home -- go to first field End -- go to last field\n");
6574 addstr("^L -- go to field to left ^R -- go to field to right\n");
6575 addstr("^U -- move upward to field ^D -- move downward to field\n");
6576 addstr("^W -- go to next word ^B -- go to previous word\n");
6577 addstr("^S -- go to start of field ^E -- go to end of field\n");
6578 addstr("^H -- delete previous char ^Y -- delete line\n");
6579 addstr("^G -- delete current word ^C -- clear to end of line\n");
6580 addstr("^K -- clear to end of field ^X -- clear field\n");
6581 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6583 MvAddStr(4, 57, "Forms Entry Test");
6587 /* describe the form */
6588 memset(f, 0, sizeof(f));
6589 f[n++] = make_label(0, 15, "Sample Form");
6591 f[n++] = make_label(2, 0, "Last Name");
6592 f[n++] = make_field(3, 0, 1, 18, FALSE);
6593 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6595 f[n++] = make_label(2, 20, "First Name");
6596 f[n++] = make_field(3, 20, 1, 12, FALSE);
6597 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6599 f[n++] = make_label(2, 34, "Middle Name");
6600 f[n++] = make_field(3, 34, 1, 12, FALSE);
6601 set_field_type(f[n - 1], fty_middle);
6603 f[n++] = make_label(5, 0, "Comments");
6604 f[n++] = make_field(6, 0, 4, 46, FALSE);
6606 f[n++] = make_label(5, 20, "Password:");
6608 f[n++] = make_field(5, 30, 1, 9, TRUE);
6609 set_field_type(f[n - 1], fty_passwd);
6612 if ((form = new_form(f)) != 0) {
6618 nonl(); /* lets us read ^M's */
6620 switch (form_driver(form, c = form_virtualize(form, w))) {
6622 MvAddStr(5, 57, field_buffer(secure, 1));
6626 case E_UNKNOWN_COMMAND:
6627 finished = my_form_driver(form, c);
6639 for (c = 0; f[c] != 0; c++)
6641 free_fieldtype(fty_middle);
6642 free_fieldtype(fty_passwd);
6646 #ifdef NCURSES_MOUSE_VERSION
6647 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6651 #endif /* USE_LIBFORM */
6653 /****************************************************************************
6657 ****************************************************************************/
6659 #if HAVE_COPYWIN /* ...and overlay, overwrite */
6667 getmaxyx(stdscr, y, x);
6668 if (y < 23 || x < 80) {
6669 Cannot("The screen is too small for this test");
6672 const int H_SIZE = 1; /* header-size */
6673 const int F_SIZE = 6; /* footer-size */
6674 int ymax = y - (H_SIZE + F_SIZE);
6675 int high = ymax / 5; /* equal-sized parts for cross */
6676 int xmax = x - 2; /* margin */
6677 int wide = (xmax / 5) & ~1;
6686 tmar = (ymax - (5 * high)) / 2 + H_SIZE;
6687 lmar = (xmax - (5 * wide)) / 2;
6690 result = newwin(3 * high, 3 * wide, tmar, lmar);
6692 result = newwin(3 * high, 3 * wide, tmar + 2 * high, lmar + 2 * wide);
6699 fillwin(WINDOW *win, char ch)
6704 getmaxyx(win, y1, x1);
6705 for (y = 0; y < y1; y++) {
6707 for (x = 0; x < x1; x++)
6708 waddch(win, UChar(ch));
6712 #define InCross(x,y, x1,y1) \
6713 (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3)) \
6714 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3))))
6717 crosswin(WINDOW *win, char ch)
6723 getmaxyx(win, y1, x1);
6724 for (y = 0; y < y1; y++) {
6725 for (x = 0; x < x1; x += xw) {
6726 if (InCross(x, y, x1, y1)) {
6728 waddch(win, UChar(ch));
6735 * Match "crosswin()", but using line-drawing characters. This could be done
6736 * a little simpler using box(), but the reason for this example is to test
6737 * hline/vline and addch with line-drawing vs the copy/overlay functions.
6740 crossbox(WINDOW *win)
6745 getmaxyx(win, y1, x1);
6750 mvwhline(win, 0, (xmax / 3), ACS_HLINE, (xmax / 3));
6751 mvwhline(win, ymax / 3, 0, ACS_HLINE, xmax);
6752 mvwhline(win, ((2 * ymax) / 3) - 1, 0, ACS_HLINE, xmax);
6753 mvwhline(win, y1 - 1, (xmax / 3), ACS_HLINE, (xmax / 3));
6755 mvwvline(win, (ymax / 3), 0, ACS_VLINE, (ymax / 3));
6756 mvwvline(win, 0, xmax / 3, ACS_VLINE, ymax);
6757 mvwvline(win, 0, ((2 * xmax) / 3) - 1, ACS_VLINE, ymax);
6758 mvwvline(win, (ymax / 3), x1 - 1, ACS_VLINE, (ymax / 3));
6760 mvwaddch(win, 0, (xmax / 3), ACS_ULCORNER);
6761 mvwaddch(win, 0, ((2 * xmax) / 3) - 1, ACS_URCORNER);
6762 mvwaddch(win, y1 - 1, (xmax / 3), ACS_LLCORNER);
6763 mvwaddch(win, y1 - 1, ((2 * xmax) / 3) - 1, ACS_LRCORNER);
6765 mvwaddch(win, (ymax / 3), 0, ACS_ULCORNER);
6766 mvwaddch(win, ((2 * ymax) / 3) - 1, 0, ACS_LLCORNER);
6767 mvwaddch(win, (ymax / 3), x1 - 1, ACS_URCORNER);
6768 mvwaddch(win, ((2 * ymax) / 3) - 1, x1 - 1, ACS_LRCORNER);
6770 mvwaddch(win, (ymax / 3), (xmax / 3), ACS_PLUS);
6771 mvwaddch(win, (ymax / 3), ((2 * xmax) / 3) - 1, ACS_PLUS);
6772 mvwaddch(win, ((2 * ymax) / 3) - 1, ((2 * xmax) / 3) - 1, ACS_PLUS);
6773 mvwaddch(win, ((2 * ymax) / 3) - 1, (xmax / 3), ACS_PLUS);
6784 #define OVERLAP_FLAVORS 6
6793 #define LimitFILL() UseColors ? 4 : 2
6796 otDRAW_text_cross = 0
6803 #define LimitDRAW() UseColors ? 5 : 3
6806 otCOPY_overwrite = 0
6812 #define LimitCOPY() 4
6815 overlap_helpitem(int state, int item, char *message)
6817 int row = (item / 2);
6818 int col = ((item % 2) ? COLS / 2 : 0);
6820 move(LINES - 6 + row, col);
6821 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6826 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6828 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6830 switch ((otFILL) flavor) {
6832 (void) wattrset(win, A_NORMAL);
6835 (void) wattrset(win, A_BOLD);
6838 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6839 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
6842 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6843 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
6849 overlap_test_2_attr(WINDOW *win, int flavor, int col)
6851 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
6853 switch ((otDRAW) flavor) {
6854 case otDRAW_text_cross:
6857 case otDRAW_line_box:
6860 case otDRAW_line_cross:
6864 init_pair(cpair, COLOR_RED, COLOR_GREEN);
6865 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
6867 case otDRAW_reset_bg:
6868 wbkgdset(win, ' ' | A_NORMAL);
6874 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
6879 int limit[OVERLAP_FLAVORS];
6880 const char *ths, *tht;
6884 state += OVERLAP_FLAVORS;
6885 state = state % OVERLAP_FLAVORS;
6886 assert(state >= 0 && state < OVERLAP_FLAVORS);
6888 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
6891 ths = col ? "B" : "A";
6892 tht = col ? "A" : "B";
6894 switch ((otBASE) row) {
6895 case otBASE_refresh:
6898 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6899 "refresh %s, then %s, then doupdate.", ths, tht);
6902 limit[row] = LimitFILL();
6903 flavors[row] %= limit[row];
6904 overlap_test_1_attr(stdscr, flavors[row], col);
6905 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6906 "fill window %s with letter %s.", ths, ths);
6909 limit[row] = LimitDRAW();
6910 flavors[row] %= limit[row];
6911 switch ((otDRAW) flavors[row]) {
6912 case otDRAW_text_cross:
6913 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6914 "cross text-pattern in window %s.", ths);
6916 case otDRAW_line_box:
6917 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6918 "draw line-box in window %s.", ths);
6920 case otDRAW_line_cross:
6921 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6922 "draw line-cross in window %s.", ths);
6925 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6926 "set background of window %s.", ths);
6928 case otDRAW_reset_bg:
6929 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6930 "reset background of window %s.", ths);
6937 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6938 "clear window %s.", ths);
6941 limit[row] = LimitCOPY();
6942 flavors[row] %= limit[row];
6943 switch ((otCOPY) flavors[row]) {
6944 case otCOPY_overwrite:
6945 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6946 "overwrite %s onto %s.", ths, tht);
6949 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6950 "copywin(FALSE) %s onto %s.", ths, tht);
6953 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6954 "copywin(TRUE) %s onto %s.", ths, tht);
6956 case otCOPY_overlay:
6957 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
6958 "overlay %s onto %s.", ths, tht);
6963 overlap_helpitem(state, item, msg);
6964 (void) wattrset(stdscr, A_NORMAL);
6965 wbkgdset(stdscr, ' ' | A_NORMAL);
6968 printw("^Q/ESC = terminate test. Up/down/space select tests (row %d",
6970 if (limit[state] > 1)
6971 printw(" test %d:%d", 1 + flavors[state], limit[state]);
6979 overlap_test_0(WINDOW *a, WINDOW *b)
6989 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
6991 overlap_test_1_attr(a, flavor, col);
6993 (void) wattrset(a, A_NORMAL);
6997 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6999 overlap_test_2_attr(a, flavor, col);
7000 switch ((otDRAW) flavor) {
7001 case otDRAW_text_cross:
7004 case otDRAW_line_box:
7007 case otDRAW_line_cross:
7011 /* done in overlap_test_2_attr */
7013 case otDRAW_reset_bg:
7014 /* done in overlap_test_2_attr */
7020 overlap_test_3(WINDOW *a)
7027 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
7029 switch ((otCOPY) flavor) {
7030 case otCOPY_overwrite:
7034 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
7037 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
7039 case otCOPY_overlay:
7045 /* test effects of overlapping windows */
7047 overlap_test(bool recur GCC_UNUSED)
7049 WINDOW *win1, *win2;
7051 int state, flavor[OVERLAP_FLAVORS];
7053 if ((win1 = make_overlap(0)) == 0
7054 || (win2 = make_overlap(1)) == 0)
7061 printw("Test wnoutrefresh() for two overlapping windows:");
7063 memset(flavor, 0, sizeof(flavor));
7064 state = overlap_help(0, flavor);
7066 while (!isQuit(ch = Getchar(), TRUE)) {
7068 case 'a': /* refresh window A first, then B */
7069 overlap_test_0(win1, win2);
7072 case 'b': /* refresh window B first, then A */
7073 overlap_test_0(win2, win1);
7076 case 'c': /* fill window A so it's visible */
7077 overlap_test_1(flavor[otBASE_fill], 0, win1, 'A');
7080 case 'd': /* fill window B so it's visible */
7081 overlap_test_1(flavor[otBASE_fill], 1, win2, 'B');
7084 case 'e': /* cross test pattern in window A */
7085 overlap_test_2(flavor[otBASE_draw], 0, win1, 'A');
7088 case 'f': /* cross test pattern in window A */
7089 overlap_test_2(flavor[otBASE_draw], 1, win2, 'B');
7092 case 'g': /* clear window A */
7093 overlap_test_3(win1);
7096 case 'h': /* clear window B */
7097 overlap_test_3(win2);
7100 case 'i': /* overwrite A onto B */
7101 overlap_test_4(flavor[otBASE_copy], win1, win2);
7104 case 'j': /* overwrite B onto A */
7105 overlap_test_4(flavor[otBASE_copy], win2, win1);
7110 state = overlap_help(state + 1, flavor);
7115 state = overlap_help(state - 1, flavor);
7120 state = overlap_help(state, flavor);
7124 state = overlap_help(state, flavor);
7140 #if USE_WIDEC_SUPPORT
7142 x_fillwin(WINDOW *win, wchar_t ch)
7147 getmaxyx(win, y1, x1);
7149 for (y = 0; y < y1; y++) {
7151 for (x = 0; x < x1; x++)
7152 waddnwstr(win, &ch, 1);
7157 x_crosswin(WINDOW *win, wchar_t ch)
7163 getmaxyx(win, y1, x1);
7164 for (y = 0; y < y1; y++) {
7165 for (x = 0; x < x1; x += xw) {
7166 if (InCross(x, y, x1, y1)) {
7168 waddnwstr(win, &ch, 1);
7175 x_overlap_test_1(int flavor, int col, WINDOW *a, wchar_t fill)
7177 overlap_test_1_attr(a, flavor, col);
7179 (void) wattrset(a, A_NORMAL);
7183 x_overlap_test_2(int flavor, int col, WINDOW *a, wchar_t fill)
7185 overlap_test_2_attr(a, flavor, col);
7186 switch ((otDRAW) flavor) {
7187 case otDRAW_text_cross:
7188 x_crosswin(a, fill);
7190 case otDRAW_line_box:
7193 case otDRAW_line_cross:
7197 /* done in overlap_test_2_attr */
7199 case otDRAW_reset_bg:
7200 /* done in overlap_test_2_attr */
7205 /* test effects of overlapping windows */
7207 x_overlap_test(bool recur GCC_UNUSED)
7209 const wchar_t WIDE_A = 0xff21;
7210 const wchar_t WIDE_B = 0xff22;
7211 WINDOW *win1, *win2;
7213 int state, flavor[OVERLAP_FLAVORS];
7215 if ((win1 = make_overlap(0)) == 0
7216 || (win2 = make_overlap(1)) == 0)
7223 printw("Test wnoutrefresh() for overlapping windows with double-cell characters:");
7225 memset(flavor, 0, sizeof(flavor));
7226 state = overlap_help(0, flavor);
7228 while (!isQuit(ch = Getchar(), TRUE)) {
7230 case 'a': /* refresh window A first, then B */
7231 overlap_test_0(win1, win2);
7234 case 'b': /* refresh window B first, then A */
7235 overlap_test_0(win2, win1);
7238 case 'c': /* fill window A so it's visible */
7239 x_overlap_test_1(flavor[otBASE_fill], 0, win1, WIDE_A);
7242 case 'd': /* fill window B so it's visible */
7243 x_overlap_test_1(flavor[otBASE_fill], 1, win2, WIDE_B);
7246 case 'e': /* cross test pattern in window A */
7247 x_overlap_test_2(flavor[otBASE_draw], 0, win1, WIDE_A);
7250 case 'f': /* cross test pattern in window A */
7251 x_overlap_test_2(flavor[otBASE_draw], 1, win2, WIDE_B);
7254 case 'g': /* clear window A */
7255 overlap_test_3(win1);
7258 case 'h': /* clear window B */
7259 overlap_test_3(win2);
7262 case 'i': /* overwrite A onto B */
7263 overlap_test_4(flavor[otBASE_copy], win1, win2);
7266 case 'j': /* overwrite B onto A */
7267 overlap_test_4(flavor[otBASE_copy], win2, win1);
7272 state = overlap_help(state + 1, flavor);
7277 state = overlap_help(state - 1, flavor);
7282 state = overlap_help(state, flavor);
7286 state = overlap_help(state, flavor);
7301 #endif /* USE_WIDEC_SUPPORT */
7303 #endif /* HAVE_COPYWIN */
7306 show_setting_name(const char *name)
7308 printw("%-25s ", name);
7312 show_string_setting(const char *name, const char *value)
7314 show_setting_name(name);
7316 printw("\"%s\"", value);
7326 show_number_setting(const char *name, int value)
7328 show_setting_name(name);
7330 printw("%d", value);
7333 printw("%d", value);
7340 show_boolean_setting(const char *name, int value)
7342 show_setting_name(name);
7344 printw("%s", value ? "TRUE" : "FALSE");
7347 printw("%d", value);
7354 settings_test(bool recur GCC_UNUSED)
7356 #if USE_WIDEC_SUPPORT
7361 show_string_setting("termname", termname());
7362 show_string_setting("longname", longname());
7363 show_number_setting("baudrate", baudrate());
7364 if (erasechar() > 0) {
7365 show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
7366 show_string_setting("keyname(erasechar)", keyname(erasechar()));
7368 if (killchar() > 0) {
7369 show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
7370 show_string_setting("keyname(killchar)", keyname(killchar()));
7372 #if USE_WIDEC_SUPPORT
7373 if (erasewchar(&ch) == OK) {
7374 show_string_setting("key_name(erasewchar)", key_name(ch));
7376 if (killwchar(&ch) == OK) {
7377 show_string_setting("key_name(killwchar)", key_name(ch));
7380 show_boolean_setting("has_ic", has_ic());
7381 show_boolean_setting("has_il", has_il());
7382 show_boolean_setting("has_colors", has_colors());
7383 #if HAVE_COLOR_CONTENT
7384 show_boolean_setting("can_change_color", can_change_color());
7392 /****************************************************************************
7396 ****************************************************************************/
7401 static const char *const tbl[] =
7403 "Usage: ncurses [options]"
7406 #ifdef NCURSES_VERSION
7407 ," -a f,b set default-colors (assumed white-on-black)"
7408 ," -d use default-colors if terminal supports them"
7411 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
7414 ," -e fmt specify format for soft-keys test (e)"
7417 ," -f rip-off footer line (can repeat)"
7418 ," -h rip-off header line (can repeat)"
7420 ," -m do not use colors"
7421 #if HAVE_COLOR_CONTENT
7422 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
7425 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
7427 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(__MINGW32__)
7428 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
7431 ," -t mask specify default trace-level (may toggle with ^T)"
7433 #if HAVE_COLOR_CONTENT
7434 ," -x use xterm-compatible control for reading color palette"
7438 for (n = 0; n < SIZEOF(tbl); n++)
7439 fprintf(stderr, "%s\n", tbl[n]);
7440 ExitProgram(EXIT_FAILURE);
7444 set_terminal_modes(void)
7449 scrollok(stdscr, TRUE);
7450 idlok(stdscr, TRUE);
7451 keypad(stdscr, TRUE);
7456 announce_sig(int sig)
7458 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
7464 rip_footer(WINDOW *win, int cols)
7466 wbkgd(win, A_REVERSE);
7469 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
7475 rip_header(WINDOW *win, int cols)
7477 wbkgd(win, A_REVERSE);
7480 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
7484 #endif /* HAVE_RIPOFFLINE */
7489 #if USE_WIDEC_SUPPORT
7492 int (*narrow_func) (bool);
7493 int (*wide_func) (bool);
7497 #define BOTH(a) a, x_ ## a
7498 #define ONLY(a) a, NULL
7499 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7503 int (*narrow_func) (bool);
7509 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7512 static MyCmds cmds[] =
7514 CMDS(TRUE, BOTH(getch_test), 'a', "keyboard and mouse input test"),
7515 CMDS(TRUE, BOTH(attr_test), 'b', "character attribute test"),
7516 CMDS(TRUE, BOTH(color_test), 'c', "color test pattern"),
7517 #if HAVE_COLOR_CONTENT
7518 CMDS(FALSE, ONLY(color_edit), 'd', "edit RGB color values"),
7521 CMDS(TRUE, BOTH(slk_test), 'e', "exercise soft keys"),
7523 CMDS(TRUE, BOTH(acs_test), 'f', "display ACS characters"),
7524 CMDS(TRUE, ONLY(scroll_test), 'g', "display windows and scrolling"),
7525 CMDS(TRUE, ONLY(flushinp_test), 'i', "test flushinp()"),
7526 CMDS(TRUE, ONLY(sgr_attr_test), 'k', "display character attributes"),
7528 CMDS(TRUE, ONLY(menu_test), 'm', "exercise menu library"),
7531 CMDS(TRUE, BOTH(panel_test), 'o', "exercise panel library"),
7534 CMDS(TRUE, ONLY(pad_test), 'p', "exercise pad features"),
7536 CMDS(TRUE, ONLY(NULL), 'q', "quit"),
7538 CMDS(TRUE, ONLY(form_test), 'r', "exercise form library"),
7541 CMDS(TRUE, BOTH(overlap_test), 's', "overlapping-refresh test"),
7543 #if USE_LIBMENU && defined(TRACE)
7544 CMDS(TRUE, ONLY(trace_set), 't', "set trace level"),
7546 CMDS(TRUE, ONLY(settings_test), 'v', "show terminal name and settings"),
7547 CMDS(FALSE, ONLY(NULL), '?', "repeat this command summary")
7556 printf("This is the ncurses main menu (uppercase for wide-characters)\n");
7557 for (n = 0; n < SIZEOF(cmds); ++n) {
7558 if (top || cmds[n].recur) {
7560 #if USE_WIDEC_SUPPORT
7561 if (cmds[n].wide_func) {
7562 printf("%c,", toupper(cmds[n].code));
7565 printf("%c\t= %s\n", cmds[n].code, cmds[n].help);
7569 (void) fputs("> ", stdout);
7570 (void) fflush(stdout); /* necessary under SVr4 curses */
7573 * This used to be an 'fgets()' call (until 1996/10). However with
7574 * some runtime libraries, mixing stream I/O and 'read()' causes the
7575 * input stream to be flushed when switching between the two.
7580 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7584 } else if (command == 0 && !isspace(UChar(ch))) {
7586 } else if (ch == '\n' || ch == '\r') {
7587 if ((command == 'd') && !top) {
7588 (void) fputs("Do not nest test-d\n", stdout);
7593 (void) fputs("> ", stdout);
7594 (void) fflush(stdout);
7599 for (n = 0; n < SIZEOF(cmds); ++n) {
7600 if (cmds[n].code == command) {
7601 doit = cmds[n].narrow_func;
7604 #if USE_WIDEC_SUPPORT
7605 if (toupper(cmds[n].code) == command) {
7606 doit = cmds[n].wide_func;
7612 if (doit != NULL && doit(FALSE) == OK) {
7614 * This may be overkill; it's intended to reset everything back
7615 * to the initial terminal modes so that tests don't get in
7619 set_terminal_modes();
7624 if (command == '?') {
7625 (void) puts("This is the ncurses capability tester.");
7627 puts("You may select a test from the main menu by typing the");
7629 puts("key letter of the choice (the letter to left of the =)");
7631 puts("at the > prompt. Type `q' to exit.");
7639 /*+-------------------------------------------------------------------------
7641 --------------------------------------------------------------------------*/
7644 main(int argc, char *argv[])
7648 #ifdef NCURSES_VERSION
7649 int default_fg = COLOR_WHITE;
7650 int default_bg = COLOR_BLACK;
7651 bool assumed_colors = FALSE;
7652 bool default_colors = FALSE;
7654 bool monochrome = FALSE;
7655 #if HAVE_COLOR_CONTENT
7656 bool xterm_colors = FALSE;
7657 char *palette_file = 0;
7660 setlocale(LC_ALL, "");
7662 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) {
7664 #ifdef NCURSES_VERSION
7666 assumed_colors = TRUE;
7667 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7669 default_fg = COLOR_WHITE;
7672 default_bg = COLOR_BLACK;
7677 default_colors = TRUE;
7686 my_e_param = atoi(optarg);
7687 #ifdef NCURSES_VERSION
7688 if (my_e_param > 3) /* allow extended layouts */
7697 ripoffline(-1, rip_footer);
7700 ripoffline(1, rip_header);
7702 #endif /* HAVE_RIPOFFLINE */
7706 #if HAVE_COLOR_CONTENT
7708 palette_file = optarg;
7713 nap_msec = (int) atol(optarg);
7716 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(__MINGW32__)
7723 save_trace = (unsigned) strtol(optarg, 0, 0);
7726 #if HAVE_COLOR_CONTENT
7728 xterm_colors = TRUE;
7737 * If there's no menus (unlikely for ncurses!), then we'll have to set
7738 * tracing on initially, just in case the user wants to test something that
7739 * doesn't involve wGetchar.
7742 /* enable debugging */
7746 if (!isatty(fileno(stdin)))
7748 #endif /* USE_LIBMENU */
7752 /* tell it we're going to play with soft keys */
7753 slk_init(my_e_param);
7757 /* set up null signal catcher so we can see what interrupts to getch do */
7758 signal(SIGUSR1, announce_sig);
7761 /* we must initialize the curses data structure only once */
7765 set_terminal_modes();
7768 /* tests, in general, will want these modes */
7769 UseColors = (bool) (monochrome ? FALSE : has_colors());
7773 #ifdef NCURSES_VERSION_PATCH
7774 MaxColors = COLORS; /* was > 16 ? 16 : COLORS */
7775 #if HAVE_USE_DEFAULT_COLORS
7776 if (default_colors) {
7777 use_default_colors();
7780 #if HAVE_ASSUME_DEFAULT_COLORS
7782 assume_default_colors(default_fg, default_bg);
7785 #else /* normal SVr4 curses */
7786 MaxColors = COLORS; /* was > 8 ? 8 : COLORS */
7788 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
7790 #if HAVE_COLOR_CONTENT
7791 if (can_change_color()) {
7792 init_all_colors(xterm_colors, palette_file);
7798 * Return to terminal mode, so we're guaranteed of being able to
7799 * select terminal commands even if the capabilities are wrong.
7803 #if HAVE_CURSES_VERSION
7804 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
7805 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
7806 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
7807 NCURSES_VERSION_MAJOR,
7808 NCURSES_VERSION_MINOR,
7809 NCURSES_VERSION_PATCH);
7811 (void) puts("Welcome to ncurses. Press ? for help.");
7816 ExitProgram(EXIT_SUCCESS);
7819 /* ncurses.c ends here */