1 /****************************************************************************
2 * Copyright (c) 1998-2018,2019 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.518 2019/08/31 23:22:40 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);
239 if (x > (int) strlen(buffer))
240 x = (int) strlen(buffer);
242 wprintw(win, "%-*s", limit, buffer);
243 wmove(win, y0, x0 + x);
244 switch (ch = wGetchar(win)) {
257 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
275 if (!isprint(ch) || ch >= KEY_MIN) {
277 } else if ((int) strlen(buffer) < limit) {
279 for (j = (int) strlen(buffer) + 1; j > x; --j) {
280 buffer[j] = buffer[j - 1];
282 buffer[x++] = (char) ch;
289 wattroff(win, A_REVERSE);
295 #if USE_WIDEC_SUPPORT
297 fullwidth_digit(int ch)
299 return (wchar_t) (ch + 0xff10 - '0');
303 make_fullwidth_text(wchar_t *target, const char *source)
306 while ((ch = *source++) != 0) {
307 *target++ = fullwidth_digit(ch);
313 make_narrow_text(wchar_t *target, const char *source)
316 while ((ch = *source++) != 0) {
317 *target++ = (wchar_t) ch;
324 make_fullwidth_digit(cchar_t *target, int digit)
328 source[0] = fullwidth_digit(digit + '0');
330 setcchar(target, source, A_NORMAL, 0, 0);
335 wGet_wchar(WINDOW *win, wint_t *result)
339 while ((c = wget_wch(win, result)) == CTRL('T')) {
341 save_trace = _nc_tracing;
342 Trace(("TOGGLE-TRACING OFF"));
345 _nc_tracing = save_trace;
349 Trace(("TOGGLE-TRACING ON"));
352 c = wget_wch(win, result);
356 #define Get_wchar(result) wGet_wchar(stdscr, result)
358 /* replaces wgetn_wstr(), since we want to be able to edit values */
361 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
370 (void) wattrset(win, A_REVERSE);
372 x = (int) wcslen(buffer);
374 if (x > (int) wcslen(buffer))
375 x = (int) wcslen(buffer);
377 /* clear the "window' */
379 wprintw(win, "%*s", limit, " ");
381 /* write the existing buffer contents */
383 waddnwstr(win, buffer, limit);
385 /* positions the cursor past character 'x' */
387 waddnwstr(win, buffer, x);
389 switch (wGet_wchar(win, &ch)) {
429 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
449 } else if ((int) wcslen(buffer) < limit) {
451 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
452 buffer[j] = buffer[j - 1];
454 buffer[x++] = (wchar_t) ch;
461 wattroff(win, A_REVERSE);
465 #endif /* USE_SOFTKEYS */
467 #endif /* USE_WIDEC_SUPPORT */
473 addstr("Press any key to continue... ");
478 Cannot(const char *what)
480 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
486 ShellOut(bool message)
489 addstr("Shelling out...");
495 IGNORE_RC(system("sh"));
498 addstr("returned from shellout.\n");
502 #ifdef NCURSES_MOUSE_VERSION
504 * This function is the same as _tracemouse(), but we cannot count on that
505 * being available in the non-debug library.
508 mouse_decode(MEVENT const *ep)
510 static char buf[80 + (5 * 10) + (32 * 15)];
512 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
513 "id %2d at (%2d, %2d, %d) state %4lx = {",
514 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
517 if ((ep->bstate & m)==m) { \
518 _nc_STRCAT(buf, s, sizeof(buf)); \
519 _nc_STRCAT(buf, ", ", sizeof(buf)); \
522 SHOW(BUTTON1_RELEASED, "release-1");
523 SHOW(BUTTON1_PRESSED, "press-1");
524 SHOW(BUTTON1_CLICKED, "click-1");
525 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
526 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
527 #if NCURSES_MOUSE_VERSION == 1
528 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
531 SHOW(BUTTON2_RELEASED, "release-2");
532 SHOW(BUTTON2_PRESSED, "press-2");
533 SHOW(BUTTON2_CLICKED, "click-2");
534 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
535 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
536 #if NCURSES_MOUSE_VERSION == 1
537 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
540 SHOW(BUTTON3_RELEASED, "release-3");
541 SHOW(BUTTON3_PRESSED, "press-3");
542 SHOW(BUTTON3_CLICKED, "click-3");
543 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
544 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
545 #if NCURSES_MOUSE_VERSION == 1
546 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
549 SHOW(BUTTON4_RELEASED, "release-4");
550 SHOW(BUTTON4_PRESSED, "press-4");
551 SHOW(BUTTON4_CLICKED, "click-4");
552 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
553 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
554 #if NCURSES_MOUSE_VERSION == 1
555 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
558 #if NCURSES_MOUSE_VERSION == 2
559 SHOW(BUTTON5_RELEASED, "release-5");
560 SHOW(BUTTON5_PRESSED, "press-5");
561 SHOW(BUTTON5_CLICKED, "click-5");
562 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
563 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
566 SHOW(BUTTON_CTRL, "ctrl");
567 SHOW(BUTTON_SHIFT, "shift");
568 SHOW(BUTTON_ALT, "alt");
569 SHOW(ALL_MOUSE_EVENTS, "all-events");
570 SHOW(REPORT_MOUSE_POSITION, "position");
574 if (buf[strlen(buf) - 1] == ' ')
575 buf[strlen(buf) - 2] = '\0';
576 _nc_STRCAT(buf, "}", sizeof(buf));
581 show_mouse(WINDOW *win)
588 outside = !wenclose(win, event.y, event.x);
591 (void) wstandout(win);
592 waddstr(win, "KEY_MOUSE");
593 (void) wstandend(win);
595 waddstr(win, "KEY_MOUSE");
597 wprintw(win, ", %s", mouse_decode(&event));
602 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
607 wmove(win, event.y, event.x);
615 #endif /* NCURSES_MOUSE_VERSION */
617 /****************************************************************************
619 * Character input test
621 ****************************************************************************/
623 #define NUM_GETCH_FLAGS 256
624 typedef bool GetchFlags[NUM_GETCH_FLAGS];
627 setup_getch(WINDOW *win, GetchFlags flags)
629 keypad(win, flags['k']); /* should be redundant, but for testing */
630 meta(win, flags['m']); /* force this to a known state */
638 init_getch(WINDOW *win, GetchFlags flags, int delay)
640 memset(flags, FALSE, NUM_GETCH_FLAGS);
641 flags[UChar('k')] = (win == stdscr);
642 flags[UChar('m')] = TRUE;
643 flags[UChar('t')] = (delay != 0);
645 setup_getch(win, flags);
649 blocking_getch(GetchFlags flags, int delay)
651 return ((delay < 0) && flags['t']);
654 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
657 wgetch_help(WINDOW *win, GetchFlags flags)
659 static const char *help[] =
661 "e -- toggle echo mode"
662 ,"g -- triggers a getstr test"
663 ,"k -- toggle keypad/literal mode"
664 ,"m -- toggle meta (7-bit/8-bit) mode"
667 ,"t -- toggle timeout"
668 ,"w -- create a new window"
670 ,"z -- suspend this process"
674 unsigned chk = ((SIZEOF(help) + 1) / 2);
679 printw("Type any key to see its %s value. Also:\n",
680 flags['k'] ? "keypad" : "literal");
681 for (n = 0; n < SIZEOF(help); ++n) {
682 const char *msg = help[n];
683 int row = 1 + (int) (n % chk);
684 int col = (n >= chk) ? COLS / 2 : 0;
685 int flg = ((strstr(msg, "toggle") != 0)
686 && (flags[UChar(*msg)] != FALSE));
687 if (*msg == '^' && ExitOnEscape())
688 msg = "^[,^q -- quit";
691 MvPrintw(row, col, "%s", msg);
702 wgetch_wrap(WINDOW *win, int first_y)
704 int last_y = getmaxy(win) - 1;
705 int y = getcury(win) + 1;
713 #if defined(KEY_RESIZE) && HAVE_WRESIZE
719 static WINSTACK *winstack = 0;
720 static unsigned len_winstack = 0;
733 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
735 unsigned need = (level + 1) * 2;
737 assert(level < (unsigned) COLS);
741 winstack = typeMalloc(WINSTACK, len_winstack);
742 } else if (need >= len_winstack) {
744 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
747 failed("remember_boxes");
748 winstack[level].text = txt_win;
749 winstack[level].frame = box_win;
752 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
756 /* this chunk is now done in resize_term() */
763 #define slk_repaint() /* nothing */
766 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
768 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
769 * Resize both and paint the box in the parent.
772 resize_boxes(unsigned level, WINDOW *win)
776 int high = LINES - base;
780 wnoutrefresh(stdscr);
784 for (n = 0; n < level; ++n) {
785 wresize(winstack[n].frame, high, wide);
786 wresize(winstack[n].text, high - 2, wide - 2);
789 werase(winstack[n].text);
790 box(winstack[n].frame, 0, 0);
791 wnoutrefresh(winstack[n].frame);
792 wprintw(winstack[n].text,
794 getmaxy(winstack[n].text),
795 getmaxx(winstack[n].text));
796 wnoutrefresh(winstack[n].text);
797 if (winstack[n].text == win)
802 #endif /* resize_boxes */
804 #define forget_boxes() /* nothing */
805 #define remember_boxes(level,text,frame) /* nothing */
809 * Return-code is OK/ERR or a keyname.
814 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
818 wgetch_test(unsigned level, WINDOW *win, int delay)
821 int first_y, first_x;
825 init_getch(win, flags, delay);
826 notimeout(win, FALSE);
827 wtimeout(win, delay);
828 getyx(win, first_y, first_x);
830 wgetch_help(win, flags);
831 wsetscrreg(win, first_y, getmaxy(win) - 1);
837 while ((c = wGetchar(win)) == ERR) {
839 if (blocking_getch(flags, delay)) {
840 (void) wprintw(win, "%05d: input error", incount);
843 (void) wprintw(win, "%05d: input timed out", incount);
845 wgetch_wrap(win, first_y);
847 if (c == ERR && blocking_getch(flags, delay)) {
849 wgetch_wrap(win, first_y);
850 } else if (isQuit(c, ExitOnEscape())) {
852 } else if (c == 'e') {
853 flags[UChar('e')] = !flags[UChar('e')];
854 setup_getch(win, flags);
855 wgetch_help(win, flags);
856 } else if (c == 'g') {
857 waddstr(win, "getstr test: ");
859 c = wgetnstr(win, buf, sizeof(buf) - 1);
861 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
862 (int) strlen(buf), buf,
865 wgetch_wrap(win, first_y);
866 } else if (c == 'k') {
867 flags[UChar('k')] = !flags[UChar('k')];
868 setup_getch(win, flags);
869 wgetch_help(win, flags);
870 } else if (c == 'm') {
871 flags[UChar('m')] = !flags[UChar('m')];
872 setup_getch(win, flags);
873 wgetch_help(win, flags);
874 } else if (c == 's') {
876 } else if (c == 't') {
877 notimeout(win, flags[UChar('t')]);
878 flags[UChar('t')] = !flags[UChar('t')];
879 wgetch_help(win, flags);
880 } else if (c == 'w') {
881 int high = getmaxy(win) - 1 - first_y + 1;
882 int wide = getmaxx(win) - first_x;
884 int new_y = first_y + getbegy(win);
885 int new_x = first_x + getbegx(win);
887 getyx(win, old_y, old_x);
888 if (high > 2 && wide > 2) {
889 WINDOW *wb = newwin(high, wide, new_y, new_x);
890 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
895 remember_boxes(level, wi, wb);
896 wgetch_test(level + 1, wi, delay);
900 wgetch_help(win, flags);
901 wmove(win, old_y, old_x);
907 } else if (c == 'z') {
908 kill(getpid(), SIGTSTP);
911 wprintw(win, "Key pressed: %04o ", c);
912 #ifdef NCURSES_MOUSE_VERSION
913 if (c == KEY_MOUSE) {
916 #endif /* NCURSES_MOUSE_VERSION */
918 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
919 if (c == KEY_RESIZE) {
920 resize_boxes(level, win);
923 (void) waddstr(win, keyname(c));
924 } else if (c >= 0x80) {
925 unsigned c2 = (unsigned) c;
926 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
927 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
931 (void) wprintw(win, "%c", UChar(c));
932 else if (c2 != UChar(c))
933 (void) wprintw(win, "M-%s", unctrl(c2));
935 (void) wprintw(win, "%s", unctrl(c2));
936 waddstr(win, " (high-half character)");
939 (void) wprintw(win, "%c (ASCII printable character)", c);
941 (void) wprintw(win, "%s (ASCII control character)",
944 wgetch_wrap(win, first_y);
951 init_getch(win, flags, delay);
955 begin_getch_test(void)
962 #ifdef NCURSES_MOUSE_VERSION
963 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
966 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
968 getnstr(buf, sizeof(buf) - 1);
972 if (isdigit(UChar(buf[0]))) {
973 delay = atoi(buf) * 100;
983 finish_getch_test(void)
985 #ifdef NCURSES_MOUSE_VERSION
986 mousemask(0, (mmask_t *) 0);
995 getch_test(bool recur GCC_UNUSED)
997 int delay = begin_getch_test();
1000 wgetch_test(0, stdscr, delay);
1002 finish_getch_test();
1007 #if USE_WIDEC_SUPPORT
1009 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1010 * Resize both and paint the box in the parent.
1012 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1014 resize_wide_boxes(unsigned level, WINDOW *win)
1018 int high = LINES - base;
1022 wnoutrefresh(stdscr);
1026 for (n = 0; n < level; ++n) {
1027 wresize(winstack[n].frame, high, wide);
1028 wresize(winstack[n].text, high - 2, wide - 2);
1031 werase(winstack[n].text);
1032 box_set(winstack[n].frame, 0, 0);
1033 wnoutrefresh(winstack[n].frame);
1034 wprintw(winstack[n].text,
1036 getmaxy(winstack[n].text),
1037 getmaxx(winstack[n].text));
1038 wnoutrefresh(winstack[n].text);
1039 if (winstack[n].text == win)
1044 #endif /* KEY_RESIZE */
1047 wcstos(const wchar_t *src)
1051 const wchar_t *tmp = src;
1052 #ifndef state_unused
1056 reset_wchars(state);
1057 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1058 unsigned have = (unsigned) need;
1059 if ((result = typeCalloc(char, have + 1)) != 0) {
1061 if (trans_wchars(result, tmp, have, &state) != have) {
1073 wget_wch_test(unsigned level, WINDOW *win, int delay)
1075 wchar_t wchar_buf[BUFSIZ];
1076 wint_t wint_buf[BUFSIZ];
1077 int first_y, first_x;
1083 init_getch(win, flags, delay);
1084 notimeout(win, FALSE);
1085 wtimeout(win, delay);
1086 getyx(win, first_y, first_x);
1088 wgetch_help(win, flags);
1089 wsetscrreg(win, first_y, getmaxy(win) - 1);
1090 scrollok(win, TRUE);
1095 while ((code = wGet_wchar(win, &c)) == ERR) {
1097 if (blocking_getch(flags, delay)) {
1098 (void) wprintw(win, "%05d: input error", incount);
1101 (void) wprintw(win, "%05d: input timed out", incount);
1103 wgetch_wrap(win, first_y);
1105 if (code == ERR && blocking_getch(flags, delay)) {
1106 wprintw(win, "ERR");
1107 wgetch_wrap(win, first_y);
1108 } else if (isQuit((int) c, ExitOnEscape())) {
1110 } else if (c == 'e') {
1111 flags[UChar('e')] = !flags[UChar('e')];
1112 setup_getch(win, flags);
1113 wgetch_help(win, flags);
1114 } else if (c == 'g') {
1115 waddstr(win, "getstr test: ");
1117 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1120 wprintw(win, "wgetn_wstr returns an error.");
1123 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1126 if ((temp = wcstos(wchar_buf)) != 0) {
1127 wprintw(win, "I saw %d characters:\n\t`%s'.",
1128 (int) wcslen(wchar_buf), temp);
1131 wprintw(win, "I saw %d characters (cannot convert).",
1132 (int) wcslen(wchar_buf));
1136 wgetch_wrap(win, first_y);
1137 } else if (c == 'k') {
1138 flags[UChar('k')] = !flags[UChar('k')];
1139 setup_getch(win, flags);
1140 wgetch_help(win, flags);
1141 } else if (c == 'm') {
1142 flags[UChar('m')] = !flags[UChar('m')];
1143 setup_getch(win, flags);
1144 wgetch_help(win, flags);
1145 } else if (c == 's') {
1147 } else if (c == 't') {
1148 notimeout(win, flags[UChar('t')]);
1149 flags[UChar('t')] = !flags[UChar('t')];
1150 wgetch_help(win, flags);
1151 } else if (c == 'w') {
1152 int high = getmaxy(win) - 1 - first_y + 1;
1153 int wide = getmaxx(win) - first_x;
1155 int new_y = first_y + getbegy(win);
1156 int new_x = first_x + getbegx(win);
1158 getyx(win, old_y, old_x);
1159 if (high > 2 && wide > 2) {
1160 WINDOW *wb = newwin(high, wide, new_y, new_x);
1161 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1166 remember_boxes(level, wi, wb);
1167 wget_wch_test(level + 1, wi, delay);
1171 wgetch_help(win, flags);
1172 wmove(win, old_y, old_x);
1177 } else if (c == 'z') {
1178 kill(getpid(), SIGTSTP);
1181 wprintw(win, "Key pressed: %04o ", (int) c);
1182 #ifdef NCURSES_MOUSE_VERSION
1183 if (c == KEY_MOUSE) {
1186 #endif /* NCURSES_MOUSE_VERSION */
1187 if (code == KEY_CODE_YES) {
1188 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1189 if (c == KEY_RESIZE) {
1190 resize_wide_boxes(level, win);
1193 (void) waddstr(win, keyname((wchar_t) c));
1195 (void) waddstr(win, key_name((wchar_t) c));
1196 if (c < 256 && iscntrl(c)) {
1197 (void) wprintw(win, " (control character)");
1199 (void) wprintw(win, " = %#x (printable character)",
1203 wgetch_wrap(win, first_y);
1210 init_getch(win, flags, delay);
1214 x_getch_test(bool recur GCC_UNUSED)
1216 int delay = begin_getch_test();
1219 wget_wch_test(0, stdscr, delay);
1221 finish_getch_test();
1227 /****************************************************************************
1229 * Character attributes test
1231 ****************************************************************************/
1233 #if HAVE_SETUPTERM || HAVE_TGETENT
1234 #define get_ncv() TIGETNUM("ncv","NC")
1235 #define get_xmc() TIGETNUM("xmc","sg")
1237 #define get_ncv() -1
1238 #define get_xmc() -1
1245 static int first = TRUE;
1246 static chtype result = 0;
1252 char *area_pointer = parsed;
1254 tgetent(buffer, getenv("TERM"));
1257 if (TIGETSTR("smso", "so"))
1258 result |= A_STANDOUT;
1259 if (TIGETSTR("smul", "us"))
1260 result |= A_UNDERLINE;
1261 if (TIGETSTR("rev", "mr"))
1262 result |= A_REVERSE;
1263 if (TIGETSTR("blink", "mb"))
1265 if (TIGETSTR("dim", "mh"))
1267 if (TIGETSTR("bold", "md"))
1269 if (TIGETSTR("smacs", "ac"))
1270 result |= A_ALTCHARSET;
1276 #define termattrs() my_termattrs()
1279 #define ATTRSTRING_1ST 32 /* ' ' */
1280 #define ATTRSTRING_END 126 /* '~' */
1282 #define COLS_PRE_ATTRS 5
1283 #define COLS_AFT_ATTRS 15
1284 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1285 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1286 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1288 static char attr_test_string[MAX_ATTRSTRING + 1];
1291 attr_legend(WINDOW *helpwin)
1296 MvWPrintw(helpwin, row++, col,
1298 MvWPrintw(helpwin, row++, col,
1301 MvWPrintw(helpwin, row++, col,
1302 "Modify the test strings:");
1303 MvWPrintw(helpwin, row++, col,
1304 " A digit sets gaps on each side of displayed attributes");
1305 MvWPrintw(helpwin, row++, col,
1306 " </> shifts the text left/right. ");
1308 MvWPrintw(helpwin, row++, col,
1311 MvWPrintw(helpwin, row++, col,
1312 " f/F/b/B toggle foreground/background background color");
1313 MvWPrintw(helpwin, row++, col,
1314 " t/T toggle text/background color attribute");
1316 MvWPrintw(helpwin, row++, col,
1317 " a/A toggle ACS (alternate character set) mapping");
1318 MvWPrintw(helpwin, row, col,
1319 " v/V toggle video attribute to combine with each line");
1320 #if USE_WIDEC_SUPPORT
1321 MvWPrintw(helpwin, row, col,
1322 " w/W toggle normal/wide (double-width) test-characters");
1327 show_color_attr(int fg, int bg, int tx)
1330 printw(" Colors (fg %d, bg %d", fg, bg);
1332 printw(", text %d", tx);
1338 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1345 *fg = (NCURSES_COLOR_T) (*fg + 1);
1348 *fg = (NCURSES_COLOR_T) (*fg - 1);
1351 *bg = (NCURSES_COLOR_T) (*bg + 1);
1354 *bg = (NCURSES_COLOR_T) (*bg - 1);
1357 *tx = (NCURSES_COLOR_T) (*tx + 1);
1360 *tx = (NCURSES_COLOR_T) (*tx - 1);
1368 *fg = (NCURSES_COLOR_T) MinColors;
1369 if (*fg < MinColors)
1370 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1372 *bg = (NCURSES_COLOR_T) MinColors;
1373 if (*bg < MinColors)
1374 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1378 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1387 adjust_attr_string(int adjust)
1389 char save = attr_test_string[0];
1390 int first = ((int) UChar(save)) + adjust;
1392 if (first >= ATTRSTRING_1ST) {
1395 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1396 if (k > ATTRSTRING_END)
1398 attr_test_string[j] = (char) k;
1399 if (((k + 1 - first) % 5) == 0) {
1400 if (++j >= MAX_ATTRSTRING)
1402 attr_test_string[j] = ' ';
1405 if ((LEN_ATTRSTRING - j) > 5) {
1406 attr_test_string[0] = save;
1407 adjust_attr_string(adjust - 1);
1409 while (j < MAX_ATTRSTRING)
1410 attr_test_string[j++] = ' ';
1411 attr_test_string[j] = '\0';
1417 * Prefer the right-end of the string for starting, since that maps to the
1418 * VT100 line-drawing.
1421 default_attr_string(void)
1423 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1424 result += (LEN_ATTRSTRING / 5);
1425 if (result < ATTRSTRING_1ST)
1426 result = ATTRSTRING_1ST;
1431 init_attr_string(void)
1433 attr_test_string[0] = (char) default_attr_string();
1434 adjust_attr_string(0);
1438 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1440 int ncv = get_ncv();
1441 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1444 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1445 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1446 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1448 printw("%*s", skip, " ");
1450 * Just for testing, write text using the alternate character set one
1451 * character at a time (to pass its rendition directly), and use the
1452 * string operation for the other attributes.
1456 if (attr & A_ALTCHARSET) {
1459 for (s = attr_test_string; *s != '\0'; ++s) {
1460 chtype ch = UChar(*s);
1461 (void) waddch(win, ch | attr);
1464 (void) wattrset(win, AttrArg(attr, 0));
1465 (void) waddstr(win, attr_test_string);
1466 (void) wattroff(win, (int) attr);
1469 printw("%*s", skip, " ");
1470 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1471 if (test != A_NORMAL) {
1472 if (!(termattrs() & test)) {
1475 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1476 static const chtype table[] =
1495 for (n = 0; n < SIZEOF(table); n++) {
1496 if ((table[n] & attr) != 0
1497 && ((1 << n) & ncv) != 0) {
1505 if ((termattrs() & test) != test) {
1515 NCURSES_CONST char *name;
1518 static const ATTR_TBL attrs_to_test[] = {
1519 { A_STANDOUT, "STANDOUT" },
1520 { A_REVERSE, "REVERSE" },
1522 { A_UNDERLINE, "UNDERLINE" },
1524 { A_BLINK, "BLINK" },
1525 { A_PROTECT, "PROTECT" },
1527 { A_INVIS, "INVISIBLE" },
1530 { A_ITALIC, "ITALIC" },
1532 { A_NORMAL, "NORMAL" },
1537 init_attr_list(ATTR_TBL * target, attr_t attrs)
1539 unsigned result = 0;
1542 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1543 attr_t test = attrs_to_test[n].attr;
1544 if (test == A_NORMAL || (test & attrs) != 0) {
1545 target[result++] = attrs_to_test[n];
1551 #if USE_WIDEC_SUPPORT
1554 NCURSES_CONST char *name;
1557 static const W_ATTR_TBL w_attrs_to_test[] = {
1558 { WA_STANDOUT, "STANDOUT" },
1559 { WA_REVERSE, "REVERSE" },
1560 { WA_BOLD, "BOLD" },
1561 { WA_UNDERLINE, "UNDERLINE" },
1563 { WA_BLINK, "BLINK" },
1564 { WA_PROTECT, "PROTECT" },
1566 { WA_INVIS, "INVISIBLE" },
1569 { WA_ITALIC, "ITALIC" },
1571 { WA_NORMAL, "NORMAL" },
1576 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1578 unsigned result = 0;
1581 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1582 attr_t test = w_attrs_to_test[n].attr;
1583 if (test == WA_NORMAL || (test & attrs) != 0) {
1584 target[result++] = w_attrs_to_test[n];
1592 attr_getc(int *skip,
1593 NCURSES_COLOR_T *fg,
1594 NCURSES_COLOR_T *bg,
1595 NCURSES_COLOR_T *tx,
1608 if (ch < 256 && isdigit(ch)) {
1616 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1618 attr_legend(helpwin);
1641 adjust_attr_string(-1);
1644 adjust_attr_string(1);
1650 error = cycle_color_attr(ch, fg, bg, tx);
1659 attr_test(bool recur GCC_UNUSED)
1660 /* test text attributes */
1663 int skip = get_xmc();
1664 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1665 NCURSES_COLOR_T bg = COLOR_BLACK;
1666 NCURSES_COLOR_T tx = -1;
1668 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1669 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1670 unsigned my_size = init_attr_list(my_list, termattrs());
1675 for (j = 0; j < my_size; ++j) {
1676 my_wins[j] = subwin(stdscr,
1678 2 + (int) (2 * j), COL_ATTRSTRING);
1679 scrollok(my_wins[j], FALSE);
1685 n = skip; /* make it easy */
1691 chtype normal = A_NORMAL | BLANK;
1692 chtype extras = (chtype) ac;
1695 NCURSES_PAIRS_T pair = 0;
1696 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1698 if (init_pair(pair, fg, bg) == ERR) {
1701 normal |= (chtype) COLOR_PAIR(pair);
1706 if (init_pair(pair, tx, bg) == ERR) {
1709 extras |= (chtype) COLOR_PAIR(pair);
1719 MvAddStr(0, 20, "Character attribute test display");
1721 for (j = 0; j < my_size; ++j) {
1722 bool arrow = (j == k);
1723 row = show_attr(my_wins[j], row, n, arrow,
1731 MvPrintw(row, COLS_PRE_ATTRS,
1732 "This terminal does %shave the magic-cookie glitch",
1733 get_xmc() > -1 ? "" : "not ");
1734 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1735 show_color_attr(fg, bg, tx);
1736 printw(" ACS (%d)", ac != 0);
1739 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1741 bkgdset(A_NORMAL | BLANK);
1746 Cannot("does not support video attributes.");
1751 #if USE_WIDEC_SUPPORT
1752 static bool use_fullwidth;
1753 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1755 #define FULL_LO 0xff00
1756 #define FULL_HI 0xff5e
1757 #define HALF_LO 0x20
1759 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1760 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1761 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1764 * Returns an ASCII code in [32..126]
1767 normal_wchar(int ch)
1769 wchar_t result = (wchar_t) ch;
1770 if (isFullWidth(ch))
1771 result = ToNormalWidth(ch);
1776 * Returns either an ASCII code in in [32..126] or full-width in
1777 * [0xff00..0xff5e], according to use_fullwidth setting.
1780 target_wchar(int ch)
1782 wchar_t result = (wchar_t) ch;
1783 if (use_fullwidth) {
1784 if (!isFullWidth(ch))
1785 result = ToFullWidth(ch);
1787 if (isFullWidth(ch))
1788 result = ToNormalWidth(ch);
1794 wide_adjust_attr_string(int adjust)
1796 wchar_t save = wide_attr_test_string[0];
1797 int first = ((int) normal_wchar(save)) + adjust;
1799 if (first >= ATTRSTRING_1ST) {
1802 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1803 if (k > ATTRSTRING_END)
1805 wide_attr_test_string[j] = target_wchar(k);
1806 if (((k + 1 - first) % 5) == 0) {
1807 if (++j >= MAX_ATTRSTRING)
1809 wide_attr_test_string[j] = ' ';
1812 if ((LEN_ATTRSTRING - j) > 5) {
1813 wide_attr_test_string[0] = save;
1814 wide_adjust_attr_string(adjust - 1);
1816 while (j < MAX_ATTRSTRING)
1817 wide_attr_test_string[j++] = ' ';
1818 wide_attr_test_string[j] = '\0';
1824 wide_init_attr_string(void)
1826 use_fullwidth = FALSE;
1827 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1828 wide_adjust_attr_string(0);
1832 set_wide_background(NCURSES_PAIRS_T pair)
1839 setcchar(&normal, blank, A_NORMAL, pair, 0);
1845 get_wide_background(void)
1847 attr_t result = WA_NORMAL;
1850 NCURSES_PAIRS_T pair;
1852 memset(&ch, 0, sizeof(ch));
1853 if (getbkgrnd(&ch) != ERR) {
1854 wchar_t wch[CCHARW_MAX];
1856 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1864 wide_show_attr(WINDOW *win,
1869 NCURSES_PAIRS_T pair,
1872 int ncv = get_ncv();
1873 attr_t test = attr & ~WA_ALTCHARSET;
1876 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1877 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1878 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1880 printw("%*s", skip, " ");
1883 * Just for testing, write text using the alternate character set one
1884 * character at a time (to pass its rendition directly), and use the
1885 * string operation for the other attributes.
1889 if (attr & WA_ALTCHARSET) {
1893 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1897 setcchar(&ch, fill, attr, pair, 0);
1898 (void) wadd_wch(win, &ch);
1901 attr_t old_attr = 0;
1902 NCURSES_PAIRS_T old_pair = 0;
1904 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1905 (void) wattr_set(win, attr, pair, 0);
1906 (void) waddwstr(win, wide_attr_test_string);
1907 (void) wattr_set(win, old_attr, old_pair, 0);
1910 printw("%*s", skip, " ");
1911 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1912 if (test != A_NORMAL) {
1913 if (!(term_attrs() & test)) {
1916 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1917 static const attr_t table[] =
1931 for (n = 0; n < SIZEOF(table); n++) {
1932 if ((table[n] & attr) != 0
1933 && ((1 << n) & ncv) != 0) {
1941 if ((term_attrs() & test) != test) {
1950 wide_attr_getc(int *skip,
1951 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1952 NCURSES_COLOR_T *tx, int *ac,
1953 unsigned *kc, unsigned limit)
1963 if (ch < 256 && isdigit(ch)) {
1971 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1972 box_set(helpwin, 0, 0);
1973 attr_legend(helpwin);
1996 use_fullwidth = FALSE;
1997 wide_adjust_attr_string(0);
2000 use_fullwidth = TRUE;
2001 wide_adjust_attr_string(0);
2004 wide_adjust_attr_string(-1);
2007 wide_adjust_attr_string(1);
2013 error = cycle_color_attr(ch, fg, bg, tx);
2022 x_attr_test(bool recur GCC_UNUSED)
2023 /* test text attributes using wide-character calls */
2026 int skip = get_xmc();
2027 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2028 NCURSES_COLOR_T bg = COLOR_BLACK;
2029 NCURSES_COLOR_T tx = -1;
2031 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2032 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2033 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2038 for (j = 0; j < my_size; ++j) {
2039 my_wins[j] = subwin(stdscr,
2041 2 + (int) (2 * j), COL_ATTRSTRING);
2042 scrollok(my_wins[j], FALSE);
2048 n = skip; /* make it easy */
2050 wide_init_attr_string();
2054 NCURSES_PAIRS_T pair = 0;
2055 NCURSES_PAIRS_T extras = 0;
2058 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2061 if (init_pair(pair, fg, bg) == ERR) {
2068 if (init_pair(extras, tx, bg) == ERR) {
2073 set_wide_background(pair);
2076 box_set(stdscr, 0, 0);
2077 MvAddStr(0, 20, "Character attribute test display");
2079 for (j = 0; j < my_size; ++j) {
2080 row = wide_show_attr(my_wins[j], row, n, (j == k),
2088 MvPrintw(row, COLS_PRE_ATTRS,
2089 "This terminal does %shave the magic-cookie glitch",
2090 get_xmc() > -1 ? "" : "not ");
2091 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2092 show_color_attr(fg, bg, tx);
2093 printw(" ACS (%d)", ac != 0);
2096 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2098 set_wide_background(0);
2103 Cannot("does not support extended video attributes.");
2109 /****************************************************************************
2111 * Color support tests
2113 ****************************************************************************/
2115 static NCURSES_CONST char *the_color_names[] =
2136 show_color_name(int y, int x, int color, bool wide, int zoom)
2138 if (move(y, x) != ERR) {
2143 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2147 if ((int) strlen(temp) >= width) {
2149 while ((1 << pwr2) < color)
2151 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2152 width > 4 ? "2^%d" : "^%d", pwr2);
2154 } else if (color >= 8) {
2155 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2157 } else if (color < 0) {
2158 _nc_STRCPY(temp, "default", sizeof(temp));
2160 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2161 "%.*s", 16, the_color_names[color]);
2163 printw("%-*.*s", width, width, temp);
2168 color_legend(WINDOW *helpwin, bool wide)
2173 MvWPrintw(helpwin, row++, col,
2176 MvWPrintw(helpwin, row++, col,
2177 "Use up/down arrow to scroll through the display if it is");
2178 MvWPrintw(helpwin, row++, col,
2179 "longer than one screen. Control/N and Control/P can be used");
2180 MvWPrintw(helpwin, row++, col,
2181 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2182 MvWPrintw(helpwin, row++, col,
2183 "full screen; control/B and control/F can be used here.");
2185 MvWPrintw(helpwin, row++, col,
2187 MvWPrintw(helpwin, row++, col,
2188 " a/A toggle altcharset off/on");
2189 MvWPrintw(helpwin, row++, col,
2190 " b/B toggle bold off/on");
2192 MvWPrintw(helpwin, row++, col,
2193 " c/C cycle used-colors through 8,16,...,COLORS");
2195 MvWPrintw(helpwin, row++, col,
2196 " n/N toggle text/number on/off");
2197 MvWPrintw(helpwin, row++, col,
2198 " r/R toggle reverse on/off");
2199 MvWPrintw(helpwin, row++, col,
2200 " w/W switch width between 4/8 columns");
2201 MvWPrintw(helpwin, row++, col,
2202 " z/Z zoom out (or in)");
2203 #if USE_WIDEC_SUPPORT
2205 MvWPrintw(helpwin, row++, col,
2206 "Wide characters:");
2207 MvWPrintw(helpwin, row, col,
2208 " x/X toggle text between ASCII and wide-character");
2215 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2218 color_cycle(int current, int step)
2220 int result = current;
2226 if ((result * 2) > COLORS) {
2229 while ((result * 2) < current) {
2235 if (current >= COLORS) {
2240 if (result > COLORS)
2246 /* generate a color test pattern */
2248 color_test(bool recur GCC_UNUSED)
2253 int grid_top = top + 3;
2254 int page_size = (LINES - grid_top);
2256 int colors_max = COLORS;
2263 bool opt_acsc = FALSE;
2264 bool opt_bold = FALSE;
2265 bool opt_revs = FALSE;
2266 bool opt_nums = FALSE;
2267 bool opt_wide = FALSE;
2272 Cannot("does not support color.");
2276 numbered = typeCalloc(char, COLS + 1);
2277 done = ((COLS < 16) || (numbered == 0));
2280 * Because the number of colors is usually a power of two, we also use
2281 * a power of two for the number of colors shown per line (to be tidy).
2283 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2288 int zoom_size = (1 << opt_zoom);
2289 int colors_max1 = colors_max / zoom_size;
2290 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2292 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2293 if (colors_max2 <= COLOR_PAIRS) {
2294 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2295 if (pairs_max > limit)
2298 if (pairs_max > COLOR_PAIRS)
2299 pairs_max = COLOR_PAIRS;
2300 if (pairs_max < colors_max1)
2301 pairs_max = colors_max1;
2303 /* this assumes an 80-column line */
2307 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2311 per_row = (col_limit / width);
2313 per_row -= MinColors;
2315 row_limit = (pairs_max + per_row - 1) / per_row;
2318 (void) printw("There are %d color pairs and %d colors",
2320 if (colors_max1 != COLORS)
2321 (void) printw(" (using %d colors)", colors_max1);
2323 (void) addstr(" besides 'default'");
2325 (void) printw(" zoom:%d", opt_zoom);
2328 MvPrintw(top + 1, 0,
2329 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2332 opt_bold ? "on" : "off");
2334 /* show color names/numbers across the top */
2335 for (i = 0; i < per_row; i++) {
2336 show_color_name(top + 2,
2338 (int) i * zoom_size + MinColors,
2343 /* show a grid of colors, with color names/ numbers on the left */
2344 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2345 int row = grid_top + (i / per_row) - base_row;
2346 int col = (i % per_row + 1) * width;
2347 NCURSES_PAIRS_T pair = i;
2349 if ((i / per_row) > row_limit)
2352 #define InxToFG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) % (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2353 #define InxToBG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) / (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2354 if (row >= 0 && move(row, col) != ERR) {
2355 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) InxToFG(i);
2356 NCURSES_COLOR_T bg = (NCURSES_COLOR_T) InxToBG(i);
2358 init_pair(pair, fg, bg);
2359 attron(COLOR_PAIR(pair));
2361 attron(A_ALTCHARSET);
2368 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2372 printw("%-*.*s", width, width, hello);
2373 (void) attrset(A_NORMAL);
2375 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2376 show_color_name(row, 0,
2387 switch (wGetchar(stdscr)) {
2401 colors_max = color_cycle(colors_max, -1);
2404 colors_max = color_cycle(colors_max, 1);
2422 set_color_test(opt_wide, FALSE);
2425 set_color_test(opt_wide, TRUE);
2428 if (opt_zoom <= 0) {
2436 if ((1 << opt_zoom) >= colors_max) {
2445 if (base_row <= 0) {
2453 if (base_row + page_size >= row_limit) {
2462 if (base_row <= 0) {
2465 base_row -= (page_size - 1);
2473 if (base_row + page_size >= row_limit) {
2476 base_row += page_size - 1;
2477 if (base_row + page_size >= row_limit) {
2478 base_row = row_limit - page_size - 1;
2483 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2485 color_legend(helpwin, FALSE);
2503 #if USE_WIDEC_SUPPORT
2505 #if USE_EXTENDED_COLOR
2506 #define InitExtendedPair(p,f,g) init_extended_pair((p),(f),(g))
2507 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), &(p))
2508 #define EXTENDED_PAIRS_T int
2510 #define InitExtendedPair(p,f,g) init_pair((NCURSES_PAIRS_T) (p),(NCURSES_COLOR_T)(f),(NCURSES_COLOR_T)(g))
2511 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), NULL)
2512 #define EXTENDED_PAIRS_T NCURSES_PAIRS_T
2515 /* generate a color test pattern */
2517 x_color_test(bool recur GCC_UNUSED)
2522 int grid_top = top + 3;
2523 int page_size = (LINES - grid_top);
2525 int colors_max = COLORS;
2532 bool opt_acsc = FALSE;
2533 bool opt_bold = FALSE;
2534 bool opt_revs = FALSE;
2535 bool opt_wide = FALSE;
2536 bool opt_nums = FALSE;
2537 bool opt_xchr = FALSE;
2539 wchar_t *buffer = 0;
2543 Cannot("does not support color.");
2546 numbered = typeCalloc(char, COLS + 1);
2547 buffer = typeCalloc(wchar_t, COLS + 1);
2548 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2551 * Because the number of colors is usually a power of two, we also use
2552 * a power of two for the number of colors shown per line (to be tidy).
2554 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2559 int zoom_size = (1 << opt_zoom);
2560 int colors_max1 = colors_max / zoom_size;
2561 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2563 pairs_max = ((unsigned) (-1)) / 2;
2564 if (colors_max2 <= COLOR_PAIRS) {
2565 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2566 if (pairs_max > limit)
2569 if (pairs_max > COLOR_PAIRS)
2570 pairs_max = COLOR_PAIRS;
2571 if (pairs_max < colors_max1)
2572 pairs_max = colors_max1;
2577 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2581 per_row = (col_limit / width);
2583 per_row -= MinColors;
2586 make_fullwidth_text(buffer, hello);
2590 make_narrow_text(buffer, hello);
2593 row_limit = (pairs_max + per_row - 1) / per_row;
2596 (void) printw("There are %d color pairs and %d colors",
2598 if (colors_max1 != COLORS)
2599 (void) printw(" (using %d colors)", colors_max1);
2601 (void) addstr(" besides 'default'");
2603 (void) printw(" zoom:%d", opt_zoom);
2606 MvPrintw(top + 1, 0,
2607 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2610 opt_bold ? "on" : "off");
2612 /* show color names/numbers across the top */
2613 for (i = 0; i < per_row; i++) {
2614 show_color_name(top + 2,
2615 ((int) i + 1) * width,
2616 (int) i * zoom_size + MinColors,
2621 /* show a grid of colors, with color names/ numbers on the left */
2622 for (i = (base_row * per_row); i < pairs_max; i++) {
2623 int row = grid_top + ((int) i / per_row) - base_row;
2624 int col = ((int) i % per_row + 1) * width;
2627 if ((i / per_row) > row_limit)
2630 if (row >= 0 && move(row, col) != ERR) {
2631 InitExtendedPair(pair, InxToFG(i), InxToBG(i));
2632 (void) ExtendedColorSet(pair);
2634 attr_on(WA_ALTCHARSET, NULL);
2636 attr_on(WA_BOLD, NULL);
2638 attr_on(WA_REVERSE, NULL);
2641 _nc_SPRINTF(numbered,
2642 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2643 "{%02X}", (unsigned) i);
2645 make_fullwidth_text(buffer, numbered);
2647 make_narrow_text(buffer, numbered);
2650 addnwstr(buffer, width);
2651 (void) attr_set(A_NORMAL, 0, NULL);
2653 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2654 show_color_name(row, 0,
2665 switch (wGetchar(stdscr)) {
2679 colors_max = color_cycle(colors_max, -1);
2682 colors_max = color_cycle(colors_max, 1);
2700 set_color_test(opt_wide, FALSE);
2703 set_color_test(opt_wide, TRUE);
2712 if (opt_zoom <= 0) {
2720 if ((1 << opt_zoom) >= colors_max) {
2729 if (base_row <= 0) {
2737 if (base_row + page_size >= row_limit) {
2746 if (base_row <= 0) {
2749 base_row -= (page_size - 1);
2757 if (base_row + page_size >= row_limit) {
2760 base_row += page_size - 1;
2761 if (base_row + page_size >= row_limit) {
2762 base_row = row_limit - page_size - 1;
2767 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2769 color_legend(helpwin, TRUE);
2787 #endif /* USE_WIDEC_SUPPORT */
2789 #if HAVE_COLOR_CONTENT
2791 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2793 NCURSES_COLOR_T red, green, blue;
2795 color_content(current, &red, &green, &blue);
2799 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2802 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2805 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2809 if (init_color(current, red, green, blue) == ERR)
2814 reset_all_colors(void)
2818 for (c = 0; c < COLORS; ++c)
2821 all_colors[c].green,
2822 all_colors[c].blue);
2825 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2826 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2827 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2830 init_all_colors(bool xterm_colors, char *palette_file)
2833 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2835 failed("all_colors");
2836 for (cp = 0; cp < MaxColors; ++cp) {
2838 &all_colors[cp].red,
2839 &all_colors[cp].green,
2840 &all_colors[cp].blue);
2842 /* xterm and compatible terminals can read results of an OSC string
2843 * asking for the current color palette.
2847 char result[BUFSIZ];
2849 unsigned check_r, check_g, check_b;
2854 for (n = 0; n < MaxColors; ++n) {
2857 fprintf(stderr, "\033]4;%d;?\007", n);
2858 got = (int) read(0, result, sizeof(result) - 1);
2862 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2868 all_colors[n].red = DecodeRGB(check_r);
2869 all_colors[n].green = DecodeRGB(check_g);
2870 all_colors[n].blue = DecodeRGB(check_b);
2877 if (palette_file != 0) {
2878 FILE *fp = fopen(palette_file, "r");
2880 char buffer[BUFSIZ];
2881 int red, green, blue;
2884 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2885 if (sscanf(buffer, "scale:%d", &c) == 1) {
2887 } else if (sscanf(buffer, "%d:%d %d %d",
2896 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2897 all_colors[c].red = Scaled(red);
2898 all_colors[c].green = Scaled(green);
2899 all_colors[c].blue = Scaled(blue);
2907 #define scaled_rgb(n) ((255 * (n)) / 1000)
2910 color_edit(bool recur GCC_UNUSED)
2911 /* display the color test pattern, without trying to edit colors */
2915 int this_c, value, field;
2921 Cannot("does not support color.");
2923 } else if (!can_change_color()) {
2924 Cannot("has hardwired color values.");
2937 page_size = (LINES - 6);
2940 for (i = 0; i < MaxColors; i++)
2941 init_pair((NCURSES_PAIRS_T) i,
2942 (NCURSES_COLOR_T) COLOR_WHITE,
2943 (NCURSES_COLOR_T) i);
2945 MvPrintw(LINES - 2, 0, "Number: %d", value);
2948 NCURSES_COLOR_T red, green, blue;
2951 MvAddStr(0, 20, "Color RGB Value Editing");
2954 for (i = (NCURSES_COLOR_T) top_color;
2955 (i - top_color < page_size)
2956 && (i < MaxColors); i++) {
2959 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2960 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2961 (i == current ? '>' : ' '),
2962 (i < (int) SIZEOF(the_color_names)
2963 ? the_color_names[i] : numeric));
2964 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2966 (void) attrset(A_NORMAL);
2968 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2970 if (current == i && field == 0)
2972 printw("%04d", (int) red);
2973 if (current == i && field == 0)
2974 (void) attrset(A_NORMAL);
2976 if (current == i && field == 1)
2978 printw("%04d", (int) green);
2979 if (current == i && field == 1)
2980 (void) attrset(A_NORMAL);
2982 if (current == i && field == 2)
2984 printw("%04d", (int) blue);
2985 if (current == i && field == 2)
2986 (void) attrset(A_NORMAL);
2987 (void) attrset(A_NORMAL);
2988 printw(" ( %3d %3d %3d )",
2989 (int) scaled_rgb(red),
2990 (int) scaled_rgb(green),
2991 (int) scaled_rgb(blue));
2994 MvAddStr(LINES - 3, 0,
2995 "Use up/down to select a color, left/right to change fields.");
2996 MvAddStr(LINES - 2, 0,
2997 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2999 move(2 + current - top_color, 0);
3003 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
3025 current -= (page_size - 1);
3032 if (current < (MaxColors - 1))
3033 current += (page_size - 1);
3040 current = (current == 0 ? (MaxColors - 1) : current - 1);
3045 current = (current == (MaxColors - 1) ? 0 : current + 1);
3050 field = (field == 2 ? 0 : field + 1);
3055 field = (field == 0 ? 2 : field - 1);
3068 value = value * 10 + (this_c - '0');
3072 change_color((NCURSES_PAIRS_T) current, field, value, 1);
3076 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
3080 change_color((NCURSES_PAIRS_T) current, field, value, 0);
3085 P(" RGB Value Editing Help");
3087 P("You are in the RGB value editor. Use the arrow keys to select one of");
3088 P("the fields in one of the RGB triples of the current colors; the one");
3089 P("currently selected will be reverse-video highlighted.");
3091 P("To change a field, enter the digits of the new value; they are echoed");
3092 P("as entered. Finish by typing `='. The change will take effect instantly.");
3093 P("To increment or decrement a value, use the same procedure, but finish");
3094 P("with a `+' or `-'.");
3096 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3098 P("Press 'm' to invoke the top-level menu with the current color settings.");
3099 P("To quit, do ESC");
3108 for (i = 0; i < MaxColors; i++)
3109 init_pair((NCURSES_PAIRS_T) i,
3110 (NCURSES_COLOR_T) COLOR_WHITE,
3111 (NCURSES_COLOR_T) i);
3125 if (current >= MaxColors)
3126 current = MaxColors - 1;
3127 if (current < top_color)
3128 top_color = current;
3129 if (current - top_color >= page_size)
3130 top_color = current - (page_size - 1);
3132 MvPrintw(LINES - 1, 0, "Number: %d", value);
3135 (!isQuit(this_c, TRUE));
3140 * ncurses does not reset each color individually when calling endwin().
3147 #endif /* HAVE_COLOR_CONTENT */
3149 /****************************************************************************
3151 * Alternate character-set stuff
3153 ****************************************************************************/
3155 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3161 if ((*at_code += 1) >= limit)
3166 *at_code = limit - 1;
3175 *attr = list[*at_code].attr;
3179 #if USE_WIDEC_SUPPORT
3181 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3187 if ((*at_code += 1) >= limit)
3192 *at_code = limit - 1;
3201 *attr = list[*at_code].attr;
3207 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3209 bool result = FALSE;
3219 if ((*fg += 1) >= COLORS)
3227 if ((*bg += 1) >= COLORS)
3235 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3238 if (init_pair(*pair,
3239 (NCURSES_COLOR_T) *fg,
3240 (NCURSES_COLOR_T) *bg) == ERR) {
3249 /****************************************************************************
3251 * Soft-key label test
3253 ****************************************************************************/
3258 #define SLK_WORK (SLK_HELP + 3)
3263 static const char *table[] =
3265 "Available commands are:"
3267 ,"^L -- repaint this message and activate soft keys"
3268 ,"a/d -- activate/disable soft keys"
3269 ,"c -- set centered format for labels"
3270 ,"l -- set left-justified format for labels"
3271 ,"r -- set right-justified format for labels"
3272 ,"[12345678] -- set label; labels are numbered 1 through 8"
3273 ,"e -- erase stdscr (should not erase labels)"
3274 ,"s -- test scrolling of shortened screen"
3275 ,"v/V -- cycle through video attributes"
3277 ,"F/f/B/b -- cycle through foreground/background colors"
3279 ,"ESC -- return to main menu"
3281 ,"Note: if activating the soft keys causes your terminal to scroll up"
3282 ,"one line, your terminal auto-scrolls when anything is written to the"
3283 ,"last screen position. The ncurses code does not yet handle this"
3289 for (j = 0; j < SIZEOF(table); ++j) {
3297 call_slk_color(int fg, int bg)
3299 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3301 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3310 slk_test(bool recur GCC_UNUSED)
3311 /* exercise the soft keys */
3316 chtype attr = A_NORMAL;
3317 unsigned at_code = 0;
3319 int fg = COLOR_BLACK;
3320 int bg = COLOR_WHITE;
3321 NCURSES_PAIRS_T pair = 0;
3323 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3324 unsigned my_size = init_attr_list(my_list, termattrs());
3329 call_slk_color(fg, bg);
3339 MvAddStr(0, 20, "Soft Key Exerciser");
3354 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3355 while ((c = Getchar()) != 'Q' && (c != ERR))
3383 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3384 _nc_STRCPY(buf, "", sizeof(buf));
3385 if ((s = slk_label(c - '0')) != 0) {
3386 _nc_STRNCPY(buf, s, (size_t) 8);
3388 wGetstring(stdscr, buf, 8);
3389 slk_set((c - '0'), buf, fmt);
3398 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3400 wnoutrefresh(stdscr);
3405 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3412 if (cycle_colors(c, &fg, &bg, &pair)) {
3414 call_slk_color(fg, bg);
3424 } while (!isQuit(c = Getchar(), TRUE));
3433 #if USE_WIDEC_SUPPORT
3436 x_slk_test(bool recur GCC_UNUSED)
3437 /* exercise the soft keys */
3440 wchar_t buf[SLKLEN + 1];
3442 attr_t attr = WA_NORMAL;
3443 unsigned at_code = 0;
3444 int fg = COLOR_BLACK;
3445 int bg = COLOR_WHITE;
3446 NCURSES_PAIRS_T pair = 0;
3447 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3448 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3452 call_slk_color(fg, bg);
3459 attr_on(WA_BOLD, NULL);
3460 MvAddStr(0, 20, "Soft Key Exerciser");
3461 attr_off(WA_BOLD, NULL);
3475 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3476 while ((c = Getchar()) != 'Q' && (c != ERR))
3504 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3506 if ((s = slk_label(c - '0')) != 0) {
3507 char *temp = strdup(s);
3508 size_t used = strlen(temp);
3509 size_t want = SLKLEN;
3510 #ifndef state_unused
3515 while (want > 0 && used != 0) {
3517 const char *base = s;
3519 reset_mbytes(state);
3520 test = count_mbytes(base, 0, &state);
3521 if (test == (size_t) -1) {
3523 } else if (test > want) {
3526 reset_mbytes(state);
3527 trans_mbytes(buf, base, want, &state);
3533 wGet_wstring(stdscr, buf, SLKLEN);
3534 slk_wset((c - '0'), buf, fmt);
3545 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3546 call_slk_color(fg, bg);
3551 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3552 call_slk_color(fg, bg);
3555 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3557 wnoutrefresh(stdscr);
3561 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3562 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3568 if (cycle_colors(c, &fg, &bg, &pair)) {
3570 call_slk_color(fg, bg);
3580 } while (!isQuit(c = Getchar(), TRUE));
3589 #endif /* SLK_INIT */
3592 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3595 unsigned last = 255;
3601 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3606 for (code = first; code <= last; ++code) {
3607 int row = (int) (2 + (code / 16));
3608 int col = (int) (5 * (code % 16));
3609 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3610 for (count = 1; count < repeat; ++count) {
3611 AddCh(colored_chtype(code, attr, pair));
3618 * Show a slice of 32 characters, allowing those to be repeated up to the
3621 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3622 * terminal to perform functions. The remaining codes can be graphic.
3625 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3628 unsigned first = (unsigned) base;
3629 unsigned last = first + (unsigned) pagesize - 2;
3630 bool C1 = (first == 128);
3635 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3636 C1 ? "C1" : "GR", first, last);
3640 for (code = first; code <= last; code++) {
3642 int row = 2 + ((int) (code - first) % (pagesize / 2));
3643 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3645 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3646 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3650 nodelay(stdscr, TRUE);
3651 echochar(colored_chtype(code, attr, pair));
3653 /* (yes, this _is_ crude) */
3654 while ((reply = Getchar()) != ERR) {
3655 AddCh(UChar(reply));
3658 nodelay(stdscr, FALSE);
3660 } while (--count > 0);
3667 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3673 MvPrintw(0, 20, "Display of PC Character Codes");
3677 for (code = 0; code < 16; ++code) {
3678 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3680 for (code = 0; code < 256; code++) {
3682 int row = 3 + (int) (code / 16) + (code >= 128);
3683 int col = 8 + (int) (code % 16) * PC_COLS;
3684 if ((code % 16) == 0)
3685 MvPrintw(row, 0, "0x%02x:", code);
3696 * Skip the ones that do not work.
3700 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3703 } while (--count > 0);
3708 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3712 attr |= (attr_t) COLOR_PAIR(pair);
3716 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3721 colored_chtype(ACS_VLINE, attr, pair),
3722 colored_chtype(ACS_VLINE, attr, pair),
3723 colored_chtype(ACS_HLINE, attr, pair),
3724 colored_chtype(ACS_HLINE, attr, pair),
3725 colored_chtype(ACS_ULCORNER, attr, pair),
3726 colored_chtype(ACS_URCORNER, attr, pair),
3727 colored_chtype(ACS_LLCORNER, attr, pair),
3728 colored_chtype(ACS_LRCORNER, attr, pair));
3729 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3730 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3731 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3732 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3733 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3734 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3735 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3741 show_1_acs(int n, int repeat, const char *name, chtype code)
3743 const int height = 16;
3744 int row = 2 + (n % height);
3745 int col = (n / height) * COLS / 2;
3747 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3750 } while (--repeat > 0);
3755 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3756 /* display the ACS character set */
3760 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3764 MvAddStr(0, 20, "Display of the ACS Character Set");
3768 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3769 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3770 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3771 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3773 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3774 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3775 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3776 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3778 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3779 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3782 * HPUX's ACS definitions are broken here. Just give up.
3784 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3785 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3786 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3787 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3788 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3790 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3791 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3792 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3793 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3794 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3795 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3796 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3797 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3798 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3800 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3801 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3802 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3804 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3805 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3806 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3807 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3808 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3809 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3815 acs_test(bool recur GCC_UNUSED)
3819 char *term = getenv("TERM");
3820 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3823 chtype attr = A_NORMAL;
3826 int fg = COLOR_BLACK;
3827 int bg = COLOR_BLACK;
3828 unsigned at_code = 0;
3829 NCURSES_PAIRS_T pair = 0;
3830 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3831 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3832 unsigned my_size = init_attr_list(my_list, termattrs());
3840 ToggleAcs(last_show_acs, show_acs_chars);
3844 ToggleAcs(last_show_acs, show_pc_chars);
3849 if (pagesize == 32) {
3856 ToggleAcs(last_show_acs, show_box_chars);
3882 if (repeat < (COLS / 4))
3890 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3891 || cycle_colors(c, &fg, &bg, &pair)) {
3898 if (pagesize != 32) {
3899 show_256_chars(repeat, attr, pair);
3900 } else if (last_show_acs != 0) {
3901 last_show_acs(repeat, attr, pair);
3903 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3906 MvPrintw(LINES - 3, 0,
3907 "Note: ANSI terminals may not display C1 characters.");
3908 MvPrintw(LINES - 2, 0,
3909 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3912 MvPrintw(LINES - 1, 0,
3913 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3914 my_list[at_code].name,
3917 MvPrintw(LINES - 1, 0,
3918 "v/V cycles through video attributes (%s).",
3919 my_list[at_code].name);
3922 } while (!isQuit(c = Getchar(), TRUE));
3930 #if USE_WIDEC_SUPPORT
3932 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3938 TEST_CCHAR(src, count, {
3939 attr |= (test_attrs & A_ALTCHARSET);
3940 setcchar(dst, test_wch, attr, pair, NULL);
3949 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3950 * display. If there are no repeats, we could normally display 16 lines of 64
3951 * characters (1024 total). However, taking repeats and double-width cells
3952 * into account, use 256 characters for the page.
3955 show_paged_widechars(unsigned base,
3960 NCURSES_PAIRS_T pair)
3962 unsigned first = base * pagesize;
3963 unsigned last = first + pagesize - 1;
3971 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3974 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
3975 int row = (2 + (int) (code - (wchar_t) first) / per_line);
3976 int col = 5 * ((int) code % per_line);
3979 memset(&codes, 0, sizeof(codes));
3981 setcchar(&temp, codes, attr, pair, 0);
3983 if (wcwidth(code) == 0 && code != 0) {
3984 AddCh((chtype) space |
3985 (A_REVERSE ^ attr) |
3986 (attr_t) COLOR_PAIR(pair));
3989 for (count = 1; count < repeat; ++count) {
3996 show_upper_widechars(unsigned first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
4000 unsigned last = first + 31;
4004 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
4007 for (code = (wchar_t) first; code <= (wchar_t) last; code++) {
4008 int row = 2 + ((int) (code - (wchar_t) first) % 16);
4009 int col = ((int) (code - (wchar_t) first) / 16) * COLS / 2;
4014 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
4015 "%3ld (0x%lx)", (long) code, (long) code);
4016 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
4018 memset(&codes, 0, sizeof(codes));
4020 setcchar(&temp, codes, attr, pair, 0);
4026 * Give non-spacing characters something to combine with. If we
4027 * don't, they'll bunch up in a heap on the space after the ":".
4028 * Mark them with reverse-video to make them simpler to find on
4031 if (wcwidth(code) == 0) {
4032 AddCh((chtype) space |
4033 (A_REVERSE ^ attr) |
4034 (attr_t) COLOR_PAIR(pair));
4037 * This uses echo_wchar(), for comparison with the normal 'f'
4038 * test (and to make a test-case for echo_wchar()). The screen
4039 * may flicker because the erase() at the top of the function
4040 * is met by the builtin refresh() in echo_wchar().
4044 * The repeat-count may make text wrap - avoid that.
4046 getyx(stdscr, y, x);
4048 if (x >= col + (COLS / 2) - 2)
4050 } while (--count > 0);
4055 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
4057 const int height = 16;
4058 int row = 2 + (n % height);
4059 int col = (n / height) * COLS / 2;
4061 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4062 while (--repeat >= 0) {
4068 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
4071 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4072 /* display the wide-ACS character set */
4078 /*#define BOTH2(name) #name, &(name) */
4079 #define BOTH2(name) #name, MERGE_ATTR(name)
4083 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4087 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
4088 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
4089 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
4090 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
4092 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
4093 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
4094 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
4095 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
4097 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
4098 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
4100 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4101 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4102 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4103 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4105 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4106 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4107 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4108 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4109 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4110 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4111 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4112 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4113 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4115 #ifdef CURSES_WACS_ARRAY
4116 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4117 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4118 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4120 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4121 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4122 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4123 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4124 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4125 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4131 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4132 /* display the wide-ACS character set */
4138 /*#define BOTH2(name) #name, &(name) */
4139 #define BOTH2(name) #name, MERGE_ATTR(name)
4143 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4147 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
4148 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
4149 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
4150 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
4152 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
4153 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
4154 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
4155 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
4157 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
4158 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
4160 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4161 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4162 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4163 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4165 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4166 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4167 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4168 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4169 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4170 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4171 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4172 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4173 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
4175 #ifdef CURSES_WACS_ARRAY
4176 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4177 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4178 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4180 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4181 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4182 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4183 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4184 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4185 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4192 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4193 /* display the wide-ACS character set */
4199 /*#define BOTH2(name) #name, &(name) */
4200 #define BOTH2(name) #name, MERGE_ATTR(name)
4204 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4208 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4209 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4210 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4211 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4213 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4214 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4215 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4216 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4218 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4219 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4221 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4222 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4223 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4224 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4226 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4227 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4228 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4229 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4230 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4231 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4232 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4233 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4234 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4236 #ifdef CURSES_WACS_ARRAY
4237 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4238 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4239 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4241 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4242 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4243 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4244 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4245 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4246 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4253 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4256 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4263 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4268 MERGE_ATTR(0, WACS_VLINE),
4269 MERGE_ATTR(1, WACS_VLINE),
4270 MERGE_ATTR(2, WACS_HLINE),
4271 MERGE_ATTR(3, WACS_HLINE),
4272 MERGE_ATTR(4, WACS_ULCORNER),
4273 MERGE_ATTR(5, WACS_URCORNER),
4274 MERGE_ATTR(6, WACS_LLCORNER),
4275 MERGE_ATTR(7, WACS_LRCORNER));
4277 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4278 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4279 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4280 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4281 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4282 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4283 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4291 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4293 const int height = 16;
4294 int row = 2 + (n % height);
4295 int col = (n / height) * COLS / 2;
4298 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4299 (void) attr_set(attr, pair, 0);
4300 _nc_STRNCPY(temp, code, 20);
4302 (void) attr_set(A_NORMAL, 0, 0);
4306 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4309 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4316 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4320 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4321 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4322 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4323 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4325 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4326 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4327 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4328 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4330 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4331 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4333 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4334 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4335 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4336 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4338 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4339 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4340 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4341 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4342 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4343 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4344 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4345 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4346 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4347 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4348 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4349 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4351 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4352 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4353 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4354 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4355 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4356 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4361 /* display the wide-ACS character set */
4363 x_acs_test(bool recur GCC_UNUSED)
4369 unsigned pagesize = 32;
4370 attr_t attr = WA_NORMAL;
4371 int fg = COLOR_BLACK;
4372 int bg = COLOR_BLACK;
4373 unsigned at_code = 0;
4374 NCURSES_PAIRS_T pair = 0;
4375 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4376 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
4377 unsigned my_size = init_w_attr_list(my_list, term_attrs());
4379 bool pending_code = FALSE;
4388 ToggleAcs(last_show_wacs, show_wacs_chars);
4392 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4397 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4401 if (pagesize == 32) {
4408 ToggleAcs(last_show_wacs, show_wbox_chars);
4411 ToggleAcs(last_show_wacs, show_utf8_chars);
4414 pending_code = !pending_code;
4416 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4417 } else if (at_page[0] != '\0') {
4418 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%x", digit);
4422 if (pending_code && isxdigit(c)) {
4423 size_t len = strlen(at_page);
4424 if (len && at_page[0] == '0') {
4425 memmove(at_page, at_page + 1, len--);
4427 if (len < sizeof(at_page) - 1) {
4428 at_page[len++] = (char) c;
4429 at_page[len] = '\0';
4431 } else if (pending_code
4432 && (c == '\b' || c == KEY_BACKSPACE || c == KEY_DC)) {
4433 size_t len = strlen(at_page);
4435 at_page[--len] = '\0';
4436 } else if (c < 256 && isdigit(c)) {
4437 digit = (unsigned) (c - '0');
4439 } else if (c == '+') {
4441 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x", digit);
4443 } else if (c == '-' && digit > 0) {
4445 _nc_SPRINTF(at_page, _nc_SLIMIT(sizeof(at_page)) "%02x",
4448 } else if (c == '>' &&