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.460 2017/09/09 22:52:38 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
84 #define NCURSES_CONST_PARAM char
86 #define mmask_t chtype /* not specified in XSI */
89 #ifdef CURSES_ACS_ARRAY
90 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
91 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
92 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
93 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
94 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
95 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
96 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
98 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
99 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
100 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
101 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
102 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
103 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
104 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
109 #ifdef CURSES_WACS_ARRAY
110 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
111 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
112 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
113 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
114 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
115 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
116 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
123 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
124 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
125 #define reset_wchars(state) init_mb(state)
126 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
127 #define count_wchars(src, len, state) wcstombs(0, src, len)
128 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
129 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
134 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
135 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
136 #define reset_mbytes(state) init_mb(state)
137 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
138 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
139 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
140 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
144 #define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real)
146 #define P(string) printw("%s\n", string)
148 #define BLANK ' ' /* this is the background character */
151 static int max_colors; /* the actual number of colors we'll use */
152 static int min_colors; /* the minimum color code */
153 static bool use_colors; /* 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 void failed(const char *s) GCC_NORETURN;
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;
216 Trace(("TOGGLE-TRACING ON"));
223 #define Getchar() wGetchar(stdscr)
225 /* replaces wgetnstr(), since we want to be able to edit values */
227 wGetstring(WINDOW *win, char *buffer, int limit)
234 (void) wattrset(win, A_REVERSE);
236 x = (int) strlen(buffer);
238 if (x > (int) strlen(buffer))
239 x = (int) strlen(buffer);
241 wprintw(win, "%-*s", limit, buffer);
242 wmove(win, y0, x0 + x);
243 switch (ch = wGetchar(win)) {
256 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
274 if (!isprint(ch) || ch >= KEY_MIN) {
276 } else if ((int) strlen(buffer) < limit) {
278 for (j = (int) strlen(buffer) + 1; j > x; --j) {
279 buffer[j] = buffer[j - 1];
281 buffer[x++] = (char) ch;
288 wattroff(win, A_REVERSE);
293 #if USE_WIDEC_SUPPORT
295 fullwidth_digit(int ch)
297 return (wchar_t) (ch + 0xff10 - '0');
301 make_fullwidth_text(wchar_t *target, const char *source)
304 while ((ch = *source++) != 0) {
305 *target++ = fullwidth_digit(ch);
311 make_narrow_text(wchar_t *target, const char *source)
314 while ((ch = *source++) != 0) {
315 *target++ = (wchar_t) ch;
322 make_fullwidth_digit(cchar_t *target, int digit)
326 source[0] = fullwidth_digit(digit + '0');
328 setcchar(target, source, A_NORMAL, 0, 0);
333 wGet_wchar(WINDOW *win, wint_t *result)
337 while ((c = wget_wch(win, result)) == CTRL('T')) {
339 save_trace = _nc_tracing;
340 Trace(("TOGGLE-TRACING OFF"));
343 _nc_tracing = save_trace;
347 Trace(("TOGGLE-TRACING ON"));
350 c = wget_wch(win, result);
354 #define Get_wchar(result) wGet_wchar(stdscr, result)
356 /* replaces wgetn_wstr(), since we want to be able to edit values */
358 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
367 (void) wattrset(win, A_REVERSE);
369 x = (int) wcslen(buffer);
371 if (x > (int) wcslen(buffer))
372 x = (int) wcslen(buffer);
374 /* clear the "window' */
376 wprintw(win, "%*s", limit, " ");
378 /* write the existing buffer contents */
380 waddnwstr(win, buffer, limit);
382 /* positions the cursor past character 'x' */
384 waddnwstr(win, buffer, x);
386 switch (wGet_wchar(win, &ch)) {
426 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
446 } else if ((int) wcslen(buffer) < limit) {
448 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
449 buffer[j] = buffer[j - 1];
451 buffer[x++] = (wchar_t) ch;
458 wattroff(win, A_REVERSE);
469 addstr("Press any key to continue... ");
474 Cannot(const char *what)
476 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
481 ShellOut(bool message)
484 addstr("Shelling out...");
490 IGNORE_RC(system("sh"));
493 addstr("returned from shellout.\n");
497 #ifdef NCURSES_MOUSE_VERSION
499 * This function is the same as _tracemouse(), but we cannot count on that
500 * being available in the non-debug library.
503 mouse_decode(MEVENT const *ep)
505 static char buf[80 + (5 * 10) + (32 * 15)];
507 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
508 "id %2d at (%2d, %2d, %d) state %4lx = {",
509 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
512 if ((ep->bstate & m)==m) { \
513 _nc_STRCAT(buf, s, sizeof(buf)); \
514 _nc_STRCAT(buf, ", ", sizeof(buf)); \
517 SHOW(BUTTON1_RELEASED, "release-1");
518 SHOW(BUTTON1_PRESSED, "press-1");
519 SHOW(BUTTON1_CLICKED, "click-1");
520 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
521 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
522 #if NCURSES_MOUSE_VERSION == 1
523 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
526 SHOW(BUTTON2_RELEASED, "release-2");
527 SHOW(BUTTON2_PRESSED, "press-2");
528 SHOW(BUTTON2_CLICKED, "click-2");
529 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
530 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
531 #if NCURSES_MOUSE_VERSION == 1
532 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
535 SHOW(BUTTON3_RELEASED, "release-3");
536 SHOW(BUTTON3_PRESSED, "press-3");
537 SHOW(BUTTON3_CLICKED, "click-3");
538 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
539 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
540 #if NCURSES_MOUSE_VERSION == 1
541 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
544 SHOW(BUTTON4_RELEASED, "release-4");
545 SHOW(BUTTON4_PRESSED, "press-4");
546 SHOW(BUTTON4_CLICKED, "click-4");
547 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
548 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
549 #if NCURSES_MOUSE_VERSION == 1
550 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
553 #if NCURSES_MOUSE_VERSION == 2
554 SHOW(BUTTON5_RELEASED, "release-5");
555 SHOW(BUTTON5_PRESSED, "press-5");
556 SHOW(BUTTON5_CLICKED, "click-5");
557 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
558 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
561 SHOW(BUTTON_CTRL, "ctrl");
562 SHOW(BUTTON_SHIFT, "shift");
563 SHOW(BUTTON_ALT, "alt");
564 SHOW(ALL_MOUSE_EVENTS, "all-events");
565 SHOW(REPORT_MOUSE_POSITION, "position");
569 if (buf[strlen(buf) - 1] == ' ')
570 buf[strlen(buf) - 2] = '\0';
571 _nc_STRCAT(buf, "}", sizeof(buf));
576 show_mouse(WINDOW *win)
584 outside = !wenclose(win, event.y, event.x);
587 (void) wstandout(win);
588 waddstr(win, "KEY_MOUSE");
589 (void) wstandend(win);
591 waddstr(win, "KEY_MOUSE");
593 wprintw(win, ", %s", mouse_decode(&event));
598 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
602 wmove(win, event.y, event.x);
610 #endif /* NCURSES_MOUSE_VERSION */
612 /****************************************************************************
614 * Character input test
616 ****************************************************************************/
618 #define NUM_GETCH_FLAGS 256
619 typedef bool GetchFlags[NUM_GETCH_FLAGS];
622 setup_getch(WINDOW *win, GetchFlags flags)
624 keypad(win, flags['k']); /* should be redundant, but for testing */
625 meta(win, flags['m']); /* force this to a known state */
633 init_getch(WINDOW *win, GetchFlags flags, int delay)
635 memset(flags, FALSE, NUM_GETCH_FLAGS);
636 flags[UChar('k')] = (win == stdscr);
637 flags[UChar('m')] = TRUE;
638 flags[UChar('t')] = (delay != 0);
640 setup_getch(win, flags);
644 blocking_getch(GetchFlags flags, int delay)
646 return ((delay < 0) && flags['t']);
649 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
652 wgetch_help(WINDOW *win, GetchFlags flags)
654 static const char *help[] =
656 "e -- toggle echo mode"
657 ,"g -- triggers a getstr test"
658 ,"k -- toggle keypad/literal mode"
659 ,"m -- toggle meta (7-bit/8-bit) mode"
662 ,"t -- toggle timeout"
663 ,"w -- create a new window"
665 ,"z -- suspend this process"
669 unsigned chk = ((SIZEOF(help) + 1) / 2);
674 printw("Type any key to see its %s value. Also:\n",
675 flags['k'] ? "keypad" : "literal");
676 for (n = 0; n < SIZEOF(help); ++n) {
677 const char *msg = help[n];
678 int row = 1 + (int) (n % chk);
679 int col = (n >= chk) ? COLS / 2 : 0;
680 int flg = ((strstr(msg, "toggle") != 0)
681 && (flags[UChar(*msg)] != FALSE));
682 if (*msg == '^' && ExitOnEscape())
683 msg = "^[,^q -- quit";
686 MvPrintw(row, col, "%s", msg);
697 wgetch_wrap(WINDOW *win, int first_y)
699 int last_y = getmaxy(win) - 1;
700 int y = getcury(win) + 1;
708 #if defined(KEY_RESIZE) && HAVE_WRESIZE
714 static WINSTACK *winstack = 0;
715 static unsigned len_winstack = 0;
728 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
730 unsigned need = (level + 1) * 2;
732 assert(level < (unsigned) COLS);
736 winstack = typeMalloc(WINSTACK, len_winstack);
737 } else if (need >= len_winstack) {
739 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
742 failed("remember_boxes");
743 winstack[level].text = txt_win;
744 winstack[level].frame = box_win;
747 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
751 /* this chunk is now done in resize_term() */
758 #define slk_repaint() /* nothing */
761 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
763 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
764 * Resize both and paint the box in the parent.
767 resize_boxes(unsigned level, WINDOW *win)
771 int high = LINES - base;
775 wnoutrefresh(stdscr);
779 for (n = 0; n < level; ++n) {
780 wresize(winstack[n].frame, high, wide);
781 wresize(winstack[n].text, high - 2, wide - 2);
784 werase(winstack[n].text);
785 box(winstack[n].frame, 0, 0);
786 wnoutrefresh(winstack[n].frame);
787 wprintw(winstack[n].text,
789 getmaxy(winstack[n].text),
790 getmaxx(winstack[n].text));
791 wnoutrefresh(winstack[n].text);
792 if (winstack[n].text == win)
797 #endif /* resize_boxes */
799 #define forget_boxes() /* nothing */
800 #define remember_boxes(level,text,frame) /* nothing */
804 * Return-code is OK/ERR or a keyname.
809 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
813 wgetch_test(unsigned level, WINDOW *win, int delay)
816 int first_y, first_x;
821 init_getch(win, flags, delay);
822 notimeout(win, FALSE);
823 wtimeout(win, delay);
824 getyx(win, first_y, first_x);
826 wgetch_help(win, flags);
827 wsetscrreg(win, first_y, getmaxy(win) - 1);
831 while ((c = wGetchar(win)) == ERR) {
833 if (blocking_getch(flags, delay)) {
834 (void) wprintw(win, "%05d: input error", incount);
837 (void) wprintw(win, "%05d: input timed out", incount);
839 wgetch_wrap(win, first_y);
841 if (c == ERR && blocking_getch(flags, delay)) {
843 wgetch_wrap(win, first_y);
844 } else if (isQuit(c, ExitOnEscape())) {
846 } else if (c == 'e') {
847 flags[UChar('e')] = !flags[UChar('e')];
848 setup_getch(win, flags);
849 wgetch_help(win, flags);
850 } else if (c == 'g') {
851 waddstr(win, "getstr test: ");
853 c = wgetnstr(win, buf, sizeof(buf) - 1);
855 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
856 (int) strlen(buf), buf,
859 wgetch_wrap(win, first_y);
860 } else if (c == 'k') {
861 flags[UChar('k')] = !flags[UChar('k')];
862 setup_getch(win, flags);
863 wgetch_help(win, flags);
864 } else if (c == 'm') {
865 flags[UChar('m')] = !flags[UChar('m')];
866 setup_getch(win, flags);
867 wgetch_help(win, flags);
868 } else if (c == 's') {
870 } else if (c == 't') {
871 notimeout(win, flags[UChar('t')]);
872 flags[UChar('t')] = !flags[UChar('t')];
873 wgetch_help(win, flags);
874 } else if (c == 'w') {
875 int high = getmaxy(win) - 1 - first_y + 1;
876 int wide = getmaxx(win) - first_x;
878 int new_y = first_y + getbegy(win);
879 int new_x = first_x + getbegx(win);
881 getyx(win, old_y, old_x);
882 if (high > 2 && wide > 2) {
883 WINDOW *wb = newwin(high, wide, new_y, new_x);
884 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
889 remember_boxes(level, wi, wb);
890 wgetch_test(level + 1, wi, delay);
894 wgetch_help(win, flags);
895 wmove(win, old_y, old_x);
901 } else if (c == 'z') {
902 kill(getpid(), SIGTSTP);
905 wprintw(win, "Key pressed: %04o ", c);
906 #ifdef NCURSES_MOUSE_VERSION
907 if (c == KEY_MOUSE) {
910 #endif /* NCURSES_MOUSE_VERSION */
912 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
913 if (c == KEY_RESIZE) {
914 resize_boxes(level, win);
917 (void) waddstr(win, keyname(c));
918 } else if (c >= 0x80) {
919 unsigned c2 = (unsigned) c;
920 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
921 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
925 (void) wprintw(win, "%c", UChar(c));
926 else if (c2 != UChar(c))
927 (void) wprintw(win, "M-%s", unctrl(c2));
929 (void) wprintw(win, "%s", unctrl(c2));
930 waddstr(win, " (high-half character)");
933 (void) wprintw(win, "%c (ASCII printable character)", c);
935 (void) wprintw(win, "%s (ASCII control character)",
938 wgetch_wrap(win, first_y);
945 init_getch(win, flags, delay);
949 begin_getch_test(void)
956 #ifdef NCURSES_MOUSE_VERSION
957 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
960 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
962 getnstr(buf, sizeof(buf) - 1);
966 if (isdigit(UChar(buf[0]))) {
967 delay = atoi(buf) * 100;
977 finish_getch_test(void)
979 #ifdef NCURSES_MOUSE_VERSION
980 mousemask(0, (mmask_t *) 0);
991 int delay = begin_getch_test();
994 wgetch_test(0, stdscr, delay);
1000 #if USE_WIDEC_SUPPORT
1002 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1003 * Resize both and paint the box in the parent.
1005 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1007 resize_wide_boxes(unsigned level, WINDOW *win)
1011 int high = LINES - base;
1015 wnoutrefresh(stdscr);
1019 for (n = 0; n < level; ++n) {
1020 wresize(winstack[n].frame, high, wide);
1021 wresize(winstack[n].text, high - 2, wide - 2);
1024 werase(winstack[n].text);
1025 box_set(winstack[n].frame, 0, 0);
1026 wnoutrefresh(winstack[n].frame);
1027 wprintw(winstack[n].text,
1029 getmaxy(winstack[n].text),
1030 getmaxx(winstack[n].text));
1031 wnoutrefresh(winstack[n].text);
1032 if (winstack[n].text == win)
1037 #endif /* KEY_RESIZE */
1040 wcstos(const wchar_t *src)
1044 const wchar_t *tmp = src;
1045 #ifndef state_unused
1049 reset_wchars(state);
1050 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1051 unsigned have = (unsigned) need;
1052 if ((result = typeCalloc(char, have + 1)) != 0) {
1054 if (trans_wchars(result, tmp, have, &state) != have) {
1066 wget_wch_test(unsigned level, WINDOW *win, int delay)
1068 wchar_t wchar_buf[BUFSIZ];
1069 wint_t wint_buf[BUFSIZ];
1070 int first_y, first_x;
1077 init_getch(win, flags, delay);
1078 notimeout(win, FALSE);
1079 wtimeout(win, delay);
1080 getyx(win, first_y, first_x);
1082 wgetch_help(win, flags);
1083 wsetscrreg(win, first_y, getmaxy(win) - 1);
1084 scrollok(win, TRUE);
1087 while ((code = wGet_wchar(win, &c)) == ERR) {
1089 if (blocking_getch(flags, delay)) {
1090 (void) wprintw(win, "%05d: input error", incount);
1093 (void) wprintw(win, "%05d: input timed out", incount);
1095 wgetch_wrap(win, first_y);
1097 if (code == ERR && blocking_getch(flags, delay)) {
1098 wprintw(win, "ERR");
1099 wgetch_wrap(win, first_y);
1100 } else if (isQuit((int) c, ExitOnEscape())) {
1102 } else if (c == 'e') {
1103 flags[UChar('e')] = !flags[UChar('e')];
1104 setup_getch(win, flags);
1105 wgetch_help(win, flags);
1106 } else if (c == 'g') {
1107 waddstr(win, "getstr test: ");
1109 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1112 wprintw(win, "wgetn_wstr returns an error.");
1115 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1118 if ((temp = wcstos(wchar_buf)) != 0) {
1119 wprintw(win, "I saw %d characters:\n\t`%s'.",
1120 (int) wcslen(wchar_buf), temp);
1123 wprintw(win, "I saw %d characters (cannot convert).",
1124 (int) wcslen(wchar_buf));
1128 wgetch_wrap(win, first_y);
1129 } else if (c == 'k') {
1130 flags[UChar('k')] = !flags[UChar('k')];
1131 setup_getch(win, flags);
1132 wgetch_help(win, flags);
1133 } else if (c == 'm') {
1134 flags[UChar('m')] = !flags[UChar('m')];
1135 setup_getch(win, flags);
1136 wgetch_help(win, flags);
1137 } else if (c == 's') {
1139 } else if (c == 't') {
1140 notimeout(win, flags[UChar('t')]);
1141 flags[UChar('t')] = !flags[UChar('t')];
1142 wgetch_help(win, flags);
1143 } else if (c == 'w') {
1144 int high = getmaxy(win) - 1 - first_y + 1;
1145 int wide = getmaxx(win) - first_x;
1147 int new_y = first_y + getbegy(win);
1148 int new_x = first_x + getbegx(win);
1150 getyx(win, old_y, old_x);
1151 if (high > 2 && wide > 2) {
1152 WINDOW *wb = newwin(high, wide, new_y, new_x);
1153 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1158 remember_boxes(level, wi, wb);
1159 wget_wch_test(level + 1, wi, delay);
1163 wgetch_help(win, flags);
1164 wmove(win, old_y, old_x);
1169 } else if (c == 'z') {
1170 kill(getpid(), SIGTSTP);
1173 wprintw(win, "Key pressed: %04o ", (int) c);
1174 #ifdef NCURSES_MOUSE_VERSION
1175 if (c == KEY_MOUSE) {
1178 #endif /* NCURSES_MOUSE_VERSION */
1179 if (code == KEY_CODE_YES) {
1180 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1181 if (c == KEY_RESIZE) {
1182 resize_wide_boxes(level, win);
1185 (void) waddstr(win, keyname((wchar_t) c));
1187 (void) waddstr(win, key_name((wchar_t) c));
1188 if (c < 256 && iscntrl(c)) {
1189 (void) wprintw(win, " (control character)");
1191 (void) wprintw(win, " = %#x (printable character)",
1195 wgetch_wrap(win, first_y);
1202 init_getch(win, flags, delay);
1208 int delay = begin_getch_test();
1211 wget_wch_test(0, stdscr, delay);
1213 finish_getch_test();
1218 /****************************************************************************
1220 * Character attributes test
1222 ****************************************************************************/
1224 #if HAVE_SETUPTERM || HAVE_TGETENT
1225 #define get_ncv() TIGETNUM("ncv","NC")
1226 #define get_xmc() TIGETNUM("xmc","sg")
1228 #define get_ncv() -1
1229 #define get_xmc() -1
1236 static int first = TRUE;
1237 static chtype result = 0;
1243 char *area_pointer = parsed;
1245 tgetent(buffer, getenv("TERM"));
1248 if (TIGETSTR("smso", "so"))
1249 result |= A_STANDOUT;
1250 if (TIGETSTR("smul", "us"))
1251 result |= A_UNDERLINE;
1252 if (TIGETSTR("rev", "mr"))
1253 result |= A_REVERSE;
1254 if (TIGETSTR("blink", "mb"))
1256 if (TIGETSTR("dim", "mh"))
1258 if (TIGETSTR("bold", "md"))
1260 if (TIGETSTR("smacs", "ac"))
1261 result |= A_ALTCHARSET;
1267 #define termattrs() my_termattrs()
1270 #define ATTRSTRING_1ST 32 /* ' ' */
1271 #define ATTRSTRING_END 126 /* '~' */
1273 #define COLS_PRE_ATTRS 5
1274 #define COLS_AFT_ATTRS 15
1275 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1276 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1277 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1279 static char attr_test_string[MAX_ATTRSTRING + 1];
1282 attr_legend(WINDOW *helpwin)
1287 MvWPrintw(helpwin, row++, col,
1289 MvWPrintw(helpwin, row++, col,
1292 MvWPrintw(helpwin, row++, col,
1293 "Modify the test strings:");
1294 MvWPrintw(helpwin, row++, col,
1295 " A digit sets gaps on each side of displayed attributes");
1296 MvWPrintw(helpwin, row++, col,
1297 " </> shifts the text left/right. ");
1299 MvWPrintw(helpwin, row++, col,
1302 MvWPrintw(helpwin, row++, col,
1303 " f/F/b/B toggle foreground/background background color");
1304 MvWPrintw(helpwin, row++, col,
1305 " t/T toggle text/background color attribute");
1307 MvWPrintw(helpwin, row++, col,
1308 " a/A toggle ACS (alternate character set) mapping");
1309 MvWPrintw(helpwin, row, col,
1310 " v/V toggle video attribute to combine with each line");
1311 #if USE_WIDEC_SUPPORT
1312 MvWPrintw(helpwin, row, col,
1313 " w/W toggle normal/wide (double-width) test-characters");
1318 show_color_attr(int fg, int bg, int tx)
1321 printw(" Colors (fg %d, bg %d", fg, bg);
1323 printw(", text %d", tx);
1329 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1336 *fg = (NCURSES_COLOR_T) (*fg + 1);
1339 *fg = (NCURSES_COLOR_T) (*fg - 1);
1342 *bg = (NCURSES_COLOR_T) (*bg + 1);
1345 *bg = (NCURSES_COLOR_T) (*bg - 1);
1348 *tx = (NCURSES_COLOR_T) (*tx + 1);
1351 *tx = (NCURSES_COLOR_T) (*tx - 1);
1359 *fg = (NCURSES_COLOR_T) min_colors;
1360 if (*fg < min_colors)
1361 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1363 *bg = (NCURSES_COLOR_T) min_colors;
1364 if (*bg < min_colors)
1365 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1369 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1378 adjust_attr_string(int adjust)
1380 char save = attr_test_string[0];
1381 int first = ((int) UChar(save)) + adjust;
1384 if (first >= ATTRSTRING_1ST) {
1385 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1386 if (k > ATTRSTRING_END)
1388 attr_test_string[j] = (char) k;
1389 if (((k + 1 - first) % 5) == 0) {
1390 if (++j >= MAX_ATTRSTRING)
1392 attr_test_string[j] = ' ';
1395 if ((LEN_ATTRSTRING - j) > 5) {
1396 attr_test_string[0] = save;
1397 adjust_attr_string(adjust - 1);
1399 while (j < MAX_ATTRSTRING)
1400 attr_test_string[j++] = ' ';
1401 attr_test_string[j] = '\0';
1407 * Prefer the right-end of the string for starting, since that maps to the
1408 * VT100 line-drawing.
1411 default_attr_string(void)
1413 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1414 result += (LEN_ATTRSTRING / 5);
1415 if (result < ATTRSTRING_1ST)
1416 result = ATTRSTRING_1ST;
1421 init_attr_string(void)
1423 attr_test_string[0] = (char) default_attr_string();
1424 adjust_attr_string(0);
1428 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1430 int ncv = get_ncv();
1431 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1434 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1435 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1436 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1438 printw("%*s", skip, " ");
1440 * Just for testing, write text using the alternate character set one
1441 * character at a time (to pass its rendition directly), and use the
1442 * string operation for the other attributes.
1446 if (attr & A_ALTCHARSET) {
1450 for (s = attr_test_string; *s != '\0'; ++s) {
1452 (void) waddch(win, ch | attr);
1455 (void) wattrset(win, AttrArg(attr, 0));
1456 (void) waddstr(win, attr_test_string);
1457 (void) wattroff(win, (int) attr);
1460 printw("%*s", skip, " ");
1461 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1462 if (test != A_NORMAL) {
1463 if (!(termattrs() & test)) {
1466 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1467 static const chtype table[] =
1486 for (n = 0; n < SIZEOF(table); n++) {
1487 if ((table[n] & attr) != 0
1488 && ((1 << n) & ncv) != 0) {
1496 if ((termattrs() & test) != test) {
1506 NCURSES_CONST char *name;
1509 static const ATTR_TBL attrs_to_test[] = {
1510 { A_STANDOUT, "STANDOUT" },
1511 { A_REVERSE, "REVERSE" },
1513 { A_UNDERLINE, "UNDERLINE" },
1515 { A_BLINK, "BLINK" },
1516 { A_PROTECT, "PROTECT" },
1518 { A_INVIS, "INVISIBLE" },
1521 { A_ITALIC, "ITALIC" },
1523 { A_NORMAL, "NORMAL" },
1528 init_attr_list(ATTR_TBL * target, attr_t attrs)
1530 unsigned result = 0;
1533 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1534 attr_t test = attrs_to_test[n].attr;
1535 if (test == A_NORMAL || (test & attrs) != 0) {
1536 target[result++] = attrs_to_test[n];
1543 attr_getc(int *skip,
1544 NCURSES_COLOR_T *fg,
1545 NCURSES_COLOR_T *bg,
1546 NCURSES_COLOR_T *tx,
1559 if (ch < 256 && isdigit(ch)) {
1567 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1569 attr_legend(helpwin);
1592 adjust_attr_string(-1);
1595 adjust_attr_string(1);
1601 error = cycle_color_attr(ch, fg, bg, tx);
1611 /* test text attributes */
1614 int skip = get_xmc();
1615 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1616 NCURSES_COLOR_T bg = COLOR_BLACK;
1617 NCURSES_COLOR_T tx = -1;
1620 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1621 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1622 unsigned my_size = init_attr_list(my_list, termattrs());
1625 for (j = 0; j < my_size; ++j) {
1626 my_wins[j] = subwin(stdscr,
1628 2 + (int) (2 * j), COL_ATTRSTRING);
1629 scrollok(my_wins[j], FALSE);
1635 n = skip; /* make it easy */
1641 chtype normal = A_NORMAL | BLANK;
1642 chtype extras = (chtype) ac;
1645 NCURSES_PAIRS_T pair = 0;
1646 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1648 if (init_pair(pair, fg, bg) == ERR) {
1651 normal |= (chtype) COLOR_PAIR(pair);
1656 if (init_pair(pair, tx, bg) == ERR) {
1659 extras |= (chtype) COLOR_PAIR(pair);
1669 MvAddStr(0, 20, "Character attribute test display");
1671 for (j = 0; j < my_size; ++j) {
1672 bool arrow = (j == k);
1673 row = show_attr(my_wins[j], row, n, arrow,
1681 MvPrintw(row, COLS_PRE_ATTRS,
1682 "This terminal does %shave the magic-cookie glitch",
1683 get_xmc() > -1 ? "" : "not ");
1684 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1685 show_color_attr(fg, bg, tx);
1686 printw(" ACS (%d)", ac != 0);
1689 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1691 bkgdset(A_NORMAL | BLANK);
1695 Cannot("does not support video attributes.");
1699 #if USE_WIDEC_SUPPORT
1700 static bool use_fullwidth;
1701 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1703 #define FULL_LO 0xff00
1704 #define FULL_HI 0xff5e
1705 #define HALF_LO 0x20
1707 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1708 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1709 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1712 * Returns an ASCII code in [32..126]
1715 normal_wchar(int ch)
1717 wchar_t result = (wchar_t) ch;
1718 if (isFullWidth(ch))
1719 result = ToNormalWidth(ch);
1724 * Returns either an ASCII code in in [32..126] or full-width in
1725 * [0xff00..0xff5e], according to use_fullwidth setting.
1728 target_wchar(int ch)
1730 wchar_t result = (wchar_t) ch;
1731 if (use_fullwidth) {
1732 if (!isFullWidth(ch))
1733 result = ToFullWidth(ch);
1735 if (isFullWidth(ch))
1736 result = ToNormalWidth(ch);
1742 wide_adjust_attr_string(int adjust)
1744 wchar_t save = wide_attr_test_string[0];
1745 int first = ((int) normal_wchar(save)) + adjust;
1748 if (first >= ATTRSTRING_1ST) {
1749 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1750 if (k > ATTRSTRING_END)
1752 wide_attr_test_string[j] = target_wchar(k);
1753 if (((k + 1 - first) % 5) == 0) {
1754 if (++j >= MAX_ATTRSTRING)
1756 wide_attr_test_string[j] = ' ';
1759 if ((LEN_ATTRSTRING - j) > 5) {
1760 wide_attr_test_string[0] = save;
1761 wide_adjust_attr_string(adjust - 1);
1763 while (j < MAX_ATTRSTRING)
1764 wide_attr_test_string[j++] = ' ';
1765 wide_attr_test_string[j] = '\0';
1771 wide_init_attr_string(void)
1773 use_fullwidth = FALSE;
1774 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1775 wide_adjust_attr_string(0);
1779 set_wide_background(NCURSES_PAIRS_T pair)
1786 setcchar(&normal, blank, A_NORMAL, pair, 0);
1792 get_wide_background(void)
1794 attr_t result = A_NORMAL;
1797 NCURSES_PAIRS_T pair;
1800 memset(&ch, 0, sizeof(ch));
1801 if (getbkgrnd(&ch) != ERR) {
1802 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1810 wide_show_attr(WINDOW *win,
1815 NCURSES_PAIRS_T pair,
1818 int ncv = get_ncv();
1819 chtype test = attr & ~WA_ALTCHARSET;
1822 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1823 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1824 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1826 printw("%*s", skip, " ");
1829 * Just for testing, write text using the alternate character set one
1830 * character at a time (to pass its rendition directly), and use the
1831 * string operation for the other attributes.
1835 if (attr & WA_ALTCHARSET) {
1839 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1843 setcchar(&ch, fill, attr, pair, 0);
1844 (void) wadd_wch(win, &ch);
1847 attr_t old_attr = 0;
1848 NCURSES_PAIRS_T old_pair = 0;
1850 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1851 (void) wattr_set(win, attr, pair, 0);
1852 (void) waddwstr(win, wide_attr_test_string);
1853 (void) wattr_set(win, old_attr, old_pair, 0);
1856 printw("%*s", skip, " ");
1857 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1858 if (test != A_NORMAL) {
1859 if (!(term_attrs() & test)) {
1862 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1863 static const attr_t table[] =
1877 for (n = 0; n < SIZEOF(table); n++) {
1878 if ((table[n] & attr) != 0
1879 && ((1 << n) & ncv) != 0) {
1887 if ((term_attrs() & test) != test) {
1896 wide_attr_getc(int *skip,
1897 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1898 NCURSES_COLOR_T *tx, int *ac,
1899 unsigned *kc, unsigned limit)
1909 if (ch < 256 && isdigit(ch)) {
1917 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1918 box_set(helpwin, 0, 0);
1919 attr_legend(helpwin);
1942 use_fullwidth = FALSE;
1943 wide_adjust_attr_string(0);
1946 use_fullwidth = TRUE;
1947 wide_adjust_attr_string(0);
1950 wide_adjust_attr_string(-1);
1953 wide_adjust_attr_string(1);
1959 error = cycle_color_attr(ch, fg, bg, tx);
1968 wide_attr_test(void)
1969 /* test text attributes using wide-character calls */
1972 int skip = get_xmc();
1973 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1974 NCURSES_COLOR_T bg = COLOR_BLACK;
1975 NCURSES_COLOR_T tx = -1;
1978 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1979 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1980 unsigned my_size = init_attr_list(my_list, term_attrs());
1983 for (j = 0; j < my_size; ++j) {
1984 my_wins[j] = subwin(stdscr,
1986 2 + (int) (2 * j), COL_ATTRSTRING);
1987 scrollok(my_wins[j], FALSE);
1993 n = skip; /* make it easy */
1995 wide_init_attr_string();
1999 NCURSES_PAIRS_T pair = 0;
2000 NCURSES_PAIRS_T extras = 0;
2003 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2006 if (init_pair(pair, fg, bg) == ERR) {
2013 if (init_pair(extras, tx, bg) == ERR) {
2018 set_wide_background(pair);
2021 box_set(stdscr, 0, 0);
2022 MvAddStr(0, 20, "Character attribute test display");
2024 for (j = 0; j < my_size; ++j) {
2025 row = wide_show_attr(my_wins[j], row, n, (j == k),
2033 MvPrintw(row, COLS_PRE_ATTRS,
2034 "This terminal does %shave the magic-cookie glitch",
2035 get_xmc() > -1 ? "" : "not ");
2036 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2037 show_color_attr(fg, bg, tx);
2038 printw(" ACS (%d)", ac != 0);
2041 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2043 set_wide_background(0);
2047 Cannot("does not support extended video attributes.");
2052 /****************************************************************************
2054 * Color support tests
2056 ****************************************************************************/
2058 static NCURSES_CONST char *the_color_names[] =
2079 show_color_name(int y, int x, int color, bool wide)
2081 if (move(y, x) != ERR) {
2086 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2089 } else if (color >= 8) {
2090 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2092 } else if (color < 0) {
2093 _nc_STRCPY(temp, "default", sizeof(temp));
2095 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2096 "%.*s", 16, the_color_names[color]);
2098 printw("%-*.*s", width, width, temp);
2103 color_legend(WINDOW *helpwin, bool wide)
2108 MvWPrintw(helpwin, row++, col,
2111 MvWPrintw(helpwin, row++, col,
2112 "Use up/down arrow to scroll through the display if it is");
2113 MvWPrintw(helpwin, row++, col,
2114 "longer than one screen. Control/N and Control/P can be used");
2115 MvWPrintw(helpwin, row++, col,
2116 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2117 MvWPrintw(helpwin, row++, col,
2118 "full screen; control/B and control/F can be used here.");
2120 MvWPrintw(helpwin, row++, col,
2122 MvWPrintw(helpwin, row++, col,
2123 " a/A toggle altcharset off/on");
2124 MvWPrintw(helpwin, row++, col,
2125 " b/B toggle bold off/on");
2127 MvWPrintw(helpwin, row++, col,
2128 " c/C cycle used-colors through 8,16,...,COLORS");
2130 MvWPrintw(helpwin, row++, col,
2131 " n/N toggle text/number on/off");
2132 MvWPrintw(helpwin, row++, col,
2133 " r/R toggle reverse on/off");
2134 MvWPrintw(helpwin, row++, col,
2135 " w/W toggle width between 8/16 colors");
2136 #if USE_WIDEC_SUPPORT
2138 MvWPrintw(helpwin, row++, col,
2139 "Wide characters:");
2140 MvWPrintw(helpwin, row, col,
2141 " x/X toggle text between ASCII and wide-character");
2148 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2151 color_cycle(int current, int step)
2153 int result = current;
2159 if ((result * 2) > COLORS) {
2162 while ((result * 2) < current) {
2168 if (current >= COLORS) {
2173 if (result > COLORS)
2179 /* generate a color test pattern */
2186 int grid_top = top + 3;
2187 int page_size = (LINES - grid_top);
2189 int colors_max = COLORS;
2196 bool opt_acsc = FALSE;
2197 bool opt_bold = FALSE;
2198 bool opt_revs = FALSE;
2199 bool opt_nums = FALSE;
2200 bool opt_wide = FALSE;
2203 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2204 done = ((COLS < 16) || (numbered == 0));
2207 * Because the number of colors is usually a power of two, we also use
2208 * a power of two for the number of colors shown per line (to be tidy).
2210 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2215 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2216 if (colors_max * colors_max <= COLOR_PAIRS) {
2217 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2218 if (pairs_max > limit)
2221 if (pairs_max > COLOR_PAIRS)
2222 pairs_max = COLOR_PAIRS;
2225 /* this assumes an 80-column line */
2229 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2233 per_row = (col_limit / 8);
2235 per_row -= min_colors;
2237 row_limit = (pairs_max + per_row - 1) / per_row;
2240 (void) printw("There are %d color pairs and %d colors",
2242 if (colors_max != COLORS)
2243 (void) printw(" (using %d colors)", colors_max);
2245 (void) addstr(" besides 'default'");
2248 MvPrintw(top + 1, 0,
2249 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2252 opt_bold ? "on" : "off");
2254 /* show color names/numbers across the top */
2255 for (i = 0; i < per_row; i++)
2256 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2258 /* show a grid of colors, with color names/ numbers on the left */
2259 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2260 int row = grid_top + (i / per_row) - base_row;
2261 int col = (i % per_row + 1) * width;
2262 NCURSES_PAIRS_T pair = i;
2264 if ((i / per_row) > row_limit)
2267 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - min_colors)) + min_colors)
2268 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - min_colors)) + min_colors)
2269 if (row >= 0 && move(row, col) != ERR) {
2270 NCURSES_COLOR_T fg = InxToFG(i);
2271 NCURSES_COLOR_T bg = InxToBG(i);
2273 init_pair(pair, fg, bg);
2274 attron(COLOR_PAIR(pair));
2276 attron(A_ALTCHARSET);
2283 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2287 printw("%-*.*s", width, width, hello);
2288 (void) attrset(A_NORMAL);
2290 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2291 show_color_name(row, 0, InxToBG(i), opt_wide);
2299 switch (wGetchar(stdscr)) {
2313 colors_max = color_cycle(colors_max, -1);
2316 colors_max = color_cycle(colors_max, 1);
2334 set_color_test(opt_wide, FALSE);
2337 set_color_test(opt_wide, TRUE);
2341 if (base_row <= 0) {
2349 if (base_row + page_size >= row_limit) {
2358 if (base_row <= 0) {
2361 base_row -= (page_size - 1);
2369 if (base_row + page_size >= row_limit) {
2372 base_row += page_size - 1;
2373 if (base_row + page_size >= row_limit) {
2374 base_row = row_limit - page_size - 1;
2379 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2381 color_legend(helpwin, FALSE);
2398 #if USE_WIDEC_SUPPORT
2399 /* generate a color test pattern */
2401 wide_color_test(void)
2406 int grid_top = top + 3;
2407 int page_size = (LINES - grid_top);
2408 int pairs_max = (unsigned short) (-1);
2409 int colors_max = COLORS;
2416 bool opt_acsc = FALSE;
2417 bool opt_bold = FALSE;
2418 bool opt_revs = FALSE;
2419 bool opt_wide = FALSE;
2420 bool opt_nums = FALSE;
2421 bool opt_xchr = FALSE;
2422 wchar_t *buffer = 0;
2425 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2426 buffer = (wchar_t *) calloc((size_t) (COLS + 1), sizeof(wchar_t));
2427 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2430 * Because the number of colors is usually a power of two, we also use
2431 * a power of two for the number of colors shown per line (to be tidy).
2433 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2438 pairs_max = (unsigned short) (-1);
2439 if (colors_max * colors_max <= COLOR_PAIRS) {
2440 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2441 if (pairs_max > limit)
2444 if (pairs_max > COLOR_PAIRS)
2445 pairs_max = COLOR_PAIRS;
2451 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2455 per_row = (col_limit / 8);
2457 per_row -= min_colors;
2460 make_fullwidth_text(buffer, hello);
2464 make_narrow_text(buffer, hello);
2467 row_limit = (pairs_max + per_row - 1) / per_row;
2470 (void) printw("There are %d color pairs and %d colors",
2472 if (colors_max != COLORS)
2473 (void) printw(" (using %d colors)", colors_max);
2475 (void) addstr(" besides 'default'");
2478 MvPrintw(top + 1, 0,
2479 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2482 opt_bold ? "on" : "off");
2484 /* show color names/numbers across the top */
2485 for (i = 0; i < per_row; i++)
2486 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2488 /* show a grid of colors, with color names/ numbers on the left */
2489 for (i = (base_row * per_row); i < pairs_max; i++) {
2490 int row = grid_top + (i / per_row) - base_row;
2491 int col = (i % per_row + 1) * width;
2492 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2494 if ((i / per_row) > row_limit)
2497 if (row >= 0 && move(row, col) != ERR) {
2498 init_pair(pair, InxToFG(i), InxToBG(i));
2499 (void) color_set(pair, NULL);
2501 attr_on(A_ALTCHARSET, NULL);
2503 attr_on(A_BOLD, NULL);
2505 attr_on(A_REVERSE, NULL);
2508 _nc_SPRINTF(numbered,
2509 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2512 make_fullwidth_text(buffer, numbered);
2514 make_narrow_text(buffer, numbered);
2517 addnwstr(buffer, width);
2518 (void) attr_set(A_NORMAL, 0, NULL);
2520 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2521 show_color_name(row, 0, InxToBG(i), opt_wide);
2529 switch (wGetchar(stdscr)) {
2543 colors_max = color_cycle(colors_max, -1);
2546 colors_max = color_cycle(colors_max, 1);
2564 set_color_test(opt_wide, FALSE);
2567 set_color_test(opt_wide, TRUE);
2577 if (base_row <= 0) {
2585 if (base_row + page_size >= row_limit) {
2594 if (base_row <= 0) {
2597 base_row -= (page_size - 1);
2605 if (base_row + page_size >= row_limit) {
2608 base_row += page_size - 1;
2609 if (base_row + page_size >= row_limit) {
2610 base_row = row_limit - page_size - 1;
2615 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2617 color_legend(helpwin, TRUE);
2634 #endif /* USE_WIDEC_SUPPORT */
2636 #if HAVE_COLOR_CONTENT
2638 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2640 NCURSES_COLOR_T red, green, blue;
2642 color_content(current, &red, &green, &blue);
2646 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2649 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2652 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2656 if (init_color(current, red, green, blue) == ERR)
2661 reset_all_colors(void)
2665 for (c = 0; c < COLORS; ++c)
2668 all_colors[c].green,
2669 all_colors[c].blue);
2672 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
2673 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2674 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2677 init_all_colors(bool xterm_colors, char *palette_file)
2680 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
2682 failed("all_colors");
2683 for (cp = 0; cp < max_colors; ++cp) {
2685 &all_colors[cp].red,
2686 &all_colors[cp].green,
2687 &all_colors[cp].blue);
2689 /* xterm and compatible terminals can read results of an OSC string
2690 * asking for the current color palette.
2695 char result[BUFSIZ];
2697 unsigned check_r, check_g, check_b;
2701 for (n = 0; n < max_colors; ++n) {
2702 fprintf(stderr, "\033]4;%d;?\007", n);
2703 got = (int) read(0, result, sizeof(result) - 1);
2707 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2713 all_colors[n].red = DecodeRGB(check_r);
2714 all_colors[n].green = DecodeRGB(check_g);
2715 all_colors[n].blue = DecodeRGB(check_b);
2722 if (palette_file != 0) {
2723 FILE *fp = fopen(palette_file, "r");
2725 char buffer[BUFSIZ];
2726 int red, green, blue;
2729 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2730 if (sscanf(buffer, "scale:%d", &c) == 1) {
2732 } else if (sscanf(buffer, "%d:%d %d %d",
2741 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2742 all_colors[c].red = Scaled(red);
2743 all_colors[c].green = Scaled(green);
2744 all_colors[c].blue = Scaled(blue);
2752 #define scaled_rgb(n) ((255 * (n)) / 1000)
2756 /* display the color test pattern, without trying to edit colors */
2760 int this_c, value, field;
2774 page_size = (LINES - 6);
2777 for (i = 0; i < max_colors; i++)
2778 init_pair((NCURSES_PAIRS_T) i,
2779 (NCURSES_COLOR_T) COLOR_WHITE,
2780 (NCURSES_COLOR_T) i);
2782 MvPrintw(LINES - 2, 0, "Number: %d", value);
2785 NCURSES_COLOR_T red, green, blue;
2788 MvAddStr(0, 20, "Color RGB Value Editing");
2791 for (i = (NCURSES_COLOR_T) top_color;
2792 (i - top_color < page_size)
2793 && (i < max_colors); i++) {
2796 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2797 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2798 (i == current ? '>' : ' '),
2799 (i < (int) SIZEOF(the_color_names)
2800 ? the_color_names[i] : numeric));
2801 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2803 (void) attrset(A_NORMAL);
2805 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2807 if (current == i && field == 0)
2809 printw("%04d", (int) red);
2810 if (current == i && field == 0)
2811 (void) attrset(A_NORMAL);
2813 if (current == i && field == 1)
2815 printw("%04d", (int) green);
2816 if (current == i && field == 1)
2817 (void) attrset(A_NORMAL);
2819 if (current == i && field == 2)
2821 printw("%04d", (int) blue);
2822 if (current == i && field == 2)
2823 (void) attrset(A_NORMAL);
2824 (void) attrset(A_NORMAL);
2825 printw(" ( %3d %3d %3d )",
2826 (int) scaled_rgb(red),
2827 (int) scaled_rgb(green),
2828 (int) scaled_rgb(blue));
2831 MvAddStr(LINES - 3, 0,
2832 "Use up/down to select a color, left/right to change fields.");
2833 MvAddStr(LINES - 2, 0,
2834 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2836 move(2 + current - top_color, 0);
2840 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2862 current -= (page_size - 1);
2869 if (current < (max_colors - 1))
2870 current += (page_size - 1);
2877 current = (current == 0 ? (max_colors - 1) : current - 1);
2882 current = (current == (max_colors - 1) ? 0 : current + 1);
2887 field = (field == 2 ? 0 : field + 1);
2892 field = (field == 0 ? 2 : field - 1);
2905 value = value * 10 + (this_c - '0');
2909 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2913 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2917 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2922 P(" RGB Value Editing Help");
2924 P("You are in the RGB value editor. Use the arrow keys to select one of");
2925 P("the fields in one of the RGB triples of the current colors; the one");
2926 P("currently selected will be reverse-video highlighted.");
2928 P("To change a field, enter the digits of the new value; they are echoed");
2929 P("as entered. Finish by typing `='. The change will take effect instantly.");
2930 P("To increment or decrement a value, use the same procedure, but finish");
2931 P("with a `+' or `-'.");
2933 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
2935 P("Press 'm' to invoke the top-level menu with the current color settings.");
2936 P("To quit, do ESC");
2945 for (i = 0; i < max_colors; i++)
2946 init_pair((NCURSES_PAIRS_T) i,
2947 (NCURSES_COLOR_T) COLOR_WHITE,
2948 (NCURSES_COLOR_T) i);
2962 if (current >= max_colors)
2963 current = max_colors - 1;
2964 if (current < top_color)
2965 top_color = current;
2966 if (current - top_color >= page_size)
2967 top_color = current - (page_size - 1);
2969 MvPrintw(LINES - 1, 0, "Number: %d", value);
2972 (!isQuit(this_c, TRUE));
2977 * ncurses does not reset each color individually when calling endwin().
2983 #endif /* HAVE_COLOR_CONTENT */
2985 /****************************************************************************
2987 * Alternate character-set stuff
2989 ****************************************************************************/
2991 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
2997 if ((*at_code += 1) >= limit)
3002 *at_code = limit - 1;
3011 *attr = list[*at_code].attr;
3016 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3018 bool result = FALSE;
3028 if ((*fg += 1) >= COLORS)
3036 if ((*bg += 1) >= COLORS)
3044 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3047 if (init_pair(*pair,
3048 (NCURSES_COLOR_T) *fg,
3049 (NCURSES_COLOR_T) *bg) == ERR) {
3058 /****************************************************************************
3060 * Soft-key label test
3062 ****************************************************************************/
3067 #define SLK_WORK (SLK_HELP + 3)
3072 static const char *table[] =
3074 "Available commands are:"
3076 ,"^L -- repaint this message and activate soft keys"
3077 ,"a/d -- activate/disable soft keys"
3078 ,"c -- set centered format for labels"
3079 ,"l -- set left-justified format for labels"
3080 ,"r -- set right-justified format for labels"
3081 ,"[12345678] -- set label; labels are numbered 1 through 8"
3082 ,"e -- erase stdscr (should not erase labels)"
3083 ,"s -- test scrolling of shortened screen"
3084 ,"v/V -- cycle through video attributes"
3086 ,"F/f/B/b -- cycle through foreground/background colors"
3088 ,"ESC -- return to main menu"
3090 ,"Note: if activating the soft keys causes your terminal to scroll up"
3091 ,"one line, your terminal auto-scrolls when anything is written to the"
3092 ,"last screen position. The ncurses code does not yet handle this"
3098 for (j = 0; j < SIZEOF(table); ++j) {
3106 call_slk_color(int fg, int bg)
3108 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3110 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3120 /* exercise the soft keys */
3125 chtype attr = A_NORMAL;
3126 unsigned at_code = 0;
3128 int fg = COLOR_BLACK;
3129 int bg = COLOR_WHITE;
3130 NCURSES_PAIRS_T pair = 0;
3132 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3133 unsigned my_size = init_attr_list(my_list, termattrs());
3138 call_slk_color(fg, bg);
3148 MvAddStr(0, 20, "Soft Key Exerciser");
3163 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3164 while ((c = Getchar()) != 'Q' && (c != ERR))
3192 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3193 _nc_STRCPY(buf, "", sizeof(buf));
3194 if ((s = slk_label(c - '0')) != 0) {
3195 _nc_STRNCPY(buf, s, (size_t) 8);
3197 wGetstring(stdscr, buf, 8);
3198 slk_set((c - '0'), buf, fmt);
3207 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3209 wnoutrefresh(stdscr);
3214 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3221 if (cycle_colors(c, &fg, &bg, &pair)) {
3223 call_slk_color(fg, bg);
3233 } while (!isQuit(c = Getchar(), TRUE));
3241 #if USE_WIDEC_SUPPORT
3245 /* exercise the soft keys */
3248 wchar_t buf[SLKLEN + 1];
3250 chtype attr = A_NORMAL;
3251 unsigned at_code = 0;
3252 int fg = COLOR_BLACK;
3253 int bg = COLOR_WHITE;
3254 NCURSES_PAIRS_T pair = 0;
3255 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3256 unsigned my_size = init_attr_list(my_list, term_attrs());
3260 call_slk_color(fg, bg);
3267 attr_on(WA_BOLD, NULL);
3268 MvAddStr(0, 20, "Soft Key Exerciser");
3269 attr_off(WA_BOLD, NULL);
3283 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3284 while ((c = Getchar()) != 'Q' && (c != ERR))
3312 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3314 if ((s = slk_label(c - '0')) != 0) {
3315 char *temp = strdup(s);
3316 size_t used = strlen(temp);
3317 size_t want = SLKLEN;
3319 #ifndef state_unused
3324 while (want > 0 && used != 0) {
3325 const char *base = s;
3326 reset_mbytes(state);
3327 test = count_mbytes(base, 0, &state);
3328 if (test == (size_t) -1) {
3330 } else if (test > want) {
3333 reset_mbytes(state);
3334 trans_mbytes(buf, base, want, &state);
3340 wGet_wstring(stdscr, buf, SLKLEN);
3341 slk_wset((c - '0'), buf, fmt);
3352 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3353 call_slk_color(fg, bg);
3358 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3359 call_slk_color(fg, bg);
3362 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3364 wnoutrefresh(stdscr);
3368 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3369 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3375 if (cycle_colors(c, &fg, &bg, &pair)) {
3377 call_slk_color(fg, bg);
3387 } while (!isQuit(c = Getchar(), TRUE));
3395 #endif /* SLK_INIT */
3398 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3401 unsigned last = 255;
3407 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3412 for (code = first; code <= last; ++code) {
3413 int row = (int) (2 + (code / 16));
3414 int col = (int) (5 * (code % 16));
3415 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3416 for (count = 1; count < repeat; ++count) {
3417 AddCh(colored_chtype(code, attr, pair));
3424 * Show a slice of 32 characters, allowing those to be repeated up to the
3427 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3428 * terminal to perform functions. The remaining codes can be graphic.
3431 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3434 unsigned first = (unsigned) base;
3435 unsigned last = first + (unsigned) pagesize - 2;
3436 bool C1 = (first == 128);
3441 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3442 C1 ? "C1" : "GR", first, last);
3446 for (code = first; code <= last; code++) {
3448 int row = 2 + ((int) (code - first) % (pagesize / 2));
3449 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3451 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3452 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3456 nodelay(stdscr, TRUE);
3457 echochar(colored_chtype(code, attr, pair));
3459 /* (yes, this _is_ crude) */
3460 while ((reply = Getchar()) != ERR) {
3461 AddCh(UChar(reply));
3464 nodelay(stdscr, FALSE);
3466 } while (--count > 0);
3473 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3479 MvPrintw(0, 20, "Display of PC Character Codes");
3483 for (code = 0; code < 16; ++code) {
3484 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3486 for (code = 0; code < 256; code++) {
3488 int row = 3 + (int) (code / 16) + (code >= 128);
3489 int col = 8 + (int) (code % 16) * PC_COLS;
3490 if ((code % 16) == 0)
3491 MvPrintw(row, 0, "0x%02x:", code);
3502 * Skip the ones that do not work.
3506 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3509 } while (--count > 0);
3514 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3518 attr |= (attr_t) COLOR_PAIR(pair);
3522 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3527 colored_chtype(ACS_VLINE, attr, pair),
3528 colored_chtype(ACS_VLINE, attr, pair),
3529 colored_chtype(ACS_HLINE, attr, pair),
3530 colored_chtype(ACS_HLINE, attr, pair),
3531 colored_chtype(ACS_ULCORNER, attr, pair),
3532 colored_chtype(ACS_URCORNER, attr, pair),
3533 colored_chtype(ACS_LLCORNER, attr, pair),
3534 colored_chtype(ACS_LRCORNER, attr, pair));
3535 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3536 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3537 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3538 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3539 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3540 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3541 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3547 show_1_acs(int n, int repeat, const char *name, chtype code)
3549 const int height = 16;
3550 int row = 2 + (n % height);
3551 int col = (n / height) * COLS / 2;
3553 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3556 } while (--repeat > 0);
3561 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3562 /* display the ACS character set */
3566 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3570 MvAddStr(0, 20, "Display of the ACS Character Set");
3574 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3575 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3576 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3577 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3579 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3580 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3581 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3582 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3584 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3585 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3588 * HPUX's ACS definitions are broken here. Just give up.
3590 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3591 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3592 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3593 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3594 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3596 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3597 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3598 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3599 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3600 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3601 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3602 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3603 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3604 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3606 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3607 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3608 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3610 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3611 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3612 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3613 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3614 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3615 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3624 char *term = getenv("TERM");
3625 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3628 chtype attr = A_NORMAL;
3631 int fg = COLOR_BLACK;
3632 int bg = COLOR_BLACK;
3633 unsigned at_code = 0;
3634 NCURSES_PAIRS_T pair = 0;
3635 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3636 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3637 unsigned my_size = init_attr_list(my_list, termattrs());
3645 ToggleAcs(last_show_acs, show_acs_chars);
3649 ToggleAcs(last_show_acs, show_pc_chars);
3654 if (pagesize == 32) {
3661 ToggleAcs(last_show_acs, show_box_chars);
3687 if (repeat < (COLS / 4))
3695 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3696 || cycle_colors(c, &fg, &bg, &pair)) {
3703 if (pagesize != 32) {
3704 show_256_chars(repeat, attr, pair);
3705 } else if (last_show_acs != 0) {
3706 last_show_acs(repeat, attr, pair);
3708 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3711 MvPrintw(LINES - 3, 0,
3712 "Note: ANSI terminals may not display C1 characters.");
3713 MvPrintw(LINES - 2, 0,
3714 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3717 MvPrintw(LINES - 1, 0,
3718 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3719 my_list[at_code].name,
3722 MvPrintw(LINES - 1, 0,
3723 "v/V cycles through video attributes (%s).",
3724 my_list[at_code].name);
3727 } while (!isQuit(c = Getchar(), TRUE));
3734 #if USE_WIDEC_SUPPORT
3736 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3742 TEST_CCHAR(src, count, {
3743 attr |= (test_attrs & A_ALTCHARSET);
3744 setcchar(dst, test_wch, attr, pair, NULL);
3754 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3755 * display. If there are no repeats, we could normally display 16 lines of 64
3756 * characters (1024 total). However, taking repeats and double-width cells
3757 * into account, use 256 characters for the page.
3760 show_paged_widechars(int base,
3765 NCURSES_PAIRS_T pair)
3767 int first = base * pagesize;
3768 int last = first + pagesize - 1;
3776 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3779 for (code = (wchar_t) first; (int) code <= last; code++) {
3780 int row = (2 + ((int) code - first) / per_line);
3781 int col = 5 * ((int) code % per_line);
3784 memset(&codes, 0, sizeof(codes));
3786 setcchar(&temp, codes, attr, pair, 0);
3788 if (wcwidth(code) == 0 && code != 0) {
3789 AddCh((chtype) space |
3790 (A_REVERSE ^ attr) |
3791 (attr_t) COLOR_PAIR(pair));
3794 for (count = 1; count < repeat; ++count) {
3801 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3805 int last = first + 31;
3809 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3812 for (code = (wchar_t) first; (int) code <= last; code++) {
3813 int row = 2 + ((code - first) % 16);
3814 int col = ((code - first) / 16) * COLS / 2;
3820 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp))
3821 "%3ld (0x%lx)", (long) code, (long) code);
3822 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3824 memset(&codes, 0, sizeof(codes));
3826 setcchar(&temp, codes, attr, pair, 0);
3830 * Give non-spacing characters something to combine with. If we
3831 * don't, they'll bunch up in a heap on the space after the ":".
3832 * Mark them with reverse-video to make them simpler to find on
3835 if (wcwidth(code) == 0) {
3836 AddCh((chtype) space |
3837 (A_REVERSE ^ attr) |
3838 (attr_t) COLOR_PAIR(pair));
3841 * This uses echo_wchar(), for comparison with the normal 'f'
3842 * test (and to make a test-case for echo_wchar()). The screen
3843 * may flicker because the erase() at the top of the function
3844 * is met by the builtin refresh() in echo_wchar().
3848 * The repeat-count may make text wrap - avoid that.
3850 getyx(stdscr, y, x);
3852 if (x >= col + (COLS / 2) - 2)
3854 } while (--count > 0);
3859 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3861 const int height = 16;
3862 int row = 2 + (n % height);
3863 int col = (n / height) * COLS / 2;
3865 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3866 while (--repeat >= 0) {
3872 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3875 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3876 /* display the wide-ACS character set */
3882 /*#define BOTH2(name) #name, &(name) */
3883 #define BOTH2(name) #name, MERGE_ATTR(name)
3887 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3891 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3892 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3893 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3894 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3896 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3897 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3898 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3899 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3901 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3902 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3904 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3905 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3906 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3907 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3909 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3910 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3911 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3912 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3913 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3914 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3915 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3916 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3917 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3919 #ifdef CURSES_WACS_ARRAY
3920 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3921 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3922 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3924 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3925 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3926 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3927 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3928 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3929 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3935 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3936 /* display the wide-ACS character set */
3942 /*#define BOTH2(name) #name, &(name) */
3943 #define BOTH2(name) #name, MERGE_ATTR(name)
3947 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3951 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3952 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3953 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3954 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3956 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3957 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3958 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3959 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3961 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3962 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3964 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3965 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3966 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3967 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3969 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3970 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3971 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3972 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3973 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3974 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3975 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3976 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3977 n = show_1_wacs(n, repeat, BOTH2(WACS_D_PLUS));
3979 #ifdef CURSES_WACS_ARRAY
3980 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3981 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3982 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3984 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3985 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3986 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3987 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3988 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3989 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3996 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3997 /* display the wide-ACS character set */
4003 /*#define BOTH2(name) #name, &(name) */
4004 #define BOTH2(name) #name, MERGE_ATTR(name)
4008 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4012 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4013 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4014 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4015 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4017 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4018 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4019 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4020 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4022 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4023 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4025 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4026 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4027 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4028 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4030 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4031 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4032 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4033 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4034 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4035 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4036 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4037 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4038 n = show_1_wacs(n, repeat, BOTH2(WACS_T_PLUS));
4040 #ifdef CURSES_WACS_ARRAY
4041 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4042 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4043 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4045 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4046 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4047 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4048 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4049 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4050 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4057 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4060 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4067 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4072 MERGE_ATTR(0, WACS_VLINE),
4073 MERGE_ATTR(1, WACS_VLINE),
4074 MERGE_ATTR(2, WACS_HLINE),
4075 MERGE_ATTR(3, WACS_HLINE),
4076 MERGE_ATTR(4, WACS_ULCORNER),
4077 MERGE_ATTR(5, WACS_URCORNER),
4078 MERGE_ATTR(6, WACS_LLCORNER),
4079 MERGE_ATTR(7, WACS_LRCORNER));
4081 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4082 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4083 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4084 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4085 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4086 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4087 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4095 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4097 const int height = 16;
4098 int row = 2 + (n % height);
4099 int col = (n / height) * COLS / 2;
4102 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4103 (void) attr_set(attr, pair, 0);
4104 _nc_STRNCPY(temp, code, 20);
4106 (void) attr_set(A_NORMAL, 0, 0);
4110 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4113 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4120 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4124 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4125 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4126 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4127 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4129 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4130 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4131 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4132 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4134 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4135 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4137 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4138 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4139 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4140 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4142 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4143 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4144 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4145 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4146 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4147 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4148 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4149 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4150 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4151 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4152 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4153 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4155 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4156 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4157 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4158 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4159 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4160 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4165 /* display the wide-ACS character set */
4167 wide_acs_display(void)
4174 chtype attr = A_NORMAL;
4175 int fg = COLOR_BLACK;
4176 int bg = COLOR_BLACK;
4177 unsigned at_code = 0;
4178 NCURSES_PAIRS_T pair = 0;
4179 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4180 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
4181 unsigned my_size = init_attr_list(my_list, term_attrs());
4189 ToggleAcs(last_show_wacs, show_wacs_chars);
4193 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4198 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4202 if (pagesize == 32) {
4209 ToggleAcs(last_show_wacs, show_wbox_chars);
4212 ToggleAcs(last_show_wacs, show_utf8_chars);
4215 if (c < 256 && isdigit(c)) {
4218 } else if (c == '+') {
4221 } else if (c == '-' && digit > 0) {
4224 } else if (c == '>' && repeat < (COLS / 4)) {
4226 } else if (c == '<' && repeat > 1) {
4228 } else if (c == '_') {
4229 space = (space == ' ') ? '_' : ' ';
4231 } else if (cycle_attr(c, &at_code, &attr, my_list, my_size)
4232 || cycle_colors(c, &fg, &bg, &pair)) {
4233 if (last_show_wacs != 0)
4241 if (pagesize != 32) {
4242 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4243 } else if (last_show_wacs != 0) {
4244 last_show_wacs(repeat, attr, pair);
4246 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4249 MvPrintw(LINES - 4, 0,
4250 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
4251 MvPrintw(LINES - 3, 2,
4252 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4254 MvPrintw(LINES - 2, 2,
4255 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4256 my_list[at_code].name,
4259 MvPrintw(LINES - 2, 2,
4260 "v/V cycles through video attributes (%s).",
4261 my_list[at_code].name);
4264 } while (!isQuit(c = Getchar(), TRUE));
4274 * Graphic-rendition test (adapted from vttest)
4277 test_sgr_attributes(void)
4281 for (pass = 0; pass < 2; pass++) {
4282 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4284 /* Use non-default colors if possible to exercise bce a little */
4286 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4287 normal |= (chtype) COLOR_PAIR(1);
4291 MvPrintw(1, 20, "Graphic rendition test pattern:");
4293 MvPrintw(4, 1, "vanilla");
4295 #define set_sgr(mask) bkgdset((normal^(mask)));
4297 MvPrintw(4, 40, "bold");
4299 set_sgr(A_UNDERLINE);
4300 MvPrintw(6, 6, "underline");
4302 set_sgr(A_BOLD | A_UNDERLINE);
4303 MvPrintw(6, 45, "bold underline");
4306 MvPrintw(8, 1, "blink");
4308 set_sgr(A_BLINK | A_BOLD);
4309 MvPrintw(8, 40, "bold blink");
4311 set_sgr(A_UNDERLINE | A_BLINK);
4312 MvPrintw(10, 6, "underline blink");
4314 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4315 MvPrintw(10, 45, "bold underline blink");
4318 MvPrintw(12, 1, "negative");
4320 set_sgr(A_BOLD | A_REVERSE);
4321 MvPrintw(12, 40, "bold negative");
4323 set_sgr(A_UNDERLINE | A_REVERSE);
4324 MvPrintw(14, 6, "underline negative");
4326 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4327 MvPrintw(14, 45, "bold underline negative");
4329 set_sgr(A_BLINK | A_REVERSE);
4330 MvPrintw(16, 1, "blink negative");
4332 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4333 MvPrintw(16, 40, "bold blink negative");
4335 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4336 MvPrintw(18, 6, "underline blink negative");
4338 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4339 MvPrintw(18, 45, "bold underline blink negative");
4342 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4348 bkgdset(A_NORMAL | BLANK);
4353 /****************************************************************************
4355 * Windows and scrolling tester.
4357 ****************************************************************************/
4359 #define BOTLINES 4 /* number of line stolen from screen bottom */
4365 #define FRAME struct frame
4374 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4375 #if (NCURSES_VERSION_PATCH < 20070331)
4376 #define is_keypad(win) (win)->_use_keypad
4377 #define is_scrollok(win) (win)->_scroll
4380 #define is_keypad(win) FALSE
4381 #define is_scrollok(win) FALSE
4385 frame_win(FRAME * curp)
4387 return (curp != 0) ? curp->wind : stdscr;
4390 /* We need to know if these flags are actually set, so don't look in FRAME.
4391 * These names are known to work with SVr4 curses as well as ncurses. The
4392 * _use_keypad name does not work with Solaris 8.
4395 HaveKeypad(FRAME * curp)
4397 WINDOW *win = frame_win(curp);
4399 return is_keypad(win);
4403 HaveScroll(FRAME * curp)
4405 WINDOW *win = frame_win(curp);
4407 return is_scrollok(win);
4411 newwin_legend(FRAME * curp)
4413 #define DATA(num, name) { name, num }
4414 static const struct {
4418 DATA(0, "^C = create window"),
4419 DATA(0, "^N = next window"),
4420 DATA(0, "^P = previous window"),
4421 DATA(0, "^F = scroll forward"),
4422 DATA(0, "^B = scroll backward"),
4423 DATA(1, "^K = keypad(%s)"),
4424 DATA(2, "^S = scrollok(%s)"),
4425 DATA(0, "^W = save window"),
4426 DATA(0, "^R = restore window"),
4428 DATA(0, "^X = resize"),
4430 DATA(3, "^Q%s = exit")
4435 bool do_keypad = HaveKeypad(curp);
4436 bool do_scroll = HaveScroll(curp);
4440 for (n = 0; n < SIZEOF(legend); n++) {
4441 switch (legend[n].code) {
4443 _nc_STRCPY(buf, legend[n].msg, sizeof(buf));
4446 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4447 legend[n].msg, do_keypad ? "yes" : "no");
4450 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4451 legend[n].msg, do_scroll ? "yes" : "no");
4454 _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
4455 legend[n].msg, do_keypad ? "/ESC" : "");
4458 x = getcurx(stdscr);
4459 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));