1 /****************************************************************************
2 * Copyright (c) 1998-2012,2013 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.389 2013/04/27 19:46:53 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 */
110 #ifdef CURSES_WACS_ARRAY
111 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
112 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
113 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
114 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
115 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
116 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
117 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
124 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
125 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
126 #define reset_wchars(state) init_mb(state)
127 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
128 #define count_wchars(src, len, state) wcstombs(0, src, len)
129 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
130 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
135 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
136 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
137 #define reset_mbytes(state) init_mb(state)
138 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
139 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
140 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
141 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
145 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
147 #define P(string) printw("%s\n", string)
149 #define BLANK ' ' /* this is the background character */
152 static int max_colors; /* the actual number of colors we'll use */
153 static int min_colors; /* the minimum color code */
154 static bool use_colors; /* true if we use colors */
157 static int max_pairs; /* ...and the number of color pairs */
165 static RGB_DATA *all_colors;
167 static void main_menu(bool);
170 failed(const char *s)
174 ExitProgram(EXIT_FAILURE);
177 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
178 * though we can rely on negative x/y values to stop the macro.
181 do_h_line(int y, int x, chtype c, int to)
184 MvHLine(y, x, c, (to) - (x));
188 do_v_line(int y, int x, chtype c, int to)
191 MvVLine(y, x, c, (to) - (y));
205 return ((c) == QUIT || (c) == ESCAPE);
207 #define case_QUIT QUIT: case ESCAPE
209 /* Common function to allow ^T to toggle trace-mode in the middle of a test
210 * so that trace-files can be made smaller.
213 wGetchar(WINDOW *win)
217 while ((c = wgetch(win)) == CTRL('T')) {
219 save_trace = _nc_tracing;
220 Trace(("TOGGLE-TRACING OFF"));
223 _nc_tracing = save_trace;
227 Trace(("TOGGLE-TRACING ON"));
234 #define Getchar() wGetchar(stdscr)
236 /* replaces wgetnstr(), since we want to be able to edit values */
238 wGetstring(WINDOW *win, char *buffer, int limit)
245 (void) wattrset(win, A_REVERSE);
247 x = (int) strlen(buffer);
249 if (x > (int) strlen(buffer))
250 x = (int) strlen(buffer);
252 wprintw(win, "%-*s", limit, buffer);
253 wmove(win, y0, x0 + x);
254 switch (ch = wGetchar(win)) {
267 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
285 if (!isprint(ch) || ch >= KEY_MIN) {
287 } else if ((int) strlen(buffer) < limit) {
289 for (j = (int) strlen(buffer) + 1; j > x; --j) {
290 buffer[j] = buffer[j - 1];
292 buffer[x++] = (char) ch;
299 wattroff(win, A_REVERSE);
304 #if USE_WIDEC_SUPPORT
308 return (ch + 0xff10 - '0');
312 make_fullwidth_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = fullwidth_of(ch);
322 make_narrow_text(wchar_t *target, const char *source)
325 while ((ch = *source++) != 0) {
333 make_fullwidth_digit(cchar_t *target, int digit)
337 source[0] = fullwidth_of(digit + '0');
339 setcchar(target, source, A_NORMAL, 0, 0);
344 wGet_wchar(WINDOW *win, wint_t *result)
348 while ((c = wget_wch(win, result)) == CTRL('T')) {
350 save_trace = _nc_tracing;
351 Trace(("TOGGLE-TRACING OFF"));
354 _nc_tracing = save_trace;
358 Trace(("TOGGLE-TRACING ON"));
361 c = wget_wch(win, result);
365 #define Get_wchar(result) wGet_wchar(stdscr, result)
367 /* replaces wgetn_wstr(), since we want to be able to edit values */
369 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
378 (void) wattrset(win, A_REVERSE);
380 x = (int) wcslen(buffer);
382 if (x > (int) wcslen(buffer))
383 x = (int) wcslen(buffer);
385 /* clear the "window' */
387 wprintw(win, "%*s", limit, " ");
389 /* write the existing buffer contents */
391 waddnwstr(win, buffer, limit);
393 /* positions the cursor past character 'x' */
395 waddnwstr(win, buffer, x);
397 switch (wGet_wchar(win, &ch)) {
437 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
457 } else if ((int) wcslen(buffer) < limit) {
459 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
460 buffer[j] = buffer[j - 1];
462 buffer[x++] = (wchar_t) ch;
469 wattroff(win, A_REVERSE);
480 addstr("Press any key to continue... ");
485 Cannot(const char *what)
487 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
492 ShellOut(bool message)
495 addstr("Shelling out...");
501 IGNORE_RC(system("sh"));
504 addstr("returned from shellout.\n");
508 #ifdef NCURSES_MOUSE_VERSION
510 * This function is the same as _tracemouse(), but we cannot count on that
511 * being available in the non-debug library.
514 mouse_decode(MEVENT const *ep)
516 static char buf[80 + (5 * 10) + (32 * 15)];
518 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
519 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
521 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
523 SHOW(BUTTON1_RELEASED, "release-1");
524 SHOW(BUTTON1_PRESSED, "press-1");
525 SHOW(BUTTON1_CLICKED, "click-1");
526 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
527 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
528 #if NCURSES_MOUSE_VERSION == 1
529 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
532 SHOW(BUTTON2_RELEASED, "release-2");
533 SHOW(BUTTON2_PRESSED, "press-2");
534 SHOW(BUTTON2_CLICKED, "click-2");
535 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
536 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
537 #if NCURSES_MOUSE_VERSION == 1
538 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
541 SHOW(BUTTON3_RELEASED, "release-3");
542 SHOW(BUTTON3_PRESSED, "press-3");
543 SHOW(BUTTON3_CLICKED, "click-3");
544 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
545 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
546 #if NCURSES_MOUSE_VERSION == 1
547 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
550 SHOW(BUTTON4_RELEASED, "release-4");
551 SHOW(BUTTON4_PRESSED, "press-4");
552 SHOW(BUTTON4_CLICKED, "click-4");
553 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
554 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
555 #if NCURSES_MOUSE_VERSION == 1
556 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
559 #if NCURSES_MOUSE_VERSION == 2
560 SHOW(BUTTON5_RELEASED, "release-5");
561 SHOW(BUTTON5_PRESSED, "press-5");
562 SHOW(BUTTON5_CLICKED, "click-5");
563 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
564 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
567 SHOW(BUTTON_CTRL, "ctrl");
568 SHOW(BUTTON_SHIFT, "shift");
569 SHOW(BUTTON_ALT, "alt");
570 SHOW(ALL_MOUSE_EVENTS, "all-events");
571 SHOW(REPORT_MOUSE_POSITION, "position");
575 if (buf[strlen(buf) - 1] == ' ')
576 buf[strlen(buf) - 2] = '\0';
577 (void) strcat(buf, "}");
582 show_mouse(WINDOW *win)
590 outside = !wenclose(win, event.y, event.x);
593 (void) wstandout(win);
594 waddstr(win, "KEY_MOUSE");
595 (void) wstandend(win);
597 waddstr(win, "KEY_MOUSE");
599 wprintw(win, ", %s", mouse_decode(&event));
604 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
608 wmove(win, event.y, event.x);
616 #endif /* NCURSES_MOUSE_VERSION */
618 /****************************************************************************
620 * Character input test
622 ****************************************************************************/
624 #define NUM_GETCH_FLAGS 256
625 typedef bool GetchFlags[NUM_GETCH_FLAGS];
628 setup_getch(WINDOW *win, GetchFlags flags)
630 keypad(win, flags['k']); /* should be redundant, but for testing */
631 meta(win, flags['m']); /* force this to a known state */
639 init_getch(WINDOW *win, GetchFlags flags)
641 memset(flags, FALSE, NUM_GETCH_FLAGS);
642 flags[UChar('k')] = (win == stdscr);
643 flags[UChar('m')] = TRUE;
645 setup_getch(win, flags);
649 wgetch_help(WINDOW *win, GetchFlags flags)
651 static const char *help[] =
653 "e -- toggle echo mode"
654 ,"g -- triggers a getstr test"
655 ,"k -- toggle keypad/literal mode"
656 ,"m -- toggle meta (7-bit/8-bit) mode"
659 ,"w -- create a new window"
661 ,"z -- suspend this process"
665 unsigned chk = ((SIZEOF(help) + 1) / 2);
670 printw("Type any key to see its %s value. Also:\n",
671 flags['k'] ? "keypad" : "literal");
672 for (n = 0; n < SIZEOF(help); ++n) {
673 int row = 1 + (int) (n % chk);
674 int col = (n >= chk) ? COLS / 2 : 0;
675 int flg = ((strstr(help[n], "toggle") != 0)
676 && (flags[UChar(*help[n])] != FALSE));
679 MvPrintw(row, col, "%s", help[n]);
690 wgetch_wrap(WINDOW *win, int first_y)
692 int last_y = getmaxy(win) - 1;
693 int y = getcury(win) + 1;
701 #if defined(KEY_RESIZE) && HAVE_WRESIZE
707 static WINSTACK *winstack = 0;
708 static unsigned len_winstack = 0;
721 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
723 unsigned need = (level + 1) * 2;
725 assert(level < (unsigned) COLS);
729 winstack = typeMalloc(WINSTACK, len_winstack);
730 } else if (need >= len_winstack) {
732 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
735 failed("remember_boxes");
736 winstack[level].text = txt_win;
737 winstack[level].frame = box_win;
740 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
744 /* this chunk is now done in resize_term() */
751 #define slk_repaint() /* nothing */
754 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
756 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
757 * Resize both and paint the box in the parent.
760 resize_boxes(unsigned level, WINDOW *win)
764 int high = LINES - base;
768 wnoutrefresh(stdscr);
772 for (n = 0; n < level; ++n) {
773 wresize(winstack[n].frame, high, wide);
774 wresize(winstack[n].text, high - 2, wide - 2);
777 werase(winstack[n].text);
778 box(winstack[n].frame, 0, 0);
779 wnoutrefresh(winstack[n].frame);
780 wprintw(winstack[n].text,
782 getmaxy(winstack[n].text),
783 getmaxx(winstack[n].text));
784 wnoutrefresh(winstack[n].text);
785 if (winstack[n].text == win)
790 #endif /* resize_boxes */
792 #define forget_boxes() /* nothing */
793 #define remember_boxes(level,text,frame) /* nothing */
797 * Return-code is OK/ERR or a keyname.
802 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
806 wgetch_test(unsigned level, WINDOW *win, int delay)
809 int first_y, first_x;
813 bool blocking = (delay < 0);
815 init_getch(win, flags);
816 wtimeout(win, delay);
817 getyx(win, first_y, first_x);
819 wgetch_help(win, flags);
820 wsetscrreg(win, first_y, getmaxy(win) - 1);
824 while ((c = wGetchar(win)) == ERR) {
827 (void) wprintw(win, "%05d: input error", incount);
830 (void) wprintw(win, "%05d: input timed out", incount);
832 wgetch_wrap(win, first_y);
834 if (c == ERR && blocking) {
836 wgetch_wrap(win, first_y);
837 } else if (isQuit(c)) {
839 } else if (c == 'e') {
840 flags[UChar('e')] = !flags[UChar('e')];
841 setup_getch(win, flags);
842 wgetch_help(win, flags);
843 } else if (c == 'g') {
844 waddstr(win, "getstr test: ");
846 c = wgetnstr(win, buf, sizeof(buf) - 1);
848 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
849 (int) strlen(buf), buf,
852 wgetch_wrap(win, first_y);
853 } else if (c == 'k') {
854 flags[UChar('k')] = !flags[UChar('k')];
855 setup_getch(win, flags);
856 wgetch_help(win, flags);
857 } else if (c == 'm') {
858 flags[UChar('m')] = !flags[UChar('m')];
859 setup_getch(win, flags);
860 wgetch_help(win, flags);
861 } else if (c == 's') {
863 } else if (c == 'w') {
864 int high = getmaxy(win) - 1 - first_y + 1;
865 int wide = getmaxx(win) - first_x;
867 int new_y = first_y + getbegy(win);
868 int new_x = first_x + getbegx(win);
870 getyx(win, old_y, old_x);
871 if (high > 2 && wide > 2) {
872 WINDOW *wb = newwin(high, wide, new_y, new_x);
873 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
878 remember_boxes(level, wi, wb);
879 wgetch_test(level + 1, wi, delay);
883 wgetch_help(win, flags);
884 wmove(win, old_y, old_x);
890 } else if (c == 'z') {
891 kill(getpid(), SIGTSTP);
894 wprintw(win, "Key pressed: %04o ", c);
895 #ifdef NCURSES_MOUSE_VERSION
896 if (c == KEY_MOUSE) {
899 #endif /* NCURSES_MOUSE_VERSION */
901 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
902 if (c == KEY_RESIZE) {
903 resize_boxes(level, win);
906 (void) waddstr(win, keyname(c));
907 } else if (c >= 0x80) {
908 unsigned c2 = (unsigned) c;
909 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
910 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
914 (void) wprintw(win, "%c", UChar(c));
915 else if (c2 != UChar(c))
916 (void) wprintw(win, "M-%s", unctrl(c2));
918 (void) wprintw(win, "%s", unctrl(c2));
919 waddstr(win, " (high-half character)");
922 (void) wprintw(win, "%c (ASCII printable character)", c);
924 (void) wprintw(win, "%s (ASCII control character)",
927 wgetch_wrap(win, first_y);
934 init_getch(win, flags);
938 begin_getch_test(void)
945 #ifdef NCURSES_MOUSE_VERSION
946 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
949 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
951 getnstr(buf, sizeof(buf) - 1);
955 if (isdigit(UChar(buf[0]))) {
956 delay = atoi(buf) * 100;
966 finish_getch_test(void)
968 #ifdef NCURSES_MOUSE_VERSION
969 mousemask(0, (mmask_t *) 0);
980 int delay = begin_getch_test();
983 wgetch_test(0, stdscr, delay);
989 #if USE_WIDEC_SUPPORT
991 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
992 * Resize both and paint the box in the parent.
994 #if defined(KEY_RESIZE) && HAVE_WRESIZE
996 resize_wide_boxes(unsigned level, WINDOW *win)
1000 int high = LINES - base;
1004 wnoutrefresh(stdscr);
1008 for (n = 0; n < level; ++n) {
1009 wresize(winstack[n].frame, high, wide);
1010 wresize(winstack[n].text, high - 2, wide - 2);
1013 werase(winstack[n].text);
1014 box_set(winstack[n].frame, 0, 0);
1015 wnoutrefresh(winstack[n].frame);
1016 wprintw(winstack[n].text,
1018 getmaxy(winstack[n].text),
1019 getmaxx(winstack[n].text));
1020 wnoutrefresh(winstack[n].text);
1021 if (winstack[n].text == win)
1026 #endif /* KEY_RESIZE */
1029 wcstos(const wchar_t *src)
1033 const wchar_t *tmp = src;
1034 #ifndef state_unused
1038 reset_wchars(state);
1039 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1040 unsigned have = (unsigned) need;
1041 if ((result = typeCalloc(char, have + 1)) != 0) {
1043 if (trans_wchars(result, tmp, have, &state) != have) {
1055 wget_wch_test(unsigned level, WINDOW *win, int delay)
1057 wchar_t wchar_buf[BUFSIZ];
1058 wint_t wint_buf[BUFSIZ];
1059 int first_y, first_x;
1063 bool blocking = (delay < 0);
1067 init_getch(win, flags);
1068 wtimeout(win, delay);
1069 getyx(win, first_y, first_x);
1071 wgetch_help(win, flags);
1072 wsetscrreg(win, first_y, getmaxy(win) - 1);
1073 scrollok(win, TRUE);
1076 while ((code = wGet_wchar(win, &c)) == ERR) {
1079 (void) wprintw(win, "%05d: input error", incount);
1082 (void) wprintw(win, "%05d: input timed out", incount);
1084 wgetch_wrap(win, first_y);
1086 if (code == ERR && blocking) {
1087 wprintw(win, "ERR");
1088 wgetch_wrap(win, first_y);
1089 } else if (isQuit((int) c)) {
1091 } else if (c == 'e') {
1092 flags[UChar('e')] = !flags[UChar('e')];
1093 setup_getch(win, flags);
1094 wgetch_help(win, flags);
1095 } else if (c == 'g') {
1096 waddstr(win, "getstr test: ");
1098 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1101 wprintw(win, "wgetn_wstr returns an error.");
1104 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1107 if ((temp = wcstos(wchar_buf)) != 0) {
1108 wprintw(win, "I saw %d characters:\n\t`%s'.",
1109 (int) wcslen(wchar_buf), temp);
1112 wprintw(win, "I saw %d characters (cannot convert).",
1113 (int) wcslen(wchar_buf));
1117 wgetch_wrap(win, first_y);
1118 } else if (c == 'k') {
1119 flags[UChar('k')] = !flags[UChar('k')];
1120 setup_getch(win, flags);
1121 wgetch_help(win, flags);
1122 } else if (c == 'm') {
1123 flags[UChar('m')] = !flags[UChar('m')];
1124 setup_getch(win, flags);
1125 wgetch_help(win, flags);
1126 } else if (c == 's') {
1128 } else if (c == 'w') {
1129 int high = getmaxy(win) - 1 - first_y + 1;
1130 int wide = getmaxx(win) - first_x;
1132 int new_y = first_y + getbegy(win);
1133 int new_x = first_x + getbegx(win);
1135 getyx(win, old_y, old_x);
1136 if (high > 2 && wide > 2) {
1137 WINDOW *wb = newwin(high, wide, new_y, new_x);
1138 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1143 remember_boxes(level, wi, wb);
1144 wget_wch_test(level + 1, wi, delay);
1148 wgetch_help(win, flags);
1149 wmove(win, old_y, old_x);
1154 } else if (c == 'z') {
1155 kill(getpid(), SIGTSTP);
1158 wprintw(win, "Key pressed: %04o ", (int) c);
1159 #ifdef NCURSES_MOUSE_VERSION
1160 if (c == KEY_MOUSE) {
1163 #endif /* NCURSES_MOUSE_VERSION */
1164 if (code == KEY_CODE_YES) {
1165 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1166 if (c == KEY_RESIZE) {
1167 resize_wide_boxes(level, win);
1170 (void) waddstr(win, keyname((wchar_t) c));
1172 (void) waddstr(win, key_name((wchar_t) c));
1173 if (c < 256 && iscntrl(c)) {
1174 (void) wprintw(win, " (control character)");
1176 (void) wprintw(win, " = %#x (printable character)",
1180 wgetch_wrap(win, first_y);
1187 init_getch(win, flags);
1193 int delay = begin_getch_test();
1196 wget_wch_test(0, stdscr, delay);
1198 finish_getch_test();
1203 /****************************************************************************
1205 * Character attributes test
1207 ****************************************************************************/
1209 #if HAVE_SETUPTERM || HAVE_TGETENT
1210 #define get_ncv() TIGETNUM("ncv","NC")
1211 #define get_xmc() TIGETNUM("xmc","sg")
1213 #define get_ncv() -1
1214 #define get_xmc() -1
1221 static int first = TRUE;
1222 static chtype result = 0;
1228 char *area_pointer = parsed;
1230 tgetent(buffer, getenv("TERM"));
1233 if (TIGETSTR("smso", "so"))
1234 result |= A_STANDOUT;
1235 if (TIGETSTR("smul", "us"))
1236 result |= A_UNDERLINE;
1237 if (TIGETSTR("rev", "mr"))
1238 result |= A_REVERSE;
1239 if (TIGETSTR("blink", "mb"))
1241 if (TIGETSTR("dim", "mh"))
1243 if (TIGETSTR("bold", "md"))
1245 if (TIGETSTR("smacs", "ac"))
1246 result |= A_ALTCHARSET;
1252 #define termattrs() my_termattrs()
1255 #define MAX_ATTRSTRING 31
1256 #define LEN_ATTRSTRING 26
1258 static char attr_test_string[MAX_ATTRSTRING + 1];
1261 attr_legend(WINDOW *helpwin)
1266 MvWPrintw(helpwin, row++, col,
1268 MvWPrintw(helpwin, row++, col,
1271 MvWPrintw(helpwin, row++, col,
1272 "Modify the test strings:");
1273 MvWPrintw(helpwin, row++, col,
1274 " A digit sets gaps on each side of displayed attributes");
1275 MvWPrintw(helpwin, row++, col,
1276 " </> shifts the text left/right. ");
1278 MvWPrintw(helpwin, row++, col,
1281 MvWPrintw(helpwin, row++, col,
1282 " f/F/b/F toggle foreground/background background color");
1283 MvWPrintw(helpwin, row++, col,
1284 " t/T toggle text/background color attribute");
1286 MvWPrintw(helpwin, row++, col,
1287 " a/A toggle ACS (alternate character set) mapping");
1288 MvWPrintw(helpwin, row, col,
1289 " v/V toggle video attribute to combine with each line");
1293 show_color_attr(int fg, int bg, int tx)
1296 printw(" Colors (fg %d, bg %d", fg, bg);
1298 printw(", text %d", tx);
1304 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1311 *fg = (short) (*fg + 1);
1314 *fg = (short) (*fg - 1);
1317 *bg = (short) (*bg + 1);
1320 *bg = (short) (*bg - 1);
1323 *tx = (short) (*tx + 1);
1326 *tx = (short) (*tx - 1);
1334 *fg = (short) min_colors;
1335 if (*fg < min_colors)
1336 *fg = (short) (COLORS - 1);
1338 *bg = (short) min_colors;
1339 if (*bg < min_colors)
1340 *bg = (short) (COLORS - 1);
1344 *tx = (short) (COLORS - 1);
1353 adjust_attr_string(int adjust)
1355 int first = ((int) UChar(attr_test_string[0])) + adjust;
1356 int last = first + LEN_ATTRSTRING;
1358 if (first >= ' ' && last <= '~') { /* 32..126 */
1360 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1361 attr_test_string[j] = (char) k;
1362 if (((k + 1 - first) % 5) == 0) {
1363 if (++j >= MAX_ATTRSTRING)
1365 attr_test_string[j] = ' ';
1368 while (j < MAX_ATTRSTRING)
1369 attr_test_string[j++] = ' ';
1370 attr_test_string[j] = '\0';
1377 init_attr_string(void)
1379 attr_test_string[0] = 'a';
1380 adjust_attr_string(0);
1384 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1386 int ncv = get_ncv();
1387 chtype test = attr & (chtype) (~A_ALTCHARSET);
1390 MvPrintw(row, 5, "-->");
1391 MvPrintw(row, 8, "%s mode:", name);
1392 MvPrintw(row, 24, "|");
1394 printw("%*s", skip, " ");
1396 * Just for testing, write text using the alternate character set one
1397 * character at a time (to pass its rendition directly), and use the
1398 * string operation for the other attributes.
1400 if (attr & A_ALTCHARSET) {
1404 for (s = attr_test_string; *s != '\0'; ++s) {
1409 (void) attrset(attr);
1410 addstr(attr_test_string);
1414 printw("%*s", skip, " ");
1416 if (test != A_NORMAL) {
1417 if (!(termattrs() & test)) {
1420 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1421 static const chtype table[] =
1437 for (n = 0; n < SIZEOF(table); n++) {
1438 if ((table[n] & attr) != 0
1439 && ((1 << n) & ncv) != 0) {
1447 if ((termattrs() & test) != test)
1454 static const struct {
1456 NCURSES_CONST char * name;
1457 } attrs_to_test[] = {
1458 { A_STANDOUT, "STANDOUT" },
1459 { A_REVERSE, "REVERSE" },
1461 { A_UNDERLINE, "UNDERLINE" },
1463 { A_BLINK, "BLINK" },
1464 { A_PROTECT, "PROTECT" },
1466 { A_INVIS, "INVISIBLE" },
1468 { A_NORMAL, "NORMAL" },
1473 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1483 if (ch < 256 && isdigit(ch)) {
1491 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1493 attr_legend(helpwin);
1506 *kc = SIZEOF(attrs_to_test) - 1;
1512 if (*kc >= SIZEOF(attrs_to_test))
1516 adjust_attr_string(-1);
1519 adjust_attr_string(1);
1525 error = cycle_color_attr(ch, fg, bg, tx);
1535 /* test text attributes */
1538 int skip = get_xmc();
1539 short fg = COLOR_BLACK; /* color pair 0 is special */
1540 short bg = COLOR_BLACK;
1548 n = skip; /* make it easy */
1549 k = SIZEOF(attrs_to_test) - 1;
1554 chtype normal = A_NORMAL | BLANK;
1555 chtype extras = (chtype) ac;
1558 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1561 if (init_pair(pair, fg, bg) == ERR) {
1564 normal |= (chtype) COLOR_PAIR(pair);
1569 if (init_pair(pair, tx, bg) == ERR) {
1572 extras |= (chtype) COLOR_PAIR(pair);
1581 MvAddStr(0, 20, "Character attribute test display");
1583 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1584 bool arrow = (j == k);
1585 row = show_attr(row, n, arrow,
1587 attrs_to_test[j].attr |
1588 attrs_to_test[k].attr,
1589 attrs_to_test[j].name);
1593 "This terminal does %shave the magic-cookie glitch",
1594 get_xmc() > -1 ? "" : "not ");
1595 MvPrintw(row + 1, 8, "Enter '?' for help.");
1596 show_color_attr(fg, bg, tx);
1597 printw(" ACS (%d)", ac != 0);
1600 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1602 bkgdset(A_NORMAL | BLANK);
1607 #if USE_WIDEC_SUPPORT
1608 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1611 wide_adjust_attr_string(int adjust)
1613 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1614 int last = first + LEN_ATTRSTRING;
1616 if (first >= ' ' && last <= '~') { /* 32..126 */
1618 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1619 wide_attr_test_string[j] = k;
1620 if (((k + 1 - first) % 5) == 0) {
1621 if (++j >= MAX_ATTRSTRING)
1623 wide_attr_test_string[j] = ' ';
1626 while (j < MAX_ATTRSTRING)
1627 wide_attr_test_string[j++] = ' ';
1628 wide_attr_test_string[j] = '\0';
1635 wide_init_attr_string(void)
1637 wide_attr_test_string[0] = 'a';
1638 wide_adjust_attr_string(0);
1642 set_wide_background(short pair)
1649 setcchar(&normal, blank, A_NORMAL, pair, 0);
1655 get_wide_background(void)
1657 attr_t result = A_NORMAL;
1663 memset(&ch, 0, sizeof(ch));
1664 if (getbkgrnd(&ch) != ERR) {
1665 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1673 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1675 int ncv = get_ncv();
1676 chtype test = attr & ~WA_ALTCHARSET;
1679 MvPrintw(row, 5, "-->");
1680 MvPrintw(row, 8, "%s mode:", name);
1681 MvPrintw(row, 24, "|");
1683 printw("%*s", skip, " ");
1686 * Just for testing, write text using the alternate character set one
1687 * character at a time (to pass its rendition directly), and use the
1688 * string operation for the other attributes.
1690 if (attr & WA_ALTCHARSET) {
1694 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1698 setcchar(&ch, fill, attr, pair, 0);
1702 attr_t old_attr = 0;
1705 (void) attr_get(&old_attr, &old_pair, 0);
1706 (void) attr_set(attr, pair, 0);
1707 addwstr(wide_attr_test_string);
1708 (void) attr_set(old_attr, old_pair, 0);
1711 printw("%*s", skip, " ");
1713 if (test != A_NORMAL) {
1714 if (!(term_attrs() & test)) {
1717 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1718 static const attr_t table[] =
1732 for (n = 0; n < SIZEOF(table); n++) {
1733 if ((table[n] & attr) != 0
1734 && ((1 << n) & ncv) != 0) {
1742 if ((term_attrs() & test) != test)
1750 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1760 if (ch < 256 && isdigit(ch)) {
1768 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1769 box_set(helpwin, 0, 0);
1770 attr_legend(helpwin);
1783 *kc = SIZEOF(attrs_to_test) - 1;
1789 if (*kc >= SIZEOF(attrs_to_test))
1793 wide_adjust_attr_string(-1);
1796 wide_adjust_attr_string(1);
1802 error = cycle_color_attr(ch, fg, bg, tx);
1811 wide_attr_test(void)
1812 /* test text attributes using wide-character calls */
1815 int skip = get_xmc();
1816 short fg = COLOR_BLACK; /* color pair 0 is special */
1817 short bg = COLOR_BLACK;
1825 n = skip; /* make it easy */
1826 k = SIZEOF(attrs_to_test) - 1;
1827 wide_init_attr_string();
1835 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1838 if (init_pair(pair, fg, bg) == ERR) {
1845 if (init_pair(extras, tx, bg) == ERR) {
1850 set_wide_background(pair);
1853 box_set(stdscr, 0, 0);
1854 MvAddStr(0, 20, "Character attribute test display");
1856 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1857 row = wide_show_attr(row, n, j == k,
1859 attrs_to_test[j].attr |
1860 attrs_to_test[k].attr),
1862 attrs_to_test[j].name);
1866 "This terminal does %shave the magic-cookie glitch",
1867 get_xmc() > -1 ? "" : "not ");
1868 MvPrintw(row + 1, 8, "Enter '?' for help.");
1869 show_color_attr(fg, bg, tx);
1870 printw(" ACS (%d)", ac != 0);
1873 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1875 set_wide_background(0);
1881 /****************************************************************************
1883 * Color support tests
1885 ****************************************************************************/
1887 static NCURSES_CONST char *the_color_names[] =
1908 show_color_name(int y, int x, int color, bool wide)
1910 if (move(y, x) != ERR) {
1915 sprintf(temp, "%02d", color);
1917 } else if (color >= 8) {
1918 sprintf(temp, "[%02d]", color);
1919 } else if (color < 0) {
1920 strcpy(temp, "default");
1922 sprintf(temp, "%.*s", 16, the_color_names[color]);
1924 printw("%-*.*s", width, width, temp);
1929 color_legend(WINDOW *helpwin, bool wide)
1934 MvWPrintw(helpwin, row++, col,
1937 MvWPrintw(helpwin, row++, col,
1938 "Use up/down arrow to scroll through the display if it is");
1939 MvWPrintw(helpwin, row++, col,
1940 "longer than one screen. Control/N and Control/P can be used");
1941 MvWPrintw(helpwin, row++, col,
1942 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1943 MvWPrintw(helpwin, row++, col,
1944 "full screen; control/B and control/F can be used here.");
1946 MvWPrintw(helpwin, row++, col,
1948 MvWPrintw(helpwin, row++, col,
1949 " a/A toggle altcharset off/on");
1950 MvWPrintw(helpwin, row++, col,
1951 " b/B toggle bold off/on");
1952 MvWPrintw(helpwin, row++, col,
1953 " n/N toggle text/number on/off");
1954 MvWPrintw(helpwin, row++, col,
1955 " r/R toggle reverse on/off");
1956 MvWPrintw(helpwin, row++, col,
1957 " w/W toggle width between 8/16 colors");
1958 #if USE_WIDEC_SUPPORT
1960 MvWPrintw(helpwin, row++, col,
1961 "Wide characters:");
1962 MvWPrintw(helpwin, row, col,
1963 " x/X toggle text between ASCII and wide-character");
1970 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1972 /* generate a color test pattern */
1979 int grid_top = top + 3;
1980 int page_size = (LINES - grid_top);
1981 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1987 bool opt_acsc = FALSE;
1988 bool opt_bold = FALSE;
1989 bool opt_revs = FALSE;
1990 bool opt_nums = FALSE;
1991 bool opt_wide = FALSE;
1994 if (COLORS * COLORS == COLOR_PAIRS) {
1995 int limit = (COLORS - min_colors) * (COLORS - min_colors);
1996 if (pairs_max > limit)
1999 if (pairs_max > COLOR_PAIRS)
2000 pairs_max = COLOR_PAIRS;
2006 /* this assumes an 80-column line */
2010 per_row = (COLORS > 8) ? 16 : 8;
2016 per_row -= min_colors;
2018 row_limit = (pairs_max + per_row - 1) / per_row;
2021 (void) printw("There are %d color pairs and %d colors%s\n",
2023 min_colors ? " besides 'default'" : "");
2026 MvPrintw(top + 1, 0,
2027 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2030 opt_bold ? "on" : "off");
2032 /* show color names/numbers across the top */
2033 for (i = 0; i < per_row; i++)
2034 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2036 /* show a grid of colors, with color names/ numbers on the left */
2037 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
2038 int row = grid_top + (i / per_row) - base_row;
2039 int col = (i % per_row + 1) * width;
2042 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
2043 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
2044 if (row >= 0 && move(row, col) != ERR) {
2045 short fg = InxToFG(i);
2046 short bg = InxToBG(i);
2048 init_pair(pair, fg, bg);
2049 attron((attr_t) COLOR_PAIR(pair));
2051 attron((attr_t) A_ALTCHARSET);
2053 attron((attr_t) A_BOLD);
2055 attron((attr_t) A_REVERSE);
2058 sprintf(numbered, "{%02X}", i);
2061 printw("%-*.*s", width, width, hello);
2062 (void) attrset(A_NORMAL);
2064 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2065 show_color_name(row, 0, InxToBG(i), opt_wide);
2073 switch (wGetchar(stdscr)) {
2102 set_color_test(opt_wide, FALSE);
2105 set_color_test(opt_wide, TRUE);
2109 if (base_row <= 0) {
2117 if (base_row + page_size >= row_limit) {
2126 if (base_row <= 0) {
2129 base_row -= (page_size - 1);
2137 if (base_row + page_size >= row_limit) {
2140 base_row += page_size - 1;
2141 if (base_row + page_size >= row_limit) {
2142 base_row = row_limit - page_size - 1;
2147 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2149 color_legend(helpwin, FALSE);
2164 #if USE_WIDEC_SUPPORT
2165 /* generate a color test pattern */
2167 wide_color_test(void)
2172 int grid_top = top + 3;
2173 int page_size = (LINES - grid_top);
2174 int pairs_max = (unsigned short) (-1);
2180 bool opt_acsc = FALSE;
2181 bool opt_bold = FALSE;
2182 bool opt_revs = FALSE;
2183 bool opt_wide = FALSE;
2184 bool opt_nums = FALSE;
2185 bool opt_xchr = FALSE;
2189 if (COLORS * COLORS == COLOR_PAIRS) {
2190 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2191 if (pairs_max > limit)
2194 if (pairs_max > COLOR_PAIRS)
2195 pairs_max = COLOR_PAIRS;
2201 /* this assumes an 80-column line */
2205 per_row = (COLORS > 8) ? 16 : 8;
2211 per_row -= min_colors;
2214 make_fullwidth_text(buffer, hello);
2218 make_narrow_text(buffer, hello);
2221 row_limit = (pairs_max + per_row - 1) / per_row;
2224 (void) printw("There are %d color pairs and %d colors%s\n",
2226 min_colors ? " besides 'default'" : "");
2229 MvPrintw(top + 1, 0,
2230 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2233 opt_bold ? "on" : "off");
2235 /* show color names/numbers across the top */
2236 for (i = 0; i < per_row; i++)
2237 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2239 /* show a grid of colors, with color names/ numbers on the left */
2240 for (i = (base_row * per_row); i < pairs_max; i++) {
2241 int row = grid_top + (i / per_row) - base_row;
2242 int col = (i % per_row + 1) * width;
2243 short pair = (short) i;
2245 if (row >= 0 && move(row, col) != ERR) {
2246 init_pair(pair, InxToFG(i), InxToBG(i));
2247 (void) color_set(pair, NULL);
2249 attr_on((attr_t) A_ALTCHARSET, NULL);
2251 attr_on((attr_t) A_BOLD, NULL);
2253 attr_on((attr_t) A_REVERSE, NULL);
2256 sprintf(numbered, "{%02X}", i);
2258 make_fullwidth_text(buffer, numbered);
2260 make_narrow_text(buffer, numbered);
2263 addnwstr(buffer, width);
2264 (void) attr_set(A_NORMAL, 0, NULL);
2266 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2267 show_color_name(row, 0, InxToBG(i), opt_wide);
2275 switch (wGetchar(stdscr)) {
2304 set_color_test(opt_wide, FALSE);
2307 set_color_test(opt_wide, TRUE);
2317 if (base_row <= 0) {
2325 if (base_row + page_size >= row_limit) {
2334 if (base_row <= 0) {
2337 base_row -= (page_size - 1);
2345 if (base_row + page_size >= row_limit) {
2348 base_row += page_size - 1;
2349 if (base_row + page_size >= row_limit) {
2350 base_row = row_limit - page_size - 1;
2355 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2357 color_legend(helpwin, TRUE);
2371 #endif /* USE_WIDEC_SUPPORT */
2374 change_color(short current, int field, int value, int usebase)
2376 short red, green, blue;
2378 color_content(current, &red, &green, &blue);
2382 red = (short) (usebase ? (red + value) : value);
2385 green = (short) (usebase ? (green + value) : value);
2388 blue = (short) (usebase ? (blue + value) : value);
2392 if (init_color(current, red, green, blue) == ERR)
2397 init_all_colors(void)
2401 for (c = 0; c < COLORS; ++c)
2404 all_colors[c].green,
2405 all_colors[c].blue);
2408 #define scaled_rgb(n) ((255 * (n)) / 1000)
2412 /* display the color test pattern, without trying to edit colors */
2416 int this_c = 0, value = 0, field = 0;
2419 int page_size = (LINES - 6);
2424 for (i = 0; i < max_colors; i++)
2425 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2427 MvPrintw(LINES - 2, 0, "Number: %d", value);
2430 short red, green, blue;
2433 MvAddStr(0, 20, "Color RGB Value Editing");
2436 for (i = (short) top_color;
2437 (i - top_color < page_size)
2438 && (i < max_colors); i++) {
2441 sprintf(numeric, "[%d]", i);
2442 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2443 (i == current ? '>' : ' '),
2444 (i < (int) SIZEOF(the_color_names)
2445 ? the_color_names[i] : numeric));
2446 (void) attrset((attr_t) COLOR_PAIR(i));
2448 (void) attrset(A_NORMAL);
2450 color_content((short) i, &red, &green, &blue);
2452 if (current == i && field == 0)
2454 printw("%04d", red);
2455 if (current == i && field == 0)
2456 (void) attrset(A_NORMAL);
2458 if (current == i && field == 1)
2460 printw("%04d", green);
2461 if (current == i && field == 1)
2462 (void) attrset(A_NORMAL);
2464 if (current == i && field == 2)
2466 printw("%04d", blue);
2467 if (current == i && field == 2)
2468 (void) attrset(A_NORMAL);
2469 (void) attrset(A_NORMAL);
2470 printw(" ( %3d %3d %3d )",
2476 MvAddStr(LINES - 3, 0,
2477 "Use up/down to select a color, left/right to change fields.");
2478 MvAddStr(LINES - 2, 0,
2479 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2481 move(2 + current - top_color, 0);
2485 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2492 current -= (page_size - 1);
2499 if (current < (max_colors - 1))
2500 current += (page_size - 1);
2507 current = (current == 0 ? (max_colors - 1) : current - 1);
2512 current = (current == (max_colors - 1) ? 0 : current + 1);
2516 field = (field == 2 ? 0 : field + 1);
2520 field = (field == 0 ? 2 : field - 1);
2533 value = value * 10 + (this_c - '0');
2537 change_color((short) current, field, value, 1);
2541 change_color((short) current, field, -value, 1);
2545 change_color((short) current, field, value, 0);
2550 P(" RGB Value Editing Help");
2552 P("You are in the RGB value editor. Use the arrow keys to select one of");
2553 P("the fields in one of the RGB triples of the current colors; the one");
2554 P("currently selected will be reverse-video highlighted.");
2556 P("To change a field, enter the digits of the new value; they are echoed");
2557 P("as entered. Finish by typing `='. The change will take effect instantly.");
2558 P("To increment or decrement a value, use the same procedure, but finish");
2559 P("with a `+' or `-'.");
2561 P("Press 'm' to invoke the top-level menu with the current color settings.");
2562 P("To quit, do ESC");
2571 for (i = 0; i < max_colors; i++)
2572 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2586 if (current >= max_colors)
2587 current = max_colors - 1;
2588 if (current < top_color)
2589 top_color = current;
2590 if (current - top_color >= page_size)
2591 top_color = current - (page_size - 1);
2593 MvPrintw(LINES - 1, 0, "Number: %d", value);
2601 * ncurses does not reset each color individually when calling endwin().
2608 /****************************************************************************
2610 * Alternate character-set stuff
2612 ****************************************************************************/
2617 } attrs_to_cycle[] = {
2618 { A_NORMAL, "normal" },
2620 { A_BLINK, "blink" },
2621 { A_REVERSE, "reverse" },
2622 { A_UNDERLINE, "underline" },
2627 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2633 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2638 *at_code = SIZEOF(attrs_to_cycle) - 1;
2647 *attr = attrs_to_cycle[*at_code].attr;
2652 cycle_colors(int ch, int *fg, int *bg, short *pair)
2654 bool result = FALSE;
2664 if ((*fg += 1) >= COLORS)
2672 if ((*bg += 1) >= COLORS)
2680 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2683 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2692 /****************************************************************************
2694 * Soft-key label test
2696 ****************************************************************************/
2701 #define SLK_WORK (SLK_HELP + 3)
2706 static const char *table[] =
2708 "Available commands are:"
2710 ,"^L -- repaint this message and activate soft keys"
2711 ,"a/d -- activate/disable soft keys"
2712 ,"c -- set centered format for labels"
2713 ,"l -- set left-justified format for labels"
2714 ,"r -- set right-justified format for labels"
2715 ,"[12345678] -- set label; labels are numbered 1 through 8"
2716 ,"e -- erase stdscr (should not erase labels)"
2717 ,"s -- test scrolling of shortened screen"
2718 ,"v/V -- cycle through video attributes"
2720 ,"F/f/B/b -- cycle through foreground/background colors"
2722 ,"ESC -- return to main menu"
2724 ,"Note: if activating the soft keys causes your terminal to scroll up"
2725 ,"one line, your terminal auto-scrolls when anything is written to the"
2726 ,"last screen position. The ncurses code does not yet handle this"
2732 for (j = 0; j < SIZEOF(table); ++j) {
2740 call_slk_color(int fg, int bg)
2742 init_pair(1, (short) bg, (short) fg);
2744 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2754 /* exercise the soft keys */
2759 chtype attr = A_NORMAL;
2760 unsigned at_code = 0;
2762 int fg = COLOR_BLACK;
2763 int bg = COLOR_WHITE;
2770 call_slk_color(fg, bg);
2780 MvAddStr(0, 20, "Soft Key Exerciser");
2795 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2796 while ((c = Getchar()) != 'Q' && (c != ERR))
2824 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2826 if ((s = slk_label(c - '0')) != 0) {
2829 wGetstring(stdscr, buf, 8);
2830 slk_set((c - '0'), buf, fmt);
2839 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2841 wnoutrefresh(stdscr);
2846 if (cycle_attr(c, &at_code, &attr)) {
2853 if (cycle_colors(c, &fg, &bg, &pair)) {
2855 call_slk_color(fg, bg);
2865 } while (!isQuit(c = Getchar()));
2873 #if USE_WIDEC_SUPPORT
2877 /* exercise the soft keys */
2880 wchar_t buf[SLKLEN + 1];
2882 chtype attr = A_NORMAL;
2883 unsigned at_code = 0;
2884 int fg = COLOR_BLACK;
2885 int bg = COLOR_WHITE;
2890 call_slk_color(fg, bg);
2897 attr_on(WA_BOLD, NULL);
2898 MvAddStr(0, 20, "Soft Key Exerciser");
2899 attr_off(WA_BOLD, NULL);
2913 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2914 while ((c = Getchar()) != 'Q' && (c != ERR))
2942 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2944 if ((s = slk_label(c - '0')) != 0) {
2945 char *temp = strdup(s);
2946 size_t used = strlen(temp);
2947 size_t want = SLKLEN;
2949 #ifndef state_unused
2954 while (want > 0 && used != 0) {
2955 const char *base = s;
2956 reset_mbytes(state);
2957 test = count_mbytes(base, 0, &state);
2958 if (test == (size_t) -1) {
2960 } else if (test > want) {
2963 reset_mbytes(state);
2964 trans_mbytes(buf, base, want, &state);
2970 wGet_wstring(stdscr, buf, SLKLEN);
2971 slk_wset((c - '0'), buf, fmt);
2982 fg = (short) ((fg + 1) % COLORS);
2983 call_slk_color(fg, bg);
2988 bg = (short) ((bg + 1) % COLORS);
2989 call_slk_color(fg, bg);
2992 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2994 wnoutrefresh(stdscr);
2998 if (cycle_attr(c, &at_code, &attr)) {
2999 slk_attr_set(attr, (short) (fg || bg), NULL);
3005 if (cycle_colors(c, &fg, &bg, &pair)) {
3007 call_slk_color(fg, bg);
3017 } while (!isQuit(c = Getchar()));
3025 #endif /* SLK_INIT */
3028 show_256_chars(int repeat, attr_t attr, short pair)
3031 unsigned last = 255;
3037 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3042 for (code = first; code <= last; ++code) {
3043 int row = (int) (2 + (code / 16));
3044 int col = (int) (5 * (code % 16));
3045 mvaddch(row, col, colored_chtype(code, attr, pair));
3046 for (count = 1; count < repeat; ++count) {
3047 addch(colored_chtype(code, attr, pair));
3054 * Show a slice of 32 characters, allowing those to be repeated up to the
3057 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3058 * terminal to perform functions. The remaining codes can be graphic.
3061 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, short pair)
3064 unsigned first = (unsigned) base;
3065 unsigned last = first + (unsigned) pagesize - 2;
3066 bool C1 = (first == 128);
3071 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3072 C1 ? "C1" : "GR", first, last);
3076 for (code = first; code <= last; code++) {
3078 int row = 2 + ((int) (code - first) % (pagesize / 2));
3079 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3081 sprintf(tmp, "%3u (0x%x)", code, code);
3082 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3086 nodelay(stdscr, TRUE);
3087 echochar(colored_chtype(code, attr, pair));
3089 /* (yes, this _is_ crude) */
3090 while ((reply = Getchar()) != ERR) {
3091 addch(UChar(reply));
3094 nodelay(stdscr, FALSE);
3096 } while (--count > 0);
3103 show_pc_chars(int repeat, attr_t attr, short pair)
3109 MvPrintw(0, 20, "Display of PC Character Codes");
3113 for (code = 0; code < 16; ++code) {
3114 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3116 for (code = 0; code < 256; code++) {
3118 int row = 3 + (int) (code / 16) + (code >= 128);
3119 int col = 8 + (int) (code % 16) * PC_COLS;
3120 if ((code % 16) == 0)
3121 MvPrintw(row, 0, "0x%02x:", code);
3132 * Skip the ones that do not work.
3136 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3139 } while (--count > 0);
3144 show_box_chars(int repeat, attr_t attr, short pair)
3148 attr |= (attr_t) COLOR_PAIR(pair);
3152 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3157 colored_chtype(ACS_VLINE, attr, pair),
3158 colored_chtype(ACS_VLINE, attr, pair),
3159 colored_chtype(ACS_HLINE, attr, pair),
3160 colored_chtype(ACS_HLINE, attr, pair),
3161 colored_chtype(ACS_ULCORNER, attr, pair),
3162 colored_chtype(ACS_URCORNER, attr, pair),
3163 colored_chtype(ACS_LLCORNER, attr, pair),
3164 colored_chtype(ACS_LRCORNER, attr, pair));
3165 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3166 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3167 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3168 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3169 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3170 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3171 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3177 show_1_acs(int n, int repeat, const char *name, chtype code)
3179 const int height = 16;
3180 int row = 2 + (n % height);
3181 int col = (n / height) * COLS / 2;
3183 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3186 } while (--repeat > 0);
3191 show_acs_chars(int repeat, attr_t attr, short pair)
3192 /* display the ACS character set */
3196 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3200 MvAddStr(0, 20, "Display of the ACS Character Set");
3204 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3205 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3206 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3207 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3209 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3210 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3211 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3212 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3214 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3215 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3218 * HPUX's ACS definitions are broken here. Just give up.
3220 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3221 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3222 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3223 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3224 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3226 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3227 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3228 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3229 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3230 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3231 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3232 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3233 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3234 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3236 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3237 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3238 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3240 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3241 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3242 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3243 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3244 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3245 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3254 char *term = getenv("TERM");
3255 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3258 chtype attr = A_NORMAL;
3261 int fg = COLOR_BLACK;
3262 int bg = COLOR_BLACK;
3263 unsigned at_code = 0;
3265 void (*last_show_acs) (int, attr_t, short) = 0;
3273 ToggleAcs(last_show_acs, show_acs_chars);
3277 ToggleAcs(last_show_acs, show_pc_chars);
3282 if (pagesize == 32) {
3289 ToggleAcs(last_show_acs, show_box_chars);
3315 if (repeat < (COLS / 4))
3323 if (cycle_attr(c, &at_code, &attr)
3324 || cycle_colors(c, &fg, &bg, &pair)) {
3331 if (pagesize != 32) {
3332 show_256_chars(repeat, attr, pair);
3333 } else if (last_show_acs != 0) {
3334 last_show_acs(repeat, attr, pair);
3336 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3339 MvPrintw(LINES - 3, 0,
3340 "Note: ANSI terminals may not display C1 characters.");
3341 MvPrintw(LINES - 2, 0,
3342 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3345 MvPrintw(LINES - 1, 0,
3346 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3347 attrs_to_cycle[at_code].name,
3350 MvPrintw(LINES - 1, 0,
3351 "v/V cycles through video attributes (%s).",
3352 attrs_to_cycle[at_code].name);
3355 } while (!isQuit(c = Getchar()));
3362 #if USE_WIDEC_SUPPORT
3364 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3370 TEST_CCHAR(src, count, {
3371 attr |= (test_attrs & A_ALTCHARSET);
3372 setcchar(dst, test_wch, attr, pair, NULL);
3382 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3383 * display. If there are no repeats, we could normally display 16 lines of 64
3384 * characters (1024 total). However, taking repeats and double-width cells
3385 * into account, use 256 characters for the page.
3388 show_paged_widechars(int base,
3395 int first = base * pagesize;
3396 int last = first + pagesize - 1;
3404 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3407 for (code = first; (int) code <= last; code++) {
3408 int row = (2 + ((int) code - first) / per_line);
3409 int col = 5 * ((int) code % per_line);
3412 memset(&codes, 0, sizeof(codes));
3414 setcchar(&temp, codes, attr, pair, 0);
3416 if (wcwidth(code) == 0 && code != 0) {
3417 addch((chtype) space |
3418 (A_REVERSE ^ attr) |
3419 (attr_t) COLOR_PAIR(pair));
3422 for (count = 1; count < repeat; ++count) {
3429 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3433 int last = first + 31;
3437 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3440 for (code = first; (int) code <= last; code++) {
3441 int row = 2 + ((code - first) % 16);
3442 int col = ((code - first) / 16) * COLS / 2;
3448 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3449 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3451 memset(&codes, 0, sizeof(codes));
3453 setcchar(&temp, codes, attr, pair, 0);
3457 * Give non-spacing characters something to combine with. If we
3458 * don't, they'll bunch up in a heap on the space after the ":".
3459 * Mark them with reverse-video to make them simpler to find on
3462 if (wcwidth(code) == 0) {
3463 addch((chtype) space |
3464 (A_REVERSE ^ attr) |
3465 (attr_t) COLOR_PAIR(pair));
3468 * This uses echo_wchar(), for comparison with the normal 'f'
3469 * test (and to make a test-case for echo_wchar()). The screen
3470 * may flicker because the erase() at the top of the function
3471 * is met by the builtin refresh() in echo_wchar().
3475 * The repeat-count may make text wrap - avoid that.
3477 getyx(stdscr, y, x);
3479 if (x >= col + (COLS / 2) - 2)
3481 } while (--count > 0);
3486 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3488 const int height = 16;
3489 int row = 2 + (n % height);
3490 int col = (n / height) * COLS / 2;
3492 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3493 while (--repeat >= 0) {
3499 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3502 show_wacs_chars(int repeat, attr_t attr, short pair)
3503 /* display the wide-ACS character set */
3509 /*#define BOTH2(name) #name, &(name) */
3510 #define BOTH2(name) #name, MERGE_ATTR(name)
3514 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3518 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3519 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3520 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3521 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3523 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3524 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3525 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3526 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3528 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3529 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3531 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3532 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3533 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3534 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3536 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3537 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3538 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3539 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3540 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3541 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3542 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3543 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3544 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3546 #ifdef CURSES_WACS_ARRAY
3547 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3548 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3549 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3551 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3552 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3553 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3554 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3555 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3556 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3562 show_wacs_chars_double(int repeat, attr_t attr, short pair)
3563 /* display the wide-ACS character set */
3569 /*#define BOTH2(name) #name, &(name) */
3570 #define BOTH2(name) #name, MERGE_ATTR(name)
3574 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3578 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3579 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3580 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3581 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3583 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3584 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3585 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3586 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3588 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3589 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3591 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3592 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3593 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3594 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3596 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3597 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3598 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3599 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3600 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3601 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3602 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3603 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3604 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3606 #ifdef CURSES_WACS_ARRAY
3607 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3608 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3609 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3611 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3612 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3613 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3614 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3615 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3616 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3623 show_wacs_chars_thick(int repeat, attr_t attr, short pair)
3624 /* display the wide-ACS character set */
3630 /*#define BOTH2(name) #name, &(name) */
3631 #define BOTH2(name) #name, MERGE_ATTR(name)
3635 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3639 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
3640 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
3641 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
3642 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
3644 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
3645 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
3646 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
3647 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
3649 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
3650 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
3652 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3653 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3654 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3655 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3657 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3658 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3659 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3660 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3661 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3662 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3663 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3664 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3665 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3667 #ifdef CURSES_WACS_ARRAY
3668 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3669 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3670 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3672 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3673 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3674 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3675 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3676 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3677 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3684 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3687 show_wbox_chars(int repeat, attr_t attr, short pair)
3694 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3699 MERGE_ATTR(0, WACS_VLINE),
3700 MERGE_ATTR(1, WACS_VLINE),
3701 MERGE_ATTR(2, WACS_HLINE),
3702 MERGE_ATTR(3, WACS_HLINE),
3703 MERGE_ATTR(4, WACS_ULCORNER),
3704 MERGE_ATTR(5, WACS_URCORNER),
3705 MERGE_ATTR(6, WACS_LLCORNER),
3706 MERGE_ATTR(7, WACS_LRCORNER));
3708 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3709 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3710 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3711 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3712 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3713 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3714 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3722 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3724 const int height = 16;
3725 int row = 2 + (n % height);
3726 int col = (n / height) * COLS / 2;
3729 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3730 (void) attr_set(attr, pair, 0);
3731 addstr(strncpy(temp, code, 20));
3732 (void) attr_set(A_NORMAL, 0, 0);
3736 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3739 show_utf8_chars(int repeat, attr_t attr, short pair)
3746 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3750 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3751 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3752 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3753 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3755 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3756 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3757 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3758 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3760 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3761 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3763 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3764 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3765 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3766 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3768 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3769 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3770 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3771 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3772 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3773 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3774 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3775 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3776 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3777 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3778 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3779 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3781 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3782 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3783 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3784 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3785 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3786 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3791 /* display the wide-ACS character set */
3793 wide_acs_display(void)