1 /****************************************************************************
2 * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
28 /****************************************************************************
31 ncurses.c --- ncurses library exerciser
37 An interactive test module for the ncurses library.
40 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
41 Thomas E. Dickey (beginning revision 1.27 in 1996).
43 $Id: ncurses.c,v 1.469 2017/10/01 18:22:48 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
84 #define NCURSES_CONST_PARAM char
86 #define mmask_t chtype /* not specified in XSI */
89 #ifdef CURSES_ACS_ARRAY
90 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
91 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
92 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
93 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
94 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
95 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
96 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
98 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
99 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
100 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
101 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
102 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
103 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
104 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
109 #ifdef CURSES_WACS_ARRAY
110 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
111 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
112 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
113 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
114 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
115 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
116 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
123 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
124 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
125 #define reset_wchars(state) init_mb(state)
126 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
127 #define count_wchars(src, len, state) wcstombs(0, src, len)
128 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
129 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
134 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
135 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
136 #define reset_mbytes(state) init_mb(state)
137 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
138 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
139 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
140 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
144 #define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real)
146 #define P(string) printw("%s\n", string)
148 #define BLANK ' ' /* this is the background character */
150 static int MaxColors; /* the actual number of colors we'll use */
151 static int MinColors; /* the minimum color code */
152 static bool UseColors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
157 #if HAVE_COLOR_CONTENT
160 NCURSES_COLOR_T green;
161 NCURSES_COLOR_T blue;
164 static RGB_DATA *all_colors;
167 static void main_menu(bool);
168 static void failed(const char *s) GCC_NORETURN;
171 failed(const char *s)
175 ExitProgram(EXIT_FAILURE);
191 isQuit(int c, bool escape)
193 return ((c) == QUIT || (escape && ((c) == ESCAPE)));
195 #define case_QUIT QUIT: case ESCAPE
197 /* Common function to allow ^T to toggle trace-mode in the middle of a test
198 * so that trace-files can be made smaller.
201 wGetchar(WINDOW *win)
205 while ((c = wgetch(win)) == CTRL('T')) {
207 save_trace = _nc_tracing;
208 Trace(("TOGGLE-TRACING OFF"));
211 _nc_tracing = save_trace;
215 Trace(("TOGGLE-TRACING ON"));
222 #define Getchar() wGetchar(stdscr)
225 /* replaces wgetnstr(), since we want to be able to edit values */
227 wGetstring(WINDOW *win, char *buffer, int limit)
234 (void) wattrset(win, A_REVERSE);
236 x = (int) strlen(buffer);
238 if (x > (int) strlen(buffer))
239 x = (int) strlen(buffer);
241 wprintw(win, "%-*s", limit, buffer);
242 wmove(win, y0, x0 + x);
243 switch (ch = wGetchar(win)) {
256 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
274 if (!isprint(ch) || ch >= KEY_MIN) {
276 } else if ((int) strlen(buffer) < limit) {
278 for (j = (int) strlen(buffer) + 1; j > x; --j) {
279 buffer[j] = buffer[j - 1];
281 buffer[x++] = (char) ch;
288 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
296 fullwidth_digit(int ch)
298 return (wchar_t) (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_digit(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = (wchar_t) ch;
323 make_fullwidth_digit(cchar_t *target, int digit)
327 source[0] = fullwidth_digit(digit + '0');
329 setcchar(target, source, A_NORMAL, 0, 0);
334 wGet_wchar(WINDOW *win, wint_t *result)
338 while ((c = wget_wch(win, result)) == CTRL('T')) {
340 save_trace = _nc_tracing;
341 Trace(("TOGGLE-TRACING OFF"));
344 _nc_tracing = save_trace;
348 Trace(("TOGGLE-TRACING ON"));
351 c = wget_wch(win, result);
355 #define Get_wchar(result) wGet_wchar(stdscr, result)
357 /* replaces wgetn_wstr(), since we want to be able to edit values */
359 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
368 (void) wattrset(win, A_REVERSE);
370 x = (int) wcslen(buffer);
372 if (x > (int) wcslen(buffer))
373 x = (int) wcslen(buffer);
375 /* clear the "window' */
377 wprintw(win, "%*s", limit, " ");
379 /* write the existing buffer contents */
381 waddnwstr(win, buffer, limit);
383 /* positions the cursor past character 'x' */
385 waddnwstr(win, buffer, x);
387 switch (wGet_wchar(win, &ch)) {
427 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
447 } else if ((int) wcslen(buffer) < limit) {
449 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
450 buffer[j] = buffer[j - 1];
452 buffer[x++] = (wchar_t) ch;
459 wattroff(win, A_REVERSE);
470 addstr("Press any key to continue... ");
475 Cannot(const char *what)
477 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
482 ShellOut(bool message)
485 addstr("Shelling out...");
491 IGNORE_RC(system("sh"));
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) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
509 "id %2d at (%2d, %2d, %d) state %4lx = {",
510 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
513 if ((ep->bstate & m)==m) { \
514 _nc_STRCAT(buf, s, sizeof(buf)); \
515 _nc_STRCAT(buf, ", ", sizeof(buf)); \
518 SHOW(BUTTON1_RELEASED, "release-1");
519 SHOW(BUTTON1_PRESSED, "press-1");
520 SHOW(BUTTON1_CLICKED, "click-1");
521 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
522 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
523 #if NCURSES_MOUSE_VERSION == 1
524 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
527 SHOW(BUTTON2_RELEASED, "release-2");
528 SHOW(BUTTON2_PRESSED, "press-2");
529 SHOW(BUTTON2_CLICKED, "click-2");
530 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
531 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
532 #if NCURSES_MOUSE_VERSION == 1
533 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
536 SHOW(BUTTON3_RELEASED, "release-3");
537 SHOW(BUTTON3_PRESSED, "press-3");
538 SHOW(BUTTON3_CLICKED, "click-3");
539 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
540 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
541 #if NCURSES_MOUSE_VERSION == 1
542 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
545 SHOW(BUTTON4_RELEASED, "release-4");
546 SHOW(BUTTON4_PRESSED, "press-4");
547 SHOW(BUTTON4_CLICKED, "click-4");
548 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
549 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
550 #if NCURSES_MOUSE_VERSION == 1
551 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
554 #if NCURSES_MOUSE_VERSION == 2
555 SHOW(BUTTON5_RELEASED, "release-5");
556 SHOW(BUTTON5_PRESSED, "press-5");
557 SHOW(BUTTON5_CLICKED, "click-5");
558 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
559 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
562 SHOW(BUTTON_CTRL, "ctrl");
563 SHOW(BUTTON_SHIFT, "shift");
564 SHOW(BUTTON_ALT, "alt");
565 SHOW(ALL_MOUSE_EVENTS, "all-events");
566 SHOW(REPORT_MOUSE_POSITION, "position");
570 if (buf[strlen(buf) - 1] == ' ')
571 buf[strlen(buf) - 2] = '\0';
572 _nc_STRCAT(buf, "}", sizeof(buf));
577 show_mouse(WINDOW *win)
585 outside = !wenclose(win, event.y, event.x);
588 (void) wstandout(win);
589 waddstr(win, "KEY_MOUSE");
590 (void) wstandend(win);
592 waddstr(win, "KEY_MOUSE");
594 wprintw(win, ", %s", mouse_decode(&event));
599 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
603 wmove(win, event.y, event.x);
611 #endif /* NCURSES_MOUSE_VERSION */
613 /****************************************************************************
615 * Character input test
617 ****************************************************************************/
619 #define NUM_GETCH_FLAGS 256
620 typedef bool GetchFlags[NUM_GETCH_FLAGS];
623 setup_getch(WINDOW *win, GetchFlags flags)
625 keypad(win, flags['k']); /* should be redundant, but for testing */
626 meta(win, flags['m']); /* force this to a known state */
634 init_getch(WINDOW *win, GetchFlags flags, int delay)
636 memset(flags, FALSE, NUM_GETCH_FLAGS);
637 flags[UChar('k')] = (win == stdscr);
638 flags[UChar('m')] = TRUE;
639 flags[UChar('t')] = (delay != 0);
641 setup_getch(win, flags);
645 blocking_getch(GetchFlags flags, int delay)
647 return ((delay < 0) && flags['t']);
650 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
653 wgetch_help(WINDOW *win, GetchFlags flags)
655 static const char *help[] =
657 "e -- toggle echo mode"
658 ,"g -- triggers a getstr test"
659 ,"k -- toggle keypad/literal mode"
660 ,"m -- toggle meta (7-bit/8-bit) mode"
663 ,"t -- toggle timeout"
664 ,"w -- create a new window"
666 ,"z -- suspend this process"
670 unsigned chk = ((SIZEOF(help) + 1) / 2);
675 printw("Type any key to see its %s value. Also:\n",
676 flags['k'] ? "keypad" : "literal");
677 for (n = 0; n < SIZEOF(help); ++n) {
678 const char *msg = help[n];
679 int row = 1 + (int) (n % chk);
680 int col = (n >= chk) ? COLS / 2 : 0;
681 int flg = ((strstr(msg, "toggle") != 0)
682 && (flags[UChar(*msg)] != FALSE));
683 if (*msg == '^' && ExitOnEscape())
684 msg = "^[,^q -- quit";
687 MvPrintw(row, col, "%s", msg);
698 wgetch_wrap(WINDOW *win, int first_y)
700 int last_y = getmaxy(win) - 1;
701 int y = getcury(win) + 1;
709 #if defined(KEY_RESIZE) && HAVE_WRESIZE
715 static WINSTACK *winstack = 0;
716 static unsigned len_winstack = 0;
729 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
731 unsigned need = (level + 1) * 2;
733 assert(level < (unsigned) COLS);
737 winstack = typeMalloc(WINSTACK, len_winstack);
738 } else if (need >= len_winstack) {
740 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
743 failed("remember_boxes");
744 winstack[level].text = txt_win;
745 winstack[level].frame = box_win;
748 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
752 /* this chunk is now done in resize_term() */
759 #define slk_repaint() /* nothing */
762 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
764 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
765 * Resize both and paint the box in the parent.
768 resize_boxes(unsigned level, WINDOW *win)
772 int high = LINES - base;
776 wnoutrefresh(stdscr);
780 for (n = 0; n < level; ++n) {
781 wresize(winstack[n].frame, high, wide);
782 wresize(winstack[n].text, high - 2, wide - 2);
785 werase(winstack[n].text);
786 box(winstack[n].frame, 0, 0);
787 wnoutrefresh(winstack[n].frame);
788 wprintw(winstack[n].text,
790 getmaxy(winstack[n].text),
791 getmaxx(winstack[n].text));
792 wnoutrefresh(winstack[n].text);
793 if (winstack[n].text == win)
798 #endif /* resize_boxes */
800 #define forget_boxes() /* nothing */
801 #define remember_boxes(level,text,frame) /* nothing */
805 * Return-code is OK/ERR or a keyname.
810 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
814 wgetch_test(unsigned level, WINDOW *win, int delay)
817 int first_y, first_x;
822 init_getch(win, flags, delay);
823 notimeout(win, FALSE);
824 wtimeout(win, delay);
825 getyx(win, first_y, first_x);
827 wgetch_help(win, flags);
828 wsetscrreg(win, first_y, getmaxy(win) - 1);
832 while ((c = wGetchar(win)) == ERR) {
834 if (blocking_getch(flags, delay)) {
835 (void) wprintw(win, "%05d: input error", incount);
838 (void) wprintw(win, "%05d: input timed out", incount);
840 wgetch_wrap(win, first_y);
842 if (c == ERR && blocking_getch(flags, delay)) {
844 wgetch_wrap(win, first_y);
845 } else if (isQuit(c, ExitOnEscape())) {
847 } else if (c == 'e') {
848 flags[UChar('e')] = !flags[UChar('e')];
849 setup_getch(win, flags);
850 wgetch_help(win, flags);
851 } else if (c == 'g') {
852 waddstr(win, "getstr test: ");
854 c = wgetnstr(win, buf, sizeof(buf) - 1);
856 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
857 (int) strlen(buf), buf,
860 wgetch_wrap(win, first_y);
861 } else if (c == 'k') {
862 flags[UChar('k')] = !flags[UChar('k')];
863 setup_getch(win, flags);
864 wgetch_help(win, flags);
865 } else if (c == 'm') {
866 flags[UChar('m')] = !flags[UChar('m')];
867 setup_getch(win, flags);
868 wgetch_help(win, flags);
869 } else if (c == 's') {
871 } else if (c == 't') {
872 notimeout(win, flags[UChar('t')]);
873 flags[UChar('t')] = !flags[UChar('t')];
874 wgetch_help(win, flags);
875 } else if (c == 'w') {
876 int high = getmaxy(win) - 1 - first_y + 1;
877 int wide = getmaxx(win) - first_x;
879 int new_y = first_y + getbegy(win);
880 int new_x = first_x + getbegx(win);
882 getyx(win, old_y, old_x);
883 if (high > 2 && wide > 2) {
884 WINDOW *wb = newwin(high, wide, new_y, new_x);
885 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
890 remember_boxes(level, wi, wb);
891 wgetch_test(level + 1, wi, delay);
895 wgetch_help(win, flags);
896 wmove(win, old_y, old_x);
902 } else if (c == 'z') {
903 kill(getpid(), SIGTSTP);
906 wprintw(win, "Key pressed: %04o ", c);
907 #ifdef NCURSES_MOUSE_VERSION
908 if (c == KEY_MOUSE) {
911 #endif /* NCURSES_MOUSE_VERSION */
913 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
914 if (c == KEY_RESIZE) {
915 resize_boxes(level, win);
918 (void) waddstr(win, keyname(c));
919 } else if (c >= 0x80) {
920 unsigned c2 = (unsigned) c;
921 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
922 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
926 (void) wprintw(win, "%c", UChar(c));
927 else if (c2 != UChar(c))
928 (void) wprintw(win, "M-%s", unctrl(c2));
930 (void) wprintw(win, "%s", unctrl(c2));
931 waddstr(win, " (high-half character)");
934 (void) wprintw(win, "%c (ASCII printable character)", c);
936 (void) wprintw(win, "%s (ASCII control character)",
939 wgetch_wrap(win, first_y);
946 init_getch(win, flags, delay);
950 begin_getch_test(void)
957 #ifdef NCURSES_MOUSE_VERSION
958 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
961 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
963 getnstr(buf, sizeof(buf) - 1);
967 if (isdigit(UChar(buf[0]))) {
968 delay = atoi(buf) * 100;
978 finish_getch_test(void)
980 #ifdef NCURSES_MOUSE_VERSION
981 mousemask(0, (mmask_t *) 0);
990 getch_test(bool recur GCC_UNUSED)
992 int delay = begin_getch_test();
995 wgetch_test(0, stdscr, delay);
1002 #if USE_WIDEC_SUPPORT
1004 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1005 * Resize both and paint the box in the parent.
1007 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1009 resize_wide_boxes(unsigned level, WINDOW *win)
1013 int high = LINES - base;
1017 wnoutrefresh(stdscr);
1021 for (n = 0; n < level; ++n) {
1022 wresize(winstack[n].frame, high, wide);
1023 wresize(winstack[n].text, high - 2, wide - 2);
1026 werase(winstack[n].text);
1027 box_set(winstack[n].frame, 0, 0);
1028 wnoutrefresh(winstack[n].frame);
1029 wprintw(winstack[n].text,
1031 getmaxy(winstack[n].text),
1032 getmaxx(winstack[n].text));
1033 wnoutrefresh(winstack[n].text);
1034 if (winstack[n].text == win)
1039 #endif /* KEY_RESIZE */
1042 wcstos(const wchar_t *src)
1046 const wchar_t *tmp = src;
1047 #ifndef state_unused
1051 reset_wchars(state);
1052 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1053 unsigned have = (unsigned) need;
1054 if ((result = typeCalloc(char, have + 1)) != 0) {
1056 if (trans_wchars(result, tmp, have, &state) != have) {
1068 wget_wch_test(unsigned level, WINDOW *win, int delay)
1070 wchar_t wchar_buf[BUFSIZ];
1071 wint_t wint_buf[BUFSIZ];
1072 int first_y, first_x;
1079 init_getch(win, flags, delay);
1080 notimeout(win, FALSE);
1081 wtimeout(win, delay);
1082 getyx(win, first_y, first_x);
1084 wgetch_help(win, flags);
1085 wsetscrreg(win, first_y, getmaxy(win) - 1);
1086 scrollok(win, TRUE);
1089 while ((code = wGet_wchar(win, &c)) == ERR) {
1091 if (blocking_getch(flags, delay)) {
1092 (void) wprintw(win, "%05d: input error", incount);
1095 (void) wprintw(win, "%05d: input timed out", incount);
1097 wgetch_wrap(win, first_y);
1099 if (code == ERR && blocking_getch(flags, delay)) {
1100 wprintw(win, "ERR");
1101 wgetch_wrap(win, first_y);
1102 } else if (isQuit((int) c, ExitOnEscape())) {
1104 } else if (c == 'e') {
1105 flags[UChar('e')] = !flags[UChar('e')];
1106 setup_getch(win, flags);
1107 wgetch_help(win, flags);
1108 } else if (c == 'g') {
1109 waddstr(win, "getstr test: ");
1111 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1114 wprintw(win, "wgetn_wstr returns an error.");
1117 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1120 if ((temp = wcstos(wchar_buf)) != 0) {
1121 wprintw(win, "I saw %d characters:\n\t`%s'.",
1122 (int) wcslen(wchar_buf), temp);
1125 wprintw(win, "I saw %d characters (cannot convert).",
1126 (int) wcslen(wchar_buf));
1130 wgetch_wrap(win, first_y);
1131 } else if (c == 'k') {
1132 flags[UChar('k')] = !flags[UChar('k')];
1133 setup_getch(win, flags);
1134 wgetch_help(win, flags);
1135 } else if (c == 'm') {
1136 flags[UChar('m')] = !flags[UChar('m')];
1137 setup_getch(win, flags);
1138 wgetch_help(win, flags);
1139 } else if (c == 's') {
1141 } else if (c == 't') {
1142 notimeout(win, flags[UChar('t')]);
1143 flags[UChar('t')] = !flags[UChar('t')];
1144 wgetch_help(win, flags);
1145 } else if (c == 'w') {
1146 int high = getmaxy(win) - 1 - first_y + 1;
1147 int wide = getmaxx(win) - first_x;
1149 int new_y = first_y + getbegy(win);
1150 int new_x = first_x + getbegx(win);
1152 getyx(win, old_y, old_x);
1153 if (high > 2 && wide > 2) {
1154 WINDOW *wb = newwin(high, wide, new_y, new_x);
1155 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1160 remember_boxes(level, wi, wb);
1161 wget_wch_test(level + 1, wi, delay);
1165 wgetch_help(win, flags);
1166 wmove(win, old_y, old_x);
1171 } else if (c == 'z') {
1172 kill(getpid(), SIGTSTP);
1175 wprintw(win, "Key pressed: %04o ", (int) c);
1176 #ifdef NCURSES_MOUSE_VERSION
1177 if (c == KEY_MOUSE) {
1180 #endif /* NCURSES_MOUSE_VERSION */
1181 if (code == KEY_CODE_YES) {
1182 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1183 if (c == KEY_RESIZE) {
1184 resize_wide_boxes(level, win);
1187 (void) waddstr(win, keyname((wchar_t) c));
1189 (void) waddstr(win, key_name((wchar_t) c));
1190 if (c < 256 && iscntrl(c)) {
1191 (void) wprintw(win, " (control character)");
1193 (void) wprintw(win, " = %#x (printable character)",
1197 wgetch_wrap(win, first_y);
1204 init_getch(win, flags, delay);
1208 x_getch_test(bool recur GCC_UNUSED)
1210 int delay = begin_getch_test();
1213 wget_wch_test(0, stdscr, delay);
1215 finish_getch_test();
1221 /****************************************************************************
1223 * Character attributes test
1225 ****************************************************************************/
1227 #if HAVE_SETUPTERM || HAVE_TGETENT
1228 #define get_ncv() TIGETNUM("ncv","NC")
1229 #define get_xmc() TIGETNUM("xmc","sg")
1231 #define get_ncv() -1
1232 #define get_xmc() -1
1239 static int first = TRUE;
1240 static chtype result = 0;
1246 char *area_pointer = parsed;
1248 tgetent(buffer, getenv("TERM"));
1251 if (TIGETSTR("smso", "so"))
1252 result |= A_STANDOUT;
1253 if (TIGETSTR("smul", "us"))
1254 result |= A_UNDERLINE;
1255 if (TIGETSTR("rev", "mr"))
1256 result |= A_REVERSE;
1257 if (TIGETSTR("blink", "mb"))
1259 if (TIGETSTR("dim", "mh"))
1261 if (TIGETSTR("bold", "md"))
1263 if (TIGETSTR("smacs", "ac"))
1264 result |= A_ALTCHARSET;
1270 #define termattrs() my_termattrs()
1273 #define ATTRSTRING_1ST 32 /* ' ' */
1274 #define ATTRSTRING_END 126 /* '~' */
1276 #define COLS_PRE_ATTRS 5
1277 #define COLS_AFT_ATTRS 15
1278 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1279 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1280 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1282 static char attr_test_string[MAX_ATTRSTRING + 1];
1285 attr_legend(WINDOW *helpwin)
1290 MvWPrintw(helpwin, row++, col,
1292 MvWPrintw(helpwin, row++, col,
1295 MvWPrintw(helpwin, row++, col,
1296 "Modify the test strings:");
1297 MvWPrintw(helpwin, row++, col,
1298 " A digit sets gaps on each side of displayed attributes");
1299 MvWPrintw(helpwin, row++, col,
1300 " </> shifts the text left/right. ");
1302 MvWPrintw(helpwin, row++, col,
1305 MvWPrintw(helpwin, row++, col,
1306 " f/F/b/B toggle foreground/background background color");
1307 MvWPrintw(helpwin, row++, col,
1308 " t/T toggle text/background color attribute");
1310 MvWPrintw(helpwin, row++, col,
1311 " a/A toggle ACS (alternate character set) mapping");
1312 MvWPrintw(helpwin, row, col,
1313 " v/V toggle video attribute to combine with each line");
1314 #if USE_WIDEC_SUPPORT
1315 MvWPrintw(helpwin, row, col,
1316 " w/W toggle normal/wide (double-width) test-characters");
1321 show_color_attr(int fg, int bg, int tx)
1324 printw(" Colors (fg %d, bg %d", fg, bg);
1326 printw(", text %d", tx);
1332 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1339 *fg = (NCURSES_COLOR_T) (*fg + 1);
1342 *fg = (NCURSES_COLOR_T) (*fg - 1);
1345 *bg = (NCURSES_COLOR_T) (*bg + 1);
1348 *bg = (NCURSES_COLOR_T) (*bg - 1);
1351 *tx = (NCURSES_COLOR_T) (*tx + 1);
1354 *tx = (NCURSES_COLOR_T) (*tx - 1);
1362 *fg = (NCURSES_COLOR_T) MinColors;
1363 if (*fg < MinColors)
1364 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1366 *bg = (NCURSES_COLOR_T) MinColors;
1367 if (*bg < MinColors)
1368 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1372 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1381 adjust_attr_string(int adjust)
1383 char save = attr_test_string[0];
1384 int first = ((int) UChar(save)) + adjust;
1387 if (first >= ATTRSTRING_1ST) {
1388 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1389 if (k > ATTRSTRING_END)
1391 attr_test_string[j] = (char) k;
1392 if (((k + 1 - first) % 5) == 0) {
1393 if (++j >= MAX_ATTRSTRING)
1395 attr_test_string[j] = ' ';
1398 if ((LEN_ATTRSTRING - j) > 5) {
1399 attr_test_string[0] = save;
1400 adjust_attr_string(adjust - 1);
1402 while (j < MAX_ATTRSTRING)
1403 attr_test_string[j++] = ' ';
1404 attr_test_string[j] = '\0';
1410 * Prefer the right-end of the string for starting, since that maps to the
1411 * VT100 line-drawing.
1414 default_attr_string(void)
1416 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1417 result += (LEN_ATTRSTRING / 5);
1418 if (result < ATTRSTRING_1ST)
1419 result = ATTRSTRING_1ST;
1424 init_attr_string(void)
1426 attr_test_string[0] = (char) default_attr_string();
1427 adjust_attr_string(0);
1431 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1433 int ncv = get_ncv();
1434 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1437 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1438 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1439 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1441 printw("%*s", skip, " ");
1443 * Just for testing, write text using the alternate character set one
1444 * character at a time (to pass its rendition directly), and use the
1445 * string operation for the other attributes.
1449 if (attr & A_ALTCHARSET) {
1453 for (s = attr_test_string; *s != '\0'; ++s) {
1455 (void) waddch(win, ch | attr);
1458 (void) wattrset(win, AttrArg(attr, 0));
1459 (void) waddstr(win, attr_test_string);
1460 (void) wattroff(win, (int) attr);
1463 printw("%*s", skip, " ");
1464 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1465 if (test != A_NORMAL) {
1466 if (!(termattrs() & test)) {
1469 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1470 static const chtype table[] =
1489 for (n = 0; n < SIZEOF(table); n++) {
1490 if ((table[n] & attr) != 0
1491 && ((1 << n) & ncv) != 0) {
1499 if ((termattrs() & test) != test) {
1509 NCURSES_CONST char *name;
1512 static const ATTR_TBL attrs_to_test[] = {
1513 { A_STANDOUT, "STANDOUT" },
1514 { A_REVERSE, "REVERSE" },
1516 { A_UNDERLINE, "UNDERLINE" },
1518 { A_BLINK, "BLINK" },
1519 { A_PROTECT, "PROTECT" },
1521 { A_INVIS, "INVISIBLE" },
1524 { A_ITALIC, "ITALIC" },
1526 { A_NORMAL, "NORMAL" },
1531 init_attr_list(ATTR_TBL * target, attr_t attrs)
1533 unsigned result = 0;
1536 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1537 attr_t test = attrs_to_test[n].attr;
1538 if (test == A_NORMAL || (test & attrs) != 0) {
1539 target[result++] = attrs_to_test[n];
1545 #if USE_WIDEC_SUPPORT
1548 NCURSES_CONST char *name;
1551 static const W_ATTR_TBL w_attrs_to_test[] = {
1552 { WA_STANDOUT, "STANDOUT" },
1553 { WA_REVERSE, "REVERSE" },
1554 { WA_BOLD, "BOLD" },
1555 { WA_UNDERLINE, "UNDERLINE" },
1557 { WA_BLINK, "BLINK" },
1558 { WA_PROTECT, "PROTECT" },
1560 { WA_INVIS, "INVISIBLE" },
1563 { WA_ITALIC, "ITALIC" },
1565 { WA_NORMAL, "NORMAL" },
1570 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1572 unsigned result = 0;
1575 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1576 attr_t test = w_attrs_to_test[n].attr;
1577 if (test == WA_NORMAL || (test & attrs) != 0) {
1578 target[result++] = w_attrs_to_test[n];
1586 attr_getc(int *skip,
1587 NCURSES_COLOR_T *fg,
1588 NCURSES_COLOR_T *bg,
1589 NCURSES_COLOR_T *tx,
1602 if (ch < 256 && isdigit(ch)) {
1610 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1612 attr_legend(helpwin);
1635 adjust_attr_string(-1);
1638 adjust_attr_string(1);
1644 error = cycle_color_attr(ch, fg, bg, tx);
1653 attr_test(bool recur GCC_UNUSED)
1654 /* test text attributes */
1657 int skip = get_xmc();
1658 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1659 NCURSES_COLOR_T bg = COLOR_BLACK;
1660 NCURSES_COLOR_T tx = -1;
1663 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1664 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1665 unsigned my_size = init_attr_list(my_list, termattrs());
1668 for (j = 0; j < my_size; ++j) {
1669 my_wins[j] = subwin(stdscr,
1671 2 + (int) (2 * j), COL_ATTRSTRING);
1672 scrollok(my_wins[j], FALSE);
1678 n = skip; /* make it easy */
1684 chtype normal = A_NORMAL | BLANK;
1685 chtype extras = (chtype) ac;
1688 NCURSES_PAIRS_T pair = 0;
1689 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1691 if (init_pair(pair, fg, bg) == ERR) {
1694 normal |= (chtype) COLOR_PAIR(pair);
1699 if (init_pair(pair, tx, bg) == ERR) {
1702 extras |= (chtype) COLOR_PAIR(pair);
1712 MvAddStr(0, 20, "Character attribute test display");
1714 for (j = 0; j < my_size; ++j) {
1715 bool arrow = (j == k);
1716 row = show_attr(my_wins[j], row, n, arrow,
1724 MvPrintw(row, COLS_PRE_ATTRS,
1725 "This terminal does %shave the magic-cookie glitch",
1726 get_xmc() > -1 ? "" : "not ");
1727 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1728 show_color_attr(fg, bg, tx);
1729 printw(" ACS (%d)", ac != 0);
1732 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1734 bkgdset(A_NORMAL | BLANK);
1739 Cannot("does not support video attributes.");
1744 #if USE_WIDEC_SUPPORT
1745 static bool use_fullwidth;
1746 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1748 #define FULL_LO 0xff00
1749 #define FULL_HI 0xff5e
1750 #define HALF_LO 0x20
1752 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1753 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1754 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1757 * Returns an ASCII code in [32..126]
1760 normal_wchar(int ch)
1762 wchar_t result = (wchar_t) ch;
1763 if (isFullWidth(ch))
1764 result = ToNormalWidth(ch);
1769 * Returns either an ASCII code in in [32..126] or full-width in
1770 * [0xff00..0xff5e], according to use_fullwidth setting.
1773 target_wchar(int ch)
1775 wchar_t result = (wchar_t) ch;
1776 if (use_fullwidth) {
1777 if (!isFullWidth(ch))
1778 result = ToFullWidth(ch);
1780 if (isFullWidth(ch))
1781 result = ToNormalWidth(ch);
1787 wide_adjust_attr_string(int adjust)
1789 wchar_t save = wide_attr_test_string[0];
1790 int first = ((int) normal_wchar(save)) + adjust;
1793 if (first >= ATTRSTRING_1ST) {
1794 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1795 if (k > ATTRSTRING_END)
1797 wide_attr_test_string[j] = target_wchar(k);
1798 if (((k + 1 - first) % 5) == 0) {
1799 if (++j >= MAX_ATTRSTRING)
1801 wide_attr_test_string[j] = ' ';
1804 if ((LEN_ATTRSTRING - j) > 5) {
1805 wide_attr_test_string[0] = save;
1806 wide_adjust_attr_string(adjust - 1);
1808 while (j < MAX_ATTRSTRING)
1809 wide_attr_test_string[j++] = ' ';
1810 wide_attr_test_string[j] = '\0';
1816 wide_init_attr_string(void)
1818 use_fullwidth = FALSE;
1819 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1820 wide_adjust_attr_string(0);
1824 set_wide_background(NCURSES_PAIRS_T pair)
1831 setcchar(&normal, blank, A_NORMAL, pair, 0);
1837 get_wide_background(void)
1839 attr_t result = WA_NORMAL;
1842 NCURSES_PAIRS_T pair;
1845 memset(&ch, 0, sizeof(ch));
1846 if (getbkgrnd(&ch) != ERR) {
1847 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1855 wide_show_attr(WINDOW *win,
1860 NCURSES_PAIRS_T pair,
1863 int ncv = get_ncv();
1864 attr_t test = attr & ~WA_ALTCHARSET;
1867 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1868 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1869 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1871 printw("%*s", skip, " ");
1874 * Just for testing, write text using the alternate character set one
1875 * character at a time (to pass its rendition directly), and use the
1876 * string operation for the other attributes.
1880 if (attr & WA_ALTCHARSET) {
1884 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1888 setcchar(&ch, fill, attr, pair, 0);
1889 (void) wadd_wch(win, &ch);
1892 attr_t old_attr = 0;
1893 NCURSES_PAIRS_T old_pair = 0;
1895 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1896 (void) wattr_set(win, attr, pair, 0);
1897 (void) waddwstr(win, wide_attr_test_string);
1898 (void) wattr_set(win, old_attr, old_pair, 0);
1901 printw("%*s", skip, " ");
1902 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1903 if (test != A_NORMAL) {
1904 if (!(term_attrs() & test)) {
1907 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1908 static const attr_t table[] =
1922 for (n = 0; n < SIZEOF(table); n++) {
1923 if ((table[n] & attr) != 0
1924 && ((1 << n) & ncv) != 0) {
1932 if ((term_attrs() & test) != test) {
1941 wide_attr_getc(int *skip,
1942 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1943 NCURSES_COLOR_T *tx, int *ac,
1944 unsigned *kc, unsigned limit)
1954 if (ch < 256 && isdigit(ch)) {
1962 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1963 box_set(helpwin, 0, 0);
1964 attr_legend(helpwin);
1987 use_fullwidth = FALSE;
1988 wide_adjust_attr_string(0);
1991 use_fullwidth = TRUE;
1992 wide_adjust_attr_string(0);
1995 wide_adjust_attr_string(-1);
1998 wide_adjust_attr_string(1);
2004 error = cycle_color_attr(ch, fg, bg, tx);
2013 x_attr_test(bool recur GCC_UNUSED)
2014 /* test text attributes using wide-character calls */
2017 int skip = get_xmc();
2018 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2019 NCURSES_COLOR_T bg = COLOR_BLACK;
2020 NCURSES_COLOR_T tx = -1;
2023 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2024 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2025 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2028 for (j = 0; j < my_size; ++j) {
2029 my_wins[j] = subwin(stdscr,
2031 2 + (int) (2 * j), COL_ATTRSTRING);
2032 scrollok(my_wins[j], FALSE);
2038 n = skip; /* make it easy */
2040 wide_init_attr_string();
2044 NCURSES_PAIRS_T pair = 0;
2045 NCURSES_PAIRS_T extras = 0;
2048 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2051 if (init_pair(pair, fg, bg) == ERR) {
2058 if (init_pair(extras, tx, bg) == ERR) {
2063 set_wide_background(pair);
2066 box_set(stdscr, 0, 0);
2067 MvAddStr(0, 20, "Character attribute test display");
2069 for (j = 0; j < my_size; ++j) {
2070 row = wide_show_attr(my_wins[j], row, n, (j == k),
2078 MvPrintw(row, COLS_PRE_ATTRS,
2079 "This terminal does %shave the magic-cookie glitch",
2080 get_xmc() > -1 ? "" : "not ");
2081 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2082 show_color_attr(fg, bg, tx);
2083 printw(" ACS (%d)", ac != 0);
2086 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2088 set_wide_background(0);
2093 Cannot("does not support extended video attributes.");
2099 /****************************************************************************
2101 * Color support tests
2103 ****************************************************************************/
2105 static NCURSES_CONST char *the_color_names[] =
2126 show_color_name(int y, int x, int color, bool wide)
2128 if (move(y, x) != ERR) {
2133 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2136 } else if (color >= 8) {
2137 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2139 } else if (color < 0) {
2140 _nc_STRCPY(temp, "default", sizeof(temp));
2142 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2143 "%.*s", 16, the_color_names[color]);
2145 printw("%-*.*s", width, width, temp);
2150 color_legend(WINDOW *helpwin, bool wide)
2155 MvWPrintw(helpwin, row++, col,
2158 MvWPrintw(helpwin, row++, col,
2159 "Use up/down arrow to scroll through the display if it is");
2160 MvWPrintw(helpwin, row++, col,
2161 "longer than one screen. Control/N and Control/P can be used");
2162 MvWPrintw(helpwin, row++, col,
2163 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2164 MvWPrintw(helpwin, row++, col,
2165 "full screen; control/B and control/F can be used here.");
2167 MvWPrintw(helpwin, row++, col,
2169 MvWPrintw(helpwin, row++, col,
2170 " a/A toggle altcharset off/on");
2171 MvWPrintw(helpwin, row++, col,
2172 " b/B toggle bold off/on");
2174 MvWPrintw(helpwin, row++, col,
2175 " c/C cycle used-colors through 8,16,...,COLORS");
2177 MvWPrintw(helpwin, row++, col,
2178 " n/N toggle text/number on/off");
2179 MvWPrintw(helpwin, row++, col,
2180 " r/R toggle reverse on/off");
2181 MvWPrintw(helpwin, row++, col,
2182 " w/W toggle width between 8/16 colors");
2183 #if USE_WIDEC_SUPPORT
2185 MvWPrintw(helpwin, row++, col,
2186 "Wide characters:");
2187 MvWPrintw(helpwin, row, col,
2188 " x/X toggle text between ASCII and wide-character");
2195 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2198 color_cycle(int current, int step)
2200 int result = current;
2206 if ((result * 2) > COLORS) {
2209 while ((result * 2) < current) {
2215 if (current >= COLORS) {
2220 if (result > COLORS)
2226 /* generate a color test pattern */
2228 color_test(bool recur GCC_UNUSED)
2233 int grid_top = top + 3;
2234 int page_size = (LINES - grid_top);
2236 int colors_max = COLORS;
2243 bool opt_acsc = FALSE;
2244 bool opt_bold = FALSE;
2245 bool opt_revs = FALSE;
2246 bool opt_nums = FALSE;
2247 bool opt_wide = FALSE;
2251 Cannot("does not support color.");
2255 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2256 done = ((COLS < 16) || (numbered == 0));
2259 * Because the number of colors is usually a power of two, we also use
2260 * a power of two for the number of colors shown per line (to be tidy).
2262 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2267 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2268 if (colors_max * colors_max <= COLOR_PAIRS) {
2269 int limit = (colors_max - MinColors) * (colors_max - MinColors);
2270 if (pairs_max > limit)
2273 if (pairs_max > COLOR_PAIRS)
2274 pairs_max = COLOR_PAIRS;
2277 /* this assumes an 80-column line */
2281 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2285 per_row = (col_limit / 8);
2287 per_row -= MinColors;
2289 row_limit = (pairs_max + per_row - 1) / per_row;
2292 (void) printw("There are %d color pairs and %d colors",
2294 if (colors_max != COLORS)
2295 (void) printw(" (using %d colors)", colors_max);
2297 (void) addstr(" besides 'default'");
2300 MvPrintw(top + 1, 0,
2301 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2304 opt_bold ? "on" : "off");
2306 /* show color names/numbers across the top */
2307 for (i = 0; i < per_row; i++)
2308 show_color_name(top + 2, (i + 1) * width, i + MinColors, opt_wide);
2310 /* show a grid of colors, with color names/ numbers on the left */
2311 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2312 int row = grid_top + (i / per_row) - base_row;
2313 int col = (i % per_row + 1) * width;
2314 NCURSES_PAIRS_T pair = i;
2316 if ((i / per_row) > row_limit)
2319 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - MinColors)) + MinColors)
2320 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - MinColors)) + MinColors)
2321 if (row >= 0 && move(row, col) != ERR) {
2322 NCURSES_COLOR_T fg = InxToFG(i);
2323 NCURSES_COLOR_T bg = InxToBG(i);
2325 init_pair(pair, fg, bg);
2326 attron(COLOR_PAIR(pair));
2328 attron(A_ALTCHARSET);
2335 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2339 printw("%-*.*s", width, width, hello);
2340 (void) attrset(A_NORMAL);
2342 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2343 show_color_name(row, 0, InxToBG(i), opt_wide);
2351 switch (wGetchar(stdscr)) {
2365 colors_max = color_cycle(colors_max, -1);
2368 colors_max = color_cycle(colors_max, 1);
2386 set_color_test(opt_wide, FALSE);
2389 set_color_test(opt_wide, TRUE);
2393 if (base_row <= 0) {
2401 if (base_row + page_size >= row_limit) {
2410 if (base_row <= 0) {
2413 base_row -= (page_size - 1);
2421 if (base_row + page_size >= row_limit) {
2424 base_row += page_size - 1;
2425 if (base_row + page_size >= row_limit) {
2426 base_row = row_limit - page_size - 1;
2431 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2433 color_legend(helpwin, FALSE);
2451 #if USE_WIDEC_SUPPORT
2452 /* generate a color test pattern */
2454 x_color_test(bool recur GCC_UNUSED)
2459 int grid_top = top + 3;
2460 int page_size = (LINES - grid_top);
2461 int pairs_max = (unsigned short) (-1);
2462 int colors_max = COLORS;
2469 bool opt_acsc = FALSE;
2470 bool opt_bold = FALSE;
2471 bool opt_revs = FALSE;
2472 bool opt_wide = FALSE;
2473 bool opt_nums = FALSE;
2474 bool opt_xchr = FALSE;
2475 wchar_t *buffer = 0;
2479 Cannot("does not support color.");
2482 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2483 buffer = (wchar_t *) calloc((size_t) (COLS + 1), sizeof(wchar_t));
2484 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2487 * Because the number of colors is usually a power of two, we also use
2488 * a power of two for the number of colors shown per line (to be tidy).
2490 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2495 pairs_max = (unsigned short) (-1);
2496 if (colors_max * colors_max <= COLOR_PAIRS) {
2497 int limit = (colors_max - MinColors) * (colors_max - MinColors);
2498 if (pairs_max > limit)
2501 if (pairs_max > COLOR_PAIRS)
2502 pairs_max = COLOR_PAIRS;
2508 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2512 per_row = (col_limit / 8);
2514 per_row -= MinColors;
2517 make_fullwidth_text(buffer, hello);
2521 make_narrow_text(buffer, hello);
2524 row_limit = (pairs_max + per_row - 1) / per_row;
2527 (void) printw("There are %d color pairs and %d colors",
2529 if (colors_max != COLORS)
2530 (void) printw(" (using %d colors)", colors_max);
2532 (void) addstr(" besides 'default'");
2535 MvPrintw(top + 1, 0,
2536 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2539 opt_bold ? "on" : "off");
2541 /* show color names/numbers across the top */
2542 for (i = 0; i < per_row; i++)
2543 show_color_name(top + 2, (i + 1) * width, i + MinColors, opt_wide);
2545 /* show a grid of colors, with color names/ numbers on the left */
2546 for (i = (base_row * per_row); i < pairs_max; i++) {
2547 int row = grid_top + (i / per_row) - base_row;
2548 int col = (i % per_row + 1) * width;
2549 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2551 if ((i / per_row) > row_limit)
2554 if (row >= 0 && move(row, col) != ERR) {
2555 init_pair(pair, InxToFG(i), InxToBG(i));
2556 (void) color_set(pair, NULL);
2558 attr_on(WA_ALTCHARSET, NULL);
2560 attr_on(WA_BOLD, NULL);
2562 attr_on(WA_REVERSE, NULL);
2565 _nc_SPRINTF(numbered,
2566 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2569 make_fullwidth_text(buffer, numbered);
2571 make_narrow_text(buffer, numbered);
2574 addnwstr(buffer, width);
2575 (void) attr_set(A_NORMAL, 0, NULL);
2577 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2578 show_color_name(row, 0, InxToBG(i), opt_wide);
2586 switch (wGetchar(stdscr)) {
2600 colors_max = color_cycle(colors_max, -1);
2603 colors_max = color_cycle(colors_max, 1);
2621 set_color_test(opt_wide, FALSE);
2624 set_color_test(opt_wide, TRUE);
2634 if (base_row <= 0) {
2642 if (base_row + page_size >= row_limit) {
2651 if (base_row <= 0) {
2654 base_row -= (page_size - 1);
2662 if (base_row + page_size >= row_limit) {
2665 base_row += page_size - 1;
2666 if (base_row + page_size >= row_limit) {
2667 base_row = row_limit - page_size - 1;
2672 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2674 color_legend(helpwin, TRUE);
2692 #endif /* USE_WIDEC_SUPPORT */
2694 #if HAVE_COLOR_CONTENT
2696 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2698 NCURSES_COLOR_T red, green, blue;
2700 color_content(current, &red, &green, &blue);
2704 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2707 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2710 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2714 if (init_color(current, red, green, blue) == ERR)
2719 reset_all_colors(void)
2723 for (c = 0; c < COLORS; ++c)
2726 all_colors[c].green,
2727 all_colors[c].blue);
2730 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2731 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2732 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2735 init_all_colors(bool xterm_colors, char *palette_file)
2738 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2740 failed("all_colors");
2741 for (cp = 0; cp < MaxColors; ++cp) {
2743 &all_colors[cp].red,
2744 &all_colors[cp].green,
2745 &all_colors[cp].blue);
2747 /* xterm and compatible terminals can read results of an OSC string
2748 * asking for the current color palette.
2753 char result[BUFSIZ];
2755 unsigned check_r, check_g, check_b;
2759 for (n = 0; n < MaxColors; ++n) {
2760 fprintf(stderr, "\033]4;%d;?\007", n);
2761 got = (int) read(0, result, sizeof(result) - 1);
2765 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2771 all_colors[n].red = DecodeRGB(check_r);
2772 all_colors[n].green = DecodeRGB(check_g);
2773 all_colors[n].blue = DecodeRGB(check_b);
2780 if (palette_file != 0) {
2781 FILE *fp = fopen(palette_file, "r");
2783 char buffer[BUFSIZ];
2784 int red, green, blue;
2787 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2788 if (sscanf(buffer, "scale:%d", &c) == 1) {
2790 } else if (sscanf(buffer, "%d:%d %d %d",
2799 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2800 all_colors[c].red = Scaled(red);
2801 all_colors[c].green = Scaled(green);
2802 all_colors[c].blue = Scaled(blue);
2810 #define scaled_rgb(n) ((255 * (n)) / 1000)
2813 color_edit(bool recur GCC_UNUSED)
2814 /* display the color test pattern, without trying to edit colors */
2818 int this_c, value, field;
2824 Cannot("does not support color.");
2826 } else if (!can_change_color()) {
2827 Cannot("has hardwired color values.");
2840 page_size = (LINES - 6);
2843 for (i = 0; i < MaxColors; i++)
2844 init_pair((NCURSES_PAIRS_T) i,
2845 (NCURSES_COLOR_T) COLOR_WHITE,
2846 (NCURSES_COLOR_T) i);
2848 MvPrintw(LINES - 2, 0, "Number: %d", value);
2851 NCURSES_COLOR_T red, green, blue;
2854 MvAddStr(0, 20, "Color RGB Value Editing");
2857 for (i = (NCURSES_COLOR_T) top_color;
2858 (i - top_color < page_size)
2859 && (i < MaxColors); i++) {
2862 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2863 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2864 (i == current ? '>' : ' '),
2865 (i < (int) SIZEOF(the_color_names)
2866 ? the_color_names[i] : numeric));
2867 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2869 (void) attrset(A_NORMAL);
2871 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2873 if (current == i && field == 0)
2875 printw("%04d", (int) red);
2876 if (current == i && field == 0)
2877 (void) attrset(A_NORMAL);
2879 if (current == i && field == 1)
2881 printw("%04d", (int) green);
2882 if (current == i && field == 1)
2883 (void) attrset(A_NORMAL);
2885 if (current == i && field == 2)
2887 printw("%04d", (int) blue);
2888 if (current == i && field == 2)
2889 (void) attrset(A_NORMAL);
2890 (void) attrset(A_NORMAL);
2891 printw(" ( %3d %3d %3d )",
2892 (int) scaled_rgb(red),
2893 (int) scaled_rgb(green),
2894 (int) scaled_rgb(blue));
2897 MvAddStr(LINES - 3, 0,
2898 "Use up/down to select a color, left/right to change fields.");
2899 MvAddStr(LINES - 2, 0,
2900 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2902 move(2 + current - top_color, 0);
2906 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2928 current -= (page_size - 1);
2935 if (current < (MaxColors - 1))
2936 current += (page_size - 1);
2943 current = (current == 0 ? (MaxColors - 1) : current - 1);
2948 current = (current == (MaxColors - 1) ? 0 : current + 1);
2953 field = (field == 2 ? 0 : field + 1);
2958 field = (field == 0 ? 2 : field - 1);
2971 value = value * 10 + (this_c - '0');
2975 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2979 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2983 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2988 P(" RGB Value Editing Help");
2990 P("You are in the RGB value editor. Use the arrow keys to select one of");
2991 P("the fields in one of the RGB triples of the current colors; the one");
2992 P("currently selected will be reverse-video highlighted.");
2994 P("To change a field, enter the digits of the new value; they are echoed");
2995 P("as entered. Finish by typing `='. The change will take effect instantly.");
2996 P("To increment or decrement a value, use the same procedure, but finish");
2997 P("with a `+' or `-'.");
2999 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3001 P("Press 'm' to invoke the top-level menu with the current color settings.");
3002 P("To quit, do ESC");
3011 for (i = 0; i < MaxColors; i++)
3012 init_pair((NCURSES_PAIRS_T) i,
3013 (NCURSES_COLOR_T) COLOR_WHITE,
3014 (NCURSES_COLOR_T) i);
3028 if (current >= MaxColors)
3029 current = MaxColors - 1;
3030 if (current < top_color)
3031 top_color = current;
3032 if (current - top_color >= page_size)
3033 top_color = current - (page_size - 1);
3035 MvPrintw(LINES - 1, 0, "Number: %d", value);
3038 (!isQuit(this_c, TRUE));
3043 * ncurses does not reset each color individually when calling endwin().
3050 #endif /* HAVE_COLOR_CONTENT */
3052 /****************************************************************************
3054 * Alternate character-set stuff
3056 ****************************************************************************/
3058 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3064 if ((*at_code += 1) >= limit)
3069 *at_code = limit - 1;
3078 *attr = list[*at_code].attr;
3082 #if USE_WIDEC_SUPPORT
3084 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3090 if ((*at_code += 1) >= limit)
3095 *at_code = limit - 1;
3104 *attr = list[*at_code].attr;
3110 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3112 bool result = FALSE;
3122 if ((*fg += 1) >= COLORS)
3130 if ((*bg += 1) >= COLORS)
3138 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3141 if (init_pair(*pair,
3142 (NCURSES_COLOR_T) *fg,
3143 (NCURSES_COLOR_T) *bg) == ERR) {
3152 /****************************************************************************
3154 * Soft-key label test
3156 ****************************************************************************/
3161 #define SLK_WORK (SLK_HELP + 3)
3166 static const char *table[] =
3168 "Available commands are:"
3170 ,"^L -- repaint this message and activate soft keys"
3171 ,"a/d -- activate/disable soft keys"
3172 ,"c -- set centered format for labels"
3173 ,"l -- set left-justified format for labels"
3174 ,"r -- set right-justified format for labels"
3175 ,"[12345678] -- set label; labels are numbered 1 through 8"
3176 ,"e -- erase stdscr (should not erase labels)"
3177 ,"s -- test scrolling of shortened screen"
3178 ,"v/V -- cycle through video attributes"
3180 ,"F/f/B/b -- cycle through foreground/background colors"
3182 ,"ESC -- return to main menu"
3184 ,"Note: if activating the soft keys causes your terminal to scroll up"
3185 ,"one line, your terminal auto-scrolls when anything is written to the"
3186 ,"last screen position. The ncurses code does not yet handle this"
3192 for (j = 0; j < SIZEOF(table); ++j) {
3200 call_slk_color(int fg, int bg)
3202 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3204 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3213 slk_test(bool recur GCC_UNUSED)
3214 /* exercise the soft keys */
3219 chtype attr = A_NORMAL;
3220 unsigned at_code = 0;
3222 int fg = COLOR_BLACK;
3223 int bg = COLOR_WHITE;
3224 NCURSES_PAIRS_T pair = 0;
3226 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3227 unsigned my_size = init_attr_list(my_list, termattrs());
3232 call_slk_color(fg, bg);
3242 MvAddStr(0, 20, "Soft Key Exerciser");
3257 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3258 while ((c = Getchar()) != 'Q' && (c != ERR))
3286 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3287 _nc_STRCPY(buf, "", sizeof(buf));
3288 if ((s = slk_label(c - '0')) != 0) {
3289 _nc_STRNCPY(buf, s, (size_t) 8);
3291 wGetstring(stdscr, buf, 8);
3292 slk_set((c - '0'), buf, fmt);
3301 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3303 wnoutrefresh(stdscr);
3308 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3315 if (cycle_colors(c, &fg, &bg, &pair)) {
3317 call_slk_color(fg, bg);
3327 } while (!isQuit(c = Getchar(), TRUE));
3336 #if USE_WIDEC_SUPPORT
3339 x_slk_test(bool recur GCC_UNUSED)
3340 /* exercise the soft keys */
3343 wchar_t buf[SLKLEN + 1];
3345 attr_t attr = WA_NORMAL;
3346 unsigned at_code = 0;
3347 int fg = COLOR_BLACK;
3348 int bg = COLOR_WHITE;
3349 NCURSES_PAIRS_T pair = 0;
3350 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3351 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3355 call_slk_color(fg, bg);
3362 attr_on(WA_BOLD, NULL);
3363 MvAddStr(0, 20, "Soft Key Exerciser");
3364 attr_off(WA_BOLD, NULL);
3378 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3379 while ((c = Getchar()) != 'Q' && (c != ERR))
3407 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3409 if ((s = slk_label(c - '0')) != 0) {
3410 char *temp = strdup(s);
3411 size_t used = strlen(temp);
3412 size_t want = SLKLEN;
3414 #ifndef state_unused
3419 while (want > 0 && used != 0) {
3420 const char *base = s;
3421 reset_mbytes(state);
3422 test = count_mbytes(base, 0, &state);
3423 if (test == (size_t) -1) {
3425 } else if (test > want) {
3428 reset_mbytes(state);
3429 trans_mbytes(buf, base, want, &state);
3435 wGet_wstring(stdscr, buf, SLKLEN);
3436 slk_wset((c - '0'), buf, fmt);
3447 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3448 call_slk_color(fg, bg);
3453 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3454 call_slk_color(fg, bg);
3457 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3459 wnoutrefresh(stdscr);
3463 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3464 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3470 if (cycle_colors(c, &fg, &bg, &pair)) {
3472 call_slk_color(fg, bg);
3482 } while (!isQuit(c = Getchar(), TRUE));
3491 #endif /* SLK_INIT */
3494 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3497 unsigned last = 255;
3503 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3508 for (code = first; code <= last; ++code) {
3509 int row = (int) (2 + (code / 16));
3510 int col = (int) (5 * (code % 16));
3511 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3512 for (count = 1; count < repeat; ++count) {
3513 AddCh(colored_chtype(code, attr, pair));
3520 * Show a slice of 32 characters, allowing those to be repeated up to the
3523 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3524 * terminal to perform functions. The remaining codes can be graphic.
3527 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3530 unsigned first = (unsigned) base;
3531 unsigned last = first + (unsigned) pagesize - 2;
3532 bool C1 = (first == 128);
3537 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3538 C1 ? "C1" : "GR", first, last);
3542 for (code = first; code <= last; code++) {
3544 int row = 2 + ((int) (code - first) % (pagesize / 2));
3545 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3547 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3548 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3552 nodelay(stdscr, TRUE);
3553 echochar(colored_chtype(code, attr, pair));
3555 /* (yes, this _is_ crude) */
3556 while ((reply = Getchar()) != ERR) {
3557 AddCh(UChar(reply));
3560 nodelay(stdscr, FALSE);
3562 } while (--count > 0);
3569 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3575 MvPrintw(0, 20, "Display of PC Character Codes");
3579 for (code = 0; code < 16; ++code) {
3580 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3582 for (code = 0; code < 256; code++) {
3584 int row = 3 + (int) (code / 16) + (code >= 128);
3585 int col = 8 + (int) (code % 16) * PC_COLS;
3586 if ((code % 16) == 0)
3587 MvPrintw(row, 0, "0x%02x:", code);
3598 * Skip the ones that do not work.
3602 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3605 } while (--count > 0);
3610 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3614 attr |= (attr_t) COLOR_PAIR(pair);
3618 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3623 colored_chtype(ACS_VLINE, attr, pair),
3624 colored_chtype(ACS_VLINE, attr, pair),
3625 colored_chtype(ACS_HLINE, attr, pair),
3626 colored_chtype(ACS_HLINE, attr, pair),
3627 colored_chtype(ACS_ULCORNER, attr, pair),
3628 colored_chtype(ACS_URCORNER, attr, pair),
3629 colored_chtype(ACS_LLCORNER, attr, pair),
3630 colored_chtype(ACS_LRCORNER, attr, pair));
3631 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3632 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3633 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3634 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3635 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3636 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3637 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3643 show_1_acs(int n, int repeat, const char *name, chtype code)
3645 const int height = 16;
3646 int row = 2 + (n % height);
3647 int col = (n / height) * COLS / 2;
3649 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3652 } while (--repeat > 0);
3657 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3658 /* display the ACS character set */
3662 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3666 MvAddStr(0, 20, "Display of the ACS Character Set");
3670 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3671 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3672 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3673 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3675 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3676 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3677 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3678 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3680 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3681 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3684 * HPUX's ACS definitions are broken here. Just give up.
3686 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3687 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3688 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3689 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3690 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3692 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3693 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3694 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3695 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3696 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3697 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3698 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3699 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3700 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3702 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3703 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3704 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3706 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3707 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3708 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3709 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3710 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3711 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3717 acs_test(bool recur GCC_UNUSED)
3721 char *term = getenv("TERM");
3722 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3725 chtype attr = A_NORMAL;
3728 int fg = COLOR_BLACK;
3729 int bg = COLOR_BLACK;
3730 unsigned at_code = 0;
3731 NCURSES_PAIRS_T pair = 0;
3732 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3733 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3734 unsigned my_size = init_attr_list(my_list, termattrs());
3742 ToggleAcs(last_show_acs, show_acs_chars);
3746 ToggleAcs(last_show_acs, show_pc_chars);
3751 if (pagesize == 32) {
3758 ToggleAcs(last_show_acs, show_box_chars);
3784 if (repeat < (COLS / 4))
3792 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3793 || cycle_colors(c, &fg, &bg, &pair)) {
3800 if (pagesize != 32) {
3801 show_256_chars(repeat, attr, pair);
3802 } else if (last_show_acs != 0) {
3803 last_show_acs(repeat, attr, pair);
3805 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3808 MvPrintw(LINES - 3, 0,
3809 "Note: ANSI terminals may not display C1 characters.");
3810 MvPrintw(LINES - 2, 0,
3811 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3814 MvPrintw(LINES - 1, 0,
3815 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3816 my_list[at_code].name,
3819 MvPrintw(LINES - 1, 0,
3820 "v/V cycles through video attributes (%s).",
3821 my_list[at_code].name);
3824 } while (!isQuit(c = Getchar(), TRUE));
3832 #if USE_WIDEC_SUPPORT
3834 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3840 TEST_CCHAR(src, count, {
3841 attr |= (test_attrs & A_ALTCHARSET);
3842 setcchar(dst, test_wch, attr, pair, NULL);
3852 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3853 * display. If there are no repeats, we could normally display 16 lines of 64
3854 * characters (1024 total). However, taking repeats and double-width cells
3855 * into account, use 256 characters for the page.
3858 show_paged_widechars(int base,
3863 NCURSES_PAIRS_T pair)
3865 int first = base * pagesize;
3866 int last = first + pagesize - 1;
3874 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3877 for (code = (wchar_t) first; (int) code <= last; code++) {
3878 int row = (2 + ((int) code - first) / per_line);
3879 int col = 5 * ((int) code % per_line);
3882 memset(&codes, 0, sizeof(codes));
3884 setcchar(&temp, codes, attr, pair, 0);
3886 if (wcwidth(code) == 0 && code != 0) {
3887 AddCh((chtype) space |
3888 (A_REVERSE ^ attr) |
3889 (attr_t) COLOR_PAIR(pair));
3892 for (count = 1; count < repeat; ++count) {
3899 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3903 int last = first + 31;
3907 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3910 for (code = (wchar_t) first; (int) code <= last; code++) {
3911 int row = 2 + ((code - first) % 16);
3912 int col = ((code - first) / 16) * COLS / 2;
3918 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
3919 "%3ld (0x%lx)", (long) code, (long) code);
3920 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3922 memset(&codes, 0, sizeof(codes));
3924 setcchar(&temp, codes, attr, pair, 0);
3928 * Give non-spacing characters something to combine with. If we
3929 * don't, they'll bunch up in a heap on the space after the ":".
3930 * Mark them with reverse-video to make them simpler to find on
3933 if (wcwidth(code) == 0) {
3934 AddCh((chtype) space |
3935 (A_REVERSE ^ attr) |
3936 (attr_t) COLOR_PAIR(pair));
3939 * This uses echo_wchar(), for comparison with the normal 'f'
3940 * test (and to make a test-case for echo_wchar()). The screen
3941 * may flicker because the erase() at the top of the function
3942 * is met by the builtin refresh() in echo_wchar().
3946 * The repeat-count may make text wrap - avoid that.
3948 getyx(stdscr, y, x);
3950 if (x >= col + (COLS / 2) - 2)
3952 } while (--count > 0);
3957 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3959 const int height = 16;
3960 int row = 2 + (n % height);
3961 int col = (n / height) * COLS / 2;
3963 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3964 while (--repeat >= 0) {
3970 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3973 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3974 /* display the wide-ACS character set */
3980 /*#define BOTH2(name) #name, &(name) */
3981 #define BOTH2(name) #name, MERGE_ATTR(name)
3985 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3989 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3990 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3991 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3992 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3994 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3995 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3996 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3997 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3999 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4000 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4002 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4003 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4004 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4005 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4007 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4008 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4009 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4010 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4011 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4012 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4013 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4014 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4015 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4017 #ifdef CURSES_WACS_ARRAY
4018 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4019 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4020 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4022 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4023 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4024 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4025 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4026 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4027 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4033 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4034 /* display the wide-ACS character set */
4040 /*#define BOTH2(name) #name, &(name) */
4041 #define BOTH2(name) #name, MERGE_ATTR(name)
4045 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4049 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4050 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4051 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4052 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4054 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4055 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4056 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4057 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4059 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4060 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4062 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4063 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4064 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4065 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4067 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4068 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4069 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4070 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4071 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4072 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4073 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4074 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4075 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4077 #ifdef CURSES_WACS_ARRAY
4078 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4079 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4080 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4082 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4083 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4084 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4085 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4086 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4087 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4094 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4095 /* display the wide-ACS character set */
4101 /*#define BOTH2(name) #name, &(name) */
4102 #define BOTH2(name) #name, MERGE_ATTR(name)
4106 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4110 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4111 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4115 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4117 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4118 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4120 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4121 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4123 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4124 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4125 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4126 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4128 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4129 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4130 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4131 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4132 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4133 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4134 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4135 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4136 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4138 #ifdef CURSES_WACS_ARRAY
4139 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4140 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4141 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4143 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4144 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4145 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4146 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4147 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4148 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4155 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4158 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4165 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4170 MERGE_ATTR(0, WACS_VLINE),
4171 MERGE_ATTR(1, WACS_VLINE),
4172 MERGE_ATTR(2, WACS_HLINE),
4173 MERGE_ATTR(3, WACS_HLINE),
4174 MERGE_ATTR(4, WACS_ULCORNER),
4175 MERGE_ATTR(5, WACS_URCORNER),
4176 MERGE_ATTR(6, WACS_LLCORNER),
4177 MERGE_ATTR(7, WACS_LRCORNER));
4179 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4180 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4181 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4182 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4183 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4184 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4185 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4193 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4195 const int height = 16;
4196 int row = 2 + (n % height);
4197 int col = (n / height) * COLS / 2;
4200 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4201 (void) attr_set(attr, pair, 0);
4202 _nc_STRNCPY(temp, code, 20);
4204 (void) attr_set(A_NORMAL, 0, 0);
4208 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4211 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4218 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4222 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4223 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4224 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4225 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4227 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4228 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4229 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4230 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4232 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4233 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4235 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4236 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4237 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4238 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4240 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4241 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4242 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4243 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4244 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4245 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4246 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4247 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4248 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4249 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4250 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4251 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4253 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4254 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4255 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4256 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4257 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4258 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4263 /* display the wide-ACS character set */
4265 x_acs_test(bool recur GCC_UNUSED)
4272 attr_t attr = WA_NORMAL;
4273 int fg = COLOR_BLACK;
4274 int bg = COLOR_BLACK;
4275 unsigned at_code = 0;
4276 NCURSES_PAIRS_T pair = 0;
4277 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4278 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4279 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4287 ToggleAcs(last_show_wacs, show_wacs_chars);
4291 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4296 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4300 if (pagesize == 32) {
4307 ToggleAcs(last_show_wacs, show_wbox_chars);
4310 ToggleAcs(last_show_wacs, show_utf8_chars);
4313 if (c < 256 && isdigit(c)) {
4316 } else if (c == '+') {
4319 } else if (c == '-' && digit > 0) {
4322 } else if (c == '>' && repeat < (COLS / 4)) {
4324 } else if (c == '<' && repeat > 1) {
4326 } else if (c == '_') {
4327 space = (space == ' ') ? '_' : ' ';
4329 } else if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)
4330 || cycle_colors(c, &fg, &bg, &pair)) {
4331 if (last_show_wacs != 0)
4339 if (pagesize != 32) {
4340 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4341 } else if (last_show_wacs != 0) {
4342 last_show_wacs(repeat, attr, pair);
4344 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4347 MvPrintw(LINES - 4, 0,
4348 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
4349 MvPrintw(LINES - 3, 2,
4350 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4352 MvPrintw(LINES - 2, 2,
4353 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4354 my_list[at_code].name,
4357 MvPrintw(LINES - 2, 2,
4358 "v/V cycles through video attributes (%s).",
4359 my_list[at_code].name);
4362 } while (!isQuit(c = Getchar(), TRUE));
4373 * Graphic-rendition test (adapted from vttest)
4376 sgr_attr_test(bool recur GCC_UNUSED)
4380 for (pass = 0; pass < 2; pass++) {
4381 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4383 /* Use non-default colors if possible to exercise bce a little */
4385 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4386 normal |= (chtype) COLOR_PAIR(1);
4390 MvPrintw(1, 20, "Graphic rendition test pattern:");
4392 MvPrintw(4, 1, "vanilla");
4394 #define set_sgr(mask) bkgdset((normal^(mask)));
4396 MvPrintw(4, 40, "bold");
4398 set_sgr(A_UNDERLINE);
4399 MvPrintw(6, 6, "underline");
4401 set_sgr(A_BOLD | A_UNDERLINE);
4402 MvPrintw(6, 45, "bold underline");
4405 MvPrintw(8, 1, "blink");
4407 set_sgr(A_BLINK | A_BOLD);
4408 MvPrintw(8, 40, "bold blink");
4410 set_sgr(A_UNDERLINE | A_BLINK);
4411 MvPrintw(10, 6, "underline blink");
4413 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4414 MvPrintw(10, 45, "bold underline blink");
4417 MvPrintw(12, 1, "negative");
4419 set_sgr(A_BOLD | A_REVERSE);
4420 MvPrintw(12, 40, "bold negative");
4422 set_sgr(A_UNDERLINE | A_REVERSE);
4423 MvPrintw(14, 6, "underline negative");
4425 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4426 MvPrintw(14, 45, "bold underline negative");
4428 set_sgr(A_BLINK | A_REVERSE);
4429 MvPrintw(16, 1, "blink negative");
4431 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4432 MvPrintw(16, 40, "bold blink negative");
4434 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4435 MvPrintw(18, 6, "underline blink negative");
4437 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4438 MvPrintw(18, 45, "bold underline blink negative");
4441 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4447 bkgdset(A_NORMAL | BLANK);
4453 /****************************************************************************
4455 * Windows and scrolling tester.
4457 ****************************************************************************/
4459 #define BOTLINES 4 /* number of line stolen from screen bottom */
4465 #define FRAME struct frame