1 /****************************************************************************
2 * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
28 /****************************************************************************
31 ncurses.c --- ncurses library exerciser
37 An interactive test module for the ncurses library.
40 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
41 Thomas E. Dickey (beginning revision 1.27 in 1996).
43 $Id: ncurses.c,v 1.449 2017/04/15 18:53:50 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
110 #ifdef CURSES_WACS_ARRAY
111 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
112 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
113 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
114 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
115 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
116 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
117 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
124 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
125 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
126 #define reset_wchars(state) init_mb(state)
127 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
128 #define count_wchars(src, len, state) wcstombs(0, src, len)
129 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
130 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
135 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
136 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
137 #define reset_mbytes(state) init_mb(state)
138 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
139 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
140 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
141 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
145 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
147 #define P(string) printw("%s\n", string)
149 #define BLANK ' ' /* this is the background character */
152 static int max_colors; /* the actual number of colors we'll use */
153 static int min_colors; /* the minimum color code */
154 static bool use_colors; /* true if we use colors */
157 static int max_pairs; /* ...and the number of color pairs */
161 NCURSES_COLOR_T green;
162 NCURSES_COLOR_T blue;
165 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);
178 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
179 * though we can rely on negative x/y values to stop the macro.
182 do_h_line(int y, int x, chtype c, int to)
185 MvHLine(y, x, c, (to) - (x));
189 do_v_line(int y, int x, chtype c, int to)
192 MvVLine(y, x, c, (to) - (y));
204 isQuit(int c, bool escape)
206 return ((c) == QUIT || (escape && ((c) == ESCAPE)));
208 #define case_QUIT QUIT: case ESCAPE
210 /* Common function to allow ^T to toggle trace-mode in the middle of a test
211 * so that trace-files can be made smaller.
214 wGetchar(WINDOW *win)
218 while ((c = wgetch(win)) == CTRL('T')) {
220 save_trace = _nc_tracing;
221 Trace(("TOGGLE-TRACING OFF"));
224 _nc_tracing = save_trace;
228 Trace(("TOGGLE-TRACING ON"));
235 #define Getchar() wGetchar(stdscr)
237 /* replaces wgetnstr(), since we want to be able to edit values */
239 wGetstring(WINDOW *win, char *buffer, int limit)
246 (void) wattrset(win, A_REVERSE);
248 x = (int) strlen(buffer);
250 if (x > (int) strlen(buffer))
251 x = (int) strlen(buffer);
253 wprintw(win, "%-*s", limit, buffer);
254 wmove(win, y0, x0 + x);
255 switch (ch = wGetchar(win)) {
268 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
286 if (!isprint(ch) || ch >= KEY_MIN) {
288 } else if ((int) strlen(buffer) < limit) {
290 for (j = (int) strlen(buffer) + 1; j > x; --j) {
291 buffer[j] = buffer[j - 1];
293 buffer[x++] = (char) ch;
300 wattroff(win, A_REVERSE);
305 #if USE_WIDEC_SUPPORT
307 fullwidth_digit(int ch)
309 return (wchar_t) (ch + 0xff10 - '0');
313 make_fullwidth_text(wchar_t *target, const char *source)
316 while ((ch = *source++) != 0) {
317 *target++ = fullwidth_digit(ch);
323 make_narrow_text(wchar_t *target, const char *source)
326 while ((ch = *source++) != 0) {
327 *target++ = (wchar_t) ch;
334 make_fullwidth_digit(cchar_t *target, int digit)
338 source[0] = fullwidth_digit(digit + '0');
340 setcchar(target, source, A_NORMAL, 0, 0);
345 wGet_wchar(WINDOW *win, wint_t *result)
349 while ((c = wget_wch(win, result)) == CTRL('T')) {
351 save_trace = _nc_tracing;
352 Trace(("TOGGLE-TRACING OFF"));
355 _nc_tracing = save_trace;
359 Trace(("TOGGLE-TRACING ON"));
362 c = wget_wch(win, result);
366 #define Get_wchar(result) wGet_wchar(stdscr, result)
368 /* replaces wgetn_wstr(), since we want to be able to edit values */
370 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
379 (void) wattrset(win, A_REVERSE);
381 x = (int) wcslen(buffer);
383 if (x > (int) wcslen(buffer))
384 x = (int) wcslen(buffer);
386 /* clear the "window' */
388 wprintw(win, "%*s", limit, " ");
390 /* write the existing buffer contents */
392 waddnwstr(win, buffer, limit);
394 /* positions the cursor past character 'x' */
396 waddnwstr(win, buffer, x);
398 switch (wGet_wchar(win, &ch)) {
438 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
458 } else if ((int) wcslen(buffer) < limit) {
460 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
461 buffer[j] = buffer[j - 1];
463 buffer[x++] = (wchar_t) ch;
470 wattroff(win, A_REVERSE);
481 addstr("Press any key to continue... ");
486 Cannot(const char *what)
488 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
493 ShellOut(bool message)
496 addstr("Shelling out...");
502 IGNORE_RC(system("sh"));
505 addstr("returned from shellout.\n");
509 #ifdef NCURSES_MOUSE_VERSION
511 * This function is the same as _tracemouse(), but we cannot count on that
512 * being available in the non-debug library.
515 mouse_decode(MEVENT const *ep)
517 static char buf[80 + (5 * 10) + (32 * 15)];
519 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
520 "id %2d at (%2d, %2d, %d) state %4lx = {",
521 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
524 if ((ep->bstate & m)==m) { \
525 _nc_STRCAT(buf, s, sizeof(buf)); \
526 _nc_STRCAT(buf, ", ", sizeof(buf)); \
529 SHOW(BUTTON1_RELEASED, "release-1");
530 SHOW(BUTTON1_PRESSED, "press-1");
531 SHOW(BUTTON1_CLICKED, "click-1");
532 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
533 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
534 #if NCURSES_MOUSE_VERSION == 1
535 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
538 SHOW(BUTTON2_RELEASED, "release-2");
539 SHOW(BUTTON2_PRESSED, "press-2");
540 SHOW(BUTTON2_CLICKED, "click-2");
541 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
542 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
543 #if NCURSES_MOUSE_VERSION == 1
544 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
547 SHOW(BUTTON3_RELEASED, "release-3");
548 SHOW(BUTTON3_PRESSED, "press-3");
549 SHOW(BUTTON3_CLICKED, "click-3");
550 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
551 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
552 #if NCURSES_MOUSE_VERSION == 1
553 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
556 SHOW(BUTTON4_RELEASED, "release-4");
557 SHOW(BUTTON4_PRESSED, "press-4");
558 SHOW(BUTTON4_CLICKED, "click-4");
559 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
560 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
561 #if NCURSES_MOUSE_VERSION == 1
562 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
565 #if NCURSES_MOUSE_VERSION == 2
566 SHOW(BUTTON5_RELEASED, "release-5");
567 SHOW(BUTTON5_PRESSED, "press-5");
568 SHOW(BUTTON5_CLICKED, "click-5");
569 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
570 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
573 SHOW(BUTTON_CTRL, "ctrl");
574 SHOW(BUTTON_SHIFT, "shift");
575 SHOW(BUTTON_ALT, "alt");
576 SHOW(ALL_MOUSE_EVENTS, "all-events");
577 SHOW(REPORT_MOUSE_POSITION, "position");
581 if (buf[strlen(buf) - 1] == ' ')
582 buf[strlen(buf) - 2] = '\0';
583 _nc_STRCAT(buf, "}", sizeof(buf));
588 show_mouse(WINDOW *win)
596 outside = !wenclose(win, event.y, event.x);
599 (void) wstandout(win);
600 waddstr(win, "KEY_MOUSE");
601 (void) wstandend(win);
603 waddstr(win, "KEY_MOUSE");
605 wprintw(win, ", %s", mouse_decode(&event));
610 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
614 wmove(win, event.y, event.x);
622 #endif /* NCURSES_MOUSE_VERSION */
624 /****************************************************************************
626 * Character input test
628 ****************************************************************************/
630 #define NUM_GETCH_FLAGS 256
631 typedef bool GetchFlags[NUM_GETCH_FLAGS];
634 setup_getch(WINDOW *win, GetchFlags flags)
636 keypad(win, flags['k']); /* should be redundant, but for testing */
637 meta(win, flags['m']); /* force this to a known state */
645 init_getch(WINDOW *win, GetchFlags flags, int delay)
647 memset(flags, FALSE, NUM_GETCH_FLAGS);
648 flags[UChar('k')] = (win == stdscr);
649 flags[UChar('m')] = TRUE;
650 flags[UChar('t')] = (delay != 0);
652 setup_getch(win, flags);
656 blocking_getch(GetchFlags flags, int delay)
658 return ((delay < 0) && flags['t']);
661 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
664 wgetch_help(WINDOW *win, GetchFlags flags)
666 static const char *help[] =
668 "e -- toggle echo mode"
669 ,"g -- triggers a getstr test"
670 ,"k -- toggle keypad/literal mode"
671 ,"m -- toggle meta (7-bit/8-bit) mode"
674 ,"t -- toggle timeout"
675 ,"w -- create a new window"
677 ,"z -- suspend this process"
681 unsigned chk = ((SIZEOF(help) + 1) / 2);
686 printw("Type any key to see its %s value. Also:\n",
687 flags['k'] ? "keypad" : "literal");
688 for (n = 0; n < SIZEOF(help); ++n) {
689 const char *msg = help[n];
690 int row = 1 + (int) (n % chk);
691 int col = (n >= chk) ? COLS / 2 : 0;
692 int flg = ((strstr(msg, "toggle") != 0)
693 && (flags[UChar(*msg)] != FALSE));
694 if (*msg == '^' && ExitOnEscape())
695 msg = "^[,^q -- quit";
698 MvPrintw(row, col, "%s", msg);
709 wgetch_wrap(WINDOW *win, int first_y)
711 int last_y = getmaxy(win) - 1;
712 int y = getcury(win) + 1;
720 #if defined(KEY_RESIZE) && HAVE_WRESIZE
726 static WINSTACK *winstack = 0;
727 static unsigned len_winstack = 0;
740 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
742 unsigned need = (level + 1) * 2;
744 assert(level < (unsigned) COLS);
748 winstack = typeMalloc(WINSTACK, len_winstack);
749 } else if (need >= len_winstack) {
751 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
754 failed("remember_boxes");
755 winstack[level].text = txt_win;
756 winstack[level].frame = box_win;
759 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
763 /* this chunk is now done in resize_term() */
770 #define slk_repaint() /* nothing */
773 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
775 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
776 * Resize both and paint the box in the parent.
779 resize_boxes(unsigned level, WINDOW *win)
783 int high = LINES - base;
787 wnoutrefresh(stdscr);
791 for (n = 0; n < level; ++n) {
792 wresize(winstack[n].frame, high, wide);
793 wresize(winstack[n].text, high - 2, wide - 2);
796 werase(winstack[n].text);
797 box(winstack[n].frame, 0, 0);
798 wnoutrefresh(winstack[n].frame);
799 wprintw(winstack[n].text,
801 getmaxy(winstack[n].text),
802 getmaxx(winstack[n].text));
803 wnoutrefresh(winstack[n].text);
804 if (winstack[n].text == win)
809 #endif /* resize_boxes */
811 #define forget_boxes() /* nothing */
812 #define remember_boxes(level,text,frame) /* nothing */
816 * Return-code is OK/ERR or a keyname.
821 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
825 wgetch_test(unsigned level, WINDOW *win, int delay)
828 int first_y, first_x;
833 init_getch(win, flags, delay);
834 notimeout(win, FALSE);
835 wtimeout(win, delay);
836 getyx(win, first_y, first_x);
838 wgetch_help(win, flags);
839 wsetscrreg(win, first_y, getmaxy(win) - 1);
843 while ((c = wGetchar(win)) == ERR) {
845 if (blocking_getch(flags, delay)) {
846 (void) wprintw(win, "%05d: input error", incount);
849 (void) wprintw(win, "%05d: input timed out", incount);
851 wgetch_wrap(win, first_y);
853 if (c == ERR && blocking_getch(flags, delay)) {
855 wgetch_wrap(win, first_y);
856 } else if (isQuit(c, ExitOnEscape())) {
858 } else if (c == 'e') {
859 flags[UChar('e')] = !flags[UChar('e')];
860 setup_getch(win, flags);
861 wgetch_help(win, flags);
862 } else if (c == 'g') {
863 waddstr(win, "getstr test: ");
865 c = wgetnstr(win, buf, sizeof(buf) - 1);
867 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
868 (int) strlen(buf), buf,
871 wgetch_wrap(win, first_y);
872 } else if (c == 'k') {
873 flags[UChar('k')] = !flags[UChar('k')];
874 setup_getch(win, flags);
875 wgetch_help(win, flags);
876 } else if (c == 'm') {
877 flags[UChar('m')] = !flags[UChar('m')];
878 setup_getch(win, flags);
879 wgetch_help(win, flags);
880 } else if (c == 's') {
882 } else if (c == 't') {
883 notimeout(win, flags[UChar('t')]);
884 flags[UChar('t')] = !flags[UChar('t')];
885 wgetch_help(win, flags);
886 } else if (c == 'w') {
887 int high = getmaxy(win) - 1 - first_y + 1;
888 int wide = getmaxx(win) - first_x;
890 int new_y = first_y + getbegy(win);
891 int new_x = first_x + getbegx(win);
893 getyx(win, old_y, old_x);
894 if (high > 2 && wide > 2) {
895 WINDOW *wb = newwin(high, wide, new_y, new_x);
896 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
901 remember_boxes(level, wi, wb);
902 wgetch_test(level + 1, wi, delay);
906 wgetch_help(win, flags);
907 wmove(win, old_y, old_x);
913 } else if (c == 'z') {
914 kill(getpid(), SIGTSTP);
917 wprintw(win, "Key pressed: %04o ", c);
918 #ifdef NCURSES_MOUSE_VERSION
919 if (c == KEY_MOUSE) {
922 #endif /* NCURSES_MOUSE_VERSION */
924 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
925 if (c == KEY_RESIZE) {
926 resize_boxes(level, win);
929 (void) waddstr(win, keyname(c));
930 } else if (c >= 0x80) {
931 unsigned c2 = (unsigned) c;
932 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
933 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
937 (void) wprintw(win, "%c", UChar(c));
938 else if (c2 != UChar(c))
939 (void) wprintw(win, "M-%s", unctrl(c2));
941 (void) wprintw(win, "%s", unctrl(c2));
942 waddstr(win, " (high-half character)");
945 (void) wprintw(win, "%c (ASCII printable character)", c);
947 (void) wprintw(win, "%s (ASCII control character)",
950 wgetch_wrap(win, first_y);
957 init_getch(win, flags, delay);
961 begin_getch_test(void)
968 #ifdef NCURSES_MOUSE_VERSION
969 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
972 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
974 getnstr(buf, sizeof(buf) - 1);
978 if (isdigit(UChar(buf[0]))) {
979 delay = atoi(buf) * 100;
989 finish_getch_test(void)
991 #ifdef NCURSES_MOUSE_VERSION
992 mousemask(0, (mmask_t *) 0);
1003 int delay = begin_getch_test();
1006 wgetch_test(0, stdscr, delay);
1008 finish_getch_test();
1012 #if USE_WIDEC_SUPPORT
1014 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1015 * Resize both and paint the box in the parent.
1017 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1019 resize_wide_boxes(unsigned level, WINDOW *win)
1023 int high = LINES - base;
1027 wnoutrefresh(stdscr);
1031 for (n = 0; n < level; ++n) {
1032 wresize(winstack[n].frame, high, wide);
1033 wresize(winstack[n].text, high - 2, wide - 2);
1036 werase(winstack[n].text);
1037 box_set(winstack[n].frame, 0, 0);
1038 wnoutrefresh(winstack[n].frame);
1039 wprintw(winstack[n].text,
1041 getmaxy(winstack[n].text),
1042 getmaxx(winstack[n].text));
1043 wnoutrefresh(winstack[n].text);
1044 if (winstack[n].text == win)
1049 #endif /* KEY_RESIZE */
1052 wcstos(const wchar_t *src)
1056 const wchar_t *tmp = src;
1057 #ifndef state_unused
1061 reset_wchars(state);
1062 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1063 unsigned have = (unsigned) need;
1064 if ((result = typeCalloc(char, have + 1)) != 0) {
1066 if (trans_wchars(result, tmp, have, &state) != have) {
1078 wget_wch_test(unsigned level, WINDOW *win, int delay)
1080 wchar_t wchar_buf[BUFSIZ];
1081 wint_t wint_buf[BUFSIZ];
1082 int first_y, first_x;
1089 init_getch(win, flags, delay);
1090 notimeout(win, FALSE);
1091 wtimeout(win, delay);
1092 getyx(win, first_y, first_x);
1094 wgetch_help(win, flags);
1095 wsetscrreg(win, first_y, getmaxy(win) - 1);
1096 scrollok(win, TRUE);
1099 while ((code = wGet_wchar(win, &c)) == ERR) {
1101 if (blocking_getch(flags, delay)) {
1102 (void) wprintw(win, "%05d: input error", incount);
1105 (void) wprintw(win, "%05d: input timed out", incount);
1107 wgetch_wrap(win, first_y);
1109 if (code == ERR && blocking_getch(flags, delay)) {
1110 wprintw(win, "ERR");
1111 wgetch_wrap(win, first_y);
1112 } else if (isQuit((int) c, ExitOnEscape())) {
1114 } else if (c == 'e') {
1115 flags[UChar('e')] = !flags[UChar('e')];
1116 setup_getch(win, flags);
1117 wgetch_help(win, flags);
1118 } else if (c == 'g') {
1119 waddstr(win, "getstr test: ");
1121 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1124 wprintw(win, "wgetn_wstr returns an error.");
1127 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1130 if ((temp = wcstos(wchar_buf)) != 0) {
1131 wprintw(win, "I saw %d characters:\n\t`%s'.",
1132 (int) wcslen(wchar_buf), temp);
1135 wprintw(win, "I saw %d characters (cannot convert).",
1136 (int) wcslen(wchar_buf));
1140 wgetch_wrap(win, first_y);
1141 } else if (c == 'k') {
1142 flags[UChar('k')] = !flags[UChar('k')];
1143 setup_getch(win, flags);
1144 wgetch_help(win, flags);
1145 } else if (c == 'm') {
1146 flags[UChar('m')] = !flags[UChar('m')];
1147 setup_getch(win, flags);
1148 wgetch_help(win, flags);
1149 } else if (c == 's') {
1151 } else if (c == 't') {
1152 notimeout(win, flags[UChar('t')]);
1153 flags[UChar('t')] = !flags[UChar('t')];
1154 wgetch_help(win, flags);
1155 } else if (c == 'w') {
1156 int high = getmaxy(win) - 1 - first_y + 1;
1157 int wide = getmaxx(win) - first_x;
1159 int new_y = first_y + getbegy(win);
1160 int new_x = first_x + getbegx(win);
1162 getyx(win, old_y, old_x);
1163 if (high > 2 && wide > 2) {
1164 WINDOW *wb = newwin(high, wide, new_y, new_x);
1165 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1170 remember_boxes(level, wi, wb);
1171 wget_wch_test(level + 1, wi, delay);
1175 wgetch_help(win, flags);
1176 wmove(win, old_y, old_x);
1181 } else if (c == 'z') {
1182 kill(getpid(), SIGTSTP);
1185 wprintw(win, "Key pressed: %04o ", (int) c);
1186 #ifdef NCURSES_MOUSE_VERSION
1187 if (c == KEY_MOUSE) {
1190 #endif /* NCURSES_MOUSE_VERSION */
1191 if (code == KEY_CODE_YES) {
1192 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1193 if (c == KEY_RESIZE) {
1194 resize_wide_boxes(level, win);
1197 (void) waddstr(win, keyname((wchar_t) c));
1199 (void) waddstr(win, key_name((wchar_t) c));
1200 if (c < 256 && iscntrl(c)) {
1201 (void) wprintw(win, " (control character)");
1203 (void) wprintw(win, " = %#x (printable character)",
1207 wgetch_wrap(win, first_y);
1214 init_getch(win, flags, delay);
1220 int delay = begin_getch_test();
1223 wget_wch_test(0, stdscr, delay);
1225 finish_getch_test();
1230 /****************************************************************************
1232 * Character attributes test
1234 ****************************************************************************/
1236 #if HAVE_SETUPTERM || HAVE_TGETENT
1237 #define get_ncv() TIGETNUM("ncv","NC")
1238 #define get_xmc() TIGETNUM("xmc","sg")
1240 #define get_ncv() -1
1241 #define get_xmc() -1
1248 static int first = TRUE;
1249 static chtype result = 0;
1255 char *area_pointer = parsed;
1257 tgetent(buffer, getenv("TERM"));
1260 if (TIGETSTR("smso", "so"))
1261 result |= A_STANDOUT;
1262 if (TIGETSTR("smul", "us"))
1263 result |= A_UNDERLINE;
1264 if (TIGETSTR("rev", "mr"))
1265 result |= A_REVERSE;
1266 if (TIGETSTR("blink", "mb"))
1268 if (TIGETSTR("dim", "mh"))
1270 if (TIGETSTR("bold", "md"))
1272 if (TIGETSTR("smacs", "ac"))
1273 result |= A_ALTCHARSET;
1279 #define termattrs() my_termattrs()
1282 #define ATTRSTRING_1ST 32 /* ' ' */
1283 #define ATTRSTRING_END 126 /* '~' */
1285 #define COLS_PRE_ATTRS 5
1286 #define COLS_AFT_ATTRS 15
1287 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1288 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1289 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1291 static char attr_test_string[MAX_ATTRSTRING + 1];
1294 attr_legend(WINDOW *helpwin)
1299 MvWPrintw(helpwin, row++, col,
1301 MvWPrintw(helpwin, row++, col,
1304 MvWPrintw(helpwin, row++, col,
1305 "Modify the test strings:");
1306 MvWPrintw(helpwin, row++, col,
1307 " A digit sets gaps on each side of displayed attributes");
1308 MvWPrintw(helpwin, row++, col,
1309 " </> shifts the text left/right. ");
1311 MvWPrintw(helpwin, row++, col,
1314 MvWPrintw(helpwin, row++, col,
1315 " f/F/b/B toggle foreground/background background color");
1316 MvWPrintw(helpwin, row++, col,
1317 " t/T toggle text/background color attribute");
1319 MvWPrintw(helpwin, row++, col,
1320 " a/A toggle ACS (alternate character set) mapping");
1321 MvWPrintw(helpwin, row, col,
1322 " v/V toggle video attribute to combine with each line");
1323 #if USE_WIDEC_SUPPORT
1324 MvWPrintw(helpwin, row, col,
1325 " w/W toggle normal/wide (double-width) test-characters");
1330 show_color_attr(int fg, int bg, int tx)
1333 printw(" Colors (fg %d, bg %d", fg, bg);
1335 printw(", text %d", tx);
1341 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1348 *fg = (NCURSES_COLOR_T) (*fg + 1);
1351 *fg = (NCURSES_COLOR_T) (*fg - 1);
1354 *bg = (NCURSES_COLOR_T) (*bg + 1);
1357 *bg = (NCURSES_COLOR_T) (*bg - 1);
1360 *tx = (NCURSES_COLOR_T) (*tx + 1);
1363 *tx = (NCURSES_COLOR_T) (*tx - 1);
1371 *fg = (NCURSES_COLOR_T) min_colors;
1372 if (*fg < min_colors)
1373 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1375 *bg = (NCURSES_COLOR_T) min_colors;
1376 if (*bg < min_colors)
1377 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1381 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1390 adjust_attr_string(int adjust)
1392 char save = attr_test_string[0];
1393 int first = ((int) UChar(save)) + adjust;
1396 if (first >= ATTRSTRING_1ST) {
1397 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1398 if (k > ATTRSTRING_END)
1400 attr_test_string[j] = (char) k;
1401 if (((k + 1 - first) % 5) == 0) {
1402 if (++j >= MAX_ATTRSTRING)
1404 attr_test_string[j] = ' ';
1407 if ((LEN_ATTRSTRING - j) > 5) {
1408 attr_test_string[0] = save;
1409 adjust_attr_string(adjust - 1);
1411 while (j < MAX_ATTRSTRING)
1412 attr_test_string[j++] = ' ';
1413 attr_test_string[j] = '\0';
1419 * Prefer the right-end of the string for starting, since that maps to the
1420 * VT100 line-drawing.
1423 default_attr_string(void)
1425 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1426 result += (LEN_ATTRSTRING / 5);
1427 if (result < ATTRSTRING_1ST)
1428 result = ATTRSTRING_1ST;
1433 init_attr_string(void)
1435 attr_test_string[0] = (char) default_attr_string();
1436 adjust_attr_string(0);
1440 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1442 int ncv = get_ncv();
1443 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1446 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1447 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1448 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1450 printw("%*s", skip, " ");
1452 * Just for testing, write text using the alternate character set one
1453 * character at a time (to pass its rendition directly), and use the
1454 * string operation for the other attributes.
1458 if (attr & A_ALTCHARSET) {
1462 for (s = attr_test_string; *s != '\0'; ++s) {
1464 (void) waddch(win, ch | attr);
1467 (void) wattrset(win, AttrArg(attr, 0));
1468 (void) waddstr(win, attr_test_string);
1469 (void) wattroff(win, (int) attr);
1472 printw("%*s", skip, " ");
1473 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1474 if (test != A_NORMAL) {
1475 if (!(termattrs() & test)) {
1478 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1479 static const chtype table[] =
1498 for (n = 0; n < SIZEOF(table); n++) {
1499 if ((table[n] & attr) != 0
1500 && ((1 << n) & ncv) != 0) {
1508 if ((termattrs() & test) != test) {
1518 NCURSES_CONST char *name;
1521 static const ATTR_TBL attrs_to_test[] = {
1522 { A_STANDOUT, "STANDOUT" },
1523 { A_REVERSE, "REVERSE" },
1525 { A_UNDERLINE, "UNDERLINE" },
1527 { A_BLINK, "BLINK" },
1528 { A_PROTECT, "PROTECT" },
1530 { A_INVIS, "INVISIBLE" },
1533 { A_ITALIC, "ITALIC" },
1535 { A_NORMAL, "NORMAL" },
1540 init_attr_list(ATTR_TBL * target, attr_t attrs)
1542 unsigned result = 0;
1545 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1546 attr_t test = attrs_to_test[n].attr;
1547 if (test == A_NORMAL || (test & attrs) != 0) {
1548 target[result++] = attrs_to_test[n];
1555 attr_getc(int *skip,
1556 NCURSES_COLOR_T *fg,
1557 NCURSES_COLOR_T *bg,
1558 NCURSES_COLOR_T *tx,
1571 if (ch < 256 && isdigit(ch)) {
1579 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1581 attr_legend(helpwin);
1604 adjust_attr_string(-1);
1607 adjust_attr_string(1);
1613 error = cycle_color_attr(ch, fg, bg, tx);
1623 /* test text attributes */
1626 int skip = get_xmc();
1627 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1628 NCURSES_COLOR_T bg = COLOR_BLACK;
1629 NCURSES_COLOR_T tx = -1;
1632 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1633 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1634 unsigned my_size = init_attr_list(my_list, termattrs());
1637 for (j = 0; j < my_size; ++j) {
1638 my_wins[j] = subwin(stdscr,
1640 2 + (int) (2 * j), COL_ATTRSTRING);
1641 scrollok(my_wins[j], FALSE);
1647 n = skip; /* make it easy */
1653 chtype normal = A_NORMAL | BLANK;
1654 chtype extras = (chtype) ac;
1657 NCURSES_PAIRS_T pair = 0;
1658 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1660 if (init_pair(pair, fg, bg) == ERR) {
1663 normal |= (chtype) COLOR_PAIR(pair);
1668 if (init_pair(pair, tx, bg) == ERR) {
1671 extras |= (chtype) COLOR_PAIR(pair);
1681 MvAddStr(0, 20, "Character attribute test display");
1683 for (j = 0; j < my_size; ++j) {
1684 bool arrow = (j == k);
1685 row = show_attr(my_wins[j], row, n, arrow,
1693 MvPrintw(row, COLS_PRE_ATTRS,
1694 "This terminal does %shave the magic-cookie glitch",
1695 get_xmc() > -1 ? "" : "not ");
1696 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1697 show_color_attr(fg, bg, tx);
1698 printw(" ACS (%d)", ac != 0);
1701 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1703 bkgdset(A_NORMAL | BLANK);
1707 Cannot("does not support video attributes.");
1711 #if USE_WIDEC_SUPPORT
1712 static bool use_fullwidth;
1713 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1715 #define FULL_LO 0xff00
1716 #define FULL_HI 0xff5e
1717 #define HALF_LO 0x20
1719 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1720 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1721 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1724 * Returns an ASCII code in [32..126]
1727 normal_wchar(int ch)
1729 wchar_t result = (wchar_t) ch;
1730 if (isFullWidth(ch))
1731 result = ToNormalWidth(ch);
1736 * Returns either an ASCII code in in [32..126] or full-width in
1737 * [0xff00..0xff5e], according to use_fullwidth setting.
1740 target_wchar(int ch)
1742 wchar_t result = (wchar_t) ch;
1743 if (use_fullwidth) {
1744 if (!isFullWidth(ch))
1745 result = ToFullWidth(ch);
1747 if (isFullWidth(ch))
1748 result = ToNormalWidth(ch);
1754 wide_adjust_attr_string(int adjust)
1756 wchar_t save = wide_attr_test_string[0];
1757 int first = ((int) normal_wchar(save)) + adjust;
1760 if (first >= ATTRSTRING_1ST) {
1761 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1762 if (k > ATTRSTRING_END)
1764 wide_attr_test_string[j] = target_wchar(k);
1765 if (((k + 1 - first) % 5) == 0) {
1766 if (++j >= MAX_ATTRSTRING)
1768 wide_attr_test_string[j] = ' ';
1771 if ((LEN_ATTRSTRING - j) > 5) {
1772 wide_attr_test_string[0] = save;
1773 wide_adjust_attr_string(adjust - 1);
1775 while (j < MAX_ATTRSTRING)
1776 wide_attr_test_string[j++] = ' ';
1777 wide_attr_test_string[j] = '\0';
1783 wide_init_attr_string(void)
1785 use_fullwidth = FALSE;
1786 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1787 wide_adjust_attr_string(0);
1791 set_wide_background(NCURSES_PAIRS_T pair)
1798 setcchar(&normal, blank, A_NORMAL, pair, 0);
1804 get_wide_background(void)
1806 attr_t result = A_NORMAL;
1809 NCURSES_PAIRS_T pair;
1812 memset(&ch, 0, sizeof(ch));
1813 if (getbkgrnd(&ch) != ERR) {
1814 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1822 wide_show_attr(WINDOW *win,
1827 NCURSES_PAIRS_T pair,
1830 int ncv = get_ncv();
1831 chtype test = attr & ~WA_ALTCHARSET;
1834 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1835 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1836 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1838 printw("%*s", skip, " ");
1841 * Just for testing, write text using the alternate character set one
1842 * character at a time (to pass its rendition directly), and use the
1843 * string operation for the other attributes.
1847 if (attr & WA_ALTCHARSET) {
1851 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1855 setcchar(&ch, fill, attr, pair, 0);
1856 (void) wadd_wch(win, &ch);
1859 attr_t old_attr = 0;
1860 NCURSES_PAIRS_T old_pair = 0;
1862 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1863 (void) wattr_set(win, attr, pair, 0);
1864 (void) waddwstr(win, wide_attr_test_string);
1865 (void) wattr_set(win, old_attr, old_pair, 0);
1868 printw("%*s", skip, " ");
1869 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1870 if (test != A_NORMAL) {
1871 if (!(term_attrs() & test)) {
1874 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1875 static const attr_t table[] =
1889 for (n = 0; n < SIZEOF(table); n++) {
1890 if ((table[n] & attr) != 0
1891 && ((1 << n) & ncv) != 0) {
1899 if ((term_attrs() & test) != test) {
1908 wide_attr_getc(int *skip,
1909 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1910 NCURSES_COLOR_T *tx, int *ac,
1911 unsigned *kc, unsigned limit)
1921 if (ch < 256 && isdigit(ch)) {
1929 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1930 box_set(helpwin, 0, 0);
1931 attr_legend(helpwin);
1954 use_fullwidth = FALSE;
1955 wide_adjust_attr_string(0);
1958 use_fullwidth = TRUE;
1959 wide_adjust_attr_string(0);
1962 wide_adjust_attr_string(-1);
1965 wide_adjust_attr_string(1);
1971 error = cycle_color_attr(ch, fg, bg, tx);
1980 wide_attr_test(void)
1981 /* test text attributes using wide-character calls */
1984 int skip = get_xmc();
1985 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1986 NCURSES_COLOR_T bg = COLOR_BLACK;
1987 NCURSES_COLOR_T tx = -1;
1990 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1991 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1992 unsigned my_size = init_attr_list(my_list, term_attrs());
1995 for (j = 0; j < my_size; ++j) {
1996 my_wins[j] = subwin(stdscr,
1998 2 + (int) (2 * j), COL_ATTRSTRING);
1999 scrollok(my_wins[j], FALSE);
2005 n = skip; /* make it easy */
2007 wide_init_attr_string();
2011 NCURSES_PAIRS_T pair = 0;
2012 NCURSES_PAIRS_T extras = 0;
2015 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2018 if (init_pair(pair, fg, bg) == ERR) {
2025 if (init_pair(extras, tx, bg) == ERR) {
2030 set_wide_background(pair);
2033 box_set(stdscr, 0, 0);
2034 MvAddStr(0, 20, "Character attribute test display");
2036 for (j = 0; j < my_size; ++j) {
2037 row = wide_show_attr(my_wins[j], row, n, (j == k),
2045 MvPrintw(row, COLS_PRE_ATTRS,
2046 "This terminal does %shave the magic-cookie glitch",
2047 get_xmc() > -1 ? "" : "not ");
2048 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2049 show_color_attr(fg, bg, tx);
2050 printw(" ACS (%d)", ac != 0);
2053 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2055 set_wide_background(0);
2059 Cannot("does not support extended video attributes.");
2064 /****************************************************************************
2066 * Color support tests
2068 ****************************************************************************/
2070 static NCURSES_CONST char *the_color_names[] =
2091 show_color_name(int y, int x, int color, bool wide)
2093 if (move(y, x) != ERR) {
2098 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2101 } else if (color >= 8) {
2102 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2104 } else if (color < 0) {
2105 _nc_STRCPY(temp, "default", sizeof(temp));
2107 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2108 "%.*s", 16, the_color_names[color]);
2110 printw("%-*.*s", width, width, temp);
2115 color_legend(WINDOW *helpwin, bool wide)
2120 MvWPrintw(helpwin, row++, col,
2123 MvWPrintw(helpwin, row++, col,
2124 "Use up/down arrow to scroll through the display if it is");
2125 MvWPrintw(helpwin, row++, col,
2126 "longer than one screen. Control/N and Control/P can be used");
2127 MvWPrintw(helpwin, row++, col,
2128 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2129 MvWPrintw(helpwin, row++, col,
2130 "full screen; control/B and control/F can be used here.");
2132 MvWPrintw(helpwin, row++, col,
2134 MvWPrintw(helpwin, row++, col,
2135 " a/A toggle altcharset off/on");
2136 MvWPrintw(helpwin, row++, col,
2137 " b/B toggle bold off/on");
2139 MvWPrintw(helpwin, row++, col,
2140 " c/C cycle used-colors through 8,16,...,COLORS");
2142 MvWPrintw(helpwin, row++, col,
2143 " n/N toggle text/number on/off");
2144 MvWPrintw(helpwin, row++, col,
2145 " r/R toggle reverse on/off");
2146 MvWPrintw(helpwin, row++, col,
2147 " w/W toggle width between 8/16 colors");
2148 #if USE_WIDEC_SUPPORT
2150 MvWPrintw(helpwin, row++, col,
2151 "Wide characters:");
2152 MvWPrintw(helpwin, row, col,
2153 " x/X toggle text between ASCII and wide-character");
2160 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2163 color_cycle(int current, int step)
2165 int result = current;
2171 if ((result * 2) > COLORS) {
2174 while ((result * 2) < current) {
2180 if (current >= COLORS) {
2185 if (result > COLORS)
2191 /* generate a color test pattern */
2198 int grid_top = top + 3;
2199 int page_size = (LINES - grid_top);
2201 int colors_max = COLORS;
2208 bool opt_acsc = FALSE;
2209 bool opt_bold = FALSE;
2210 bool opt_revs = FALSE;
2211 bool opt_nums = FALSE;
2212 bool opt_wide = FALSE;
2215 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2216 done = ((COLS < 16) || (numbered == 0));
2219 * Because the number of colors is usually a power of two, we also use
2220 * a power of two for the number of colors shown per line (to be tidy).
2222 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2227 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2228 if (colors_max * colors_max <= COLOR_PAIRS) {
2229 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2230 if (pairs_max > limit)
2233 if (pairs_max > COLOR_PAIRS)
2234 pairs_max = COLOR_PAIRS;
2237 /* this assumes an 80-column line */
2241 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2245 per_row = (col_limit / 8);
2247 per_row -= min_colors;
2249 row_limit = (pairs_max + per_row - 1) / per_row;
2252 (void) printw("There are %d color pairs and %d colors",
2254 if (colors_max != COLORS)
2255 (void) printw(" (using %d colors)", colors_max);
2257 (void) addstr(" besides 'default'");
2260 MvPrintw(top + 1, 0,
2261 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2264 opt_bold ? "on" : "off");
2266 /* show color names/numbers across the top */
2267 for (i = 0; i < per_row; i++)
2268 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2270 /* show a grid of colors, with color names/ numbers on the left */
2271 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2272 int row = grid_top + (i / per_row) - base_row;
2273 int col = (i % per_row + 1) * width;
2274 NCURSES_PAIRS_T pair = i;
2276 if ((i / per_row) > row_limit)
2279 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - min_colors)) + min_colors)
2280 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - min_colors)) + min_colors)
2281 if (row >= 0 && move(row, col) != ERR) {
2282 NCURSES_COLOR_T fg = InxToFG(i);
2283 NCURSES_COLOR_T bg = InxToBG(i);
2285 init_pair(pair, fg, bg);
2286 attron(COLOR_PAIR(pair));
2288 attron(A_ALTCHARSET);
2295 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2299 printw("%-*.*s", width, width, hello);
2300 (void) attrset(A_NORMAL);
2302 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2303 show_color_name(row, 0, InxToBG(i), opt_wide);
2311 switch (wGetchar(stdscr)) {
2325 colors_max = color_cycle(colors_max, -1);
2328 colors_max = color_cycle(colors_max, 1);
2346 set_color_test(opt_wide, FALSE);
2349 set_color_test(opt_wide, TRUE);
2353 if (base_row <= 0) {
2361 if (base_row + page_size >= row_limit) {
2370 if (base_row <= 0) {
2373 base_row -= (page_size - 1);
2381 if (base_row + page_size >= row_limit) {
2384 base_row += page_size - 1;
2385 if (base_row + page_size >= row_limit) {
2386 base_row = row_limit - page_size - 1;
2391 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2393 color_legend(helpwin, FALSE);
2410 #if USE_WIDEC_SUPPORT
2411 /* generate a color test pattern */
2413 wide_color_test(void)
2418 int grid_top = top + 3;
2419 int page_size = (LINES - grid_top);
2420 int pairs_max = (unsigned short) (-1);
2421 int colors_max = COLORS;
2428 bool opt_acsc = FALSE;
2429 bool opt_bold = FALSE;
2430 bool opt_revs = FALSE;
2431 bool opt_wide = FALSE;
2432 bool opt_nums = FALSE;
2433 bool opt_xchr = FALSE;
2434 wchar_t *buffer = 0;
2437 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2438 buffer = (wchar_t *) calloc((size_t) (COLS + 1), sizeof(wchar_t));
2439 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2442 * Because the number of colors is usually a power of two, we also use
2443 * a power of two for the number of colors shown per line (to be tidy).
2445 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2450 pairs_max = (unsigned short) (-1);
2451 if (colors_max * colors_max <= COLOR_PAIRS) {
2452 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2453 if (pairs_max > limit)
2456 if (pairs_max > COLOR_PAIRS)
2457 pairs_max = COLOR_PAIRS;
2463 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2467 per_row = (col_limit / 8);
2469 per_row -= min_colors;
2472 make_fullwidth_text(buffer, hello);
2476 make_narrow_text(buffer, hello);
2479 row_limit = (pairs_max + per_row - 1) / per_row;
2482 (void) printw("There are %d color pairs and %d colors",
2484 if (colors_max != COLORS)
2485 (void) printw(" (using %d colors)", colors_max);
2487 (void) addstr(" besides 'default'");
2490 MvPrintw(top + 1, 0,
2491 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2494 opt_bold ? "on" : "off");
2496 /* show color names/numbers across the top */
2497 for (i = 0; i < per_row; i++)
2498 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2500 /* show a grid of colors, with color names/ numbers on the left */
2501 for (i = (base_row * per_row); i < pairs_max; i++) {
2502 int row = grid_top + (i / per_row) - base_row;
2503 int col = (i % per_row + 1) * width;
2504 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2506 if ((i / per_row) > row_limit)
2509 if (row >= 0 && move(row, col) != ERR) {
2510 init_pair(pair, InxToFG(i), InxToBG(i));
2511 (void) color_set(pair, NULL);
2513 attr_on(A_ALTCHARSET, NULL);
2515 attr_on(A_BOLD, NULL);
2517 attr_on(A_REVERSE, NULL);
2520 _nc_SPRINTF(numbered,
2521 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2524 make_fullwidth_text(buffer, numbered);
2526 make_narrow_text(buffer, numbered);
2529 addnwstr(buffer, width);
2530 (void) attr_set(A_NORMAL, 0, NULL);
2532 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2533 show_color_name(row, 0, InxToBG(i), opt_wide);
2541 switch (wGetchar(stdscr)) {
2555 colors_max = color_cycle(colors_max, -1);
2558 colors_max = color_cycle(colors_max, 1);
2576 set_color_test(opt_wide, FALSE);
2579 set_color_test(opt_wide, TRUE);
2589 if (base_row <= 0) {
2597 if (base_row + page_size >= row_limit) {
2606 if (base_row <= 0) {
2609 base_row -= (page_size - 1);
2617 if (base_row + page_size >= row_limit) {
2620 base_row += page_size - 1;
2621 if (base_row + page_size >= row_limit) {
2622 base_row = row_limit - page_size - 1;
2627 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2629 color_legend(helpwin, TRUE);
2646 #endif /* USE_WIDEC_SUPPORT */
2649 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2651 NCURSES_COLOR_T red, green, blue;
2653 color_content(current, &red, &green, &blue);
2657 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2660 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2663 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2667 if (init_color(current, red, green, blue) == ERR)
2672 reset_all_colors(void)
2676 for (c = 0; c < COLORS; ++c)
2679 all_colors[c].green,
2680 all_colors[c].blue);
2683 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
2684 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2685 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2688 init_all_colors(bool xterm_colors, char *palette_file)
2691 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
2693 failed("all_colors");
2694 for (cp = 0; cp < max_colors; ++cp) {
2696 &all_colors[cp].red,
2697 &all_colors[cp].green,
2698 &all_colors[cp].blue);
2700 /* xterm and compatible terminals can read results of an OSC string
2701 * asking for the current color palette.
2706 char result[BUFSIZ];
2708 unsigned check_r, check_g, check_b;
2712 for (n = 0; n < max_colors; ++n) {
2713 fprintf(stderr, "\033]4;%d;?\007", n);
2714 got = (int) read(0, result, sizeof(result) - 1);
2718 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2724 all_colors[n].red = DecodeRGB(check_r);
2725 all_colors[n].green = DecodeRGB(check_g);
2726 all_colors[n].blue = DecodeRGB(check_b);
2733 if (palette_file != 0) {
2734 FILE *fp = fopen(palette_file, "r");
2736 char buffer[BUFSIZ];
2737 int red, green, blue;
2740 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2741 if (sscanf(buffer, "scale:%d", &c) == 1) {
2743 } else if (sscanf(buffer, "%d:%d %d %d",
2752 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2753 all_colors[c].red = Scaled(red);
2754 all_colors[c].green = Scaled(green);
2755 all_colors[c].blue = Scaled(blue);
2763 #define scaled_rgb(n) ((255 * (n)) / 1000)
2767 /* display the color test pattern, without trying to edit colors */
2771 int this_c, value, field;
2785 page_size = (LINES - 6);
2788 for (i = 0; i < max_colors; i++)
2789 init_pair((NCURSES_PAIRS_T) i,
2790 (NCURSES_COLOR_T) COLOR_WHITE,
2791 (NCURSES_COLOR_T) i);
2793 MvPrintw(LINES - 2, 0, "Number: %d", value);
2796 NCURSES_COLOR_T red, green, blue;
2799 MvAddStr(0, 20, "Color RGB Value Editing");
2802 for (i = (NCURSES_COLOR_T) top_color;
2803 (i - top_color < page_size)
2804 && (i < max_colors); i++) {
2807 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2808 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2809 (i == current ? '>' : ' '),
2810 (i < (int) SIZEOF(the_color_names)
2811 ? the_color_names[i] : numeric));
2812 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2814 (void) attrset(A_NORMAL);
2816 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2818 if (current == i && field == 0)
2820 printw("%04d", (int) red);
2821 if (current == i && field == 0)
2822 (void) attrset(A_NORMAL);
2824 if (current == i && field == 1)
2826 printw("%04d", (int) green);
2827 if (current == i && field == 1)
2828 (void) attrset(A_NORMAL);
2830 if (current == i && field == 2)
2832 printw("%04d", (int) blue);
2833 if (current == i && field == 2)
2834 (void) attrset(A_NORMAL);
2835 (void) attrset(A_NORMAL);
2836 printw(" ( %3d %3d %3d )",
2837 (int) scaled_rgb(red),
2838 (int) scaled_rgb(green),
2839 (int) scaled_rgb(blue));
2842 MvAddStr(LINES - 3, 0,
2843 "Use up/down to select a color, left/right to change fields.");
2844 MvAddStr(LINES - 2, 0,
2845 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2847 move(2 + current - top_color, 0);
2851 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2873 current -= (page_size - 1);
2880 if (current < (max_colors - 1))
2881 current += (page_size - 1);
2888 current = (current == 0 ? (max_colors - 1) : current - 1);
2893 current = (current == (max_colors - 1) ? 0 : current + 1);
2898 field = (field == 2 ? 0 : field + 1);
2903 field = (field == 0 ? 2 : field - 1);
2916 value = value * 10 + (this_c - '0');
2920 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2924 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2928 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2933 P(" RGB Value Editing Help");
2935 P("You are in the RGB value editor. Use the arrow keys to select one of");
2936 P("the fields in one of the RGB triples of the current colors; the one");
2937 P("currently selected will be reverse-video highlighted.");
2939 P("To change a field, enter the digits of the new value; they are echoed");
2940 P("as entered. Finish by typing `='. The change will take effect instantly.");
2941 P("To increment or decrement a value, use the same procedure, but finish");
2942 P("with a `+' or `-'.");
2944 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
2946 P("Press 'm' to invoke the top-level menu with the current color settings.");
2947 P("To quit, do ESC");
2956 for (i = 0; i < max_colors; i++)
2957 init_pair((NCURSES_PAIRS_T) i,
2958 (NCURSES_COLOR_T) COLOR_WHITE,
2959 (NCURSES_COLOR_T) i);
2973 if (current >= max_colors)
2974 current = max_colors - 1;
2975 if (current < top_color)
2976 top_color = current;
2977 if (current - top_color >= page_size)
2978 top_color = current - (page_size - 1);
2980 MvPrintw(LINES - 1, 0, "Number: %d", value);
2983 (!isQuit(this_c, TRUE));
2988 * ncurses does not reset each color individually when calling endwin().
2995 /****************************************************************************
2997 * Alternate character-set stuff
2999 ****************************************************************************/
3001 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3007 if ((*at_code += 1) >= limit)
3012 *at_code = limit - 1;
3021 *attr = list[*at_code].attr;
3026 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3028 bool result = FALSE;
3038 if ((*fg += 1) >= COLORS)
3046 if ((*bg += 1) >= COLORS)
3054 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3057 if (init_pair(*pair,
3058 (NCURSES_COLOR_T) *fg,
3059 (NCURSES_COLOR_T) *bg) == ERR) {
3068 /****************************************************************************
3070 * Soft-key label test
3072 ****************************************************************************/
3077 #define SLK_WORK (SLK_HELP + 3)
3082 static const char *table[] =
3084 "Available commands are:"
3086 ,"^L -- repaint this message and activate soft keys"
3087 ,"a/d -- activate/disable soft keys"
3088 ,"c -- set centered format for labels"
3089 ,"l -- set left-justified format for labels"
3090 ,"r -- set right-justified format for labels"
3091 ,"[12345678] -- set label; labels are numbered 1 through 8"
3092 ,"e -- erase stdscr (should not erase labels)"
3093 ,"s -- test scrolling of shortened screen"
3094 ,"v/V -- cycle through video attributes"
3096 ,"F/f/B/b -- cycle through foreground/background colors"
3098 ,"ESC -- return to main menu"
3100 ,"Note: if activating the soft keys causes your terminal to scroll up"
3101 ,"one line, your terminal auto-scrolls when anything is written to the"
3102 ,"last screen position. The ncurses code does not yet handle this"
3108 for (j = 0; j < SIZEOF(table); ++j) {
3116 call_slk_color(int fg, int bg)
3118 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3120 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3130 /* exercise the soft keys */
3135 chtype attr = A_NORMAL;
3136 unsigned at_code = 0;
3138 int fg = COLOR_BLACK;
3139 int bg = COLOR_WHITE;
3140 NCURSES_PAIRS_T pair = 0;
3142 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3143 unsigned my_size = init_attr_list(my_list, termattrs());
3148 call_slk_color(fg, bg);
3158 MvAddStr(0, 20, "Soft Key Exerciser");
3173 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3174 while ((c = Getchar()) != 'Q' && (c != ERR))
3202 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3203 _nc_STRCPY(buf, "", sizeof(buf));
3204 if ((s = slk_label(c - '0')) != 0) {
3205 _nc_STRNCPY(buf, s, (size_t) 8);
3207 wGetstring(stdscr, buf, 8);
3208 slk_set((c - '0'), buf, fmt);
3217 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3219 wnoutrefresh(stdscr);
3224 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3231 if (cycle_colors(c, &fg, &bg, &pair)) {
3233 call_slk_color(fg, bg);
3243 } while (!isQuit(c = Getchar(), TRUE));
3251 #if USE_WIDEC_SUPPORT
3255 /* exercise the soft keys */
3258 wchar_t buf[SLKLEN + 1];
3260 chtype attr = A_NORMAL;
3261 unsigned at_code = 0;
3262 int fg = COLOR_BLACK;
3263 int bg = COLOR_WHITE;
3264 NCURSES_PAIRS_T pair = 0;
3265 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3266 unsigned my_size = init_attr_list(my_list, term_attrs());
3270 call_slk_color(fg, bg);
3277 attr_on(WA_BOLD, NULL);
3278 MvAddStr(0, 20, "Soft Key Exerciser");
3279 attr_off(WA_BOLD, NULL);
3293 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3294 while ((c = Getchar()) != 'Q' && (c != ERR))
3322 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3324 if ((s = slk_label(c - '0')) != 0) {
3325 char *temp = strdup(s);
3326 size_t used = strlen(temp);
3327 size_t want = SLKLEN;
3329 #ifndef state_unused
3334 while (want > 0 && used != 0) {
3335 const char *base = s;
3336 reset_mbytes(state);
3337 test = count_mbytes(base, 0, &state);
3338 if (test == (size_t) -1) {
3340 } else if (test > want) {
3343 reset_mbytes(state);
3344 trans_mbytes(buf, base, want, &state);
3350 wGet_wstring(stdscr, buf, SLKLEN);
3351 slk_wset((c - '0'), buf, fmt);
3362 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3363 call_slk_color(fg, bg);
3368 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3369 call_slk_color(fg, bg);
3372 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3374 wnoutrefresh(stdscr);
3378 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3379 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3385 if (cycle_colors(c, &fg, &bg, &pair)) {
3387 call_slk_color(fg, bg);
3397 } while (!isQuit(c = Getchar(), TRUE));
3405 #endif /* SLK_INIT */
3408 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3411 unsigned last = 255;
3417 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3422 for (code = first; code <= last; ++code) {
3423 int row = (int) (2 + (code / 16));
3424 int col = (int) (5 * (code % 16));
3425 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3426 for (count = 1; count < repeat; ++count) {
3427 AddCh(colored_chtype(code, attr, pair));
3434 * Show a slice of 32 characters, allowing those to be repeated up to the
3437 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3438 * terminal to perform functions. The remaining codes can be graphic.
3441 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3444 unsigned first = (unsigned) base;
3445 unsigned last = first + (unsigned) pagesize - 2;
3446 bool C1 = (first == 128);
3451 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3452 C1 ? "C1" : "GR", first, last);
3456 for (code = first; code <= last; code++) {
3458 int row = 2 + ((int) (code - first) % (pagesize / 2));
3459 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3461 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3462 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3466 nodelay(stdscr, TRUE);
3467 echochar(colored_chtype(code, attr, pair));
3469 /* (yes, this _is_ crude) */
3470 while ((reply = Getchar()) != ERR) {
3471 AddCh(UChar(reply));
3474 nodelay(stdscr, FALSE);
3476 } while (--count > 0);
3483 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3489 MvPrintw(0, 20, "Display of PC Character Codes");
3493 for (code = 0; code < 16; ++code) {
3494 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3496 for (code = 0; code < 256; code++) {
3498 int row = 3 + (int) (code / 16) + (code >= 128);
3499 int col = 8 + (int) (code % 16) * PC_COLS;
3500 if ((code % 16) == 0)
3501 MvPrintw(row, 0, "0x%02x:", code);
3512 * Skip the ones that do not work.
3516 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3519 } while (--count > 0);
3524 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3528 attr |= (attr_t) COLOR_PAIR(pair);
3532 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3537 colored_chtype(ACS_VLINE, attr, pair),
3538 colored_chtype(ACS_VLINE, attr, pair),
3539 colored_chtype(ACS_HLINE, attr, pair),
3540 colored_chtype(ACS_HLINE, attr, pair),
3541 colored_chtype(ACS_ULCORNER, attr, pair),
3542 colored_chtype(ACS_URCORNER, attr, pair),
3543 colored_chtype(ACS_LLCORNER, attr, pair),
3544 colored_chtype(ACS_LRCORNER, attr, pair));
3545 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3546 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3547 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3548 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3549 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3550 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3551 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3557 show_1_acs(int n, int repeat, const char *name, chtype code)
3559 const int height = 16;
3560 int row = 2 + (n % height);
3561 int col = (n / height) * COLS / 2;
3563 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3566 } while (--repeat > 0);
3571 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3572 /* display the ACS character set */
3576 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3580 MvAddStr(0, 20, "Display of the ACS Character Set");
3584 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3585 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3586 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3587 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3589 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3590 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3591 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3592 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3594 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3595 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3598 * HPUX's ACS definitions are broken here. Just give up.
3600 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3601 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3602 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3603 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3604 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3606 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3607 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3608 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3609 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3610 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3611 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3612 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3613 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3614 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3616 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3617 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3618 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3620 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3621 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3622 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3623 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3624 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3625 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3634 char *term = getenv("TERM");
3635 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3638 chtype attr = A_NORMAL;
3641 int fg = COLOR_BLACK;
3642 int bg = COLOR_BLACK;
3643 unsigned at_code = 0;
3644 NCURSES_PAIRS_T pair = 0;
3645 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3646 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3647 unsigned my_size = init_attr_list(my_list, termattrs());
3655 ToggleAcs(last_show_acs, show_acs_chars);
3659 ToggleAcs(last_show_acs, show_pc_chars);
3664 if (pagesize == 32) {
3671 ToggleAcs(last_show_acs, show_box_chars);
3697 if (repeat < (COLS / 4))
3705 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3706 || cycle_colors(c, &fg, &bg, &pair)) {
3713 if (pagesize != 32) {
3714 show_256_chars(repeat, attr, pair);
3715 } else if (last_show_acs != 0) {
3716 last_show_acs(repeat, attr, pair);
3718 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3721 MvPrintw(LINES - 3, 0,
3722 "Note: ANSI terminals may not display C1 characters.");
3723 MvPrintw(LINES - 2, 0,
3724 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3727 MvPrintw(LINES - 1, 0,
3728 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3729 my_list[at_code].name,
3732 MvPrintw(LINES - 1, 0,
3733 "v/V cycles through video attributes (%s).",
3734 my_list[at_code].name);
3737 } while (!isQuit(c = Getchar(), TRUE));
3744 #if USE_WIDEC_SUPPORT
3746 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3752 TEST_CCHAR(src, count, {
3753 attr |= (test_attrs & A_ALTCHARSET);
3754 setcchar(dst, test_wch, attr, pair, NULL);
3764 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3765 * display. If there are no repeats, we could normally display 16 lines of 64
3766 * characters (1024 total). However, taking repeats and double-width cells
3767 * into account, use 256 characters for the page.
3770 show_paged_widechars(int base,
3775 NCURSES_PAIRS_T pair)
3777 int first = base * pagesize;
3778 int last = first + pagesize - 1;
3786 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3789 for (code = (wchar_t) first; (int) code <= last; code++) {
3790 int row = (2 + ((int) code - first) / per_line);
3791 int col = 5 * ((int) code % per_line);
3794 memset(&codes, 0, sizeof(codes));
3796 setcchar(&temp, codes, attr, pair, 0);
3798 if (wcwidth(code) == 0 && code != 0) {
3799 AddCh((chtype) space |
3800 (A_REVERSE ^ attr) |
3801 (attr_t) COLOR_PAIR(pair));
3804 for (count = 1; count < repeat; ++count) {
3811 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3815 int last = first + 31;
3819 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3822 for (code = (wchar_t) first; (int) code <= last; code++) {
3823 int row = 2 + ((code - first) % 16);
3824 int col = ((code - first) / 16) * COLS / 2;
3830 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
3831 "%3ld (0x%lx)", (long) code, (long) code);
3832 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3834 memset(&codes, 0, sizeof(codes));
3836 setcchar(&temp, codes, attr, pair, 0);
3840 * Give non-spacing characters something to combine with. If we
3841 * don't, they'll bunch up in a heap on the space after the ":".
3842 * Mark them with reverse-video to make them simpler to find on
3845 if (wcwidth(code) == 0) {
3846 AddCh((chtype) space |
3847 (A_REVERSE ^ attr) |
3848 (attr_t) COLOR_PAIR(pair));
3851 * This uses echo_wchar(), for comparison with the normal 'f'
3852 * test (and to make a test-case for echo_wchar()). The screen
3853 * may flicker because the erase() at the top of the function
3854 * is met by the builtin refresh() in echo_wchar().
3858 * The repeat-count may make text wrap - avoid that.
3860 getyx(stdscr, y, x);
3862 if (x >= col + (COLS / 2) - 2)
3864 } while (--count > 0);
3869 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3871 const int height = 16;
3872 int row = 2 + (n % height);
3873 int col = (n / height) * COLS / 2;
3875 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3876 while (--repeat >= 0) {
3882 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3885 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3886 /* display the wide-ACS character set */
3892 /*#define BOTH2(name) #name, &(name) */
3893 #define BOTH2(name) #name, MERGE_ATTR(name)
3897 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3901 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3902 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3903 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3904 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3906 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3907 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3908 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3909 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3911 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3912 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3914 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3915 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3916 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3917 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3919 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3920 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3921 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3922 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3923 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3924 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3925 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3926 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3927 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3929 #ifdef CURSES_WACS_ARRAY
3930 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3931 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3932 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3934 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3935 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3936 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3937 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3938 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3939 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3945 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3946 /* display the wide-ACS character set */
3952 /*#define BOTH2(name) #name, &(name) */
3953 #define BOTH2(name) #name, MERGE_ATTR(name)
3957 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3961 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3962 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3963 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3964 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3966 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3967 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3968 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3969 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3971 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3972 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3974 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3975 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3976 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3977 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3979 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3980 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3981 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3982 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3983 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3984 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3985 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3986 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3987 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3989 #ifdef CURSES_WACS_ARRAY
3990 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3991 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3992 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3994 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3995 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3996 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3997 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3998 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3999 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4006 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4007 /* display the wide-ACS character set */
4013 /*#define BOTH2(name) #name, &(name) */
4014 #define BOTH2(name) #name, MERGE_ATTR(name)
4018 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4022 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4023 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4024 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4025 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4027 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4028 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4029 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4030 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4032 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4033 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4035 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4036 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4037 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4038 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4040 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4041 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4042 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4043 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4044 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4045 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4046 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4047 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4048 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4050 #ifdef CURSES_WACS_ARRAY
4051 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4052 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4053 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4055 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4056 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4057 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4058 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4059 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4060 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4067 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4070 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4077 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4082 MERGE_ATTR(0, WACS_VLINE),
4083 MERGE_ATTR(1, WACS_VLINE),
4084 MERGE_ATTR(2, WACS_HLINE),
4085 MERGE_ATTR(3, WACS_HLINE),
4086 MERGE_ATTR(4, WACS_ULCORNER),
4087 MERGE_ATTR(5, WACS_URCORNER),
4088 MERGE_ATTR(6, WACS_LLCORNER),
4089 MERGE_ATTR(7, WACS_LRCORNER));
4091 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4092 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4093 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4094 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4095 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4096 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4097 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4105 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4107 const int height = 16;
4108 int row = 2 + (n % height);
4109 int col = (n / height) * COLS / 2;
4112 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4113 (void) attr_set(attr, pair, 0);
4114 _nc_STRNCPY(temp, code, 20);
4116 (void) attr_set(A_NORMAL, 0, 0);
4120 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4123 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4130 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4134 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4135 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4136 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4137 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4139 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4140 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4141 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4142 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4144 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4145 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4147 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4148 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4149 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4150 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4152 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4153 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4154 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4155 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4156 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4157 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4158 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4159 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4160 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4161 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4162 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4163 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4165 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4166 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4167 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4168 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4169 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4170 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4175 /* display the wide-ACS character set */
4177 wide_acs_display(void)
4184 chtype attr = A_NORMAL;
4185 int fg = COLOR_BLACK;
4186 int bg = COLOR_BLACK;
4187 unsigned at_code = 0;
4188 NCURSES_PAIRS_T pair = 0;
4189 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4190 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
4191 unsigned my_size = init_attr_list(my_list, term_attrs());
4199 ToggleAcs(last_show_wacs, show_wacs_chars);
4203 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4208 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4212 if (pagesize == 32) {
4219 ToggleAcs(last_show_wacs, show_wbox_chars);
4222 ToggleAcs(last_show_wacs, show_utf8_chars);
4225 if (c < 256 && isdigit(c)) {
4228 } else if (c == '+') {
4231 } else if (c == '-' && digit > 0) {
4234 } else if (c == '>' && repeat < (COLS / 4)) {
4236 } else if (c == '<' && repeat > 1) {
4238 } else if (c == '_') {
4239 space = (space == ' ') ? '_' : ' ';
4241 } else if (cycle_attr(c, &at_code, &attr, my_list, my_size)
4242 || cycle_colors(c, &fg, &bg, &pair)) {
4243 if (last_show_wacs != 0)
4251 if (pagesize != 32) {
4252 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4253 } else if (last_show_wacs != 0) {
4254 last_show_wacs(repeat, attr, pair);
4256 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4259 MvPrintw(LINES - 4, 0,
4260 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
4261 MvPrintw(LINES - 3, 2,
4262 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4264 MvPrintw(LINES - 2, 2,
4265 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4266 my_list[at_code].name,
4269 MvPrintw(LINES - 2, 2,
4270 "v/V cycles through video attributes (%s).",
4271 my_list[at_code].name);
4274 } while (!isQuit(c = Getchar(), TRUE));
4284 * Graphic-rendition test (adapted from vttest)
4287 test_sgr_attributes(void)
4291 for (pass = 0; pass < 2; pass++) {
4292 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4294 /* Use non-default colors if possible to exercise bce a little */
4296 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4297 normal |= (chtype) COLOR_PAIR(1);
4301 MvPrintw(1, 20, "Graphic rendition test pattern:");
4303 MvPrintw(4, 1, "vanilla");
4305 #define set_sgr(mask) bkgdset((normal^(mask)));
4307 MvPrintw(4, 40, "bold");
4309 set_sgr(A_UNDERLINE);
4310 MvPrintw(6, 6, "underline");
4312 set_sgr(A_BOLD | A_UNDERLINE);
4313 MvPrintw(6, 45, "bold underline");
4316 MvPrintw(8, 1, "blink");
4318 set_sgr(A_BLINK | A_BOLD);
4319 MvPrintw(8, 40, "bold blink");
4321 set_sgr(A_UNDERLINE | A_BLINK);
4322 MvPrintw(10, 6, "underline blink");
4324 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4325 MvPrintw(10, 45, "bold underline blink");
4328 MvPrintw(12, 1, "negative");
4330 set_sgr(A_BOLD | A_REVERSE);
4331 MvPrintw(12, 40, "bold negative");
4333 set_sgr(A_UNDERLINE | A_REVERSE);
4334 MvPrintw(14, 6, "underline negative");
4336 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4337 MvPrintw(14, 45, "bold underline negative");
4339 set_sgr(A_BLINK | A_REVERSE);
4340 MvPrintw(16, 1, "blink negative");
4342 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4343 MvPrintw(16, 40, "bold blink negative");
4345 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4346 MvPrintw(18, 6, "underline blink negative");
4348 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4349 MvPrintw(18, 45, "bold underline blink negative");
4352 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4358 bkgdset(A_NORMAL | BLANK);
4363 /****************************************************************************
4365 * Windows and scrolling tester.
4367 ****************************************************************************/
4369 #define BOTLINES 4 /* number of line stolen from screen bottom */
4375 #define FRAME struct frame
4384 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4385 #if (NCURSES_VERSION_PATCH < 20070331)
4386 #define is_keypad(win) (win)->_use_keypad
4387 #define is_scrollok(win) (win)->_scroll
4390 #define is_keypad(win) FALSE
4391 #define is_scrollok(win) FALSE
4395 frame_win(FRAME * curp)
4397 return (curp != 0) ? curp->wind : stdscr;
4400 /* We need to know if these flags are actually set, so don't look in FRAME.
4401 * These names are known to work with SVr4 curses as well as ncurses. The
4402 * _use_keypad name does not work with Solaris 8.
4405 HaveKeypad(FRAME * curp)
4407 WINDOW *win = frame_win(curp);
4409 return is_keypad(win);
4413 HaveScroll(FRAME * curp)
4415 WINDOW *win = frame_win(curp);
4417 return is_scrollok(win);
4421 newwin_legend(FRAME * curp)
4423 #define DATA(num, name) { name, num }
4424 static const struct {
4428 DATA(0, "^C = create window"),
4429 DATA(0, "^N = next window"),
4430 DATA(0, "^P = previous window"),
4431 DATA(0, "^F = scroll forward"),
4432 DATA(0, "^B = scroll backward"),
4433 DATA(1, "^K = keypad(%s)"),
4434 DATA(2, "^S = scrollok(%s)"),
4435 DATA(0, "^W = save window"),
4436 DATA(0, "^R = restore window"),
4438 DATA(0, "^X = resize"),
4440 DATA(3, "^Q%s = exit")
4445 bool do_keypad = HaveKeypad(curp);
4446 bool do_scroll = HaveScroll(curp);
4450 for (n = 0; n < SIZEOF(legend); n++) {
4451 switch (legend[n].code) {
4453 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4456 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4457 legend[n].msg, do_keypad ? "yes" : "no");
4460 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4461 legend[n].msg, do_scroll ? "yes" : "no");
4464 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))