1 /****************************************************************************
2 * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
28 /****************************************************************************
31 ncurses.c --- ncurses library exerciser
37 An interactive test module for the ncurses library.
40 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
41 Thomas E. Dickey (beginning revision 1.27 in 1996).
43 $Id: ncurses.c,v 1.487 2017/10/28 00:54:41 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
84 #define NCURSES_CONST_PARAM char
86 #define mmask_t chtype /* not specified in XSI */
89 #ifdef CURSES_ACS_ARRAY
90 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
91 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
92 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
93 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
94 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
95 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
96 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
98 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
99 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
100 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
101 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
102 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
103 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
104 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
109 #ifdef CURSES_WACS_ARRAY
110 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
111 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
112 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
113 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
114 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
115 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
116 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
123 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
124 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
125 #define reset_wchars(state) init_mb(state)
126 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
127 #define count_wchars(src, len, state) wcstombs(0, src, len)
128 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
129 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
134 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
135 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
136 #define reset_mbytes(state) init_mb(state)
137 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
138 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
139 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
140 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
144 #define ToggleAcs(temp,real) temp = ((temp == real) ? NULL : real)
146 #define P(string) printw("%s\n", string)
148 #define BLANK ' ' /* this is the background character */
150 static int MaxColors; /* the actual number of colors we'll use */
151 static int MinColors; /* the minimum color code */
152 static bool UseColors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
157 #if HAVE_COLOR_CONTENT
160 NCURSES_COLOR_T green;
161 NCURSES_COLOR_T blue;
164 static RGB_DATA *all_colors;
167 static void main_menu(bool);
168 static void failed(const char *s) GCC_NORETURN;
171 failed(const char *s)
175 ExitProgram(EXIT_FAILURE);
191 isQuit(int c, bool escape)
193 return ((c) == QUIT || (escape && ((c) == ESCAPE)));
195 #define case_QUIT QUIT: case ESCAPE
197 /* Common function to allow ^T to toggle trace-mode in the middle of a test
198 * so that trace-files can be made smaller.
201 wGetchar(WINDOW *win)
205 while ((c = wgetch(win)) == CTRL('T')) {
207 save_trace = _nc_tracing;
208 Trace(("TOGGLE-TRACING OFF"));
211 _nc_tracing = save_trace;
215 Trace(("TOGGLE-TRACING ON"));
222 #define Getchar() wGetchar(stdscr)
225 /* replaces wgetnstr(), since we want to be able to edit values */
227 wGetstring(WINDOW *win, char *buffer, int limit)
234 (void) wattrset(win, A_REVERSE);
236 x = (int) strlen(buffer);
238 if (x > (int) strlen(buffer))
239 x = (int) strlen(buffer);
241 wprintw(win, "%-*s", limit, buffer);
242 wmove(win, y0, x0 + x);
243 switch (ch = wGetchar(win)) {
256 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
274 if (!isprint(ch) || ch >= KEY_MIN) {
276 } else if ((int) strlen(buffer) < limit) {
278 for (j = (int) strlen(buffer) + 1; j > x; --j) {
279 buffer[j] = buffer[j - 1];
281 buffer[x++] = (char) ch;
288 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
296 fullwidth_digit(int ch)
298 return (wchar_t) (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_digit(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = (wchar_t) ch;
323 make_fullwidth_digit(cchar_t *target, int digit)
327 source[0] = fullwidth_digit(digit + '0');
329 setcchar(target, source, A_NORMAL, 0, 0);
334 wGet_wchar(WINDOW *win, wint_t *result)
338 while ((c = wget_wch(win, result)) == CTRL('T')) {
340 save_trace = _nc_tracing;
341 Trace(("TOGGLE-TRACING OFF"));
344 _nc_tracing = save_trace;
348 Trace(("TOGGLE-TRACING ON"));
351 c = wget_wch(win, result);
355 #define Get_wchar(result) wGet_wchar(stdscr, result)
357 /* replaces wgetn_wstr(), since we want to be able to edit values */
359 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
368 (void) wattrset(win, A_REVERSE);
370 x = (int) wcslen(buffer);
372 if (x > (int) wcslen(buffer))
373 x = (int) wcslen(buffer);
375 /* clear the "window' */
377 wprintw(win, "%*s", limit, " ");
379 /* write the existing buffer contents */
381 waddnwstr(win, buffer, limit);
383 /* positions the cursor past character 'x' */
385 waddnwstr(win, buffer, x);
387 switch (wGet_wchar(win, &ch)) {
427 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
447 } else if ((int) wcslen(buffer) < limit) {
449 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
450 buffer[j] = buffer[j - 1];
452 buffer[x++] = (wchar_t) ch;
459 wattroff(win, A_REVERSE);
470 addstr("Press any key to continue... ");
475 Cannot(const char *what)
477 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
483 ShellOut(bool message)
486 addstr("Shelling out...");
492 IGNORE_RC(system("sh"));
495 addstr("returned from shellout.\n");
499 #ifdef NCURSES_MOUSE_VERSION
501 * This function is the same as _tracemouse(), but we cannot count on that
502 * being available in the non-debug library.
505 mouse_decode(MEVENT const *ep)
507 static char buf[80 + (5 * 10) + (32 * 15)];
509 (void) _nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf))
510 "id %2d at (%2d, %2d, %d) state %4lx = {",
511 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
514 if ((ep->bstate & m)==m) { \
515 _nc_STRCAT(buf, s, sizeof(buf)); \
516 _nc_STRCAT(buf, ", ", sizeof(buf)); \
519 SHOW(BUTTON1_RELEASED, "release-1");
520 SHOW(BUTTON1_PRESSED, "press-1");
521 SHOW(BUTTON1_CLICKED, "click-1");
522 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
523 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
524 #if NCURSES_MOUSE_VERSION == 1
525 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
528 SHOW(BUTTON2_RELEASED, "release-2");
529 SHOW(BUTTON2_PRESSED, "press-2");
530 SHOW(BUTTON2_CLICKED, "click-2");
531 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
532 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
533 #if NCURSES_MOUSE_VERSION == 1
534 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
537 SHOW(BUTTON3_RELEASED, "release-3");
538 SHOW(BUTTON3_PRESSED, "press-3");
539 SHOW(BUTTON3_CLICKED, "click-3");
540 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
541 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
542 #if NCURSES_MOUSE_VERSION == 1
543 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
546 SHOW(BUTTON4_RELEASED, "release-4");
547 SHOW(BUTTON4_PRESSED, "press-4");
548 SHOW(BUTTON4_CLICKED, "click-4");
549 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
550 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
551 #if NCURSES_MOUSE_VERSION == 1
552 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
555 #if NCURSES_MOUSE_VERSION == 2
556 SHOW(BUTTON5_RELEASED, "release-5");
557 SHOW(BUTTON5_PRESSED, "press-5");
558 SHOW(BUTTON5_CLICKED, "click-5");
559 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
560 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
563 SHOW(BUTTON_CTRL, "ctrl");
564 SHOW(BUTTON_SHIFT, "shift");
565 SHOW(BUTTON_ALT, "alt");
566 SHOW(ALL_MOUSE_EVENTS, "all-events");
567 SHOW(REPORT_MOUSE_POSITION, "position");
571 if (buf[strlen(buf) - 1] == ' ')
572 buf[strlen(buf) - 2] = '\0';
573 _nc_STRCAT(buf, "}", sizeof(buf));
578 show_mouse(WINDOW *win)
586 outside = !wenclose(win, event.y, event.x);
589 (void) wstandout(win);
590 waddstr(win, "KEY_MOUSE");
591 (void) wstandend(win);
593 waddstr(win, "KEY_MOUSE");
595 wprintw(win, ", %s", mouse_decode(&event));
600 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
604 wmove(win, event.y, event.x);
612 #endif /* NCURSES_MOUSE_VERSION */
614 /****************************************************************************
616 * Character input test
618 ****************************************************************************/
620 #define NUM_GETCH_FLAGS 256
621 typedef bool GetchFlags[NUM_GETCH_FLAGS];
624 setup_getch(WINDOW *win, GetchFlags flags)
626 keypad(win, flags['k']); /* should be redundant, but for testing */
627 meta(win, flags['m']); /* force this to a known state */
635 init_getch(WINDOW *win, GetchFlags flags, int delay)
637 memset(flags, FALSE, NUM_GETCH_FLAGS);
638 flags[UChar('k')] = (win == stdscr);
639 flags[UChar('m')] = TRUE;
640 flags[UChar('t')] = (delay != 0);
642 setup_getch(win, flags);
646 blocking_getch(GetchFlags flags, int delay)
648 return ((delay < 0) && flags['t']);
651 #define ExitOnEscape() (flags[UChar('k')] && flags[UChar('t')])
654 wgetch_help(WINDOW *win, GetchFlags flags)
656 static const char *help[] =
658 "e -- toggle echo mode"
659 ,"g -- triggers a getstr test"
660 ,"k -- toggle keypad/literal mode"
661 ,"m -- toggle meta (7-bit/8-bit) mode"
664 ,"t -- toggle timeout"
665 ,"w -- create a new window"
667 ,"z -- suspend this process"
671 unsigned chk = ((SIZEOF(help) + 1) / 2);
676 printw("Type any key to see its %s value. Also:\n",
677 flags['k'] ? "keypad" : "literal");
678 for (n = 0; n < SIZEOF(help); ++n) {
679 const char *msg = help[n];
680 int row = 1 + (int) (n % chk);
681 int col = (n >= chk) ? COLS / 2 : 0;
682 int flg = ((strstr(msg, "toggle") != 0)
683 && (flags[UChar(*msg)] != FALSE));
684 if (*msg == '^' && ExitOnEscape())
685 msg = "^[,^q -- quit";
688 MvPrintw(row, col, "%s", msg);
699 wgetch_wrap(WINDOW *win, int first_y)
701 int last_y = getmaxy(win) - 1;
702 int y = getcury(win) + 1;
710 #if defined(KEY_RESIZE) && HAVE_WRESIZE
716 static WINSTACK *winstack = 0;
717 static unsigned len_winstack = 0;
730 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
732 unsigned need = (level + 1) * 2;
734 assert(level < (unsigned) COLS);
738 winstack = typeMalloc(WINSTACK, len_winstack);
739 } else if (need >= len_winstack) {
741 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
744 failed("remember_boxes");
745 winstack[level].text = txt_win;
746 winstack[level].frame = box_win;
749 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
753 /* this chunk is now done in resize_term() */
760 #define slk_repaint() /* nothing */
763 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
765 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
766 * Resize both and paint the box in the parent.
769 resize_boxes(unsigned level, WINDOW *win)
773 int high = LINES - base;
777 wnoutrefresh(stdscr);
781 for (n = 0; n < level; ++n) {
782 wresize(winstack[n].frame, high, wide);
783 wresize(winstack[n].text, high - 2, wide - 2);
786 werase(winstack[n].text);
787 box(winstack[n].frame, 0, 0);
788 wnoutrefresh(winstack[n].frame);
789 wprintw(winstack[n].text,
791 getmaxy(winstack[n].text),
792 getmaxx(winstack[n].text));
793 wnoutrefresh(winstack[n].text);
794 if (winstack[n].text == win)
799 #endif /* resize_boxes */
801 #define forget_boxes() /* nothing */
802 #define remember_boxes(level,text,frame) /* nothing */
806 * Return-code is OK/ERR or a keyname.
811 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
815 wgetch_test(unsigned level, WINDOW *win, int delay)
818 int first_y, first_x;
823 init_getch(win, flags, delay);
824 notimeout(win, FALSE);
825 wtimeout(win, delay);
826 getyx(win, first_y, first_x);
828 wgetch_help(win, flags);
829 wsetscrreg(win, first_y, getmaxy(win) - 1);
833 while ((c = wGetchar(win)) == ERR) {
835 if (blocking_getch(flags, delay)) {
836 (void) wprintw(win, "%05d: input error", incount);
839 (void) wprintw(win, "%05d: input timed out", incount);
841 wgetch_wrap(win, first_y);
843 if (c == ERR && blocking_getch(flags, delay)) {
845 wgetch_wrap(win, first_y);
846 } else if (isQuit(c, ExitOnEscape())) {
848 } else if (c == 'e') {
849 flags[UChar('e')] = !flags[UChar('e')];
850 setup_getch(win, flags);
851 wgetch_help(win, flags);
852 } else if (c == 'g') {
853 waddstr(win, "getstr test: ");
855 c = wgetnstr(win, buf, sizeof(buf) - 1);
857 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
858 (int) strlen(buf), buf,
861 wgetch_wrap(win, first_y);
862 } else if (c == 'k') {
863 flags[UChar('k')] = !flags[UChar('k')];
864 setup_getch(win, flags);
865 wgetch_help(win, flags);
866 } else if (c == 'm') {
867 flags[UChar('m')] = !flags[UChar('m')];
868 setup_getch(win, flags);
869 wgetch_help(win, flags);
870 } else if (c == 's') {
872 } else if (c == 't') {
873 notimeout(win, flags[UChar('t')]);
874 flags[UChar('t')] = !flags[UChar('t')];
875 wgetch_help(win, flags);
876 } else if (c == 'w') {
877 int high = getmaxy(win) - 1 - first_y + 1;
878 int wide = getmaxx(win) - first_x;
880 int new_y = first_y + getbegy(win);
881 int new_x = first_x + getbegx(win);
883 getyx(win, old_y, old_x);
884 if (high > 2 && wide > 2) {
885 WINDOW *wb = newwin(high, wide, new_y, new_x);
886 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
891 remember_boxes(level, wi, wb);
892 wgetch_test(level + 1, wi, delay);
896 wgetch_help(win, flags);
897 wmove(win, old_y, old_x);
903 } else if (c == 'z') {
904 kill(getpid(), SIGTSTP);
907 wprintw(win, "Key pressed: %04o ", c);
908 #ifdef NCURSES_MOUSE_VERSION
909 if (c == KEY_MOUSE) {
912 #endif /* NCURSES_MOUSE_VERSION */
914 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
915 if (c == KEY_RESIZE) {
916 resize_boxes(level, win);
919 (void) waddstr(win, keyname(c));
920 } else if (c >= 0x80) {
921 unsigned c2 = (unsigned) c;
922 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
923 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
927 (void) wprintw(win, "%c", UChar(c));
928 else if (c2 != UChar(c))
929 (void) wprintw(win, "M-%s", unctrl(c2));
931 (void) wprintw(win, "%s", unctrl(c2));
932 waddstr(win, " (high-half character)");
935 (void) wprintw(win, "%c (ASCII printable character)", c);
937 (void) wprintw(win, "%s (ASCII control character)",
940 wgetch_wrap(win, first_y);
947 init_getch(win, flags, delay);
951 begin_getch_test(void)
958 #ifdef NCURSES_MOUSE_VERSION
959 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
962 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
964 getnstr(buf, sizeof(buf) - 1);
968 if (isdigit(UChar(buf[0]))) {
969 delay = atoi(buf) * 100;
979 finish_getch_test(void)
981 #ifdef NCURSES_MOUSE_VERSION
982 mousemask(0, (mmask_t *) 0);
991 getch_test(bool recur GCC_UNUSED)
993 int delay = begin_getch_test();
996 wgetch_test(0, stdscr, delay);
1003 #if USE_WIDEC_SUPPORT
1005 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1006 * Resize both and paint the box in the parent.
1008 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1010 resize_wide_boxes(unsigned level, WINDOW *win)
1014 int high = LINES - base;
1018 wnoutrefresh(stdscr);
1022 for (n = 0; n < level; ++n) {
1023 wresize(winstack[n].frame, high, wide);
1024 wresize(winstack[n].text, high - 2, wide - 2);
1027 werase(winstack[n].text);
1028 box_set(winstack[n].frame, 0, 0);
1029 wnoutrefresh(winstack[n].frame);
1030 wprintw(winstack[n].text,
1032 getmaxy(winstack[n].text),
1033 getmaxx(winstack[n].text));
1034 wnoutrefresh(winstack[n].text);
1035 if (winstack[n].text == win)
1040 #endif /* KEY_RESIZE */
1043 wcstos(const wchar_t *src)
1047 const wchar_t *tmp = src;
1048 #ifndef state_unused
1052 reset_wchars(state);
1053 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1054 unsigned have = (unsigned) need;
1055 if ((result = typeCalloc(char, have + 1)) != 0) {
1057 if (trans_wchars(result, tmp, have, &state) != have) {
1069 wget_wch_test(unsigned level, WINDOW *win, int delay)
1071 wchar_t wchar_buf[BUFSIZ];
1072 wint_t wint_buf[BUFSIZ];
1073 int first_y, first_x;
1080 init_getch(win, flags, delay);
1081 notimeout(win, FALSE);
1082 wtimeout(win, delay);
1083 getyx(win, first_y, first_x);
1085 wgetch_help(win, flags);
1086 wsetscrreg(win, first_y, getmaxy(win) - 1);
1087 scrollok(win, TRUE);
1090 while ((code = wGet_wchar(win, &c)) == ERR) {
1092 if (blocking_getch(flags, delay)) {
1093 (void) wprintw(win, "%05d: input error", incount);
1096 (void) wprintw(win, "%05d: input timed out", incount);
1098 wgetch_wrap(win, first_y);
1100 if (code == ERR && blocking_getch(flags, delay)) {
1101 wprintw(win, "ERR");
1102 wgetch_wrap(win, first_y);
1103 } else if (isQuit((int) c, ExitOnEscape())) {
1105 } else if (c == 'e') {
1106 flags[UChar('e')] = !flags[UChar('e')];
1107 setup_getch(win, flags);
1108 wgetch_help(win, flags);
1109 } else if (c == 'g') {
1110 waddstr(win, "getstr test: ");
1112 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1115 wprintw(win, "wgetn_wstr returns an error.");
1118 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1121 if ((temp = wcstos(wchar_buf)) != 0) {
1122 wprintw(win, "I saw %d characters:\n\t`%s'.",
1123 (int) wcslen(wchar_buf), temp);
1126 wprintw(win, "I saw %d characters (cannot convert).",
1127 (int) wcslen(wchar_buf));
1131 wgetch_wrap(win, first_y);
1132 } else if (c == 'k') {
1133 flags[UChar('k')] = !flags[UChar('k')];
1134 setup_getch(win, flags);
1135 wgetch_help(win, flags);
1136 } else if (c == 'm') {
1137 flags[UChar('m')] = !flags[UChar('m')];
1138 setup_getch(win, flags);
1139 wgetch_help(win, flags);
1140 } else if (c == 's') {
1142 } else if (c == 't') {
1143 notimeout(win, flags[UChar('t')]);
1144 flags[UChar('t')] = !flags[UChar('t')];
1145 wgetch_help(win, flags);
1146 } else if (c == 'w') {
1147 int high = getmaxy(win) - 1 - first_y + 1;
1148 int wide = getmaxx(win) - first_x;
1150 int new_y = first_y + getbegy(win);
1151 int new_x = first_x + getbegx(win);
1153 getyx(win, old_y, old_x);
1154 if (high > 2 && wide > 2) {
1155 WINDOW *wb = newwin(high, wide, new_y, new_x);
1156 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1161 remember_boxes(level, wi, wb);
1162 wget_wch_test(level + 1, wi, delay);
1166 wgetch_help(win, flags);
1167 wmove(win, old_y, old_x);
1172 } else if (c == 'z') {
1173 kill(getpid(), SIGTSTP);
1176 wprintw(win, "Key pressed: %04o ", (int) c);
1177 #ifdef NCURSES_MOUSE_VERSION
1178 if (c == KEY_MOUSE) {
1181 #endif /* NCURSES_MOUSE_VERSION */
1182 if (code == KEY_CODE_YES) {
1183 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1184 if (c == KEY_RESIZE) {
1185 resize_wide_boxes(level, win);
1188 (void) waddstr(win, keyname((wchar_t) c));
1190 (void) waddstr(win, key_name((wchar_t) c));
1191 if (c < 256 && iscntrl(c)) {
1192 (void) wprintw(win, " (control character)");
1194 (void) wprintw(win, " = %#x (printable character)",
1198 wgetch_wrap(win, first_y);
1205 init_getch(win, flags, delay);
1209 x_getch_test(bool recur GCC_UNUSED)
1211 int delay = begin_getch_test();
1214 wget_wch_test(0, stdscr, delay);
1216 finish_getch_test();
1222 /****************************************************************************
1224 * Character attributes test
1226 ****************************************************************************/
1228 #if HAVE_SETUPTERM || HAVE_TGETENT
1229 #define get_ncv() TIGETNUM("ncv","NC")
1230 #define get_xmc() TIGETNUM("xmc","sg")
1232 #define get_ncv() -1
1233 #define get_xmc() -1
1240 static int first = TRUE;
1241 static chtype result = 0;
1247 char *area_pointer = parsed;
1249 tgetent(buffer, getenv("TERM"));
1252 if (TIGETSTR("smso", "so"))
1253 result |= A_STANDOUT;
1254 if (TIGETSTR("smul", "us"))
1255 result |= A_UNDERLINE;
1256 if (TIGETSTR("rev", "mr"))
1257 result |= A_REVERSE;
1258 if (TIGETSTR("blink", "mb"))
1260 if (TIGETSTR("dim", "mh"))
1262 if (TIGETSTR("bold", "md"))
1264 if (TIGETSTR("smacs", "ac"))
1265 result |= A_ALTCHARSET;
1271 #define termattrs() my_termattrs()
1274 #define ATTRSTRING_1ST 32 /* ' ' */
1275 #define ATTRSTRING_END 126 /* '~' */
1277 #define COLS_PRE_ATTRS 5
1278 #define COLS_AFT_ATTRS 15
1279 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1280 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1281 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1283 static char attr_test_string[MAX_ATTRSTRING + 1];
1286 attr_legend(WINDOW *helpwin)
1291 MvWPrintw(helpwin, row++, col,
1293 MvWPrintw(helpwin, row++, col,
1296 MvWPrintw(helpwin, row++, col,
1297 "Modify the test strings:");
1298 MvWPrintw(helpwin, row++, col,
1299 " A digit sets gaps on each side of displayed attributes");
1300 MvWPrintw(helpwin, row++, col,
1301 " </> shifts the text left/right. ");
1303 MvWPrintw(helpwin, row++, col,
1306 MvWPrintw(helpwin, row++, col,
1307 " f/F/b/B toggle foreground/background background color");
1308 MvWPrintw(helpwin, row++, col,
1309 " t/T toggle text/background color attribute");
1311 MvWPrintw(helpwin, row++, col,
1312 " a/A toggle ACS (alternate character set) mapping");
1313 MvWPrintw(helpwin, row, col,
1314 " v/V toggle video attribute to combine with each line");
1315 #if USE_WIDEC_SUPPORT
1316 MvWPrintw(helpwin, row, col,
1317 " w/W toggle normal/wide (double-width) test-characters");
1322 show_color_attr(int fg, int bg, int tx)
1325 printw(" Colors (fg %d, bg %d", fg, bg);
1327 printw(", text %d", tx);
1333 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1340 *fg = (NCURSES_COLOR_T) (*fg + 1);
1343 *fg = (NCURSES_COLOR_T) (*fg - 1);
1346 *bg = (NCURSES_COLOR_T) (*bg + 1);
1349 *bg = (NCURSES_COLOR_T) (*bg - 1);
1352 *tx = (NCURSES_COLOR_T) (*tx + 1);
1355 *tx = (NCURSES_COLOR_T) (*tx - 1);
1363 *fg = (NCURSES_COLOR_T) MinColors;
1364 if (*fg < MinColors)
1365 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1367 *bg = (NCURSES_COLOR_T) MinColors;
1368 if (*bg < MinColors)
1369 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1373 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1382 adjust_attr_string(int adjust)
1384 char save = attr_test_string[0];
1385 int first = ((int) UChar(save)) + adjust;
1388 if (first >= ATTRSTRING_1ST) {
1389 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1390 if (k > ATTRSTRING_END)
1392 attr_test_string[j] = (char) k;
1393 if (((k + 1 - first) % 5) == 0) {
1394 if (++j >= MAX_ATTRSTRING)
1396 attr_test_string[j] = ' ';
1399 if ((LEN_ATTRSTRING - j) > 5) {
1400 attr_test_string[0] = save;
1401 adjust_attr_string(adjust - 1);
1403 while (j < MAX_ATTRSTRING)
1404 attr_test_string[j++] = ' ';
1405 attr_test_string[j] = '\0';
1411 * Prefer the right-end of the string for starting, since that maps to the
1412 * VT100 line-drawing.
1415 default_attr_string(void)
1417 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1418 result += (LEN_ATTRSTRING / 5);
1419 if (result < ATTRSTRING_1ST)
1420 result = ATTRSTRING_1ST;
1425 init_attr_string(void)
1427 attr_test_string[0] = (char) default_attr_string();
1428 adjust_attr_string(0);
1432 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1434 int ncv = get_ncv();
1435 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1438 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1439 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1440 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1442 printw("%*s", skip, " ");
1444 * Just for testing, write text using the alternate character set one
1445 * character at a time (to pass its rendition directly), and use the
1446 * string operation for the other attributes.
1450 if (attr & A_ALTCHARSET) {
1454 for (s = attr_test_string; *s != '\0'; ++s) {
1456 (void) waddch(win, ch | attr);
1459 (void) wattrset(win, AttrArg(attr, 0));
1460 (void) waddstr(win, attr_test_string);
1461 (void) wattroff(win, (int) attr);
1464 printw("%*s", skip, " ");
1465 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1466 if (test != A_NORMAL) {
1467 if (!(termattrs() & test)) {
1470 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1471 static const chtype table[] =
1490 for (n = 0; n < SIZEOF(table); n++) {
1491 if ((table[n] & attr) != 0
1492 && ((1 << n) & ncv) != 0) {
1500 if ((termattrs() & test) != test) {
1510 NCURSES_CONST char *name;
1513 static const ATTR_TBL attrs_to_test[] = {
1514 { A_STANDOUT, "STANDOUT" },
1515 { A_REVERSE, "REVERSE" },
1517 { A_UNDERLINE, "UNDERLINE" },
1519 { A_BLINK, "BLINK" },
1520 { A_PROTECT, "PROTECT" },
1522 { A_INVIS, "INVISIBLE" },
1525 { A_ITALIC, "ITALIC" },
1527 { A_NORMAL, "NORMAL" },
1532 init_attr_list(ATTR_TBL * target, attr_t attrs)
1534 unsigned result = 0;
1537 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1538 attr_t test = attrs_to_test[n].attr;
1539 if (test == A_NORMAL || (test & attrs) != 0) {
1540 target[result++] = attrs_to_test[n];
1546 #if USE_WIDEC_SUPPORT
1549 NCURSES_CONST char *name;
1552 static const W_ATTR_TBL w_attrs_to_test[] = {
1553 { WA_STANDOUT, "STANDOUT" },
1554 { WA_REVERSE, "REVERSE" },
1555 { WA_BOLD, "BOLD" },
1556 { WA_UNDERLINE, "UNDERLINE" },
1558 { WA_BLINK, "BLINK" },
1559 { WA_PROTECT, "PROTECT" },
1561 { WA_INVIS, "INVISIBLE" },
1564 { WA_ITALIC, "ITALIC" },
1566 { WA_NORMAL, "NORMAL" },
1571 init_w_attr_list(W_ATTR_TBL * target, attr_t attrs)
1573 unsigned result = 0;
1576 for (n = 0; n < SIZEOF(w_attrs_to_test); ++n) {
1577 attr_t test = w_attrs_to_test[n].attr;
1578 if (test == WA_NORMAL || (test & attrs) != 0) {
1579 target[result++] = w_attrs_to_test[n];
1587 attr_getc(int *skip,
1588 NCURSES_COLOR_T *fg,
1589 NCURSES_COLOR_T *bg,
1590 NCURSES_COLOR_T *tx,
1603 if (ch < 256 && isdigit(ch)) {
1611 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1613 attr_legend(helpwin);
1636 adjust_attr_string(-1);
1639 adjust_attr_string(1);
1645 error = cycle_color_attr(ch, fg, bg, tx);
1654 attr_test(bool recur GCC_UNUSED)
1655 /* test text attributes */
1658 int skip = get_xmc();
1659 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1660 NCURSES_COLOR_T bg = COLOR_BLACK;
1661 NCURSES_COLOR_T tx = -1;
1664 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1665 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1666 unsigned my_size = init_attr_list(my_list, termattrs());
1669 for (j = 0; j < my_size; ++j) {
1670 my_wins[j] = subwin(stdscr,
1672 2 + (int) (2 * j), COL_ATTRSTRING);
1673 scrollok(my_wins[j], FALSE);
1679 n = skip; /* make it easy */
1685 chtype normal = A_NORMAL | BLANK;
1686 chtype extras = (chtype) ac;
1689 NCURSES_PAIRS_T pair = 0;
1690 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1692 if (init_pair(pair, fg, bg) == ERR) {
1695 normal |= (chtype) COLOR_PAIR(pair);
1700 if (init_pair(pair, tx, bg) == ERR) {
1703 extras |= (chtype) COLOR_PAIR(pair);
1713 MvAddStr(0, 20, "Character attribute test display");
1715 for (j = 0; j < my_size; ++j) {
1716 bool arrow = (j == k);
1717 row = show_attr(my_wins[j], row, n, arrow,
1725 MvPrintw(row, COLS_PRE_ATTRS,
1726 "This terminal does %shave the magic-cookie glitch",
1727 get_xmc() > -1 ? "" : "not ");
1728 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1729 show_color_attr(fg, bg, tx);
1730 printw(" ACS (%d)", ac != 0);
1733 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1735 bkgdset(A_NORMAL | BLANK);
1740 Cannot("does not support video attributes.");
1745 #if USE_WIDEC_SUPPORT
1746 static bool use_fullwidth;
1747 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1749 #define FULL_LO 0xff00
1750 #define FULL_HI 0xff5e
1751 #define HALF_LO 0x20
1753 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1754 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1755 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1758 * Returns an ASCII code in [32..126]
1761 normal_wchar(int ch)
1763 wchar_t result = (wchar_t) ch;
1764 if (isFullWidth(ch))
1765 result = ToNormalWidth(ch);
1770 * Returns either an ASCII code in in [32..126] or full-width in
1771 * [0xff00..0xff5e], according to use_fullwidth setting.
1774 target_wchar(int ch)
1776 wchar_t result = (wchar_t) ch;
1777 if (use_fullwidth) {
1778 if (!isFullWidth(ch))
1779 result = ToFullWidth(ch);
1781 if (isFullWidth(ch))
1782 result = ToNormalWidth(ch);
1788 wide_adjust_attr_string(int adjust)
1790 wchar_t save = wide_attr_test_string[0];
1791 int first = ((int) normal_wchar(save)) + adjust;
1794 if (first >= ATTRSTRING_1ST) {
1795 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1796 if (k > ATTRSTRING_END)
1798 wide_attr_test_string[j] = target_wchar(k);
1799 if (((k + 1 - first) % 5) == 0) {
1800 if (++j >= MAX_ATTRSTRING)
1802 wide_attr_test_string[j] = ' ';
1805 if ((LEN_ATTRSTRING - j) > 5) {
1806 wide_attr_test_string[0] = save;
1807 wide_adjust_attr_string(adjust - 1);
1809 while (j < MAX_ATTRSTRING)
1810 wide_attr_test_string[j++] = ' ';
1811 wide_attr_test_string[j] = '\0';
1817 wide_init_attr_string(void)
1819 use_fullwidth = FALSE;
1820 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1821 wide_adjust_attr_string(0);
1825 set_wide_background(NCURSES_PAIRS_T pair)
1832 setcchar(&normal, blank, A_NORMAL, pair, 0);
1838 get_wide_background(void)
1840 attr_t result = WA_NORMAL;
1843 NCURSES_PAIRS_T pair;
1844 wchar_t wch[CCHARW_MAX];
1846 memset(&ch, 0, sizeof(ch));
1847 if (getbkgrnd(&ch) != ERR) {
1848 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1856 wide_show_attr(WINDOW *win,
1861 NCURSES_PAIRS_T pair,
1864 int ncv = get_ncv();
1865 attr_t test = attr & ~WA_ALTCHARSET;
1868 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1869 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1870 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1872 printw("%*s", skip, " ");
1875 * Just for testing, write text using the alternate character set one
1876 * character at a time (to pass its rendition directly), and use the
1877 * string operation for the other attributes.
1881 if (attr & WA_ALTCHARSET) {
1885 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1889 setcchar(&ch, fill, attr, pair, 0);
1890 (void) wadd_wch(win, &ch);
1893 attr_t old_attr = 0;
1894 NCURSES_PAIRS_T old_pair = 0;
1896 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1897 (void) wattr_set(win, attr, pair, 0);
1898 (void) waddwstr(win, wide_attr_test_string);
1899 (void) wattr_set(win, old_attr, old_pair, 0);
1902 printw("%*s", skip, " ");
1903 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1904 if (test != A_NORMAL) {
1905 if (!(term_attrs() & test)) {
1908 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1909 static const attr_t table[] =
1923 for (n = 0; n < SIZEOF(table); n++) {
1924 if ((table[n] & attr) != 0
1925 && ((1 << n) & ncv) != 0) {
1933 if ((term_attrs() & test) != test) {
1942 wide_attr_getc(int *skip,
1943 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1944 NCURSES_COLOR_T *tx, int *ac,
1945 unsigned *kc, unsigned limit)
1955 if (ch < 256 && isdigit(ch)) {
1963 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1964 box_set(helpwin, 0, 0);
1965 attr_legend(helpwin);
1988 use_fullwidth = FALSE;
1989 wide_adjust_attr_string(0);
1992 use_fullwidth = TRUE;
1993 wide_adjust_attr_string(0);
1996 wide_adjust_attr_string(-1);
1999 wide_adjust_attr_string(1);
2005 error = cycle_color_attr(ch, fg, bg, tx);
2014 x_attr_test(bool recur GCC_UNUSED)
2015 /* test text attributes using wide-character calls */
2018 int skip = get_xmc();
2019 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
2020 NCURSES_COLOR_T bg = COLOR_BLACK;
2021 NCURSES_COLOR_T tx = -1;
2024 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
2025 WINDOW *my_wins[SIZEOF(w_attrs_to_test)];
2026 unsigned my_size = init_w_attr_list(my_list, term_attrs());
2029 for (j = 0; j < my_size; ++j) {
2030 my_wins[j] = subwin(stdscr,
2032 2 + (int) (2 * j), COL_ATTRSTRING);
2033 scrollok(my_wins[j], FALSE);
2039 n = skip; /* make it easy */
2041 wide_init_attr_string();
2045 NCURSES_PAIRS_T pair = 0;
2046 NCURSES_PAIRS_T extras = 0;
2049 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2052 if (init_pair(pair, fg, bg) == ERR) {
2059 if (init_pair(extras, tx, bg) == ERR) {
2064 set_wide_background(pair);
2067 box_set(stdscr, 0, 0);
2068 MvAddStr(0, 20, "Character attribute test display");
2070 for (j = 0; j < my_size; ++j) {
2071 row = wide_show_attr(my_wins[j], row, n, (j == k),
2079 MvPrintw(row, COLS_PRE_ATTRS,
2080 "This terminal does %shave the magic-cookie glitch",
2081 get_xmc() > -1 ? "" : "not ");
2082 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2083 show_color_attr(fg, bg, tx);
2084 printw(" ACS (%d)", ac != 0);
2087 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2089 set_wide_background(0);
2094 Cannot("does not support extended video attributes.");
2100 /****************************************************************************
2102 * Color support tests
2104 ****************************************************************************/
2106 static NCURSES_CONST char *the_color_names[] =
2127 show_color_name(int y, int x, int color, bool wide)
2129 if (move(y, x) != ERR) {
2134 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2137 } else if (color >= 8) {
2138 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2140 } else if (color < 0) {
2141 _nc_STRCPY(temp, "default", sizeof(temp));
2143 _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
2144 "%.*s", 16, the_color_names[color]);
2146 printw("%-*.*s", width, width, temp);
2151 color_legend(WINDOW *helpwin, bool wide)
2156 MvWPrintw(helpwin, row++, col,
2159 MvWPrintw(helpwin, row++, col,
2160 "Use up/down arrow to scroll through the display if it is");
2161 MvWPrintw(helpwin, row++, col,
2162 "longer than one screen. Control/N and Control/P can be used");
2163 MvWPrintw(helpwin, row++, col,
2164 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2165 MvWPrintw(helpwin, row++, col,
2166 "full screen; control/B and control/F can be used here.");
2168 MvWPrintw(helpwin, row++, col,
2170 MvWPrintw(helpwin, row++, col,
2171 " a/A toggle altcharset off/on");
2172 MvWPrintw(helpwin, row++, col,
2173 " b/B toggle bold off/on");
2175 MvWPrintw(helpwin, row++, col,
2176 " c/C cycle used-colors through 8,16,...,COLORS");
2178 MvWPrintw(helpwin, row++, col,
2179 " n/N toggle text/number on/off");
2180 MvWPrintw(helpwin, row++, col,
2181 " r/R toggle reverse on/off");
2182 MvWPrintw(helpwin, row++, col,
2183 " w/W toggle width between 8/16 colors");
2184 #if USE_WIDEC_SUPPORT
2186 MvWPrintw(helpwin, row++, col,
2187 "Wide characters:");
2188 MvWPrintw(helpwin, row, col,
2189 " x/X toggle text between ASCII and wide-character");
2196 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2199 color_cycle(int current, int step)
2201 int result = current;
2207 if ((result * 2) > COLORS) {
2210 while ((result * 2) < current) {
2216 if (current >= COLORS) {
2221 if (result > COLORS)
2227 /* generate a color test pattern */
2229 color_test(bool recur GCC_UNUSED)
2234 int grid_top = top + 3;
2235 int page_size = (LINES - grid_top);
2237 int colors_max = COLORS;
2244 bool opt_acsc = FALSE;
2245 bool opt_bold = FALSE;
2246 bool opt_revs = FALSE;
2247 bool opt_nums = FALSE;
2248 bool opt_wide = FALSE;
2252 Cannot("does not support color.");
2256 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2257 done = ((COLS < 16) || (numbered == 0));
2260 * Because the number of colors is usually a power of two, we also use
2261 * a power of two for the number of colors shown per line (to be tidy).
2263 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2267 double colors_max2 = (double) colors_max * (double) colors_max;
2269 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2270 if (colors_max2 <= COLOR_PAIRS) {
2271 int limit = (colors_max - MinColors) * (colors_max - MinColors);
2272 if (pairs_max > limit)
2275 if (pairs_max < COLOR_PAIRS)
2276 pairs_max = COLOR_PAIRS;
2278 /* this assumes an 80-column line */
2282 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2286 per_row = (col_limit / 8);
2288 per_row -= MinColors;
2290 row_limit = (pairs_max + per_row - 1) / per_row;
2293 (void) printw("There are %d color pairs and %d colors",
2295 if (colors_max != COLORS)
2296 (void) printw(" (using %d colors)", colors_max);
2298 (void) addstr(" besides 'default'");
2301 MvPrintw(top + 1, 0,
2302 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2305 opt_bold ? "on" : "off");
2307 /* show color names/numbers across the top */
2308 for (i = 0; i < per_row; i++)
2309 show_color_name(top + 2, (i + 1) * width, i + MinColors, opt_wide);
2311 /* show a grid of colors, with color names/ numbers on the left */
2312 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2313 int row = grid_top + (i / per_row) - base_row;
2314 int col = (i % per_row + 1) * width;
2315 NCURSES_PAIRS_T pair = i;
2317 if ((i / per_row) > row_limit)
2320 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - MinColors)) + MinColors)
2321 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - MinColors)) + MinColors)
2322 if (row >= 0 && move(row, col) != ERR) {
2323 NCURSES_COLOR_T fg = InxToFG(i);
2324 NCURSES_COLOR_T bg = InxToBG(i);
2326 init_pair(pair, fg, bg);
2327 attron(COLOR_PAIR(pair));
2329 attron(A_ALTCHARSET);
2336 _nc_SPRINTF(numbered, _nc_SLIMIT((size_t) (COLS + 1))
2340 printw("%-*.*s", width, width, hello);
2341 (void) attrset(A_NORMAL);
2343 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2344 show_color_name(row, 0, InxToBG(i), opt_wide);
2352 switch (wGetchar(stdscr)) {
2366 colors_max = color_cycle(colors_max, -1);
2369 colors_max = color_cycle(colors_max, 1);
2387 set_color_test(opt_wide, FALSE);
2390 set_color_test(opt_wide, TRUE);
2394 if (base_row <= 0) {
2402 if (base_row + page_size >= row_limit) {
2411 if (base_row <= 0) {
2414 base_row -= (page_size - 1);
2422 if (base_row + page_size >= row_limit) {
2425 base_row += page_size - 1;
2426 if (base_row + page_size >= row_limit) {
2427 base_row = row_limit - page_size - 1;
2432 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2434 color_legend(helpwin, FALSE);
2452 #if USE_WIDEC_SUPPORT
2453 /* generate a color test pattern */
2455 x_color_test(bool recur GCC_UNUSED)
2460 int grid_top = top + 3;
2461 int page_size = (LINES - grid_top);
2462 int pairs_max = (unsigned short) (-1);
2463 int colors_max = COLORS;
2470 bool opt_acsc = FALSE;
2471 bool opt_bold = FALSE;
2472 bool opt_revs = FALSE;
2473 bool opt_wide = FALSE;
2474 bool opt_nums = FALSE;
2475 bool opt_xchr = FALSE;
2476 wchar_t *buffer = 0;
2480 Cannot("does not support color.");
2483 numbered = (char *) calloc((size_t) (COLS + 1), sizeof(char));
2484 buffer = (wchar_t *) calloc((size_t) (COLS + 1), sizeof(wchar_t));
2485 done = ((COLS < 16) || (numbered == 0) || (buffer == 0));
2488 * Because the number of colors is usually a power of two, we also use
2489 * a power of two for the number of colors shown per line (to be tidy).
2491 for (col_limit = 1; col_limit * 2 < COLS; col_limit *= 2) ;
2495 double colors_max2 = (double) colors_max * (double) colors_max;
2497 pairs_max = ((unsigned) (-1)) / 2;
2498 if (colors_max2 <= COLOR_PAIRS) {
2499 int limit = (colors_max - MinColors) * (colors_max - MinColors);
2500 if (pairs_max > limit)
2503 if (pairs_max > COLOR_PAIRS)
2504 pairs_max = COLOR_PAIRS;
2509 per_row = (col_limit / ((colors_max > 8) ? 4 : 8));
2513 per_row = (col_limit / 8);
2515 per_row -= MinColors;
2518 make_fullwidth_text(buffer, hello);
2522 make_narrow_text(buffer, hello);
2525 row_limit = (pairs_max + per_row - 1) / per_row;
2528 (void) printw("There are %d color pairs and %d colors",
2530 if (colors_max != COLORS)
2531 (void) printw(" (using %d colors)", colors_max);
2533 (void) addstr(" besides 'default'");
2536 MvPrintw(top + 1, 0,
2537 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2540 opt_bold ? "on" : "off");
2542 /* show color names/numbers across the top */
2543 for (i = 0; i < per_row; i++)
2544 show_color_name(top + 2, (i + 1) * width, i + MinColors, opt_wide);
2546 /* show a grid of colors, with color names/ numbers on the left */
2547 for (i = (base_row * per_row); i < pairs_max; i++) {
2548 int row = grid_top + (i / per_row) - base_row;
2549 int col = (i % per_row + 1) * width;
2550 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2552 if ((i / per_row) > row_limit)
2555 if (row >= 0 && move(row, col) != ERR) {
2556 init_pair(pair, InxToFG(i), InxToBG(i));
2557 (void) color_set(pair, NULL);
2559 attr_on(WA_ALTCHARSET, NULL);
2561 attr_on(WA_BOLD, NULL);
2563 attr_on(WA_REVERSE, NULL);
2566 _nc_SPRINTF(numbered,
2567 _nc_SLIMIT((size_t) (COLS + 1) * sizeof(wchar_t))
2570 make_fullwidth_text(buffer, numbered);
2572 make_narrow_text(buffer, numbered);
2575 addnwstr(buffer, width);
2576 (void) attr_set(A_NORMAL, 0, NULL);
2578 if ((i % per_row) == 0 && InxToFG(i) == MinColors) {
2579 show_color_name(row, 0, InxToBG(i), opt_wide);
2587 switch (wGetchar(stdscr)) {
2601 colors_max = color_cycle(colors_max, -1);
2604 colors_max = color_cycle(colors_max, 1);
2622 set_color_test(opt_wide, FALSE);
2625 set_color_test(opt_wide, TRUE);
2635 if (base_row <= 0) {
2643 if (base_row + page_size >= row_limit) {
2652 if (base_row <= 0) {
2655 base_row -= (page_size - 1);
2663 if (base_row + page_size >= row_limit) {
2666 base_row += page_size - 1;
2667 if (base_row + page_size >= row_limit) {
2668 base_row = row_limit - page_size - 1;
2673 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2675 color_legend(helpwin, TRUE);
2693 #endif /* USE_WIDEC_SUPPORT */
2695 #if HAVE_COLOR_CONTENT
2697 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2699 NCURSES_COLOR_T red, green, blue;
2701 color_content(current, &red, &green, &blue);
2705 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2708 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2711 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2715 if (init_color(current, red, green, blue) == ERR)
2720 reset_all_colors(void)
2724 for (c = 0; c < COLORS; ++c)
2727 all_colors[c].green,
2728 all_colors[c].blue);
2731 #define okCOLOR(n) ((n) >= 0 && (n) < MaxColors)
2732 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
2733 #define DecodeRGB(n) (NCURSES_COLOR_T) ((n * 1000) / 0xffff)
2736 init_all_colors(bool xterm_colors, char *palette_file)
2739 all_colors = typeMalloc(RGB_DATA, (unsigned) MaxColors);
2741 failed("all_colors");
2742 for (cp = 0; cp < MaxColors; ++cp) {
2744 &all_colors[cp].red,
2745 &all_colors[cp].green,
2746 &all_colors[cp].blue);
2748 /* xterm and compatible terminals can read results of an OSC string
2749 * asking for the current color palette.
2754 char result[BUFSIZ];
2756 unsigned check_r, check_g, check_b;
2760 for (n = 0; n < MaxColors; ++n) {
2761 fprintf(stderr, "\033]4;%d;?\007", n);
2762 got = (int) read(0, result, sizeof(result) - 1);
2766 if (sscanf(result, "\033]4;%d;rgb:%x/%x/%x\007",
2772 all_colors[n].red = DecodeRGB(check_r);
2773 all_colors[n].green = DecodeRGB(check_g);
2774 all_colors[n].blue = DecodeRGB(check_b);
2781 if (palette_file != 0) {
2782 FILE *fp = fopen(palette_file, "r");
2784 char buffer[BUFSIZ];
2785 int red, green, blue;
2788 while (fgets(buffer, sizeof(buffer), fp) != 0) {
2789 if (sscanf(buffer, "scale:%d", &c) == 1) {
2791 } else if (sscanf(buffer, "%d:%d %d %d",
2800 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
2801 all_colors[c].red = Scaled(red);
2802 all_colors[c].green = Scaled(green);
2803 all_colors[c].blue = Scaled(blue);
2811 #define scaled_rgb(n) ((255 * (n)) / 1000)
2814 color_edit(bool recur GCC_UNUSED)
2815 /* display the color test pattern, without trying to edit colors */
2819 int this_c, value, field;
2825 Cannot("does not support color.");
2827 } else if (!can_change_color()) {
2828 Cannot("has hardwired color values.");
2841 page_size = (LINES - 6);
2844 for (i = 0; i < MaxColors; i++)
2845 init_pair((NCURSES_PAIRS_T) i,
2846 (NCURSES_COLOR_T) COLOR_WHITE,
2847 (NCURSES_COLOR_T) i);
2849 MvPrintw(LINES - 2, 0, "Number: %d", value);
2852 NCURSES_COLOR_T red, green, blue;
2855 MvAddStr(0, 20, "Color RGB Value Editing");
2858 for (i = (NCURSES_COLOR_T) top_color;
2859 (i - top_color < page_size)
2860 && (i < MaxColors); i++) {
2863 _nc_SPRINTF(numeric, _nc_SLIMIT(sizeof(numeric)) "[%d]", i);
2864 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2865 (i == current ? '>' : ' '),
2866 (i < (int) SIZEOF(the_color_names)
2867 ? the_color_names[i] : numeric));
2868 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2870 (void) attrset(A_NORMAL);
2872 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2874 if (current == i && field == 0)
2876 printw("%04d", (int) red);
2877 if (current == i && field == 0)
2878 (void) attrset(A_NORMAL);
2880 if (current == i && field == 1)
2882 printw("%04d", (int) green);
2883 if (current == i && field == 1)
2884 (void) attrset(A_NORMAL);
2886 if (current == i && field == 2)
2888 printw("%04d", (int) blue);
2889 if (current == i && field == 2)
2890 (void) attrset(A_NORMAL);
2891 (void) attrset(A_NORMAL);
2892 printw(" ( %3d %3d %3d )",
2893 (int) scaled_rgb(red),
2894 (int) scaled_rgb(green),
2895 (int) scaled_rgb(blue));
2898 MvAddStr(LINES - 3, 0,
2899 "Use up/down to select a color, left/right to change fields.");
2900 MvAddStr(LINES - 2, 0,
2901 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2903 move(2 + current - top_color, 0);
2907 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2929 current -= (page_size - 1);
2936 if (current < (MaxColors - 1))
2937 current += (page_size - 1);
2944 current = (current == 0 ? (MaxColors - 1) : current - 1);
2949 current = (current == (MaxColors - 1) ? 0 : current + 1);
2954 field = (field == 2 ? 0 : field + 1);
2959 field = (field == 0 ? 2 : field - 1);
2972 value = value * 10 + (this_c - '0');
2976 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2980 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2984 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2989 P(" RGB Value Editing Help");
2991 P("You are in the RGB value editor. Use the arrow keys to select one of");
2992 P("the fields in one of the RGB triples of the current colors; the one");
2993 P("currently selected will be reverse-video highlighted.");
2995 P("To change a field, enter the digits of the new value; they are echoed");
2996 P("as entered. Finish by typing `='. The change will take effect instantly.");
2997 P("To increment or decrement a value, use the same procedure, but finish");
2998 P("with a `+' or `-'.");
3000 P("Use `!' to shell-out, ^R or ^L to repaint the screen.");
3002 P("Press 'm' to invoke the top-level menu with the current color settings.");
3003 P("To quit, do ESC");
3012 for (i = 0; i < MaxColors; i++)
3013 init_pair((NCURSES_PAIRS_T) i,
3014 (NCURSES_COLOR_T) COLOR_WHITE,
3015 (NCURSES_COLOR_T) i);
3029 if (current >= MaxColors)
3030 current = MaxColors - 1;
3031 if (current < top_color)
3032 top_color = current;
3033 if (current - top_color >= page_size)
3034 top_color = current - (page_size - 1);
3036 MvPrintw(LINES - 1, 0, "Number: %d", value);
3039 (!isQuit(this_c, TRUE));
3044 * ncurses does not reset each color individually when calling endwin().
3051 #endif /* HAVE_COLOR_CONTENT */
3053 /****************************************************************************
3055 * Alternate character-set stuff
3057 ****************************************************************************/
3059 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
3065 if ((*at_code += 1) >= limit)
3070 *at_code = limit - 1;
3079 *attr = list[*at_code].attr;
3083 #if USE_WIDEC_SUPPORT
3085 cycle_w_attr(int ch, unsigned *at_code, attr_t *attr, W_ATTR_TBL * list, unsigned limit)
3091 if ((*at_code += 1) >= limit)
3096 *at_code = limit - 1;
3105 *attr = list[*at_code].attr;
3111 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
3113 bool result = FALSE;
3123 if ((*fg += 1) >= COLORS)
3131 if ((*bg += 1) >= COLORS)
3139 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
3142 if (init_pair(*pair,
3143 (NCURSES_COLOR_T) *fg,
3144 (NCURSES_COLOR_T) *bg) == ERR) {
3153 /****************************************************************************
3155 * Soft-key label test
3157 ****************************************************************************/
3162 #define SLK_WORK (SLK_HELP + 3)
3167 static const char *table[] =
3169 "Available commands are:"
3171 ,"^L -- repaint this message and activate soft keys"
3172 ,"a/d -- activate/disable soft keys"
3173 ,"c -- set centered format for labels"
3174 ,"l -- set left-justified format for labels"
3175 ,"r -- set right-justified format for labels"
3176 ,"[12345678] -- set label; labels are numbered 1 through 8"
3177 ,"e -- erase stdscr (should not erase labels)"
3178 ,"s -- test scrolling of shortened screen"
3179 ,"v/V -- cycle through video attributes"
3181 ,"F/f/B/b -- cycle through foreground/background colors"
3183 ,"ESC -- return to main menu"
3185 ,"Note: if activating the soft keys causes your terminal to scroll up"
3186 ,"one line, your terminal auto-scrolls when anything is written to the"
3187 ,"last screen position. The ncurses code does not yet handle this"
3193 for (j = 0; j < SIZEOF(table); ++j) {
3201 call_slk_color(int fg, int bg)
3203 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
3205 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
3214 slk_test(bool recur GCC_UNUSED)
3215 /* exercise the soft keys */
3220 chtype attr = A_NORMAL;
3221 unsigned at_code = 0;
3223 int fg = COLOR_BLACK;
3224 int bg = COLOR_WHITE;
3225 NCURSES_PAIRS_T pair = 0;
3227 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3228 unsigned my_size = init_attr_list(my_list, termattrs());
3233 call_slk_color(fg, bg);
3243 MvAddStr(0, 20, "Soft Key Exerciser");
3258 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3259 while ((c = Getchar()) != 'Q' && (c != ERR))
3287 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3288 _nc_STRCPY(buf, "", sizeof(buf));
3289 if ((s = slk_label(c - '0')) != 0) {
3290 _nc_STRNCPY(buf, s, (size_t) 8);
3292 wGetstring(stdscr, buf, 8);
3293 slk_set((c - '0'), buf, fmt);
3302 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3304 wnoutrefresh(stdscr);
3309 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3316 if (cycle_colors(c, &fg, &bg, &pair)) {
3318 call_slk_color(fg, bg);
3328 } while (!isQuit(c = Getchar(), TRUE));
3337 #if USE_WIDEC_SUPPORT
3340 x_slk_test(bool recur GCC_UNUSED)
3341 /* exercise the soft keys */
3344 wchar_t buf[SLKLEN + 1];
3346 attr_t attr = WA_NORMAL;
3347 unsigned at_code = 0;
3348 int fg = COLOR_BLACK;
3349 int bg = COLOR_WHITE;
3350 NCURSES_PAIRS_T pair = 0;
3351 W_ATTR_TBL my_list[SIZEOF(w_attrs_to_test)];
3352 unsigned my_size = init_w_attr_list(my_list, term_attrs());
3356 call_slk_color(fg, bg);
3363 attr_on(WA_BOLD, NULL);
3364 MvAddStr(0, 20, "Soft Key Exerciser");
3365 attr_off(WA_BOLD, NULL);
3379 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3380 while ((c = Getchar()) != 'Q' && (c != ERR))
3408 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3410 if ((s = slk_label(c - '0')) != 0) {
3411 char *temp = strdup(s);
3412 size_t used = strlen(temp);
3413 size_t want = SLKLEN;
3415 #ifndef state_unused
3420 while (want > 0 && used != 0) {
3421 const char *base = s;
3422 reset_mbytes(state);
3423 test = count_mbytes(base, 0, &state);
3424 if (test == (size_t) -1) {
3426 } else if (test > want) {
3429 reset_mbytes(state);
3430 trans_mbytes(buf, base, want, &state);
3436 wGet_wstring(stdscr, buf, SLKLEN);
3437 slk_wset((c - '0'), buf, fmt);
3448 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3449 call_slk_color(fg, bg);
3454 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3455 call_slk_color(fg, bg);
3458 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3460 wnoutrefresh(stdscr);
3464 if (cycle_w_attr(c, &at_code, &attr, my_list, my_size)) {
3465 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3471 if (cycle_colors(c, &fg, &bg, &pair)) {
3473 call_slk_color(fg, bg);
3483 } while (!isQuit(c = Getchar(), TRUE));
3492 #endif /* SLK_INIT */
3495 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3498 unsigned last = 255;
3504 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3509 for (code = first; code <= last; ++code) {
3510 int row = (int) (2 + (code / 16));
3511 int col = (int) (5 * (code % 16));
3512 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3513 for (count = 1; count < repeat; ++count) {
3514 AddCh(colored_chtype(code, attr, pair));
3521 * Show a slice of 32 characters, allowing those to be repeated up to the
3524 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3525 * terminal to perform functions. The remaining codes can be graphic.
3528 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3531 unsigned first = (unsigned) base;
3532 unsigned last = first + (unsigned) pagesize - 2;
3533 bool C1 = (first == 128);
3538 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3539 C1 ? "C1" : "GR", first, last);
3543 for (code = first; code <= last; code++) {
3545 int row = 2 + ((int) (code - first) % (pagesize / 2));
3546 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3548 _nc_SPRINTF(tmp, _nc_SLIMIT(sizeof(tmp)) "%3u (0x%x)", code, code);
3549 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3553 nodelay(stdscr, TRUE);
3554 echochar(colored_chtype(code, attr, pair));
3556 /* (yes, this _is_ crude) */
3557 while ((reply = Getchar()) != ERR) {
3558 AddCh(UChar(reply));
3561 nodelay(stdscr, FALSE);
3563 } while (--count > 0);
3570 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3576 MvPrintw(0, 20, "Display of PC Character Codes");
3580 for (code = 0; code < 16; ++code) {
3581 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3583 for (code = 0; code < 256; code++) {
3585 int row = 3 + (int) (code / 16) + (code >= 128);
3586 int col = 8 + (int) (code % 16) * PC_COLS;
3587 if ((code % 16) == 0)
3588 MvPrintw(row, 0, "0x%02x:", code);
3599 * Skip the ones that do not work.
3603 AddCh(colored_chtype(code, A_ALTCHARSET | attr, pair));
3606 } while (--count > 0);
3611 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3615 attr |= (attr_t) COLOR_PAIR(pair);
3619 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3624 colored_chtype(ACS_VLINE, attr, pair),
3625 colored_chtype(ACS_VLINE, attr, pair),
3626 colored_chtype(ACS_HLINE, attr, pair),
3627 colored_chtype(ACS_HLINE, attr, pair),
3628 colored_chtype(ACS_ULCORNER, attr, pair),
3629 colored_chtype(ACS_URCORNER, attr, pair),
3630 colored_chtype(ACS_LLCORNER, attr, pair),
3631 colored_chtype(ACS_LRCORNER, attr, pair));
3632 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3633 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3634 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3635 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3636 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3637 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3638 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3644 show_1_acs(int n, int repeat, const char *name, chtype code)
3646 const int height = 16;
3647 int row = 2 + (n % height);
3648 int col = (n / height) * COLS / 2;
3650 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3653 } while (--repeat > 0);
3658 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3659 /* display the ACS character set */
3663 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3667 MvAddStr(0, 20, "Display of the ACS Character Set");
3671 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3672 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3673 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3674 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3676 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3677 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3678 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3679 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3681 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3682 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3685 * HPUX's ACS definitions are broken here. Just give up.
3687 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3688 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3689 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3690 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3691 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3693 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3694 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3695 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3696 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3697 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3698 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3699 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3700 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3701 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3703 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3704 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3705 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3707 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3708 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3709 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3710 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3711 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3712 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3718 acs_test(bool recur GCC_UNUSED)
3722 char *term = getenv("TERM");
3723 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3726 chtype attr = A_NORMAL;
3729 int fg = COLOR_BLACK;
3730 int bg = COLOR_BLACK;
3731 unsigned at_code = 0;
3732 NCURSES_PAIRS_T pair = 0;
3733 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3734 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3735 unsigned my_size = init_attr_list(my_list, termattrs());
3743 ToggleAcs(last_show_acs, show_acs_chars);
3747 ToggleAcs(last_show_acs, show_pc_chars);
3752 if (pagesize == 32) {
3759 ToggleAcs(last_show_acs, show_box_chars);