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.502 2017/11/02 20:46:06 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, int zoom)
2129 if (move(y, x) != ERR) {
2136 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2140 if ((have = (int) strlen(temp)) >= width) {
2142 while ((1 << pwr2) < color)
2144 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2145 width > 4 ? "2^%d" : "^%d", pwr2);
2147 } else if (color >= 8) {
2148 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2150 } else if (color < 0) {
2151 _nc_STRCPY(temp, "default", sizeof(temp));
2153 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2154 "%.*s", 16, the_color_names[color]);
2156 printw("%-*.*s", width, width, temp);
2161 color_legend(WINDOW *helpwin, bool wide)
2166 MvWPrintw(helpwin, row++, col,
2169 MvWPrintw(helpwin, row++, col,
2170 "Use up/down arrow to scroll through the display if it is");
2171 MvWPrintw(helpwin, row++, col,
2172 "longer than one screen. Control/N and Control/P can be used");
2173 MvWPrintw(helpwin, row++, col,
2174 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2175 MvWPrintw(helpwin, row++, col,
2176 "full screen; control/B and control/F can be used here.");
2178 MvWPrintw(helpwin, row++, col,
2180 MvWPrintw(helpwin, row++, col,
2181 " a/A toggle altcharset off/on");
2182 MvWPrintw(helpwin, row++, col,
2183 " b/B toggle bold off/on");
2185 MvWPrintw(helpwin, row++, col,
2186 " c/C cycle used-colors through 8,16,...,COLORS");
2188 MvWPrintw(helpwin, row++, col,
2189 " n/N toggle text/number on/off");
2190 MvWPrintw(helpwin, row++, col,
2191 " r/R toggle reverse on/off");
2192 MvWPrintw(helpwin, row++, col,
2193 " w/W switch width between 4/8 columns");
2194 MvWPrintw(helpwin, row++, col,
2195 " z/Z zoom out (or in)");
2196 #if USE_WIDEC_SUPPORT
2198 MvWPrintw(helpwin, row++, col,
2199 "Wide characters:");
2200 MvWPrintw(helpwin, row, col,
2201 " x/X toggle text between ASCII and wide-character");
2208 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2211 color_cycle(int current, int step)
2213 int result = current;
2219 if ((result * 2) > COLORS) {
2222 while ((result * 2) < current) {
2228 if (current >= COLORS) {
2233 if (result > COLORS)
2239 /* generate a color test pattern */
2241 color_test(bool recur GCC_UNUSED)
2246 int grid_top = top + 3;
2247 int page_size = (LINES - grid_top);
2249 int colors_max = COLORS;
2256 bool opt_acsc = FALSE;
2257 bool opt_bold = FALSE;
2258 bool opt_revs = FALSE;
2259 bool opt_nums = FALSE;
2260 bool opt_wide = FALSE;
2265 Cannot("does not support color.");
2269 numbered = typeCalloc(char, COLS + 1);
2270 done = ((COLS < 16) || (numbered == 0));
2273 * Because the number of colors is usually a power of two, we also use
2274 * a power of two for the number of colors shown per line (to be tidy).
2276 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2281 int zoom_size = (1 << opt_zoom);
2282 int colors_max1 = colors_max / zoom_size;
2283 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2285 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2286 if (colors_max2 <= COLOR_PAIRS) {
2287 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2288 if (pairs_max > limit)
2291 if (pairs_max > COLOR_PAIRS)
2292 pairs_max = COLOR_PAIRS;
2293 if (pairs_max < colors_max1)
2294 pairs_max = colors_max1;
2296 /* this assumes an 80-column line */
2300 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2304 per_row = (col_limit / width);
2306 per_row -= MinColors;
2308 row_limit = (pairs_max + per_row - 1) / per_row;
2311 (void) printw("There are %d color pairs and %d colors",
2313 if (colors_max1 != COLORS)
2314 (void) printw(" (using %d colors)", colors_max1);
2316 (void) addstr(" besides 'default'");
2318 (void) printw(" zoom:%d", opt_zoom);
2321 MvPrintw(top + 1, 0,
2322 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2325 opt_bold ? "on" : "off");
2327 /* show color names/numbers across the top */
2328 for (i = 0; i < per_row; i++) {
2329 show_color_name(top + 2,
2331 (int) i * zoom_size + MinColors,
2336 /* show a grid of colors, with color names/ numbers on the left */
2337 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2338 int row = grid_top + (i / per_row) - base_row;
2339 int col = (i % per_row + 1) * width;
2340 NCURSES_PAIRS_T pair = i;
2342 if ((i / per_row) > row_limit)
2345 #define InxToFG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) % (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2346 #define InxToBG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) / (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2347 if (row >= 0 && move(row, col) != ERR) {
2348 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) InxToFG(i);
2349 NCURSES_COLOR_T bg = (NCURSES_COLOR_T) InxToBG(i);
2351 init_pair(pair, fg, bg);
2352 attron(COLOR_PAIR(pair));
2354 attron(A_ALTCHARSET);
2361 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2365 printw("%-*.*s", width, width, hello);
2366 (void) attrset(A_NORMAL);
2368 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2369 show_color_name(row, 0,
2380 switch (wGetchar(stdscr)) {
2394 colors_max = color_cycle(colors_max, -1);
2397 colors_max = color_cycle(colors_max, 1);
2415 set_color_test(opt_wide, FALSE);
2418 set_color_test(opt_wide, TRUE);
2421 if (opt_zoom <= 0) {
2429 if ((1 << opt_zoom) >= colors_max) {
2438 if (base_row <= 0) {
2446 if (base_row + page_size >= row_limit) {
2455 if (base_row <= 0) {
2458 base_row -= (page_size - 1);
2466 if (base_row + page_size >= row_limit) {
2469 base_row += page_size - 1;
2470 if (base_row + page_size >= row_limit) {
2471 base_row = row_limit - page_size - 1;
2476 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2478 color_legend(helpwin, FALSE);
2496 #if USE_WIDEC_SUPPORT
2498 #if HAVE_INIT_EXTENDED_COLOR
2499 #define InitExtendedPair(p,f,g) init_extended_pair((p),(f),(g))
2500 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), &(p))
2501 #define EXTENDED_PAIRS_T int
2503 #define InitExtendedPair(p,f,g) init_pair((NCURSES_PAIRS_T) (p),(f),(g))
2504 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), NULL)
2505 #define EXTENDED_PAIRS_T NCURSES_PAIRS_T
2508 /* generate a color test pattern */
2510 x_color_test(bool recur GCC_UNUSED)
2515 int grid_top = top + 3;
2516 int page_size = (LINES - grid_top);
2517 int pairs_max = (unsigned short) (-1);
2518 int colors_max = COLORS;
2525 bool opt_acsc = FALSE;
2526 bool opt_bold = FALSE;
2527 bool opt_revs = FALSE;
2528 bool opt_wide = FALSE;
2529 bool opt_nums = FALSE;
2530 bool opt_xchr = FALSE;
2532 wchar_t *buffer = 0;
2536 Cannot("does not support color.");
2539 numbered = typeCalloc(char, COLS + 1);
2540 buffer = typeCalloc(wchar_t, COLS + 1);
2541 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2544 * Because the number of colors is usually a power of two, we also use
2545 * a power of two for the number of colors shown per line (to be tidy).
2547 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2552 int zoom_size = (1 << opt_zoom);
2553 int colors_max1 = colors_max / zoom_size;
2554 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2556 pairs_max = ((unsigned) (-1)) / 2;
2557 if (colors_max2 <= COLOR_PAIRS) {
2558 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2559 if (pairs_max > limit)
2562 if (pairs_max > COLOR_PAIRS)
2563 pairs_max = COLOR_PAIRS;
2564 if (pairs_max < colors_max1)
2565 pairs_max = colors_max1;
2570 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2574 per_row = (col_limit / width);
2576 per_row -= MinColors;
2579 make_fullwidth_text(buffer, hello);
2583 make_narrow_text(buffer, hello);
2586 row_limit = (pairs_max + per_row - 1) / per_row;
2589 (void) printw("There are %d color pairs and %d colors",
2591 if (colors_max1 != COLORS)
2592 (void) printw(" (using %d colors)", colors_max1);
2594 (void) addstr(" besides 'default'");
2596 (void) printw(" zoom:%d", opt_zoom);
2599 MvPrintw(top + 1, 0,
2600 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2603 opt_bold ? "on" : "off");
2605 /* show color names/numbers across the top */
2606 for (i = 0; i < per_row; i++) {
2607 show_color_name(top + 2,
2608 ((int) i + 1) * width,
2609 (int) i * zoom_size + MinColors,
2614 /* show a grid of colors, with color names/ numbers on the left */
2615 for (i = (base_row * per_row); i < pairs_max; i++) {
2616 int row = grid_top + ((int) i / per_row) - base_row;
2617 int col = ((int) i % per_row + 1) * width;
2620 if ((i / per_row) > row_limit)
2623 if (row >= 0 && move(row, col) != ERR) {
2624 InitExtendedPair(pair, InxToFG(i), InxToBG(i));
2625 (void) ExtendedColorSet(pair);
2627 attr_on(WA_ALTCHARSET, NULL);
2629 attr_on(WA_BOLD, NULL);
2631 attr_on(WA_REVERSE, NULL);
2634 _nc_SPRINTF(numbered,
2635 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2636 "{%02X}", (unsigned) i);
2638 make_fullwidth_text(buffer, numbered);
2640 make_narrow_text(buffer, numbered);
2643 addnwstr(buffer, width);
2644 (void) attr_set(A_NORMAL, 0, NULL);
2646 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2647 show_color_name(row, 0,
2658 switch (wGetchar(stdscr)) {
2672 colors_max = color_cycle(colors_max, -1);
2675 colors_max = color_cycle(colors_max, 1);
2693 set_color_test(opt_wide, FALSE);
2696 set_color_test(opt_wide, TRUE);
2705 if (opt_zoom <= 0) {
2713 if ((1 << opt_zoom) >= colors_max) {
2722 if (base_row <= 0) {
2730 if (base_row + page_size >= row_limit) {
2739 if (base_row <= 0) {
2742 base_row -= (page_size - 1);
2750 if (base_row + page_size >= row_limit) {
2753 base_row += page_size - 1;
2754 if (base_row + page_size >= row_limit) {
2755 base_row = row_limit - page_size - 1;
2760 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2762 color_legend(helpwin, TRUE);
2780 #endif /* USE_WIDEC_SUPPORT */
2782 #if HAVE_COLOR_CONTENT
2784 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2786 NCURSES_COLOR_T red, green, blue;
2788 color_content(current, &red, &green, &blue);
2792 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2795 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2798 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2802 if (init_color(current, red, green, blue) == ERR)
2807 reset_all_colors(void)
2811 for (c = 0; c < COLORS; ++c)
2814 all_colors[c].green,
2815 all_colors[c].blue);
2818 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2819 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2820 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2823 init_all_colors(bool xterm_colors, char *palette_file)
2826 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2828 failed("all_colors");
2829 for (cp = 0; cp < MaxColors; ++cp) {
2831 &all_colors[cp].red,
2832 &all_colors[cp].green,
2833 &all_colors[cp].blue);
2835 /* xterm and compatible terminals can read results of an OSC string
2836 * asking for the current color palette.
2841 char result[BUFSIZ];
2843 unsigned check_r, check_g, check_b;
2847 for (n = 0; n < MaxColors; ++n) {
2848 fprintf(stderr, "\033]4;%d;?\007", n);
2849 got = (int) read(0, result, sizeof(result) - 1);
2853 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2859 all_colors[n].red = DecodeRGB(check_r);
2860 all_colors[n].green = DecodeRGB(check_g);
2861 all_colors[n].blue = DecodeRGB(check_b);
2868 if (palette_file != 0) {
2869 FILE *fp = fopen(palette_file, "r");
2871 char buffer[BUFSIZ];
2872 int red, green, blue;
2875 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2876 if (sscanf(buffer, "scale:%d", &c) == 1) {
2878 } else if (sscanf(buffer, "%d:%d %d %d",
2887 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2888 all_colors[c].red = Scaled(red);
2889 all_colors[c].green = Scaled(green);
2890 all_colors[c].blue = Scaled(blue);
2898 #define scaled_rgb(n) ((255 * (n)) / 1000)
2901 color_edit(bool recur GCC_UNUSED)
2902 /* display the color test pattern, without trying to edit colors */
2906 int this_c, value, field;
2912 Cannot("does not support color.");
2914 } else if (!can_change_color()) {
2915 Cannot("has hardwired color values.");
2928 page_size = (LINES - 6);
2931 for (i = 0; i < MaxColors; i++)
2932 init_pair((NCURSES_PAIRS_T) i,
2933 (NCURSES_COLOR_T) COLOR_WHITE,
2934 (NCURSES_COLOR_T) i);
2936 MvPrintw(LINES - 2, 0, "Number: %d", value);
2939 NCURSES_COLOR_T red, green, blue;
2942 MvAddStr(0, 20, "Color RGB Value Editing");
2945 for (i = (NCURSES_COLOR_T) top_color;
2946 (i - top_color < page_size)
2947 && (i < MaxColors); i++) {
2950 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2951 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2952 (i == current ? '>' : ' '),
2953 (i < (int) SIZEOF(the_color_names)
2954 ? the_color_names[i] : numeric));
2955 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2957 (void) attrset(A_NORMAL);
2959 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2961 if (current == i && field == 0)
2963 printw("%04d", (int) red);
2964 if (current == i && field == 0)
2965 (void) attrset(A_NORMAL);
2967 if (current == i && field == 1)
2969 printw("%04d", (int) green);
2970 if (current == i && field == 1)
2971 (void) attrset(A_NORMAL);
2973 if (current == i && field == 2)
2975 printw("%04d", (int) blue);
2976 if (current == i && field == 2)
2977 (void) attrset(A_NORMAL);
2978 (void) attrset(A_NORMAL);
2979 printw(" ( %3d %3d %3d )",
2980 (int) scaled_rgb(red),
2981 (int) scaled_rgb(green),
2982 (int) scaled_rgb(blue));
2985 MvAddStr(LINES - 3, 0,
2986 "Use up/down to select a color, left/right to change fields.");
2987 MvAddStr(LINES - 2, 0,
2988 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2990 move(2 + current - top_color, 0);
2994 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
3016 current -= (page_size - 1);
3023 if (current < (MaxColors - 1))
3024 current += (page_size - 1);
3031 current = (current == 0 ? (MaxColors - 1) : current - 1);
3036 current = (current == (MaxColors - 1) ? 0 : current + 1);
3041 field = (field == 2 ? 0 : field + 1);
3046 field = (field == 0 ? 2 : field - 1);
3059 value = value * 10 + (this_c - '0');
3063 change_color((NCURSES_PAIRS_T) current, field, value, 1);
3067 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
3071 change_color((NCURSES_PAIRS_T) current, field, value, 0);
3076 P(" RGB Value Editing Help");
3078 P("You are in the RGB value editor. Use the arrow keys to select one of");
3079 P("the fields in one of the RGB triples of the current colors; the one");
3080 P("currently selected will be reverse-video highlighted.");
3082 P("To change a field, enter the digits of the new value; they are echoed");
3083 P("as entered. Finish by typing `='. The change will take effect instantly.");
3084 P("To increment or decrement a value, use the same procedure, but finish");
3085 P("with a `+' or `-'.");
3087 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3089 P("Press 'm' to invoke the top-level menu with the current color settings.");
3090 P("To quit, do ESC");
3099 for (i = 0; i < MaxColors; i++)
3100 init_pair((NCURSES_PAIRS_T) i,
3101 (NCURSES_COLOR_T) COLOR_WHITE,
3102 (NCURSES_COLOR_T) i);
3116 if (current >= MaxColors)
3117 current = MaxColors - 1;
3118 if (current < top_color)
3119 top_color = current;
3120 if (current - top_color >= page_size)
3121 top_color = current - (page_size - 1);
3123 MvPrintw(LINES - 1, 0, "Number: %d", value);
3126 (!isQuit(this_c, TRUE));
3131 * ncurses does not reset each color individually when calling endwin().
3138 #endif /* HAVE_COLOR_CONTENT */
3140 /****************************************************************************
3142 * Alternate character-set stuff
3144 ****************************************************************************/
3146 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3152 if ((*at_code += 1) >= limit)
3157 *at_code = limit - 1;
3166 *attr = list[*at_code].attr;
3170 #if USE_WIDEC_SUPPORT
3172 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3178 if ((*at_code += 1) >= limit)
3183 *at_code = limit - 1;
3192 *attr = list[*at_code].attr;
3198 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3200 bool result = FALSE;
3210 if ((*fg += 1) >= COLORS)
3218 if ((*bg += 1) >= COLORS)
3226 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3229 if (init_pair(*pair,
3230 (NCURSES_COLOR_T) *fg,
3231 (NCURSES_COLOR_T) *bg) == ERR) {
3240 /****************************************************************************
3242 * Soft-key label test
3244 ****************************************************************************/
3249 #define SLK_WORK (SLK_HELP + 3)
3254 static const char *table[] =
3256 "Available commands are:"
3258 ,"^L -- repaint this message and activate soft keys"
3259 ,"a/d -- activate/disable soft keys"
3260 ,"c -- set centered format for labels"
3261 ,"l -- set left-justified format for labels"
3262 ,"r -- set right-justified format for labels"
3263 ,"[12345678] -- set label; labels are numbered 1 through 8"
3264 ,"e -- erase stdscr (should not erase labels)"
3265 ,"s -- test scrolling of shortened screen"
3266 ,"v/V -- cycle through video attributes"
3268 ,"F/f/B/b -- cycle through foreground/background colors"
3270 ,"ESC -- return to main menu"
3272 ,"Note: if activating the soft keys causes your terminal to scroll up"
3273 ,"one line, your terminal auto-scrolls when anything is written to the"
3274 ,"last screen position. The ncurses code does not yet handle this"
3280 for (j = 0; j < SIZEOF(table); ++j) {
3288 call_slk_color(int fg, int bg)
3290 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3292 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3301 slk_test(bool recur GCC_UNUSED)
3302 /* exercise the soft keys */
3307 chtype attr = A_NORMAL;
3308 unsigned at_code = 0;
3310 int fg = COLOR_BLACK;
3311 int bg = COLOR_WHITE;
3312 NCURSES_PAIRS_T pair = 0;
3314 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3315 unsigned my_size = init_attr_list(my_list, termattrs());
3320 call_slk_color(fg, bg);
3330 MvAddStr(0, 20, "Soft Key Exerciser");
3345 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3346 while ((c = Getchar()) != 'Q' && (c != ERR))
3374 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3375 _nc_STRCPY(buf, "", sizeof(buf));
3376 if ((s = slk_label(c - '0')) != 0) {
3377 _nc_STRNCPY(buf, s, (size_t) 8);
3379 wGetstring(stdscr, buf, 8);
3380 slk_set((c - '0'), buf, fmt);
3389 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3391 wnoutrefresh(stdscr);
3396 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3403 if (cycle_colors(c, &fg, &bg, &pair)) {
3405 call_slk_color(fg, bg);
3415 } while (!isQuit(c = Getchar(), TRUE));
3424 #if USE_WIDEC_SUPPORT
3427 x_slk_test(bool recur GCC_UNUSED)
3428 /* exercise the soft keys */
3431 wchar_t buf[SLKLEN + 1];
3433 attr_t attr = WA_NORMAL;
3434 unsigned at_code = 0;
3435 int fg = COLOR_BLACK;
3436 int bg = COLOR_WHITE;
3437 NCURSES_PAIRS_T pair = 0;
3438 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3439 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3443 call_slk_color(fg, bg);
3450 attr_on(WA_BOLD, NULL);
3451 MvAddStr(0, 20, "Soft Key Exerciser");
3452 attr_off(WA_BOLD, NULL);
3466 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3467 while ((c = Getchar()) != 'Q' && (c != ERR))
3495 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3497 if ((s = slk_label(c - '0')) != 0) {
3498 char *temp = strdup(s);
3499 size_t used = strlen(temp);
3500 size_t want = SLKLEN;
3502 #ifndef state_unused
3507 while (want > 0 && used != 0) {
3508 const char *base = s;
3509 reset_mbytes(state);
3510 test = count_mbytes(base, 0, &state);
3511 if (test == (size_t) -1) {
3513 } else if (test > want) {
3516 reset_mbytes(state);
3517 trans_mbytes(buf, base, want, &state);
3523 wGet_wstring(stdscr, buf, SLKLEN);
3524 slk_wset((c - '0'), buf, fmt);
3535 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3536 call_slk_color(fg, bg);
3541 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3542 call_slk_color(fg, bg);
3545 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3547 wnoutrefresh(stdscr);
3551 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3552 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3558 if (cycle_colors(c, &fg, &bg, &pair)) {
3560 call_slk_color(fg, bg);
3570 } while (!isQuit(c = Getchar(), TRUE));
3579 #endif /* SLK_INIT */
3582 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3585 unsigned last = 255;
3591 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3596 for (code = first; code <= last; ++code) {
3597 int row = (int) (2 + (code / 16));
3598 int col = (int) (5 * (code % 16));
3599 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3600 for (count = 1; count < repeat; ++count) {
3601 AddCh(colored_chtype(code, attr, pair));
3608 * Show a slice of 32 characters, allowing those to be repeated up to the
3611 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3612 * terminal to perform functions. The remaining codes can be graphic.
3615 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3618 unsigned first = (unsigned) base;
3619 unsigned last = first + (unsigned) pagesize - 2;
3620 bool C1 = (first == 128);
3625 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3626 C1 ? "C1" : "GR", first, last);
3630 for (code = first; code <= last; code++) {
3632 int row = 2 + ((int) (code - first) % (pagesize / 2));
3633 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3635 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3636 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3640 nodelay(stdscr, TRUE);
3641 echochar(colored_chtype(code, attr, pair));
3643 /* (yes, this _is_ crude) */
3644 while ((reply = Getchar()) != ERR) {
3645 AddCh(UChar(reply));
3648 nodelay(stdscr, FALSE);
3650 } while (--count > 0);
3657 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3663 MvPrintw(0, 20, "Display of PC Character Codes");
3667 for (code = 0; code < 16; ++code) {
3668 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3670 for (code = 0; code < 256; code++) {
3672 int row = 3 + (int) (code / 16) + (code >= 128);
3673 int col = 8 + (int) (code % 16) * PC_COLS;
3674 if ((code % 16) == 0)
3675 MvPrintw(row, 0, "0x%02x:", code);
3686 * Skip the ones that do not work.
3690 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3693 } while (--count > 0);
3698 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3702 attr |= (attr_t) COLOR_PAIR(pair);
3706 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3711 colored_chtype(ACS_VLINE, attr, pair),
3712 colored_chtype(ACS_VLINE, attr, pair),
3713 colored_chtype(ACS_HLINE, attr, pair),
3714 colored_chtype(ACS_HLINE, attr, pair),
3715 colored_chtype(ACS_ULCORNER, attr, pair),
3716 colored_chtype(ACS_URCORNER, attr, pair),
3717 colored_chtype(ACS_LLCORNER, attr, pair),
3718 colored_chtype(ACS_LRCORNER, attr, pair));
3719 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3720 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3721 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3722 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3723 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3724 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3725 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3731 show_1_acs(int n, int repeat, const char *name, chtype code)
3733 const int height = 16;
3734 int row = 2 + (n % height);
3735 int col = (n / height) * COLS / 2;
3737 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3740 } while (--repeat > 0);
3745 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3746 /* display the ACS character set */
3750 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3754 MvAddStr(0, 20, "Display of the ACS Character Set");
3758 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3759 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3760 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3761 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3763 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3764 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3765 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3766 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3768 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3769 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3772 * HPUX's ACS definitions are broken here. Just give up.
3774 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3775 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3776 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3777 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3778 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3780 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3781 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3782 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3783 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3784 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3785 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3786 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3787 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3788 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3790 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3791 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3792 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3794 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3795 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3796 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3797 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3798 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3799 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3805 acs_test(bool recur GCC_UNUSED)
3809 char *term = getenv("TERM");
3810 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3813 chtype attr = A_NORMAL;
3816 int fg = COLOR_BLACK;
3817 int bg = COLOR_BLACK;
3818 unsigned at_code = 0;
3819 NCURSES_PAIRS_T pair = 0;
3820 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3821 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3822 unsigned my_size = init_attr_list(my_list, termattrs());
3830 ToggleAcs(last_show_acs, show_acs_chars);
3834 ToggleAcs(last_show_acs, show_pc_chars);
3839 if (pagesize == 32) {
3846 ToggleAcs(last_show_acs, show_box_chars);
3872 if (repeat < (COLS / 4))
3880 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3881 || cycle_colors(c, &fg, &bg, &pair)) {
3888 if (pagesize != 32) {
3889 show_256_chars(repeat, attr, pair);
3890 } else if (last_show_acs != 0) {
3891 last_show_acs(repeat, attr, pair);
3893 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3896 MvPrintw(LINES - 3, 0,
3897 "Note: ANSI terminals may not display C1 characters.");
3898 MvPrintw(LINES - 2, 0,
3899 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3902 MvPrintw(LINES - 1, 0,
3903 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3904 my_list[at_code].name,
3907 MvPrintw(LINES - 1, 0,
3908 "v/V cycles through video attributes (%s).",
3909 my_list[at_code].name);
3912 } while (!isQuit(c = Getchar(), TRUE));
3920 #if USE_WIDEC_SUPPORT
3922 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3928 TEST_CCHAR(src, count, {
3929 attr |= (test_attrs & A_ALTCHARSET);
3930 setcchar(dst, test_wch, attr, pair, NULL);
3940 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3941 * display. If there are no repeats, we could normally display 16 lines of 64
3942 * characters (1024 total). However, taking repeats and double-width cells
3943 * into account, use 256 characters for the page.
3946 show_paged_widechars(int base,
3951 NCURSES_PAIRS_T pair)
3953 int first = base * pagesize;
3954 int last = first + pagesize - 1;
3962 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3965 for (code = (wchar_t) first; (int) code <= last; code++) {
3966 int row = (2 + ((int) code - first) / per_line);
3967 int col = 5 * ((int) code % per_line);
3970 memset(&codes, 0, sizeof(codes));
3972 setcchar(&temp, codes, attr, pair, 0);
3974 if (wcwidth(code) == 0 && code != 0) {
3975 AddCh((chtype) space |
3976 (A_REVERSE ^ attr) |
3977 (attr_t) COLOR_PAIR(pair));
3980 for (count = 1; count < repeat; ++count) {
3987 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3991 int last = first + 31;
3995 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3998 for (code = (wchar_t) first; (int) code <= last; code++) {
3999 int row = 2 + ((code - first) % 16);
4000 int col = ((code - first) / 16) * COLS / 2;
4006 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
4007 "%3ld (0x%lx)", (long) code, (long) code);
4008 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
4010 memset(&codes, 0, sizeof(codes));
4012 setcchar(&temp, codes, attr, pair, 0);
4016 * Give non-spacing characters something to combine with. If we
4017 * don't, they'll bunch up in a heap on the space after the ":".
4018 * Mark them with reverse-video to make them simpler to find on
4021 if (wcwidth(code) == 0) {
4022 AddCh((chtype) space |
4023 (A_REVERSE ^ attr) |
4024 (attr_t) COLOR_PAIR(pair));
4027 * This uses echo_wchar(), for comparison with the normal 'f'
4028 * test (and to make a test-case for echo_wchar()). The screen
4029 * may flicker because the erase() at the top of the function
4030 * is met by the builtin refresh() in echo_wchar().
4034 * The repeat-count may make text wrap - avoid that.
4036 getyx(stdscr, y, x);
4038 if (x >= col + (COLS / 2) - 2)
4040 } while (--count > 0);
4045 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
4047 const int height = 16;
4048 int row = 2 + (n % height);
4049 int col = (n / height) * COLS / 2;
4051 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4052 while (--repeat >= 0) {
4058 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
4061 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4062 /* display the wide-ACS character set */
4068 /*#define BOTH2(name) #name, &(name) */
4069 #define BOTH2(name) #name, MERGE_ATTR(name)
4073 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4077 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
4078 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
4079 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
4080 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
4082 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
4083 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
4084 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
4085 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
4087 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4088 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4090 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4091 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4092 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4093 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4095 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4096 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4097 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4098 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4099 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4100 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4101 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4102 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4103 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4105 #ifdef CURSES_WACS_ARRAY
4106 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4107 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4108 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4110 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4111 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4114 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4115 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4121 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4122 /* display the wide-ACS character set */
4128 /*#define BOTH2(name) #name, &(name) */
4129 #define BOTH2(name) #name, MERGE_ATTR(name)
4133 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4137 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4138 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4139 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4140 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4142 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4143 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4144 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4145 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4147 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4148 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4150 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4151 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4152 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4153 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4155 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4156 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4157 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4158 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4159 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4160 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4161 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4162 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4163 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4165 #ifdef CURSES_WACS_ARRAY
4166 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4167 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4168 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4170 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4171 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4172 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4173 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4174 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4175 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4182 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4183 /* display the wide-ACS character set */
4189 /*#define BOTH2(name) #name, &(name) */
4190 #define BOTH2(name) #name, MERGE_ATTR(name)
4194 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4198 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4199 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4200 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4201 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4203 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4204 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4205 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4206 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4208 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4209 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4211 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4212 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4213 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4214 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4216 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4217 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4218 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4219 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4220 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4221 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4222 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4223 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4224 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4226 #ifdef CURSES_WACS_ARRAY
4227 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4228 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4229 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4231 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4232 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4233 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4234 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4235 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4236 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4243 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4246 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4253 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4258 MERGE_ATTR(0, WACS_VLINE),
4259 MERGE_ATTR(1, WACS_VLINE),
4260 MERGE_ATTR(2, WACS_HLINE),
4261 MERGE_ATTR(3, WACS_HLINE),
4262 MERGE_ATTR(4, WACS_ULCORNER),
4263 MERGE_ATTR(5, WACS_URCORNER),
4264 MERGE_ATTR(6, WACS_LLCORNER),
4265 MERGE_ATTR(7, WACS_LRCORNER));
4267 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4268 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4269 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4270 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4271 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4272 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4273 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4281 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4283 const int height = 16;
4284 int row = 2 + (n % height);
4285 int col = (n / height) * COLS / 2;
4288 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4289 (void) attr_set(attr, pair, 0);
4290 _nc_STRNCPY(temp, code, 20);
4292 (void) attr_set(A_NORMAL, 0, 0);
4296 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4299 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4306 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4310 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4311 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4312 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4313 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4315 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4316 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4317 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4318 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4320 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4321 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4323 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4324 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4325 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4326 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4328 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4329 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4330 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4331 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4332 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4333 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4334 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4335 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4336 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4337 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4338 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4339 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4341 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4342 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4343 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4344 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4345 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4346 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4351 /* display the wide-ACS character set */
4353 x_acs_test(bool recur GCC_UNUSED)
4360 attr_t attr = WA_NORMAL;
4361 int fg = COLOR_BLACK;
4362 int bg = COLOR_BLACK;
4363 unsigned at_code = 0;
4364 NCURSES_PAIRS_T pair = 0;
4365 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4366 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4367 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4375 ToggleAcs(last_show_wacs, show_wacs_chars);
4379 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4384 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4388 if (pagesize == 32) {
4395 ToggleAcs(last_show_wacs, show_wbox_chars);
4398 ToggleAcs(last_show_wacs, show_utf8_chars);
4401 if (c < 256 && isdigit(c)) {
4404 } else if (c == '+') {
4407 } else if (c == '-' && digit > 0) {
4410 } else if (c == '>' && repeat < (COLS / 4)) {
4412 } else if (c == '<' && repeat > 1) {
4414 } else if (c == '_') {
4415 space = (space == ' ') ? '_' : ' ';
4417 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4418 || cycle_colors(c, &fg, &bg, &pair)) {
4419 if (last_show_wacs != 0)
4427 if (pagesize != 32) {
4428 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4429 } else if (last_show_wacs != 0) {
4430 last_show_wacs(repeat, attr, pair);
4432 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4435 MvPrintw(LINES - 4, 0,
4436 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
4437 MvPrintw(LINES - 3, 2,
4438 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4440 MvPrintw(LINES - 2, 2,
4441 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4442 my_list[at_code].name,
4445 MvPrintw(LINES - 2, 2,
4446 "v/V cycles through video attributes (%s).",
4447 my_list[at_code].name);
4450 } while (!isQuit(c = Getchar(), TRUE));
4461 * Graphic-rendition test (adapted from vttest)
4464 sgr_attr_test(bool recur GCC_UNUSED)
4468 for (pass = 0; pass < 2; pass++) {
4469 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4471 /* Use non-default colors if possible to exercise bce a little */
4473 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4474 normal |= (chtype) COLOR_PAIR(1);
4478 MvPrintw(1, 20, "Graphic rendition test pattern:");
4480 MvPrintw(4, 1, "vanilla");
4482 #define set_sgr(mask) bkgdset((normal^(mask)));
4484 MvPrintw(4, 40, "bold");
4486 set_sgr(A_UNDERLINE);
4487 MvPrintw(6, 6, "underline");
4489 set_sgr(A_BOLD | A_UNDERLINE);
4490 MvPrintw(6, 45, "bold underline");
4493 MvPrintw(8, 1, "blink");
4495 set_sgr(A_BLINK | A_BOLD);
4496 MvPrintw(8, 40, "bold blink");
4498 set_sgr(A_UNDERLINE | A_BLINK);
4499 MvPrintw(10, 6, "underline blink");
4501 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4502 MvPrintw(10, 45, "bold underline blink");
4505 MvPrintw(12, 1, "negative");
4507 set_sgr(A_BOLD | A_REVERSE);
4508 MvPrintw(12, 40, "bold negative");
4510 set_sgr(A_UNDERLINE | A_REVERSE);
4511 MvPrintw(14, 6, "underline negative");
4513 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4514 MvPrintw(14, 45, "bold underline negative");
4516 set_sgr(A_BLINK | A_REVERSE);
4517 MvPrintw(16, 1, "blink negative");
4519 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4520 MvPrintw(16, 40, "bold blink negative");
4522 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4523 MvPrintw(18, 6, "underline blink negative");
4525 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4526 MvPrintw(18, 45, "bold underline blink negative");
4529 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4535 bkgdset(A_NORMAL | BLANK);
4541 /****************************************************************************
4543 * Windows and scrolling tester.
4545 ****************************************************************************/
4547 #define BOTLINES 4 /* number of line stolen from screen bottom */
4553 #define FRAME struct frame
4562 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4563 #if (NCURSES_VERSION_PATCH < 20070331)
4564 #define is_keypad(win) (win)->_use_keypad
4565 #define is_scrollok(win) (win)->_scroll
4568 #define is_keypad(win) FALSE
4569 #define is_scrollok(win) FALSE
4573 frame_win(FRAME * curp)
4575 return (curp != 0) ? curp->wind : stdscr;
4578 /* We need to know if these flags are actually set, so don't look in FRAME.
4579 * These names are known to work with SVr4 curses as well as ncurses. The
4580 * _use_keypad name does not work with Solaris 8.
4583 HaveKeypad(FRAME * curp)
4585 WINDOW *win = frame_win(curp);
4587 return is_keypad(win);
4591 HaveScroll(FRAME * curp)
4593 WINDOW *win = frame_win(curp);
4595 return is_scrollok(win);
4599 newwin_legend(FRAME * curp)
4601 #define DATA(num, name) { name, num }
4602 static const struct {
4606 DATA(0, "^C = create window"),
4607 DATA(0, "^N = next window"),
4608 DATA(0, "^P = previous window"),
4609 DATA(0, "^F = scroll forward"),
4610 DATA(0, "^B = scroll backward"),
4611 DATA(1, "^K = keypad(%s)"),
4612 DATA(2, "^S = scrollok(%s)"),
4613 DATA(0, "^W = save window"),
4614 DATA(0, "^R = restore window"),
4616 DATA(0, "^X = resize"),
4618 DATA(3, "^Q%s = exit")
4623 bool do_keypad = HaveKeypad(curp);
4624 bool do_scroll = HaveScroll(curp);
4628 for (n = 0; n < SIZEOF(legend); n++) {
4629 switch (legend[n].code) {
4631 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4634 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4635 legend[n].msg, do_keypad ? "yes" : "no");
4638 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4639 legend[n].msg, do_scroll ? "yes" : "no");
4642 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4643 legend[n].msg, do_keypad ? "/ESC" : "");
4646 x = getcurx(stdscr);
4647 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4654 transient(FRAME * curp, NCURSES_CONST char *msg)
4656 newwin_legend(curp);
4658 MvAddStr(LINES - 1, 0, msg);
4664 printw("%s characters are echoed, window should %sscroll.",
4665 HaveKeypad(curp) ? "Non-arrow" : "All other",
4666 HaveScroll(curp) ? "" : "not ");
4671 newwin_report(FRAME * curp)
4672 /* report on the cursor's current position, then restore it */
4674 WINDOW *win = frame_win(curp);
4678 transient(curp, (char *) 0);
4680 move(LINES - 1, COLS - 17);
4681 printw("Y = %2d X = %2d", y, x);
4689 selectcell(int uli, int ulj, int lri, int lrj)
4690 /* arrows keys move cursor, return location at current on non-arrow key */
4692 static pair res; /* result cell */
4693 int si = lri - uli + 1; /* depth of the select area */
4694 int sj = lrj - ulj + 1; /* width of the select area */
4695 int i = 0, j = 0; /* offsets into the select area */
4700 move(uli + i, ulj + j);
4701 newwin_report((FRAME *) 0);
4703 switch (Getchar()) {
4717 return ((pair *) 0);
4718 #ifdef NCURSES_MOUSE_VERSION
4724 if (event.y > uli && event.x > ulj) {
4745 outerbox(pair ul, pair lr, bool onoff)
4746 /* draw or erase a box *outside* the given pair of corners */
4748 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4749 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4750 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4751 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4752 move(ul.y - 1, ul.x);
4753 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4754 move(ul.y, ul.x - 1);
4755 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4756 move(lr.y + 1, ul.x);
4757 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4758 move(ul.y, lr.x + 1);
4759 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4764 /* Ask user for a window definition */
4771 addstr("Use arrows to move cursor, anything else to mark corner 1");
4773 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4774 return ((WINDOW *) 0);
4775 memcpy(&ul, tmp, sizeof(pair));
4776 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4779 addstr("Use arrows to move cursor, anything else to mark corner 2");
4781 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4783 return ((WINDOW *) 0);
4784 memcpy(&lr, tmp, sizeof(pair));
4786 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4788 outerbox(ul, lr, TRUE);
4800 newwin_move(FRAME * curp, int dy, int dx)
4802 WINDOW *win = frame_win(curp);
4806 getyx(win, cur_y, cur_x);
4807 getmaxyx(win, max_y, max_x);
4808 if ((cur_x += dx) < 0)
4810 else if (cur_x >= max_x)
4812 if ((cur_y += dy) < 0)
4814 else if (cur_y >= max_y)
4816 wmove(win, cur_y, cur_x);
4820 delete_framed(FRAME * fp, bool showit)
4825 fp->last->next = fp->next;
4826 fp->next->last = fp->last;
4834 np = (fp == fp->next) ? NULL : fp->next;
4841 scroll_test(bool recur GCC_UNUSED)
4842 /* Demonstrate windows */
4845 FRAME *current = (FRAME *) 0, *neww;
4847 #if HAVE_PUTWIN && HAVE_GETWIN
4851 #define DUMPFILE "screendump"
4853 #ifdef NCURSES_MOUSE_VERSION
4854 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4859 transient((FRAME *) 0, (char *) 0);
4862 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4863 failed("scroll_test");
4866 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4867 failed("scroll_test");
4872 if (current == 0) { /* First element, */
4873 neww->next = neww; /* so point it at itself */
4876 neww->next = current->next;
4877 neww->last = current;
4878 neww->last->next = neww;
4879 neww->next->last = neww;
4882 /* SVr4 curses sets the keypad on all newly-created windows to
4883 * false. Someone reported that PDCurses makes new windows inherit
4884 * this flag. Remove the following 'keypad()' call to test this
4886 keypad(current->wind, TRUE);
4887 current->do_keypad = HaveKeypad(current);
4888 current->do_scroll = HaveScroll(current);
4891 case CTRL('N'): /* go to next window */
4893 current = current->next;
4896 case CTRL('P'): /* go to previous window */
4898 current = current->last;
4901 case CTRL('F'): /* scroll current window forward */
4903 wscrl(frame_win(current), 1);
4906 case CTRL('B'): /* scroll current window backwards */
4908 wscrl(frame_win(current), -1);
4911 case CTRL('K'): /* toggle keypad mode for current */
4913 current->do_keypad = !current->do_keypad;
4914 keypad(current->wind, current->do_keypad);
4920 current->do_scroll = !current->do_scroll;
4921 scrollok(current->wind, current->do_scroll);
4925 #if HAVE_PUTWIN && HAVE_GETWIN
4926 case CTRL('W'): /* save and delete window */
4927 if ((current != 0) && (current == current->next)) {
4928 transient(current, "Will not save/delete ONLY window");
4930 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4931 transient(current, "Can't open screen dump file");
4933 int rc = putwin(frame_win(current), fp);
4937 current = delete_framed(current, TRUE);
4939 transient(current, "Can't write screen dump file");
4944 case CTRL('R'): /* restore window */
4945 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4946 transient(current, "Can't open screen dump file");
4948 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4950 neww->next = current ? current->next : 0;
4951 neww->last = current;
4952 if (neww->last != 0)
4953 neww->last->next = neww;
4954 if (neww->next != 0)
4955 neww->next->last = neww;
4957 neww->wind = getwin(fp);
4959 wrefresh(neww->wind);
4961 failed("scroll_test");
4969 case CTRL('X'): /* resize window */
4976 addstr("Use arrows to move cursor, anything else to mark new corner");
4979 getbegyx(current->wind, ul.y, ul.x);
4981 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4982 if (tmp == (pair *) 0) {
4987 getmaxyx(current->wind, lr.y, lr.x);
4990 outerbox(ul, lr, FALSE);
4991 wnoutrefresh(stdscr);
4993 /* strictly cosmetic hack for the test */
4994 getmaxyx(current->wind, my, mx);
4995 if (my > tmp->y - ul.y) {
4996 getyx(current->wind, lr.y, lr.x);
4997 wmove(current->wind, tmp->y - ul.y + 1, 0);
4998 wclrtobot(current->wind);
4999 wmove(current->wind, lr.y, lr.x);
5001 if (mx > tmp->x - ul.x)
5002 for (i = 0; i < my; i++) {
5003 wmove(current->wind, i, tmp->x - ul.x + 1);
5004 wclrtoeol(current->wind);
5006 wnoutrefresh(current->wind);
5008 memcpy(&lr, tmp, sizeof(pair));
5009 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
5011 getbegyx(current->wind, ul.y, ul.x);
5012 getmaxyx(current->wind, lr.y, lr.x);
5015 outerbox(ul, lr, TRUE);
5016 wnoutrefresh(stdscr);
5018 wnoutrefresh(current->wind);
5024 #endif /* HAVE_WRESIZE */
5027 newwin_move(current, -1, 0);
5030 newwin_move(current, 1, 0);
5033 newwin_move(current, 0, -1);
5036 newwin_move(current, 0, 1);
5044 getyx(frame_win(current), y, x);
5048 x = getmaxx(frame_win(current)) - 1;
5050 (void) mvwdelch(frame_win(current), y, x);
5060 waddch(current->wind, (chtype) c);
5065 newwin_report(current);
5066 usescr = frame_win(current);
5069 (!isQuit(c = wGetchar(usescr), TRUE)
5073 while (current != 0)
5074 current = delete_framed(current, FALSE);
5076 scrollok(stdscr, TRUE); /* reset to driver's default */
5077 #ifdef NCURSES_MOUSE_VERSION
5078 mousemask(0, (mmask_t *) 0);
5086 /****************************************************************************
5090 ****************************************************************************/
5093 static int nap_msec = 1;
5095 static NCURSES_CONST char *mod[] =
5105 /*+-------------------------------------------------------------------------
5107 --------------------------------------------------------------------------*/
5109 wait_a_while(int msec GCC_UNUSED)
5119 else if (msec > 1000)
5120 sleep((unsigned) msec / 1000);
5124 } /* end of wait_a_while */
5126 /*+-------------------------------------------------------------------------
5128 --------------------------------------------------------------------------*/
5130 saywhat(NCURSES_CONST char *text)
5132 wmove(stdscr, LINES - 1, 0);
5134 if (text != 0 && *text != '\0') {
5135 waddstr(stdscr, text);
5136 waddstr(stdscr, "; ");
5138 waddstr(stdscr, "press any key to continue");
5139 } /* end of saywhat */
5141 /*+-------------------------------------------------------------------------
5142 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
5143 --------------------------------------------------------------------------*/
5145 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
5150 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
5151 if ((pan = new_panel(win)) == 0) {
5153 } else if (UseColors) {
5154 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
5157 NCURSES_COLOR_T bg = color;
5159 init_pair(color, fg, bg);
5160 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
5162 wbkgdset(win, A_BOLD | ' ');
5166 } /* end of mkpanel */
5168 /*+-------------------------------------------------------------------------
5170 --------------------------------------------------------------------------*/
5174 WINDOW *win = panel_window(pan);
5177 } /* end of rmpanel */
5179 /*+-------------------------------------------------------------------------
5181 --------------------------------------------------------------------------*/
5187 } /* end of pflush */
5189 /*+-------------------------------------------------------------------------
5191 --------------------------------------------------------------------------*/
5193 init_panel(WINDOW *win)
5197 for (y = 0; y < LINES - 1; y++) {
5198 for (x = 0; x < COLS; x++)
5199 wprintw(win, "%d", (y + x) % 10);
5204 fill_panel(PANEL *pan)
5206 WINDOW *win = panel_window(pan);
5207 const char *userptr = (const char *) panel_userptr(pan);
5208 int num = (userptr && *userptr) ? userptr[1] : '?';
5212 wprintw(win, "-pan%c-", num);
5215 for (y = 2; y < getmaxy(win) - 1; y++) {
5216 for (x = 1; x < getmaxx(win) - 1; x++) {
5218 waddch(win, UChar(num));
5223 #if USE_WIDEC_SUPPORT
5225 init_wide_panel(WINDOW *win)
5230 for (digit = 0; digit < 10; ++digit)
5231 make_fullwidth_digit(&temp[digit], digit);
5235 getyx(stdscr, y, x);
5236 digit = (y + x / 2) % 10;
5237 } while (wadd_wch(win, &temp[digit]) != ERR);
5241 fill_wide_panel(PANEL *pan)
5243 WINDOW *win = panel_window(pan);
5244 const char *userptr = (const char *) panel_userptr(pan);
5245 int num = (userptr && *userptr) ? userptr[1] : '?';
5249 wprintw(win, "-pan%c-", num);
5252 for (y = 2; y < getmaxy(win) - 1; y++) {
5253 for (x = 1; x < getmaxx(win) - 1; x++) {
5255 waddch(win, UChar(num));
5261 #define MAX_PANELS 5
5264 canned_panel(PANEL *px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
5266 int which = cmd[1] - '0';
5271 hide_panel(px[which]);
5274 show_panel(px[which]);
5277 top_panel(px[which]);
5280 bottom_panel(px[which]);
5287 wait_a_while(nap_msec);
5291 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
5295 PANEL *px[MAX_PANELS + 1];
5297 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5301 for (count = 0; count < 5; count++) {
5302 px[1] = mkpanel(COLOR_RED,
5307 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
5309 px[2] = mkpanel(COLOR_GREEN,
5314 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5316 px[3] = mkpanel(COLOR_YELLOW,
5321 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5323 px[4] = mkpanel(COLOR_BLUE,
5328 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5330 px[5] = mkpanel(COLOR_MAGENTA,
5335 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5347 wait_a_while(nap_msec);
5349 saywhat("h3 s1 s2 s4 s5");
5350 move_panel(px[1], 0, 0);
5357 wait_a_while(nap_msec);
5359 canned_panel(px, "s1");
5360 canned_panel(px, "s2");
5363 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5365 wait_a_while(nap_msec);
5367 canned_panel(px, "s3");
5370 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5372 wait_a_while(nap_msec);
5374 canned_panel(px, "b3");
5375 canned_panel(px, "s4");
5376 canned_panel(px, "s5");
5377 canned_panel(px, "t3");
5378 canned_panel(px, "t1");
5379 canned_panel(px, "t2");
5380 canned_panel(px, "t3");
5381 canned_panel(px, "t4");
5383 for (itmp = 0; itmp < 6; itmp++) {
5384 WINDOW *w4 = panel_window(px[4]);
5385 WINDOW *w5 = panel_window(px[5]);
5388 wmove(w4, LINES / 8, 1);
5389 waddstr(w4, mod[itmp]);
5390 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5391 wmove(w5, LINES / 6, 1);
5392 waddstr(w5, mod[itmp]);
5394 wait_a_while(nap_msec);
5397 wmove(w4, LINES / 6, 1);
5398 waddstr(w4, mod[itmp]);
5399 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5400 wmove(w5, LINES / 8, 1);
5401 waddstr(w5, mod[itmp]);
5403 wait_a_while(nap_msec);
5407 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5409 wait_a_while(nap_msec);
5411 canned_panel(px, "t5");
5412 canned_panel(px, "t2");
5413 canned_panel(px, "t1");
5414 canned_panel(px, "d2");
5415 canned_panel(px, "h3");
5416 canned_panel(px, "d1");
5417 canned_panel(px, "d4");
5418 canned_panel(px, "d5");
5419 canned_panel(px, "d3");
5421 wait_a_while(nap_msec);
5434 panel_test(bool recur GCC_UNUSED)
5436 return demo_panels(init_panel, fill_panel);
5440 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
5442 x_panel_test(bool recur GCC_UNUSED)
5444 return demo_panels(init_wide_panel, fill_wide_panel);
5447 #endif /* USE_LIBPANEL */
5449 /****************************************************************************
5453 ****************************************************************************/
5457 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
5458 * though we can rely on negative x/y values to stop the macro.
5461 do_h_line(int y, int x, chtype c, int to)
5464 MvHLine(y, x, c, (to) - (x));
5468 do_v_line(int y, int x, chtype c, int to)
5471 MvVLine(y, x, c, (to) - (y));
5476 static bool pending_pan = FALSE;
5477 static bool show_panner_legend = TRUE;
5480 panner_legend(int line)
5482 static const char *const legend[] =
5484 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5485 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5486 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5487 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5489 int n = ((int) SIZEOF(legend) - (LINES - line));
5491 if (move(line, 0) != ERR) {
5492 if (show_panner_legend)
5493 printw("%s", legend[n]);
5495 return show_panner_legend;
5502 panner_h_cleanup(int from_y, int from_x, int to_x)
5504 if (!panner_legend(from_y))
5505 do_h_line(from_y, from_x, ' ', to_x);
5509 panner_v_cleanup(int from_y, int from_x, int to_y)
5511 if (!panner_legend(from_y))
5512 do_v_line(from_y, from_x, ' ', to_y);
5516 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5519 unsigned gridcount = 0;
5523 fill = (chtype) COLOR_PAIR(1);
5526 wmove(panpad, 0, 0);
5527 for (y = 0; y < getmaxy(panpad); y++) {
5528 for (x = 0; x < getmaxx(panpad); x++) {
5529 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5530 if (y == 0 && x == 0)
5531 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5533 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5534 else if (y == 0 || x == 0)
5535 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5537 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5538 (int) (gridcount++ % 26)) | fill);
5539 } else if (y % GRIDSIZE == 0)
5540 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5541 else if (x % GRIDSIZE == 0)
5542 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5544 waddch(panpad, ' ');
5551 int top_x, int top_y, int porty, int portx,
5552 int (*pgetc) (WINDOW *),
5555 #if HAVE_GETTIMEOFDAY
5556 struct timeval before, after;
5559 bool pan_lines = FALSE;
5560 bool scrollers = TRUE;
5563 int pxmax, pymax, lowend, highend, c;
5565 getmaxyx(pad, pymax, pxmax);
5566 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5570 #ifdef NCURSES_VERSION
5572 * During shell-out, the user may have resized the window. Adjust
5573 * the port size of the pad to accommodate this. Ncurses automatically
5574 * resizes all of the normal windows to fit on the new screen.
5591 if (c == HELP_KEY_1)
5592 show_panner_legend = !show_panner_legend;
5593 panner_legend(LINES - 4);
5594 panner_legend(LINES - 3);
5595 panner_legend(LINES - 2);
5596 panner_legend(LINES - 1);
5599 pan_lines = !pan_lines;
5600 fill_pad(pad, pan_lines, colored);
5601 pending_pan = FALSE;
5604 #if HAVE_GETTIMEOFDAY
5608 panner_legend(LINES - 1);
5612 scrollers = !scrollers;
5615 /* Move the top-left corner of the pad, keeping the bottom-right
5618 case 'h': /* increase-columns: move left edge to left */
5622 panner_v_cleanup(top_y, top_x, porty);
5627 case 'j': /* decrease-lines: move top-edge down */
5631 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5636 case 'k': /* increase-lines: move top-edge up */
5641 panner_h_cleanup(top_y, top_x, portx);
5645 case 'l': /* decrease-columns: move left-edge to right */
5649 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5654 /* Move the bottom-right corner of the pad, keeping the top-left
5657 case KEY_IC: /* increase-columns: move right-edge to right */
5658 if (portx >= pxmax || portx >= COLS)
5661 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5666 case KEY_IL: /* increase-lines: move bottom-edge down */
5667 if (porty >= pymax || porty >= LINES)
5670 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5675 case KEY_DC: /* decrease-columns: move bottom edge up */
5680 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5684 case KEY_DL: /* decrease-lines */
5689 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5693 case KEY_LEFT: /* pan leftwards */
5700 case KEY_RIGHT: /* pan rightwards */
5701 if (basex + portx - (pymax > porty) < pxmax)
5707 case KEY_UP: /* pan upwards */
5714 case KEY_DOWN: /* pan downwards */
5715 if (basey + porty - (pxmax > portx) < pymax)
5730 basey = pymax - porty;
5740 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5741 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5742 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5744 if (scrollers && (pxmax > portx - 1)) {
5745 int length = (portx - top_x - 1);
5746 float ratio = ((float) length) / ((float) pxmax);
5748 lowend = (int) ((float) top_x + ((float) basex * ratio));
5749 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5751 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5752 if (highend < portx) {
5754 do_h_line(porty - 1, lowend, ' ', highend + 1);
5756 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5759 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5761 if (scrollers && (pymax > porty - 1)) {
5762 int length = (porty - top_y - 1);
5763 float ratio = ((float) length) / ((float) pymax);
5765 lowend = (int) ((float) top_y + ((float) basey * ratio));
5766 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5768 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5769 if (highend < porty) {
5771 do_v_line(lowend, portx - 1, ' ', highend + 1);
5773 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5776 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5778 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5779 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5780 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5783 #if HAVE_GETTIMEOFDAY
5784 gettimeofday(&before, 0);
5786 wnoutrefresh(stdscr);
5791 porty - (pxmax > portx) - 1,
5792 portx - (pymax > porty) - 1);
5795 #if HAVE_GETTIMEOFDAY
5796 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5799 gettimeofday(&after, 0);
5800 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5801 move(LINES - 1, COLS - 12);
5802 printw("Secs: %2.03f", elapsed);
5809 ((c = pgetc(pad)) != KEY_EXIT);
5811 scrollok(stdscr, TRUE); /* reset to driver's default */
5815 padgetch(WINDOW *win)
5821 if ((pending_pan = (count > 0)) != FALSE) {
5823 pending_pan = (count != 0);
5826 switch (c = wGetchar(win)) {
5862 case ERR: /* FALLTHRU */
5868 if (c >= '0' && c <= '9') {
5869 count = count * 10 + (c - '0');
5883 #define PAD_HIGH 200
5884 #define PAD_WIDE 200
5887 pad_test(bool recur GCC_UNUSED)
5888 /* Demonstrate pads. */
5890 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5893 Cannot("cannot create requested pad");
5898 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5899 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5900 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5903 fill_pad(panpad, FALSE, TRUE);
5905 panner_legend(LINES - 4);
5906 panner_legend(LINES - 3);
5907 panner_legend(LINES - 2);
5908 panner_legend(LINES - 1);
5910 keypad(panpad, TRUE);
5912 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5913 * We'll still be able to widen it during a test, since that's required
5914 * for testing boundaries.
5916 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, TRUE);
5923 #endif /* HAVE_NEWPAD */
5925 /****************************************************************************
5927 * Tests from John Burnell's PDCurses tester
5929 ****************************************************************************/
5932 Continue(WINDOW *win)
5936 MvWAddStr(win, 10, 1, " Press any key to continue");
5942 flushinp_test(bool recur GCC_UNUSED)
5943 /* Input test, adapted from John Burnell's PDCurses tester */
5945 WINDOW *win = stdscr;
5946 int w, h, bx, by, sw, sh, i;
5951 getmaxyx(win, h, w);
5952 getbegyx(win, by, bx);
5955 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5960 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5961 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
5964 (void) wattrset(subWin, A_BOLD);
5965 box(subWin, ACS_VLINE, ACS_HLINE);
5966 MvWAddStr(subWin, 2, 1, "This is a subwindow");
5970 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5971 * it only happened to "work" on SVr4 because that implementation does not
5972 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5973 * test behavior, we're using 'cbreak()', which will allow a single
5974 * character to return without needing a newline. - T.Dickey 1997/10/11.
5977 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
5979 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
5980 MvWAddStr(win, 3, 1,
5981 "These should be discarded (not echoed) after the subwindow goes away.");
5984 for (i = 0; i < 5; i++) {
5985 MvWPrintw(subWin, 1, 1, "Time = %d", i);
5997 MvWAddStr(win, 2, 1,
5998 "If you were still typing when the window timer expired,");
5999 MvWAddStr(win, 3, 1,
6000 "or else you typed nothing at all while it was running,");
6001 MvWAddStr(win, 4, 1,
6002 "test was invalid. You'll see garbage or nothing at all. ");
6003 MvWAddStr(win, 6, 1, "Press a key");
6009 MvWAddStr(win, 12, 0,
6010 "If you see any key other than what you typed, flushinp() is broken.");
6019 "What you typed should now have been deleted; if not, wdelch() failed.");
6026 /****************************************************************************
6030 ****************************************************************************/
6038 menu_virtualize(int c)
6040 if (c == '\n' || c == KEY_EXIT)
6041 return (MAX_COMMAND + 1);
6043 return (REQ_SCR_ULINE);
6045 return (REQ_SCR_DLINE);
6046 else if (c == 'b' || c == KEY_NPAGE)
6047 return (REQ_SCR_UPAGE);
6048 else if (c == 'f' || c == KEY_PPAGE)
6049 return (REQ_SCR_DPAGE);
6050 else if (c == 'n' || c == KEY_DOWN)
6051 return (REQ_NEXT_ITEM);
6052 else if (c == 'p' || c == KEY_UP)
6053 return (REQ_PREV_ITEM);
6055 return (REQ_TOGGLE_ITEM);
6063 static CONST_MENUS char *animals[] =
6076 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6077 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
6082 menu_test(bool recur GCC_UNUSED)
6085 ITEM *items[SIZEOF(animals)];
6087 CONST_MENUS char **ap;
6088 int mrows, mcols, c;
6091 #ifdef NCURSES_MOUSE_VERSION
6092 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6094 MvAddStr(0, 0, "This is the menu test:");
6095 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
6096 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
6098 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
6099 MvAddStr(5, 0, " Press return to exit.");
6102 for (ap = animals; *ap; ap++) {
6103 if ((*ip = new_item(*ap, "")) != 0)
6108 m = new_menu(items);
6110 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
6111 scale_menu(m, &mrows, &mcols);
6113 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6114 set_menu_win(m, menuwin);
6115 keypad(menuwin, TRUE);
6118 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6122 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
6123 if (c == E_NOT_POSTED)
6125 if (c == E_REQUEST_DENIED)
6130 MvPrintw(LINES - 2, 0,
6131 "You chose: %s\n", item_name(current_item(m)));
6132 (void) addstr("Press any key to continue...");
6139 for (ip = items; *ip; ip++)
6141 #ifdef NCURSES_MOUSE_VERSION
6142 mousemask(0, (mmask_t *) 0);
6148 #define T_TBL(name) { #name, name }
6154 T_TBL(TRACE_DISABLE),
6157 T_TBL(TRACE_UPDATE),
6159 T_TBL(TRACE_CHARPUT),
6160 T_TBL(TRACE_ORDINARY),
6162 T_TBL(TRACE_VIRTPUT),
6163 T_TBL(TRACE_IEVENT),
6165 T_TBL(TRACE_ICALLS),
6166 T_TBL(TRACE_CCALLS),
6167 T_TBL(TRACE_DATABASE),
6169 T_TBL(TRACE_MAXIMUM),
6176 tracetrace(unsigned tlevel)
6179 static size_t need = 12;
6183 for (n = 0; t_tbl[n].name != 0; n++)
6184 need += strlen(t_tbl[n].name) + 2;
6185 buf = typeMalloc(char, need);
6187 failed("tracetrace");
6189 _nc_SPRINTF(buf, _nc_SLIMIT(need) "0x%02x = {", tlevel);
6191 _nc_STRCAT(buf, t_tbl[0].name, need);
6192 _nc_STRCAT(buf, ", ", need);
6194 for (n = 1; t_tbl[n].name != 0; n++)
6195 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
6196 _nc_STRCAT(buf, t_tbl[n].name, need);
6197 _nc_STRCAT(buf, ", ", need);
6200 if (buf[strlen(buf) - 2] == ',')
6201 buf[strlen(buf) - 2] = '\0';
6202 _nc_STRCAT(buf, "}", need);
6206 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
6210 run_trace_menu(MENU * m)
6216 bool changed = FALSE;
6217 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
6218 case E_UNKNOWN_COMMAND:
6221 items = menu_items(m);
6222 i = current_item(m);
6223 if (i == items[0]) {
6224 if (item_value(i)) {
6225 for (p = items + 1; *p != 0; p++)
6226 if (item_value(*p)) {
6227 set_item_value(*p, FALSE);
6232 for (p = items + 1; *p != 0; p++)
6233 if (item_value(*p)) {
6234 set_item_value(items[0], FALSE);
6246 trace_set(bool recur GCC_UNUSED)
6247 /* interactively set the trace level */
6250 ITEM *items[SIZEOF(t_tbl)];
6257 MvAddStr(0, 0, "Interactively set trace level:");
6258 MvAddStr(2, 0, " Press space bar to toggle a selection.");
6259 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
6260 MvAddStr(4, 0, " Press return to set the trace level.");
6261 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
6265 for (n = 0; t_tbl[n].name != 0; n++) {
6266 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
6272 m = new_menu(items);
6274 set_menu_format(m, 0, 2);
6275 scale_menu(m, &mrows, &mcols);
6277 menu_opts_off(m, O_ONEVALUE);
6278 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
6279 set_menu_win(m, menuwin);
6280 keypad(menuwin, TRUE);
6283 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
6287 for (ip = menu_items(m); *ip; ip++) {
6288 unsigned mask = t_tbl[item_index(*ip)].mask;
6290 set_item_value(*ip, _nc_tracing == 0);
6291 else if ((mask & _nc_tracing) == mask)
6292 set_item_value(*ip, TRUE);
6295 while (run_trace_menu(m))
6299 for (ip = menu_items(m); *ip; ip++)
6300 if (item_value(*ip))
6301 newtrace |= t_tbl[item_index(*ip)].mask;
6303 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
6305 MvPrintw(LINES - 2, 0,
6306 "Trace level is %s\n", tracetrace(_nc_tracing));
6307 (void) addstr("Press any key to continue...");
6314 for (ip = items; *ip; ip++)
6320 #endif /* USE_LIBMENU */
6322 /****************************************************************************
6326 ****************************************************************************/
6329 make_label(int frow, int fcol, NCURSES_CONST char *label)
6331 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
6334 set_field_buffer(f, 0, label);
6335 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
6341 make_field(int frow, int fcol, int rows, int cols, bool secure)
6343 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
6346 set_field_back(f, A_UNDERLINE);
6347 set_field_userptr(f, (void *) 0);
6353 display_form(FORM *f)
6358 scale_form(f, &rows, &cols);
6360 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6362 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6365 if (post_form(f) != E_OK)
6373 WINDOW *w = form_win(f);
6374 WINDOW *s = form_sub(f);
6384 edit_secure(FIELD *me, int c)
6386 int rows, cols, frow, fcol, nrow, nbuf;
6388 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6390 char *source = field_buffer(me, 1);
6391 size_t have = (source ? strlen(source) : 0) + 1;
6392 size_t need = 80 + have;
6393 char *temp = malloc(need);
6397 _nc_STRNCPY(temp, source ? source : "", have + 1);
6398 len = (size_t) (char *) field_userptr(me);
6400 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6401 temp[len++] = (char) c;
6403 set_field_buffer(me, 1, temp);
6423 case REQ_RIGHT_CHAR:
6425 c = 0; /* we don't want to do inline editing */
6430 set_field_buffer(me, 1, temp);
6437 set_field_buffer(me, 1, temp);
6442 set_field_userptr(me, (void *) len);
6450 form_virtualize(FORM *f, WINDOW *w)
6453 static const struct {
6457 { CTRL('A'), REQ_NEXT_CHOICE },
6458 { CTRL('B'), REQ_PREV_WORD },
6459 { CTRL('C'), REQ_CLR_EOL },
6460 { CTRL('D'), REQ_DOWN_FIELD },
6461 { CTRL('E'), REQ_END_FIELD },
6462 { CTRL('F'), REQ_NEXT_PAGE },
6463 { CTRL('G'), REQ_DEL_WORD },
6464 { CTRL('H'), REQ_DEL_PREV },
6465 { CTRL('I'), REQ_INS_CHAR },
6466 { CTRL('K'), REQ_CLR_EOF },
6467 { CTRL('L'), REQ_LEFT_FIELD },
6468 { CTRL('M'), REQ_NEW_LINE },
6469 { CTRL('N'), REQ_NEXT_FIELD },
6470 { CTRL('O'), REQ_INS_LINE },
6471 { CTRL('P'), REQ_PREV_FIELD },
6472 { CTRL('R'), REQ_RIGHT_FIELD },
6473 { CTRL('S'), REQ_BEG_FIELD },
6474 { CTRL('U'), REQ_UP_FIELD },
6475 { CTRL('V'), REQ_DEL_CHAR },
6476 { CTRL('W'), REQ_NEXT_WORD },
6477 { CTRL('X'), REQ_CLR_FIELD },
6478 { CTRL('Y'), REQ_DEL_LINE },
6479 { CTRL('Z'), REQ_PREV_CHOICE },
6480 { ESCAPE, MAX_FORM_COMMAND + 1 },
6481 { KEY_BACKSPACE, REQ_DEL_PREV },
6482 { KEY_DOWN, REQ_DOWN_CHAR },
6483 { KEY_END, REQ_LAST_FIELD },
6484 { KEY_HOME, REQ_FIRST_FIELD },
6485 { KEY_LEFT, REQ_LEFT_CHAR },
6486 { KEY_LL, REQ_LAST_FIELD },
6487 { KEY_NEXT, REQ_NEXT_FIELD },
6488 { KEY_NPAGE, REQ_NEXT_PAGE },
6489 { KEY_PPAGE, REQ_PREV_PAGE },
6490 { KEY_PREVIOUS, REQ_PREV_FIELD },
6491 { KEY_RIGHT, REQ_RIGHT_CHAR },
6492 { KEY_UP, REQ_UP_CHAR },
6493 { QUIT, MAX_FORM_COMMAND + 1 }
6497 static int mode = REQ_INS_MODE;
6498 int c = wGetchar(w);
6500 FIELD *me = current_field(f);
6501 bool current = TRUE;
6503 if (c == CTRL(']')) {
6504 if (mode == REQ_INS_MODE) {
6505 mode = REQ_OVL_MODE;
6507 mode = REQ_INS_MODE;
6511 for (n = 0; n < SIZEOF(lookup); n++) {
6512 if (lookup[n].code == c) {
6513 c = lookup[n].result;
6518 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6521 * Force the field that the user is typing into to be in reverse video,
6522 * while the other fields are shown underlined.
6537 case REQ_LEFT_FIELD:
6539 case REQ_RIGHT_CHAR:
6543 current = (c < KEY_MAX);
6547 c = edit_secure(me, c);
6548 set_field_back(me, A_REVERSE);
6550 c = edit_secure(me, c);
6551 set_field_back(me, A_UNDERLINE);
6557 my_form_driver(FORM *form, int c)
6559 if (c == (MAX_FORM_COMMAND + 1)
6560 && form_driver(form, REQ_VALIDATION) == E_OK)
6568 #ifdef NCURSES_VERSION
6569 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6570 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6572 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6573 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6577 * Allow a middle initial, optionally with a '.' to end it.
6580 FIELDCHECK_CB(mi_field_check)
6582 char *s = field_buffer(fld, 0);
6586 for (n = 0; s[n] != '\0'; ++n) {
6593 } else if (isspace(UChar(s[n]))) {
6598 if (!isspace(UChar(s[n])))
6604 /* force the form to display a leading capital */
6605 if (islower(UChar(s[0]))) {
6606 s[0] = (char) toupper(UChar(s[0]));
6607 set_field_buffer(fld, 0, s);
6613 CHAR_CHECK_CB(mi_char_check)
6615 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6619 * Passwords should be at least 6 characters.
6622 FIELDCHECK_CB(pw_field_check)
6624 char *s = field_buffer(fld, 0);
6627 for (n = 0; s[n] != '\0'; ++n) {
6628 if (isspace(UChar(s[n]))) {
6637 CHAR_CHECK_CB(pw_char_check)
6639 return (isgraph(ch) ? TRUE : FALSE);
6643 form_test(bool recur GCC_UNUSED)
6647 FIELD *f[12], *secure;
6648 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6649 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6650 int finished = 0, c;
6653 #ifdef NCURSES_MOUSE_VERSION
6654 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6658 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6659 addstr("^N -- go to next field ^P -- go to previous field\n");
6660 addstr("Home -- go to first field End -- go to last field\n");
6661 addstr("^L -- go to field to left ^R -- go to field to right\n");
6662 addstr("^U -- move upward to field ^D -- move downward to field\n");
6663 addstr("^W -- go to next word ^B -- go to previous word\n");
6664 addstr("^S -- go to start of field ^E -- go to end of field\n");
6665 addstr("^H -- delete previous char ^Y -- delete line\n");
6666 addstr("^G -- delete current word ^C -- clear to end of line\n");
6667 addstr("^K -- clear to end of field ^X -- clear field\n");
6668 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6670 MvAddStr(4, 57, "Forms Entry Test");
6674 /* describe the form */
6675 memset(f, 0, sizeof(f));
6676 f[n++] = make_label(0, 15, "Sample Form");
6678 f[n++] = make_label(2, 0, "Last Name");
6679 f[n++] = make_field(3, 0, 1, 18, FALSE);
6680 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6682 f[n++] = make_label(2, 20, "First Name");
6683 f[n++] = make_field(3, 20, 1, 12, FALSE);
6684 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6686 f[n++] = make_label(2, 34, "Middle Name");
6687 f[n++] = make_field(3, 34, 1, 12, FALSE);
6688 set_field_type(f[n - 1], fty_middle);
6690 f[n++] = make_label(5, 0, "Comments");
6691 f[n++] = make_field(6, 0, 4, 46, FALSE);
6693 f[n++] = make_label(5, 20, "Password:");
6695 f[n++] = make_field(5, 30, 1, 9, TRUE);
6696 set_field_type(f[n - 1], fty_passwd);
6699 if ((form = new_form(f)) != 0) {
6705 nonl(); /* lets us read ^M's */
6707 switch (form_driver(form, c = form_virtualize(form, w))) {
6709 MvAddStr(5, 57, field_buffer(secure, 1));
6713 case E_UNKNOWN_COMMAND:
6714 finished = my_form_driver(form, c);
6726 for (c = 0; f[c] != 0; c++)
6728 free_fieldtype(fty_middle);
6729 free_fieldtype(fty_passwd);
6733 #ifdef NCURSES_MOUSE_VERSION
6734 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6738 #endif /* USE_LIBFORM */
6740 /****************************************************************************
6744 ****************************************************************************/
6746 #if HAVE_COPYWIN /* ...and overlay, overwrite */
6748 static const int overlap_HEAD = 1;
6749 static const int overlap_FOOT = 6;
6757 getmaxyx(stdscr, y, x);
6758 if (y < 23 || x < 80) {
6759 Cannot("The screen is too small for this test");
6762 int ymax = y - (overlap_HEAD + overlap_FOOT);
6763 int high = ymax / 5; /* equal-sized parts for cross */
6764 int xmax = x - 2; /* margin */
6765 int wide = (xmax / 5) & ~1;
6774 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6775 lmar = (xmax - (5 * wide)) / 2;
6778 result = newwin(3 * high, 3 * wide, tmar, lmar);
6780 result = newwin(3 * high, 3 * wide, tmar + 2 * high, lmar + 2 * wide);
6791 for (row = overlap_HEAD; row < LINES - overlap_FOOT; ++row) {
6798 move_overlap(int shift, WINDOW *win1)
6800 int ymax = getmaxy(stdscr) - (overlap_HEAD + overlap_FOOT);
6801 int high = ymax / 5; /* equal-sized parts for cross */
6803 int xmax1 = getmaxx(win1) + 1;
6804 int lmar1 = (COLS - (5 * (xmax1) / 3)) / 2;
6809 tmar = (ymax - (5 * high)) / 2 + overlap_HEAD;
6811 rc = mvwin(win1, tmar, lmar1 + shift);
6816 fillwin(WINDOW *win, char ch)
6821 getmaxyx(win, y1, x1);
6822 for (y = 0; y < y1; y++) {
6824 for (x = 0; x < x1; x++)
6825 waddch(win, UChar(ch));
6829 #define InCross(x,y, x1,y1) \
6830 (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3)) \
6831 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3))))
6834 crosswin(WINDOW *win, char ch)
6840 getmaxyx(win, y1, x1);
6841 for (y = 0; y < y1; y++) {
6842 for (x = 0; x < x1; x += xw) {
6843 if (InCross(x, y, x1, y1)) {
6845 waddch(win, UChar(ch));
6852 * Match "crosswin()", but using line-drawing characters. This could be done
6853 * a little simpler using box(), but the reason for this example is to test
6854 * hline/vline and addch with line-drawing vs the copy/overlay functions.
6857 crossbox(WINDOW *win)
6862 getmaxyx(win, y1, x1);
6867 mvwhline(win, 0, (xmax / 3), ACS_HLINE, (xmax / 3));
6868 mvwhline(win, ymax / 3, 0, ACS_HLINE, xmax);
6869 mvwhline(win, ((2 * ymax) / 3) - 1, 0, ACS_HLINE, xmax);
6870 mvwhline(win, y1 - 1, (xmax / 3), ACS_HLINE, (xmax / 3));
6872 mvwvline(win, (ymax / 3), 0, ACS_VLINE, (ymax / 3));
6873 mvwvline(win, 0, xmax / 3, ACS_VLINE, ymax);
6874 mvwvline(win, 0, ((2 * xmax) / 3) - 1, ACS_VLINE, ymax);
6875 mvwvline(win, (ymax / 3), x1 - 1, ACS_VLINE, (ymax / 3));
6877 mvwaddch(win, 0, (xmax / 3), ACS_ULCORNER);
6878 mvwaddch(win, 0, ((2 * xmax) / 3) - 1, ACS_URCORNER);
6879 mvwaddch(win, y1 - 1, (xmax / 3), ACS_LLCORNER);
6880 mvwaddch(win, y1 - 1, ((2 * xmax) / 3) - 1, ACS_LRCORNER);
6882 mvwaddch(win, (ymax / 3), 0, ACS_ULCORNER);
6883 mvwaddch(win, ((2 * ymax) / 3) - 1, 0, ACS_LLCORNER);
6884 mvwaddch(win, (ymax / 3), x1 - 1, ACS_URCORNER);
6885 mvwaddch(win, ((2 * ymax) / 3) - 1, x1 - 1, ACS_LRCORNER);
6887 mvwaddch(win, (ymax / 3), (xmax / 3), ACS_PLUS);
6888 mvwaddch(win, (ymax / 3), ((2 * xmax) / 3) - 1, ACS_PLUS);
6889 mvwaddch(win, ((2 * ymax) / 3) - 1, ((2 * xmax) / 3) - 1, ACS_PLUS);
6890 mvwaddch(win, ((2 * ymax) / 3) - 1, (xmax / 3), ACS_PLUS);
6901 #define OVERLAP_FLAVORS 6
6910 #define LimitFILL() UseColors ? 4 : 2
6913 otDRAW_text_cross = 0
6920 #define LimitDRAW() UseColors ? 5 : 3
6923 otCOPY_overwrite = 0
6929 #define LimitCOPY() 4
6932 overlap_helpitem(int state, int item, char *message)
6934 int row = (item / 2);
6935 int col = ((item % 2) ? COLS / 2 : 0);
6937 move(LINES - 6 + row, col);
6938 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6943 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6945 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6947 switch ((otFILL) flavor) {
6949 (void) wattrset(win, A_NORMAL);
6952 (void) wattrset(win, A_BOLD);
6955 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6956 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
6959 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6960 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
6966 overlap_test_2_attr(WINDOW *win, int flavor, int col)
6968 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
6970 switch ((otDRAW) flavor) {
6971 case otDRAW_text_cross:
6974 case otDRAW_line_box:
6977 case otDRAW_line_cross:
6981 init_pair(cpair, COLOR_RED, COLOR_GREEN);
6982 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
6984 case otDRAW_reset_bg:
6985 wbkgdset(win, ' ' | A_NORMAL);
6991 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
6996 int limit[OVERLAP_FLAVORS];
6997 const char *ths, *tht;
7001 state += OVERLAP_FLAVORS;
7002 state = state % OVERLAP_FLAVORS;
7003 assert(state >= 0 && state < OVERLAP_FLAVORS);
7005 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
7008 ths = col ? "B" : "A";
7009 tht = col ? "A" : "B";
7011 switch ((otBASE) row) {
7012 case otBASE_refresh:
7015 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7016 "refresh %s, then %s, then doupdate.", ths, tht);
7019 limit[row] = LimitFILL();
7020 flavors[row] %= limit[row];
7021 overlap_test_1_attr(stdscr, flavors[row], col);
7022 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7023 "fill window %s with letter %s.", ths, ths);
7026 limit[row] = LimitDRAW();
7027 flavors[row] %= limit[row];
7028 switch ((otDRAW) flavors[row]) {
7029 case otDRAW_text_cross:
7030 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7031 "cross text-pattern in window %s.", ths);
7033 case otDRAW_line_box:
7034 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7035 "draw line-box in window %s.", ths);
7037 case otDRAW_line_cross:
7038 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7039 "draw line-cross in window %s.", ths);
7042 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7043 "set background of window %s.", ths);
7045 case otDRAW_reset_bg:
7046 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7047 "reset background of window %s.", ths);
7054 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7055 "clear window %s.", ths);
7058 limit[row] = LimitCOPY();
7059 flavors[row] %= limit[row];
7060 switch ((otCOPY) flavors[row]) {
7061 case otCOPY_overwrite:
7062 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7063 "overwrite %s onto %s.", ths, tht);
7066 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7067 "copywin(FALSE) %s onto %s.", ths, tht);
7070 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7071 "copywin(TRUE) %s onto %s.", ths, tht);
7073 case otCOPY_overlay:
7074 _nc_SPRINTF(msg, _nc_SLIMIT(sizeof(msg))
7075 "overlay %s onto %s.", ths, tht);
7080 overlap_helpitem(state, item, msg);
7081 (void) wattrset(stdscr, A_NORMAL);
7082 wbkgdset(stdscr, ' ' | A_NORMAL);
7085 printw("^Q/ESC = terminate test. </> shift. Up/down/space select (row %d",
7087 if (limit[state] > 1)
7088 printw(" test %d:%d", 1 + flavors[state], limit[state]);
7096 overlap_test_0(WINDOW *a, WINDOW *b)
7106 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
7108 overlap_test_1_attr(a, flavor, col);
7110 (void) wattrset(a, A_NORMAL);
7114 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
7116 overlap_test_2_attr(a, flavor, col);
7117 switch ((otDRAW) flavor) {
7118 case otDRAW_text_cross:
7121 case otDRAW_line_box:
7124 case otDRAW_line_cross:
7128 /* done in overlap_test_2_attr */
7130 case otDRAW_reset_bg:
7131 /* done in overlap_test_2_attr */
7137 overlap_test_3(WINDOW *a)
7144 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
7146 switch ((otCOPY) flavor) {
7147 case otCOPY_overwrite:
7151 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
7154 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
7156 case otCOPY_overlay:
7162 /* test effects of overlapping windows */
7164 overlap_test(bool recur GCC_UNUSED)
7166 WINDOW *win1, *win2;
7168 int shift = 0, last_refresh = -1;
7169 int state, flavor[OVERLAP_FLAVORS];
7171 if ((win1 = make_overlap(0)) == 0
7172 || (win2 = make_overlap(1)) == 0)
7179 printw("Test wnoutrefresh() for two overlapping windows:");
7181 memset(flavor, 0, sizeof(flavor));
7182 state = overlap_help(0, flavor);
7184 while (!isQuit(ch = Getchar(), TRUE)) {
7186 case 'a': /* refresh window A first, then B */
7187 overlap_test_0(win1, win2);
7190 case 'b': /* refresh window B first, then A */
7191 overlap_test_0(win2, win1);
7194 case 'c': /* fill window A so it's visible */
7195 overlap_test_1(flavor[otBASE_fill], 0, win1, 'A');
7198 case 'd': /* fill window B so it's visible */
7199 overlap_test_1(flavor[otBASE_fill], 1, win2, 'B');
7202 case 'e': /* cross test pattern in window A */
7203 overlap_test_2(flavor[otBASE_draw], 0, win1, 'A');
7206 case 'f': /* cross test pattern in window A */
7207 overlap_test_2(flavor[otBASE_draw], 1, win2, 'B');
7210 case 'g': /* clear window A */
7211 overlap_test_3(win1);
7214 case 'h': /* clear window B */
7215 overlap_test_3(win2);
7218 case 'i': /* overwrite A onto B */
7219 overlap_test_4(flavor[otBASE_copy], win1, win2);
7222 case 'j': /* overwrite B onto A */
7223 overlap_test_4(flavor[otBASE_copy], win2, win1);
7228 state = overlap_help(state + 1, flavor);
7233 state = overlap_help(state - 1, flavor);
7238 state = overlap_help(state, flavor);
7242 state = overlap_help(state, flavor);
7267 if (move_overlap(shift, win1) != OK) {
7269 shift += (ch == '>') ? -1 : 1;
7270 } else if (last_refresh > 0) {
7272 wnoutrefresh(stdscr);
7273 if (last_refresh == 'a')
7274 overlap_test_0(win1, win2);
7276 overlap_test_0(win2, win1);
7292 #if USE_WIDEC_SUPPORT
7294 x_fillwin(WINDOW *win, wchar_t ch)
7299 getmaxyx(win, y1, x1);
7301 for (y = 0; y < y1; y++) {
7303 for (x = 0; x < x1; x++)
7304 waddnwstr(win, &ch, 1);
7309 x_crosswin(WINDOW *win, wchar_t ch)
7315 getmaxyx(win, y1, x1);
7316 for (y = 0; y < y1; y++) {
7317 for (x = 0; x < x1; x += xw) {
7318 if (InCross(x, y, x1, y1)) {
7320 waddnwstr(win, &ch, 1);
7327 x_overlap_test_1(int flavor, int col, WINDOW *a, wchar_t fill)
7329 overlap_test_1_attr(a, flavor, col);
7331 (void) wattrset(a, A_NORMAL);
7335 x_overlap_test_2(int flavor, int col, WINDOW *a, wchar_t fill)
7337 overlap_test_2_attr(a, flavor, col);
7338 switch ((otDRAW) flavor) {
7339 case otDRAW_text_cross:
7340 x_crosswin(a, fill);
7342 case otDRAW_line_box:
7345 case otDRAW_line_cross:
7349 /* done in overlap_test_2_attr */
7351 case otDRAW_reset_bg:
7352 /* done in overlap_test_2_attr */
7357 /* test effects of overlapping windows */
7359 x_overlap_test(bool recur GCC_UNUSED)
7361 const wchar_t WIDE_A = 0xff21;
7362 const wchar_t WIDE_B = 0xff22;
7363 WINDOW *win1, *win2;
7365 int shift = 0, last_refresh = -1;
7366 int state, flavor[OVERLAP_FLAVORS];
7368 if ((win1 = make_overlap(0)) == 0
7369 || (win2 = make_overlap(1)) == 0)
7376 printw("Test wnoutrefresh() for overlapping windows with double-cell characters:");
7378 memset(flavor, 0, sizeof(flavor));
7379 state = overlap_help(0, flavor);
7381 while (!isQuit(ch = Getchar(), TRUE)) {
7383 case 'a': /* refresh window A first, then B */
7384 overlap_test_0(win1, win2);
7387 case 'b': /* refresh window B first, then A */
7388 overlap_test_0(win2, win1);
7391 case 'c': /* fill window A so it's visible */
7392 x_overlap_test_1(flavor[otBASE_fill], 0, win1, WIDE_A);
7395 case 'd': /* fill window B so it's visible */
7396 x_overlap_test_1(flavor[otBASE_fill], 1, win2, WIDE_B);
7399 case 'e': /* cross test pattern in window A */
7400 x_overlap_test_2(flavor[otBASE_draw], 0, win1, WIDE_A);
7403 case 'f': /* cross test pattern in window A */
7404 x_overlap_test_2(flavor[otBASE_draw], 1, win2, WIDE_B);
7407 case 'g': /* clear window A */
7408 overlap_test_3(win1);
7411 case 'h': /* clear window B */
7412 overlap_test_3(win2);
7415 case 'i': /* overwrite A onto B */
7416 overlap_test_4(flavor[otBASE_copy], win1, win2);
7419 case 'j': /* overwrite B onto A */
7420 overlap_test_4(flavor[otBASE_copy], win2, win1);
7425 state = overlap_help(state + 1, flavor);
7430 state = overlap_help(state - 1, flavor);
7435 state = overlap_help(state, flavor);
7439 state = overlap_help(state, flavor);
7464 if (move_overlap(shift, win1) != OK) {
7466 shift += (ch == '>') ? -1 : 1;
7467 } else if (last_refresh > 0) {
7469 wnoutrefresh(stdscr);
7470 if (last_refresh == 'a')
7471 overlap_test_0(win1, win2);
7473 overlap_test_0(win2, win1);
7488 #endif /* USE_WIDEC_SUPPORT */
7490 #endif /* HAVE_COPYWIN */
7493 show_setting_name(const char *name)
7495 printw("%-25s ", name);
7499 show_string_setting(const char *name, const char *value)
7501 show_setting_name(name);
7503 printw("\"%s\"", value);
7513 show_number_setting(const char *name, int value)
7515 show_setting_name(name);
7517 printw("%d", value);
7520 printw("%d", value);
7527 show_boolean_setting(const char *name, int value)
7529 show_setting_name(name);
7531 printw("%s", value ? "TRUE" : "FALSE");
7534 printw("%d", value);
7541 settings_test(bool recur GCC_UNUSED)
7543 #if USE_WIDEC_SUPPORT
7548 show_string_setting("termname", termname());
7549 show_string_setting("longname", longname());
7550 show_number_setting("baudrate", baudrate());
7551 if (erasechar() > 0) {
7552 show_string_setting("unctrl(erasechar)", unctrl((chtype) erasechar()));
7553 show_string_setting("keyname(erasechar)", keyname(erasechar()));
7555 if (killchar() > 0) {
7556 show_string_setting("unctrl(killchar)", unctrl((chtype) killchar()));
7557 show_string_setting("keyname(killchar)", keyname(killchar()));
7559 #if USE_WIDEC_SUPPORT
7560 if (erasewchar(&ch) == OK) {
7561 show_string_setting("key_name(erasewchar)", key_name(ch));
7563 if (killwchar(&ch) == OK) {
7564 show_string_setting("key_name(killwchar)", key_name(ch));
7567 show_boolean_setting("has_ic", has_ic());
7568 show_boolean_setting("has_il", has_il());
7569 show_boolean_setting("has_colors", has_colors());
7570 #if HAVE_COLOR_CONTENT
7571 show_boolean_setting("can_change_color", can_change_color());
7579 /****************************************************************************
7583 ****************************************************************************/
7588 static const char *const tbl[] =
7590 "Usage: ncurses [options]"
7593 #ifdef NCURSES_VERSION
7594 ," -a f,b set default-colors (assumed white-on-black)"
7595 ," -d use default-colors if terminal supports them"
7598 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
7601 ," -e fmt specify format for soft-keys test (e)"
7604 ," -f rip-off footer line (can repeat)"
7605 ," -h rip-off header line (can repeat)"
7607 ," -m do not use colors"
7608 #if HAVE_COLOR_CONTENT
7609 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
7612 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
7614 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(__MINGW32__)
7615 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
7618 ," -t mask specify default trace-level (may toggle with ^T)"
7620 #if HAVE_COLOR_CONTENT
7621 ," -x use xterm-compatible control for reading color palette"
7625 for (n = 0; n < SIZEOF(tbl); n++)
7626 fprintf(stderr, "%s\n", tbl[n]);
7627 ExitProgram(EXIT_FAILURE);
7631 set_terminal_modes(void)
7636 scrollok(stdscr, TRUE);
7637 idlok(stdscr, TRUE);
7638 keypad(stdscr, TRUE);
7643 announce_sig(int sig)
7645 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
7651 rip_footer(WINDOW *win, int cols)
7653 wbkgd(win, A_REVERSE);
7656 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
7662 rip_header(WINDOW *win, int cols)
7664 wbkgd(win, A_REVERSE);
7667 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
7671 #endif /* HAVE_RIPOFFLINE */
7676 #if USE_WIDEC_SUPPORT
7679 int (*narrow_func) (bool);
7680 int (*wide_func) (bool);
7684 #define BOTH(a) a, x_ ## a
7685 #define ONLY(a) a, NULL
7686 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7690 int (*narrow_func) (bool);
7696 #define CMDS(recur, funcs,code,help) { recur, funcs, code, help }
7699 static MyCmds cmds[] =
7701 CMDS(TRUE, BOTH(getch_test), 'a', "keyboard and mouse input test"),
7702 CMDS(TRUE, BOTH(attr_test), 'b', "character attribute test"),
7703 CMDS(TRUE, BOTH(color_test), 'c', "color test pattern"),
7704 #if HAVE_COLOR_CONTENT
7705 CMDS(FALSE, ONLY(color_edit), 'd', "edit RGB color values"),
7708 CMDS(TRUE, BOTH(slk_test), 'e', "exercise soft keys"),
7710 CMDS(TRUE, BOTH(acs_test), 'f', "display ACS characters"),
7711 CMDS(TRUE, ONLY(scroll_test), 'g', "display windows and scrolling"),
7712 CMDS(TRUE, ONLY(flushinp_test), 'i', "test flushinp()"),
7713 CMDS(TRUE, ONLY(sgr_attr_test), 'k', "display character attributes"),
7715 CMDS(TRUE, ONLY(menu_test), 'm', "exercise menu library"),
7718 CMDS(TRUE, BOTH(panel_test), 'o', "exercise panel library"),
7721 CMDS(TRUE, ONLY(pad_test), 'p', "exercise pad features"),
7723 CMDS(TRUE, ONLY(NULL), 'q', "quit"),
7725 CMDS(TRUE, ONLY(form_test), 'r', "exercise form library"),
7728 CMDS(TRUE, BOTH(overlap_test), 's', "overlapping-refresh test"),
7730 #if USE_LIBMENU && defined(TRACE)
7731 CMDS(TRUE, ONLY(trace_set), 't', "set trace level"),
7733 CMDS(TRUE, ONLY(settings_test), 'v', "show terminal name and settings"),
7734 CMDS(FALSE, ONLY(NULL), '?', "repeat this command summary")
7743 printf("This is the ncurses main menu (uppercase for wide-characters)\n");
7744 for (n = 0; n < SIZEOF(cmds); ++n) {
7745 if (top || cmds[n].recur) {
7747 #if USE_WIDEC_SUPPORT
7748 if (cmds[n].wide_func) {
7749 printf("%c,", toupper(cmds[n].code));
7752 printf("%c\t= %s\n", cmds[n].code, cmds[n].help);
7756 (void) fputs("> ", stdout);
7757 (void) fflush(stdout); /* necessary under SVr4 curses */
7760 * This used to be an 'fgets()' call (until 1996/10). However with
7761 * some runtime libraries, mixing stream I/O and 'read()' causes the
7762 * input stream to be flushed when switching between the two.
7767 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7771 } else if (command == 0 && !isspace(UChar(ch))) {
7773 } else if (ch == '\n' || ch == '\r') {
7774 if ((command == 'd') && !top) {
7775 (void) fputs("Do not nest test-d\n", stdout);
7780 (void) fputs("> ", stdout);
7781 (void) fflush(stdout);
7786 for (n = 0; n < SIZEOF(cmds); ++n) {
7787 if (cmds[n].code == command) {
7788 doit = cmds[n].narrow_func;
7791 #if USE_WIDEC_SUPPORT
7792 if (toupper(cmds[n].code) == command) {
7793 doit = cmds[n].wide_func;
7799 if (doit != NULL && doit(FALSE) == OK) {
7801 * This may be overkill; it's intended to reset everything back
7802 * to the initial terminal modes so that tests don't get in
7806 set_terminal_modes();
7811 if (command == '?') {
7812 (void) puts("This is the ncurses capability tester.");
7814 puts("You may select a test from the main menu by typing the");
7816 puts("key letter of the choice (the letter to left of the =)");
7818 puts("at the > prompt. Type `q' to exit.");
7826 /*+-------------------------------------------------------------------------
7828 --------------------------------------------------------------------------*/
7831 main(int argc, char *argv[])
7835 #ifdef NCURSES_VERSION
7836 int default_fg = COLOR_WHITE;
7837 int default_bg = COLOR_BLACK;
7838 bool assumed_colors = FALSE;
7839 bool default_colors = FALSE;
7841 bool monochrome = FALSE;
7842 #if HAVE_COLOR_CONTENT
7843 bool xterm_colors = FALSE;
7844 char *palette_file = 0;
7847 setlocale(LC_ALL, "");
7849 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:x")) != -1) {
7851 #ifdef NCURSES_VERSION
7853 assumed_colors = TRUE;
7854 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7856 default_fg = COLOR_WHITE;
7859 default_bg = COLOR_BLACK;
7864 default_colors = TRUE;
7873 my_e_param = atoi(optarg);
7874 #ifdef NCURSES_VERSION
7875 if (my_e_param > 3) /* allow extended layouts */
7884 ripoffline(-1, rip_footer);
7887 ripoffline(1, rip_header);
7889 #endif /* HAVE_RIPOFFLINE */
7893 #if HAVE_COLOR_CONTENT
7895 palette_file = optarg;
7900 nap_msec = (int) atol(optarg);
7903 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(__MINGW32__)
7910 save_trace = (unsigned) strtol(optarg, 0, 0);
7913 #if HAVE_COLOR_CONTENT
7915 xterm_colors = TRUE;
7924 * If there's no menus (unlikely for ncurses!), then we'll have to set
7925 * tracing on initially, just in case the user wants to test something that
7926 * doesn't involve wGetchar.
7929 /* enable debugging */
7933 if (!isatty(fileno(stdin)))
7935 #endif /* USE_LIBMENU */
7939 /* tell it we're going to play with soft keys */
7940 slk_init(my_e_param);
7944 /* set up null signal catcher so we can see what interrupts to getch do */
7945 signal(SIGUSR1, announce_sig);
7948 /* we must initialize the curses data structure only once */
7952 set_terminal_modes();
7955 /* tests, in general, will want these modes */
7956 UseColors = (bool) (monochrome ? FALSE : has_colors());
7960 #ifdef NCURSES_VERSION_PATCH
7961 MaxColors = COLORS; /* was > 16 ? 16 : COLORS */
7962 #if HAVE_USE_DEFAULT_COLORS
7963 if (default_colors) {
7964 use_default_colors();
7967 #if HAVE_ASSUME_DEFAULT_COLORS
7969 assume_default_colors(default_fg, default_bg);
7972 #else /* normal SVr4 curses */
7973 MaxColors = COLORS; /* was > 8 ? 8 : COLORS */
7975 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
7977 #if HAVE_COLOR_CONTENT
7978 if (can_change_color()) {
7979 init_all_colors(xterm_colors, palette_file);
7985 * Return to terminal mode, so we're guaranteed of being able to
7986 * select terminal commands even if the capabilities are wrong.
7990 #if HAVE_CURSES_VERSION
7991 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
7992 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
7993 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
7994 NCURSES_VERSION_MAJOR,
7995 NCURSES_VERSION_MINOR,
7996 NCURSES_VERSION_PATCH);
7998 (void) puts("Welcome to ncurses. Press ? for help.");
8003 ExitProgram(EXIT_SUCCESS);
8006 /* ncurses.c ends here */