1 /****************************************************************************
2 * Copyright (c) 1998-2014,2015 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.421 2015/10/24 23:32:57 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);
170 failed(const char *s)
174 ExitProgram(EXIT_FAILURE);
177 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
178 * though we can rely on negative x/y values to stop the macro.
181 do_h_line(int y, int x, chtype c, int to)
184 MvHLine(y, x, c, (to) - (x));
188 do_v_line(int y, int x, chtype c, int to)
191 MvVLine(y, x, c, (to) - (y));
205 return ((c) == QUIT || (c) == ESCAPE);
207 #define case_QUIT QUIT: case ESCAPE
209 /* Common function to allow ^T to toggle trace-mode in the middle of a test
210 * so that trace-files can be made smaller.
213 wGetchar(WINDOW *win)
217 while ((c = wgetch(win)) == CTRL('T')) {
219 save_trace = _nc_tracing;
220 Trace(("TOGGLE-TRACING OFF"));
223 _nc_tracing = save_trace;
227 Trace(("TOGGLE-TRACING ON"));
234 #define Getchar() wGetchar(stdscr)
236 /* replaces wgetnstr(), since we want to be able to edit values */
238 wGetstring(WINDOW *win, char *buffer, int limit)
245 (void) wattrset(win, A_REVERSE);
247 x = (int) strlen(buffer);
249 if (x > (int) strlen(buffer))
250 x = (int) strlen(buffer);
252 wprintw(win, "%-*s", limit, buffer);
253 wmove(win, y0, x0 + x);
254 switch (ch = wGetchar(win)) {
267 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
285 if (!isprint(ch) || ch >= KEY_MIN) {
287 } else if ((int) strlen(buffer) < limit) {
289 for (j = (int) strlen(buffer) + 1; j > x; --j) {
290 buffer[j] = buffer[j - 1];
292 buffer[x++] = (char) ch;
299 wattroff(win, A_REVERSE);
304 #if USE_WIDEC_SUPPORT
306 fullwidth_digit(int ch)
308 return (wchar_t) (ch + 0xff10 - '0');
312 make_fullwidth_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = fullwidth_digit(ch);
322 make_narrow_text(wchar_t *target, const char *source)
325 while ((ch = *source++) != 0) {
326 *target++ = (wchar_t) ch;
333 make_fullwidth_digit(cchar_t *target, int digit)
337 source[0] = fullwidth_digit(digit + '0');
339 setcchar(target, source, A_NORMAL, 0, 0);
344 wGet_wchar(WINDOW *win, wint_t *result)
348 while ((c = wget_wch(win, result)) == CTRL('T')) {
350 save_trace = _nc_tracing;
351 Trace(("TOGGLE-TRACING OFF"));
354 _nc_tracing = save_trace;
358 Trace(("TOGGLE-TRACING ON"));
361 c = wget_wch(win, result);
365 #define Get_wchar(result) wGet_wchar(stdscr, result)
367 /* replaces wgetn_wstr(), since we want to be able to edit values */
369 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
378 (void) wattrset(win, A_REVERSE);
380 x = (int) wcslen(buffer);
382 if (x > (int) wcslen(buffer))
383 x = (int) wcslen(buffer);
385 /* clear the "window' */
387 wprintw(win, "%*s", limit, " ");
389 /* write the existing buffer contents */
391 waddnwstr(win, buffer, limit);
393 /* positions the cursor past character 'x' */
395 waddnwstr(win, buffer, x);
397 switch (wGet_wchar(win, &ch)) {
437 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
457 } else if ((int) wcslen(buffer) < limit) {
459 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
460 buffer[j] = buffer[j - 1];
462 buffer[x++] = (wchar_t) ch;
469 wattroff(win, A_REVERSE);
480 addstr("Press any key to continue... ");
485 Cannot(const char *what)
487 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
492 ShellOut(bool message)
495 addstr("Shelling out...");
501 IGNORE_RC(system("sh"));
504 addstr("returned from shellout.\n");
508 #ifdef NCURSES_MOUSE_VERSION
510 * This function is the same as _tracemouse(), but we cannot count on that
511 * being available in the non-debug library.
514 mouse_decode(MEVENT const *ep)
516 static char buf[80 + (5 * 10) + (32 * 15)];
518 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
519 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
521 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
523 SHOW(BUTTON1_RELEASED, "release-1");
524 SHOW(BUTTON1_PRESSED, "press-1");
525 SHOW(BUTTON1_CLICKED, "click-1");
526 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
527 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
528 #if NCURSES_MOUSE_VERSION == 1
529 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
532 SHOW(BUTTON2_RELEASED, "release-2");
533 SHOW(BUTTON2_PRESSED, "press-2");
534 SHOW(BUTTON2_CLICKED, "click-2");
535 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
536 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
537 #if NCURSES_MOUSE_VERSION == 1
538 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
541 SHOW(BUTTON3_RELEASED, "release-3");
542 SHOW(BUTTON3_PRESSED, "press-3");
543 SHOW(BUTTON3_CLICKED, "click-3");
544 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
545 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
546 #if NCURSES_MOUSE_VERSION == 1
547 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
550 SHOW(BUTTON4_RELEASED, "release-4");
551 SHOW(BUTTON4_PRESSED, "press-4");
552 SHOW(BUTTON4_CLICKED, "click-4");
553 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
554 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
555 #if NCURSES_MOUSE_VERSION == 1
556 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
559 #if NCURSES_MOUSE_VERSION == 2
560 SHOW(BUTTON5_RELEASED, "release-5");
561 SHOW(BUTTON5_PRESSED, "press-5");
562 SHOW(BUTTON5_CLICKED, "click-5");
563 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
564 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
567 SHOW(BUTTON_CTRL, "ctrl");
568 SHOW(BUTTON_SHIFT, "shift");
569 SHOW(BUTTON_ALT, "alt");
570 SHOW(ALL_MOUSE_EVENTS, "all-events");
571 SHOW(REPORT_MOUSE_POSITION, "position");
575 if (buf[strlen(buf) - 1] == ' ')
576 buf[strlen(buf) - 2] = '\0';
577 (void) strcat(buf, "}");
582 show_mouse(WINDOW *win)
590 outside = !wenclose(win, event.y, event.x);
593 (void) wstandout(win);
594 waddstr(win, "KEY_MOUSE");
595 (void) wstandend(win);
597 waddstr(win, "KEY_MOUSE");
599 wprintw(win, ", %s", mouse_decode(&event));
604 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
608 wmove(win, event.y, event.x);
616 #endif /* NCURSES_MOUSE_VERSION */
618 /****************************************************************************
620 * Character input test
622 ****************************************************************************/
624 #define NUM_GETCH_FLAGS 256
625 typedef bool GetchFlags[NUM_GETCH_FLAGS];
628 setup_getch(WINDOW *win, GetchFlags flags)
630 keypad(win, flags['k']); /* should be redundant, but for testing */
631 meta(win, flags['m']); /* force this to a known state */
639 init_getch(WINDOW *win, GetchFlags flags)
641 memset(flags, FALSE, NUM_GETCH_FLAGS);
642 flags[UChar('k')] = (win == stdscr);
643 flags[UChar('m')] = TRUE;
645 setup_getch(win, flags);
649 wgetch_help(WINDOW *win, GetchFlags flags)
651 static const char *help[] =
653 "e -- toggle echo mode"
654 ,"g -- triggers a getstr test"
655 ,"k -- toggle keypad/literal mode"
656 ,"m -- toggle meta (7-bit/8-bit) mode"
659 ,"w -- create a new window"
661 ,"z -- suspend this process"
665 unsigned chk = ((SIZEOF(help) + 1) / 2);
670 printw("Type any key to see its %s value. Also:\n",
671 flags['k'] ? "keypad" : "literal");
672 for (n = 0; n < SIZEOF(help); ++n) {
673 int row = 1 + (int) (n % chk);
674 int col = (n >= chk) ? COLS / 2 : 0;
675 int flg = ((strstr(help[n], "toggle") != 0)
676 && (flags[UChar(*help[n])] != FALSE));
679 MvPrintw(row, col, "%s", help[n]);
690 wgetch_wrap(WINDOW *win, int first_y)
692 int last_y = getmaxy(win) - 1;
693 int y = getcury(win) + 1;
701 #if defined(KEY_RESIZE) && HAVE_WRESIZE
707 static WINSTACK *winstack = 0;
708 static unsigned len_winstack = 0;
721 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
723 unsigned need = (level + 1) * 2;
725 assert(level < (unsigned) COLS);
729 winstack = typeMalloc(WINSTACK, len_winstack);
730 } else if (need >= len_winstack) {
732 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
735 failed("remember_boxes");
736 winstack[level].text = txt_win;
737 winstack[level].frame = box_win;
740 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
744 /* this chunk is now done in resize_term() */
751 #define slk_repaint() /* nothing */
754 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
756 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
757 * Resize both and paint the box in the parent.
760 resize_boxes(unsigned level, WINDOW *win)
764 int high = LINES - base;
768 wnoutrefresh(stdscr);
772 for (n = 0; n < level; ++n) {
773 wresize(winstack[n].frame, high, wide);
774 wresize(winstack[n].text, high - 2, wide - 2);
777 werase(winstack[n].text);
778 box(winstack[n].frame, 0, 0);
779 wnoutrefresh(winstack[n].frame);
780 wprintw(winstack[n].text,
782 getmaxy(winstack[n].text),
783 getmaxx(winstack[n].text));
784 wnoutrefresh(winstack[n].text);
785 if (winstack[n].text == win)
790 #endif /* resize_boxes */
792 #define forget_boxes() /* nothing */
793 #define remember_boxes(level,text,frame) /* nothing */
797 * Return-code is OK/ERR or a keyname.
802 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
806 wgetch_test(unsigned level, WINDOW *win, int delay)
809 int first_y, first_x;
813 bool blocking = (delay < 0);
815 init_getch(win, flags);
816 wtimeout(win, delay);
817 getyx(win, first_y, first_x);
819 wgetch_help(win, flags);
820 wsetscrreg(win, first_y, getmaxy(win) - 1);
824 while ((c = wGetchar(win)) == ERR) {
827 (void) wprintw(win, "%05d: input error", incount);
830 (void) wprintw(win, "%05d: input timed out", incount);
832 wgetch_wrap(win, first_y);
834 if (c == ERR && blocking) {
836 wgetch_wrap(win, first_y);
837 } else if (isQuit(c)) {
839 } else if (c == 'e') {
840 flags[UChar('e')] = !flags[UChar('e')];
841 setup_getch(win, flags);
842 wgetch_help(win, flags);
843 } else if (c == 'g') {
844 waddstr(win, "getstr test: ");
846 c = wgetnstr(win, buf, sizeof(buf) - 1);
848 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
849 (int) strlen(buf), buf,
852 wgetch_wrap(win, first_y);
853 } else if (c == 'k') {
854 flags[UChar('k')] = !flags[UChar('k')];
855 setup_getch(win, flags);
856 wgetch_help(win, flags);
857 } else if (c == 'm') {
858 flags[UChar('m')] = !flags[UChar('m')];
859 setup_getch(win, flags);
860 wgetch_help(win, flags);
861 } else if (c == 's') {
863 } else if (c == 'w') {
864 int high = getmaxy(win) - 1 - first_y + 1;
865 int wide = getmaxx(win) - first_x;
867 int new_y = first_y + getbegy(win);
868 int new_x = first_x + getbegx(win);
870 getyx(win, old_y, old_x);
871 if (high > 2 && wide > 2) {
872 WINDOW *wb = newwin(high, wide, new_y, new_x);
873 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
878 remember_boxes(level, wi, wb);
879 wgetch_test(level + 1, wi, delay);
883 wgetch_help(win, flags);
884 wmove(win, old_y, old_x);
890 } else if (c == 'z') {
891 kill(getpid(), SIGTSTP);
894 wprintw(win, "Key pressed: %04o ", c);
895 #ifdef NCURSES_MOUSE_VERSION
896 if (c == KEY_MOUSE) {
899 #endif /* NCURSES_MOUSE_VERSION */
901 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
902 if (c == KEY_RESIZE) {
903 resize_boxes(level, win);
906 (void) waddstr(win, keyname(c));
907 } else if (c >= 0x80) {
908 unsigned c2 = (unsigned) c;
909 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
910 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
914 (void) wprintw(win, "%c", UChar(c));
915 else if (c2 != UChar(c))
916 (void) wprintw(win, "M-%s", unctrl(c2));
918 (void) wprintw(win, "%s", unctrl(c2));
919 waddstr(win, " (high-half character)");
922 (void) wprintw(win, "%c (ASCII printable character)", c);
924 (void) wprintw(win, "%s (ASCII control character)",
927 wgetch_wrap(win, first_y);
934 init_getch(win, flags);
938 begin_getch_test(void)
945 #ifdef NCURSES_MOUSE_VERSION
946 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
949 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
951 getnstr(buf, sizeof(buf) - 1);
955 if (isdigit(UChar(buf[0]))) {
956 delay = atoi(buf) * 100;
966 finish_getch_test(void)
968 #ifdef NCURSES_MOUSE_VERSION
969 mousemask(0, (mmask_t *) 0);
980 int delay = begin_getch_test();
983 wgetch_test(0, stdscr, delay);
989 #if USE_WIDEC_SUPPORT
991 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
992 * Resize both and paint the box in the parent.
994 #if defined(KEY_RESIZE) && HAVE_WRESIZE
996 resize_wide_boxes(unsigned level, WINDOW *win)
1000 int high = LINES - base;
1004 wnoutrefresh(stdscr);
1008 for (n = 0; n < level; ++n) {
1009 wresize(winstack[n].frame, high, wide);
1010 wresize(winstack[n].text, high - 2, wide - 2);
1013 werase(winstack[n].text);
1014 box_set(winstack[n].frame, 0, 0);
1015 wnoutrefresh(winstack[n].frame);
1016 wprintw(winstack[n].text,
1018 getmaxy(winstack[n].text),
1019 getmaxx(winstack[n].text));
1020 wnoutrefresh(winstack[n].text);
1021 if (winstack[n].text == win)
1026 #endif /* KEY_RESIZE */
1029 wcstos(const wchar_t *src)
1033 const wchar_t *tmp = src;
1034 #ifndef state_unused
1038 reset_wchars(state);
1039 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1040 unsigned have = (unsigned) need;
1041 if ((result = typeCalloc(char, have + 1)) != 0) {
1043 if (trans_wchars(result, tmp, have, &state) != have) {
1055 wget_wch_test(unsigned level, WINDOW *win, int delay)
1057 wchar_t wchar_buf[BUFSIZ];
1058 wint_t wint_buf[BUFSIZ];
1059 int first_y, first_x;
1063 bool blocking = (delay < 0);
1067 init_getch(win, flags);
1068 wtimeout(win, delay);
1069 getyx(win, first_y, first_x);
1071 wgetch_help(win, flags);
1072 wsetscrreg(win, first_y, getmaxy(win) - 1);
1073 scrollok(win, TRUE);
1076 while ((code = wGet_wchar(win, &c)) == ERR) {
1079 (void) wprintw(win, "%05d: input error", incount);
1082 (void) wprintw(win, "%05d: input timed out", incount);
1084 wgetch_wrap(win, first_y);
1086 if (code == ERR && blocking) {
1087 wprintw(win, "ERR");
1088 wgetch_wrap(win, first_y);
1089 } else if (isQuit((int) c)) {
1091 } else if (c == 'e') {
1092 flags[UChar('e')] = !flags[UChar('e')];
1093 setup_getch(win, flags);
1094 wgetch_help(win, flags);
1095 } else if (c == 'g') {
1096 waddstr(win, "getstr test: ");
1098 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1101 wprintw(win, "wgetn_wstr returns an error.");
1104 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1107 if ((temp = wcstos(wchar_buf)) != 0) {
1108 wprintw(win, "I saw %d characters:\n\t`%s'.",
1109 (int) wcslen(wchar_buf), temp);
1112 wprintw(win, "I saw %d characters (cannot convert).",
1113 (int) wcslen(wchar_buf));
1117 wgetch_wrap(win, first_y);
1118 } else if (c == 'k') {
1119 flags[UChar('k')] = !flags[UChar('k')];
1120 setup_getch(win, flags);
1121 wgetch_help(win, flags);
1122 } else if (c == 'm') {
1123 flags[UChar('m')] = !flags[UChar('m')];
1124 setup_getch(win, flags);
1125 wgetch_help(win, flags);
1126 } else if (c == 's') {
1128 } else if (c == 'w') {
1129 int high = getmaxy(win) - 1 - first_y + 1;
1130 int wide = getmaxx(win) - first_x;
1132 int new_y = first_y + getbegy(win);
1133 int new_x = first_x + getbegx(win);
1135 getyx(win, old_y, old_x);
1136 if (high > 2 && wide > 2) {
1137 WINDOW *wb = newwin(high, wide, new_y, new_x);
1138 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1143 remember_boxes(level, wi, wb);
1144 wget_wch_test(level + 1, wi, delay);
1148 wgetch_help(win, flags);
1149 wmove(win, old_y, old_x);
1154 } else if (c == 'z') {
1155 kill(getpid(), SIGTSTP);
1158 wprintw(win, "Key pressed: %04o ", (int) c);
1159 #ifdef NCURSES_MOUSE_VERSION
1160 if (c == KEY_MOUSE) {
1163 #endif /* NCURSES_MOUSE_VERSION */
1164 if (code == KEY_CODE_YES) {
1165 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1166 if (c == KEY_RESIZE) {
1167 resize_wide_boxes(level, win);
1170 (void) waddstr(win, keyname((wchar_t) c));
1172 (void) waddstr(win, key_name((wchar_t) c));
1173 if (c < 256 && iscntrl(c)) {
1174 (void) wprintw(win, " (control character)");
1176 (void) wprintw(win, " = %#x (printable character)",
1180 wgetch_wrap(win, first_y);
1187 init_getch(win, flags);
1193 int delay = begin_getch_test();
1196 wget_wch_test(0, stdscr, delay);
1198 finish_getch_test();
1203 /****************************************************************************
1205 * Character attributes test
1207 ****************************************************************************/
1209 #if HAVE_SETUPTERM || HAVE_TGETENT
1210 #define get_ncv() TIGETNUM("ncv","NC")
1211 #define get_xmc() TIGETNUM("xmc","sg")
1213 #define get_ncv() -1
1214 #define get_xmc() -1
1221 static int first = TRUE;
1222 static chtype result = 0;
1228 char *area_pointer = parsed;
1230 tgetent(buffer, getenv("TERM"));
1233 if (TIGETSTR("smso", "so"))
1234 result |= A_STANDOUT;
1235 if (TIGETSTR("smul", "us"))
1236 result |= A_UNDERLINE;
1237 if (TIGETSTR("rev", "mr"))
1238 result |= A_REVERSE;
1239 if (TIGETSTR("blink", "mb"))
1241 if (TIGETSTR("dim", "mh"))
1243 if (TIGETSTR("bold", "md"))
1245 if (TIGETSTR("smacs", "ac"))
1246 result |= A_ALTCHARSET;
1252 #define termattrs() my_termattrs()
1255 #define ATTRSTRING_1ST 32 /* ' ' */
1256 #define ATTRSTRING_END 126 /* '~' */
1258 #define COLS_PRE_ATTRS 5
1259 #define COLS_AFT_ATTRS 15
1260 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1261 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1262 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1264 static char attr_test_string[MAX_ATTRSTRING + 1];
1267 attr_legend(WINDOW *helpwin)
1272 MvWPrintw(helpwin, row++, col,
1274 MvWPrintw(helpwin, row++, col,
1277 MvWPrintw(helpwin, row++, col,
1278 "Modify the test strings:");
1279 MvWPrintw(helpwin, row++, col,
1280 " A digit sets gaps on each side of displayed attributes");
1281 MvWPrintw(helpwin, row++, col,
1282 " </> shifts the text left/right. ");
1284 MvWPrintw(helpwin, row++, col,
1287 MvWPrintw(helpwin, row++, col,
1288 " f/F/b/F toggle foreground/background background color");
1289 MvWPrintw(helpwin, row++, col,
1290 " t/T toggle text/background color attribute");
1292 MvWPrintw(helpwin, row++, col,
1293 " a/A toggle ACS (alternate character set) mapping");
1294 MvWPrintw(helpwin, row, col,
1295 " v/V toggle video attribute to combine with each line");
1296 #if USE_WIDEC_SUPPORT
1297 MvWPrintw(helpwin, row, col,
1298 " w/W toggle normal/wide (double-width) test-characters");
1303 show_color_attr(int fg, int bg, int tx)
1306 printw(" Colors (fg %d, bg %d", fg, bg);
1308 printw(", text %d", tx);
1314 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1321 *fg = (NCURSES_COLOR_T) (*fg + 1);
1324 *fg = (NCURSES_COLOR_T) (*fg - 1);
1327 *bg = (NCURSES_COLOR_T) (*bg + 1);
1330 *bg = (NCURSES_COLOR_T) (*bg - 1);
1333 *tx = (NCURSES_COLOR_T) (*tx + 1);
1336 *tx = (NCURSES_COLOR_T) (*tx - 1);
1344 *fg = (NCURSES_COLOR_T) min_colors;
1345 if (*fg < min_colors)
1346 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1348 *bg = (NCURSES_COLOR_T) min_colors;
1349 if (*bg < min_colors)
1350 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1354 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1363 adjust_attr_string(int adjust)
1365 char save = attr_test_string[0];
1366 int first = ((int) UChar(save)) + adjust;
1369 if (first >= ATTRSTRING_1ST) {
1370 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1371 if (k > ATTRSTRING_END)
1373 attr_test_string[j] = (char) k;
1374 if (((k + 1 - first) % 5) == 0) {
1375 if (++j >= MAX_ATTRSTRING)
1377 attr_test_string[j] = ' ';
1380 if ((LEN_ATTRSTRING - j) > 5) {
1381 attr_test_string[0] = save;
1382 adjust_attr_string(adjust - 1);
1384 while (j < MAX_ATTRSTRING)
1385 attr_test_string[j++] = ' ';
1386 attr_test_string[j] = '\0';
1392 * Prefer the right-end of the string for starting, since that maps to the
1393 * VT100 line-drawing.
1396 default_attr_string(void)
1398 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1399 result += (LEN_ATTRSTRING / 5);
1400 if (result < ATTRSTRING_1ST)
1401 result = ATTRSTRING_1ST;
1406 init_attr_string(void)
1408 attr_test_string[0] = (char) default_attr_string();
1409 adjust_attr_string(0);
1413 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1415 int ncv = get_ncv();
1416 chtype test = attr & (chtype) (~A_ALTCHARSET);
1419 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1420 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1421 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1423 printw("%*s", skip, " ");
1425 * Just for testing, write text using the alternate character set one
1426 * character at a time (to pass its rendition directly), and use the
1427 * string operation for the other attributes.
1431 if (attr & A_ALTCHARSET) {
1435 for (s = attr_test_string; *s != '\0'; ++s) {
1437 (void) waddch(win, ch | attr);
1440 (void) wattrset(win, AttrArg(attr, 0));
1441 (void) waddstr(win, attr_test_string);
1442 (void) wattroff(win, (int) attr);
1445 printw("%*s", skip, " ");
1446 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1447 if (test != A_NORMAL) {
1448 if (!(termattrs() & test)) {
1451 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1452 static const chtype table[] =
1471 for (n = 0; n < SIZEOF(table); n++) {
1472 if ((table[n] & attr) != 0
1473 && ((1 << n) & ncv) != 0) {
1481 if ((termattrs() & test) != test)
1490 NCURSES_CONST char *name;
1493 static const ATTR_TBL attrs_to_test[] = {
1494 { A_STANDOUT, "STANDOUT" },
1495 { A_REVERSE, "REVERSE" },
1497 { A_UNDERLINE, "UNDERLINE" },
1499 { A_BLINK, "BLINK" },
1500 { A_PROTECT, "PROTECT" },
1502 { A_INVIS, "INVISIBLE" },
1505 { A_ITALIC, "ITALIC" },
1507 { A_NORMAL, "NORMAL" },
1512 init_attr_list(ATTR_TBL * target, attr_t attrs)
1514 unsigned result = 0;
1517 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1518 attr_t test = attrs_to_test[n].attr;
1519 if (test == A_NORMAL || (test & attrs) != 0) {
1520 target[result++] = attrs_to_test[n];
1527 attr_getc(int *skip,
1528 NCURSES_COLOR_T *fg,
1529 NCURSES_COLOR_T *bg,
1530 NCURSES_COLOR_T *tx,
1543 if (ch < 256 && isdigit(ch)) {
1551 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1553 attr_legend(helpwin);
1576 adjust_attr_string(-1);
1579 adjust_attr_string(1);
1585 error = cycle_color_attr(ch, fg, bg, tx);
1595 /* test text attributes */
1598 int skip = get_xmc();
1599 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1600 NCURSES_COLOR_T bg = COLOR_BLACK;
1601 NCURSES_COLOR_T tx = -1;
1604 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1605 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1606 unsigned my_size = init_attr_list(my_list, termattrs());
1609 for (j = 0; j < my_size; ++j) {
1610 my_wins[j] = subwin(stdscr,
1612 2 + (int) (2 * j), COL_ATTRSTRING);
1613 scrollok(my_wins[j], FALSE);
1619 n = skip; /* make it easy */
1625 chtype normal = A_NORMAL | BLANK;
1626 chtype extras = (chtype) ac;
1629 NCURSES_PAIRS_T pair = 0;
1630 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1632 if (init_pair(pair, fg, bg) == ERR) {
1635 normal |= (chtype) COLOR_PAIR(pair);
1640 if (init_pair(pair, tx, bg) == ERR) {
1643 extras |= (chtype) COLOR_PAIR(pair);
1653 MvAddStr(0, 20, "Character attribute test display");
1655 for (j = 0; j < my_size; ++j) {
1656 bool arrow = (j == k);
1657 row = show_attr(my_wins[j], row, n, arrow,
1665 MvPrintw(row, COLS_PRE_ATTRS,
1666 "This terminal does %shave the magic-cookie glitch",
1667 get_xmc() > -1 ? "" : "not ");
1668 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1669 show_color_attr(fg, bg, tx);
1670 printw(" ACS (%d)", ac != 0);
1673 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1675 bkgdset(A_NORMAL | BLANK);
1679 Cannot("does not support video attributes.");
1683 #if USE_WIDEC_SUPPORT
1684 static bool use_fullwidth;
1685 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1687 #define FULL_LO 0xff00
1688 #define FULL_HI 0xff5e
1689 #define HALF_LO 0x20
1691 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1692 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1693 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1696 * Returns an ASCII code in [32..126]
1699 normal_wchar(int ch)
1701 wchar_t result = (wchar_t) ch;
1702 if (isFullWidth(ch))
1703 result = ToNormalWidth(ch);
1708 * Returns either an ASCII code in in [32..126] or full-width in
1709 * [0xff00..0xff5e], according to use_fullwidth setting.
1712 target_wchar(int ch)
1714 wchar_t result = (wchar_t) ch;
1715 if (use_fullwidth) {
1716 if (!isFullWidth(ch))
1717 result = ToFullWidth(ch);
1719 if (isFullWidth(ch))
1720 result = ToNormalWidth(ch);
1726 wide_adjust_attr_string(int adjust)
1728 wchar_t save = wide_attr_test_string[0];
1729 int first = ((int) normal_wchar(save)) + adjust;
1732 if (first >= ATTRSTRING_1ST) {
1733 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1734 if (k > ATTRSTRING_END)
1736 wide_attr_test_string[j] = target_wchar(k);
1737 if (((k + 1 - first) % 5) == 0) {
1738 if (++j >= MAX_ATTRSTRING)
1740 wide_attr_test_string[j] = ' ';
1743 if ((LEN_ATTRSTRING - j) > 5) {
1744 wide_attr_test_string[0] = save;
1745 wide_adjust_attr_string(adjust - 1);
1747 while (j < MAX_ATTRSTRING)
1748 wide_attr_test_string[j++] = ' ';
1749 wide_attr_test_string[j] = '\0';
1755 wide_init_attr_string(void)
1757 use_fullwidth = FALSE;
1758 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1759 wide_adjust_attr_string(0);
1763 set_wide_background(NCURSES_PAIRS_T pair)
1770 setcchar(&normal, blank, A_NORMAL, pair, 0);
1776 get_wide_background(void)
1778 attr_t result = A_NORMAL;
1781 NCURSES_PAIRS_T pair;
1784 memset(&ch, 0, sizeof(ch));
1785 if (getbkgrnd(&ch) != ERR) {
1786 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1794 wide_show_attr(WINDOW *win,
1799 NCURSES_PAIRS_T pair,
1802 int ncv = get_ncv();
1803 chtype test = attr & ~WA_ALTCHARSET;
1806 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1807 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1808 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1810 printw("%*s", skip, " ");
1813 * Just for testing, write text using the alternate character set one
1814 * character at a time (to pass its rendition directly), and use the
1815 * string operation for the other attributes.
1819 if (attr & WA_ALTCHARSET) {
1823 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1827 setcchar(&ch, fill, attr, pair, 0);
1828 (void) wadd_wch(win, &ch);
1831 attr_t old_attr = 0;
1832 NCURSES_PAIRS_T old_pair = 0;
1834 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1835 (void) wattr_set(win, attr, pair, 0);
1836 (void) waddwstr(win, wide_attr_test_string);
1837 (void) wattr_set(win, old_attr, old_pair, 0);
1840 printw("%*s", skip, " ");
1841 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1842 if (test != A_NORMAL) {
1843 if (!(term_attrs() & test)) {
1846 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1847 static const attr_t table[] =
1861 for (n = 0; n < SIZEOF(table); n++) {
1862 if ((table[n] & attr) != 0
1863 && ((1 << n) & ncv) != 0) {
1871 if ((term_attrs() & test) != test)
1879 wide_attr_getc(int *skip,
1880 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1881 NCURSES_COLOR_T *tx, int *ac,
1882 unsigned *kc, unsigned limit)
1892 if (ch < 256 && isdigit(ch)) {
1900 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1901 box_set(helpwin, 0, 0);
1902 attr_legend(helpwin);
1925 use_fullwidth = FALSE;
1926 wide_adjust_attr_string(0);
1929 use_fullwidth = TRUE;
1930 wide_adjust_attr_string(0);
1933 wide_adjust_attr_string(-1);
1936 wide_adjust_attr_string(1);
1942 error = cycle_color_attr(ch, fg, bg, tx);
1951 wide_attr_test(void)
1952 /* test text attributes using wide-character calls */
1955 int skip = get_xmc();
1956 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1957 NCURSES_COLOR_T bg = COLOR_BLACK;
1958 NCURSES_COLOR_T tx = -1;
1961 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1962 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1963 unsigned my_size = init_attr_list(my_list, term_attrs());
1966 for (j = 0; j < my_size; ++j) {
1967 my_wins[j] = subwin(stdscr,
1969 2 + (int) (2 * j), COL_ATTRSTRING);
1970 scrollok(my_wins[j], FALSE);
1976 n = skip; /* make it easy */
1978 wide_init_attr_string();
1982 NCURSES_PAIRS_T pair = 0;
1983 NCURSES_PAIRS_T extras = 0;
1986 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1989 if (init_pair(pair, fg, bg) == ERR) {
1996 if (init_pair(extras, tx, bg) == ERR) {
2001 set_wide_background(pair);
2004 box_set(stdscr, 0, 0);
2005 MvAddStr(0, 20, "Character attribute test display");
2007 for (j = 0; j < my_size; ++j) {
2008 row = wide_show_attr(my_wins[j], row, n, (j == k),
2016 MvPrintw(row, COLS_PRE_ATTRS,
2017 "This terminal does %shave the magic-cookie glitch",
2018 get_xmc() > -1 ? "" : "not ");
2019 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2020 show_color_attr(fg, bg, tx);
2021 printw(" ACS (%d)", ac != 0);
2024 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2026 set_wide_background(0);
2030 Cannot("does not support extended video attributes.");
2035 /****************************************************************************
2037 * Color support tests
2039 ****************************************************************************/
2041 static NCURSES_CONST char *the_color_names[] =
2062 show_color_name(int y, int x, int color, bool wide)
2064 if (move(y, x) != ERR) {
2069 sprintf(temp, "%02d", color);
2071 } else if (color >= 8) {
2072 sprintf(temp, "[%02d]", color);
2073 } else if (color < 0) {
2074 strcpy(temp, "default");
2076 sprintf(temp, "%.*s", 16, the_color_names[color]);
2078 printw("%-*.*s", width, width, temp);
2083 color_legend(WINDOW *helpwin, bool wide)
2088 MvWPrintw(helpwin, row++, col,
2091 MvWPrintw(helpwin, row++, col,
2092 "Use up/down arrow to scroll through the display if it is");
2093 MvWPrintw(helpwin, row++, col,
2094 "longer than one screen. Control/N and Control/P can be used");
2095 MvWPrintw(helpwin, row++, col,
2096 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2097 MvWPrintw(helpwin, row++, col,
2098 "full screen; control/B and control/F can be used here.");
2100 MvWPrintw(helpwin, row++, col,
2102 MvWPrintw(helpwin, row++, col,
2103 " a/A toggle altcharset off/on");
2104 MvWPrintw(helpwin, row++, col,
2105 " b/B toggle bold off/on");
2107 MvWPrintw(helpwin, row++, col,
2108 " c/C cycle used-colors through 8,16,...,COLORS");
2110 MvWPrintw(helpwin, row++, col,
2111 " n/N toggle text/number on/off");
2112 MvWPrintw(helpwin, row++, col,
2113 " r/R toggle reverse on/off");
2114 MvWPrintw(helpwin, row++, col,
2115 " w/W toggle width between 8/16 colors");
2116 #if USE_WIDEC_SUPPORT
2118 MvWPrintw(helpwin, row++, col,
2119 "Wide characters:");
2120 MvWPrintw(helpwin, row, col,
2121 " x/X toggle text between ASCII and wide-character");
2128 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2131 color_cycle(int current, int step)
2133 int result = current;
2139 if ((result * 2) > COLORS) {
2142 while ((result * 2) < current) {
2148 if (current >= COLORS) {
2153 if (result > COLORS)
2159 /* generate a color test pattern */
2166 int grid_top = top + 3;
2167 int page_size = (LINES - grid_top);
2169 int colors_max = COLORS;
2175 bool opt_acsc = FALSE;
2176 bool opt_bold = FALSE;
2177 bool opt_revs = FALSE;
2178 bool opt_nums = FALSE;
2179 bool opt_wide = FALSE;
2185 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2186 if (colors_max * colors_max <= COLOR_PAIRS) {
2187 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2188 if (pairs_max > limit)
2191 if (pairs_max > COLOR_PAIRS)
2192 pairs_max = COLOR_PAIRS;
2195 /* this assumes an 80-column line */
2199 per_row = (colors_max > 8) ? 16 : 8;
2205 per_row -= min_colors;
2207 row_limit = (pairs_max + per_row - 1) / per_row;
2210 (void) printw("There are %d color pairs and %d colors",
2212 if (colors_max != COLORS)
2213 (void) printw(" (using %d colors)", colors_max);
2215 (void) addstr(" besides 'default'");
2218 MvPrintw(top + 1, 0,
2219 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2222 opt_bold ? "on" : "off");
2224 /* show color names/numbers across the top */
2225 for (i = 0; i < per_row; i++)
2226 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2228 /* show a grid of colors, with color names/ numbers on the left */
2229 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2230 int row = grid_top + (i / per_row) - base_row;
2231 int col = (i % per_row + 1) * width;
2232 NCURSES_PAIRS_T pair = i;
2234 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - min_colors)) + min_colors)
2235 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - min_colors)) + min_colors)
2236 if (row >= 0 && move(row, col) != ERR) {
2237 NCURSES_COLOR_T fg = InxToFG(i);
2238 NCURSES_COLOR_T bg = InxToBG(i);
2240 init_pair(pair, fg, bg);
2241 attron(COLOR_PAIR(pair));
2243 attron(A_ALTCHARSET);
2250 sprintf(numbered, "{%02X}", (int) i);
2253 printw("%-*.*s", width, width, hello);
2254 (void) attrset(A_NORMAL);
2256 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2257 show_color_name(row, 0, InxToBG(i), opt_wide);
2265 switch (wGetchar(stdscr)) {
2279 colors_max = color_cycle(colors_max, -1);
2282 colors_max = color_cycle(colors_max, 1);
2300 set_color_test(opt_wide, FALSE);
2303 set_color_test(opt_wide, TRUE);
2307 if (base_row <= 0) {
2315 if (base_row + page_size >= row_limit) {
2324 if (base_row <= 0) {
2327 base_row -= (page_size - 1);
2335 if (base_row + page_size >= row_limit) {
2338 base_row += page_size - 1;
2339 if (base_row + page_size >= row_limit) {
2340 base_row = row_limit - page_size - 1;
2345 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2347 color_legend(helpwin, FALSE);
2362 #if USE_WIDEC_SUPPORT
2363 /* generate a color test pattern */
2365 wide_color_test(void)
2370 int grid_top = top + 3;
2371 int page_size = (LINES - grid_top);
2372 int pairs_max = (unsigned short) (-1);
2373 int colors_max = COLORS;
2379 bool opt_acsc = FALSE;
2380 bool opt_bold = FALSE;
2381 bool opt_revs = FALSE;
2382 bool opt_wide = FALSE;
2383 bool opt_nums = FALSE;
2384 bool opt_xchr = FALSE;
2391 pairs_max = (unsigned short) (-1);
2392 if (colors_max * colors_max <= COLOR_PAIRS) {
2393 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2394 if (pairs_max > limit)
2397 if (pairs_max > COLOR_PAIRS)
2398 pairs_max = COLOR_PAIRS;
2401 /* this assumes an 80-column line */
2405 per_row = (colors_max > 8) ? 16 : 8;
2411 per_row -= min_colors;
2414 make_fullwidth_text(buffer, hello);
2418 make_narrow_text(buffer, hello);
2421 row_limit = (pairs_max + per_row - 1) / per_row;
2424 (void) printw("There are %d color pairs and %d colors",
2426 if (colors_max != COLORS)
2427 (void) printw(" (using %d colors)", colors_max);
2429 (void) addstr(" besides 'default'");
2432 MvPrintw(top + 1, 0,
2433 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2436 opt_bold ? "on" : "off");
2438 /* show color names/numbers across the top */
2439 for (i = 0; i < per_row; i++)
2440 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2442 /* show a grid of colors, with color names/ numbers on the left */
2443 for (i = (base_row * per_row); i < pairs_max; i++) {
2444 int row = grid_top + (i / per_row) - base_row;
2445 int col = (i % per_row + 1) * width;
2446 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2448 if (row >= 0 && move(row, col) != ERR) {
2449 init_pair(pair, InxToFG(i), InxToBG(i));
2450 (void) color_set(pair, NULL);
2452 attr_on(A_ALTCHARSET, NULL);
2454 attr_on(A_BOLD, NULL);
2456 attr_on(A_REVERSE, NULL);
2459 sprintf(numbered, "{%02X}", i);
2461 make_fullwidth_text(buffer, numbered);
2463 make_narrow_text(buffer, numbered);
2466 addnwstr(buffer, width);
2467 (void) attr_set(A_NORMAL, 0, NULL);
2469 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2470 show_color_name(row, 0, InxToBG(i), opt_wide);
2478 switch (wGetchar(stdscr)) {
2492 colors_max = color_cycle(colors_max, -1);
2495 colors_max = color_cycle(colors_max, 1);
2513 set_color_test(opt_wide, FALSE);
2516 set_color_test(opt_wide, TRUE);
2526 if (base_row <= 0) {
2534 if (base_row + page_size >= row_limit) {
2543 if (base_row <= 0) {
2546 base_row -= (page_size - 1);
2554 if (base_row + page_size >= row_limit) {
2557 base_row += page_size - 1;
2558 if (base_row + page_size >= row_limit) {
2559 base_row = row_limit - page_size - 1;
2564 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2566 color_legend(helpwin, TRUE);
2580 #endif /* USE_WIDEC_SUPPORT */
2583 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2585 NCURSES_COLOR_T red, green, blue;
2587 color_content(current, &red, &green, &blue);
2591 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2594 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2597 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2601 if (init_color(current, red, green, blue) == ERR)
2606 init_all_colors(void)
2610 for (c = 0; c < COLORS; ++c)
2613 all_colors[c].green,
2614 all_colors[c].blue);
2617 #define scaled_rgb(n) ((255 * (n)) / 1000)
2621 /* display the color test pattern, without trying to edit colors */
2625 int this_c = 0, value = 0, field = 0;
2628 int page_size = (LINES - 6);
2633 for (i = 0; i < max_colors; i++)
2634 init_pair((NCURSES_PAIRS_T) i,
2635 (NCURSES_COLOR_T) COLOR_WHITE,
2636 (NCURSES_COLOR_T) i);
2638 MvPrintw(LINES - 2, 0, "Number: %d", value);
2641 NCURSES_COLOR_T red, green, blue;
2644 MvAddStr(0, 20, "Color RGB Value Editing");
2647 for (i = (NCURSES_COLOR_T) top_color;
2648 (i - top_color < page_size)
2649 && (i < max_colors); i++) {
2652 sprintf(numeric, "[%d]", i);
2653 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2654 (i == current ? '>' : ' '),
2655 (i < (int) SIZEOF(the_color_names)
2656 ? the_color_names[i] : numeric));
2657 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2659 (void) attrset(A_NORMAL);
2661 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2663 if (current == i && field == 0)
2665 printw("%04d", (int) red);
2666 if (current == i && field == 0)
2667 (void) attrset(A_NORMAL);
2669 if (current == i && field == 1)
2671 printw("%04d", (int) green);
2672 if (current == i && field == 1)
2673 (void) attrset(A_NORMAL);
2675 if (current == i && field == 2)
2677 printw("%04d", (int) blue);
2678 if (current == i && field == 2)
2679 (void) attrset(A_NORMAL);
2680 (void) attrset(A_NORMAL);
2681 printw(" ( %3d %3d %3d )",
2682 (int) scaled_rgb(red),
2683 (int) scaled_rgb(green),
2684 (int) scaled_rgb(blue));
2687 MvAddStr(LINES - 3, 0,
2688 "Use up/down to select a color, left/right to change fields.");
2689 MvAddStr(LINES - 2, 0,
2690 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2692 move(2 + current - top_color, 0);
2696 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2703 current -= (page_size - 1);
2710 if (current < (max_colors - 1))
2711 current += (page_size - 1);
2718 current = (current == 0 ? (max_colors - 1) : current - 1);
2723 current = (current == (max_colors - 1) ? 0 : current + 1);
2727 field = (field == 2 ? 0 : field + 1);
2731 field = (field == 0 ? 2 : field - 1);
2744 value = value * 10 + (this_c - '0');
2748 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2752 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2756 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2761 P(" RGB Value Editing Help");
2763 P("You are in the RGB value editor. Use the arrow keys to select one of");
2764 P("the fields in one of the RGB triples of the current colors; the one");
2765 P("currently selected will be reverse-video highlighted.");
2767 P("To change a field, enter the digits of the new value; they are echoed");
2768 P("as entered. Finish by typing `='. The change will take effect instantly.");
2769 P("To increment or decrement a value, use the same procedure, but finish");
2770 P("with a `+' or `-'.");
2772 P("Press 'm' to invoke the top-level menu with the current color settings.");
2773 P("To quit, do ESC");
2782 for (i = 0; i < max_colors; i++)
2783 init_pair((NCURSES_PAIRS_T) i,
2784 (NCURSES_COLOR_T) COLOR_WHITE,
2785 (NCURSES_COLOR_T) i);
2799 if (current >= max_colors)
2800 current = max_colors - 1;
2801 if (current < top_color)
2802 top_color = current;
2803 if (current - top_color >= page_size)
2804 top_color = current - (page_size - 1);
2806 MvPrintw(LINES - 1, 0, "Number: %d", value);
2814 * ncurses does not reset each color individually when calling endwin().
2821 /****************************************************************************
2823 * Alternate character-set stuff
2825 ****************************************************************************/
2827 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
2833 if ((*at_code += 1) >= limit)
2838 *at_code = limit - 1;
2847 *attr = list[*at_code].attr;
2852 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
2854 bool result = FALSE;
2864 if ((*fg += 1) >= COLORS)
2872 if ((*bg += 1) >= COLORS)
2880 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2883 if (init_pair(*pair,
2884 (NCURSES_COLOR_T) *fg,
2885 (NCURSES_COLOR_T) *bg) == ERR) {
2894 /****************************************************************************
2896 * Soft-key label test
2898 ****************************************************************************/
2903 #define SLK_WORK (SLK_HELP + 3)
2908 static const char *table[] =
2910 "Available commands are:"
2912 ,"^L -- repaint this message and activate soft keys"
2913 ,"a/d -- activate/disable soft keys"
2914 ,"c -- set centered format for labels"
2915 ,"l -- set left-justified format for labels"
2916 ,"r -- set right-justified format for labels"
2917 ,"[12345678] -- set label; labels are numbered 1 through 8"
2918 ,"e -- erase stdscr (should not erase labels)"
2919 ,"s -- test scrolling of shortened screen"
2920 ,"v/V -- cycle through video attributes"
2922 ,"F/f/B/b -- cycle through foreground/background colors"
2924 ,"ESC -- return to main menu"
2926 ,"Note: if activating the soft keys causes your terminal to scroll up"
2927 ,"one line, your terminal auto-scrolls when anything is written to the"
2928 ,"last screen position. The ncurses code does not yet handle this"
2934 for (j = 0; j < SIZEOF(table); ++j) {
2942 call_slk_color(int fg, int bg)
2944 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
2946 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2956 /* exercise the soft keys */
2961 chtype attr = A_NORMAL;
2962 unsigned at_code = 0;
2964 int fg = COLOR_BLACK;
2965 int bg = COLOR_WHITE;
2966 NCURSES_PAIRS_T pair = 0;
2968 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
2969 unsigned my_size = init_attr_list(my_list, termattrs());
2974 call_slk_color(fg, bg);
2984 MvAddStr(0, 20, "Soft Key Exerciser");
2999 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3000 while ((c = Getchar()) != 'Q' && (c != ERR))
3028 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3030 if ((s = slk_label(c - '0')) != 0) {
3031 strncpy(buf, s, (size_t) 8);
3033 wGetstring(stdscr, buf, 8);
3034 slk_set((c - '0'), buf, fmt);
3043 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3045 wnoutrefresh(stdscr);
3050 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3057 if (cycle_colors(c, &fg, &bg, &pair)) {
3059 call_slk_color(fg, bg);
3069 } while (!isQuit(c = Getchar()));
3077 #if USE_WIDEC_SUPPORT
3081 /* exercise the soft keys */
3084 wchar_t buf[SLKLEN + 1];
3086 chtype attr = A_NORMAL;
3087 unsigned at_code = 0;
3088 int fg = COLOR_BLACK;
3089 int bg = COLOR_WHITE;
3090 NCURSES_PAIRS_T pair = 0;
3091 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3092 unsigned my_size = init_attr_list(my_list, term_attrs());
3096 call_slk_color(fg, bg);
3103 attr_on(WA_BOLD, NULL);
3104 MvAddStr(0, 20, "Soft Key Exerciser");
3105 attr_off(WA_BOLD, NULL);
3119 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3120 while ((c = Getchar()) != 'Q' && (c != ERR))
3148 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3150 if ((s = slk_label(c - '0')) != 0) {
3151 char *temp = strdup(s);
3152 size_t used = strlen(temp);
3153 size_t want = SLKLEN;
3155 #ifndef state_unused
3160 while (want > 0 && used != 0) {
3161 const char *base = s;
3162 reset_mbytes(state);
3163 test = count_mbytes(base, 0, &state);
3164 if (test == (size_t) -1) {
3166 } else if (test > want) {
3169 reset_mbytes(state);
3170 trans_mbytes(buf, base, want, &state);
3176 wGet_wstring(stdscr, buf, SLKLEN);
3177 slk_wset((c - '0'), buf, fmt);
3188 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3189 call_slk_color(fg, bg);
3194 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3195 call_slk_color(fg, bg);
3198 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3200 wnoutrefresh(stdscr);
3204 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3205 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3211 if (cycle_colors(c, &fg, &bg, &pair)) {
3213 call_slk_color(fg, bg);
3223 } while (!isQuit(c = Getchar()));
3231 #endif /* SLK_INIT */
3234 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3237 unsigned last = 255;
3243 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3248 for (code = first; code <= last; ++code) {
3249 int row = (int) (2 + (code / 16));
3250 int col = (int) (5 * (code % 16));
3251 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3252 for (count = 1; count < repeat; ++count) {
3253 addch(colored_chtype(code, attr, pair));
3260 * Show a slice of 32 characters, allowing those to be repeated up to the
3263 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3264 * terminal to perform functions. The remaining codes can be graphic.
3267 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3270 unsigned first = (unsigned) base;
3271 unsigned last = first + (unsigned) pagesize - 2;
3272 bool C1 = (first == 128);
3277 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3278 C1 ? "C1" : "GR", first, last);
3282 for (code = first; code <= last; code++) {
3284 int row = 2 + ((int) (code - first) % (pagesize / 2));
3285 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3287 sprintf(tmp, "%3u (0x%x)", code, code);
3288 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3292 nodelay(stdscr, TRUE);
3293 echochar(colored_chtype(code, attr, pair));
3295 /* (yes, this _is_ crude) */
3296 while ((reply = Getchar()) != ERR) {
3297 addch(UChar(reply));
3300 nodelay(stdscr, FALSE);
3302 } while (--count > 0);
3309 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3315 MvPrintw(0, 20, "Display of PC Character Codes");
3319 for (code = 0; code < 16; ++code) {
3320 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3322 for (code = 0; code < 256; code++) {
3324 int row = 3 + (int) (code / 16) + (code >= 128);
3325 int col = 8 + (int) (code % 16) * PC_COLS;
3326 if ((code % 16) == 0)
3327 MvPrintw(row, 0, "0x%02x:", code);
3338 * Skip the ones that do not work.
3342 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3345 } while (--count > 0);
3350 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3354 attr |= (attr_t) COLOR_PAIR(pair);
3358 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3363 colored_chtype(ACS_VLINE, attr, pair),
3364 colored_chtype(ACS_VLINE, attr, pair),
3365 colored_chtype(ACS_HLINE, attr, pair),
3366 colored_chtype(ACS_HLINE, attr, pair),
3367 colored_chtype(ACS_ULCORNER, attr, pair),
3368 colored_chtype(ACS_URCORNER, attr, pair),
3369 colored_chtype(ACS_LLCORNER, attr, pair),
3370 colored_chtype(ACS_LRCORNER, attr, pair));
3371 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3372 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3373 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3374 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3375 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3376 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3377 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3383 show_1_acs(int n, int repeat, const char *name, chtype code)
3385 const int height = 16;
3386 int row = 2 + (n % height);
3387 int col = (n / height) * COLS / 2;
3389 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3392 } while (--repeat > 0);
3397 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3398 /* display the ACS character set */
3402 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3406 MvAddStr(0, 20, "Display of the ACS Character Set");
3410 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3411 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3412 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3413 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3415 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3416 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3417 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3418 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3420 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3421 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3424 * HPUX's ACS definitions are broken here. Just give up.
3426 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3427 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3428 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3429 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3430 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3432 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3433 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3434 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3435 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3436 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3437 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3438 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3439 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3440 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3442 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3443 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3444 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3446 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3447 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3448 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3449 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3450 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3451 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3460 char *term = getenv("TERM");
3461 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3464 chtype attr = A_NORMAL;
3467 int fg = COLOR_BLACK;
3468 int bg = COLOR_BLACK;
3469 unsigned at_code = 0;
3470 NCURSES_PAIRS_T pair = 0;
3471 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3472 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3473 unsigned my_size = init_attr_list(my_list, termattrs());
3481 ToggleAcs(last_show_acs, show_acs_chars);
3485 ToggleAcs(last_show_acs, show_pc_chars);
3490 if (pagesize == 32) {
3497 ToggleAcs(last_show_acs, show_box_chars);
3523 if (repeat < (COLS / 4))
3531 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3532 || cycle_colors(c, &fg, &bg, &pair)) {
3539 if (pagesize != 32) {
3540 show_256_chars(repeat, attr, pair);
3541 } else if (last_show_acs != 0) {
3542 last_show_acs(repeat, attr, pair);
3544 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3547 MvPrintw(LINES - 3, 0,
3548 "Note: ANSI terminals may not display C1 characters.");
3549 MvPrintw(LINES - 2, 0,
3550 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3553 MvPrintw(LINES - 1, 0,
3554 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3555 my_list[at_code].name,
3558 MvPrintw(LINES - 1, 0,
3559 "v/V cycles through video attributes (%s).",
3560 my_list[at_code].name);
3563 } while (!isQuit(c = Getchar()));
3570 #if USE_WIDEC_SUPPORT
3572 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3578 TEST_CCHAR(src, count, {
3579 attr |= (test_attrs & A_ALTCHARSET);
3580 setcchar(dst, test_wch, attr, pair, NULL);
3590 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3591 * display. If there are no repeats, we could normally display 16 lines of 64
3592 * characters (1024 total). However, taking repeats and double-width cells
3593 * into account, use 256 characters for the page.
3596 show_paged_widechars(int base,
3601 NCURSES_PAIRS_T pair)
3603 int first = base * pagesize;
3604 int last = first + pagesize - 1;
3612 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3615 for (code = (wchar_t) first; (int) code <= last; code++) {
3616 int row = (2 + ((int) code - first) / per_line);
3617 int col = 5 * ((int) code % per_line);
3620 memset(&codes, 0, sizeof(codes));
3622 setcchar(&temp, codes, attr, pair, 0);
3624 if (wcwidth(code) == 0 && code != 0) {
3625 addch((chtype) space |
3626 (A_REVERSE ^ attr) |
3627 (attr_t) COLOR_PAIR(pair));
3630 for (count = 1; count < repeat; ++count) {
3637 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3641 int last = first + 31;
3645 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3648 for (code = (wchar_t) first; (int) code <= last; code++) {
3649 int row = 2 + ((code - first) % 16);
3650 int col = ((code - first) / 16) * COLS / 2;
3656 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3657 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3659 memset(&codes, 0, sizeof(codes));
3661 setcchar(&temp, codes, attr, pair, 0);
3665 * Give non-spacing characters something to combine with. If we
3666 * don't, they'll bunch up in a heap on the space after the ":".
3667 * Mark them with reverse-video to make them simpler to find on
3670 if (wcwidth(code) == 0) {
3671 addch((chtype) space |
3672 (A_REVERSE ^ attr) |
3673 (attr_t) COLOR_PAIR(pair));
3676 * This uses echo_wchar(), for comparison with the normal 'f'
3677 * test (and to make a test-case for echo_wchar()). The screen
3678 * may flicker because the erase() at the top of the function
3679 * is met by the builtin refresh() in echo_wchar().
3683 * The repeat-count may make text wrap - avoid that.
3685 getyx(stdscr, y, x);
3687 if (x >= col + (COLS / 2) - 2)
3689 } while (--count > 0);
3694 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3696 const int height = 16;
3697 int row = 2 + (n % height);
3698 int col = (n / height) * COLS / 2;
3700 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3701 while (--repeat >= 0) {
3707 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3710 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3711 /* display the wide-ACS character set */
3717 /*#define BOTH2(name) #name, &(name) */
3718 #define BOTH2(name) #name, MERGE_ATTR(name)
3722 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3726 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3727 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3728 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3729 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3731 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3732 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3733 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3734 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3736 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3737 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3739 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3740 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3741 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3742 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3744 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3745 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3746 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3747 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3748 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3749 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3750 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3751 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3752 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3754 #ifdef CURSES_WACS_ARRAY
3755 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3756 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3757 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3759 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3760 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3761 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3762 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3763 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3764 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3770 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3771 /* display the wide-ACS character set */