1 /****************************************************************************
2 * Copyright (c) 1998-2008,2009 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.339 2009/04/04 22:46:11 juergen 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;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
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 */
122 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
123 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
124 #define reset_wchars(state) memset(&state, 0, sizeof(state))
125 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
126 #define count_wchars(src, len, state) wcstombs(0, src, len)
127 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
128 #define reset_wchars(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
133 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
134 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
135 #define reset_mbytes(state) memset(&state, 0, sizeof(state))
136 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
137 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
138 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
139 #define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
143 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
145 #define P(string) printw("%s\n", string)
147 #define BLANK ' ' /* this is the background character */
150 static int max_colors; /* the actual number of colors we'll use */
151 static int min_colors; /* the minimum color code */
152 static bool use_colors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
163 static RGB_DATA *all_colors;
165 static void main_menu(bool);
167 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
168 * though we can rely on negative x/y values to stop the macro.
171 do_h_line(int y, int x, chtype c, int to)
174 mvhline(y, x, c, (to) - (x));
178 do_v_line(int y, int x, chtype c, int to)
181 mvvline(y, x, c, (to) - (y));
195 return ((c) == QUIT || (c) == ESCAPE);
197 #define case_QUIT QUIT: case ESCAPE
199 /* Common function to allow ^T to toggle trace-mode in the middle of a test
200 * so that trace-files can be made smaller.
203 wGetchar(WINDOW *win)
207 while ((c = wgetch(win)) == CTRL('T')) {
209 save_trace = _nc_tracing;
210 Trace(("TOGGLE-TRACING OFF"));
213 _nc_tracing = save_trace;
217 Trace(("TOGGLE-TRACING ON"));
224 #define Getchar() wGetchar(stdscr)
226 /* replaces wgetnstr(), since we want to be able to edit values */
228 wGetstring(WINDOW *win, char *buffer, int limit)
235 wattrset(win, A_REVERSE);
237 x = (int) strlen(buffer);
239 if (x > (int) strlen(buffer))
240 x = (int) strlen(buffer);
242 wprintw(win, "%-*s", limit, buffer);
243 wmove(win, y0, x0 + x);
244 switch (ch = wGetchar(win)) {
257 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
275 if (!isprint(ch) || ch >= KEY_MIN) {
277 } else if ((int) strlen(buffer) < limit) {
279 for (j = (int) strlen(buffer) + 1; j > x; --j) {
280 buffer[j] = buffer[j - 1];
282 buffer[x++] = (char) ch;
289 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
298 return (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_of(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
322 make_fullwidth_digit(cchar_t *target, int digit)
326 source[0] = fullwidth_of(digit + '0');
328 setcchar(target, source, A_NORMAL, 0, 0);
332 wGet_wchar(WINDOW *win, wint_t *result)
336 while ((c = wget_wch(win, result)) == CTRL('T')) {
338 save_trace = _nc_tracing;
339 Trace(("TOGGLE-TRACING OFF"));
342 _nc_tracing = save_trace;
346 Trace(("TOGGLE-TRACING ON"));
349 c = wget_wch(win, result);
353 #define Get_wchar(result) wGet_wchar(stdscr, result)
355 /* replaces wgetn_wstr(), since we want to be able to edit values */
357 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
366 wattrset(win, A_REVERSE);
368 x = (int) wcslen(buffer);
370 if (x > (int) wcslen(buffer))
371 x = (int) wcslen(buffer);
373 /* clear the "window' */
375 wprintw(win, "%*s", limit, " ");
377 /* write the existing buffer contents */
379 waddnwstr(win, buffer, limit);
381 /* positions the cursor past character 'x' */
383 waddnwstr(win, buffer, x);
385 switch (wGet_wchar(win, &ch)) {
425 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
445 } else if ((int) wcslen(buffer) < limit) {
447 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
448 buffer[j] = buffer[j - 1];
450 buffer[x++] = (wchar_t) ch;
457 wattroff(win, A_REVERSE);
468 addstr("Press any key to continue... ");
473 Cannot(const char *what)
475 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
480 ShellOut(bool message)
483 addstr("Shelling out...");
492 addstr("returned from shellout.\n");
496 #ifdef NCURSES_MOUSE_VERSION
498 * This function is the same as _tracemouse(), but we cannot count on that
499 * being available in the non-debug library.
502 mouse_decode(MEVENT const *ep)
504 static char buf[80 + (5 * 10) + (32 * 15)];
506 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
507 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
509 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
511 SHOW(BUTTON1_RELEASED, "release-1");
512 SHOW(BUTTON1_PRESSED, "press-1");
513 SHOW(BUTTON1_CLICKED, "click-1");
514 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
515 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
516 #if NCURSES_MOUSE_VERSION == 1
517 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
520 SHOW(BUTTON2_RELEASED, "release-2");
521 SHOW(BUTTON2_PRESSED, "press-2");
522 SHOW(BUTTON2_CLICKED, "click-2");
523 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
524 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
525 #if NCURSES_MOUSE_VERSION == 1
526 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
529 SHOW(BUTTON3_RELEASED, "release-3");
530 SHOW(BUTTON3_PRESSED, "press-3");
531 SHOW(BUTTON3_CLICKED, "click-3");
532 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
533 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
534 #if NCURSES_MOUSE_VERSION == 1
535 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
538 SHOW(BUTTON4_RELEASED, "release-4");
539 SHOW(BUTTON4_PRESSED, "press-4");
540 SHOW(BUTTON4_CLICKED, "click-4");
541 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
542 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
543 #if NCURSES_MOUSE_VERSION == 1
544 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
547 #if NCURSES_MOUSE_VERSION == 2
548 SHOW(BUTTON5_RELEASED, "release-5");
549 SHOW(BUTTON5_PRESSED, "press-5");
550 SHOW(BUTTON5_CLICKED, "click-5");
551 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
552 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
555 SHOW(BUTTON_CTRL, "ctrl");
556 SHOW(BUTTON_SHIFT, "shift");
557 SHOW(BUTTON_ALT, "alt");
558 SHOW(ALL_MOUSE_EVENTS, "all-events");
559 SHOW(REPORT_MOUSE_POSITION, "position");
563 if (buf[strlen(buf) - 1] == ' ')
564 buf[strlen(buf) - 2] = '\0';
565 (void) strcat(buf, "}");
568 #endif /* NCURSES_MOUSE_VERSION */
570 /****************************************************************************
572 * Character input test
574 ****************************************************************************/
576 #define NUM_GETCH_FLAGS 256
577 typedef bool GetchFlags[NUM_GETCH_FLAGS];
580 setup_getch(WINDOW *win, GetchFlags flags)
582 keypad(win, flags['k']); /* should be redundant, but for testing */
583 meta(win, flags['m']); /* force this to a known state */
591 init_getch(WINDOW *win, GetchFlags flags)
593 memset(flags, FALSE, NUM_GETCH_FLAGS);
594 flags[UChar('k')] = (win == stdscr);
595 flags[UChar('m')] = TRUE;
597 setup_getch(win, flags);
601 wgetch_help(WINDOW *win, GetchFlags flags)
603 static const char *help[] =
605 "e -- toggle echo mode"
606 ,"g -- triggers a getstr test"
607 ,"k -- toggle keypad/literal mode"
608 ,"m -- toggle meta (7-bit/8-bit) mode"
611 ,"w -- create a new window"
613 ,"z -- suspend this process"
617 unsigned chk = ((SIZEOF(help) + 1) / 2);
622 printw("Type any key to see its %s value. Also:\n",
623 flags['k'] ? "keypad" : "literal");
624 for (n = 0; n < SIZEOF(help); ++n) {
625 int row = 1 + (int) (n % chk);
626 int col = (n >= chk) ? COLS / 2 : 0;
627 int flg = ((strstr(help[n], "toggle") != 0)
628 && (flags[UChar(*help[n])] != FALSE));
631 mvprintw(row, col, "%s", help[n]);
642 wgetch_wrap(WINDOW *win, int first_y)
644 int last_y = getmaxy(win) - 1;
645 int y = getcury(win) + 1;
653 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
659 static WINSTACK *winstack = 0;
660 static unsigned len_winstack = 0;
673 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
675 unsigned need = (level + 1) * 2;
677 assert(level < COLS);
681 winstack = typeMalloc(WINSTACK, len_winstack);
682 } else if (need >= len_winstack) {
684 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
686 winstack[level].text = txt_win;
687 winstack[level].frame = box_win;
690 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
694 /* this chunk is now done in resize_term() */
701 #define slk_repaint() /* nothing */
705 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
706 * Resize both and paint the box in the parent.
709 resize_boxes(unsigned level, WINDOW *win)
713 int high = LINES - base;
717 wnoutrefresh(stdscr);
721 for (n = 0; n < level; ++n) {
722 wresize(winstack[n].frame, high, wide);
723 wresize(winstack[n].text, high - 2, wide - 2);
726 werase(winstack[n].text);
727 box(winstack[n].frame, 0, 0);
728 wnoutrefresh(winstack[n].frame);
729 wprintw(winstack[n].text,
731 getmaxy(winstack[n].text),
732 getmaxx(winstack[n].text));
733 wnoutrefresh(winstack[n].text);
734 if (winstack[n].text == win)
740 #define forget_boxes() /* nothing */
741 #define remember_boxes(level,text,frame) /* nothing */
745 wgetch_test(unsigned level, WINDOW *win, int delay)
748 int first_y, first_x;
752 bool blocking = (delay < 0);
754 init_getch(win, flags);
755 wtimeout(win, delay);
756 getyx(win, first_y, first_x);
758 wgetch_help(win, flags);
759 wsetscrreg(win, first_y, getmaxy(win) - 1);
763 while ((c = wGetchar(win)) == ERR) {
766 (void) wprintw(win, "%05d: input error", incount);
769 (void) wprintw(win, "%05d: input timed out", incount);
771 wgetch_wrap(win, first_y);
773 if (c == ERR && blocking) {
775 wgetch_wrap(win, first_y);
776 } else if (isQuit(c)) {
778 } else if (c == 'e') {
779 flags[UChar('e')] = !flags[UChar('e')];
780 setup_getch(win, flags);
781 wgetch_help(win, flags);
782 } else if (c == 'g') {
783 waddstr(win, "getstr test: ");
785 wgetnstr(win, buf, sizeof(buf) - 1);
787 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
789 wgetch_wrap(win, first_y);
790 } else if (c == 'k') {
791 flags[UChar('k')] = !flags[UChar('k')];
792 setup_getch(win, flags);
793 wgetch_help(win, flags);
794 } else if (c == 'm') {
795 flags[UChar('m')] = !flags[UChar('m')];
796 setup_getch(win, flags);
797 wgetch_help(win, flags);
798 } else if (c == 's') {
800 } else if (c == 'w') {
801 int high = getmaxy(win) - 1 - first_y + 1;
802 int wide = getmaxx(win) - first_x;
804 int new_y = first_y + getbegy(win);
805 int new_x = first_x + getbegx(win);
807 getyx(win, old_y, old_x);
808 if (high > 2 && wide > 2) {
809 WINDOW *wb = newwin(high, wide, new_y, new_x);
810 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
815 remember_boxes(level, wi, wb);
816 wgetch_test(level + 1, wi, delay);
820 wgetch_help(win, flags);
821 wmove(win, old_y, old_x);
827 } else if (c == 'z') {
828 kill(getpid(), SIGTSTP);
831 wprintw(win, "Key pressed: %04o ", c);
832 #ifdef NCURSES_MOUSE_VERSION
833 if (c == KEY_MOUSE) {
838 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
840 move(event.y, event.x);
844 #endif /* NCURSES_MOUSE_VERSION */
846 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
847 if (c == KEY_RESIZE) {
848 resize_boxes(level, win);
851 (void) waddstr(win, keyname(c));
852 } else if (c >= 0x80) {
853 unsigned c2 = (unsigned) c;
854 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
855 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
859 (void) wprintw(win, "%c", UChar(c));
860 else if (c2 != UChar(c))
861 (void) wprintw(win, "M-%s", unctrl(c2));
863 (void) wprintw(win, "%s", unctrl(c2));
864 waddstr(win, " (high-half character)");
867 (void) wprintw(win, "%c (ASCII printable character)", c);
869 (void) wprintw(win, "%s (ASCII control character)",
872 wgetch_wrap(win, first_y);
879 init_getch(win, flags);
883 begin_getch_test(void)
890 #ifdef NCURSES_MOUSE_VERSION
891 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
894 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
896 getnstr(buf, sizeof(buf) - 1);
900 if (isdigit(UChar(buf[0]))) {
901 delay = atoi(buf) * 100;
911 finish_getch_test(void)
913 #ifdef NCURSES_MOUSE_VERSION
914 mousemask(0, (mmask_t *) 0);
925 int delay = begin_getch_test();
928 wgetch_test(0, stdscr, delay);
934 #if USE_WIDEC_SUPPORT
936 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
937 * Resize both and paint the box in the parent.
939 #if defined(KEY_RESIZE) && HAVE_WRESIZE
941 resize_wide_boxes(unsigned level, WINDOW *win)
945 int high = LINES - base;
949 wnoutrefresh(stdscr);
953 for (n = 0; n < level; ++n) {
954 wresize(winstack[n].frame, high, wide);
955 wresize(winstack[n].text, high - 2, wide - 2);
958 werase(winstack[n].text);
959 box_set(winstack[n].frame, 0, 0);
960 wnoutrefresh(winstack[n].frame);
961 wprintw(winstack[n].text,
963 getmaxy(winstack[n].text),
964 getmaxx(winstack[n].text));
965 wnoutrefresh(winstack[n].text);
966 if (winstack[n].text == win)
971 #endif /* KEY_RESIZE */
974 wcstos(const wchar_t *src)
978 const wchar_t *tmp = src;
984 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
985 unsigned have = (unsigned) need;
986 if ((result = typeCalloc(char, have + 1)) != 0) {
988 if (trans_wchars(result, tmp, have, &state) != have) {
998 wget_wch_test(unsigned level, WINDOW *win, int delay)
1000 wchar_t wchar_buf[BUFSIZ];
1001 wint_t wint_buf[BUFSIZ];
1002 int first_y, first_x;
1006 bool blocking = (delay < 0);
1010 init_getch(win, flags);
1011 wtimeout(win, delay);
1012 getyx(win, first_y, first_x);
1014 wgetch_help(win, flags);
1015 wsetscrreg(win, first_y, getmaxy(win) - 1);
1016 scrollok(win, TRUE);
1019 while ((code = wGet_wchar(win, &c)) == ERR) {
1022 (void) wprintw(win, "%05d: input error", incount);
1025 (void) wprintw(win, "%05d: input timed out", incount);
1027 wgetch_wrap(win, first_y);
1029 if (code == ERR && blocking) {
1030 wprintw(win, "ERR");
1031 wgetch_wrap(win, first_y);
1032 } else if (isQuit((int) c)) {
1034 } else if (c == 'e') {
1035 flags[UChar('e')] = !flags[UChar('e')];
1036 setup_getch(win, flags);
1037 wgetch_help(win, flags);
1038 } else if (c == 'g') {
1039 waddstr(win, "getstr test: ");
1041 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1044 wprintw(win, "wgetn_wstr returns an error.");
1047 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1050 if ((temp = wcstos(wchar_buf)) != 0) {
1051 wprintw(win, "I saw %d characters:\n\t`%s'.",
1052 (int) wcslen(wchar_buf), temp);
1055 wprintw(win, "I saw %d characters (cannot convert).",
1056 (int) wcslen(wchar_buf));
1060 wgetch_wrap(win, first_y);
1061 } else if (c == 'k') {
1062 flags[UChar('k')] = !flags[UChar('k')];
1063 setup_getch(win, flags);
1064 wgetch_help(win, flags);
1065 } else if (c == 'm') {
1066 flags[UChar('m')] = !flags[UChar('m')];
1067 setup_getch(win, flags);
1068 wgetch_help(win, flags);
1069 } else if (c == 's') {
1071 } else if (c == 'w') {
1072 int high = getmaxy(win) - 1 - first_y + 1;
1073 int wide = getmaxx(win) - first_x;
1075 int new_y = first_y + getbegy(win);
1076 int new_x = first_x + getbegx(win);
1078 getyx(win, old_y, old_x);
1079 if (high > 2 && wide > 2) {
1080 WINDOW *wb = newwin(high, wide, new_y, new_x);
1081 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1086 remember_boxes(level, wi, wb);
1087 wget_wch_test(level + 1, wi, delay);
1091 wgetch_help(win, flags);
1092 wmove(win, old_y, old_x);
1097 } else if (c == 'z') {
1098 kill(getpid(), SIGTSTP);
1101 wprintw(win, "Key pressed: %04o ", (int) c);
1102 #ifdef NCURSES_MOUSE_VERSION
1103 if (c == KEY_MOUSE) {
1107 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1109 move(event.y, event.x);
1113 #endif /* NCURSES_MOUSE_VERSION */
1114 if (code == KEY_CODE_YES) {
1115 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1116 if (c == KEY_RESIZE) {
1117 resize_wide_boxes(level, win);
1120 (void) waddstr(win, keyname((wchar_t) c));
1122 (void) waddstr(win, key_name((wchar_t) c));
1123 if (c < 256 && iscntrl(c)) {
1124 (void) wprintw(win, " (control character)");
1126 (void) wprintw(win, " = %#x (printable character)",
1130 wgetch_wrap(win, first_y);
1137 init_getch(win, flags);
1143 int delay = begin_getch_test();
1146 wget_wch_test(0, stdscr, delay);
1148 finish_getch_test();
1153 /****************************************************************************
1155 * Character attributes test
1157 ****************************************************************************/
1159 #if HAVE_SETUPTERM || HAVE_TGETENT
1160 #define get_ncv() TIGETNUM("ncv","NC")
1161 #define get_xmc() TIGETNUM("xmc","sg")
1163 #define get_ncv() -1
1164 #define get_xmc() -1
1171 static int first = TRUE;
1172 static chtype result = 0;
1178 char *area_pointer = parsed;
1180 tgetent(buffer, getenv("TERM"));
1183 if (TIGETSTR("smso", "so"))
1184 result |= A_STANDOUT;
1185 if (TIGETSTR("smul", "us"))
1186 result |= A_UNDERLINE;
1187 if (TIGETSTR("rev", "mr"))
1188 result |= A_REVERSE;
1189 if (TIGETSTR("blink", "mb"))
1191 if (TIGETSTR("dim", "mh"))
1193 if (TIGETSTR("bold", "md"))
1195 if (TIGETSTR("smacs", "ac"))
1196 result |= A_ALTCHARSET;
1202 #define termattrs() my_termattrs()
1205 #define MAX_ATTRSTRING 31
1206 #define LEN_ATTRSTRING 26
1208 static char attr_test_string[MAX_ATTRSTRING + 1];
1211 attr_legend(WINDOW *helpwin)
1216 mvwprintw(helpwin, row++, col,
1218 mvwprintw(helpwin, row++, col,
1221 mvwprintw(helpwin, row++, col,
1222 "Modify the test strings:");
1223 mvwprintw(helpwin, row++, col,
1224 " A digit sets gaps on each side of displayed attributes");
1225 mvwprintw(helpwin, row++, col,
1226 " </> shifts the text left/right. ");
1228 mvwprintw(helpwin, row++, col,
1231 mvwprintw(helpwin, row++, col,
1232 " f/F/b/F toggle foreground/background background color");
1233 mvwprintw(helpwin, row++, col,
1234 " t/T toggle text/background color attribute");
1236 mvwprintw(helpwin, row++, col,
1237 " a/A toggle ACS (alternate character set) mapping");
1238 mvwprintw(helpwin, row++, col,
1239 " v/V toggle video attribute to combine with each line");
1243 show_color_attr(int fg, int bg, int tx)
1246 printw(" Colors (fg %d, bg %d", fg, bg);
1248 printw(", text %d", tx);
1254 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1261 *fg = (short) (*fg + 1);
1264 *fg = (short) (*fg - 1);
1267 *bg = (short) (*bg + 1);
1270 *bg = (short) (*bg - 1);
1273 *tx = (short) (*tx + 1);
1276 *tx = (short) (*tx - 1);
1284 *fg = (short) min_colors;
1285 if (*fg < min_colors)
1286 *fg = (short) (COLORS - 1);
1288 *bg = (short) min_colors;
1289 if (*bg < min_colors)
1290 *bg = (short) (COLORS - 1);
1294 *tx = (short) (COLORS - 1);
1303 adjust_attr_string(int adjust)
1305 int first = ((int) UChar(attr_test_string[0])) + adjust;
1306 int last = first + LEN_ATTRSTRING;
1308 if (first >= ' ' && last <= '~') { /* 32..126 */
1310 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1311 attr_test_string[j] = (char) k;
1312 if (((k + 1 - first) % 5) == 0) {
1313 if (++j >= MAX_ATTRSTRING)
1315 attr_test_string[j] = ' ';
1318 while (j < MAX_ATTRSTRING)
1319 attr_test_string[j++] = ' ';
1320 attr_test_string[j] = '\0';
1327 init_attr_string(void)
1329 attr_test_string[0] = 'a';
1330 adjust_attr_string(0);
1334 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1336 int ncv = get_ncv();
1337 chtype test = attr & (chtype) (~A_ALTCHARSET);
1340 mvprintw(row, 5, "-->");
1341 mvprintw(row, 8, "%s mode:", name);
1342 mvprintw(row, 24, "|");
1344 printw("%*s", skip, " ");
1346 * Just for testing, write text using the alternate character set one
1347 * character at a time (to pass its rendition directly), and use the
1348 * string operation for the other attributes.
1350 if (attr & A_ALTCHARSET) {
1354 for (s = attr_test_string; *s != '\0'; ++s) {
1360 addstr(attr_test_string);
1364 printw("%*s", skip, " ");
1366 if (test != A_NORMAL) {
1367 if (!(termattrs() & test)) {
1370 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1371 static const chtype table[] =
1387 for (n = 0; n < SIZEOF(table); n++) {
1388 if ((table[n] & attr) != 0
1389 && ((1 << n) & ncv) != 0) {
1397 if ((termattrs() & test) != test)
1404 static const struct {
1406 NCURSES_CONST char * name;
1407 } attrs_to_test[] = {
1408 { A_STANDOUT, "STANDOUT" },
1409 { A_REVERSE, "REVERSE" },
1411 { A_UNDERLINE, "UNDERLINE" },
1413 { A_BLINK, "BLINK" },
1414 { A_PROTECT, "PROTECT" },
1416 { A_INVIS, "INVISIBLE" },
1418 { A_NORMAL, "NORMAL" },
1423 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1433 if (ch < 256 && isdigit(ch)) {
1441 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1443 attr_legend(helpwin);
1456 *kc = SIZEOF(attrs_to_test) - 1;
1462 if (*kc >= SIZEOF(attrs_to_test))
1466 adjust_attr_string(-1);
1469 adjust_attr_string(1);
1475 error = cycle_color_attr(ch, fg, bg, tx);
1485 /* test text attributes */
1488 int skip = get_xmc();
1489 short fg = COLOR_BLACK; /* color pair 0 is special */
1490 short bg = COLOR_BLACK;
1498 n = skip; /* make it easy */
1499 k = SIZEOF(attrs_to_test) - 1;
1504 chtype normal = A_NORMAL | BLANK;
1505 chtype extras = (chtype) ac;
1508 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1511 if (init_pair(pair, fg, bg) == ERR) {
1514 normal |= COLOR_PAIR(pair);
1519 if (init_pair(pair, tx, bg) == ERR) {
1522 extras |= COLOR_PAIR(pair);
1531 mvaddstr(0, 20, "Character attribute test display");
1533 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1534 bool arrow = (j == k);
1535 row = show_attr(row, n, arrow,
1537 attrs_to_test[j].attr |
1538 attrs_to_test[k].attr,
1539 attrs_to_test[j].name);
1543 "This terminal does %shave the magic-cookie glitch",
1544 get_xmc() > -1 ? "" : "not ");
1545 mvprintw(row + 1, 8, "Enter '?' for help.");
1546 show_color_attr(fg, bg, tx);
1547 printw(" ACS (%d)", ac != 0);
1550 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1552 bkgdset(A_NORMAL | BLANK);
1557 #if USE_WIDEC_SUPPORT
1558 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1561 wide_adjust_attr_string(int adjust)
1563 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1564 int last = first + LEN_ATTRSTRING;
1566 if (first >= ' ' && last <= '~') { /* 32..126 */
1568 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1569 wide_attr_test_string[j] = k;
1570 if (((k + 1 - first) % 5) == 0) {
1571 if (++j >= MAX_ATTRSTRING)
1573 wide_attr_test_string[j] = ' ';
1576 while (j < MAX_ATTRSTRING)
1577 wide_attr_test_string[j++] = ' ';
1578 wide_attr_test_string[j] = '\0';
1585 wide_init_attr_string(void)
1587 wide_attr_test_string[0] = 'a';
1588 wide_adjust_attr_string(0);
1592 set_wide_background(short pair)
1599 setcchar(&normal, blank, A_NORMAL, pair, 0);
1605 get_wide_background(void)
1607 attr_t result = A_NORMAL;
1613 if (getbkgrnd(&ch) != ERR) {
1614 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1622 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1624 int ncv = get_ncv();
1625 chtype test = attr & ~WA_ALTCHARSET;
1628 mvprintw(row, 5, "-->");
1629 mvprintw(row, 8, "%s mode:", name);
1630 mvprintw(row, 24, "|");
1632 printw("%*s", skip, " ");
1635 * Just for testing, write text using the alternate character set one
1636 * character at a time (to pass its rendition directly), and use the
1637 * string operation for the other attributes.
1639 if (attr & WA_ALTCHARSET) {
1643 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1647 setcchar(&ch, fill, attr, pair, 0);
1654 attr_get(&old_attr, &old_pair, 0);
1655 attr_set(attr, pair, 0);
1656 addwstr(wide_attr_test_string);
1657 attr_set(old_attr, old_pair, 0);
1660 printw("%*s", skip, " ");
1662 if (test != A_NORMAL) {
1663 if (!(term_attrs() & test)) {
1666 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1667 static const attr_t table[] =
1681 for (n = 0; n < SIZEOF(table); n++) {
1682 if ((table[n] & attr) != 0
1683 && ((1 << n) & ncv) != 0) {
1691 if ((term_attrs() & test) != test)
1699 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1709 if (ch < 256 && isdigit(ch)) {
1717 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1718 box_set(helpwin, 0, 0);
1719 attr_legend(helpwin);
1732 *kc = SIZEOF(attrs_to_test) - 1;
1738 if (*kc >= SIZEOF(attrs_to_test))
1742 wide_adjust_attr_string(-1);
1745 wide_adjust_attr_string(1);
1751 error = cycle_color_attr(ch, fg, bg, tx);
1760 wide_attr_test(void)
1761 /* test text attributes using wide-character calls */
1764 int skip = get_xmc();
1765 short fg = COLOR_BLACK; /* color pair 0 is special */
1766 short bg = COLOR_BLACK;
1774 n = skip; /* make it easy */
1775 k = SIZEOF(attrs_to_test) - 1;
1776 wide_init_attr_string();
1784 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1787 if (init_pair(pair, fg, bg) == ERR) {
1794 if (init_pair(extras, tx, bg) == ERR) {
1799 set_wide_background(pair);
1802 box_set(stdscr, 0, 0);
1803 mvaddstr(0, 20, "Character attribute test display");
1805 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1806 row = wide_show_attr(row, n, j == k,
1808 attrs_to_test[j].attr |
1809 attrs_to_test[k].attr,
1811 attrs_to_test[j].name);
1815 "This terminal does %shave the magic-cookie glitch",
1816 get_xmc() > -1 ? "" : "not ");
1817 mvprintw(row + 1, 8, "Enter '?' for help.");
1818 show_color_attr(fg, bg, tx);
1819 printw(" ACS (%d)", ac != 0);
1822 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1824 set_wide_background(0);
1830 /****************************************************************************
1832 * Color support tests
1834 ****************************************************************************/
1836 static NCURSES_CONST char *the_color_names[] =
1857 show_color_name(int y, int x, int color, bool wide)
1859 if (move(y, x) != ERR) {
1864 sprintf(temp, "%02d", color);
1866 } else if (color >= 8) {
1867 sprintf(temp, "[%02d]", color);
1868 } else if (color < 0) {
1869 strcpy(temp, "default");
1871 strcpy(temp, the_color_names[color]);
1873 printw("%-*.*s", width, width, temp);
1878 color_legend(WINDOW *helpwin, bool wide)
1883 mvwprintw(helpwin, row++, col,
1886 mvwprintw(helpwin, row++, col,
1887 "Use up/down arrow to scroll through the display if it is");
1888 mvwprintw(helpwin, row++, col,
1889 "longer than one screen. Control/N and Control/P can be used");
1890 mvwprintw(helpwin, row++, col,
1891 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1892 mvwprintw(helpwin, row++, col,
1893 "full screen; control/B and control/F can be used here.");
1895 mvwprintw(helpwin, row++, col,
1897 mvwprintw(helpwin, row++, col,
1898 " a/A toggle altcharset off/on");
1899 mvwprintw(helpwin, row++, col,
1900 " b/B toggle bold off/on");
1901 mvwprintw(helpwin, row++, col,
1902 " n/N toggle text/number on/off");
1903 mvwprintw(helpwin, row++, col,
1904 " r/R toggle reverse on/off");
1905 mvwprintw(helpwin, row++, col,
1906 " w/W toggle width between 8/16 colors");
1907 #if USE_WIDEC_SUPPORT
1909 mvwprintw(helpwin, row++, col,
1910 "Wide characters:");
1911 mvwprintw(helpwin, row++, col,
1912 " x/X toggle text between ASCII and wide-character");
1919 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1921 /* generate a color test pattern */
1928 int grid_top = top + 3;
1929 int page_size = (LINES - grid_top);
1930 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1936 bool opt_acsc = FALSE;
1937 bool opt_bold = FALSE;
1938 bool opt_revs = FALSE;
1939 bool opt_nums = FALSE;
1940 bool opt_wide = FALSE;
1943 if (COLORS * COLORS == COLOR_PAIRS) {
1944 int limit = (COLORS - min_colors) * (COLORS - min_colors);
1945 if (pairs_max > limit)
1948 if (pairs_max > COLOR_PAIRS)
1949 pairs_max = COLOR_PAIRS;
1955 /* this assumes an 80-column line */
1959 per_row = (COLORS > 8) ? 16 : 8;
1965 per_row -= min_colors;
1967 row_limit = (pairs_max + per_row - 1) / per_row;
1970 (void) printw("There are %d color pairs and %d colors%s\n",
1972 min_colors ? " besides 'default'" : "");
1975 (void) mvprintw(top + 1, 0,
1976 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1979 opt_bold ? "on" : "off");
1981 /* show color names/numbers across the top */
1982 for (i = 0; i < per_row; i++)
1983 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
1985 /* show a grid of colors, with color names/ numbers on the left */
1986 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
1987 int row = grid_top + (i / per_row) - base_row;
1988 int col = (i % per_row + 1) * width;
1991 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
1992 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
1993 if (row >= 0 && move(row, col) != ERR) {
1994 short fg = InxToFG(i);
1995 short bg = InxToBG(i);
1997 init_pair(pair, fg, bg);
1998 attron((attr_t) COLOR_PAIR(pair));
2000 attron((attr_t) A_ALTCHARSET);
2002 attron((attr_t) A_BOLD);
2004 attron((attr_t) A_REVERSE);
2007 sprintf(numbered, "{%02X}", i);
2010 printw("%-*.*s", width, width, hello);
2013 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2014 show_color_name(row, 0, InxToBG(i), opt_wide);
2022 switch (wGetchar(stdscr)) {
2051 set_color_test(opt_wide, FALSE);
2054 set_color_test(opt_wide, TRUE);
2058 if (base_row <= 0) {
2066 if (base_row + page_size >= row_limit) {
2075 if (base_row <= 0) {
2078 base_row -= (page_size - 1);
2086 if (base_row + page_size >= row_limit) {
2089 base_row += page_size - 1;
2090 if (base_row + page_size >= row_limit) {
2091 base_row = row_limit - page_size - 1;
2096 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2098 color_legend(helpwin, FALSE);
2113 #if USE_WIDEC_SUPPORT
2114 /* generate a color test pattern */
2116 wide_color_test(void)
2122 int grid_top = top + 3;
2123 int page_size = (LINES - grid_top);
2124 int pairs_max = (unsigned short) (-1);
2130 bool opt_acsc = FALSE;
2131 bool opt_bold = FALSE;
2132 bool opt_revs = FALSE;
2133 bool opt_wide = FALSE;
2134 bool opt_nums = FALSE;
2135 bool opt_xchr = FALSE;
2139 if (COLORS * COLORS == COLOR_PAIRS) {
2140 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2141 if (pairs_max > limit)
2144 if (pairs_max > COLOR_PAIRS)
2145 pairs_max = COLOR_PAIRS;
2151 /* this assumes an 80-column line */
2155 per_row = (COLORS > 8) ? 16 : 8;
2161 per_row -= min_colors;
2164 make_fullwidth_text(buffer, hello);
2168 make_narrow_text(buffer, hello);
2171 row_limit = (pairs_max + per_row - 1) / per_row;
2174 (void) printw("There are %d color pairs and %d colors%s\n",
2176 min_colors ? " besides 'default'" : "");
2179 (void) mvprintw(top + 1, 0,
2180 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2183 opt_bold ? "on" : "off");
2185 /* show color names/numbers across the top */
2186 for (i = 0; i < per_row; i++)
2187 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2189 /* show a grid of colors, with color names/ numbers on the left */
2190 for (i = (base_row * per_row); i < pairs_max; i++) {
2191 int row = grid_top + (i / per_row) - base_row;
2192 int col = (i % per_row + 1) * width;
2193 short pair = (short) i;
2195 if (row >= 0 && move(row, col) != ERR) {
2196 init_pair(pair, InxToFG(i), InxToBG(i));
2197 color_set(pair, NULL);
2199 attr_on((attr_t) A_ALTCHARSET, NULL);
2201 attr_on((attr_t) A_BOLD, NULL);
2203 attr_on((attr_t) A_REVERSE, NULL);
2206 sprintf(numbered, "{%02X}", i);
2208 make_fullwidth_text(buffer, numbered);
2210 make_narrow_text(buffer, numbered);
2213 addnwstr(buffer, width);
2214 attr_set(A_NORMAL, 0, NULL);
2216 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2217 show_color_name(row, 0, InxToBG(i), opt_wide);
2225 switch (c = wGetchar(stdscr)) {
2254 set_color_test(opt_wide, FALSE);
2257 set_color_test(opt_wide, TRUE);
2267 if (base_row <= 0) {
2275 if (base_row + page_size >= row_limit) {
2284 if (base_row <= 0) {
2287 base_row -= (page_size - 1);
2295 if (base_row + page_size >= row_limit) {
2298 base_row += page_size - 1;
2299 if (base_row + page_size >= row_limit) {
2300 base_row = row_limit - page_size - 1;
2305 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2307 color_legend(helpwin, TRUE);
2321 #endif /* USE_WIDEC_SUPPORT */
2324 change_color(short current, int field, int value, int usebase)
2326 short red, green, blue;
2328 color_content(current, &red, &green, &blue);
2332 red = (short) (usebase ? (red + value) : value);
2335 green = (short) (usebase ? (green + value) : value);
2338 blue = (short) (usebase ? (blue + value) : value);
2342 if (init_color(current, red, green, blue) == ERR)
2347 init_all_colors(void)
2351 for (c = 0; c < COLORS; ++c)
2354 all_colors[c].green,
2355 all_colors[c].blue);
2358 #define scaled_rgb(n) ((255 * (n)) / 1000)
2362 /* display the color test pattern, without trying to edit colors */
2366 int this_c = 0, value = 0, field = 0;
2369 int page_size = (LINES - 6);
2374 for (i = 0; i < max_colors; i++)
2375 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2377 mvprintw(LINES - 2, 0, "Number: %d", value);
2380 short red, green, blue;
2383 mvaddstr(0, 20, "Color RGB Value Editing");
2386 for (i = (short) top_color;
2387 (i - top_color < page_size)
2388 && (i < max_colors); i++) {
2391 sprintf(numeric, "[%d]", i);
2392 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2393 (i == current ? '>' : ' '),
2394 (i < (int) SIZEOF(the_color_names)
2395 ? the_color_names[i] : numeric));
2396 attrset(COLOR_PAIR(i));
2400 color_content((short) i, &red, &green, &blue);
2402 if (current == i && field == 0)
2404 printw("%04d", red);
2405 if (current == i && field == 0)
2408 if (current == i && field == 1)
2410 printw("%04d", green);
2411 if (current == i && field == 1)
2414 if (current == i && field == 2)
2416 printw("%04d", blue);
2417 if (current == i && field == 2)
2420 printw(" ( %3d %3d %3d )",
2426 mvaddstr(LINES - 3, 0,
2427 "Use up/down to select a color, left/right to change fields.");
2428 mvaddstr(LINES - 2, 0,
2429 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2431 move(2 + current - top_color, 0);
2435 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2442 current -= (page_size - 1);
2449 if (current < (max_colors - 1))
2450 current += (page_size - 1);
2457 current = (current == 0 ? (max_colors - 1) : current - 1);
2462 current = (current == (max_colors - 1) ? 0 : current + 1);
2466 field = (field == 2 ? 0 : field + 1);
2470 field = (field == 0 ? 2 : field - 1);
2483 value = value * 10 + (this_c - '0');
2487 change_color((short) current, field, value, 1);
2491 change_color((short) current, field, -value, 1);
2495 change_color((short) current, field, value, 0);
2500 P(" RGB Value Editing Help");
2502 P("You are in the RGB value editor. Use the arrow keys to select one of");
2503 P("the fields in one of the RGB triples of the current colors; the one");
2504 P("currently selected will be reverse-video highlighted.");
2506 P("To change a field, enter the digits of the new value; they are echoed");
2507 P("as entered. Finish by typing `='. The change will take effect instantly.");
2508 P("To increment or decrement a value, use the same procedure, but finish");
2509 P("with a `+' or `-'.");
2511 P("Press 'm' to invoke the top-level menu with the current color settings.");
2512 P("To quit, do ESC");
2534 if (current >= max_colors)
2535 current = max_colors - 1;
2536 if (current < top_color)
2537 top_color = current;
2538 if (current - top_color >= page_size)
2539 top_color = current - (page_size - 1);
2541 mvprintw(LINES - 1, 0, "Number: %d", value);
2549 * ncurses does not reset each color individually when calling endwin().
2556 /****************************************************************************
2558 * Soft-key label test
2560 ****************************************************************************/
2565 #define SLK_WORK (SLK_HELP + 3)
2570 static const char *table[] =
2572 "Available commands are:"
2574 ,"^L -- repaint this message and activate soft keys"
2575 ,"a/d -- activate/disable soft keys"
2576 ,"c -- set centered format for labels"
2577 ,"l -- set left-justified format for labels"
2578 ,"r -- set right-justified format for labels"
2579 ,"[12345678] -- set label; labels are numbered 1 through 8"
2580 ,"e -- erase stdscr (should not erase labels)"
2581 ,"s -- test scrolling of shortened screen"
2583 ,"F/B -- cycle through foreground/background colors"
2585 ,"ESC -- return to main menu"
2587 ,"Note: if activating the soft keys causes your terminal to scroll up"
2588 ,"one line, your terminal auto-scrolls when anything is written to the"
2589 ,"last screen position. The ncurses code does not yet handle this"
2595 for (j = 0; j < SIZEOF(table); ++j) {
2603 call_slk_color(short fg, short bg)
2605 init_pair(1, bg, fg);
2607 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2615 /* exercise the soft keys */
2621 short fg = COLOR_BLACK;
2622 short bg = COLOR_WHITE;
2628 call_slk_color(fg, bg);
2638 mvaddstr(0, 20, "Soft Key Exerciser");
2653 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2654 while ((c = Getchar()) != 'Q' && (c != ERR))
2682 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2684 if ((s = slk_label(c - '0')) != 0) {
2687 wGetstring(stdscr, buf, 8);
2688 slk_set((c - '0'), buf, fmt);
2700 fg = (short) ((fg + 1) % COLORS);
2701 call_slk_color(fg, bg);
2706 bg = (short) ((bg + 1) % COLORS);
2707 call_slk_color(fg, bg);
2711 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2713 wnoutrefresh(stdscr);
2720 } while (!isQuit(c = Getchar()));
2728 #if USE_WIDEC_SUPPORT
2732 /* exercise the soft keys */
2735 wchar_t buf[SLKLEN + 1];
2737 short fg = COLOR_BLACK;
2738 short bg = COLOR_WHITE;
2742 call_slk_color(fg, bg);
2749 attr_on(WA_BOLD, NULL);
2750 mvaddstr(0, 20, "Soft Key Exerciser");
2751 attr_off(WA_BOLD, NULL);
2765 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2766 while ((c = Getchar()) != 'Q' && (c != ERR))
2794 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2796 if ((s = slk_label(c - '0')) != 0) {
2797 char *temp = strdup(s);
2798 size_t used = strlen(temp);
2799 size_t want = SLKLEN;
2801 #ifndef state_unused
2806 while (want > 0 && used != 0) {
2807 const char *base = s;
2808 reset_mbytes(state);
2809 test = count_mbytes(base, 0, &state);
2810 if (test == (size_t) -1) {
2812 } else if (test > want) {
2815 reset_mbytes(state);
2816 trans_mbytes(buf, base, want, &state);
2822 wGet_wstring(stdscr, buf, SLKLEN);
2823 slk_wset((c - '0'), buf, fmt);
2834 fg = (short) ((fg + 1) % COLORS);
2835 call_slk_color(fg, bg);
2840 bg = (short) ((bg + 1) % COLORS);
2841 call_slk_color(fg, bg);
2844 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2846 wnoutrefresh(stdscr);
2852 } while (!isQuit(c = Getchar()));
2860 #endif /* SLK_INIT */
2862 /****************************************************************************
2864 * Alternate character-set stuff
2866 ****************************************************************************/
2871 } attrs_to_cycle[] = {
2872 { A_NORMAL, "normal" },
2874 { A_BLINK, "blink" },
2875 { A_REVERSE, "reverse" },
2876 { A_UNDERLINE, "underline" },
2881 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2887 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2892 *at_code = SIZEOF(attrs_to_cycle) - 1;
2901 *attr = attrs_to_cycle[*at_code].attr;
2906 cycle_colors(int ch, int *fg, int *bg, short *pair)
2908 bool result = FALSE;
2918 if ((*fg += 1) >= COLORS)
2926 if ((*bg += 1) >= COLORS)
2934 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2937 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2946 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2947 * terminal to perform functions. The remaining codes can be graphic.
2950 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
2952 bool C1 = (first == 128);
2954 unsigned last = first + 31;
2959 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2960 C1 ? "C1" : "GR", first, last);
2964 for (code = first; code <= last; code++) {
2966 int row = 2 + ((int) (code - first) % 16);
2967 int col = ((int) (code - first) / 16) * COLS / 2;
2969 sprintf(tmp, "%3u (0x%x)", code, code);
2970 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2974 nodelay(stdscr, TRUE);
2975 echochar(colored_chtype(code, attr, pair));
2977 /* (yes, this _is_ crude) */
2978 while ((reply = Getchar()) != ERR) {
2979 addch(UChar(reply));
2982 nodelay(stdscr, FALSE);
2984 } while (--count > 0);
2991 show_pc_chars(int repeat, attr_t attr, short pair)
2997 mvprintw(0, 20, "Display of PC Character Codes");
3001 for (code = 0; code < 16; ++code) {
3002 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
3004 for (code = 0; code < 256; code++) {
3006 int row = 3 + (int) (code / 16) + (code >= 128);
3007 int col = 8 + (int) (code % 16) * PC_COLS;
3008 if ((code % 16) == 0)
3009 mvprintw(row, 0, "0x%02x:", code);
3020 * Skip the ones that do not work.
3024 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3027 } while (--count > 0);
3032 show_box_chars(int repeat, attr_t attr, short pair)
3035 attr |= COLOR_PAIR(pair);
3039 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
3044 colored_chtype(ACS_VLINE, attr, pair),
3045 colored_chtype(ACS_VLINE, attr, pair),
3046 colored_chtype(ACS_HLINE, attr, pair),
3047 colored_chtype(ACS_HLINE, attr, pair),
3048 colored_chtype(ACS_ULCORNER, attr, pair),
3049 colored_chtype(ACS_URCORNER, attr, pair),
3050 colored_chtype(ACS_LLCORNER, attr, pair),
3051 colored_chtype(ACS_LRCORNER, attr, pair));
3052 mvhline(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3053 mvvline(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3054 mvaddch(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3055 mvaddch(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3056 mvaddch(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3057 mvaddch(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3058 mvaddch(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3064 show_1_acs(int n, int repeat, const char *name, chtype code)
3066 const int height = 16;
3067 int row = 2 + (n % height);
3068 int col = (n / height) * COLS / 2;
3070 mvprintw(row, col, "%*s : ", COLS / 4, name);
3073 } while (--repeat > 0);
3078 show_acs_chars(int repeat, attr_t attr, short pair)
3079 /* display the ACS character set */
3083 #define BOTH(name) #name, colored_chtype(name, attr, pair)
3087 mvaddstr(0, 20, "Display of the ACS Character Set");
3091 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3092 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3093 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3094 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3096 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3097 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3098 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3099 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3101 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3102 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3105 * HPUX's ACS definitions are broken here. Just give up.
3107 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3108 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3109 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3110 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3111 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3113 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3114 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3115 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3116 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3117 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3118 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3119 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3120 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3121 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3123 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3124 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3125 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3127 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3128 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3129 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3130 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3131 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3132 n = show_1_acs(n, repeat, BOTH(ACS_S9));
3140 char *term = getenv("TERM");
3141 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3144 chtype attr = A_NORMAL;
3147 int fg = COLOR_BLACK;
3148 int bg = COLOR_BLACK;
3149 unsigned at_code = 0;
3151 void (*last_show_acs) (int, attr_t, short) = 0;
3159 ToggleAcs(last_show_acs, show_acs_chars);
3163 ToggleAcs(last_show_acs, show_pc_chars);
3168 ToggleAcs(last_show_acs, show_box_chars);
3194 if (repeat < (COLS / 4))
3202 if (cycle_attr(c, &at_code, &attr)
3203 || cycle_colors(c, &fg, &bg, &pair)) {
3210 if (last_show_acs != 0)
3211 last_show_acs(repeat, attr, pair);
3213 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3215 mvprintw(LINES - 3, 0,
3216 "Note: ANSI terminals may not display C1 characters.");
3217 mvprintw(LINES - 2, 0,
3218 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3221 mvprintw(LINES - 1, 0,
3222 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3223 attrs_to_cycle[at_code].name,
3226 mvprintw(LINES - 1, 0,
3227 "v/V cycles through video attributes (%s).",
3228 attrs_to_cycle[at_code].name);
3231 } while (!isQuit(c = Getchar()));
3238 #if USE_WIDEC_SUPPORT
3240 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3242 int count = getcchar(src, NULL, NULL, NULL, 0);
3249 if ((wch = typeMalloc(wchar_t, (unsigned) count + 1)) != 0) {
3250 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
3251 attr |= (ignore_attr & A_ALTCHARSET);
3252 setcchar(dst, wch, attr, pair, 0);
3261 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3265 int last = first + 31;
3269 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3272 for (code = first; (int) code <= last; code++) {
3273 int row = 2 + ((code - first) % 16);
3274 int col = ((code - first) / 16) * COLS / 2;
3280 memset(&codes, 0, sizeof(codes));
3282 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3283 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3284 setcchar(&temp, codes, attr, pair, 0);
3287 * Give non-spacing characters something to combine with. If we
3288 * don't, they'll bunch up in a heap on the space after the ":".
3289 * Mark them with reverse-video to make them simpler to find on
3292 if (wcwidth(code) == 0)
3293 addch(space | (A_REVERSE ^ attr) | COLOR_PAIR(pair));
3295 * This could use add_wch(), but is done for comparison with the
3296 * normal 'f' test (and to make a test-case for echo_wchar()).
3297 * The screen will flicker because the erase() at the top of the
3298 * function is met by the builtin refresh() in echo_wchar().
3302 * The repeat-count may make text wrap - avoid that.
3304 getyx(stdscr, y, x);
3305 if (x >= col + (COLS / 2) - 2)
3307 } while (--count > 0);
3312 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3314 const int height = 16;
3315 int row = 2 + (n % height);
3316 int col = (n / height) * COLS / 2;
3318 mvprintw(row, col, "%*s : ", COLS / 4, name);
3319 while (--repeat >= 0) {
3325 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3328 show_wacs_chars(int repeat, attr_t attr, short pair)
3329 /* display the wide-ACS character set */
3335 /*#define BOTH2(name) #name, &(name) */
3336 #define BOTH2(name) #name, MERGE_ATTR(name)
3340 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3344 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3345 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3346 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3347 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3349 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3350 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3351 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3352 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3354 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3355 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3357 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3358 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3359 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3360 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3362 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3363 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3364 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3365 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3366 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3367 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3368 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3369 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3370 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3372 #ifdef CURSES_WACS_ARRAY
3373 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3374 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3375 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3377 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3378 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3379 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3380 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3381 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3382 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3388 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3391 show_wbox_chars(int repeat, attr_t attr, short pair)
3398 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3403 MERGE_ATTR(0, WACS_VLINE),
3404 MERGE_ATTR(1, WACS_VLINE),
3405 MERGE_ATTR(2, WACS_HLINE),
3406 MERGE_ATTR(3, WACS_HLINE),
3407 MERGE_ATTR(4, WACS_ULCORNER),
3408 MERGE_ATTR(5, WACS_URCORNER),
3409 MERGE_ATTR(6, WACS_LLCORNER),
3410 MERGE_ATTR(7, WACS_LRCORNER));
3412 mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3413 mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3414 mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3415 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3416 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3417 mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3418 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3426 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3428 const int height = 16;
3429 int row = 2 + (n % height);
3430 int col = (n / height) * COLS / 2;
3433 mvprintw(row, col, "%*s : ", COLS / 4, name);
3434 attr_set(attr, pair, 0);
3435 addstr(strcpy(temp, code));
3436 attr_set(A_NORMAL, 0, 0);
3440 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3443 show_utf8_chars(int repeat, attr_t attr, short pair)
3450 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3454 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3455 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3456 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3457 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3459 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3460 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3461 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3462 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3464 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3465 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3467 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3468 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3469 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3470 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3472 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3473 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3474 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3475 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3476 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3477 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3478 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3479 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3480 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3481 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3482 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3483 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3485 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3486 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3487 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3488 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3489 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3490 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3495 /* display the wide-ACS character set */
3497 wide_acs_display(void)
3503 chtype attr = A_NORMAL;
3504 int fg = COLOR_BLACK;
3505 int bg = COLOR_BLACK;
3506 unsigned at_code = 0;
3508 void (*last_show_wacs) (int, attr_t, short) = 0;
3516 ToggleAcs(last_show_wacs, show_wacs_chars);
3519 ToggleAcs(last_show_wacs, show_wbox_chars);
3522 ToggleAcs(last_show_wacs, show_utf8_chars);
3525 if (c < 256 && isdigit(c)) {
3528 } else if (c == '+') {
3531 } else if (c == '-' && digit > 0) {
3534 } else if (c == '>' && repeat < (COLS / 4)) {
3536 } else if (c == '<' && repeat > 1) {
3538 } else if (c == '_') {
3539 space = (space == ' ') ? '_' : ' ';
3541 } else if (cycle_attr(c, &at_code, &attr)
3542 || cycle_colors(c, &fg, &bg, &pair)) {
3543 if (last_show_wacs != 0)
3551 if (last_show_wacs != 0)
3552 last_show_wacs(repeat, attr, pair);
3554 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3556 mvprintw(LINES - 3, 0,
3557 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3559 mvprintw(LINES - 2, 0,
3560 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3561 attrs_to_cycle[at_code].name,
3564 mvprintw(LINES - 2, 0,
3565 "v/V cycles through video attributes (%s).",
3566 attrs_to_cycle[at_code].name);
3569 } while (!isQuit(c = Getchar()));
3579 * Graphic-rendition test (adapted from vttest)
3582 test_sgr_attributes(void)
3586 for (pass = 0; pass < 2; pass++) {
3587 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3589 /* Use non-default colors if possible to exercise bce a little */
3591 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3592 normal |= COLOR_PAIR(1);
3596 mvprintw(1, 20, "Graphic rendition test pattern:");
3598 mvprintw(4, 1, "vanilla");
3600 #define set_sgr(mask) bkgdset((normal^(mask)));
3602 mvprintw(4, 40, "bold");
3604 set_sgr(A_UNDERLINE);
3605 mvprintw(6, 6, "underline");
3607 set_sgr(A_BOLD | A_UNDERLINE);
3608 mvprintw(6, 45, "bold underline");
3611 mvprintw(8, 1, "blink");
3613 set_sgr(A_BLINK | A_BOLD);
3614 mvprintw(8, 40, "bold blink");
3616 set_sgr(A_UNDERLINE | A_BLINK);
3617 mvprintw(10, 6, "underline blink");
3619 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3620 mvprintw(10, 45, "bold underline blink");
3623 mvprintw(12, 1, "negative");
3625 set_sgr(A_BOLD | A_REVERSE);
3626 mvprintw(12, 40, "bold negative");
3628 set_sgr(A_UNDERLINE | A_REVERSE);
3629 mvprintw(14, 6, "underline negative");
3631 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3632 mvprintw(14, 45, "bold underline negative");
3634 set_sgr(A_BLINK | A_REVERSE);
3635 mvprintw(16, 1, "blink negative");
3637 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3638 mvprintw(16, 40, "bold blink negative");
3640 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3641 mvprintw(18, 6, "underline blink negative");
3643 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3644 mvprintw(18, 45, "bold underline blink negative");
3647 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3653 bkgdset(A_NORMAL | BLANK);
3658 /****************************************************************************
3660 * Windows and scrolling tester.
3662 ****************************************************************************/
3664 #define BOTLINES 4 /* number of line stolen from screen bottom */
3670 #define FRAME struct frame
3679 #if defined(NCURSES_VERSION)
3680 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3681 #define is_keypad(win) (win)->_use_keypad
3682 #define is_scrollok(win) (win)->_scroll
3683 #elif !defined(is_keypad)
3684 #define is_keypad(win) FALSE
3685 #define is_scrollok(win) FALSE
3688 #define is_keypad(win) FALSE
3689 #define is_scrollok(win) FALSE
3693 frame_win(FRAME * curp)
3695 return (curp != 0) ? curp->wind : stdscr;
3698 /* We need to know if these flags are actually set, so don't look in FRAME.
3699 * These names are known to work with SVr4 curses as well as ncurses. The
3700 * _use_keypad name does not work with Solaris 8.
3703 HaveKeypad(FRAME * curp)
3705 WINDOW *win = frame_win(curp);
3707 return is_keypad(win);
3711 HaveScroll(FRAME * curp)
3713 WINDOW *win = frame_win(curp);
3715 return is_scrollok(win);
3719 newwin_legend(FRAME * curp)
3721 static const struct {
3726 "^C = create window", 0
3729 "^N = next window", 0
3732 "^P = previous window", 0
3735 "^F = scroll forward", 0
3738 "^B = scroll backward", 0
3741 "^K = keypad(%s)", 1
3744 "^S = scrollok(%s)", 2
3747 "^W = save window to file", 0
3750 "^R = restore window", 0
3763 bool do_keypad = HaveKeypad(curp);
3764 bool do_scroll = HaveScroll(curp);
3768 for (n = 0; n < SIZEOF(legend); n++) {
3769 switch (legend[n].code) {
3771 strcpy(buf, legend[n].msg);
3774 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3777 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3780 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3783 x = getcurx(stdscr);
3784 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));