1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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.313 2008/04/12 22:04:42 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 */
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 */
121 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
123 #define P(string) printw("%s\n", string)
125 #define BLANK ' ' /* this is the background character */
128 static int max_colors; /* the actual number of colors we'll use */
129 static int min_colors; /* the minimum color code */
130 static bool use_colors; /* true if we use colors */
133 static int max_pairs; /* ...and the number of color pairs */
141 static RGB_DATA *all_colors;
143 static void main_menu(bool);
145 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
146 * though we can rely on negative x/y values to stop the macro.
149 do_h_line(int y, int x, chtype c, int to)
152 mvhline(y, x, c, (to) - (x));
156 do_v_line(int y, int x, chtype c, int to)
159 mvvline(y, x, c, (to) - (y));
173 return ((c) == QUIT || (c) == ESCAPE);
175 #define case_QUIT QUIT: case ESCAPE
177 /* Common function to allow ^T to toggle trace-mode in the middle of a test
178 * so that trace-files can be made smaller.
181 wGetchar(WINDOW *win)
185 while ((c = wgetch(win)) == CTRL('T')) {
187 save_trace = _nc_tracing;
188 Trace(("TOGGLE-TRACING OFF"));
191 _nc_tracing = save_trace;
195 Trace(("TOGGLE-TRACING ON"));
202 #define Getchar() wGetchar(stdscr)
204 /* replaces wgetnstr(), since we want to be able to edit values */
206 wGetstring(WINDOW *win, char *buffer, int limit)
213 wattrset(win, A_REVERSE);
217 if (x > (int) strlen(buffer))
218 x = (int) strlen(buffer);
220 wprintw(win, "%-*s", limit, buffer);
221 wmove(win, y0, x0 + x);
222 switch (ch = wGetchar(win)) {
235 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
253 if (!isprint(ch) || ch >= KEY_MIN) {
255 } else if ((int) strlen(buffer) < limit) {
257 for (j = strlen(buffer) + 1; j > x; --j) {
258 buffer[j] = buffer[j - 1];
267 wattroff(win, A_REVERSE);
272 #if USE_WIDEC_SUPPORT
276 return (ch + 0xff10 - '0');
280 make_fullwidth_text(wchar_t *target, const char *source)
283 while ((ch = *source++) != 0) {
284 *target++ = fullwidth_of(ch);
290 make_narrow_text(wchar_t *target, const char *source)
293 while ((ch = *source++) != 0) {
300 make_fullwidth_digit(cchar_t *target, int digit)
304 source[0] = fullwidth_of(digit + '0');
306 setcchar(target, source, A_NORMAL, 0, 0);
310 wGet_wchar(WINDOW *win, wint_t *result)
314 while ((c = wget_wch(win, result)) == CTRL('T')) {
316 save_trace = _nc_tracing;
317 Trace(("TOGGLE-TRACING OFF"));
320 _nc_tracing = save_trace;
324 Trace(("TOGGLE-TRACING ON"));
327 c = wget_wch(win, result);
331 #define Get_wchar(result) wGet_wchar(stdscr, result)
333 /* replaces wgetn_wstr(), since we want to be able to edit values */
335 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
344 wattrset(win, A_REVERSE);
348 if (x > (int) wcslen(buffer))
349 x = (int) wcslen(buffer);
351 /* clear the "window' */
353 wprintw(win, "%*s", limit, " ");
355 /* write the existing buffer contents */
357 waddnwstr(win, buffer, limit);
359 /* positions the cursor past character 'x' */
361 waddnwstr(win, buffer, x);
363 switch (wGet_wchar(win, &ch)) {
403 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
423 } else if ((int) wcslen(buffer) < limit) {
425 for (j = wcslen(buffer) + 1; j > x; --j) {
426 buffer[j] = buffer[j - 1];
435 wattroff(win, A_REVERSE);
446 addstr("Press any key to continue... ");
451 Cannot(const char *what)
453 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
458 ShellOut(bool message)
461 addstr("Shelling out...");
466 addstr("returned from shellout.\n");
470 #ifdef NCURSES_MOUSE_VERSION
472 * This function is the same as _tracemouse(), but we cannot count on that
473 * being available in the non-debug library.
476 mouse_decode(MEVENT const *ep)
478 static char buf[80 + (5 * 10) + (32 * 15)];
480 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
481 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
483 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
485 SHOW(BUTTON1_RELEASED, "release-1");
486 SHOW(BUTTON1_PRESSED, "press-1");
487 SHOW(BUTTON1_CLICKED, "click-1");
488 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
489 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
490 #if NCURSES_MOUSE_VERSION == 1
491 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
494 SHOW(BUTTON2_RELEASED, "release-2");
495 SHOW(BUTTON2_PRESSED, "press-2");
496 SHOW(BUTTON2_CLICKED, "click-2");
497 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
498 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
499 #if NCURSES_MOUSE_VERSION == 1
500 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
503 SHOW(BUTTON3_RELEASED, "release-3");
504 SHOW(BUTTON3_PRESSED, "press-3");
505 SHOW(BUTTON3_CLICKED, "click-3");
506 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
507 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
508 #if NCURSES_MOUSE_VERSION == 1
509 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
512 SHOW(BUTTON4_RELEASED, "release-4");
513 SHOW(BUTTON4_PRESSED, "press-4");
514 SHOW(BUTTON4_CLICKED, "click-4");
515 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
516 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
517 #if NCURSES_MOUSE_VERSION == 1
518 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
521 #if NCURSES_MOUSE_VERSION == 2
522 SHOW(BUTTON5_RELEASED, "release-5");
523 SHOW(BUTTON5_PRESSED, "press-5");
524 SHOW(BUTTON5_CLICKED, "click-5");
525 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
526 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
529 SHOW(BUTTON_CTRL, "ctrl");
530 SHOW(BUTTON_SHIFT, "shift");
531 SHOW(BUTTON_ALT, "alt");
532 SHOW(ALL_MOUSE_EVENTS, "all-events");
533 SHOW(REPORT_MOUSE_POSITION, "position");
537 if (buf[strlen(buf) - 1] == ' ')
538 buf[strlen(buf) - 2] = '\0';
539 (void) strcat(buf, "}");
542 #endif /* NCURSES_MOUSE_VERSION */
544 /****************************************************************************
546 * Character input test
548 ****************************************************************************/
551 setup_getch(WINDOW *win, bool flags[])
553 keypad(win, flags['k']); /* should be redundant, but for testing */
554 meta(win, flags['m']); /* force this to a known state */
562 wgetch_help(WINDOW *win, bool flags[])
564 static const char *help[] =
566 "e -- toggle echo mode"
567 ,"g -- triggers a getstr test"
568 ,"k -- toggle keypad/literal mode"
569 ,"m -- toggle meta (7-bit/8-bit) mode"
572 ,"w -- create a new window"
574 ,"z -- suspend this process"
578 unsigned chk = ((SIZEOF(help) + 1) / 2);
583 printw("Type any key to see its %s value. Also:\n",
584 flags['k'] ? "keypad" : "literal");
585 for (n = 0; n < SIZEOF(help); ++n) {
586 int row = 1 + (n % chk);
587 int col = (n >= chk) ? COLS / 2 : 0;
588 int flg = ((strstr(help[n], "toggle") != 0)
589 && (flags[UChar(*help[n])] != FALSE));
592 mvprintw(row, col, "%s", help[n]);
603 wgetch_wrap(WINDOW *win, int first_y)
605 int last_y = getmaxy(win) - 1;
606 int y = getcury(win) + 1;
614 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
620 static WINSTACK *winstack = 0;
621 static unsigned len_winstack = 0;
634 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
636 unsigned need = (level + 1) * 2;
640 winstack = typeMalloc(WINSTACK, len_winstack);
641 } else if (need >= len_winstack) {
643 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
645 winstack[level].text = txt_win;
646 winstack[level].frame = box_win;
649 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
653 /* this chunk is now done in resize_term() */
660 #define slk_repaint() /* nothing */
664 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
665 * Resize both and paint the box in the parent.
668 resize_boxes(unsigned level, WINDOW *win)
672 int high = LINES - base;
676 wnoutrefresh(stdscr);
680 for (n = 0; n < level; ++n) {
681 wresize(winstack[n].frame, high, wide);
682 wresize(winstack[n].text, high - 2, wide - 2);
685 werase(winstack[n].text);
686 box(winstack[n].frame, 0, 0);
687 wnoutrefresh(winstack[n].frame);
688 wprintw(winstack[n].text,
690 getmaxy(winstack[n].text),
691 getmaxx(winstack[n].text));
692 wnoutrefresh(winstack[n].text);
693 if (winstack[n].text == win)
699 #define forget_boxes() /* nothing */
700 #define remember_boxes(level,text,frame) /* nothing */
704 wgetch_test(unsigned level, WINDOW *win, int delay)
707 int first_y, first_x;
711 bool blocking = (delay < 0);
713 memset(flags, FALSE, sizeof(flags));
714 flags[UChar('k')] = (win == stdscr);
716 setup_getch(win, flags);
717 wtimeout(win, delay);
718 getyx(win, first_y, first_x);
720 wgetch_help(win, flags);
721 wsetscrreg(win, first_y, getmaxy(win) - 1);
725 while ((c = wGetchar(win)) == ERR) {
728 (void) wprintw(win, "%05d: input error", incount);
731 (void) wprintw(win, "%05d: input timed out", incount);
733 wgetch_wrap(win, first_y);
735 if (c == ERR && blocking) {
737 wgetch_wrap(win, first_y);
738 } else if (isQuit(c)) {
740 } else if (c == 'e') {
741 flags[UChar('e')] = !flags[UChar('e')];
742 setup_getch(win, flags);
743 wgetch_help(win, flags);
744 } else if (c == 'g') {
745 waddstr(win, "getstr test: ");
747 wgetnstr(win, buf, sizeof(buf) - 1);
749 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
751 wgetch_wrap(win, first_y);
752 } else if (c == 'k') {
753 flags[UChar('k')] = !flags[UChar('k')];
754 setup_getch(win, flags);
755 wgetch_help(win, flags);
756 } else if (c == 'm') {
757 flags[UChar('m')] = !flags[UChar('m')];
758 setup_getch(win, flags);
759 wgetch_help(win, flags);
760 } else if (c == 's') {
762 } else if (c == 'w') {
763 int high = getmaxy(win) - 1 - first_y + 1;
764 int wide = getmaxx(win) - first_x;
766 int new_y = first_y + getbegy(win);
767 int new_x = first_x + getbegx(win);
769 getyx(win, old_y, old_x);
770 if (high > 2 && wide > 2) {
771 WINDOW *wb = newwin(high, wide, new_y, new_x);
772 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
777 remember_boxes(level, wi, wb);
778 wgetch_test(level + 1, wi, delay);
782 wgetch_help(win, flags);
783 wmove(win, old_y, old_x);
789 } else if (c == 'z') {
790 kill(getpid(), SIGTSTP);
793 wprintw(win, "Key pressed: %04o ", c);
794 #ifdef NCURSES_MOUSE_VERSION
795 if (c == KEY_MOUSE) {
800 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
802 move(event.y, event.x);
806 #endif /* NCURSES_MOUSE_VERSION */
808 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
809 if (c == KEY_RESIZE) {
810 resize_boxes(level, win);
813 (void) waddstr(win, keyname(c));
814 } else if (c > 0x80) {
815 unsigned c2 = (c & 0x7f);
817 (void) wprintw(win, "M-%c", UChar(c2));
819 (void) wprintw(win, "M-%s", unctrl(c2));
820 waddstr(win, " (high-half character)");
823 (void) wprintw(win, "%c (ASCII printable character)", c);
825 (void) wprintw(win, "%s (ASCII control character)",
828 wgetch_wrap(win, first_y);
836 begin_getch_test(void)
843 #ifdef NCURSES_MOUSE_VERSION
844 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
847 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
849 getnstr(buf, sizeof(buf) - 1);
853 if (isdigit(UChar(buf[0]))) {
854 delay = atoi(buf) * 100;
864 finish_getch_test(void)
866 #ifdef NCURSES_MOUSE_VERSION
867 mousemask(0, (mmask_t *) 0);
878 int delay = begin_getch_test();
881 wgetch_test(0, stdscr, delay);
886 #if USE_WIDEC_SUPPORT
888 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
889 * Resize both and paint the box in the parent.
891 #if defined(KEY_RESIZE) && HAVE_WRESIZE
893 resize_wide_boxes(unsigned level, WINDOW *win)
897 int high = LINES - base;
901 wnoutrefresh(stdscr);
905 for (n = 0; n < level; ++n) {
906 wresize(winstack[n].frame, high, wide);
907 wresize(winstack[n].text, high - 2, wide - 2);
910 werase(winstack[n].text);
911 box_set(winstack[n].frame, 0, 0);
912 wnoutrefresh(winstack[n].frame);
913 wprintw(winstack[n].text,
915 getmaxy(winstack[n].text),
916 getmaxx(winstack[n].text));
917 wnoutrefresh(winstack[n].text);
918 if (winstack[n].text == win)
923 #endif /* KEY_RESIZE */
926 wcstos(const wchar_t *src)
931 const wchar_t *tmp = src;
933 memset(&state, 0, sizeof(state));
934 if ((need = wcsrtombs(0, &tmp, 0, &state)) > 0) {
935 unsigned have = need;
936 result = typeCalloc(char, have + 1);
938 if (wcsrtombs(result, &tmp, have, &state) != have) {
947 wget_wch_test(unsigned level, WINDOW *win, int delay)
949 wchar_t wchar_buf[BUFSIZ];
950 wint_t wint_buf[BUFSIZ];
951 int first_y, first_x;
955 bool blocking = (delay < 0);
959 memset(flags, FALSE, sizeof(flags));
960 flags[UChar('k')] = (win == stdscr);
962 setup_getch(win, flags);
963 wtimeout(win, delay);
964 getyx(win, first_y, first_x);
966 wgetch_help(win, flags);
967 wsetscrreg(win, first_y, getmaxy(win) - 1);
971 while ((code = wGet_wchar(win, &c)) == ERR) {
974 (void) wprintw(win, "%05d: input error", incount);
977 (void) wprintw(win, "%05d: input timed out", incount);
979 wgetch_wrap(win, first_y);
981 if (code == ERR && blocking) {
983 wgetch_wrap(win, first_y);
984 } else if (isQuit((int) c)) {
986 } else if (c == 'e') {
987 flags[UChar('e')] = !flags[UChar('e')];
988 setup_getch(win, flags);
989 wgetch_help(win, flags);
990 } else if (c == 'g') {
991 waddstr(win, "getstr test: ");
993 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
996 wprintw(win, "wgetn_wstr returns an error.");
999 for (n = 0; (wchar_buf[n] = wint_buf[n]) != 0; ++n) ;
1000 if ((temp = wcstos(wchar_buf)) != 0) {
1001 wprintw(win, "I saw %d characters:\n\t`%s'.",
1002 (int) wcslen(wchar_buf), temp);
1005 wprintw(win, "I saw %d characters (cannot convert).",
1006 (int) wcslen(wchar_buf));
1010 wgetch_wrap(win, first_y);
1011 } else if (c == 'k') {
1012 flags[UChar('k')] = !flags[UChar('k')];
1013 setup_getch(win, flags);
1014 wgetch_help(win, flags);
1015 } else if (c == 'm') {
1016 flags[UChar('m')] = !flags[UChar('m')];
1017 setup_getch(win, flags);
1018 wgetch_help(win, flags);
1019 } else if (c == 's') {
1021 } else if (c == 'w') {
1022 int high = getmaxy(win) - 1 - first_y + 1;
1023 int wide = getmaxx(win) - first_x;
1025 int new_y = first_y + getbegy(win);
1026 int new_x = first_x + getbegx(win);
1028 getyx(win, old_y, old_x);
1029 if (high > 2 && wide > 2) {
1030 WINDOW *wb = newwin(high, wide, new_y, new_x);
1031 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1036 remember_boxes(level, wi, wb);
1037 wget_wch_test(level + 1, wi, delay);
1041 wgetch_help(win, flags);
1042 wmove(win, old_y, old_x);
1047 } else if (c == 'z') {
1048 kill(getpid(), SIGTSTP);
1051 wprintw(win, "Key pressed: %04o ", c);
1052 #ifdef NCURSES_MOUSE_VERSION
1053 if (c == KEY_MOUSE) {
1057 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1059 move(event.y, event.x);
1063 #endif /* NCURSES_MOUSE_VERSION */
1064 if (code == KEY_CODE_YES) {
1065 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1066 if (c == KEY_RESIZE) {
1067 resize_wide_boxes(level, win);
1070 (void) waddstr(win, key_name((wchar_t) c));
1072 if (c < 256 && iscntrl(c)) {
1073 (void) wprintw(win, "%s (control character)", unctrl(c));
1076 waddnwstr(win, &c2, 1);
1077 (void) wprintw(win, " = %#x (printable character)", c);
1080 wgetch_wrap(win, first_y);
1090 int delay = begin_getch_test();
1093 wget_wch_test(0, stdscr, delay);
1095 finish_getch_test();
1099 /****************************************************************************
1101 * Character attributes test
1103 ****************************************************************************/
1105 #if HAVE_SETUPTERM || HAVE_TGETENT
1106 #define get_ncv() TIGETNUM("ncv","NC")
1107 #define get_xmc() TIGETNUM("xmc","sg")
1109 #define get_ncv() -1
1110 #define get_xmc() -1
1117 static int first = TRUE;
1118 static chtype result = 0;
1124 char *area_pointer = parsed;
1126 tgetent(buffer, getenv("TERM"));
1129 if (TIGETSTR("smso", "so"))
1130 result |= A_STANDOUT;
1131 if (TIGETSTR("smul", "us"))
1132 result |= A_UNDERLINE;
1133 if (TIGETSTR("rev", "mr"))
1134 result |= A_REVERSE;
1135 if (TIGETSTR("blink", "mb"))
1137 if (TIGETSTR("dim", "mh"))
1139 if (TIGETSTR("bold", "md"))
1141 if (TIGETSTR("smacs", "ac"))
1142 result |= A_ALTCHARSET;
1148 #define termattrs() my_termattrs()
1151 #define MAX_ATTRSTRING 31
1152 #define LEN_ATTRSTRING 26
1154 static char attr_test_string[MAX_ATTRSTRING + 1];
1157 attr_legend(WINDOW *helpwin)
1162 mvwprintw(helpwin, row++, col,
1164 mvwprintw(helpwin, row++, col,
1167 mvwprintw(helpwin, row++, col,
1168 "Modify the test strings:");
1169 mvwprintw(helpwin, row++, col,
1170 " A digit sets gaps on each side of displayed attributes");
1171 mvwprintw(helpwin, row++, col,
1172 " </> shifts the text left/right. ");
1174 mvwprintw(helpwin, row++, col,
1177 mvwprintw(helpwin, row++, col,
1178 " f/F/b/F toggle foreground/background background color");
1179 mvwprintw(helpwin, row++, col,
1180 " t/T toggle text/background color attribute");
1182 mvwprintw(helpwin, row++, col,
1183 " a/A toggle ACS (alternate character set) mapping");
1184 mvwprintw(helpwin, row++, col,
1185 " v/V toggle video attribute to combine with each line");
1189 show_color_attr(int fg, int bg, int tx)
1192 printw(" Colors (fg %d, bg %d", fg, bg);
1194 printw(", text %d", tx);
1200 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1231 if (*fg < min_colors)
1235 if (*bg < min_colors)
1249 adjust_attr_string(int adjust)
1251 int first = ((int) UChar(attr_test_string[0])) + adjust;
1252 int last = first + LEN_ATTRSTRING;
1254 if (first >= ' ' && last <= '~') { /* 32..126 */
1256 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1257 attr_test_string[j] = k;
1258 if (((k + 1 - first) % 5) == 0) {
1260 if (j < MAX_ATTRSTRING)
1261 attr_test_string[j] = ' ';
1264 while (j < MAX_ATTRSTRING)
1265 attr_test_string[j++] = ' ';
1266 attr_test_string[j] = '\0';
1273 init_attr_string(void)
1275 attr_test_string[0] = 'a';
1276 adjust_attr_string(0);
1280 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1282 int ncv = get_ncv();
1283 chtype test = attr & (chtype) (~A_ALTCHARSET);
1286 mvprintw(row, 5, "-->");
1287 mvprintw(row, 8, "%s mode:", name);
1288 mvprintw(row, 24, "|");
1290 printw("%*s", skip, " ");
1292 * Just for testing, write text using the alternate character set one
1293 * character at a time (to pass its rendition directly), and use the
1294 * string operation for the other attributes.
1296 if (attr & A_ALTCHARSET) {
1300 for (s = attr_test_string; *s != '\0'; ++s) {
1306 addstr(attr_test_string);
1310 printw("%*s", skip, " ");
1312 if (test != A_NORMAL) {
1313 if (!(termattrs() & test)) {
1316 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1317 static const chtype table[] =
1333 for (n = 0; n < SIZEOF(table); n++) {
1334 if ((table[n] & attr) != 0
1335 && ((1 << n) & ncv) != 0) {
1343 if ((termattrs() & test) != test)
1350 static const struct {
1352 NCURSES_CONST char * name;
1353 } attrs_to_test[] = {
1354 { A_STANDOUT, "STANDOUT" },
1355 { A_REVERSE, "REVERSE" },
1357 { A_UNDERLINE, "UNDERLINE" },
1359 { A_BLINK, "BLINK" },
1360 { A_PROTECT, "PROTECT" },
1362 { A_INVIS, "INVISIBLE" },
1364 { A_NORMAL, "NORMAL" },
1369 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1379 if (ch < 256 && isdigit(ch)) {
1387 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1389 attr_legend(helpwin);
1402 *kc = SIZEOF(attrs_to_test) - 1;
1408 if (*kc >= SIZEOF(attrs_to_test))
1412 adjust_attr_string(-1);
1415 adjust_attr_string(1);
1421 error = cycle_color_attr(ch, fg, bg, tx);
1431 /* test text attributes */
1434 int skip = get_xmc();
1435 short fg = COLOR_BLACK; /* color pair 0 is special */
1436 short bg = COLOR_BLACK;
1444 n = skip; /* make it easy */
1445 k = SIZEOF(attrs_to_test) - 1;
1450 chtype normal = A_NORMAL | BLANK;
1454 short pair = (fg != COLOR_BLACK || bg != COLOR_BLACK);
1457 if (init_pair(pair, fg, bg) == ERR) {
1460 normal |= COLOR_PAIR(pair);
1465 if (init_pair(pair, tx, bg) == ERR) {
1468 extras |= COLOR_PAIR(pair);
1477 mvaddstr(0, 20, "Character attribute test display");
1479 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1480 bool arrow = (j == k);
1481 row = show_attr(row, n, arrow,
1483 attrs_to_test[j].attr |
1484 attrs_to_test[k].attr,
1485 attrs_to_test[j].name);
1489 "This terminal does %shave the magic-cookie glitch",
1490 get_xmc() > -1 ? "" : "not ");
1491 mvprintw(row + 1, 8, "Enter '?' for help.");
1492 show_color_attr(fg, bg, tx);
1493 printw(" ACS (%d)", ac != 0);
1496 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1498 bkgdset(A_NORMAL | BLANK);
1503 #if USE_WIDEC_SUPPORT
1504 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1507 wide_adjust_attr_string(int adjust)
1509 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1510 int last = first + LEN_ATTRSTRING;
1512 if (first >= ' ' && last <= '~') { /* 32..126 */
1514 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1515 wide_attr_test_string[j] = k;
1516 if (((k + 1 - first) % 5) == 0) {
1518 if (j < MAX_ATTRSTRING)
1519 wide_attr_test_string[j] = ' ';
1522 while (j < MAX_ATTRSTRING)
1523 wide_attr_test_string[j++] = ' ';
1524 wide_attr_test_string[j] = '\0';
1531 wide_init_attr_string(void)
1533 wide_attr_test_string[0] = 'a';
1534 wide_adjust_attr_string(0);
1538 set_wide_background(short pair)
1545 setcchar(&normal, blank, A_NORMAL, pair, 0);
1551 get_wide_background(void)
1553 attr_t result = A_NORMAL;
1559 if (getbkgrnd(&ch) != ERR) {
1560 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1568 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1570 int ncv = get_ncv();
1571 chtype test = attr & ~WA_ALTCHARSET;
1574 mvprintw(row, 5, "-->");
1575 mvprintw(row, 8, "%s mode:", name);
1576 mvprintw(row, 24, "|");
1578 printw("%*s", skip, " ");
1581 * Just for testing, write text using the alternate character set one
1582 * character at a time (to pass its rendition directly), and use the
1583 * string operation for the other attributes.
1585 if (attr & WA_ALTCHARSET) {
1589 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1593 setcchar(&ch, fill, attr, pair, 0);
1600 attr_get(&old_attr, &old_pair, 0);
1601 attr_set(attr, pair, 0);
1602 addwstr(wide_attr_test_string);
1603 attr_set(old_attr, old_pair, 0);
1606 printw("%*s", skip, " ");
1608 if (test != A_NORMAL) {
1609 if (!(term_attrs() & test)) {
1612 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1613 static const attr_t table[] =
1627 for (n = 0; n < SIZEOF(table); n++) {
1628 if ((table[n] & attr) != 0
1629 && ((1 << n) & ncv) != 0) {
1637 if ((term_attrs() & test) != test)
1645 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1655 if (ch < 256 && isdigit(ch)) {
1663 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1664 box_set(helpwin, 0, 0);
1665 attr_legend(helpwin);
1678 *kc = SIZEOF(attrs_to_test) - 1;
1684 if (*kc >= SIZEOF(attrs_to_test))
1688 wide_adjust_attr_string(-1);
1691 wide_adjust_attr_string(1);
1697 error = cycle_color_attr(ch, fg, bg, tx);
1706 wide_attr_test(void)
1707 /* test text attributes using wide-character calls */
1710 int skip = get_xmc();
1711 short fg = COLOR_BLACK; /* color pair 0 is special */
1712 short bg = COLOR_BLACK;
1720 n = skip; /* make it easy */
1721 k = SIZEOF(attrs_to_test) - 1;
1722 wide_init_attr_string();
1730 pair = (fg != COLOR_BLACK || bg != COLOR_BLACK);
1733 if (init_pair(pair, fg, bg) == ERR) {
1740 if (init_pair(extras, tx, bg) == ERR) {
1745 set_wide_background(pair);
1748 box_set(stdscr, 0, 0);
1749 mvaddstr(0, 20, "Character attribute test display");
1751 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1752 row = wide_show_attr(row, n, j == k,
1754 attrs_to_test[j].attr |
1755 attrs_to_test[k].attr,
1757 attrs_to_test[j].name);
1761 "This terminal does %shave the magic-cookie glitch",
1762 get_xmc() > -1 ? "" : "not ");
1763 mvprintw(row + 1, 8, "Enter '?' for help.");
1764 show_color_attr(fg, bg, tx);
1765 printw(" ACS (%d)", ac != 0);
1768 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1770 set_wide_background(0);
1776 /****************************************************************************
1778 * Color support tests
1780 ****************************************************************************/
1782 static NCURSES_CONST char *the_color_names[] =
1803 show_color_name(int y, int x, int color, bool wide)
1805 if (move(y, x) != ERR) {
1810 sprintf(temp, "%02d", color);
1812 } else if (color >= 8) {
1813 sprintf(temp, "[%02d]", color);
1815 strcpy(temp, the_color_names[color]);
1817 printw("%-*.*s", width, width, temp);
1822 color_legend(WINDOW *helpwin, bool wide)
1827 mvwprintw(helpwin, row++, col,
1830 mvwprintw(helpwin, row++, col,
1831 "Use up/down arrow to scroll through the display if it is");
1832 mvwprintw(helpwin, row++, col,
1833 "longer than one screen. Control/N and Control/P can be used");
1834 mvwprintw(helpwin, row++, col,
1835 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1836 mvwprintw(helpwin, row++, col,
1837 "full screen; control/B and control/F can be used here.");
1839 mvwprintw(helpwin, row++, col,
1841 mvwprintw(helpwin, row++, col,
1842 " a/A toggle altcharset off/on");
1843 mvwprintw(helpwin, row++, col,
1844 " b/B toggle bold off/on");
1845 mvwprintw(helpwin, row++, col,
1846 " n/N toggle text/number on/off");
1847 mvwprintw(helpwin, row++, col,
1848 " w/W toggle width between 8/16 colors");
1849 #if USE_WIDEC_SUPPORT
1851 mvwprintw(helpwin, row++, col,
1852 "Wide characters:");
1853 mvwprintw(helpwin, row++, col,
1854 " x/X toggle text between ASCII and wide-character");
1861 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1863 /* generate a color test pattern */
1870 int grid_top = top + 3;
1871 int page_size = (LINES - grid_top);
1872 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1878 bool opt_acsc = FALSE;
1879 bool opt_bold = FALSE;
1880 bool opt_wide = FALSE;
1881 bool opt_nums = FALSE;
1884 if (pairs_max > COLOR_PAIRS)
1885 pairs_max = COLOR_PAIRS;
1890 /* this assumes an 80-column line */
1894 per_row = (COLORS > 8) ? 16 : 8;
1901 row_limit = (pairs_max + per_row - 1) / per_row;
1904 (void) printw("There are %d color pairs and %d colors\n",
1908 (void) mvprintw(top + 1, 0,
1909 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1912 opt_bold ? "on" : "off");
1914 /* show color names/numbers across the top */
1915 for (i = 0; i < per_row; i++)
1916 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
1918 /* show a grid of colors, with color names/ numbers on the left */
1919 for (i = (base_row * per_row); i < pairs_max; i++) {
1920 int row = grid_top + (i / per_row) - base_row;
1921 int col = (i % per_row + 1) * width;
1924 if (row >= 0 && move(row, col) != ERR) {
1925 short fg = i % COLORS;
1926 short bg = i / COLORS;
1928 init_pair(pair, fg, bg);
1929 attron((attr_t) COLOR_PAIR(pair));
1931 attron((attr_t) A_ALTCHARSET);
1933 attron((attr_t) A_BOLD);
1936 sprintf(numbered, "{%02X}", i);
1939 printw("%-*.*s", width, width, hello);
1942 if ((i % per_row) == 0 && (i % COLORS) == 0) {
1943 show_color_name(row, 0, i / COLORS, opt_wide);
1951 switch (wGetchar(stdscr)) {
1974 set_color_test(opt_wide, FALSE);
1977 set_color_test(opt_wide, TRUE);
1981 if (base_row <= 0) {
1989 if (base_row + page_size >= row_limit) {
1998 if (base_row <= 0) {
2001 base_row -= (page_size - 1);
2009 if (base_row + page_size >= row_limit) {
2012 base_row += page_size - 1;
2013 if (base_row + page_size >= row_limit) {
2014 base_row = row_limit - page_size - 1;
2019 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2021 color_legend(helpwin, FALSE);
2036 #if USE_WIDEC_SUPPORT
2037 /* generate a color test pattern */
2039 wide_color_test(void)
2045 int grid_top = top + 3;
2046 int page_size = (LINES - grid_top);
2047 int pairs_max = COLOR_PAIRS;
2053 bool opt_acsc = FALSE;
2054 bool opt_bold = FALSE;
2055 bool opt_wide = FALSE;
2056 bool opt_nums = FALSE;
2057 bool opt_xchr = FALSE;
2064 /* this assumes an 80-column line */
2068 per_row = (COLORS > 8) ? 16 : 8;
2075 make_fullwidth_text(buffer, hello);
2079 make_narrow_text(buffer, hello);
2082 row_limit = (pairs_max + per_row - 1) / per_row;
2085 (void) printw("There are %d color pairs and %d colors\n",
2089 (void) mvprintw(top + 1, 0,
2090 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2093 opt_bold ? "on" : "off");
2095 /* show color names/numbers across the top */
2096 for (i = 0; i < per_row; i++)
2097 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
2099 /* show a grid of colors, with color names/ numbers on the left */
2100 for (i = (base_row * per_row); i < pairs_max; i++) {
2101 int row = grid_top + (i / per_row) - base_row;
2102 int col = (i % per_row + 1) * width;
2105 if (row >= 0 && move(row, col) != ERR) {
2106 init_pair(pair, i % COLORS, i / COLORS);
2107 color_set(pair, NULL);
2109 attr_on((attr_t) A_ALTCHARSET, NULL);
2111 attr_on((attr_t) A_BOLD, NULL);
2114 sprintf(numbered, "{%02X}", i);
2116 make_fullwidth_text(buffer, numbered);
2118 make_narrow_text(buffer, numbered);
2121 addnwstr(buffer, width);
2122 attr_set(A_NORMAL, 0, NULL);
2124 if ((i % per_row) == 0 && (i % COLORS) == 0) {
2125 show_color_name(row, 0, i / COLORS, opt_wide);
2133 switch (c = wGetchar(stdscr)) {
2156 set_color_test(opt_wide, FALSE);
2159 set_color_test(opt_wide, TRUE);
2169 if (base_row <= 0) {
2177 if (base_row + page_size >= row_limit) {
2186 if (base_row <= 0) {
2189 base_row -= (page_size - 1);
2197 if (base_row + page_size >= row_limit) {
2200 base_row += page_size - 1;
2201 if (base_row + page_size >= row_limit) {
2202 base_row = row_limit - page_size - 1;
2207 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2209 color_legend(helpwin, TRUE);
2223 #endif /* USE_WIDEC_SUPPORT */
2226 change_color(short current, int field, int value, int usebase)
2228 short red, green, blue;
2230 color_content(current, &red, &green, &blue);
2234 red = usebase ? red + value : value;
2237 green = usebase ? green + value : value;
2240 blue = usebase ? blue + value : value;
2244 if (init_color(current, red, green, blue) == ERR)
2249 init_all_colors(void)
2253 for (c = 0; c < COLORS; ++c)
2256 all_colors[c].green,
2257 all_colors[c].blue);
2260 #define scaled_rgb(n) ((255 * (n)) / 1000)
2264 /* display the color test pattern, without trying to edit colors */
2268 int this_c = 0, value = 0, field = 0;
2271 int page_size = (LINES - 6);
2276 for (i = 0; i < max_colors; i++)
2277 init_pair(i, COLOR_WHITE, i);
2279 mvprintw(LINES - 2, 0, "Number: %d", value);
2282 short red, green, blue;
2285 mvaddstr(0, 20, "Color RGB Value Editing");
2289 (i - top_color < page_size)
2290 && (i < max_colors); i++) {
2293 sprintf(numeric, "[%d]", i);
2294 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2295 (i == current ? '>' : ' '),
2296 (i < (int) SIZEOF(the_color_names)
2297 ? the_color_names[i] : numeric));
2298 attrset(COLOR_PAIR(i));
2302 color_content(i, &red, &green, &blue);
2304 if (current == i && field == 0)
2306 printw("%04d", red);
2307 if (current == i && field == 0)
2310 if (current == i && field == 1)
2312 printw("%04d", green);
2313 if (current == i && field == 1)
2316 if (current == i && field == 2)
2318 printw("%04d", blue);
2319 if (current == i && field == 2)
2322 printw(" ( %3d %3d %3d )",
2328 mvaddstr(LINES - 3, 0,
2329 "Use up/down to select a color, left/right to change fields.");
2330 mvaddstr(LINES - 2, 0,
2331 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2333 move(2 + current - top_color, 0);
2337 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2344 current -= (page_size - 1);
2351 if (current < (max_colors - 1))
2352 current += (page_size - 1);
2359 current = (current == 0 ? (max_colors - 1) : current - 1);
2364 current = (current == (max_colors - 1) ? 0 : current + 1);
2368 field = (field == 2 ? 0 : field + 1);
2372 field = (field == 0 ? 2 : field - 1);
2385 value = value * 10 + (this_c - '0');
2389 change_color(current, field, value, 1);
2393 change_color(current, field, -value, 1);
2397 change_color(current, field, value, 0);
2402 P(" RGB Value Editing Help");
2404 P("You are in the RGB value editor. Use the arrow keys to select one of");
2405 P("the fields in one of the RGB triples of the current colors; the one");
2406 P("currently selected will be reverse-video highlighted.");
2408 P("To change a field, enter the digits of the new value; they are echoed");
2409 P("as entered. Finish by typing `='. The change will take effect instantly.");
2410 P("To increment or decrement a value, use the same procedure, but finish");
2411 P("with a `+' or `-'.");
2413 P("Press 'm' to invoke the top-level menu with the current color settings.");
2414 P("To quit, do ESC");
2436 if (current >= max_colors)
2437 current = max_colors - 1;
2438 if (current < top_color)
2439 top_color = current;
2440 if (current - top_color >= page_size)
2441 top_color = current - (page_size - 1);
2443 mvprintw(LINES - 1, 0, "Number: %d", value);
2451 * ncurses does not reset each color individually when calling endwin().
2458 /****************************************************************************
2460 * Soft-key label test
2462 ****************************************************************************/
2467 #define SLK_WORK (SLK_HELP + 3)
2472 static const char *table[] =
2474 "Available commands are:"
2476 ,"^L -- repaint this message and activate soft keys"
2477 ,"a/d -- activate/disable soft keys"
2478 ,"c -- set centered format for labels"
2479 ,"l -- set left-justified format for labels"
2480 ,"r -- set right-justified format for labels"
2481 ,"[12345678] -- set label; labels are numbered 1 through 8"
2482 ,"e -- erase stdscr (should not erase labels)"
2483 ,"s -- test scrolling of shortened screen"
2485 ,"F/B -- cycle through foreground/background colors"
2487 ,"ESC -- return to main menu"
2489 ,"Note: if activating the soft keys causes your terminal to scroll up"
2490 ,"one line, your terminal auto-scrolls when anything is written to the"
2491 ,"last screen position. The ncurses code does not yet handle this"
2497 for (j = 0; j < SIZEOF(table); ++j) {
2505 call_slk_color(short fg, short bg)
2507 init_pair(1, bg, fg);
2509 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2517 /* exercise the soft keys */
2523 short fg = COLOR_BLACK;
2524 short bg = COLOR_WHITE;
2530 call_slk_color(fg, bg);
2540 mvaddstr(0, 20, "Soft Key Exerciser");
2555 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2556 while ((c = Getchar()) != 'Q' && (c != ERR))
2584 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2586 if ((s = slk_label(c - '0')) != 0) {
2589 wGetstring(stdscr, buf, 8);
2590 slk_set((c - '0'), buf, fmt);
2602 fg = (fg + 1) % COLORS;
2603 call_slk_color(fg, bg);
2608 bg = (bg + 1) % COLORS;
2609 call_slk_color(fg, bg);
2613 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2615 wnoutrefresh(stdscr);
2622 } while (!isQuit(c = Getchar()));
2630 #if USE_WIDEC_SUPPORT
2634 /* exercise the soft keys */
2637 wchar_t buf[SLKLEN + 1];
2639 short fg = COLOR_BLACK;
2640 short bg = COLOR_WHITE;
2644 call_slk_color(fg, bg);
2651 attr_on(WA_BOLD, NULL);
2652 mvaddstr(0, 20, "Soft Key Exerciser");
2653 attr_off(WA_BOLD, NULL);
2667 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2668 while ((c = Getchar()) != 'Q' && (c != ERR))
2696 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2698 if ((s = slk_label(c - '0')) != 0) {
2699 char *temp = strdup(s);
2700 size_t used = strlen(temp);
2701 size_t want = SLKLEN;
2706 while (want > 0 && used != 0) {
2707 const char *base = s;
2708 memset(&state, 0, sizeof(state));
2709 test = mbsrtowcs(0, &base, 0, &state);
2710 if (test == (size_t) -1) {
2712 } else if (test > want) {
2715 memset(&state, 0, sizeof(state));
2716 mbsrtowcs(buf, &base, want, &state);
2722 wGet_wstring(stdscr, buf, SLKLEN);
2723 slk_wset((c - '0'), buf, fmt);
2734 fg = (fg + 1) % COLORS;
2735 call_slk_color(fg, bg);
2740 bg = (bg + 1) % COLORS;
2741 call_slk_color(fg, bg);
2744 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2746 wnoutrefresh(stdscr);
2752 } while (!isQuit(c = Getchar()));
2760 #endif /* SLK_INIT */
2762 /****************************************************************************
2764 * Alternate character-set stuff
2766 ****************************************************************************/
2771 } attrs_to_cycle[] = {
2772 { A_NORMAL, "normal" },
2774 { A_REVERSE, "reverse" },
2775 { A_UNDERLINE, "underline" },
2780 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2786 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2791 *at_code = SIZEOF(attrs_to_cycle) - 1;
2800 *attr = attrs_to_cycle[*at_code].attr;
2805 cycle_colors(int ch, int *fg, int *bg, short *pair)
2807 bool result = FALSE;
2817 if ((*fg += 1) >= COLORS)
2825 if ((*bg += 1) >= COLORS)
2833 *pair = (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2836 if (init_pair(*pair, *fg, *bg) == ERR) {
2845 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2846 * terminal to perform functions. The remaining codes can be graphic.
2849 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
2851 bool C1 = (first == 128);
2853 unsigned last = first + 31;
2858 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2859 C1 ? "C1" : "GR", first, last);
2863 for (code = first; code <= last; code++) {
2865 int row = 2 + ((code - first) % 16);
2866 int col = ((code - first) / 16) * COLS / 2;
2868 sprintf(tmp, "%3u (0x%x)", code, code);
2869 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2873 nodelay(stdscr, TRUE);
2874 echochar(code | attr | COLOR_PAIR(pair));
2876 /* (yes, this _is_ crude) */
2877 while ((reply = Getchar()) != ERR) {
2878 addch(UChar(reply));
2881 nodelay(stdscr, FALSE);
2883 } while (--count > 0);
2890 show_pc_chars(int repeat, attr_t attr, short pair)
2896 mvprintw(0, 20, "Display of PC Character Codes");
2900 for (code = 0; code < 16; ++code) {
2901 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
2903 for (code = 0; code < 256; code++) {
2905 int row = 3 + (code / 16) + (code >= 128);
2906 int col = 8 + (code % 16) * PC_COLS;
2907 if ((code % 16) == 0)
2908 mvprintw(row, 0, "0x%02x:", code);
2919 * Skip the ones that do not work.
2923 addch(code | A_ALTCHARSET | attr | COLOR_PAIR(pair));
2926 } while (--count > 0);
2931 show_box_chars(int repeat, attr_t attr, short pair)
2934 attr |= COLOR_PAIR(pair);
2938 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
2943 mvhline(LINES / 2, 0, ACS_HLINE | attr, COLS);
2944 mvvline(0, COLS / 2, ACS_VLINE | attr, LINES);
2945 mvaddch(0, COLS / 2, ACS_TTEE | attr);
2946 mvaddch(LINES / 2, COLS / 2, ACS_PLUS | attr);
2947 mvaddch(LINES - 1, COLS / 2, ACS_BTEE | attr);
2948 mvaddch(LINES / 2, 0, ACS_LTEE | attr);
2949 mvaddch(LINES / 2, COLS - 1, ACS_RTEE | attr);
2955 show_1_acs(int n, int repeat, const char *name, chtype code)
2957 const int height = 16;
2958 int row = 2 + (n % height);
2959 int col = (n / height) * COLS / 2;
2961 mvprintw(row, col, "%*s : ", COLS / 4, name);
2964 } while (--repeat > 0);
2969 show_acs_chars(int repeat, attr_t attr, short pair)
2970 /* display the ACS character set */
2974 #define BOTH(name) #name, (name | attr | COLOR_PAIR(pair))
2978 mvaddstr(0, 20, "Display of the ACS Character Set");
2982 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
2983 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
2984 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
2985 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
2987 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
2988 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
2989 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
2990 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
2992 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
2993 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
2996 * HPUX's ACS definitions are broken here. Just give up.
2998 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
2999 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3000 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3001 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3002 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3004 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3005 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3006 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3007 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3008 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3009 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3010 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3011 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3012 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3014 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3015 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3016 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3018 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3019 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3020 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3021 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3022 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3023 n = show_1_acs(n, repeat, BOTH(ACS_S9));
3031 char *term = getenv("TERM");
3032 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3035 chtype attr = A_NORMAL;
3038 int fg = COLOR_BLACK;
3039 int bg = COLOR_BLACK;
3040 unsigned at_code = 0;
3042 void (*last_show_acs) (int, attr_t, short) = 0;
3050 ToggleAcs(last_show_acs, show_acs_chars);
3054 ToggleAcs(last_show_acs, show_pc_chars);
3059 ToggleAcs(last_show_acs, show_box_chars);
3085 if (repeat < (COLS / 4))
3093 if (cycle_attr(c, &at_code, &attr)
3094 || cycle_colors(c, &fg, &bg, &pair)) {
3101 if (last_show_acs != 0)
3102 last_show_acs(repeat, attr, pair);
3104 show_upper_chars(digit * 32 + 128, repeat, attr, pair);
3106 mvprintw(LINES - 3, 0,
3107 "Note: ANSI terminals may not display C1 characters.");
3108 mvprintw(LINES - 2, 0,
3109 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3112 mvprintw(LINES - 1, 0,
3113 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3114 attrs_to_cycle[at_code].name,
3117 mvprintw(LINES - 1, 0,
3118 "v/V cycles through video attributes (%s).",
3119 attrs_to_cycle[at_code].name);
3122 } while (!isQuit(c = Getchar()));
3129 #if USE_WIDEC_SUPPORT
3131 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3133 int count = getcchar(src, NULL, NULL, NULL, 0);
3140 if ((wch = typeMalloc(wchar_t, count + 1)) != 0) {
3141 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
3142 attr |= (ignore_attr & A_ALTCHARSET);
3143 setcchar(dst, wch, attr, pair, 0);
3152 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3156 int last = first + 31;
3160 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3163 for (code = first; code <= last; code++) {
3164 int row = 2 + ((code - first) % 16);
3165 int col = ((code - first) / 16) * COLS / 2;
3171 memset(&codes, 0, sizeof(codes));
3173 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3174 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3175 setcchar(&temp, codes, attr, pair, 0);
3178 * Give non-spacing characters something to combine with. If we
3179 * don't, they'll bunch up in a heap on the space after the ":".
3180 * Mark them with reverse-video to make them simpler to find on
3183 if (wcwidth(code) == 0)
3184 addch(space | A_REVERSE);
3186 * This could use add_wch(), but is done for comparison with the
3187 * normal 'f' test (and to make a test-case for echo_wchar()).
3188 * The screen will flicker because the erase() at the top of the
3189 * function is met by the builtin refresh() in echo_wchar().
3193 * The repeat-count may make text wrap - avoid that.
3195 getyx(stdscr, y, x);
3196 if (x >= col + (COLS / 2) - 2)
3198 } while (--count > 0);
3203 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3205 const int height = 16;
3206 int row = 2 + (n % height);
3207 int col = (n / height) * COLS / 2;
3209 mvprintw(row, col, "%*s : ", COLS / 4, name);
3210 while (repeat-- >= 0) {
3216 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3219 show_wacs_chars(int repeat, attr_t attr, short pair)
3220 /* display the wide-ACS character set */
3226 /*#define BOTH2(name) #name, &(name) */
3227 #define BOTH2(name) #name, MERGE_ATTR(name)
3231 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3235 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3236 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3237 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3238 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3240 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3241 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3242 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3243 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3245 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3246 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3248 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3249 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3250 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3251 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3253 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3254 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3255 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3256 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3257 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3258 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3259 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3260 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3261 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3263 #ifdef CURSES_WACS_ARRAY
3264 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3265 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3266 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3268 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3269 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3270 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3271 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3272 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3273 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3279 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3282 show_wbox_chars(int repeat, attr_t attr, short pair)
3289 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3293 attr_set(attr, pair, 0);
3294 box_set(stdscr, 0, 0);
3295 attr_set(A_NORMAL, 0, 0);
3297 mvhline_set(LINES / 2, 0, MERGE_ATTR(WACS_HLINE), COLS);
3298 mvvline_set(0, COLS / 2, MERGE_ATTR(WACS_VLINE), LINES);
3299 mvadd_wch(0, COLS / 2, MERGE_ATTR(WACS_TTEE));
3300 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(WACS_PLUS));
3301 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(WACS_BTEE));
3302 mvadd_wch(LINES / 2, 0, MERGE_ATTR(WACS_LTEE));
3303 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(WACS_RTEE));
3311 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3313 const int height = 16;
3314 int row = 2 + (n % height);
3315 int col = (n / height) * COLS / 2;
3318 mvprintw(row, col, "%*s : ", COLS / 4, name);
3319 attr_set(attr, pair, 0);
3320 addstr(strcpy(temp, code));
3321 attr_set(A_NORMAL, 0, 0);
3325 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3328 show_utf8_chars(int repeat, attr_t attr, short pair)
3335 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3339 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3340 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3341 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3342 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3344 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3345 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3346 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3347 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3349 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3350 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3352 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3353 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3354 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3355 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3357 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3358 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3359 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3360 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3361 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3362 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3363 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3364 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3365 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3366 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3367 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3368 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3370 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3371 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3372 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3373 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3374 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3375 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3380 /* display the wide-ACS character set */
3382 wide_acs_display(void)
3388 chtype attr = A_NORMAL;
3389 int fg = COLOR_BLACK;
3390 int bg = COLOR_BLACK;
3391 unsigned at_code = 0;
3393 void (*last_show_wacs) (int, attr_t, short) = 0;
3401 ToggleAcs(last_show_wacs, show_wacs_chars);
3404 ToggleAcs(last_show_wacs, show_wbox_chars);
3407 ToggleAcs(last_show_wacs, show_utf8_chars);
3410 if (c < 256 && isdigit(c)) {
3413 } else if (c == '+') {
3416 } else if (c == '-' && digit > 0) {
3419 } else if (c == '>' && repeat < (COLS / 4)) {
3421 } else if (c == '<' && repeat > 1) {
3423 } else if (c == '_') {
3424 space = (space == ' ') ? '_' : ' ';
3426 } else if (cycle_attr(c, &at_code, &attr)
3427 || cycle_colors(c, &fg, &bg, &pair)) {
3428 if (last_show_wacs != 0)
3436 if (last_show_wacs != 0)
3437 last_show_wacs(repeat, attr, pair);
3439 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3441 mvprintw(LINES - 3, 0,
3442 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3444 mvprintw(LINES - 2, 0,
3445 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3446 attrs_to_cycle[at_code].name,
3449 mvprintw(LINES - 2, 0,
3450 "v/V cycles through video attributes (%s).",
3451 attrs_to_cycle[at_code].name);
3454 } while (!isQuit(c = Getchar()));
3464 * Graphic-rendition test (adapted from vttest)
3467 test_sgr_attributes(void)
3471 for (pass = 0; pass < 2; pass++) {
3472 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3474 /* Use non-default colors if possible to exercise bce a little */
3476 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3477 normal |= COLOR_PAIR(1);
3481 mvprintw(1, 20, "Graphic rendition test pattern:");
3483 mvprintw(4, 1, "vanilla");
3485 #define set_sgr(mask) bkgdset((normal^(mask)));
3487 mvprintw(4, 40, "bold");
3489 set_sgr(A_UNDERLINE);
3490 mvprintw(6, 6, "underline");
3492 set_sgr(A_BOLD | A_UNDERLINE);
3493 mvprintw(6, 45, "bold underline");
3496 mvprintw(8, 1, "blink");
3498 set_sgr(A_BLINK | A_BOLD);
3499 mvprintw(8, 40, "bold blink");
3501 set_sgr(A_UNDERLINE | A_BLINK);
3502 mvprintw(10, 6, "underline blink");
3504 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3505 mvprintw(10, 45, "bold underline blink");
3508 mvprintw(12, 1, "negative");
3510 set_sgr(A_BOLD | A_REVERSE);
3511 mvprintw(12, 40, "bold negative");
3513 set_sgr(A_UNDERLINE | A_REVERSE);
3514 mvprintw(14, 6, "underline negative");
3516 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3517 mvprintw(14, 45, "bold underline negative");
3519 set_sgr(A_BLINK | A_REVERSE);
3520 mvprintw(16, 1, "blink negative");
3522 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3523 mvprintw(16, 40, "bold blink negative");
3525 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3526 mvprintw(18, 6, "underline blink negative");
3528 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3529 mvprintw(18, 45, "bold underline blink negative");
3532 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3538 bkgdset(A_NORMAL | BLANK);
3543 /****************************************************************************
3545 * Windows and scrolling tester.
3547 ****************************************************************************/
3549 #define BOTLINES 4 /* number of line stolen from screen bottom */
3555 #define FRAME struct frame
3564 #if defined(NCURSES_VERSION)
3565 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3566 #define is_keypad(win) (win)->_use_keypad
3567 #define is_scrollok(win) (win)->_scroll
3568 #elif !defined(is_keypad)
3569 #define is_keypad(win) FALSE
3570 #define is_scrollok(win) FALSE
3573 #define is_keypad(win) FALSE
3574 #define is_scrollok(win) FALSE
3577 /* We need to know if these flags are actually set, so don't look in FRAME.
3578 * These names are known to work with SVr4 curses as well as ncurses. The
3579 * _use_keypad name does not work with Solaris 8.
3582 HaveKeypad(FRAME * curp)
3584 WINDOW *win = (curp ? curp->wind : stdscr);
3586 return is_keypad(win);
3590 HaveScroll(FRAME * curp)
3592 WINDOW *win = (curp ? curp->wind : stdscr);
3594 return is_scrollok(win);
3598 newwin_legend(FRAME * curp)
3600 static const struct {
3605 "^C = create window", 0
3608 "^N = next window", 0
3611 "^P = previous window", 0
3614 "^F = scroll forward", 0
3617 "^B = scroll backward", 0
3620 "^K = keypad(%s)", 1
3623 "^S = scrollok(%s)", 2
3626 "^W = save window to file", 0
3629 "^R = restore window", 0
3642 bool do_keypad = HaveKeypad(curp);
3643 bool do_scroll = HaveScroll(curp);
3647 for (n = 0; n < SIZEOF(legend); n++) {
3648 switch (legend[n].code) {
3650 strcpy(buf, legend[n].msg);
3653 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3656 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3659 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3662 x = getcurx(stdscr);
3663 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3670 transient(FRAME * curp, NCURSES_CONST char *msg)
3672 newwin_legend(curp);
3674 mvaddstr(LINES - 1, 0, msg);
3680 printw("%s characters are echoed, window should %sscroll.",
3681 HaveKeypad(curp) ? "Non-arrow" : "All other",
3682 HaveScroll(curp) ? "" : "not ");
3687 newwin_report(FRAME * curp)
3688 /* report on the cursor's current position, then restore it */
3690 WINDOW *win = (curp != 0) ? curp->wind : stdscr;
3694 transient(curp, (char *) 0);
3696 move(LINES - 1, COLS - 17);
3697 printw("Y = %2d X = %2d", y, x);
3705 selectcell(int uli, int ulj, int lri, int lrj)
3706 /* arrows keys move cursor, return location at current on non-arrow key */
3708 static pair res; /* result cell */
3709 int si = lri - uli + 1; /* depth of the select area */
3710 int sj = lrj - ulj + 1; /* width of the select area */
3711 int i = 0, j = 0; /* offsets into the select area */
3716 move(uli + i, ulj + j);
3717 newwin_report((FRAME *) 0);
3719 switch (Getchar()) {
3733 return ((pair *) 0);
3734 #ifdef NCURSES_MOUSE_VERSION
3740 if (event.y > uli && event.x > ulj) {
3761 outerbox(pair ul, pair lr, bool onoff)
3762 /* draw or erase a box *outside* the given pair of corners */
3764 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3765 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3766 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3767 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3768 move(ul.y - 1, ul.x);
3769 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3770 move(ul.y, ul.x - 1);
3771 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3772 move(lr.y + 1, ul.x);
3773 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3774 move(ul.y, lr.x + 1);
3775 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3780 /* Ask user for a window definition */
3787 addstr("Use arrows to move cursor, anything else to mark corner 1");
3789 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3790 return ((WINDOW *) 0);
3791 memcpy(&ul, tmp, sizeof(pair));
3792 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3795 addstr("Use arrows to move cursor, anything else