1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 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.355 2010/01/09 16:52:17 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;
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) init_mb(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) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(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) init_mb(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) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(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 (void) 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) {
323 make_fullwidth_digit(cchar_t *target, int digit)
327 source[0] = fullwidth_of(digit + '0');
329 setcchar(target, source, A_NORMAL, 0, 0);
334 wGet_wchar(WINDOW *win, wint_t *result)
338 while ((c = wget_wch(win, result)) == CTRL('T')) {
340 save_trace = _nc_tracing;
341 Trace(("TOGGLE-TRACING OFF"));
344 _nc_tracing = save_trace;
348 Trace(("TOGGLE-TRACING ON"));
351 c = wget_wch(win, result);
355 #define Get_wchar(result) wGet_wchar(stdscr, result)
357 /* replaces wgetn_wstr(), since we want to be able to edit values */
359 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
368 (void) wattrset(win, A_REVERSE);
370 x = (int) wcslen(buffer);
372 if (x > (int) wcslen(buffer))
373 x = (int) wcslen(buffer);
375 /* clear the "window' */
377 wprintw(win, "%*s", limit, " ");
379 /* write the existing buffer contents */
381 waddnwstr(win, buffer, limit);
383 /* positions the cursor past character 'x' */
385 waddnwstr(win, buffer, x);
387 switch (wGet_wchar(win, &ch)) {
427 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
447 } else if ((int) wcslen(buffer) < limit) {
449 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
450 buffer[j] = buffer[j - 1];
452 buffer[x++] = (wchar_t) ch;
459 wattroff(win, A_REVERSE);
470 addstr("Press any key to continue... ");
475 Cannot(const char *what)
477 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
482 ShellOut(bool message)
485 addstr("Shelling out...");
494 addstr("returned from shellout.\n");
498 #ifdef NCURSES_MOUSE_VERSION
500 * This function is the same as _tracemouse(), but we cannot count on that
501 * being available in the non-debug library.
504 mouse_decode(MEVENT const *ep)
506 static char buf[80 + (5 * 10) + (32 * 15)];
508 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
509 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
511 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
513 SHOW(BUTTON1_RELEASED, "release-1");
514 SHOW(BUTTON1_PRESSED, "press-1");
515 SHOW(BUTTON1_CLICKED, "click-1");
516 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
517 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
518 #if NCURSES_MOUSE_VERSION == 1
519 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
522 SHOW(BUTTON2_RELEASED, "release-2");
523 SHOW(BUTTON2_PRESSED, "press-2");
524 SHOW(BUTTON2_CLICKED, "click-2");
525 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
526 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
527 #if NCURSES_MOUSE_VERSION == 1
528 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
531 SHOW(BUTTON3_RELEASED, "release-3");
532 SHOW(BUTTON3_PRESSED, "press-3");
533 SHOW(BUTTON3_CLICKED, "click-3");
534 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
535 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
536 #if NCURSES_MOUSE_VERSION == 1
537 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
540 SHOW(BUTTON4_RELEASED, "release-4");
541 SHOW(BUTTON4_PRESSED, "press-4");
542 SHOW(BUTTON4_CLICKED, "click-4");
543 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
544 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
545 #if NCURSES_MOUSE_VERSION == 1
546 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
549 #if NCURSES_MOUSE_VERSION == 2
550 SHOW(BUTTON5_RELEASED, "release-5");
551 SHOW(BUTTON5_PRESSED, "press-5");
552 SHOW(BUTTON5_CLICKED, "click-5");
553 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
554 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
557 SHOW(BUTTON_CTRL, "ctrl");
558 SHOW(BUTTON_SHIFT, "shift");
559 SHOW(BUTTON_ALT, "alt");
560 SHOW(ALL_MOUSE_EVENTS, "all-events");
561 SHOW(REPORT_MOUSE_POSITION, "position");
565 if (buf[strlen(buf) - 1] == ' ')
566 buf[strlen(buf) - 2] = '\0';
567 (void) strcat(buf, "}");
572 show_mouse(WINDOW *win)
580 outside = !wenclose(win, event.y, event.x);
583 (void) wstandout(win);
584 waddstr(win, "KEY_MOUSE");
585 (void) wstandend(win);
587 waddstr(win, "KEY_MOUSE");
589 wprintw(win, ", %s", mouse_decode(&event));
594 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
598 wmove(win, event.y, event.x);
606 #endif /* NCURSES_MOUSE_VERSION */
608 /****************************************************************************
610 * Character input test
612 ****************************************************************************/
614 #define NUM_GETCH_FLAGS 256
615 typedef bool GetchFlags[NUM_GETCH_FLAGS];
618 setup_getch(WINDOW *win, GetchFlags flags)
620 keypad(win, flags['k']); /* should be redundant, but for testing */
621 meta(win, flags['m']); /* force this to a known state */
629 init_getch(WINDOW *win, GetchFlags flags)
631 memset(flags, FALSE, NUM_GETCH_FLAGS);
632 flags[UChar('k')] = (win == stdscr);
633 flags[UChar('m')] = TRUE;
635 setup_getch(win, flags);
639 wgetch_help(WINDOW *win, GetchFlags flags)
641 static const char *help[] =
643 "e -- toggle echo mode"
644 ,"g -- triggers a getstr test"
645 ,"k -- toggle keypad/literal mode"
646 ,"m -- toggle meta (7-bit/8-bit) mode"
649 ,"w -- create a new window"
651 ,"z -- suspend this process"
655 unsigned chk = ((SIZEOF(help) + 1) / 2);
660 printw("Type any key to see its %s value. Also:\n",
661 flags['k'] ? "keypad" : "literal");
662 for (n = 0; n < SIZEOF(help); ++n) {
663 int row = 1 + (int) (n % chk);
664 int col = (n >= chk) ? COLS / 2 : 0;
665 int flg = ((strstr(help[n], "toggle") != 0)
666 && (flags[UChar(*help[n])] != FALSE));
669 mvprintw(row, col, "%s", help[n]);
680 wgetch_wrap(WINDOW *win, int first_y)
682 int last_y = getmaxy(win) - 1;
683 int y = getcury(win) + 1;
691 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
697 static WINSTACK *winstack = 0;
698 static unsigned len_winstack = 0;
711 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
713 unsigned need = (level + 1) * 2;
715 assert(level < (unsigned) COLS);
719 winstack = typeMalloc(WINSTACK, len_winstack);
720 } else if (need >= len_winstack) {
722 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
724 winstack[level].text = txt_win;
725 winstack[level].frame = box_win;
728 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
732 /* this chunk is now done in resize_term() */
739 #define slk_repaint() /* nothing */
743 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
744 * Resize both and paint the box in the parent.
747 resize_boxes(unsigned level, WINDOW *win)
751 int high = LINES - base;
755 wnoutrefresh(stdscr);
759 for (n = 0; n < level; ++n) {
760 wresize(winstack[n].frame, high, wide);
761 wresize(winstack[n].text, high - 2, wide - 2);
764 werase(winstack[n].text);
765 box(winstack[n].frame, 0, 0);
766 wnoutrefresh(winstack[n].frame);
767 wprintw(winstack[n].text,
769 getmaxy(winstack[n].text),
770 getmaxx(winstack[n].text));
771 wnoutrefresh(winstack[n].text);
772 if (winstack[n].text == win)
778 #define forget_boxes() /* nothing */
779 #define remember_boxes(level,text,frame) /* nothing */
783 wgetch_test(unsigned level, WINDOW *win, int delay)
786 int first_y, first_x;
790 bool blocking = (delay < 0);
792 init_getch(win, flags);
793 wtimeout(win, delay);
794 getyx(win, first_y, first_x);
796 wgetch_help(win, flags);
797 wsetscrreg(win, first_y, getmaxy(win) - 1);
801 while ((c = wGetchar(win)) == ERR) {
804 (void) wprintw(win, "%05d: input error", incount);
807 (void) wprintw(win, "%05d: input timed out", incount);
809 wgetch_wrap(win, first_y);
811 if (c == ERR && blocking) {
813 wgetch_wrap(win, first_y);
814 } else if (isQuit(c)) {
816 } else if (c == 'e') {
817 flags[UChar('e')] = !flags[UChar('e')];
818 setup_getch(win, flags);
819 wgetch_help(win, flags);
820 } else if (c == 'g') {
821 waddstr(win, "getstr test: ");
823 wgetnstr(win, buf, sizeof(buf) - 1);
825 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
827 wgetch_wrap(win, first_y);
828 } else if (c == 'k') {
829 flags[UChar('k')] = !flags[UChar('k')];
830 setup_getch(win, flags);
831 wgetch_help(win, flags);
832 } else if (c == 'm') {
833 flags[UChar('m')] = !flags[UChar('m')];
834 setup_getch(win, flags);
835 wgetch_help(win, flags);
836 } else if (c == 's') {
838 } else if (c == 'w') {
839 int high = getmaxy(win) - 1 - first_y + 1;
840 int wide = getmaxx(win) - first_x;
842 int new_y = first_y + getbegy(win);
843 int new_x = first_x + getbegx(win);
845 getyx(win, old_y, old_x);
846 if (high > 2 && wide > 2) {
847 WINDOW *wb = newwin(high, wide, new_y, new_x);
848 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
853 remember_boxes(level, wi, wb);
854 wgetch_test(level + 1, wi, delay);
858 wgetch_help(win, flags);
859 wmove(win, old_y, old_x);
865 } else if (c == 'z') {
866 kill(getpid(), SIGTSTP);
869 wprintw(win, "Key pressed: %04o ", c);
870 #ifdef NCURSES_MOUSE_VERSION
871 if (c == KEY_MOUSE) {
874 #endif /* NCURSES_MOUSE_VERSION */
876 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
877 if (c == KEY_RESIZE) {
878 resize_boxes(level, win);
881 (void) waddstr(win, keyname(c));
882 } else if (c >= 0x80) {
883 unsigned c2 = (unsigned) c;
884 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
885 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
889 (void) wprintw(win, "%c", UChar(c));
890 else if (c2 != UChar(c))
891 (void) wprintw(win, "M-%s", unctrl(c2));
893 (void) wprintw(win, "%s", unctrl(c2));
894 waddstr(win, " (high-half character)");
897 (void) wprintw(win, "%c (ASCII printable character)", c);
899 (void) wprintw(win, "%s (ASCII control character)",
902 wgetch_wrap(win, first_y);
909 init_getch(win, flags);
913 begin_getch_test(void)
920 #ifdef NCURSES_MOUSE_VERSION
921 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
924 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
926 getnstr(buf, sizeof(buf) - 1);
930 if (isdigit(UChar(buf[0]))) {
931 delay = atoi(buf) * 100;
941 finish_getch_test(void)
943 #ifdef NCURSES_MOUSE_VERSION
944 mousemask(0, (mmask_t *) 0);
955 int delay = begin_getch_test();
958 wgetch_test(0, stdscr, delay);
964 #if USE_WIDEC_SUPPORT
966 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
967 * Resize both and paint the box in the parent.
969 #if defined(KEY_RESIZE) && HAVE_WRESIZE
971 resize_wide_boxes(unsigned level, WINDOW *win)
975 int high = LINES - base;
979 wnoutrefresh(stdscr);
983 for (n = 0; n < level; ++n) {
984 wresize(winstack[n].frame, high, wide);
985 wresize(winstack[n].text, high - 2, wide - 2);
988 werase(winstack[n].text);
989 box_set(winstack[n].frame, 0, 0);
990 wnoutrefresh(winstack[n].frame);
991 wprintw(winstack[n].text,
993 getmaxy(winstack[n].text),
994 getmaxx(winstack[n].text));
995 wnoutrefresh(winstack[n].text);
996 if (winstack[n].text == win)
1001 #endif /* KEY_RESIZE */
1004 wcstos(const wchar_t *src)
1008 const wchar_t *tmp = src;
1009 #ifndef state_unused
1013 reset_wchars(state);
1014 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1015 unsigned have = (unsigned) need;
1016 if ((result = typeCalloc(char, have + 1)) != 0) {
1018 if (trans_wchars(result, tmp, have, &state) != have) {
1028 wget_wch_test(unsigned level, WINDOW *win, int delay)
1030 wchar_t wchar_buf[BUFSIZ];
1031 wint_t wint_buf[BUFSIZ];
1032 int first_y, first_x;
1036 bool blocking = (delay < 0);
1040 init_getch(win, flags);
1041 wtimeout(win, delay);
1042 getyx(win, first_y, first_x);
1044 wgetch_help(win, flags);
1045 wsetscrreg(win, first_y, getmaxy(win) - 1);
1046 scrollok(win, TRUE);
1049 while ((code = wGet_wchar(win, &c)) == ERR) {
1052 (void) wprintw(win, "%05d: input error", incount);
1055 (void) wprintw(win, "%05d: input timed out", incount);
1057 wgetch_wrap(win, first_y);
1059 if (code == ERR && blocking) {
1060 wprintw(win, "ERR");
1061 wgetch_wrap(win, first_y);
1062 } else if (isQuit((int) c)) {
1064 } else if (c == 'e') {
1065 flags[UChar('e')] = !flags[UChar('e')];
1066 setup_getch(win, flags);
1067 wgetch_help(win, flags);
1068 } else if (c == 'g') {
1069 waddstr(win, "getstr test: ");
1071 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1074 wprintw(win, "wgetn_wstr returns an error.");
1077 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1080 if ((temp = wcstos(wchar_buf)) != 0) {
1081 wprintw(win, "I saw %d characters:\n\t`%s'.",
1082 (int) wcslen(wchar_buf), temp);
1085 wprintw(win, "I saw %d characters (cannot convert).",
1086 (int) wcslen(wchar_buf));
1090 wgetch_wrap(win, first_y);
1091 } else if (c == 'k') {
1092 flags[UChar('k')] = !flags[UChar('k')];
1093 setup_getch(win, flags);
1094 wgetch_help(win, flags);
1095 } else if (c == 'm') {
1096 flags[UChar('m')] = !flags[UChar('m')];
1097 setup_getch(win, flags);
1098 wgetch_help(win, flags);
1099 } else if (c == 's') {
1101 } else if (c == 'w') {
1102 int high = getmaxy(win) - 1 - first_y + 1;
1103 int wide = getmaxx(win) - first_x;
1105 int new_y = first_y + getbegy(win);
1106 int new_x = first_x + getbegx(win);
1108 getyx(win, old_y, old_x);
1109 if (high > 2 && wide > 2) {
1110 WINDOW *wb = newwin(high, wide, new_y, new_x);
1111 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1116 remember_boxes(level, wi, wb);
1117 wget_wch_test(level + 1, wi, delay);
1121 wgetch_help(win, flags);
1122 wmove(win, old_y, old_x);
1127 } else if (c == 'z') {
1128 kill(getpid(), SIGTSTP);
1131 wprintw(win, "Key pressed: %04o ", (int) c);
1132 #ifdef NCURSES_MOUSE_VERSION
1133 if (c == KEY_MOUSE) {
1136 #endif /* NCURSES_MOUSE_VERSION */
1137 if (code == KEY_CODE_YES) {
1138 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1139 if (c == KEY_RESIZE) {
1140 resize_wide_boxes(level, win);
1143 (void) waddstr(win, keyname((wchar_t) c));
1145 (void) waddstr(win, key_name((wchar_t) c));
1146 if (c < 256 && iscntrl(c)) {
1147 (void) wprintw(win, " (control character)");
1149 (void) wprintw(win, " = %#x (printable character)",
1153 wgetch_wrap(win, first_y);
1160 init_getch(win, flags);
1166 int delay = begin_getch_test();
1169 wget_wch_test(0, stdscr, delay);
1171 finish_getch_test();
1176 /****************************************************************************
1178 * Character attributes test
1180 ****************************************************************************/
1182 #if HAVE_SETUPTERM || HAVE_TGETENT
1183 #define get_ncv() TIGETNUM("ncv","NC")
1184 #define get_xmc() TIGETNUM("xmc","sg")
1186 #define get_ncv() -1
1187 #define get_xmc() -1
1194 static int first = TRUE;
1195 static chtype result = 0;
1201 char *area_pointer = parsed;
1203 tgetent(buffer, getenv("TERM"));
1206 if (TIGETSTR("smso", "so"))
1207 result |= A_STANDOUT;
1208 if (TIGETSTR("smul", "us"))
1209 result |= A_UNDERLINE;
1210 if (TIGETSTR("rev", "mr"))
1211 result |= A_REVERSE;
1212 if (TIGETSTR("blink", "mb"))
1214 if (TIGETSTR("dim", "mh"))
1216 if (TIGETSTR("bold", "md"))
1218 if (TIGETSTR("smacs", "ac"))
1219 result |= A_ALTCHARSET;
1225 #define termattrs() my_termattrs()
1228 #define MAX_ATTRSTRING 31
1229 #define LEN_ATTRSTRING 26
1231 static char attr_test_string[MAX_ATTRSTRING + 1];
1234 attr_legend(WINDOW *helpwin)
1239 mvwprintw(helpwin, row++, col,
1241 mvwprintw(helpwin, row++, col,
1244 mvwprintw(helpwin, row++, col,
1245 "Modify the test strings:");
1246 mvwprintw(helpwin, row++, col,
1247 " A digit sets gaps on each side of displayed attributes");
1248 mvwprintw(helpwin, row++, col,
1249 " </> shifts the text left/right. ");
1251 mvwprintw(helpwin, row++, col,
1254 mvwprintw(helpwin, row++, col,
1255 " f/F/b/F toggle foreground/background background color");
1256 mvwprintw(helpwin, row++, col,
1257 " t/T toggle text/background color attribute");
1259 mvwprintw(helpwin, row++, col,
1260 " a/A toggle ACS (alternate character set) mapping");
1261 mvwprintw(helpwin, row++, col,
1262 " v/V toggle video attribute to combine with each line");
1266 show_color_attr(int fg, int bg, int tx)
1269 printw(" Colors (fg %d, bg %d", fg, bg);
1271 printw(", text %d", tx);
1277 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1284 *fg = (short) (*fg + 1);
1287 *fg = (short) (*fg - 1);
1290 *bg = (short) (*bg + 1);
1293 *bg = (short) (*bg - 1);
1296 *tx = (short) (*tx + 1);
1299 *tx = (short) (*tx - 1);
1307 *fg = (short) min_colors;
1308 if (*fg < min_colors)
1309 *fg = (short) (COLORS - 1);
1311 *bg = (short) min_colors;
1312 if (*bg < min_colors)
1313 *bg = (short) (COLORS - 1);
1317 *tx = (short) (COLORS - 1);
1326 adjust_attr_string(int adjust)
1328 int first = ((int) UChar(attr_test_string[0])) + adjust;
1329 int last = first + LEN_ATTRSTRING;
1331 if (first >= ' ' && last <= '~') { /* 32..126 */
1333 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1334 attr_test_string[j] = (char) k;
1335 if (((k + 1 - first) % 5) == 0) {
1336 if (++j >= MAX_ATTRSTRING)
1338 attr_test_string[j] = ' ';
1341 while (j < MAX_ATTRSTRING)
1342 attr_test_string[j++] = ' ';
1343 attr_test_string[j] = '\0';
1350 init_attr_string(void)
1352 attr_test_string[0] = 'a';
1353 adjust_attr_string(0);
1357 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1359 int ncv = get_ncv();
1360 chtype test = attr & (chtype) (~A_ALTCHARSET);
1363 mvprintw(row, 5, "-->");
1364 mvprintw(row, 8, "%s mode:", name);
1365 mvprintw(row, 24, "|");
1367 printw("%*s", skip, " ");
1369 * Just for testing, write text using the alternate character set one
1370 * character at a time (to pass its rendition directly), and use the
1371 * string operation for the other attributes.
1373 if (attr & A_ALTCHARSET) {
1377 for (s = attr_test_string; *s != '\0'; ++s) {
1382 (void) attrset(attr);
1383 addstr(attr_test_string);
1387 printw("%*s", skip, " ");
1389 if (test != A_NORMAL) {
1390 if (!(termattrs() & test)) {
1393 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1394 static const chtype table[] =
1410 for (n = 0; n < SIZEOF(table); n++) {
1411 if ((table[n] & attr) != 0
1412 && ((1 << n) & ncv) != 0) {
1420 if ((termattrs() & test) != test)
1427 static const struct {
1429 NCURSES_CONST char * name;
1430 } attrs_to_test[] = {
1431 { A_STANDOUT, "STANDOUT" },
1432 { A_REVERSE, "REVERSE" },
1434 { A_UNDERLINE, "UNDERLINE" },
1436 { A_BLINK, "BLINK" },
1437 { A_PROTECT, "PROTECT" },
1439 { A_INVIS, "INVISIBLE" },
1441 { A_NORMAL, "NORMAL" },
1446 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1456 if (ch < 256 && isdigit(ch)) {
1464 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1466 attr_legend(helpwin);
1479 *kc = SIZEOF(attrs_to_test) - 1;
1485 if (*kc >= SIZEOF(attrs_to_test))
1489 adjust_attr_string(-1);
1492 adjust_attr_string(1);
1498 error = cycle_color_attr(ch, fg, bg, tx);
1508 /* test text attributes */
1511 int skip = get_xmc();
1512 short fg = COLOR_BLACK; /* color pair 0 is special */
1513 short bg = COLOR_BLACK;
1521 n = skip; /* make it easy */
1522 k = SIZEOF(attrs_to_test) - 1;
1527 chtype normal = A_NORMAL | BLANK;
1528 chtype extras = (chtype) ac;
1531 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1534 if (init_pair(pair, fg, bg) == ERR) {
1537 normal |= COLOR_PAIR(pair);
1542 if (init_pair(pair, tx, bg) == ERR) {
1545 extras |= COLOR_PAIR(pair);
1554 mvaddstr(0, 20, "Character attribute test display");
1556 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1557 bool arrow = (j == k);
1558 row = show_attr(row, n, arrow,
1560 attrs_to_test[j].attr |
1561 attrs_to_test[k].attr,
1562 attrs_to_test[j].name);
1566 "This terminal does %shave the magic-cookie glitch",
1567 get_xmc() > -1 ? "" : "not ");
1568 mvprintw(row + 1, 8, "Enter '?' for help.");
1569 show_color_attr(fg, bg, tx);
1570 printw(" ACS (%d)", ac != 0);
1573 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1575 bkgdset(A_NORMAL | BLANK);
1580 #if USE_WIDEC_SUPPORT
1581 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1584 wide_adjust_attr_string(int adjust)
1586 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1587 int last = first + LEN_ATTRSTRING;
1589 if (first >= ' ' && last <= '~') { /* 32..126 */
1591 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1592 wide_attr_test_string[j] = k;
1593 if (((k + 1 - first) % 5) == 0) {
1594 if (++j >= MAX_ATTRSTRING)
1596 wide_attr_test_string[j] = ' ';
1599 while (j < MAX_ATTRSTRING)
1600 wide_attr_test_string[j++] = ' ';
1601 wide_attr_test_string[j] = '\0';
1608 wide_init_attr_string(void)
1610 wide_attr_test_string[0] = 'a';
1611 wide_adjust_attr_string(0);
1615 set_wide_background(short pair)
1622 setcchar(&normal, blank, A_NORMAL, pair, 0);
1628 get_wide_background(void)
1630 attr_t result = A_NORMAL;
1636 if (getbkgrnd(&ch) != ERR) {
1637 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1645 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1647 int ncv = get_ncv();
1648 chtype test = attr & ~WA_ALTCHARSET;
1651 mvprintw(row, 5, "-->");
1652 mvprintw(row, 8, "%s mode:", name);
1653 mvprintw(row, 24, "|");
1655 printw("%*s", skip, " ");
1658 * Just for testing, write text using the alternate character set one
1659 * character at a time (to pass its rendition directly), and use the
1660 * string operation for the other attributes.
1662 if (attr & WA_ALTCHARSET) {
1666 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1670 setcchar(&ch, fill, attr, pair, 0);
1677 attr_get(&old_attr, &old_pair, 0);
1678 attr_set(attr, pair, 0);
1679 addwstr(wide_attr_test_string);
1680 attr_set(old_attr, old_pair, 0);
1683 printw("%*s", skip, " ");
1685 if (test != A_NORMAL) {
1686 if (!(term_attrs() & test)) {
1689 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1690 static const attr_t table[] =
1704 for (n = 0; n < SIZEOF(table); n++) {
1705 if ((table[n] & attr) != 0
1706 && ((1 << n) & ncv) != 0) {
1714 if ((term_attrs() & test) != test)
1722 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1732 if (ch < 256 && isdigit(ch)) {
1740 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1741 box_set(helpwin, 0, 0);
1742 attr_legend(helpwin);
1755 *kc = SIZEOF(attrs_to_test) - 1;
1761 if (*kc >= SIZEOF(attrs_to_test))
1765 wide_adjust_attr_string(-1);
1768 wide_adjust_attr_string(1);
1774 error = cycle_color_attr(ch, fg, bg, tx);
1783 wide_attr_test(void)
1784 /* test text attributes using wide-character calls */
1787 int skip = get_xmc();
1788 short fg = COLOR_BLACK; /* color pair 0 is special */
1789 short bg = COLOR_BLACK;
1797 n = skip; /* make it easy */
1798 k = SIZEOF(attrs_to_test) - 1;
1799 wide_init_attr_string();
1807 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1810 if (init_pair(pair, fg, bg) == ERR) {
1817 if (init_pair(extras, tx, bg) == ERR) {
1822 set_wide_background(pair);
1825 box_set(stdscr, 0, 0);
1826 mvaddstr(0, 20, "Character attribute test display");
1828 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1829 row = wide_show_attr(row, n, j == k,
1831 attrs_to_test[j].attr |
1832 attrs_to_test[k].attr,
1834 attrs_to_test[j].name);
1838 "This terminal does %shave the magic-cookie glitch",
1839 get_xmc() > -1 ? "" : "not ");
1840 mvprintw(row + 1, 8, "Enter '?' for help.");
1841 show_color_attr(fg, bg, tx);
1842 printw(" ACS (%d)", ac != 0);
1845 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1847 set_wide_background(0);
1853 /****************************************************************************
1855 * Color support tests
1857 ****************************************************************************/
1859 static NCURSES_CONST char *the_color_names[] =
1880 show_color_name(int y, int x, int color, bool wide)
1882 if (move(y, x) != ERR) {
1887 sprintf(temp, "%02d", color);
1889 } else if (color >= 8) {
1890 sprintf(temp, "[%02d]", color);
1891 } else if (color < 0) {
1892 strcpy(temp, "default");
1894 strcpy(temp, the_color_names[color]);
1896 printw("%-*.*s", width, width, temp);
1901 color_legend(WINDOW *helpwin, bool wide)
1906 mvwprintw(helpwin, row++, col,
1909 mvwprintw(helpwin, row++, col,
1910 "Use up/down arrow to scroll through the display if it is");
1911 mvwprintw(helpwin, row++, col,
1912 "longer than one screen. Control/N and Control/P can be used");
1913 mvwprintw(helpwin, row++, col,
1914 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1915 mvwprintw(helpwin, row++, col,
1916 "full screen; control/B and control/F can be used here.");
1918 mvwprintw(helpwin, row++, col,
1920 mvwprintw(helpwin, row++, col,
1921 " a/A toggle altcharset off/on");
1922 mvwprintw(helpwin, row++, col,
1923 " b/B toggle bold off/on");
1924 mvwprintw(helpwin, row++, col,
1925 " n/N toggle text/number on/off");
1926 mvwprintw(helpwin, row++, col,
1927 " r/R toggle reverse on/off");
1928 mvwprintw(helpwin, row++, col,
1929 " w/W toggle width between 8/16 colors");
1930 #if USE_WIDEC_SUPPORT
1932 mvwprintw(helpwin, row++, col,
1933 "Wide characters:");
1934 mvwprintw(helpwin, row++, col,
1935 " x/X toggle text between ASCII and wide-character");
1942 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1944 /* generate a color test pattern */
1951 int grid_top = top + 3;
1952 int page_size = (LINES - grid_top);
1953 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1959 bool opt_acsc = FALSE;
1960 bool opt_bold = FALSE;
1961 bool opt_revs = FALSE;
1962 bool opt_nums = FALSE;
1963 bool opt_wide = FALSE;
1966 if (COLORS * COLORS == COLOR_PAIRS) {
1967 int limit = (COLORS - min_colors) * (COLORS - min_colors);
1968 if (pairs_max > limit)
1971 if (pairs_max > COLOR_PAIRS)
1972 pairs_max = COLOR_PAIRS;
1978 /* this assumes an 80-column line */
1982 per_row = (COLORS > 8) ? 16 : 8;
1988 per_row -= min_colors;
1990 row_limit = (pairs_max + per_row - 1) / per_row;
1993 (void) printw("There are %d color pairs and %d colors%s\n",
1995 min_colors ? " besides 'default'" : "");
1998 (void) mvprintw(top + 1, 0,
1999 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2002 opt_bold ? "on" : "off");
2004 /* show color names/numbers across the top */
2005 for (i = 0; i < per_row; i++)
2006 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2008 /* show a grid of colors, with color names/ numbers on the left */
2009 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
2010 int row = grid_top + (i / per_row) - base_row;
2011 int col = (i % per_row + 1) * width;
2014 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
2015 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
2016 if (row >= 0 && move(row, col) != ERR) {
2017 short fg = InxToFG(i);
2018 short bg = InxToBG(i);
2020 init_pair(pair, fg, bg);
2021 attron((attr_t) COLOR_PAIR(pair));
2023 attron((attr_t) A_ALTCHARSET);
2025 attron((attr_t) A_BOLD);
2027 attron((attr_t) A_REVERSE);
2030 sprintf(numbered, "{%02X}", i);
2033 printw("%-*.*s", width, width, hello);
2034 (void) attrset(A_NORMAL);
2036 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2037 show_color_name(row, 0, InxToBG(i), opt_wide);
2045 switch (wGetchar(stdscr)) {
2074 set_color_test(opt_wide, FALSE);
2077 set_color_test(opt_wide, TRUE);
2081 if (base_row <= 0) {
2089 if (base_row + page_size >= row_limit) {
2098 if (base_row <= 0) {
2101 base_row -= (page_size - 1);
2109 if (base_row + page_size >= row_limit) {
2112 base_row += page_size - 1;
2113 if (base_row + page_size >= row_limit) {
2114 base_row = row_limit - page_size - 1;
2119 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2121 color_legend(helpwin, FALSE);
2136 #if USE_WIDEC_SUPPORT
2137 /* generate a color test pattern */
2139 wide_color_test(void)
2145 int grid_top = top + 3;
2146 int page_size = (LINES - grid_top);
2147 int pairs_max = (unsigned short) (-1);
2153 bool opt_acsc = FALSE;
2154 bool opt_bold = FALSE;
2155 bool opt_revs = FALSE;
2156 bool opt_wide = FALSE;
2157 bool opt_nums = FALSE;
2158 bool opt_xchr = FALSE;
2162 if (COLORS * COLORS == COLOR_PAIRS) {
2163 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2164 if (pairs_max > limit)
2167 if (pairs_max > COLOR_PAIRS)
2168 pairs_max = COLOR_PAIRS;
2174 /* this assumes an 80-column line */
2178 per_row = (COLORS > 8) ? 16 : 8;
2184 per_row -= min_colors;
2187 make_fullwidth_text(buffer, hello);
2191 make_narrow_text(buffer, hello);
2194 row_limit = (pairs_max + per_row - 1) / per_row;
2197 (void) printw("There are %d color pairs and %d colors%s\n",
2199 min_colors ? " besides 'default'" : "");
2202 (void) mvprintw(top + 1, 0,
2203 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2206 opt_bold ? "on" : "off");
2208 /* show color names/numbers across the top */
2209 for (i = 0; i < per_row; i++)
2210 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2212 /* show a grid of colors, with color names/ numbers on the left */
2213 for (i = (base_row * per_row); i < pairs_max; i++) {
2214 int row = grid_top + (i / per_row) - base_row;
2215 int col = (i % per_row + 1) * width;
2216 short pair = (short) i;
2218 if (row >= 0 && move(row, col) != ERR) {
2219 init_pair(pair, InxToFG(i), InxToBG(i));
2220 color_set(pair, NULL);
2222 attr_on((attr_t) A_ALTCHARSET, NULL);
2224 attr_on((attr_t) A_BOLD, NULL);
2226 attr_on((attr_t) A_REVERSE, NULL);
2229 sprintf(numbered, "{%02X}", i);
2231 make_fullwidth_text(buffer, numbered);
2233 make_narrow_text(buffer, numbered);
2236 addnwstr(buffer, width);
2237 attr_set(A_NORMAL, 0, NULL);
2239 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2240 show_color_name(row, 0, InxToBG(i), opt_wide);
2248 switch (c = wGetchar(stdscr)) {
2277 set_color_test(opt_wide, FALSE);
2280 set_color_test(opt_wide, TRUE);
2290 if (base_row <= 0) {
2298 if (base_row + page_size >= row_limit) {
2307 if (base_row <= 0) {
2310 base_row -= (page_size - 1);
2318 if (base_row + page_size >= row_limit) {
2321 base_row += page_size - 1;
2322 if (base_row + page_size >= row_limit) {
2323 base_row = row_limit - page_size - 1;
2328 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2330 color_legend(helpwin, TRUE);
2344 #endif /* USE_WIDEC_SUPPORT */
2347 change_color(short current, int field, int value, int usebase)
2349 short red, green, blue;
2351 color_content(current, &red, &green, &blue);
2355 red = (short) (usebase ? (red + value) : value);
2358 green = (short) (usebase ? (green + value) : value);
2361 blue = (short) (usebase ? (blue + value) : value);
2365 if (init_color(current, red, green, blue) == ERR)
2370 init_all_colors(void)
2374 for (c = 0; c < COLORS; ++c)
2377 all_colors[c].green,
2378 all_colors[c].blue);
2381 #define scaled_rgb(n) ((255 * (n)) / 1000)
2385 /* display the color test pattern, without trying to edit colors */
2389 int this_c = 0, value = 0, field = 0;
2392 int page_size = (LINES - 6);
2397 for (i = 0; i < max_colors; i++)
2398 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2400 mvprintw(LINES - 2, 0, "Number: %d", value);
2403 short red, green, blue;
2406 mvaddstr(0, 20, "Color RGB Value Editing");
2409 for (i = (short) top_color;
2410 (i - top_color < page_size)
2411 && (i < max_colors); i++) {
2414 sprintf(numeric, "[%d]", i);
2415 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2416 (i == current ? '>' : ' '),
2417 (i < (int) SIZEOF(the_color_names)
2418 ? the_color_names[i] : numeric));
2419 (void) attrset(COLOR_PAIR(i));
2421 (void) attrset(A_NORMAL);
2423 color_content((short) i, &red, &green, &blue);
2425 if (current == i && field == 0)
2427 printw("%04d", red);
2428 if (current == i && field == 0)
2429 (void) attrset(A_NORMAL);
2431 if (current == i && field == 1)
2433 printw("%04d", green);
2434 if (current == i && field == 1)
2435 (void) attrset(A_NORMAL);
2437 if (current == i && field == 2)
2439 printw("%04d", blue);
2440 if (current == i && field == 2)
2441 (void) attrset(A_NORMAL);
2442 (void) attrset(A_NORMAL);
2443 printw(" ( %3d %3d %3d )",
2449 mvaddstr(LINES - 3, 0,
2450 "Use up/down to select a color, left/right to change fields.");
2451 mvaddstr(LINES - 2, 0,
2452 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2454 move(2 + current - top_color, 0);
2458 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2465 current -= (page_size - 1);
2472 if (current < (max_colors - 1))
2473 current += (page_size - 1);
2480 current = (current == 0 ? (max_colors - 1) : current - 1);
2485 current = (current == (max_colors - 1) ? 0 : current + 1);
2489 field = (field == 2 ? 0 : field + 1);
2493 field = (field == 0 ? 2 : field - 1);
2506 value = value * 10 + (this_c - '0');
2510 change_color((short) current, field, value, 1);
2514 change_color((short) current, field, -value, 1);
2518 change_color((short) current, field, value, 0);
2523 P(" RGB Value Editing Help");
2525 P("You are in the RGB value editor. Use the arrow keys to select one of");
2526 P("the fields in one of the RGB triples of the current colors; the one");
2527 P("currently selected will be reverse-video highlighted.");
2529 P("To change a field, enter the digits of the new value; they are echoed");
2530 P("as entered. Finish by typing `='. The change will take effect instantly.");
2531 P("To increment or decrement a value, use the same procedure, but finish");
2532 P("with a `+' or `-'.");
2534 P("Press 'm' to invoke the top-level menu with the current color settings.");
2535 P("To quit, do ESC");
2557 if (current >= max_colors)
2558 current = max_colors - 1;
2559 if (current < top_color)
2560 top_color = current;
2561 if (current - top_color >= page_size)
2562 top_color = current - (page_size - 1);
2564 mvprintw(LINES - 1, 0, "Number: %d", value);
2572 * ncurses does not reset each color individually when calling endwin().
2579 /****************************************************************************
2581 * Soft-key label test
2583 ****************************************************************************/
2588 #define SLK_WORK (SLK_HELP + 3)
2593 static const char *table[] =
2595 "Available commands are:"
2597 ,"^L -- repaint this message and activate soft keys"
2598 ,"a/d -- activate/disable soft keys"
2599 ,"c -- set centered format for labels"
2600 ,"l -- set left-justified format for labels"
2601 ,"r -- set right-justified format for labels"
2602 ,"[12345678] -- set label; labels are numbered 1 through 8"
2603 ,"e -- erase stdscr (should not erase labels)"
2604 ,"s -- test scrolling of shortened screen"
2605 ,"v/V -- cycle through video attributes"
2607 ,"F/f/B/b -- cycle through foreground/background colors"
2609 ,"ESC -- return to main menu"
2611 ,"Note: if activating the soft keys causes your terminal to scroll up"
2612 ,"one line, your terminal auto-scrolls when anything is written to the"
2613 ,"last screen position. The ncurses code does not yet handle this"
2619 for (j = 0; j < SIZEOF(table); ++j) {
2625 /****************************************************************************
2627 * Alternate character-set stuff
2629 ****************************************************************************/
2634 } attrs_to_cycle[] = {
2635 { A_NORMAL, "normal" },
2637 { A_BLINK, "blink" },
2638 { A_REVERSE, "reverse" },
2639 { A_UNDERLINE, "underline" },
2644 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2650 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2655 *at_code = SIZEOF(attrs_to_cycle) - 1;
2664 *attr = attrs_to_cycle[*at_code].attr;
2669 cycle_colors(int ch, int *fg, int *bg, short *pair)
2671 bool result = FALSE;
2681 if ((*fg += 1) >= COLORS)
2689 if ((*bg += 1) >= COLORS)
2697 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2700 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2711 call_slk_color(short fg, short bg)
2713 init_pair(1, bg, fg);
2715 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2725 /* exercise the soft keys */
2730 chtype attr = A_NORMAL;
2731 unsigned at_code = 0;
2733 int fg = COLOR_BLACK;
2734 int bg = COLOR_WHITE;
2741 call_slk_color(fg, bg);
2751 mvaddstr(0, 20, "Soft Key Exerciser");
2766 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2767 while ((c = Getchar()) != 'Q' && (c != ERR))
2795 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2797 if ((s = slk_label(c - '0')) != 0) {
2800 wGetstring(stdscr, buf, 8);
2801 slk_set((c - '0'), buf, fmt);
2810 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2812 wnoutrefresh(stdscr);
2817 if (cycle_attr(c, &at_code, &attr)) {
2824 if (cycle_colors(c, &fg, &bg, &pair)) {
2826 call_slk_color(fg, bg);
2836 } while (!isQuit(c = Getchar()));
2844 #if USE_WIDEC_SUPPORT
2848 /* exercise the soft keys */
2851 wchar_t buf[SLKLEN + 1];
2853 chtype attr = A_NORMAL;
2854 unsigned at_code = 0;
2855 int fg = COLOR_BLACK;
2856 int bg = COLOR_WHITE;
2861 call_slk_color(fg, bg);
2868 attr_on(WA_BOLD, NULL);
2869 mvaddstr(0, 20, "Soft Key Exerciser");
2870 attr_off(WA_BOLD, NULL);
2884 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2885 while ((c = Getchar()) != 'Q' && (c != ERR))
2913 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2915 if ((s = slk_label(c - '0')) != 0) {
2916 char *temp = strdup(s);
2917 size_t used = strlen(temp);
2918 size_t want = SLKLEN;
2920 #ifndef state_unused
2925 while (want > 0 && used != 0) {
2926 const char *base = s;
2927 reset_mbytes(state);
2928 test = count_mbytes(base, 0, &state);
2929 if (test == (size_t) -1) {
2931 } else if (test > want) {
2934 reset_mbytes(state);
2935 trans_mbytes(buf, base, want, &state);
2941 wGet_wstring(stdscr, buf, SLKLEN);
2942 slk_wset((c - '0'), buf, fmt);
2953 fg = (short) ((fg + 1) % COLORS);
2954 call_slk_color(fg, bg);
2959 bg = (short) ((bg + 1) % COLORS);
2960 call_slk_color(fg, bg);
2963 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2965 wnoutrefresh(stdscr);
2969 if (cycle_attr(c, &at_code, &attr)) {
2970 slk_attr_set(attr, (fg || bg), NULL);
2976 if (cycle_colors(c, &fg, &bg, &pair)) {
2978 call_slk_color(fg, bg);
2988 } while (!isQuit(c = Getchar()));
2996 #endif /* SLK_INIT */
2998 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2999 * terminal to perform functions. The remaining codes can be graphic.
3002 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
3004 bool C1 = (first == 128);
3006 unsigned last = first + 31;
3011 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
3012 C1 ? "C1" : "GR", first, last);
3016 for (code = first; code <= last; code++) {
3018 int row = 2 + ((int) (code - first) % 16);
3019 int col = ((int) (code - first) / 16) * COLS / 2;
3021 sprintf(tmp, "%3u (0x%x)", code, code);
3022 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3026 nodelay(stdscr, TRUE);
3027 echochar(colored_chtype(code, attr, pair));
3029 /* (yes, this _is_ crude) */
3030 while ((reply = Getchar()) != ERR) {
3031 addch(UChar(reply));
3034 nodelay(stdscr, FALSE);
3036 } while (--count > 0);
3043 show_pc_chars(int repeat, attr_t attr, short pair)
3049 mvprintw(0, 20, "Display of PC Character Codes");
3053 for (code = 0; code < 16; ++code) {
3054 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
3056 for (code = 0; code < 256; code++) {
3058 int row = 3 + (int) (code / 16) + (code >= 128);
3059 int col = 8 + (int) (code % 16) * PC_COLS;
3060 if ((code % 16) == 0)
3061 mvprintw(row, 0, "0x%02x:", code);
3072 * Skip the ones that do not work.
3076 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3079 } while (--count > 0);
3084 show_box_chars(int repeat, attr_t attr, short pair)
3087 attr |= COLOR_PAIR(pair);
3091 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
3096 colored_chtype(ACS_VLINE, attr, pair),
3097 colored_chtype(ACS_VLINE, attr, pair),
3098 colored_chtype(ACS_HLINE, attr, pair),
3099 colored_chtype(ACS_HLINE, attr, pair),
3100 colored_chtype(ACS_ULCORNER, attr, pair),
3101 colored_chtype(ACS_URCORNER, attr, pair),
3102 colored_chtype(ACS_LLCORNER, attr, pair),
3103 colored_chtype(ACS_LRCORNER, attr, pair));
3104 mvhline(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3105 mvvline(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3106 mvaddch(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3107 mvaddch(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3108 mvaddch(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3109 mvaddch(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3110 mvaddch(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3116 show_1_acs(int n, int repeat, const char *name, chtype code)
3118 const int height = 16;
3119 int row = 2 + (n % height);
3120 int col = (n / height) * COLS / 2;
3122 mvprintw(row, col, "%*s : ", COLS / 4, name);
3125 } while (--repeat > 0);
3130 show_acs_chars(int repeat, attr_t attr, short pair)
3131 /* display the ACS character set */
3135 #define BOTH(name) #name, colored_chtype(name, attr, pair)
3139 mvaddstr(0, 20, "Display of the ACS Character Set");
3143 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3144 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3145 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3146 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3148 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3149 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3150 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3151 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3153 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3154 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3157 * HPUX's ACS definitions are broken here. Just give up.
3159 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3160 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3161 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3162 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3163 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3165 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3166 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3167 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3168 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3169 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3170 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3171 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3172 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3173 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3175 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3176 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3177 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3179 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3180 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3181 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3182 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3183 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3184 n = show_1_acs(n, repeat, BOTH(ACS_S9));
3192 char *term = getenv("TERM");
3193 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3196 chtype attr = A_NORMAL;
3199 int fg = COLOR_BLACK;
3200 int bg = COLOR_BLACK;
3201 unsigned at_code = 0;
3203 void (*last_show_acs) (int, attr_t, short) = 0;
3211 ToggleAcs(last_show_acs, show_acs_chars);
3215 ToggleAcs(last_show_acs, show_pc_chars);
3220 ToggleAcs(last_show_acs, show_box_chars);
3246 if (repeat < (COLS / 4))
3254 if (cycle_attr(c, &at_code, &attr)
3255 || cycle_colors(c, &fg, &bg, &pair)) {
3262 if (last_show_acs != 0)
3263 last_show_acs(repeat, attr, pair);
3265 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3267 mvprintw(LINES - 3, 0,
3268 "Note: ANSI terminals may not display C1 characters.");
3269 mvprintw(LINES - 2, 0,
3270 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3273 mvprintw(LINES - 1, 0,
3274 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3275 attrs_to_cycle[at_code].name,
3278 mvprintw(LINES - 1, 0,
3279 "v/V cycles through video attributes (%s).",
3280 attrs_to_cycle[at_code].name);
3283 } while (!isQuit(c = Getchar()));
3290 #if USE_WIDEC_SUPPORT
3292 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3298 TEST_CCHAR(src, count, {
3299 attr |= (test_attrs & A_ALTCHARSET);
3300 setcchar(dst, test_wch, attr, pair, NULL);
3310 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3314 int last = first + 31;
3318 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3321 for (code = first; (int) code <= last; code++) {
3322 int row = 2 + ((code - first) % 16);
3323 int col = ((code - first) / 16) * COLS / 2;
3329 memset(&codes, 0, sizeof(codes));
3331 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3332 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3333 setcchar(&temp, codes, attr, pair, 0);
3336 * Give non-spacing characters something to combine with. If we
3337 * don't, they'll bunch up in a heap on the space after the ":".
3338 * Mark them with reverse-video to make them simpler to find on
3341 if (wcwidth(code) == 0)
3342 addch(space | (A_REVERSE ^ attr) | COLOR_PAIR(pair));
3344 * This could use add_wch(), but is done for comparison with the
3345 * normal 'f' test (and to make a test-case for echo_wchar()).
3346 * The screen will flicker because the erase() at the top of the
3347 * function is met by the builtin refresh() in echo_wchar().
3351 * The repeat-count may make text wrap - avoid that.
3353 getyx(stdscr, y, x);
3354 if (x >= col + (COLS / 2) - 2)
3356 } while (--count > 0);
3361 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3363 const int height = 16;
3364 int row = 2 + (n % height);
3365 int col = (n / height) * COLS / 2;
3367 mvprintw(row, col, "%*s : ", COLS / 4, name);
3368 while (--repeat >= 0) {
3374 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3377 show_wacs_chars(int repeat, attr_t attr, short pair)
3378 /* display the wide-ACS character set */
3384 /*#define BOTH2(name) #name, &(name) */
3385 #define BOTH2(name) #name, MERGE_ATTR(name)
3389 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3393 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3394 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3395 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3396 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3398 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3399 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3400 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3401 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3403 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3404 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3406 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3407 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3408 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3409 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3411 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3412 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3413 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3414 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3415 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3416 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3417 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3418 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3419 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3421 #ifdef CURSES_WACS_ARRAY
3422 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3423 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3424 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3426 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3427 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3428 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3429 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3430 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3431 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3437 show_wacs_chars_double(int repeat, attr_t attr, short pair)
3438 /* display the wide-ACS character set */
3444 /*#define BOTH2(name) #name, &(name) */
3445 #define BOTH2(name) #name, MERGE_ATTR(name)
3449 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3453 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3454 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3455 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3456 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3458 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3459 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3460 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3461 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3463 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3464 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3466 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3467 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3468 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3469 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3471 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3472 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3473 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3474 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3475 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3476 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3477 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3478 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3479 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3481 #ifdef CURSES_WACS_ARRAY
3482 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3483 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3484 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3486 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3487 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3488 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3489 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3490 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3491 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3498 show_wacs_chars_thick(int repeat, attr_t attr, short pair)
3499 /* display the wide-ACS character set */
3505 /*#define BOTH2(name) #name, &(name) */
3506 #define BOTH2(name) #name, MERGE_ATTR(name)
3510 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3514 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
3515 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
3516 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
3517 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
3519 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
3520 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
3521 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
3522 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
3524 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
3525 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
3527 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3528 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3529 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3530 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3532 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3533 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3534 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3535 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3536 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3537 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3538 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3539 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3540 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3542 #ifdef CURSES_WACS_ARRAY
3543 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3544 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3545 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3547 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3548 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3549 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3550 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3551 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3552 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3559 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3562 show_wbox_chars(int repeat, attr_t attr, short pair)
3569 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3574 MERGE_ATTR(0, WACS_VLINE),
3575 MERGE_ATTR(1, WACS_VLINE),
3576 MERGE_ATTR(2, WACS_HLINE),
3577 MERGE_ATTR(3, WACS_HLINE),
3578 MERGE_ATTR(4, WACS_ULCORNER),
3579 MERGE_ATTR(5, WACS_URCORNER),
3580 MERGE_ATTR(6, WACS_LLCORNER),
3581 MERGE_ATTR(7, WACS_LRCORNER));
3583 mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3584 mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3585 mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3586 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3587 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3588 mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3589 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3597 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3599 const int height = 16;
3600 int row = 2 + (n % height);
3601 int col = (n / height) * COLS / 2;
3604 mvprintw(row, col, "%*s : ", COLS / 4, name);
3605 attr_set(attr, pair, 0);
3606 addstr(strcpy(temp, code));
3607 attr_set(A_NORMAL, 0, 0);
3611 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3614 show_utf8_chars(int repeat, attr_t attr, short pair)
3621 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3625 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3626 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3627 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3628 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3630 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3631 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3632 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3633 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3635 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3636 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3638 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3639 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3640 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3641 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3643 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3644 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3645 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3646 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3647 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3648 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3649 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3650 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3651 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3652 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3653 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3654 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3656 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3657 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3658 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3659 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3660 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3661 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3666 /* display the wide-ACS character set */
3668 wide_acs_display(void)
3674 chtype attr = A_NORMAL;
3675 int fg = COLOR_BLACK;
3676 int bg = COLOR_BLACK;
3677 unsigned at_code = 0;
3679 void (*last_show_wacs) (int, attr_t, short) = 0;
3687 ToggleAcs(last_show_wacs, show_wacs_chars);
3691 ToggleAcs(last_show_wacs, show_wacs_chars_double);
3696 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
3700 ToggleAcs(last_show_wacs, show_wbox_chars);
3703 ToggleAcs(last_show_wacs, show_utf8_chars);
3706 if (c < 256 && isdigit(c)) {
3709 } else if (c == '+') {
3712 } else if (c == '-' && digit > 0) {
3715 } else if (c == '>' && repeat < (COLS / 4)) {
3717 } else if (c == '<' && repeat > 1) {
3719 } else if (c == '_') {
3720 space = (space == ' ') ? '_' : ' ';
3722 } else if (cycle_attr(c, &at_code, &attr)
3723 || cycle_colors(c, &fg, &bg, &pair)) {
3724 if (last_show_wacs != 0)
3732 if (last_show_wacs != 0)
3733 last_show_wacs(repeat, attr, pair);
3735 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3737 mvprintw(LINES - 3, 0,
3738 "Select: a/d/t WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3740 mvprintw(LINES - 2, 0,
3741 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3742 attrs_to_cycle[at_code].name,
3745 mvprintw(LINES - 2, 0,
3746 "v/V cycles through video attributes (%s).",
3747 attrs_to_cycle[at_code].name);
3750 } while (!isQuit(c = Getchar()));
3760 * Graphic-rendition test (adapted from vttest)
3763 test_sgr_attributes(void)
3767 for (pass = 0; pass < 2; pass++) {
3768 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3770 /* Use non-default colors if possible to exercise bce a little */
3772 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3773 normal |= COLOR_PAIR(1);
3777 mvprintw(1, 20, "Graphic rendition test pattern:");
3779 mvprintw(4, 1, "vanilla");
3781 #define set_sgr(mask) bkgdset((normal^(mask)));
3783 mvprintw(4, 40, "bold");
3785 set_sgr(A_UNDERLINE);
3786 mvprintw(6, 6, "underline");
3788 set_sgr(A_BOLD | A_UNDERLINE);
3789 mvprintw(6, 45, "bold underline");