1 /****************************************************************************
2 * Copyright (c) 1998-2015,2016 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.438 2016/06/11 21:05:48 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));
203 isQuit(int c, bool escape)
205 return ((c) == QUIT || (escape && ((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, int delay)
641 memset(flags, FALSE, NUM_GETCH_FLAGS);
642 flags[UChar('k')] = (win == stdscr);
643 flags[UChar('m')] = TRUE;
644 flags[UChar('t')] = (delay != 0);
646 setup_getch(win, flags);
650 blocking_getch(GetchFlags flags, int delay)
652 return ((delay < 0) && flags['t']);
655 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
658 wgetch_help(WINDOW *win, GetchFlags flags)
660 static const char *help[] =
662 "e -- toggle echo mode"
663 ,"g -- triggers a getstr test"
664 ,"k -- toggle keypad/literal mode"
665 ,"m -- toggle meta (7-bit/8-bit) mode"
668 ,"t -- toggle timeout"
669 ,"w -- create a new window"
671 ,"z -- suspend this process"
675 unsigned chk = ((SIZEOF(help) + 1) / 2);
680 printw("Type any key to see its %s value. Also:\n",
681 flags['k'] ? "keypad" : "literal");
682 for (n = 0; n < SIZEOF(help); ++n) {
683 const char *msg = help[n];
684 int row = 1 + (int) (n % chk);
685 int col = (n >= chk) ? COLS / 2 : 0;
686 int flg = ((strstr(msg, "toggle") != 0)
687 && (flags[UChar(*msg)] != FALSE));
688 if (*msg == '^' && ExitOnEscape())
689 msg = "^[,^q -- quit";
692 MvPrintw(row, col, "%s", msg);
703 wgetch_wrap(WINDOW *win, int first_y)
705 int last_y = getmaxy(win) - 1;
706 int y = getcury(win) + 1;
714 #if defined(KEY_RESIZE) && HAVE_WRESIZE
720 static WINSTACK *winstack = 0;
721 static unsigned len_winstack = 0;
734 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
736 unsigned need = (level + 1) * 2;
738 assert(level < (unsigned) COLS);
742 winstack = typeMalloc(WINSTACK, len_winstack);
743 } else if (need >= len_winstack) {
745 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
748 failed("remember_boxes");
749 winstack[level].text = txt_win;
750 winstack[level].frame = box_win;
753 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
757 /* this chunk is now done in resize_term() */
764 #define slk_repaint() /* nothing */
767 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
769 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
770 * Resize both and paint the box in the parent.
773 resize_boxes(unsigned level, WINDOW *win)
777 int high = LINES - base;
781 wnoutrefresh(stdscr);
785 for (n = 0; n < level; ++n) {
786 wresize(winstack[n].frame, high, wide);
787 wresize(winstack[n].text, high - 2, wide - 2);
790 werase(winstack[n].text);
791 box(winstack[n].frame, 0, 0);
792 wnoutrefresh(winstack[n].frame);
793 wprintw(winstack[n].text,
795 getmaxy(winstack[n].text),
796 getmaxx(winstack[n].text));
797 wnoutrefresh(winstack[n].text);
798 if (winstack[n].text == win)
803 #endif /* resize_boxes */
805 #define forget_boxes() /* nothing */
806 #define remember_boxes(level,text,frame) /* nothing */
810 * Return-code is OK/ERR or a keyname.
815 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
819 wgetch_test(unsigned level, WINDOW *win, int delay)
822 int first_y, first_x;
827 init_getch(win, flags, delay);
828 notimeout(win, FALSE);
829 wtimeout(win, delay);
830 getyx(win, first_y, first_x);
832 wgetch_help(win, flags);
833 wsetscrreg(win, first_y, getmaxy(win) - 1);
837 while ((c = wGetchar(win)) == ERR) {
839 if (blocking_getch(flags, delay)) {
840 (void) wprintw(win, "%05d: input error", incount);
843 (void) wprintw(win, "%05d: input timed out", incount);
845 wgetch_wrap(win, first_y);
847 if (c == ERR && blocking_getch(flags, delay)) {
849 wgetch_wrap(win, first_y);
850 } else if (isQuit(c, ExitOnEscape())) {
852 } else if (c == 'e') {
853 flags[UChar('e')] = !flags[UChar('e')];
854 setup_getch(win, flags);
855 wgetch_help(win, flags);
856 } else if (c == 'g') {
857 waddstr(win, "getstr test: ");
859 c = wgetnstr(win, buf, sizeof(buf) - 1);
861 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
862 (int) strlen(buf), buf,
865 wgetch_wrap(win, first_y);
866 } else if (c == 'k') {
867 flags[UChar('k')] = !flags[UChar('k')];
868 setup_getch(win, flags);
869 wgetch_help(win, flags);
870 } else if (c == 'm') {
871 flags[UChar('m')] = !flags[UChar('m')];
872 setup_getch(win, flags);
873 wgetch_help(win, flags);
874 } else if (c == 's') {
876 } else if (c == 't') {
877 notimeout(win, flags[UChar('t')]);
878 flags[UChar('t')] = !flags[UChar('t')];
879 wgetch_help(win, flags);
880 } else if (c == 'w') {
881 int high = getmaxy(win) - 1 - first_y + 1;
882 int wide = getmaxx(win) - first_x;
884 int new_y = first_y + getbegy(win);
885 int new_x = first_x + getbegx(win);
887 getyx(win, old_y, old_x);
888 if (high > 2 && wide > 2) {
889 WINDOW *wb = newwin(high, wide, new_y, new_x);
890 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
895 remember_boxes(level, wi, wb);
896 wgetch_test(level + 1, wi, delay);
900 wgetch_help(win, flags);
901 wmove(win, old_y, old_x);
907 } else if (c == 'z') {
908 kill(getpid(), SIGTSTP);
911 wprintw(win, "Key pressed: %04o ", c);
912 #ifdef NCURSES_MOUSE_VERSION
913 if (c == KEY_MOUSE) {
916 #endif /* NCURSES_MOUSE_VERSION */
918 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
919 if (c == KEY_RESIZE) {
920 resize_boxes(level, win);
923 (void) waddstr(win, keyname(c));
924 } else if (c >= 0x80) {
925 unsigned c2 = (unsigned) c;
926 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
927 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
931 (void) wprintw(win, "%c", UChar(c));
932 else if (c2 != UChar(c))
933 (void) wprintw(win, "M-%s", unctrl(c2));
935 (void) wprintw(win, "%s", unctrl(c2));
936 waddstr(win, " (high-half character)");
939 (void) wprintw(win, "%c (ASCII printable character)", c);
941 (void) wprintw(win, "%s (ASCII control character)",
944 wgetch_wrap(win, first_y);
951 init_getch(win, flags, delay);
955 begin_getch_test(void)
962 #ifdef NCURSES_MOUSE_VERSION
963 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
966 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
968 getnstr(buf, sizeof(buf) - 1);
972 if (isdigit(UChar(buf[0]))) {
973 delay = atoi(buf) * 100;
983 finish_getch_test(void)
985 #ifdef NCURSES_MOUSE_VERSION
986 mousemask(0, (mmask_t *) 0);
997 int delay = begin_getch_test();
1000 wgetch_test(0, stdscr, delay);
1002 finish_getch_test();
1006 #if USE_WIDEC_SUPPORT
1008 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1009 * Resize both and paint the box in the parent.
1011 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1013 resize_wide_boxes(unsigned level, WINDOW *win)
1017 int high = LINES - base;
1021 wnoutrefresh(stdscr);
1025 for (n = 0; n < level; ++n) {
1026 wresize(winstack[n].frame, high, wide);
1027 wresize(winstack[n].text, high - 2, wide - 2);
1030 werase(winstack[n].text);
1031 box_set(winstack[n].frame, 0, 0);
1032 wnoutrefresh(winstack[n].frame);
1033 wprintw(winstack[n].text,
1035 getmaxy(winstack[n].text),
1036 getmaxx(winstack[n].text));
1037 wnoutrefresh(winstack[n].text);
1038 if (winstack[n].text == win)
1043 #endif /* KEY_RESIZE */
1046 wcstos(const wchar_t *src)
1050 const wchar_t *tmp = src;
1051 #ifndef state_unused
1055 reset_wchars(state);
1056 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1057 unsigned have = (unsigned) need;
1058 if ((result = typeCalloc(char, have + 1)) != 0) {
1060 if (trans_wchars(result, tmp, have, &state) != have) {
1072 wget_wch_test(unsigned level, WINDOW *win, int delay)
1074 wchar_t wchar_buf[BUFSIZ];
1075 wint_t wint_buf[BUFSIZ];
1076 int first_y, first_x;
1083 init_getch(win, flags, delay);
1084 notimeout(win, FALSE);
1085 wtimeout(win, delay);
1086 getyx(win, first_y, first_x);
1088 wgetch_help(win, flags);
1089 wsetscrreg(win, first_y, getmaxy(win) - 1);
1090 scrollok(win, TRUE);
1093 while ((code = wGet_wchar(win, &c)) == ERR) {
1095 if (blocking_getch(flags, delay)) {
1096 (void) wprintw(win, "%05d: input error", incount);
1099 (void) wprintw(win, "%05d: input timed out", incount);
1101 wgetch_wrap(win, first_y);
1103 if (code == ERR && blocking_getch(flags, delay)) {
1104 wprintw(win, "ERR");
1105 wgetch_wrap(win, first_y);
1106 } else if (isQuit((int) c, ExitOnEscape())) {
1108 } else if (c == 'e') {
1109 flags[UChar('e')] = !flags[UChar('e')];
1110 setup_getch(win, flags);
1111 wgetch_help(win, flags);
1112 } else if (c == 'g') {
1113 waddstr(win, "getstr test: ");
1115 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1118 wprintw(win, "wgetn_wstr returns an error.");
1121 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1124 if ((temp = wcstos(wchar_buf)) != 0) {
1125 wprintw(win, "I saw %d characters:\n\t`%s'.",
1126 (int) wcslen(wchar_buf), temp);
1129 wprintw(win, "I saw %d characters (cannot convert).",
1130 (int) wcslen(wchar_buf));
1134 wgetch_wrap(win, first_y);
1135 } else if (c == 'k') {
1136 flags[UChar('k')] = !flags[UChar('k')];
1137 setup_getch(win, flags);
1138 wgetch_help(win, flags);
1139 } else if (c == 'm') {
1140 flags[UChar('m')] = !flags[UChar('m')];
1141 setup_getch(win, flags);
1142 wgetch_help(win, flags);
1143 } else if (c == 's') {
1145 } else if (c == 't') {
1146 notimeout(win, flags[UChar('t')]);
1147 flags[UChar('t')] = !flags[UChar('t')];
1148 wgetch_help(win, flags);
1149 } else if (c == 'w') {
1150 int high = getmaxy(win) - 1 - first_y + 1;
1151 int wide = getmaxx(win) - first_x;
1153 int new_y = first_y + getbegy(win);
1154 int new_x = first_x + getbegx(win);
1156 getyx(win, old_y, old_x);
1157 if (high > 2 && wide > 2) {
1158 WINDOW *wb = newwin(high, wide, new_y, new_x);
1159 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1164 remember_boxes(level, wi, wb);
1165 wget_wch_test(level + 1, wi, delay);
1169 wgetch_help(win, flags);
1170 wmove(win, old_y, old_x);
1175 } else if (c == 'z') {
1176 kill(getpid(), SIGTSTP);
1179 wprintw(win, "Key pressed: %04o ", (int) c);
1180 #ifdef NCURSES_MOUSE_VERSION
1181 if (c == KEY_MOUSE) {
1184 #endif /* NCURSES_MOUSE_VERSION */
1185 if (code == KEY_CODE_YES) {
1186 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1187 if (c == KEY_RESIZE) {
1188 resize_wide_boxes(level, win);
1191 (void) waddstr(win, keyname((wchar_t) c));
1193 (void) waddstr(win, key_name((wchar_t) c));
1194 if (c < 256 && iscntrl(c)) {
1195 (void) wprintw(win, " (control character)");
1197 (void) wprintw(win, " = %#x (printable character)",
1201 wgetch_wrap(win, first_y);
1208 init_getch(win, flags, delay);
1214 int delay = begin_getch_test();
1217 wget_wch_test(0, stdscr, delay);
1219 finish_getch_test();
1224 /****************************************************************************
1226 * Character attributes test
1228 ****************************************************************************/
1230 #if HAVE_SETUPTERM || HAVE_TGETENT
1231 #define get_ncv() TIGETNUM("ncv","NC")
1232 #define get_xmc() TIGETNUM("xmc","sg")
1234 #define get_ncv() -1
1235 #define get_xmc() -1
1242 static int first = TRUE;
1243 static chtype result = 0;
1249 char *area_pointer = parsed;
1251 tgetent(buffer, getenv("TERM"));
1254 if (TIGETSTR("smso", "so"))
1255 result |= A_STANDOUT;
1256 if (TIGETSTR("smul", "us"))
1257 result |= A_UNDERLINE;
1258 if (TIGETSTR("rev", "mr"))
1259 result |= A_REVERSE;
1260 if (TIGETSTR("blink", "mb"))
1262 if (TIGETSTR("dim", "mh"))
1264 if (TIGETSTR("bold", "md"))
1266 if (TIGETSTR("smacs", "ac"))
1267 result |= A_ALTCHARSET;
1273 #define termattrs() my_termattrs()
1276 #define ATTRSTRING_1ST 32 /* ' ' */
1277 #define ATTRSTRING_END 126 /* '~' */
1279 #define COLS_PRE_ATTRS 5
1280 #define COLS_AFT_ATTRS 15
1281 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1282 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1283 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1285 static char attr_test_string[MAX_ATTRSTRING + 1];
1288 attr_legend(WINDOW *helpwin)
1293 MvWPrintw(helpwin, row++, col,
1295 MvWPrintw(helpwin, row++, col,
1298 MvWPrintw(helpwin, row++, col,
1299 "Modify the test strings:");
1300 MvWPrintw(helpwin, row++, col,
1301 " A digit sets gaps on each side of displayed attributes");
1302 MvWPrintw(helpwin, row++, col,
1303 " </> shifts the text left/right. ");
1305 MvWPrintw(helpwin, row++, col,
1308 MvWPrintw(helpwin, row++, col,
1309 " f/F/b/F toggle foreground/background background color");
1310 MvWPrintw(helpwin, row++, col,
1311 " t/T toggle text/background color attribute");
1313 MvWPrintw(helpwin, row++, col,
1314 " a/A toggle ACS (alternate character set) mapping");
1315 MvWPrintw(helpwin, row, col,
1316 " v/V toggle video attribute to combine with each line");
1317 #if USE_WIDEC_SUPPORT
1318 MvWPrintw(helpwin, row, col,
1319 " w/W toggle normal/wide (double-width) test-characters");
1324 show_color_attr(int fg, int bg, int tx)
1327 printw(" Colors (fg %d, bg %d", fg, bg);
1329 printw(", text %d", tx);
1335 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1342 *fg = (NCURSES_COLOR_T) (*fg + 1);
1345 *fg = (NCURSES_COLOR_T) (*fg - 1);
1348 *bg = (NCURSES_COLOR_T) (*bg + 1);
1351 *bg = (NCURSES_COLOR_T) (*bg - 1);
1354 *tx = (NCURSES_COLOR_T) (*tx + 1);
1357 *tx = (NCURSES_COLOR_T) (*tx - 1);
1365 *fg = (NCURSES_COLOR_T) min_colors;
1366 if (*fg < min_colors)
1367 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1369 *bg = (NCURSES_COLOR_T) min_colors;
1370 if (*bg < min_colors)
1371 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1375 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1384 adjust_attr_string(int adjust)
1386 char save = attr_test_string[0];
1387 int first = ((int) UChar(save)) + adjust;
1390 if (first >= ATTRSTRING_1ST) {
1391 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1392 if (k > ATTRSTRING_END)
1394 attr_test_string[j] = (char) k;
1395 if (((k + 1 - first) % 5) == 0) {
1396 if (++j >= MAX_ATTRSTRING)
1398 attr_test_string[j] = ' ';
1401 if ((LEN_ATTRSTRING - j) > 5) {
1402 attr_test_string[0] = save;
1403 adjust_attr_string(adjust - 1);
1405 while (j < MAX_ATTRSTRING)
1406 attr_test_string[j++] = ' ';
1407 attr_test_string[j] = '\0';
1413 * Prefer the right-end of the string for starting, since that maps to the
1414 * VT100 line-drawing.
1417 default_attr_string(void)
1419 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1420 result += (LEN_ATTRSTRING / 5);
1421 if (result < ATTRSTRING_1ST)
1422 result = ATTRSTRING_1ST;
1427 init_attr_string(void)
1429 attr_test_string[0] = (char) default_attr_string();
1430 adjust_attr_string(0);
1434 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1436 int ncv = get_ncv();
1437 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1440 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1441 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1442 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1444 printw("%*s", skip, " ");
1446 * Just for testing, write text using the alternate character set one
1447 * character at a time (to pass its rendition directly), and use the
1448 * string operation for the other attributes.
1452 if (attr & A_ALTCHARSET) {
1456 for (s = attr_test_string; *s != '\0'; ++s) {
1458 (void) waddch(win, ch | attr);
1461 (void) wattrset(win, AttrArg(attr, 0));
1462 (void) waddstr(win, attr_test_string);
1463 (void) wattroff(win, (int) attr);
1466 printw("%*s", skip, " ");
1467 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1468 if (test != A_NORMAL) {
1469 if (!(termattrs() & test)) {
1472 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1473 static const chtype table[] =
1492 for (n = 0; n < SIZEOF(table); n++) {
1493 if ((table[n] & attr) != 0
1494 && ((1 << n) & ncv) != 0) {
1502 if ((termattrs() & test) != test) {
1512 NCURSES_CONST char *name;
1515 static const ATTR_TBL attrs_to_test[] = {
1516 { A_STANDOUT, "STANDOUT" },
1517 { A_REVERSE, "REVERSE" },
1519 { A_UNDERLINE, "UNDERLINE" },
1521 { A_BLINK, "BLINK" },
1522 { A_PROTECT, "PROTECT" },
1524 { A_INVIS, "INVISIBLE" },
1527 { A_ITALIC, "ITALIC" },
1529 { A_NORMAL, "NORMAL" },
1534 init_attr_list(ATTR_TBL * target, attr_t attrs)
1536 unsigned result = 0;
1539 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1540 attr_t test = attrs_to_test[n].attr;
1541 if (test == A_NORMAL || (test & attrs) != 0) {
1542 target[result++] = attrs_to_test[n];
1549 attr_getc(int *skip,
1550 NCURSES_COLOR_T *fg,
1551 NCURSES_COLOR_T *bg,
1552 NCURSES_COLOR_T *tx,
1565 if (ch < 256 && isdigit(ch)) {
1573 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1575 attr_legend(helpwin);
1598 adjust_attr_string(-1);
1601 adjust_attr_string(1);
1607 error = cycle_color_attr(ch, fg, bg, tx);
1617 /* test text attributes */
1620 int skip = get_xmc();
1621 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1622 NCURSES_COLOR_T bg = COLOR_BLACK;
1623 NCURSES_COLOR_T tx = -1;
1626 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1627 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1628 unsigned my_size = init_attr_list(my_list, termattrs());
1631 for (j = 0; j < my_size; ++j) {
1632 my_wins[j] = subwin(stdscr,
1634 2 + (int) (2 * j), COL_ATTRSTRING);
1635 scrollok(my_wins[j], FALSE);
1641 n = skip; /* make it easy */
1647 chtype normal = A_NORMAL | BLANK;
1648 chtype extras = (chtype) ac;
1651 NCURSES_PAIRS_T pair = 0;
1652 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1654 if (init_pair(pair, fg, bg) == ERR) {
1657 normal |= (chtype) COLOR_PAIR(pair);
1662 if (init_pair(pair, tx, bg) == ERR) {
1665 extras |= (chtype) COLOR_PAIR(pair);
1675 MvAddStr(0, 20, "Character attribute test display");
1677 for (j = 0; j < my_size; ++j) {
1678 bool arrow = (j == k);
1679 row = show_attr(my_wins[j], row, n, arrow,
1687 MvPrintw(row, COLS_PRE_ATTRS,
1688 "This terminal does %shave the magic-cookie glitch",
1689 get_xmc() > -1 ? "" : "not ");
1690 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1691 show_color_attr(fg, bg, tx);
1692 printw(" ACS (%d)", ac != 0);
1695 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1697 bkgdset(A_NORMAL | BLANK);
1701 Cannot("does not support video attributes.");
1705 #if USE_WIDEC_SUPPORT
1706 static bool use_fullwidth;
1707 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1709 #define FULL_LO 0xff00
1710 #define FULL_HI 0xff5e
1711 #define HALF_LO 0x20
1713 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1714 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1715 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1718 * Returns an ASCII code in [32..126]
1721 normal_wchar(int ch)
1723 wchar_t result = (wchar_t) ch;
1724 if (isFullWidth(ch))
1725 result = ToNormalWidth(ch);
1730 * Returns either an ASCII code in in [32..126] or full-width in
1731 * [0xff00..0xff5e], according to use_fullwidth setting.
1734 target_wchar(int ch)
1736 wchar_t result = (wchar_t) ch;
1737 if (use_fullwidth) {
1738 if (!isFullWidth(ch))
1739 result = ToFullWidth(ch);
1741 if (isFullWidth(ch))
1742 result = ToNormalWidth(ch);
1748 wide_adjust_attr_string(int adjust)
1750 wchar_t save = wide_attr_test_string[0];
1751 int first = ((int) normal_wchar(save)) + adjust;
1754 if (first >= ATTRSTRING_1ST) {
1755 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1756 if (k > ATTRSTRING_END)
1758 wide_attr_test_string[j] = target_wchar(k);
1759 if (((k + 1 - first) % 5) == 0) {
1760 if (++j >= MAX_ATTRSTRING)
1762 wide_attr_test_string[j] = ' ';
1765 if ((LEN_ATTRSTRING - j) > 5) {
1766 wide_attr_test_string[0] = save;
1767 wide_adjust_attr_string(adjust - 1);
1769 while (j < MAX_ATTRSTRING)
1770 wide_attr_test_string[j++] = ' ';
1771 wide_attr_test_string[j] = '\0';
1777 wide_init_attr_string(void)
1779 use_fullwidth = FALSE;
1780 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1781 wide_adjust_attr_string(0);
1785 set_wide_background(NCURSES_PAIRS_T pair)
1792 setcchar(&normal, blank, A_NORMAL, pair, 0);
1798 get_wide_background(void)
1800 attr_t result = A_NORMAL;
1803 NCURSES_PAIRS_T pair;
1806 memset(&ch, 0, sizeof(ch));
1807 if (getbkgrnd(&ch) != ERR) {
1808 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1816 wide_show_attr(WINDOW *win,
1821 NCURSES_PAIRS_T pair,
1824 int ncv = get_ncv();
1825 chtype test = attr & ~WA_ALTCHARSET;
1828 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1829 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1830 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1832 printw("%*s", skip, " ");
1835 * Just for testing, write text using the alternate character set one
1836 * character at a time (to pass its rendition directly), and use the
1837 * string operation for the other attributes.
1841 if (attr & WA_ALTCHARSET) {
1845 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1849 setcchar(&ch, fill, attr, pair, 0);
1850 (void) wadd_wch(win, &ch);
1853 attr_t old_attr = 0;
1854 NCURSES_PAIRS_T old_pair = 0;
1856 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1857 (void) wattr_set(win, attr, pair, 0);
1858 (void) waddwstr(win, wide_attr_test_string);
1859 (void) wattr_set(win, old_attr, old_pair, 0);
1862 printw("%*s", skip, " ");
1863 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1864 if (test != A_NORMAL) {
1865 if (!(term_attrs() & test)) {
1868 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1869 static const attr_t table[] =
1883 for (n = 0; n < SIZEOF(table); n++) {
1884 if ((table[n] & attr) != 0
1885 && ((1 << n) & ncv) != 0) {
1893 if ((term_attrs() & test) != test) {
1902 wide_attr_getc(int *skip,
1903 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1904 NCURSES_COLOR_T *tx, int *ac,
1905 unsigned *kc, unsigned limit)
1915 if (ch < 256 && isdigit(ch)) {
1923 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1924 box_set(helpwin, 0, 0);
1925 attr_legend(helpwin);
1948 use_fullwidth = FALSE;
1949 wide_adjust_attr_string(0);
1952 use_fullwidth = TRUE;
1953 wide_adjust_attr_string(0);
1956 wide_adjust_attr_string(-1);
1959 wide_adjust_attr_string(1);
1965 error = cycle_color_attr(ch, fg, bg, tx);
1974 wide_attr_test(void)
1975 /* test text attributes using wide-character calls */
1978 int skip = get_xmc();
1979 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1980 NCURSES_COLOR_T bg = COLOR_BLACK;
1981 NCURSES_COLOR_T tx = -1;
1984 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1985 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1986 unsigned my_size = init_attr_list(my_list, term_attrs());
1989 for (j = 0; j < my_size; ++j) {
1990 my_wins[j] = subwin(stdscr,
1992 2 + (int) (2 * j), COL_ATTRSTRING);
1993 scrollok(my_wins[j], FALSE);
1999 n = skip; /* make it easy */
2001 wide_init_attr_string();
2005 NCURSES_PAIRS_T pair = 0;
2006 NCURSES_PAIRS_T extras = 0;
2009 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2012 if (init_pair(pair, fg, bg) == ERR) {
2019 if (init_pair(extras, tx, bg) == ERR) {
2024 set_wide_background(pair);
2027 box_set(stdscr, 0, 0);
2028 MvAddStr(0, 20, "Character attribute test display");
2030 for (j = 0; j < my_size; ++j) {
2031 row = wide_show_attr(my_wins[j], row, n, (j == k),
2039 MvPrintw(row, COLS_PRE_ATTRS,
2040 "This terminal does %shave the magic-cookie glitch",
2041 get_xmc() > -1 ? "" : "not ");
2042 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2043 show_color_attr(fg, bg, tx);
2044 printw(" ACS (%d)", ac != 0);
2047 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2049 set_wide_background(0);
2053 Cannot("does not support extended video attributes.");
2058 /****************************************************************************
2060 * Color support tests
2062 ****************************************************************************/
2064 static NCURSES_CONST char *the_color_names[] =
2085 show_color_name(int y, int x, int color, bool wide)
2087 if (move(y, x) != ERR) {
2092 sprintf(temp, "%02d", color);
2094 } else if (color >= 8) {
2095 sprintf(temp, "[%02d]", color);
2096 } else if (color < 0) {
2097 strcpy(temp, "default");
2099 sprintf(temp, "%.*s", 16, the_color_names[color]);
2101 printw("%-*.*s", width, width, temp);
2106 color_legend(WINDOW *helpwin, bool wide)
2111 MvWPrintw(helpwin, row++, col,
2114 MvWPrintw(helpwin, row++, col,
2115 "Use up/down arrow to scroll through the display if it is");
2116 MvWPrintw(helpwin, row++, col,
2117 "longer than one screen. Control/N and Control/P can be used");
2118 MvWPrintw(helpwin, row++, col,
2119 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2120 MvWPrintw(helpwin, row++, col,
2121 "full screen; control/B and control/F can be used here.");
2123 MvWPrintw(helpwin, row++, col,
2125 MvWPrintw(helpwin, row++, col,
2126 " a/A toggle altcharset off/on");
2127 MvWPrintw(helpwin, row++, col,
2128 " b/B toggle bold off/on");
2130 MvWPrintw(helpwin, row++, col,
2131 " c/C cycle used-colors through 8,16,...,COLORS");
2133 MvWPrintw(helpwin, row++, col,
2134 " n/N toggle text/number on/off");
2135 MvWPrintw(helpwin, row++, col,
2136 " r/R toggle reverse on/off");
2137 MvWPrintw(helpwin, row++, col,
2138 " w/W toggle width between 8/16 colors");
2139 #if USE_WIDEC_SUPPORT
2141 MvWPrintw(helpwin, row++, col,
2142 "Wide characters:");
2143 MvWPrintw(helpwin, row, col,
2144 " x/X toggle text between ASCII and wide-character");
2151 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2154 color_cycle(int current, int step)
2156 int result = current;
2162 if ((result * 2) > COLORS) {
2165 while ((result * 2) < current) {
2171 if (current >= COLORS) {
2176 if (result > COLORS)
2182 /* generate a color test pattern */
2189 int grid_top = top + 3;
2190 int page_size = (LINES - grid_top);
2192 int colors_max = COLORS;
2199 bool opt_acsc = FALSE;
2200 bool opt_bold = FALSE;
2201 bool opt_revs = FALSE;
2202 bool opt_nums = FALSE;
2203 bool opt_wide = FALSE;
2206 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2207 done = ((COLS < 16) || (numbered == 0));
2210 * Because the number of colors is usually a power of two, we also use
2211 * a power of two for the number of colors shown per line (to be tidy).
2213 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2218 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2219 if (colors_max * colors_max <= COLOR_PAIRS) {
2220 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2221 if (pairs_max > limit)
2224 if (pairs_max > COLOR_PAIRS)
2225 pairs_max = COLOR_PAIRS;
2228 /* this assumes an 80-column line */
2232 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2236 per_row = (col_limit / 8);
2238 per_row -= min_colors;
2240 row_limit = (pairs_max + per_row - 1) / per_row;
2243 (void) printw("There are %d color pairs and %d colors",
2245 if (colors_max != COLORS)
2246 (void) printw(" (using %d colors)", colors_max);
2248 (void) addstr(" besides 'default'");
2251 MvPrintw(top + 1, 0,
2252 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2255 opt_bold ? "on" : "off");
2257 /* show color names/numbers across the top */
2258 for (i = 0; i < per_row; i++)
2259 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2261 /* show a grid of colors, with color names/ numbers on the left */
2262 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2263 int row = grid_top + (i / per_row) - base_row;
2264 int col = (i % per_row + 1) * width;
2265 NCURSES_PAIRS_T pair = i;
2267 if ((i / per_row) > row_limit)
2270 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - min_colors)) + min_colors)
2271 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - min_colors)) + min_colors)
2272 if (row >= 0 && move(row, col) != ERR) {
2273 NCURSES_COLOR_T fg = InxToFG(i);
2274 NCURSES_COLOR_T bg = InxToBG(i);
2276 init_pair(pair, fg, bg);
2277 attron(COLOR_PAIR(pair));
2279 attron(A_ALTCHARSET);
2286 sprintf(numbered, "{%02X}", (int) i);
2289 printw("%-*.*s", width, width, hello);
2290 (void) attrset(A_NORMAL);
2292 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2293 show_color_name(row, 0, InxToBG(i), opt_wide);
2301 switch (wGetchar(stdscr)) {
2315 colors_max = color_cycle(colors_max, -1);
2318 colors_max = color_cycle(colors_max, 1);
2336 set_color_test(opt_wide, FALSE);
2339 set_color_test(opt_wide, TRUE);
2343 if (base_row <= 0) {
2351 if (base_row + page_size >= row_limit) {
2360 if (base_row <= 0) {
2363 base_row -= (page_size - 1);
2371 if (base_row + page_size >= row_limit) {
2374 base_row += page_size - 1;
2375 if (base_row + page_size >= row_limit) {
2376 base_row = row_limit - page_size - 1;
2381 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2383 color_legend(helpwin, FALSE);
2400 #if USE_WIDEC_SUPPORT
2401 /* generate a color test pattern */
2403 wide_color_test(void)
2408 int grid_top = top + 3;
2409 int page_size = (LINES - grid_top);
2410 int pairs_max = (unsigned short) (-1);
2411 int colors_max = COLORS;
2418 bool opt_acsc = FALSE;
2419 bool opt_bold = FALSE;
2420 bool opt_revs = FALSE;
2421 bool opt_wide = FALSE;
2422 bool opt_nums = FALSE;
2423 bool opt_xchr = FALSE;
2424 wchar_t *buffer = 0;
2427 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2428 buffer = (wchar_t *) calloc((size_t) (COLS + 1), sizeof(wchar_t));
2429 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2432 * Because the number of colors is usually a power of two, we also use
2433 * a power of two for the number of colors shown per line (to be tidy).
2435 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2440 pairs_max = (unsigned short) (-1);
2441 if (colors_max * colors_max <= COLOR_PAIRS) {
2442 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2443 if (pairs_max > limit)
2446 if (pairs_max > COLOR_PAIRS)
2447 pairs_max = COLOR_PAIRS;
2453 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2457 per_row = (col_limit / 8);
2459 per_row -= min_colors;
2462 make_fullwidth_text(buffer, hello);
2466 make_narrow_text(buffer, hello);
2469 row_limit = (pairs_max + per_row - 1) / per_row;
2472 (void) printw("There are %d color pairs and %d colors",
2474 if (colors_max != COLORS)
2475 (void) printw(" (using %d colors)", colors_max);
2477 (void) addstr(" besides 'default'");
2480 MvPrintw(top + 1, 0,
2481 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2484 opt_bold ? "on" : "off");
2486 /* show color names/numbers across the top */
2487 for (i = 0; i < per_row; i++)
2488 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2490 /* show a grid of colors, with color names/ numbers on the left */
2491 for (i = (base_row * per_row); i < pairs_max; i++) {
2492 int row = grid_top + (i / per_row) - base_row;
2493 int col = (i % per_row + 1) * width;
2494 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2496 if ((i / per_row) > row_limit)
2499 if (row >= 0 && move(row, col) != ERR) {
2500 init_pair(pair, InxToFG(i), InxToBG(i));
2501 (void) color_set(pair, NULL);
2503 attr_on(A_ALTCHARSET, NULL);
2505 attr_on(A_BOLD, NULL);
2507 attr_on(A_REVERSE, NULL);
2510 sprintf(numbered, "{%02X}", i);
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 */
2637 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2639 NCURSES_COLOR_T red, green, blue;
2641 color_content(current, &red, &green, &blue);
2645 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2648 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2651 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2655 if (init_color(current, red, green, blue) == ERR)
2660 reset_all_colors(void)
2664 for (c = 0; c < COLORS; ++c)
2667 all_colors[c].green,
2668 all_colors[c].blue);
2671 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
2672 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2673 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2676 init_all_colors(bool xterm_colors, char *palette_file)
2679 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
2681 failed("all_colors");
2682 for (cp = 0; cp < max_colors; ++cp) {
2684 &all_colors[cp].red,
2685 &all_colors[cp].green,
2686 &all_colors[cp].blue);
2688 /* xterm and compatible terminals can read results of an OSC string
2689 * asking for the current color palette.
2694 char result[BUFSIZ];
2695 int check_n, check_r, check_g, check_b;
2699 for (n = 0; n < max_colors; ++n) {
2700 fprintf(stderr, "\033]4;%d;?\007", n);
2701 got = (int) read(0, result, sizeof(result) - 1);
2705 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2711 all_colors[n].red = DecodeRGB(check_r);
2712 all_colors[n].green = DecodeRGB(check_g);
2713 all_colors[n].blue = DecodeRGB(check_b);
2720 if (palette_file != 0) {
2721 FILE *fp = fopen(palette_file, "r");
2723 char buffer[BUFSIZ];
2724 int red, green, blue;
2727 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2728 if (sscanf(buffer, "scale:%d", &c) == 1) {
2730 } else if (sscanf(buffer, "%d:%d %d %d",
2739 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2740 all_colors[c].red = Scaled(red);
2741 all_colors[c].green = Scaled(green);
2742 all_colors[c].blue = Scaled(blue);
2750 #define scaled_rgb(n) ((255 * (n)) / 1000)
2754 /* display the color test pattern, without trying to edit colors */
2758 int this_c, value, field;
2772 page_size = (LINES - 6);
2775 for (i = 0; i < max_colors; i++)
2776 init_pair((NCURSES_PAIRS_T) i,
2777 (NCURSES_COLOR_T) COLOR_WHITE,
2778 (NCURSES_COLOR_T) i);
2780 MvPrintw(LINES - 2, 0, "Number: %d", value);
2783 NCURSES_COLOR_T red, green, blue;
2786 MvAddStr(0, 20, "Color RGB Value Editing");
2789 for (i = (NCURSES_COLOR_T) top_color;
2790 (i - top_color < page_size)
2791 && (i < max_colors); i++) {
2794 sprintf(numeric, "[%d]", i);
2795 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2796 (i == current ? '>' : ' '),
2797 (i < (int) SIZEOF(the_color_names)
2798 ? the_color_names[i] : numeric));
2799 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2801 (void) attrset(A_NORMAL);
2803 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2805 if (current == i && field == 0)
2807 printw("%04d", (int) red);
2808 if (current == i && field == 0)
2809 (void) attrset(A_NORMAL);
2811 if (current == i && field == 1)
2813 printw("%04d", (int) green);
2814 if (current == i && field == 1)
2815 (void) attrset(A_NORMAL);
2817 if (current == i && field == 2)
2819 printw("%04d", (int) blue);
2820 if (current == i && field == 2)
2821 (void) attrset(A_NORMAL);
2822 (void) attrset(A_NORMAL);
2823 printw(" ( %3d %3d %3d )",
2824 (int) scaled_rgb(red),
2825 (int) scaled_rgb(green),
2826 (int) scaled_rgb(blue));
2829 MvAddStr(LINES - 3, 0,
2830 "Use up/down to select a color, left/right to change fields.");
2831 MvAddStr(LINES - 2, 0,
2832 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2834 move(2 + current - top_color, 0);
2838 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2860 current -= (page_size - 1);
2867 if (current < (max_colors - 1))
2868 current += (page_size - 1);
2875 current = (current == 0 ? (max_colors - 1) : current - 1);
2880 current = (current == (max_colors - 1) ? 0 : current + 1);
2885 field = (field == 2 ? 0 : field + 1);
2890 field = (field == 0 ? 2 : field - 1);
2903 value = value * 10 + (this_c - '0');
2907 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2911 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2915 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2920 P(" RGB Value Editing Help");
2922 P("You are in the RGB value editor. Use the arrow keys to select one of");
2923 P("the fields in one of the RGB triples of the current colors; the one");
2924 P("currently selected will be reverse-video highlighted.");
2926 P("To change a field, enter the digits of the new value; they are echoed");
2927 P("as entered. Finish by typing `='. The change will take effect instantly.");
2928 P("To increment or decrement a value, use the same procedure, but finish");
2929 P("with a `+' or `-'.");
2931 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
2933 P("Press 'm' to invoke the top-level menu with the current color settings.");
2934 P("To quit, do ESC");
2943 for (i = 0; i < max_colors; i++)
2944 init_pair((NCURSES_PAIRS_T) i,
2945 (NCURSES_COLOR_T) COLOR_WHITE,
2946 (NCURSES_COLOR_T) i);
2960 if (current >= max_colors)
2961 current = max_colors - 1;
2962 if (current < top_color)
2963 top_color = current;
2964 if (current - top_color >= page_size)
2965 top_color = current - (page_size - 1);
2967 MvPrintw(LINES - 1, 0, "Number: %d", value);
2970 (!isQuit(this_c, TRUE));
2975 * ncurses does not reset each color individually when calling endwin().
2982 /****************************************************************************
2984 * Alternate character-set stuff
2986 ****************************************************************************/
2988 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
2994 if ((*at_code += 1) >= limit)
2999 *at_code = limit - 1;
3008 *attr = list[*at_code].attr;
3013 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3015 bool result = FALSE;
3025 if ((*fg += 1) >= COLORS)
3033 if ((*bg += 1) >= COLORS)
3041 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3044 if (init_pair(*pair,
3045 (NCURSES_COLOR_T) *fg,
3046 (NCURSES_COLOR_T) *bg) == ERR) {
3055 /****************************************************************************
3057 * Soft-key label test
3059 ****************************************************************************/
3064 #define SLK_WORK (SLK_HELP + 3)
3069 static const char *table[] =
3071 "Available commands are:"
3073 ,"^L -- repaint this message and activate soft keys"
3074 ,"a/d -- activate/disable soft keys"
3075 ,"c -- set centered format for labels"
3076 ,"l -- set left-justified format for labels"
3077 ,"r -- set right-justified format for labels"
3078 ,"[12345678] -- set label; labels are numbered 1 through 8"
3079 ,"e -- erase stdscr (should not erase labels)"
3080 ,"s -- test scrolling of shortened screen"
3081 ,"v/V -- cycle through video attributes"
3083 ,"F/f/B/b -- cycle through foreground/background colors"
3085 ,"ESC -- return to main menu"
3087 ,"Note: if activating the soft keys causes your terminal to scroll up"
3088 ,"one line, your terminal auto-scrolls when anything is written to the"
3089 ,"last screen position. The ncurses code does not yet handle this"
3095 for (j = 0; j < SIZEOF(table); ++j) {
3103 call_slk_color(int fg, int bg)
3105 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3107 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3117 /* exercise the soft keys */
3122 chtype attr = A_NORMAL;
3123 unsigned at_code = 0;
3125 int fg = COLOR_BLACK;
3126 int bg = COLOR_WHITE;
3127 NCURSES_PAIRS_T pair = 0;
3129 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3130 unsigned my_size = init_attr_list(my_list, termattrs());
3135 call_slk_color(fg, bg);
3145 MvAddStr(0, 20, "Soft Key Exerciser");
3160 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3161 while ((c = Getchar()) != 'Q' && (c != ERR))
3189 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3191 if ((s = slk_label(c - '0')) != 0) {
3192 strncpy(buf, s, (size_t) 8);
3194 wGetstring(stdscr, buf, 8);
3195 slk_set((c - '0'), buf, fmt);
3204 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3206 wnoutrefresh(stdscr);
3211 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3218 if (cycle_colors(c, &fg, &bg, &pair)) {
3220 call_slk_color(fg, bg);
3230 } while (!isQuit(c = Getchar(), TRUE));
3238 #if USE_WIDEC_SUPPORT
3242 /* exercise the soft keys */
3245 wchar_t buf[SLKLEN + 1];
3247 chtype attr = A_NORMAL;
3248 unsigned at_code = 0;
3249 int fg = COLOR_BLACK;
3250 int bg = COLOR_WHITE;
3251 NCURSES_PAIRS_T pair = 0;
3252 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3253 unsigned my_size = init_attr_list(my_list, term_attrs());
3257 call_slk_color(fg, bg);
3264 attr_on(WA_BOLD, NULL);
3265 MvAddStr(0, 20, "Soft Key Exerciser");
3266 attr_off(WA_BOLD, NULL);
3280 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3281 while ((c = Getchar()) != 'Q' && (c != ERR))
3309 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3311 if ((s = slk_label(c - '0')) != 0) {
3312 char *temp = strdup(s);
3313 size_t used = strlen(temp);
3314 size_t want = SLKLEN;
3316 #ifndef state_unused
3321 while (want > 0 && used != 0) {
3322 const char *base = s;
3323 reset_mbytes(state);
3324 test = count_mbytes(base, 0, &state);
3325 if (test == (size_t) -1) {
3327 } else if (test > want) {
3330 reset_mbytes(state);
3331 trans_mbytes(buf, base, want, &state);
3337 wGet_wstring(stdscr, buf, SLKLEN);
3338 slk_wset((c - '0'), buf, fmt);
3349 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3350 call_slk_color(fg, bg);
3355 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3356 call_slk_color(fg, bg);
3359 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3361 wnoutrefresh(stdscr);
3365 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3366 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3372 if (cycle_colors(c, &fg, &bg, &pair)) {
3374 call_slk_color(fg, bg);
3384 } while (!isQuit(c = Getchar(), TRUE));
3392 #endif /* SLK_INIT */
3395 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3398 unsigned last = 255;
3404 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3409 for (code = first; code <= last; ++code) {
3410 int row = (int) (2 + (code / 16));
3411 int col = (int) (5 * (code % 16));
3412 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3413 for (count = 1; count < repeat; ++count) {
3414 addch(colored_chtype(code, attr, pair));
3421 * Show a slice of 32 characters, allowing those to be repeated up to the
3424 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3425 * terminal to perform functions. The remaining codes can be graphic.
3428 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3431 unsigned first = (unsigned) base;
3432 unsigned last = first + (unsigned) pagesize - 2;
3433 bool C1 = (first == 128);
3438 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3439 C1 ? "C1" : "GR", first, last);
3443 for (code = first; code <= last; code++) {
3445 int row = 2 + ((int) (code - first) % (pagesize / 2));
3446 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3448 sprintf(tmp, "%3u (0x%x)", code, code);
3449 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3453 nodelay(stdscr, TRUE);
3454 echochar(colored_chtype(code, attr, pair));
3456 /* (yes, this _is_ crude) */
3457 while ((reply = Getchar()) != ERR) {
3458 addch(UChar(reply));
3461 nodelay(stdscr, FALSE);
3463 } while (--count > 0);
3470 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3476 MvPrintw(0, 20, "Display of PC Character Codes");
3480 for (code = 0; code < 16; ++code) {
3481 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3483 for (code = 0; code < 256; code++) {
3485 int row = 3 + (int) (code / 16) + (code >= 128);
3486 int col = 8 + (int) (code % 16) * PC_COLS;
3487 if ((code % 16) == 0)
3488 MvPrintw(row, 0, "0x%02x:", code);
3499 * Skip the ones that do not work.
3503 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3506 } while (--count > 0);
3511 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3515 attr |= (attr_t) COLOR_PAIR(pair);
3519 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3524 colored_chtype(ACS_VLINE, attr, pair),
3525 colored_chtype(ACS_VLINE, attr, pair),
3526 colored_chtype(ACS_HLINE, attr, pair),
3527 colored_chtype(ACS_HLINE, attr, pair),
3528 colored_chtype(ACS_ULCORNER, attr, pair),
3529 colored_chtype(ACS_URCORNER, attr, pair),
3530 colored_chtype(ACS_LLCORNER, attr, pair),
3531 colored_chtype(ACS_LRCORNER, attr, pair));
3532 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3533 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3534 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3535 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3536 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3537 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3538 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3544 show_1_acs(int n, int repeat, const char *name, chtype code)
3546 const int height = 16;
3547 int row = 2 + (n % height);
3548 int col = (n / height) * COLS / 2;
3550 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3553 } while (--repeat > 0);
3558 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3559 /* display the ACS character set */
3563 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3567 MvAddStr(0, 20, "Display of the ACS Character Set");
3571 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3572 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3573 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3574 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3576 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3577 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3578 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3579 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3581 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3582 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3585 * HPUX's ACS definitions are broken here. Just give up.
3587 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3588 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3589 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3590 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3591 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3593 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3594 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3595 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3596 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3597 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3598 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3599 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3600 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3601 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3603 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3604 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3605 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3607 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3608 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3609 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3610 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3611 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3612 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3621 char *term = getenv("TERM");
3622 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3625 chtype attr = A_NORMAL;
3628 int fg = COLOR_BLACK;
3629 int bg = COLOR_BLACK;
3630 unsigned at_code = 0;
3631 NCURSES_PAIRS_T pair = 0;
3632 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3633 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3634 unsigned my_size = init_attr_list(my_list, termattrs());
3642 ToggleAcs(last_show_acs, show_acs_chars);
3646 ToggleAcs(last_show_acs, show_pc_chars);
3651 if (pagesize == 32) {
3658 ToggleAcs(last_show_acs, show_box_chars);
3684 if (repeat < (COLS / 4))
3692 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3693 || cycle_colors(c, &fg, &bg, &pair)) {
3700 if (pagesize != 32) {
3701 show_256_chars(repeat, attr, pair);
3702 } else if (last_show_acs != 0) {
3703 last_show_acs(repeat, attr, pair);
3705 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3708 MvPrintw(LINES - 3, 0,
3709 "Note: ANSI terminals may not display C1 characters.");
3710 MvPrintw(LINES - 2, 0,
3711 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3714 MvPrintw(LINES - 1, 0,
3715 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3716 my_list[at_code].name,
3719 MvPrintw(LINES - 1, 0,
3720 "v/V cycles through video attributes (%s).",
3721 my_list[at_code].name);
3724 } while (!isQuit(c = Getchar(), TRUE));
3731 #if USE_WIDEC_SUPPORT
3733 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3739 TEST_CCHAR(src, count, {
3740 attr |= (test_attrs & A_ALTCHARSET);
3741 setcchar(dst, test_wch, attr, pair, NULL);
3751 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3752 * display. If there are no repeats, we could normally display 16 lines of 64
3753 * characters (1024 total). However, taking repeats and double-width cells
3754 * into account, use 256 characters for the page.
3757 show_paged_widechars(int base,
3762 NCURSES_PAIRS_T pair)
3764 int first = base * pagesize;
3765 int last = first + pagesize - 1;
3773 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3776 for (code = (wchar_t) first; (int) code <= last; code++) {
3777 int row = (2 + ((int) code - first) / per_line);
3778 int col = 5 * ((int) code % per_line);
3781 memset(&codes, 0, sizeof(codes));
3783 setcchar(&temp, codes, attr, pair, 0);
3785 if (wcwidth(code) == 0 && code != 0) {
3786 addch((chtype) space |
3787 (A_REVERSE ^ attr) |
3788 (attr_t) COLOR_PAIR(pair));
3791 for (count = 1; count < repeat; ++count) {
3798 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3802 int last = first + 31;
3806 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3809 for (code = (wchar_t) first; (int) code <= last; code++) {
3810 int row = 2 + ((code - first) % 16);
3811 int col = ((code - first) / 16) * COLS / 2;
3817 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3818 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3820 memset(&codes, 0, sizeof(codes));
3822 setcchar(&temp, codes, attr, pair, 0);
3826 * Give non-spacing characters something to combine with. If we
3827 * don't, they'll bunch up in a heap on the space after the ":".
3828 * Mark them with reverse-video to make them simpler to find on
3831 if (wcwidth(code) == 0) {
3832 addch((chtype) space |
3833 (A_REVERSE ^ attr) |
3834 (attr_t) COLOR_PAIR(pair));
3837 * This uses echo_wchar(), for comparison with the normal 'f'
3838 * test (and to make a test-case for echo_wchar()). The screen
3839 * may flicker because the erase() at the top of the function
3840 * is met by the builtin refresh() in echo_wchar().
3844 * The repeat-count may make text wrap - avoid that.
3846 getyx(stdscr, y, x);
3848 if (x >= col + (COLS / 2) - 2)
3850 } while (--count > 0);
3855 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3857 const int height = 16;
3858 int row = 2 + (n % height);
3859 int col = (n / height) * COLS / 2;
3861 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3862 while (--repeat >= 0) {
3868 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3871 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3872 /* display the wide-ACS character set */
3878 /*#define BOTH2(name) #name, &(name) */
3879 #define BOTH2(name) #name, MERGE_ATTR(name)
3883 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3887 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3888 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3889 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3890 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3892 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3893 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3894 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3895 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3897 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3898 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3900 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3901 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3902 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3903 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3905 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3906 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3907 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3908 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3909 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3910 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3911 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3912 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3913 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3915 #ifdef CURSES_WACS_ARRAY
3916 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3917 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3918 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3920 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3921 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3922 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3923 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3924 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3925 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3931 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3932 /* display the wide-ACS character set */
3938 /*#define BOTH2(name) #name, &(name) */
3939 #define BOTH2(name) #name, MERGE_ATTR(name)
3943 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3947 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3948 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3949 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3950 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3952 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3953 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3954 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3955 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3957 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3958 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3960 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3961 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3962 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3963 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3965 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3966 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3967 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3968 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3969 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3970 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3971 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3972 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3973 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3975 #ifdef CURSES_WACS_ARRAY
3976 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3977 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3978 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3980 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3981 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3982 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3983 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3984 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3985 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3992 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3993 /* display the wide-ACS character set */
3999 /*#define BOTH2(name) #name, &(name) */
4000 #define BOTH2(name) #name, MERGE_ATTR(name)
4004 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4008 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
4009 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
4010 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
4011 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
4013 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
4014 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
4015 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
4016 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
4018 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
4019 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
4021 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
4022 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
4023 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
4024 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
4026 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
4027 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
4028 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
4029 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
4030 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
4031 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
4032 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
4033 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
4034 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
4036 #ifdef CURSES_WACS_ARRAY
4037 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
4038 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
4039 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
4041 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
4042 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
4043 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
4044 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
4045 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
4046 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
4053 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
4056 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4063 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
4068 MERGE_ATTR(0, WACS_VLINE),
4069 MERGE_ATTR(1, WACS_VLINE),
4070 MERGE_ATTR(2, WACS_HLINE),
4071 MERGE_ATTR(3, WACS_HLINE),
4072 MERGE_ATTR(4, WACS_ULCORNER),
4073 MERGE_ATTR(5, WACS_URCORNER),
4074 MERGE_ATTR(6, WACS_LLCORNER),
4075 MERGE_ATTR(7, WACS_LRCORNER));
4077 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
4078 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
4079 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
4080 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
4081 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
4082 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
4083 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
4091 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
4093 const int height = 16;
4094 int row = 2 + (n % height);
4095 int col = (n / height) * COLS / 2;
4098 MvPrintw(row, col, "%*s : ", COLS / 4, name);
4099 (void) attr_set(attr, pair, 0);
4100 addstr(strncpy(temp, code, 20));
4101 (void) attr_set(A_NORMAL, 0, 0);
4105 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
4108 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
4115 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
4119 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
4120 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
4121 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
4122 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
4124 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
4125 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
4126 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
4127 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
4129 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
4130 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
4132 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
4133 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
4134 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
4135 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
4137 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
4138 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
4139 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
4140 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
4141 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
4142 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4143 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4144 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4145 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4146 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4147 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4148 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4150 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4151 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4152 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4153 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4154 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4155 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4160 /* display the wide-ACS character set */
4162 wide_acs_display(void)
4169 chtype attr = A_NORMAL;
4170 int fg = COLOR_BLACK;
4171 int bg = COLOR_BLACK;
4172 unsigned at_code = 0;
4173 NCURSES_PAIRS_T pair = 0;
4174 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4175 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
4176 unsigned my_size = init_attr_list(my_list, term_attrs());
4184 ToggleAcs(last_show_wacs, show_wacs_chars);
4188 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4193 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4197 if (pagesize == 32) {
4204 ToggleAcs(last_show_wacs, show_wbox_chars);
4207 ToggleAcs(last_show_wacs, show_utf8_chars);
4210 if (c < 256 && isdigit(c)) {
4213 } else if (c == '+') {
4216 } else if (c == '-' && digit > 0) {
4219 } else if (c == '>' && repeat < (COLS / 4)) {
4221 } else if (c == '<' && repeat > 1) {
4223 } else if (c == '_') {
4224 space = (space == ' ') ? '_' : ' ';
4226 } else if (cycle_attr(c, &at_code, &attr, my_list, my_size)
4227 || cycle_colors(c, &fg, &bg, &pair)) {
4228 if (last_show_wacs != 0)
4236 if (pagesize != 32) {
4237 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4238 } else if (last_show_wacs != 0) {
4239 last_show_wacs(repeat, attr, pair);
4241 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4244 MvPrintw(LINES - 4, 0,
4245 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
4246 MvPrintw(LINES - 3, 2,
4247 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4249 MvPrintw(LINES - 2, 2,
4250 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4251 my_list[at_code].name,
4254 MvPrintw(LINES - 2, 2,
4255 "v/V cycles through video attributes (%s).",
4256 my_list[at_code].name);
4259 } while (!isQuit(c = Getchar(), TRUE));
4269 * Graphic-rendition test (adapted from vttest)
4272 test_sgr_attributes(void)
4276 for (pass = 0; pass < 2; pass++) {
4277 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4279 /* Use non-default colors if possible to exercise bce a little */
4281 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4282 normal |= (chtype) COLOR_PAIR(1);
4286 MvPrintw(1, 20, "Graphic rendition test pattern:");
4288 MvPrintw(4, 1, "vanilla");
4290 #define set_sgr(mask) bkgdset((normal^(mask)));
4292 MvPrintw(4, 40, "bold");
4294 set_sgr(A_UNDERLINE);
4295 MvPrintw(6, 6, "underline");
4297 set_sgr(A_BOLD | A_UNDERLINE);
4298 MvPrintw(6, 45, "bold underline");
4301 MvPrintw(8, 1, "blink");
4303 set_sgr(A_BLINK | A_BOLD);
4304 MvPrintw(8, 40, "bold blink");
4306 set_sgr(A_UNDERLINE | A_BLINK);
4307 MvPrintw(10, 6, "underline blink");
4309 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4310 MvPrintw(10, 45, "bold underline blink");
4313 MvPrintw(12, 1, "negative");
4315 set_sgr(A_BOLD | A_REVERSE);
4316 MvPrintw(12, 40, "bold negative");
4318 set_sgr(A_UNDERLINE | A_REVERSE);
4319 MvPrintw(14, 6, "underline negative");
4321 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4322 MvPrintw(14, 45, "bold underline negative");
4324 set_sgr(A_BLINK | A_REVERSE);
4325 MvPrintw(16, 1, "blink negative");
4327 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4328 MvPrintw(16, 40, "bold blink negative");
4330 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4331 MvPrintw(18, 6, "underline blink negative");
4333 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4334 MvPrintw(18, 45, "bold underline blink negative");
4337 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4343 bkgdset(A_NORMAL | BLANK);
4348 /****************************************************************************
4350 * Windows and scrolling tester.
4352 ****************************************************************************/
4354 #define BOTLINES 4 /* number of line stolen from screen bottom */
4360 #define FRAME struct frame
4369 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
4370 #if (NCURSES_VERSION_PATCH < 20070331)
4371 #define is_keypad(win) (win)->_use_keypad
4372 #define is_scrollok(win) (win)->_scroll
4375 #define is_keypad(win) FALSE
4376 #define is_scrollok(win) FALSE
4380 frame_win(FRAME * curp)
4382 return (curp != 0) ? curp->wind : stdscr;
4385 /* We need to know if these flags are actually set, so don't look in FRAME.
4386 * These names are known to work with SVr4 curses as well as ncurses. The
4387 * _use_keypad name does not work with Solaris 8.
4390 HaveKeypad(FRAME * curp)
4392 WINDOW *win = frame_win(curp);
4394 return is_keypad(win);
4398 HaveScroll(FRAME * curp)
4400 WINDOW *win = frame_win(curp);
4402 return is_scrollok(win);
4406 newwin_legend(FRAME * curp)
4408 #define DATA(num, name) { name, num }
4409 static const struct {
4413 DATA(0, "^C = create window"),
4414 DATA(0, "^N = next window"),
4415 DATA(0, "^P = previous window"),
4416 DATA(0, "^F = scroll forward"),
4417 DATA(0, "^B = scroll backward"),
4418 DATA(1, "^K = keypad(%s)"),
4419 DATA(2, "^S = scrollok(%s)"),
4420 DATA(0, "^W = save window"),
4421 DATA(0, "^R = restore window"),
4423 DATA(0, "^X = resize"),
4425 DATA(3, "^Q%s = exit")
4430 bool do_keypad = HaveKeypad(curp);
4431 bool do_scroll = HaveScroll(curp);
4435 for (n = 0; n < SIZEOF(legend); n++) {
4436 switch (legend[n].code) {
4438 strcpy(buf, legend[n].msg);
4441 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
4444 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
4447 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
4450 x = getcurx(stdscr);
4451 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4458 transient(FRAME * curp, NCURSES_CONST char *msg)
4460 newwin_legend(curp);
4462 MvAddStr(LINES - 1, 0, msg);
4468 printw("%s characters are echoed, window should %sscroll.",
4469 HaveKeypad(curp) ? "Non-arrow" : "All other",
4470 HaveScroll(curp) ? "" : "not ");