1 /****************************************************************************
2 * Copyright 2018-2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
29 /****************************************************************************
32 ncurses.c --- ncurses library exerciser
38 An interactive test module for the ncurses library.
41 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
42 Thomas E. Dickey (beginning revision 1.27 in 1996).
44 $Id: ncurses.c,v 1.525 2021/05/08 19:44:31 tom Exp $
46 ***************************************************************************/
48 #include <test.priv.h>
51 #undef mvwdelch /* HPUX 11.23 macro will not compile */
55 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
59 #include <sys/select.h>
75 #ifdef NCURSES_VERSION
77 #define NCURSES_CONST_PARAM const void
80 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
110 #ifdef CURSES_WACS_ARRAY
111 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
112 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
113 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
114 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
115 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
116 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
117 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
124 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
125 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
126 #define reset_wchars(state) init_mb(state)
127 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
128 #define count_wchars(src, len, state) wcstombs(0, src, len)
129 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
130 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
135 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
136 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
137 #define reset_mbytes(state) init_mb(state)
138 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
139 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
140 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
141 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
145 #define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real)
147 #define P(string) printw("%s\n", string)
149 #define BLANK ' ' /* this is the background character */
151 static int MaxColors; /* the actual number of colors we'll use */
152 static int MinColors; /* the minimum color code */
153 static bool UseColors; /* true if we use colors */
156 static int max_pairs; /* ...and the number of color pairs */
158 #if HAVE_COLOR_CONTENT
161 NCURSES_COLOR_T green;
162 NCURSES_COLOR_T blue;
165 static RGB_DATA *all_colors;
168 static void main_menu(bool);
169 static GCC_NORETURN void failed(const char *s);
172 failed(const char *s)
176 ExitProgram(EXIT_FAILURE);
192 isQuit(int c, bool escape)
194 return ((c) == QUIT || (escape && ((c) == ESCAPE)));
196 #define case_QUIT QUIT: case ESCAPE
198 /* Common function to allow ^T to toggle trace-mode in the middle of a test
199 * so that trace-files can be made smaller.
202 wGetchar(WINDOW *win)
206 while ((c = wgetch(win)) == CTRL('T')) {
208 save_trace = _nc_tracing;
209 Trace(("TOGGLE-TRACING OFF"));
212 _nc_tracing = save_trace;
214 curses_trace(_nc_tracing);
216 Trace(("TOGGLE-TRACING ON"));
223 #define Getchar() wGetchar(stdscr)
226 /* replaces wgetnstr(), since we want to be able to edit values */
228 wGetstring(WINDOW *win, char *buffer, int limit)
235 (void) wattrset(win, A_REVERSE);
237 x = (int) strlen(buffer);
240 if (x > (int) strlen(buffer))
241 x = (int) strlen(buffer);
243 wprintw(win, "%-*s", limit, buffer);
244 wmove(win, y0, x0 + x);
245 switch (ch = wGetchar(win)) {
258 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
276 if (!isprint(ch) || ch >= KEY_MIN) {
278 } else if ((int) strlen(buffer) < limit) {
280 for (j = (int) strlen(buffer) + 1; j > x; --j) {
281 buffer[j] = buffer[j - 1];
283 buffer[x++] = (char) ch;
290 wattroff(win, A_REVERSE);
296 #if USE_WIDEC_SUPPORT
298 fullwidth_digit(int ch)
300 return (wchar_t) (ch + 0xff10 - '0');
304 make_fullwidth_text(wchar_t *target, const char *source)
307 while ((ch = *source++) != 0) {
308 *target++ = fullwidth_digit(ch);
314 make_narrow_text(wchar_t *target, const char *source)
317 while ((ch = *source++) != 0) {
318 *target++ = (wchar_t) ch;
325 make_fullwidth_digit(cchar_t *target, int digit)
329 source[0] = fullwidth_digit(digit + '0');
331 setcchar(target, source, A_NORMAL, 0, 0);
336 wGet_wchar(WINDOW *win, wint_t *result)
340 while ((c = wget_wch(win, result)) == CTRL('T')) {
342 save_trace = _nc_tracing;
343 Trace(("TOGGLE-TRACING OFF"));
346 _nc_tracing = save_trace;
348 curses_trace(_nc_tracing);
350 Trace(("TOGGLE-TRACING ON"));
353 c = wget_wch(win, result);
357 #define Get_wchar(result) wGet_wchar(stdscr, result)
359 /* replaces wgetn_wstr(), since we want to be able to edit values */
362 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
371 (void) wattrset(win, A_REVERSE);
373 x = (int) wcslen(buffer);
375 if (x > (int) wcslen(buffer))
376 x = (int) wcslen(buffer);
378 /* clear the "window' */
380 wprintw(win, "%*s", limit, " ");
382 /* write the existing buffer contents */
384 waddnwstr(win, buffer, limit);
386 /* positions the cursor past character 'x' */
388 waddnwstr(win, buffer, x);
390 switch (wGet_wchar(win, &ch)) {
430 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
450 } else if ((int) wcslen(buffer) < limit) {
452 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
453 buffer[j] = buffer[j - 1];
455 buffer[x++] = (wchar_t) ch;
462 wattroff(win, A_REVERSE);
466 #endif /* USE_SOFTKEYS */
468 #endif /* USE_WIDEC_SUPPORT */
474 addstr("Press any key to continue... ");
479 Cannot(const char *what)
481 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
487 ShellOut(bool message)
490 addstr("Shelling out...");
496 IGNORE_RC(system("sh"));
499 addstr("returned from shellout.\n");
503 #ifdef NCURSES_MOUSE_VERSION
505 * This function is the same as _tracemouse(), but we cannot count on that
506 * being available in the non-debug library.
509 mouse_decode(MEVENT const *ep)
511 static char buf[80 + (5 * 10) + (32 * 15)];
513 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
514 "id %2d at (%2d, %2d, %d) state %4lx = {",
515 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
518 if ((ep->bstate & m)==m) { \
519 _nc_STRCAT(buf, s, sizeof(buf)); \
520 _nc_STRCAT(buf, ", ", sizeof(buf)); \
523 SHOW(BUTTON1_RELEASED, "release-1");
524 SHOW(BUTTON1_PRESSED, "press-1");
525 SHOW(BUTTON1_CLICKED, "click-1");
526 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
527 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
528 #if NCURSES_MOUSE_VERSION == 1
529 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
532 SHOW(BUTTON2_RELEASED, "release-2");
533 SHOW(BUTTON2_PRESSED, "press-2");
534 SHOW(BUTTON2_CLICKED, "click-2");
535 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
536 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
537 #if NCURSES_MOUSE_VERSION == 1
538 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
541 SHOW(BUTTON3_RELEASED, "release-3");
542 SHOW(BUTTON3_PRESSED, "press-3");
543 SHOW(BUTTON3_CLICKED, "click-3");
544 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
545 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
546 #if NCURSES_MOUSE_VERSION == 1
547 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
550 SHOW(BUTTON4_RELEASED, "release-4");
551 SHOW(BUTTON4_PRESSED, "press-4");
552 SHOW(BUTTON4_CLICKED, "click-4");
553 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
554 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
555 #if NCURSES_MOUSE_VERSION == 1
556 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
559 #if NCURSES_MOUSE_VERSION == 2
560 SHOW(BUTTON5_RELEASED, "release-5");
561 SHOW(BUTTON5_PRESSED, "press-5");
562 SHOW(BUTTON5_CLICKED, "click-5");
563 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
564 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
567 SHOW(BUTTON_CTRL, "ctrl");
568 SHOW(BUTTON_SHIFT, "shift");
569 SHOW(BUTTON_ALT, "alt");
570 SHOW(ALL_MOUSE_EVENTS, "all-events");
571 SHOW(REPORT_MOUSE_POSITION, "position");
575 if (buf[strlen(buf) - 1] == ' ')
576 buf[strlen(buf) - 2] = '\0';
577 _nc_STRCAT(buf, "}", sizeof(buf));
582 show_mouse(WINDOW *win)
589 outside = !wenclose(win, event.y, event.x);
592 (void) wstandout(win);
593 waddstr(win, "KEY_MOUSE");
594 (void) wstandend(win);
596 waddstr(win, "KEY_MOUSE");
598 wprintw(win, ", %s", mouse_decode(&event));
603 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
608 wmove(win, event.y, event.x);
616 #endif /* NCURSES_MOUSE_VERSION */
618 /****************************************************************************
620 * Character input test
622 ****************************************************************************/
624 #define NUM_GETCH_FLAGS 256
625 typedef bool GetchFlags[NUM_GETCH_FLAGS];
628 setup_getch(WINDOW *win, GetchFlags flags)
630 keypad(win, flags['k']); /* should be redundant, but for testing */
631 meta(win, flags['m']); /* force this to a known state */
639 init_getch(WINDOW *win, GetchFlags flags, int delay)
641 memset(flags, FALSE, NUM_GETCH_FLAGS);
642 flags[UChar('k')] = (win == stdscr);
643 flags[UChar('m')] = TRUE;
644 flags[UChar('t')] = (delay != 0);
646 setup_getch(win, flags);
650 blocking_getch(GetchFlags flags, int delay)
652 return ((delay < 0) && flags['t']);
655 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
658 wgetch_help(WINDOW *win, GetchFlags flags)
660 static const char *help[] =
662 "e -- toggle echo mode"
663 ,"g -- triggers a getstr test"
664 ,"k -- toggle keypad/literal mode"
665 ,"m -- toggle meta (7-bit/8-bit) mode"
668 ,"t -- toggle timeout"
669 ,"w -- create a new window"
671 ,"z -- suspend this process"
675 unsigned chk = ((SIZEOF(help) + 1) / 2);
680 printw("Type any key to see its %s value. Also:\n",
681 flags['k'] ? "keypad" : "literal");
682 for (n = 0; n < SIZEOF(help); ++n) {
683 const char *msg = help[n];
684 int row = 1 + (int) (n % chk);
685 int col = (n >= chk) ? COLS / 2 : 0;
686 int flg = ((strstr(msg, "toggle") != 0)
687 && (flags[UChar(*msg)] != FALSE));
688 if (*msg == '^' && ExitOnEscape())
689 msg = "^[,^q -- quit";
692 MvPrintw(row, col, "%s", msg);
703 wgetch_wrap(WINDOW *win, int first_y)
705 int last_y = getmaxy(win) - 1;
706 int y = getcury(win) + 1;
714 #if defined(KEY_RESIZE) && HAVE_WRESIZE
720 static WINSTACK *winstack = 0;
721 static unsigned len_winstack = 0;
734 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
736 unsigned need = (level + 1) * 2;
738 assert(level < (unsigned) COLS);
742 winstack = typeMalloc(WINSTACK, len_winstack);
743 } else if (need >= len_winstack) {
745 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
748 failed("remember_boxes");
749 winstack[level].text = txt_win;
750 winstack[level].frame = box_win;
753 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
757 /* this chunk is now done in resize_term() */
764 #define slk_repaint() /* nothing */
767 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
769 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
770 * Resize both and paint the box in the parent.
773 resize_boxes(unsigned level, WINDOW *win)
777 int high = LINES - base;
781 wnoutrefresh(stdscr);
785 for (n = 0; n < level; ++n) {
786 wresize(winstack[n].frame, high, wide);
787 wresize(winstack[n].text, high - 2, wide - 2);
790 werase(winstack[n].text);
791 box(winstack[n].frame, 0, 0);
792 wnoutrefresh(winstack[n].frame);
793 wprintw(winstack[n].text,
795 getmaxy(winstack[n].text),
796 getmaxx(winstack[n].text));
797 wnoutrefresh(winstack[n].text);
798 if (winstack[n].text == win)
803 #endif /* resize_boxes */
805 #define forget_boxes() /* nothing */
806 #define remember_boxes(level,text,frame) /* nothing */
810 * Return-code is OK/ERR or a keyname.
815 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
819 wgetch_test(unsigned level, WINDOW *win, int delay)
822 int first_y, first_x;
826 init_getch(win, flags, delay);
827 notimeout(win, FALSE);
828 wtimeout(win, delay);
829 getyx(win, first_y, first_x);
831 wgetch_help(win, flags);
832 wsetscrreg(win, first_y, getmaxy(win) - 1);
838 while ((c = wGetchar(win)) == ERR) {
840 if (blocking_getch(flags, delay)) {
841 (void) wprintw(win, "%05d: input error", incount);
844 (void) wprintw(win, "%05d: input timed out", incount);
846 wgetch_wrap(win, first_y);
848 if (c == ERR && blocking_getch(flags, delay)) {
850 wgetch_wrap(win, first_y);
851 } else if (isQuit(c, ExitOnEscape())) {
853 } else if (c == 'e') {
854 flags[UChar('e')] = !flags[UChar('e')];
855 setup_getch(win, flags);
856 wgetch_help(win, flags);
857 } else if (c == 'g') {
858 waddstr(win, "getstr test: ");
860 c = wgetnstr(win, buf, sizeof(buf) - 1);
862 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
863 (int) strlen(buf), buf,
866 wgetch_wrap(win, first_y);
867 } else if (c == 'k') {
868 flags[UChar('k')] = !flags[UChar('k')];
869 setup_getch(win, flags);
870 wgetch_help(win, flags);
871 } else if (c == 'm') {
872 flags[UChar('m')] = !flags[UChar('m')];
873 setup_getch(win, flags);
874 wgetch_help(win, flags);
875 } else if (c == 's') {
877 } else if (c == 't') {
878 notimeout(win, flags[UChar('t')]);
879 flags[UChar('t')] = !flags[UChar('t')];
880 wgetch_help(win, flags);
881 } else if (c == 'w') {
882 int high = getmaxy(win) - 1 - first_y + 1;
883 int wide = getmaxx(win) - first_x;
885 int new_y = first_y + getbegy(win);
886 int new_x = first_x + getbegx(win);
888 getyx(win, old_y, old_x);
889 if (high > 2 && wide > 2) {
890 WINDOW *wb = newwin(high, wide, new_y, new_x);
891 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
896 remember_boxes(level, wi, wb);
897 wgetch_test(level + 1, wi, delay);
901 wgetch_help(win, flags);
902 wmove(win, old_y, old_x);
908 } else if (c == 'z') {
909 kill(getpid(), SIGTSTP);
912 wprintw(win, "Key pressed: %04o ", c);
913 #ifdef NCURSES_MOUSE_VERSION
914 if (c == KEY_MOUSE) {
917 #endif /* NCURSES_MOUSE_VERSION */
919 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
920 if (c == KEY_RESIZE) {
921 resize_boxes(level, win);
924 (void) waddstr(win, keyname(c));
925 } else if (c >= 0x80) {
926 unsigned c2 = (unsigned) c;
927 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
928 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
932 (void) wprintw(win, "%c", UChar(c));
933 else if (c2 != UChar(c))
934 (void) wprintw(win, "M-%s", unctrl(c2));
936 (void) wprintw(win, "%s", unctrl(c2));
937 waddstr(win, " (high-half character)");
940 (void) wprintw(win, "%c (ASCII printable character)", c);
942 (void) wprintw(win, "%s (ASCII control character)",
945 wgetch_wrap(win, first_y);
952 init_getch(win, flags, delay);
956 begin_getch_test(void)
963 #ifdef NCURSES_MOUSE_VERSION
964 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
967 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
969 getnstr(buf, sizeof(buf) - 1);
973 if (isdigit(UChar(buf[0]))) {
974 delay = atoi(buf) * 100;
984 finish_getch_test(void)
986 #ifdef NCURSES_MOUSE_VERSION
987 mousemask(0, (mmask_t *) 0);
996 getch_test(bool recur GCC_UNUSED)
998 int delay = begin_getch_test();
1001 wgetch_test(0, stdscr, delay);
1003 finish_getch_test();
1008 #if USE_WIDEC_SUPPORT
1010 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1011 * Resize both and paint the box in the parent.
1013 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1015 resize_wide_boxes(unsigned level, WINDOW *win)
1019 int high = LINES - base;
1023 wnoutrefresh(stdscr);
1027 for (n = 0; n < level; ++n) {
1028 wresize(winstack[n].frame, high, wide);
1029 wresize(winstack[n].text, high - 2, wide - 2);
1032 werase(winstack[n].text);
1033 box_set(winstack[n].frame, 0, 0);
1034 wnoutrefresh(winstack[n].frame);
1035 wprintw(winstack[n].text,
1037 getmaxy(winstack[n].text),
1038 getmaxx(winstack[n].text));
1039 wnoutrefresh(winstack[n].text);
1040 if (winstack[n].text == win)
1045 #endif /* KEY_RESIZE */
1048 wcstos(const wchar_t *src)
1052 const wchar_t *tmp = src;
1053 #ifndef state_unused
1057 reset_wchars(state);
1058 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1059 unsigned have = (unsigned) need;
1060 if ((result = typeCalloc(char, have + 1)) != 0) {
1062 if (trans_wchars(result, tmp, have, &state) != have) {
1074 wget_wch_test(unsigned level, WINDOW *win, int delay)
1076 wchar_t wchar_buf[BUFSIZ];
1077 wint_t wint_buf[BUFSIZ];
1078 int first_y, first_x;
1084 init_getch(win, flags, delay);
1085 notimeout(win, FALSE);
1086 wtimeout(win, delay);
1087 getyx(win, first_y, first_x);
1089 wgetch_help(win, flags);
1090 wsetscrreg(win, first_y, getmaxy(win) - 1);
1091 scrollok(win, TRUE);
1096 while ((code = wGet_wchar(win, &c)) == ERR) {
1098 if (blocking_getch(flags, delay)) {
1099 (void) wprintw(win, "%05d: input error", incount);
1102 (void) wprintw(win, "%05d: input timed out", incount);
1104 wgetch_wrap(win, first_y);
1106 if (code == ERR && blocking_getch(flags, delay)) {
1107 wprintw(win, "ERR");
1108 wgetch_wrap(win, first_y);
1109 } else if (isQuit((int) c, ExitOnEscape())) {
1111 } else if (c == 'e') {
1112 flags[UChar('e')] = !flags[UChar('e')];
1113 setup_getch(win, flags);
1114 wgetch_help(win, flags);
1115 } else if (c == 'g') {
1116 waddstr(win, "getstr test: ");
1118 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1121 wprintw(win, "wgetn_wstr returns an error.");
1124 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1127 if ((temp = wcstos(wchar_buf)) != 0) {
1128 wprintw(win, "I saw %d characters:\n\t`%s'.",
1129 (int) wcslen(wchar_buf), temp);
1132 wprintw(win, "I saw %d characters (cannot convert).",
1133 (int) wcslen(wchar_buf));
1137 wgetch_wrap(win, first_y);
1138 } else if (c == 'k') {
1139 flags[UChar('k')] = !flags[UChar('k')];
1140 setup_getch(win, flags);
1141 wgetch_help(win, flags);
1142 } else if (c == 'm') {
1143 flags[UChar('m')] = !flags[UChar('m')];
1144 setup_getch(win, flags);
1145 wgetch_help(win, flags);
1146 } else if (c == 's') {
1148 } else if (c == 't') {
1149 notimeout(win, flags[UChar('t')]);
1150 flags[UChar('t')] = !flags[UChar('t')];
1151 wgetch_help(win, flags);
1152 } else if (c == 'w') {
1153 int high = getmaxy(win) - 1 - first_y + 1;
1154 int wide = getmaxx(win) - first_x;
1156 int new_y = first_y + getbegy(win);
1157 int new_x = first_x + getbegx(win);
1159 getyx(win, old_y, old_x);
1160 if (high > 2 && wide > 2) {
1161 WINDOW *wb = newwin(high, wide, new_y, new_x);
1162 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1167 remember_boxes(level, wi, wb);
1168 wget_wch_test(level + 1, wi, delay);
1172 wgetch_help(win, flags);
1173 wmove(win, old_y, old_x);
1178 } else if (c == 'z') {
1179 kill(getpid(), SIGTSTP);
1182 wprintw(win, "Key pressed: %04o ", (int) c);
1183 #ifdef NCURSES_MOUSE_VERSION
1184 if (c == KEY_MOUSE) {
1187 #endif /* NCURSES_MOUSE_VERSION */
1188 if (code == KEY_CODE_YES) {
1189 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1190 if (c == KEY_RESIZE) {
1191 resize_wide_boxes(level, win);
1194 (void) waddstr(win, keyname((wchar_t) c));
1196 (void) waddstr(win, key_name((wchar_t) c));
1197 if (c < 256 && iscntrl(c)) {
1198 (void) wprintw(win, " (control character)");
1200 (void) wprintw(win, " = %#x (printable character)",
1204 wgetch_wrap(win, first_y);
1211 init_getch(win, flags, delay);
1215 x_getch_test(bool recur GCC_UNUSED)
1217 int delay = begin_getch_test();
1220 wget_wch_test(0, stdscr, delay);
1222 finish_getch_test();
1228 /****************************************************************************
1230 * Character attributes test
1232 ****************************************************************************/
1234 #if HAVE_SETUPTERM || HAVE_TGETENT
1235 #define get_ncv() TIGETNUM("ncv","NC")
1236 #define get_xmc() TIGETNUM("xmc","sg")
1238 #define get_ncv() -1
1239 #define get_xmc() -1
1246 static int first = TRUE;
1247 static chtype result = 0;
1253 char *area_pointer = parsed;
1255 tgetent(buffer, getenv("TERM"));
1258 if (TIGETSTR("smso", "so"))
1259 result |= A_STANDOUT;
1260 if (TIGETSTR("smul", "us"))
1261 result |= A_UNDERLINE;
1262 if (TIGETSTR("rev", "mr"))
1263 result |= A_REVERSE;
1264 if (TIGETSTR("blink", "mb"))
1266 if (TIGETSTR("dim", "mh"))
1268 if (TIGETSTR("bold", "md"))
1270 if (TIGETSTR("smacs", "ac"))
1271 result |= A_ALTCHARSET;
1277 #define termattrs() my_termattrs()
1280 #define ATTRSTRING_1ST 32 /* ' ' */
1281 #define ATTRSTRING_END 126 /* '~' */
1283 #define COLS_PRE_ATTRS 5
1284 #define COLS_AFT_ATTRS 15
1285 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1286 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1287 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1289 static char attr_test_string[MAX_ATTRSTRING + 1];
1292 attr_legend(WINDOW *helpwin)
1297 MvWPrintw(helpwin, row++, col,
1299 MvWPrintw(helpwin, row++, col,
1302 MvWPrintw(helpwin, row++, col,
1303 "Modify the test strings:");
1304 MvWPrintw(helpwin, row++, col,
1305 " A digit sets gaps on each side of displayed attributes");
1306 MvWPrintw(helpwin, row++, col,
1307 " </> shifts the text left/right. ");
1309 MvWPrintw(helpwin, row++, col,
1312 MvWPrintw(helpwin, row++, col,
1313 " f/F/b/B toggle foreground/background background color");
1314 MvWPrintw(helpwin, row++, col,
1315 " t/T toggle text/background color attribute");
1317 MvWPrintw(helpwin, row++, col,
1318 " a/A toggle ACS (alternate character set) mapping");
1319 MvWPrintw(helpwin, row, col,
1320 " v/V toggle video attribute to combine with each line");
1321 #if USE_WIDEC_SUPPORT
1322 MvWPrintw(helpwin, row, col,
1323 " w/W toggle normal/wide (double-width) test-characters");
1328 show_color_attr(int fg, int bg, int tx)
1331 printw(" Colors (fg %d, bg %d", fg, bg);
1333 printw(", text %d", tx);
1339 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1346 *fg = (NCURSES_COLOR_T) (*fg + 1);
1349 *fg = (NCURSES_COLOR_T) (*fg - 1);
1352 *bg = (NCURSES_COLOR_T) (*bg + 1);
1355 *bg = (NCURSES_COLOR_T) (*bg - 1);
1358 *tx = (NCURSES_COLOR_T) (*tx + 1);
1361 *tx = (NCURSES_COLOR_T) (*tx - 1);
1369 *fg = (NCURSES_COLOR_T) MinColors;
1370 if (*fg < MinColors)
1371 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1373 *bg = (NCURSES_COLOR_T) MinColors;
1374 if (*bg < MinColors)
1375 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1379 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1388 adjust_attr_string(int adjust)
1390 char save = attr_test_string[0];
1391 int first = ((int) UChar(save)) + adjust;
1393 if (first >= ATTRSTRING_1ST) {
1396 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1397 if (k > ATTRSTRING_END)
1399 attr_test_string[j] = (char) k;
1400 if (((k + 1 - first) % 5) == 0) {
1401 if (++j >= MAX_ATTRSTRING)
1403 attr_test_string[j] = ' ';
1406 if ((LEN_ATTRSTRING - j) > 5) {
1407 attr_test_string[0] = save;
1408 adjust_attr_string(adjust - 1);
1410 while (j < MAX_ATTRSTRING)
1411 attr_test_string[j++] = ' ';
1412 attr_test_string[j] = '\0';
1418 * Prefer the right-end of the string for starting, since that maps to the
1419 * VT100 line-drawing.
1422 default_attr_string(void)
1424 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1425 result += (LEN_ATTRSTRING / 5);
1426 if (result < ATTRSTRING_1ST)
1427 result = ATTRSTRING_1ST;
1432 init_attr_string(void)
1434 attr_test_string[0] = (char) default_attr_string();
1435 adjust_attr_string(0);
1439 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1441 int ncv = get_ncv();
1442 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1445 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1446 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1447 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1449 printw("%*s", skip, " ");
1451 * Just for testing, write text using the alternate character set one
1452 * character at a time (to pass its rendition directly), and use the
1453 * string operation for the other attributes.
1457 if (attr & A_ALTCHARSET) {
1460 for (s = attr_test_string; *s != '\0'; ++s) {
1461 chtype ch = UChar(*s);
1462 (void) waddch(win, ch | attr);
1465 (void) wattrset(win, AttrArg(attr, 0));
1466 (void) waddstr(win, attr_test_string);
1467 (void) wattroff(win, (int) attr);
1470 printw("%*s", skip, " ");
1471 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1472 if (test != A_NORMAL) {
1473 if (!(termattrs() & test)) {
1476 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1477 static const chtype table[] =
1496 for (n = 0; n < SIZEOF(table); n++) {
1497 if ((table[n] & attr) != 0
1498 && ((1 << n) & ncv) != 0) {
1506 if ((termattrs() & test) != test) {
1516 NCURSES_CONST char *name;
1519 static const ATTR_TBL attrs_to_test[] = {
1520 { A_STANDOUT, "STANDOUT" },
1521 { A_REVERSE, "REVERSE" },
1523 { A_UNDERLINE, "UNDERLINE" },
1525 { A_BLINK, "BLINK" },
1526 { A_PROTECT, "PROTECT" },
1528 { A_INVIS, "INVISIBLE" },
1531 { A_ITALIC, "ITALIC" },
1533 { A_NORMAL, "NORMAL" },
1538 init_attr_list(ATTR_TBL * target, attr_t attrs)
1540 unsigned result = 0;
1543 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1544 attr_t test = attrs_to_test[n].attr;
1545 if (test == A_NORMAL || (test & attrs) != 0) {
1546 target[result++] = attrs_to_test[n];
1552 #if USE_WIDEC_SUPPORT
1555 NCURSES_CONST char *name;
1558 static const W_ATTR_TBL w_attrs_to_test[] = {
1559 { WA_STANDOUT, "STANDOUT" },
1560 { WA_REVERSE, "REVERSE" },
1561 { WA_BOLD, "BOLD" },
1562 { WA_UNDERLINE, "UNDERLINE" },
1564 { WA_BLINK, "BLINK" },
1565 { WA_PROTECT, "PROTECT" },
1567 { WA_INVIS, "INVISIBLE" },
1570 { WA_ITALIC, "ITALIC" },
1572 { WA_NORMAL, "NORMAL" },
1577 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1579 unsigned result = 0;
1582 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1583 attr_t test = w_attrs_to_test[n].attr;
1584 if (test == WA_NORMAL || (test & attrs) != 0) {
1585 target[result++] = w_attrs_to_test[n];
1593 attr_getc(int *skip,
1594 NCURSES_COLOR_T *fg,
1595 NCURSES_COLOR_T *bg,
1596 NCURSES_COLOR_T *tx,
1609 if (ch < 256 && isdigit(ch)) {
1617 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1619 attr_legend(helpwin);
1642 adjust_attr_string(-1);
1645 adjust_attr_string(1);
1651 error = cycle_color_attr(ch, fg, bg, tx);
1660 attr_test(bool recur GCC_UNUSED)
1661 /* test text attributes */
1664 int skip = get_xmc();
1665 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1666 NCURSES_COLOR_T bg = COLOR_BLACK;
1667 NCURSES_COLOR_T tx = -1;
1669 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1670 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1671 unsigned my_size = init_attr_list(my_list, termattrs());
1676 for (j = 0; j < my_size; ++j) {
1677 my_wins[j] = subwin(stdscr,
1679 2 + (int) (2 * j), COL_ATTRSTRING);
1680 scrollok(my_wins[j], FALSE);
1686 n = skip; /* make it easy */
1692 chtype normal = A_NORMAL | BLANK;
1693 chtype extras = (chtype) ac;
1696 NCURSES_PAIRS_T pair = 0;
1697 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1699 if (init_pair(pair, fg, bg) == ERR) {
1702 normal |= (chtype) COLOR_PAIR(pair);
1707 if (init_pair(pair, tx, bg) == ERR) {
1710 extras |= (chtype) COLOR_PAIR(pair);
1720 MvAddStr(0, 20, "Character attribute test display");
1722 for (j = 0; j < my_size; ++j) {
1723 bool arrow = (j == k);
1724 row = show_attr(my_wins[j], row, n, arrow,
1732 MvPrintw(row, COLS_PRE_ATTRS,
1733 "This terminal does %shave the magic-cookie glitch",
1734 get_xmc() > -1 ? "" : "not ");
1735 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1736 show_color_attr(fg, bg, tx);
1737 printw(" ACS (%d)", ac != 0);
1740 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1742 bkgdset(A_NORMAL | BLANK);
1747 Cannot("does not support video attributes.");
1752 #if USE_WIDEC_SUPPORT
1753 static bool use_fullwidth;
1754 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1756 #define FULL_LO 0xff00
1757 #define FULL_HI 0xff5e
1758 #define HALF_LO 0x20
1760 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1761 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1762 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1765 * Returns an ASCII code in [32..126]
1768 normal_wchar(int ch)
1770 wchar_t result = (wchar_t) ch;
1771 if (isFullWidth(ch))
1772 result = ToNormalWidth(ch);
1777 * Returns either an ASCII code in in [32..126] or full-width in
1778 * [0xff00..0xff5e], according to use_fullwidth setting.
1781 target_wchar(int ch)
1783 wchar_t result = (wchar_t) ch;
1784 if (use_fullwidth) {
1785 if (!isFullWidth(ch))
1786 result = ToFullWidth(ch);
1788 if (isFullWidth(ch))
1789 result = ToNormalWidth(ch);
1795 wide_adjust_attr_string(int adjust)
1797 wchar_t save = wide_attr_test_string[0];
1798 int first = ((int) normal_wchar(save)) + adjust;
1800 if (first >= ATTRSTRING_1ST) {
1803 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1804 if (k > ATTRSTRING_END)
1806 wide_attr_test_string[j] = target_wchar(k);
1807 if (((k + 1 - first) % 5) == 0) {
1808 if (++j >= MAX_ATTRSTRING)
1810 wide_attr_test_string[j] = ' ';
1813 if ((LEN_ATTRSTRING - j) > 5) {
1814 wide_attr_test_string[0] = save;
1815 wide_adjust_attr_string(adjust - 1);
1817 while (j < MAX_ATTRSTRING)
1818 wide_attr_test_string[j++] = ' ';
1819 wide_attr_test_string[j] = '\0';
1825 wide_init_attr_string(void)
1827 use_fullwidth = FALSE;
1828 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1829 wide_adjust_attr_string(0);
1833 set_wide_background(NCURSES_PAIRS_T pair)
1840 setcchar(&normal, blank, A_NORMAL, pair, 0);
1846 get_wide_background(void)
1848 attr_t result = WA_NORMAL;
1851 NCURSES_PAIRS_T pair;
1853 memset(&ch, 0, sizeof(ch));
1854 if (getbkgrnd(&ch) != ERR) {
1855 wchar_t wch[CCHARW_MAX];
1857 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1865 wide_show_attr(WINDOW *win,
1870 NCURSES_PAIRS_T pair,
1873 int ncv = get_ncv();
1874 attr_t test = attr & ~WA_ALTCHARSET;
1877 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1878 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1879 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1881 printw("%*s", skip, " ");
1884 * Just for testing, write text using the alternate character set one
1885 * character at a time (to pass its rendition directly), and use the
1886 * string operation for the other attributes.
1890 if (attr & WA_ALTCHARSET) {
1894 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1898 setcchar(&ch, fill, attr, pair, 0);
1899 (void) wadd_wch(win, &ch);
1902 attr_t old_attr = 0;
1903 NCURSES_PAIRS_T old_pair = 0;
1905 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1906 (void) wattr_set(win, attr, pair, 0);
1907 (void) waddwstr(win, wide_attr_test_string);
1908 (void) wattr_set(win, old_attr, old_pair, 0);
1911 printw("%*s", skip, " ");
1912 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1913 if (test != A_NORMAL) {
1914 if (!(term_attrs() & test)) {
1917 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1918 static const attr_t table[] =
1932 for (n = 0; n < SIZEOF(table); n++) {
1933 if ((table[n] & attr) != 0
1934 && ((1 << n) & ncv) != 0) {
1942 if ((term_attrs() & test) != test) {
1951 wide_attr_getc(int *skip,
1952 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1953 NCURSES_COLOR_T *tx, int *ac,
1954 unsigned *kc, unsigned limit)
1964 if (ch < 256 && isdigit(ch)) {
1972 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1973 box_set(helpwin, 0, 0);
1974 attr_legend(helpwin);
1997 use_fullwidth = FALSE;
1998 wide_adjust_attr_string(0);
2001 use_fullwidth = TRUE;
2002 wide_adjust_attr_string(0);
2005 wide_adjust_attr_string(-1);
2008 wide_adjust_attr_string(1);
2014 error = cycle_color_attr(ch, fg, bg, tx);
2023 x_attr_test(bool recur GCC_UNUSED)
2024 /* test text attributes using wide-character calls */
2027 int skip = get_xmc();
2028 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2029 NCURSES_COLOR_T bg = COLOR_BLACK;
2030 NCURSES_COLOR_T tx = -1;
2032 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2033 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2034 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2039 for (j = 0; j < my_size; ++j) {
2040 my_wins[j] = subwin(stdscr,
2042 2 + (int) (2 * j), COL_ATTRSTRING);
2043 scrollok(my_wins[j], FALSE);
2049 n = skip; /* make it easy */
2051 wide_init_attr_string();
2055 NCURSES_PAIRS_T pair = 0;
2056 NCURSES_PAIRS_T extras = 0;
2059 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2062 if (init_pair(pair, fg, bg) == ERR) {
2069 if (init_pair(extras, tx, bg) == ERR) {
2074 set_wide_background(pair);
2077 box_set(stdscr, 0, 0);
2078 MvAddStr(0, 20, "Character attribute test display");
2080 for (j = 0; j < my_size; ++j) {
2081 row = wide_show_attr(my_wins[j], row, n, (j == k),
2089 MvPrintw(row, COLS_PRE_ATTRS,
2090 "This terminal does %shave the magic-cookie glitch",
2091 get_xmc() > -1 ? "" : "not ");
2092 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2093 show_color_attr(fg, bg, tx);
2094 printw(" ACS (%d)", ac != 0);
2097 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2099 set_wide_background(0);
2104 Cannot("does not support extended video attributes.");
2110 /****************************************************************************
2112 * Color support tests
2114 ****************************************************************************/
2116 static NCURSES_CONST char *the_color_names[] =
2137 show_color_name(int y, int x, int color, bool wide, int zoom)
2139 if (move(y, x) != ERR) {
2144 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2148 if ((int) strlen(temp) >= width) {
2150 while ((1 << pwr2) < color)
2152 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2153 width > 4 ? "2^%d" : "^%d", pwr2);
2155 } else if (color >= 8) {
2156 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2158 } else if (color < 0) {
2159 _nc_STRCPY(temp, "default", sizeof(temp));
2161 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2162 "%.*s", 16, the_color_names[color]);
2164 printw("%-*.*s", width, width, temp);
2169 color_legend(WINDOW *helpwin, bool wide)
2174 MvWPrintw(helpwin, row++, col,
2177 MvWPrintw(helpwin, row++, col,
2178 "Use up/down arrow to scroll through the display if it is");
2179 MvWPrintw(helpwin, row++, col,
2180 "longer than one screen. Control/N and Control/P can be used");
2181 MvWPrintw(helpwin, row++, col,
2182 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2183 MvWPrintw(helpwin, row++, col,
2184 "full screen; control/B and control/F can be used here.");
2186 MvWPrintw(helpwin, row++, col,
2188 MvWPrintw(helpwin, row++, col,
2189 " a/A toggle altcharset off/on");
2190 MvWPrintw(helpwin, row++, col,
2191 " b/B toggle bold off/on");
2193 MvWPrintw(helpwin, row++, col,
2194 " c/C cycle used-colors through 8,16,...,COLORS");
2196 MvWPrintw(helpwin, row++, col,
2197 " n/N toggle text/number on/off");
2198 MvWPrintw(helpwin, row++, col,
2199 " r/R toggle reverse on/off");
2200 MvWPrintw(helpwin, row++, col,
2201 " w/W switch width between 4/8 columns");
2202 MvWPrintw(helpwin, row++, col,
2203 " z/Z zoom out (or in)");
2204 #if USE_WIDEC_SUPPORT
2206 MvWPrintw(helpwin, row++, col,
2207 "Wide characters:");
2208 MvWPrintw(helpwin, row, col,
2209 " x/X toggle text between ASCII and wide-character");
2216 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2219 color_cycle(int current, int step)
2221 int result = current;
2227 if ((result * 2) > COLORS) {
2230 while ((result * 2) < current) {
2236 if (current >= COLORS) {
2241 if (result > COLORS)
2247 /* generate a color test pattern */
2249 color_test(bool recur GCC_UNUSED)
2254 int grid_top = top + 3;
2255 int page_size = (LINES - grid_top);
2257 int colors_max = COLORS;
2264 bool opt_acsc = FALSE;
2265 bool opt_bold = FALSE;
2266 bool opt_revs = FALSE;
2267 bool opt_nums = FALSE;
2268 bool opt_wide = FALSE;
2273 Cannot("does not support color.");
2277 numbered = typeCalloc(char, COLS + 1);
2278 done = ((COLS < 16) || (numbered == 0));
2281 * Because the number of colors is usually a power of two, we also use
2282 * a power of two for the number of colors shown per line (to be tidy).
2284 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2289 int zoom_size = (1 << opt_zoom);
2290 int colors_max1 = colors_max / zoom_size;
2291 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2293 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2294 if (colors_max2 <= COLOR_PAIRS) {
2295 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2296 if (pairs_max > limit)
2299 if (pairs_max > COLOR_PAIRS)
2300 pairs_max = COLOR_PAIRS;
2301 if (pairs_max < colors_max1)
2302 pairs_max = colors_max1;
2304 /* this assumes an 80-column line */
2308 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2312 per_row = (col_limit / width);
2314 per_row -= MinColors;
2316 row_limit = (pairs_max + per_row - 1) / per_row;
2319 (void) printw("There are %d color pairs and %d colors",
2321 if (colors_max1 != COLORS)
2322 (void) printw(" (using %d colors)", colors_max1);
2324 (void) addstr(" besides 'default'");
2326 (void) printw(" zoom:%d", opt_zoom);
2329 MvPrintw(top + 1, 0,
2330 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2333 opt_bold ? "on" : "off");
2335 /* show color names/numbers across the top */
2336 for (i = 0; i < per_row; i++) {
2337 show_color_name(top + 2,
2339 (int) i * zoom_size + MinColors,
2344 /* show a grid of colors, with color names/ numbers on the left */
2345 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2346 int row = grid_top + (i / per_row) - base_row;
2347 int col = (i % per_row + 1) * width;
2348 NCURSES_PAIRS_T pair = i;
2350 if ((i / per_row) > row_limit)
2353 #define InxToFG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) % (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2354 #define InxToBG(i) (int)((((unsigned long)(i) * (unsigned long)zoom_size) / (unsigned long)(colors_max1 - MinColors)) + (unsigned long)MinColors)
2355 if (row >= 0 && move(row, col) != ERR) {
2356 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) InxToFG(i);
2357 NCURSES_COLOR_T bg = (NCURSES_COLOR_T) InxToBG(i);
2359 init_pair(pair, fg, bg);
2360 attron(COLOR_PAIR(pair));
2362 attron(A_ALTCHARSET);
2369 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2373 printw("%-*.*s", width, width, hello);
2374 (void) attrset(A_NORMAL);
2376 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2377 show_color_name(row, 0,
2388 switch (wGetchar(stdscr)) {
2402 colors_max = color_cycle(colors_max, -1);
2405 colors_max = color_cycle(colors_max, 1);
2423 set_color_test(opt_wide, FALSE);
2426 set_color_test(opt_wide, TRUE);
2429 if (opt_zoom <= 0) {
2437 if ((1 << opt_zoom) >= colors_max) {
2446 if (base_row <= 0) {
2454 if (base_row + page_size >= row_limit) {
2463 if (base_row <= 0) {
2466 base_row -= (page_size - 1);
2474 if (base_row + page_size >= row_limit) {
2477 base_row += page_size - 1;
2478 if (base_row + page_size >= row_limit) {
2479 base_row = row_limit - page_size - 1;
2484 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2486 color_legend(helpwin, FALSE);
2504 #if USE_WIDEC_SUPPORT
2506 #if USE_EXTENDED_COLOR
2507 #define InitExtendedPair(p,f,g) init_extended_pair((p),(f),(g))
2508 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), &(p))
2509 #define EXTENDED_PAIRS_T int
2511 #define InitExtendedPair(p,f,g) init_pair((NCURSES_PAIRS_T) (p),(NCURSES_COLOR_T)(f),(NCURSES_COLOR_T)(g))
2512 #define ExtendedColorSet(p) color_set((NCURSES_PAIRS_T) (p), NULL)
2513 #define EXTENDED_PAIRS_T NCURSES_PAIRS_T
2516 /* generate a color test pattern */
2518 x_color_test(bool recur GCC_UNUSED)
2523 int grid_top = top + 3;
2524 int page_size = (LINES - grid_top);
2526 int colors_max = COLORS;
2533 bool opt_acsc = FALSE;
2534 bool opt_bold = FALSE;
2535 bool opt_revs = FALSE;
2536 bool opt_wide = FALSE;
2537 bool opt_nums = FALSE;
2538 bool opt_xchr = FALSE;
2540 wchar_t *buffer = 0;
2544 Cannot("does not support color.");
2547 numbered = typeCalloc(char, COLS + 1);
2548 buffer = typeCalloc(wchar_t, COLS + 1);
2549 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2552 * Because the number of colors is usually a power of two, we also use
2553 * a power of two for the number of colors shown per line (to be tidy).
2555 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2560 int zoom_size = (1 << opt_zoom);
2561 int colors_max1 = colors_max / zoom_size;
2562 double colors_max2 = (double) colors_max1 * (double) colors_max1;
2564 pairs_max = ((unsigned) (-1)) / 2;
2565 if (colors_max2 <= COLOR_PAIRS) {
2566 int limit = (colors_max1 - MinColors) * (colors_max1 - MinColors);
2567 if (pairs_max > limit)
2570 if (pairs_max > COLOR_PAIRS)
2571 pairs_max = COLOR_PAIRS;
2572 if (pairs_max < colors_max1)
2573 pairs_max = colors_max1;
2578 per_row = (col_limit / ((colors_max1 > 8) ? width : 8));
2582 per_row = (col_limit / width);
2584 per_row -= MinColors;
2587 make_fullwidth_text(buffer, hello);
2591 make_narrow_text(buffer, hello);
2594 row_limit = (pairs_max + per_row - 1) / per_row;
2597 (void) printw("There are %d color pairs and %d colors",
2599 if (colors_max1 != COLORS)
2600 (void) printw(" (using %d colors)", colors_max1);
2602 (void) addstr(" besides 'default'");
2604 (void) printw(" zoom:%d", opt_zoom);
2607 MvPrintw(top + 1, 0,
2608 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2611 opt_bold ? "on" : "off");
2613 /* show color names/numbers across the top */
2614 for (i = 0; i < per_row; i++) {
2615 show_color_name(top + 2,
2616 ((int) i + 1) * width,
2617 (int) i * zoom_size + MinColors,
2622 /* show a grid of colors, with color names/ numbers on the left */
2623 for (i = (base_row * per_row); i < pairs_max; i++) {
2624 int row = grid_top + ((int) i / per_row) - base_row;
2625 int col = ((int) i % per_row + 1) * width;
2628 if ((i / per_row) > row_limit)
2631 if (row >= 0 && move(row, col) != ERR) {
2632 InitExtendedPair(pair, InxToFG(i), InxToBG(i));
2633 (void) ExtendedColorSet(pair);
2635 attr_on(WA_ALTCHARSET, NULL);
2637 attr_on(WA_BOLD, NULL);
2639 attr_on(WA_REVERSE, NULL);
2642 _nc_SPRINTF(numbered,
2643 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2644 "{%02X}", (unsigned) i);
2646 make_fullwidth_text(buffer, numbered);
2648 make_narrow_text(buffer, numbered);
2651 addnwstr(buffer, width);
2652 (void) attr_set(A_NORMAL, 0, NULL);
2654 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2655 show_color_name(row, 0,
2666 switch (wGetchar(stdscr)) {
2680 colors_max = color_cycle(colors_max, -1);
2683 colors_max = color_cycle(colors_max, 1);
2701 set_color_test(opt_wide, FALSE);
2704 set_color_test(opt_wide, TRUE);
2713 if (opt_zoom <= 0) {
2721 if ((1 << opt_zoom) >= colors_max) {
2730 if (base_row <= 0) {
2738 if (base_row + page_size >= row_limit) {
2747 if (base_row <= 0) {
2750 base_row -= (page_size - 1);
2758 if (base_row + page_size >= row_limit) {
2761 base_row += page_size - 1;
2762 if (base_row + page_size >= row_limit) {
2763 base_row = row_limit - page_size - 1;
2768 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2770 color_legend(helpwin, TRUE);
2788 #endif /* USE_WIDEC_SUPPORT */
2790 #if HAVE_COLOR_CONTENT
2792 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2794 NCURSES_COLOR_T red, green, blue;
2796 color_content(current, &red, &green, &blue);
2800 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2803 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2806 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2810 if (init_color(current, red, green, blue) == ERR)
2815 reset_all_colors(void)
2819 for (c = 0; c < COLORS; ++c)
2822 all_colors[c].green,
2823 all_colors[c].blue);
2826 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2827 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2828 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2831 init_all_colors(bool xterm_colors, char *palette_file)
2834 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2836 failed("all_colors");
2837 for (cp = 0; cp < MaxColors; ++cp) {
2839 &all_colors[cp].red,
2840 &all_colors[cp].green,
2841 &all_colors[cp].blue);
2843 /* xterm and compatible terminals can read results of an OSC string
2844 * asking for the current color palette.
2848 char result[BUFSIZ];
2850 unsigned check_r, check_g, check_b;
2855 for (n = 0; n < MaxColors; ++n) {
2858 fprintf(stderr, "\033]4;%d;?\007", n);
2859 got = (int) read(0, result, sizeof(result) - 1);
2863 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2869 all_colors[n].red = DecodeRGB(check_r);
2870 all_colors[n].green = DecodeRGB(check_g);
2871 all_colors[n].blue = DecodeRGB(check_b);
2878 if (palette_file != 0) {
2879 FILE *fp = fopen(palette_file, "r");
2881 char buffer[BUFSIZ];
2882 int red, green, blue;
2885 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2886 if (sscanf(buffer, "scale:%d", &c) == 1) {
2888 } else if (sscanf(buffer, "%d:%d %d %d",
2897 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2898 all_colors[c].red = Scaled(red);
2899 all_colors[c].green = Scaled(green);
2900 all_colors[c].blue = Scaled(blue);
2908 #define scaled_rgb(n) ((255 * (n)) / 1000)
2911 color_edit(bool recur GCC_UNUSED)
2912 /* display the color test pattern, without trying to edit colors */
2916 int this_c, value, field;
2922 Cannot("does not support color.");
2924 } else if (!can_change_color()) {
2925 Cannot("has hardwired color values.");
2938 page_size = (LINES - 6);
2941 for (i = 0; i < MaxColors; i++)
2942 init_pair((NCURSES_PAIRS_T) i,
2943 (NCURSES_COLOR_T) COLOR_WHITE,
2944 (NCURSES_COLOR_T) i);
2946 MvPrintw(LINES - 2, 0, "Number: %d", value);
2949 NCURSES_COLOR_T red, green, blue;
2952 MvAddStr(0, 20, "Color RGB Value Editing");
2955 for (i = (NCURSES_COLOR_T) top_color;
2956 (i - top_color < page_size)
2957 && (i < MaxColors); i++) {
2960 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2961 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2962 (i == current ? '>' : ' '),
2963 (i < (int) SIZEOF(the_color_names)
2964 ? the_color_names[i] : numeric));
2965 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2967 (void) attrset(A_NORMAL);
2969 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2971 if (current == i && field == 0)
2973 printw("%04d", (int) red);
2974 if (current == i && field == 0)
2975 (void) attrset(A_NORMAL);
2977 if (current == i && field == 1)
2979 printw("%04d", (int) green);
2980 if (current == i && field == 1)
2981 (void) attrset(A_NORMAL);
2983 if (current == i && field == 2)
2985 printw("%04d", (int) blue);
2986 if (current == i && field == 2)
2987 (void) attrset(A_NORMAL);
2988 (void) attrset(A_NORMAL);
2989 printw(" ( %3d %3d %3d )",
2990 (int) scaled_rgb(red),
2991 (int) scaled_rgb(green),
2992 (int) scaled_rgb(blue));
2995 MvAddStr(LINES - 3, 0,
2996 "Use up/down to select a color, left/right to change fields.");
2997 MvAddStr(LINES - 2, 0,
2998 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
3000 move(2 + current - top_color, 0);
3004 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
3026 current -= (page_size - 1);
3033 if (current < (MaxColors - 1))
3034 current += (page_size - 1);
3041 current = (current == 0 ? (MaxColors - 1) : current - 1);
3046 current = (current == (MaxColors - 1) ? 0 : current + 1);
3051 field = (field == 2 ? 0 : field + 1);
3056 field = (field == 0 ? 2 : field - 1);
3069 value = value * 10 + (this_c - '0');
3073 change_color((NCURSES_PAIRS_T) current, field, value, 1);
3077 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
3081 change_color((NCURSES_PAIRS_T) current, field, value, 0);
3086 P(" RGB Value Editing Help");
3088 P("You are in the RGB value editor. Use the arrow keys to select one of");
3089 P("the fields in one of the RGB triples of the current colors; the one");
3090 P("currently selected will be reverse-video highlighted.");
3092 P("To change a field, enter the digits of the new value; they are echoed");
3093 P("as entered. Finish by typing `='. The change will take effect instantly.");
3094 P("To increment or decrement a value, use the same procedure, but finish");
3095 P("with a `+' or `-'.");
3097 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3099 P("Press 'm' to invoke the top-level menu with the current color settings.");
3100 P("To quit, do ESC");
3109 for (i = 0; i < MaxColors; i++)
3110 init_pair((NCURSES_PAIRS_T) i,
3111 (NCURSES_COLOR_T) COLOR_WHITE,
3112 (NCURSES_COLOR_T) i);
3126 if (current >= MaxColors)
3127 current = MaxColors - 1;
3128 if (current < top_color)
3129 top_color = current;
3130 if (current - top_color >= page_size)
3131 top_color = current - (page_size - 1);
3133 MvPrintw(LINES - 1, 0, "Number: %d", value);
3136 (!isQuit(this_c, TRUE));
3141 * ncurses does not reset each color individually when calling endwin().
3148 #endif /* HAVE_COLOR_CONTENT */
3150 /****************************************************************************
3152 * Alternate character-set stuff
3154 ****************************************************************************/
3156 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3162 if ((*at_code += 1) >= limit)
3167 *at_code = limit - 1;
3176 *attr = list[*at_code].attr;
3180 #if USE_WIDEC_SUPPORT
3182 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3188 if ((*at_code += 1) >= limit)
3193 *at_code = limit - 1;
3202 *attr = list[*at_code].attr;
3208 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3210 bool result = FALSE;
3220 if ((*fg += 1) >= COLORS)
3228 if ((*bg += 1) >= COLORS)
3236 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3239 if (init_pair(*pair,
3240 (NCURSES_COLOR_T) *fg,
3241 (NCURSES_COLOR_T) *bg) == ERR) {
3250 /****************************************************************************
3252 * Soft-key label test
3254 ****************************************************************************/
3259 #define SLK_WORK (SLK_HELP + 3)
3264 static const char *table[] =
3266 "Available commands are:"
3268 ,"^L -- repaint this message and activate soft keys"
3269 ,"a/d -- activate/disable soft keys"
3270 ,"c -- set centered format for labels"
3271 ,"l -- set left-justified format for labels"
3272 ,"r -- set right-justified format for labels"
3273 ,"[12345678] -- set label; labels are numbered 1 through 8"
3274 ,"e -- erase stdscr (should not erase labels)"
3275 ,"s -- test scrolling of shortened screen"
3276 ,"v/V -- cycle through video attributes"
3278 ,"F/f/B/b -- cycle through foreground/background colors"
3280 ,"ESC -- return to main menu"
3282 ,"Note: if activating the soft keys causes your terminal to scroll up"
3283 ,"one line, your terminal auto-scrolls when anything is written to the"
3284 ,"last screen position. The ncurses code does not yet handle this"
3290 for (j = 0; j < SIZEOF(table); ++j) {
3298 call_slk_color(int fg, int bg)
3300 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3302 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3311 slk_test(bool recur GCC_UNUSED)
3312 /* exercise the soft keys */
3317 chtype attr = A_NORMAL;
3318 unsigned at_code = 0;
3320 int fg = COLOR_BLACK;
3321 int bg = COLOR_WHITE;
3322 NCURSES_PAIRS_T pair = 0;
3324 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3325 unsigned my_size = init_attr_list(my_list, termattrs());
3330 call_slk_color(fg, bg);
3340 MvAddStr(0, 20, "Soft Key Exerciser");
3355 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3356 while ((c = Getchar()) != 'Q' && (c != ERR))
3384 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3385 _nc_STRCPY(buf, "", sizeof(buf));
3386 if ((s = slk_label(c - '0')) != 0) {
3387 _nc_STRNCPY(buf, s, (size_t) 8);
3389 wGetstring(stdscr, buf, 8);
3390 slk_set((c - '0'), buf, fmt);
3399 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3401 wnoutrefresh(stdscr);
3406 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3413 if (cycle_colors(c, &fg, &bg, &pair)) {
3415 call_slk_color(fg, bg);
3425 } while (!isQuit(c = Getchar(), TRUE));
3434 #if USE_WIDEC_SUPPORT
3437 x_slk_test(bool recur GCC_UNUSED)
3438 /* exercise the soft keys */
3441 wchar_t buf[SLKLEN + 1];
3443 attr_t attr = WA_NORMAL;
3444 unsigned at_code = 0;
3445 int fg = COLOR_BLACK;
3446 int bg = COLOR_WHITE;
3447 NCURSES_PAIRS_T pair = 0;
3448 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3449 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3453 call_slk_color(fg, bg);
3460 attr_on(WA_BOLD, NULL);
3461 MvAddStr(0, 20, "Soft Key Exerciser");
3462 attr_off(WA_BOLD, NULL);
3476 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3477 while ((c = Getchar()) != 'Q' && (c != ERR))
3505 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3507 if ((s = slk_label(c - '0')) != 0) {
3508 char *temp = strdup(s);
3509 size_t used = strlen(temp);
3510 size_t want = SLKLEN;
3511 #ifndef state_unused
3516 while (want > 0 && used != 0) {
3518 const char *base = s;
3520 reset_mbytes(state);
3521 test = count_mbytes(base, 0, &state);
3522 if (test == (size_t) -1) {
3524 } else if (test > want) {
3527 reset_mbytes(state);
3528 trans_mbytes(buf, base, want, &state);
3534 wGet_wstring(stdscr, buf, SLKLEN);
3535 slk_wset((c - '0'), buf, fmt);
3546 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3547 call_slk_color(fg, bg);
3552 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3553 call_slk_color(fg, bg);
3556 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3558 wnoutrefresh(stdscr);
3562 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3563 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3569 if (cycle_colors(c, &fg, &bg, &pair)) {
3571 call_slk_color(fg, bg);
3581 } while (!isQuit(c = Getchar(), TRUE));
3590 #endif /* SLK_INIT */
3593 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3596 unsigned last = 255;
3602 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3607 for (code = first; code <= last; ++code) {
3608 int row = (int) (2 + (code / 16));
3609 int col = (int) (5 * (code % 16));
3610 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3611 for (count = 1; count < repeat; ++count) {
3612 AddCh(colored_chtype(code, attr, pair));
3619 * Show a slice of 32 characters, allowing those to be repeated up to the
3622 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3623 * terminal to perform functions. The remaining codes can be graphic.
3626 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3629 unsigned first = (unsigned) base;
3630 unsigned last = first + (unsigned) pagesize - 2;
3631 bool C1 = (first == 128);
3636 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3637 C1 ? "C1" : "GR", first, last);
3641 for (code = first; code <= last; code++) {
3643 int row = 2 + ((int) (code - first) % (pagesize / 2));
3644 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3646 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3647 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3651 nodelay(stdscr, TRUE);
3652 echochar(colored_chtype(code, attr, pair));
3654 /* (yes, this _is_ crude) */
3655 while ((reply = Getchar()) != ERR) {
3656 AddCh(UChar(reply));
3659 nodelay(stdscr, FALSE);
3661 } while (--count > 0);
3668 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3674 MvPrintw(0, 20, "Display of PC Character Codes");
3678 for (code = 0; code < 16; ++code) {
3679 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3681 for (code = 0; code < 256; code++) {
3683 int row = 3 + (int) (code / 16) + (code >= 128);
3684 int col = 8 + (int) (code % 16) * PC_COLS;
3685 if ((code % 16) == 0)
3686 MvPrintw(row, 0, "0x%02x:", code);
3697 * Skip the ones that do not work.
3701 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3704 } while (--count > 0);
3709 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3713 attr |= (attr_t) COLOR_PAIR(pair);
3717 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3722 colored_chtype(ACS_VLINE, attr, pair),
3723 colored_chtype(ACS_VLINE, attr, pair),
3724 colored_chtype(ACS_HLINE, attr, pair),
3725 colored_chtype(ACS_HLINE, attr, pair),
3726 colored_chtype(ACS_ULCORNER, attr, pair),
3727 colored_chtype(ACS_URCORNER, attr, pair),
3728 colored_chtype(ACS_LLCORNER, attr, pair),
3729 colored_chtype(ACS_LRCORNER, attr, pair));
3730 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3731 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3732 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3733 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3734 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3735 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3736 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,