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.324 2008/08/04 16:27:54 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);
215 x = (int) strlen(buffer);
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 = (int) strlen(buffer) + 1; j > x; --j) {
258 buffer[j] = buffer[j - 1];
260 buffer[x++] = (char) ch;
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);
346 x = (int) wcslen(buffer);
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 = (int) wcslen(buffer) + 1; j > x; --j) {
426 buffer[j] = buffer[j - 1];
428 buffer[x++] = (wchar_t) ch;
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 + (int) (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;
638 assert(level < COLS);
642 winstack = typeMalloc(WINSTACK, len_winstack);
643 } else if (need >= len_winstack) {
645 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
647 winstack[level].text = txt_win;
648 winstack[level].frame = box_win;
651 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
655 /* this chunk is now done in resize_term() */
662 #define slk_repaint() /* nothing */
666 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
667 * Resize both and paint the box in the parent.
670 resize_boxes(unsigned level, WINDOW *win)
674 int high = LINES - base;
678 wnoutrefresh(stdscr);
682 for (n = 0; n < level; ++n) {
683 wresize(winstack[n].frame, high, wide);
684 wresize(winstack[n].text, high - 2, wide - 2);
687 werase(winstack[n].text);
688 box(winstack[n].frame, 0, 0);
689 wnoutrefresh(winstack[n].frame);
690 wprintw(winstack[n].text,
692 getmaxy(winstack[n].text),
693 getmaxx(winstack[n].text));
694 wnoutrefresh(winstack[n].text);
695 if (winstack[n].text == win)
701 #define forget_boxes() /* nothing */
702 #define remember_boxes(level,text,frame) /* nothing */
706 wgetch_test(unsigned level, WINDOW *win, int delay)
709 int first_y, first_x;
713 bool blocking = (delay < 0);
715 memset(flags, FALSE, sizeof(flags));
716 flags[UChar('k')] = (win == stdscr);
718 setup_getch(win, flags);
719 wtimeout(win, delay);
720 getyx(win, first_y, first_x);
722 wgetch_help(win, flags);
723 wsetscrreg(win, first_y, getmaxy(win) - 1);
727 while ((c = wGetchar(win)) == ERR) {
730 (void) wprintw(win, "%05d: input error", incount);
733 (void) wprintw(win, "%05d: input timed out", incount);
735 wgetch_wrap(win, first_y);
737 if (c == ERR && blocking) {
739 wgetch_wrap(win, first_y);
740 } else if (isQuit(c)) {
742 } else if (c == 'e') {
743 flags[UChar('e')] = !flags[UChar('e')];
744 setup_getch(win, flags);
745 wgetch_help(win, flags);
746 } else if (c == 'g') {
747 waddstr(win, "getstr test: ");
749 wgetnstr(win, buf, sizeof(buf) - 1);
751 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
753 wgetch_wrap(win, first_y);
754 } else if (c == 'k') {
755 flags[UChar('k')] = !flags[UChar('k')];
756 setup_getch(win, flags);
757 wgetch_help(win, flags);
758 } else if (c == 'm') {
759 flags[UChar('m')] = !flags[UChar('m')];
760 setup_getch(win, flags);
761 wgetch_help(win, flags);
762 } else if (c == 's') {
764 } else if (c == 'w') {
765 int high = getmaxy(win) - 1 - first_y + 1;
766 int wide = getmaxx(win) - first_x;
768 int new_y = first_y + getbegy(win);
769 int new_x = first_x + getbegx(win);
771 getyx(win, old_y, old_x);
772 if (high > 2 && wide > 2) {
773 WINDOW *wb = newwin(high, wide, new_y, new_x);
774 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
779 remember_boxes(level, wi, wb);
780 wgetch_test(level + 1, wi, delay);
784 wgetch_help(win, flags);
785 wmove(win, old_y, old_x);
791 } else if (c == 'z') {
792 kill(getpid(), SIGTSTP);
795 wprintw(win, "Key pressed: %04o ", c);
796 #ifdef NCURSES_MOUSE_VERSION
797 if (c == KEY_MOUSE) {
802 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
804 move(event.y, event.x);
808 #endif /* NCURSES_MOUSE_VERSION */
810 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
811 if (c == KEY_RESIZE) {
812 resize_boxes(level, win);
815 (void) waddstr(win, keyname(c));
816 } else if (c > 0x80) {
817 unsigned c2 = (unsigned) (c & 0x7f);
819 (void) wprintw(win, "M-%c", UChar(c2));
821 (void) wprintw(win, "M-%s", unctrl(c2));
822 waddstr(win, " (high-half character)");
825 (void) wprintw(win, "%c (ASCII printable character)", c);
827 (void) wprintw(win, "%s (ASCII control character)",
830 wgetch_wrap(win, first_y);
838 begin_getch_test(void)
845 #ifdef NCURSES_MOUSE_VERSION
846 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
849 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
851 getnstr(buf, sizeof(buf) - 1);
855 if (isdigit(UChar(buf[0]))) {
856 delay = atoi(buf) * 100;
866 finish_getch_test(void)
868 #ifdef NCURSES_MOUSE_VERSION
869 mousemask(0, (mmask_t *) 0);
880 int delay = begin_getch_test();
883 wgetch_test(0, stdscr, delay);
888 #if USE_WIDEC_SUPPORT
890 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
891 * Resize both and paint the box in the parent.
893 #if defined(KEY_RESIZE) && HAVE_WRESIZE
895 resize_wide_boxes(unsigned level, WINDOW *win)
899 int high = LINES - base;
903 wnoutrefresh(stdscr);
907 for (n = 0; n < level; ++n) {
908 wresize(winstack[n].frame, high, wide);
909 wresize(winstack[n].text, high - 2, wide - 2);
912 werase(winstack[n].text);
913 box_set(winstack[n].frame, 0, 0);
914 wnoutrefresh(winstack[n].frame);
915 wprintw(winstack[n].text,
917 getmaxy(winstack[n].text),
918 getmaxx(winstack[n].text));
919 wnoutrefresh(winstack[n].text);
920 if (winstack[n].text == win)
925 #endif /* KEY_RESIZE */
928 wcstos(const wchar_t *src)
933 const wchar_t *tmp = src;
935 memset(&state, 0, sizeof(state));
936 if ((need = (int) wcsrtombs(0, &tmp, 0, &state)) > 0) {
937 unsigned have = (unsigned) need;
938 if ((result = typeCalloc(char, have + 1)) != 0) {
940 if (wcsrtombs(result, &tmp, have, &state) != have) {
950 wget_wch_test(unsigned level, WINDOW *win, int delay)
952 wchar_t wchar_buf[BUFSIZ];
953 wint_t wint_buf[BUFSIZ];
954 int first_y, first_x;
958 bool blocking = (delay < 0);
962 memset(flags, FALSE, sizeof(flags));
963 flags[UChar('k')] = (win == stdscr);
965 setup_getch(win, flags);
966 wtimeout(win, delay);
967 getyx(win, first_y, first_x);
969 wgetch_help(win, flags);
970 wsetscrreg(win, first_y, getmaxy(win) - 1);
974 while ((code = wGet_wchar(win, &c)) == ERR) {
977 (void) wprintw(win, "%05d: input error", incount);
980 (void) wprintw(win, "%05d: input timed out", incount);
982 wgetch_wrap(win, first_y);
984 if (code == ERR && blocking) {
986 wgetch_wrap(win, first_y);
987 } else if (isQuit((int) c)) {
989 } else if (c == 'e') {
990 flags[UChar('e')] = !flags[UChar('e')];
991 setup_getch(win, flags);
992 wgetch_help(win, flags);
993 } else if (c == 'g') {
994 waddstr(win, "getstr test: ");
996 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
999 wprintw(win, "wgetn_wstr returns an error.");
1002 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1005 if ((temp = wcstos(wchar_buf)) != 0) {
1006 wprintw(win, "I saw %d characters:\n\t`%s'.",
1007 (int) wcslen(wchar_buf), temp);
1010 wprintw(win, "I saw %d characters (cannot convert).",
1011 (int) wcslen(wchar_buf));
1015 wgetch_wrap(win, first_y);
1016 } else if (c == 'k') {
1017 flags[UChar('k')] = !flags[UChar('k')];
1018 setup_getch(win, flags);
1019 wgetch_help(win, flags);
1020 } else if (c == 'm') {
1021 flags[UChar('m')] = !flags[UChar('m')];
1022 setup_getch(win, flags);
1023 wgetch_help(win, flags);
1024 } else if (c == 's') {
1026 } else if (c == 'w') {
1027 int high = getmaxy(win) - 1 - first_y + 1;
1028 int wide = getmaxx(win) - first_x;
1030 int new_y = first_y + getbegy(win);
1031 int new_x = first_x + getbegx(win);
1033 getyx(win, old_y, old_x);
1034 if (high > 2 && wide > 2) {
1035 WINDOW *wb = newwin(high, wide, new_y, new_x);
1036 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1041 remember_boxes(level, wi, wb);
1042 wget_wch_test(level + 1, wi, delay);
1046 wgetch_help(win, flags);
1047 wmove(win, old_y, old_x);
1052 } else if (c == 'z') {
1053 kill(getpid(), SIGTSTP);
1056 wprintw(win, "Key pressed: %04o ", (int) c);
1057 #ifdef NCURSES_MOUSE_VERSION
1058 if (c == KEY_MOUSE) {
1062 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1064 move(event.y, event.x);
1068 #endif /* NCURSES_MOUSE_VERSION */
1069 if (code == KEY_CODE_YES) {
1070 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1071 if (c == KEY_RESIZE) {
1072 resize_wide_boxes(level, win);
1075 (void) waddstr(win, key_name((wchar_t) c));
1077 if (c < 256 && iscntrl(c)) {
1078 (void) wprintw(win, "%s (control character)", unctrl(c));
1080 wchar_t c2 = (wchar_t) c;
1081 waddnwstr(win, &c2, 1);
1082 (void) wprintw(win, " = %#x (printable character)", c);
1085 wgetch_wrap(win, first_y);
1095 int delay = begin_getch_test();
1098 wget_wch_test(0, stdscr, delay);
1100 finish_getch_test();
1104 /****************************************************************************
1106 * Character attributes test
1108 ****************************************************************************/
1110 #if HAVE_SETUPTERM || HAVE_TGETENT
1111 #define get_ncv() TIGETNUM("ncv","NC")
1112 #define get_xmc() TIGETNUM("xmc","sg")
1114 #define get_ncv() -1
1115 #define get_xmc() -1
1122 static int first = TRUE;
1123 static chtype result = 0;
1129 char *area_pointer = parsed;
1131 tgetent(buffer, getenv("TERM"));
1134 if (TIGETSTR("smso", "so"))
1135 result |= A_STANDOUT;
1136 if (TIGETSTR("smul", "us"))
1137 result |= A_UNDERLINE;
1138 if (TIGETSTR("rev", "mr"))
1139 result |= A_REVERSE;
1140 if (TIGETSTR("blink", "mb"))
1142 if (TIGETSTR("dim", "mh"))
1144 if (TIGETSTR("bold", "md"))
1146 if (TIGETSTR("smacs", "ac"))
1147 result |= A_ALTCHARSET;
1153 #define termattrs() my_termattrs()
1156 #define MAX_ATTRSTRING 31
1157 #define LEN_ATTRSTRING 26
1159 static char attr_test_string[MAX_ATTRSTRING + 1];
1162 attr_legend(WINDOW *helpwin)
1167 mvwprintw(helpwin, row++, col,
1169 mvwprintw(helpwin, row++, col,
1172 mvwprintw(helpwin, row++, col,
1173 "Modify the test strings:");
1174 mvwprintw(helpwin, row++, col,
1175 " A digit sets gaps on each side of displayed attributes");
1176 mvwprintw(helpwin, row++, col,
1177 " </> shifts the text left/right. ");
1179 mvwprintw(helpwin, row++, col,
1182 mvwprintw(helpwin, row++, col,
1183 " f/F/b/F toggle foreground/background background color");
1184 mvwprintw(helpwin, row++, col,
1185 " t/T toggle text/background color attribute");
1187 mvwprintw(helpwin, row++, col,
1188 " a/A toggle ACS (alternate character set) mapping");
1189 mvwprintw(helpwin, row++, col,
1190 " v/V toggle video attribute to combine with each line");
1194 show_color_attr(int fg, int bg, int tx)
1197 printw(" Colors (fg %d, bg %d", fg, bg);
1199 printw(", text %d", tx);
1205 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1212 *fg = (short) (*fg + 1);
1215 *fg = (short) (*fg - 1);
1218 *bg = (short) (*bg + 1);
1221 *bg = (short) (*bg - 1);
1224 *tx = (short) (*tx + 1);
1227 *tx = (short) (*tx - 1);
1235 *fg = (short) min_colors;
1236 if (*fg < min_colors)
1237 *fg = (short) (COLORS - 1);
1239 *bg = (short) min_colors;
1240 if (*bg < min_colors)
1241 *bg = (short) (COLORS - 1);
1245 *tx = (short) (COLORS - 1);
1254 adjust_attr_string(int adjust)
1256 int first = ((int) UChar(attr_test_string[0])) + adjust;
1257 int last = first + LEN_ATTRSTRING;
1259 if (first >= ' ' && last <= '~') { /* 32..126 */
1261 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1262 attr_test_string[j] = (char) k;
1263 if (((k + 1 - first) % 5) == 0) {
1264 if (++j >= MAX_ATTRSTRING)
1266 attr_test_string[j] = ' ';
1269 while (j < MAX_ATTRSTRING)
1270 attr_test_string[j++] = ' ';
1271 attr_test_string[j] = '\0';
1278 init_attr_string(void)
1280 attr_test_string[0] = 'a';
1281 adjust_attr_string(0);
1285 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1287 int ncv = get_ncv();
1288 chtype test = attr & (chtype) (~A_ALTCHARSET);
1291 mvprintw(row, 5, "-->");
1292 mvprintw(row, 8, "%s mode:", name);
1293 mvprintw(row, 24, "|");
1295 printw("%*s", skip, " ");
1297 * Just for testing, write text using the alternate character set one
1298 * character at a time (to pass its rendition directly), and use the
1299 * string operation for the other attributes.
1301 if (attr & A_ALTCHARSET) {
1305 for (s = attr_test_string; *s != '\0'; ++s) {
1311 addstr(attr_test_string);
1315 printw("%*s", skip, " ");
1317 if (test != A_NORMAL) {
1318 if (!(termattrs() & test)) {
1321 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1322 static const chtype table[] =
1338 for (n = 0; n < SIZEOF(table); n++) {
1339 if ((table[n] & attr) != 0
1340 && ((1 << n) & ncv) != 0) {
1348 if ((termattrs() & test) != test)
1355 static const struct {
1357 NCURSES_CONST char * name;
1358 } attrs_to_test[] = {
1359 { A_STANDOUT, "STANDOUT" },
1360 { A_REVERSE, "REVERSE" },
1362 { A_UNDERLINE, "UNDERLINE" },
1364 { A_BLINK, "BLINK" },
1365 { A_PROTECT, "PROTECT" },
1367 { A_INVIS, "INVISIBLE" },
1369 { A_NORMAL, "NORMAL" },
1374 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1384 if (ch < 256 && isdigit(ch)) {
1392 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1394 attr_legend(helpwin);
1407 *kc = SIZEOF(attrs_to_test) - 1;
1413 if (*kc >= SIZEOF(attrs_to_test))
1417 adjust_attr_string(-1);
1420 adjust_attr_string(1);
1426 error = cycle_color_attr(ch, fg, bg, tx);
1436 /* test text attributes */
1439 int skip = get_xmc();
1440 short fg = COLOR_BLACK; /* color pair 0 is special */
1441 short bg = COLOR_BLACK;
1449 n = skip; /* make it easy */
1450 k = SIZEOF(attrs_to_test) - 1;
1455 chtype normal = A_NORMAL | BLANK;
1456 chtype extras = (chtype) ac;
1459 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1462 if (init_pair(pair, fg, bg) == ERR) {
1465 normal |= COLOR_PAIR(pair);
1470 if (init_pair(pair, tx, bg) == ERR) {
1473 extras |= COLOR_PAIR(pair);
1482 mvaddstr(0, 20, "Character attribute test display");
1484 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1485 bool arrow = (j == k);
1486 row = show_attr(row, n, arrow,
1488 attrs_to_test[j].attr |
1489 attrs_to_test[k].attr,
1490 attrs_to_test[j].name);
1494 "This terminal does %shave the magic-cookie glitch",
1495 get_xmc() > -1 ? "" : "not ");
1496 mvprintw(row + 1, 8, "Enter '?' for help.");
1497 show_color_attr(fg, bg, tx);
1498 printw(" ACS (%d)", ac != 0);
1501 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1503 bkgdset(A_NORMAL | BLANK);
1508 #if USE_WIDEC_SUPPORT
1509 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1512 wide_adjust_attr_string(int adjust)
1514 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1515 int last = first + LEN_ATTRSTRING;
1517 if (first >= ' ' && last <= '~') { /* 32..126 */
1519 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1520 wide_attr_test_string[j] = k;
1521 if (((k + 1 - first) % 5) == 0) {
1522 if (++j >= MAX_ATTRSTRING)
1524 wide_attr_test_string[j] = ' ';
1527 while (j < MAX_ATTRSTRING)
1528 wide_attr_test_string[j++] = ' ';
1529 wide_attr_test_string[j] = '\0';
1536 wide_init_attr_string(void)
1538 wide_attr_test_string[0] = 'a';
1539 wide_adjust_attr_string(0);
1543 set_wide_background(short pair)
1550 setcchar(&normal, blank, A_NORMAL, pair, 0);
1556 get_wide_background(void)
1558 attr_t result = A_NORMAL;
1564 if (getbkgrnd(&ch) != ERR) {
1565 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1573 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1575 int ncv = get_ncv();
1576 chtype test = attr & ~WA_ALTCHARSET;
1579 mvprintw(row, 5, "-->");
1580 mvprintw(row, 8, "%s mode:", name);
1581 mvprintw(row, 24, "|");
1583 printw("%*s", skip, " ");
1586 * Just for testing, write text using the alternate character set one
1587 * character at a time (to pass its rendition directly), and use the
1588 * string operation for the other attributes.
1590 if (attr & WA_ALTCHARSET) {
1594 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1598 setcchar(&ch, fill, attr, pair, 0);
1605 attr_get(&old_attr, &old_pair, 0);
1606 attr_set(attr, pair, 0);
1607 addwstr(wide_attr_test_string);
1608 attr_set(old_attr, old_pair, 0);
1611 printw("%*s", skip, " ");
1613 if (test != A_NORMAL) {
1614 if (!(term_attrs() & test)) {
1617 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1618 static const attr_t table[] =
1632 for (n = 0; n < SIZEOF(table); n++) {
1633 if ((table[n] & attr) != 0
1634 && ((1 << n) & ncv) != 0) {
1642 if ((term_attrs() & test) != test)
1650 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1660 if (ch < 256 && isdigit(ch)) {
1668 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1669 box_set(helpwin, 0, 0);
1670 attr_legend(helpwin);
1683 *kc = SIZEOF(attrs_to_test) - 1;
1689 if (*kc >= SIZEOF(attrs_to_test))
1693 wide_adjust_attr_string(-1);
1696 wide_adjust_attr_string(1);
1702 error = cycle_color_attr(ch, fg, bg, tx);
1711 wide_attr_test(void)
1712 /* test text attributes using wide-character calls */
1715 int skip = get_xmc();
1716 short fg = COLOR_BLACK; /* color pair 0 is special */
1717 short bg = COLOR_BLACK;
1725 n = skip; /* make it easy */
1726 k = SIZEOF(attrs_to_test) - 1;
1727 wide_init_attr_string();
1735 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1738 if (init_pair(pair, fg, bg) == ERR) {
1745 if (init_pair(extras, tx, bg) == ERR) {
1750 set_wide_background(pair);
1753 box_set(stdscr, 0, 0);
1754 mvaddstr(0, 20, "Character attribute test display");
1756 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1757 row = wide_show_attr(row, n, j == k,
1759 attrs_to_test[j].attr |
1760 attrs_to_test[k].attr,
1762 attrs_to_test[j].name);
1766 "This terminal does %shave the magic-cookie glitch",
1767 get_xmc() > -1 ? "" : "not ");
1768 mvprintw(row + 1, 8, "Enter '?' for help.");
1769 show_color_attr(fg, bg, tx);
1770 printw(" ACS (%d)", ac != 0);
1773 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1775 set_wide_background(0);
1781 /****************************************************************************
1783 * Color support tests
1785 ****************************************************************************/
1787 static NCURSES_CONST char *the_color_names[] =
1808 show_color_name(int y, int x, int color, bool wide)
1810 if (move(y, x) != ERR) {
1815 sprintf(temp, "%02d", color);
1817 } else if (color >= 8) {
1818 sprintf(temp, "[%02d]", color);
1820 strcpy(temp, the_color_names[color]);
1822 printw("%-*.*s", width, width, temp);
1827 color_legend(WINDOW *helpwin, bool wide)
1832 mvwprintw(helpwin, row++, col,
1835 mvwprintw(helpwin, row++, col,
1836 "Use up/down arrow to scroll through the display if it is");
1837 mvwprintw(helpwin, row++, col,
1838 "longer than one screen. Control/N and Control/P can be used");
1839 mvwprintw(helpwin, row++, col,
1840 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1841 mvwprintw(helpwin, row++, col,
1842 "full screen; control/B and control/F can be used here.");
1844 mvwprintw(helpwin, row++, col,
1846 mvwprintw(helpwin, row++, col,
1847 " a/A toggle altcharset off/on");
1848 mvwprintw(helpwin, row++, col,
1849 " b/B toggle bold off/on");
1850 mvwprintw(helpwin, row++, col,
1851 " n/N toggle text/number on/off");
1852 mvwprintw(helpwin, row++, col,
1853 " w/W toggle width between 8/16 colors");
1854 #if USE_WIDEC_SUPPORT
1856 mvwprintw(helpwin, row++, col,
1857 "Wide characters:");
1858 mvwprintw(helpwin, row++, col,
1859 " x/X toggle text between ASCII and wide-character");
1866 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1868 /* generate a color test pattern */
1875 int grid_top = top + 3;
1876 int page_size = (LINES - grid_top);
1877 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1883 bool opt_acsc = FALSE;
1884 bool opt_bold = FALSE;
1885 bool opt_wide = FALSE;
1886 bool opt_nums = FALSE;
1889 if (pairs_max > COLOR_PAIRS)
1890 pairs_max = COLOR_PAIRS;
1895 /* this assumes an 80-column line */
1899 per_row = (COLORS > 8) ? 16 : 8;
1906 row_limit = (pairs_max + per_row - 1) / per_row;
1909 (void) printw("There are %d color pairs and %d colors\n",
1913 (void) mvprintw(top + 1, 0,
1914 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1917 opt_bold ? "on" : "off");
1919 /* show color names/numbers across the top */
1920 for (i = 0; i < per_row; i++)
1921 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
1923 /* show a grid of colors, with color names/ numbers on the left */
1924 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
1925 int row = grid_top + (i / per_row) - base_row;
1926 int col = (i % per_row + 1) * width;
1929 if (row >= 0 && move(row, col) != ERR) {
1930 short fg = (short) (i % COLORS);
1931 short bg = (short) (i / COLORS);
1933 init_pair(pair, fg, bg);
1934 attron((attr_t) COLOR_PAIR(pair));
1936 attron((attr_t) A_ALTCHARSET);
1938 attron((attr_t) A_BOLD);
1941 sprintf(numbered, "{%02X}", i);
1944 printw("%-*.*s", width, width, hello);
1947 if ((i % per_row) == 0 && (i % COLORS) == 0) {
1948 show_color_name(row, 0, i / COLORS, opt_wide);
1956 switch (wGetchar(stdscr)) {
1979 set_color_test(opt_wide, FALSE);
1982 set_color_test(opt_wide, TRUE);
1986 if (base_row <= 0) {
1994 if (base_row + page_size >= row_limit) {
2003 if (base_row <= 0) {
2006 base_row -= (page_size - 1);
2014 if (base_row + page_size >= row_limit) {
2017 base_row += page_size - 1;
2018 if (base_row + page_size >= row_limit) {
2019 base_row = row_limit - page_size - 1;
2024 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2026 color_legend(helpwin, FALSE);
2041 #if USE_WIDEC_SUPPORT
2042 /* generate a color test pattern */
2044 wide_color_test(void)
2050 int grid_top = top + 3;
2051 int page_size = (LINES - grid_top);
2052 int pairs_max = COLOR_PAIRS;
2058 bool opt_acsc = FALSE;
2059 bool opt_bold = FALSE;
2060 bool opt_wide = FALSE;
2061 bool opt_nums = FALSE;
2062 bool opt_xchr = FALSE;
2069 /* this assumes an 80-column line */
2073 per_row = (COLORS > 8) ? 16 : 8;
2080 make_fullwidth_text(buffer, hello);
2084 make_narrow_text(buffer, hello);
2087 row_limit = (pairs_max + per_row - 1) / per_row;
2090 (void) printw("There are %d color pairs and %d colors\n",
2094 (void) mvprintw(top + 1, 0,
2095 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2098 opt_bold ? "on" : "off");
2100 /* show color names/numbers across the top */
2101 for (i = 0; i < per_row; i++)
2102 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
2104 /* show a grid of colors, with color names/ numbers on the left */
2105 for (i = (base_row * per_row); i < pairs_max; i++) {
2106 int row = grid_top + (i / per_row) - base_row;
2107 int col = (i % per_row + 1) * width;
2108 short pair = (short) i;
2110 if (row >= 0 && move(row, col) != ERR) {
2111 init_pair(pair, (short) (i % COLORS), (short) (i / COLORS));
2112 color_set(pair, NULL);
2114 attr_on((attr_t) A_ALTCHARSET, NULL);
2116 attr_on((attr_t) A_BOLD, NULL);
2119 sprintf(numbered, "{%02X}", i);
2121 make_fullwidth_text(buffer, numbered);
2123 make_narrow_text(buffer, numbered);
2126 addnwstr(buffer, width);
2127 attr_set(A_NORMAL, 0, NULL);
2129 if ((i % per_row) == 0 && (i % COLORS) == 0) {
2130 show_color_name(row, 0, i / COLORS, opt_wide);
2138 switch (c = wGetchar(stdscr)) {
2161 set_color_test(opt_wide, FALSE);
2164 set_color_test(opt_wide, TRUE);
2174 if (base_row <= 0) {
2182 if (base_row + page_size >= row_limit) {
2191 if (base_row <= 0) {
2194 base_row -= (page_size - 1);
2202 if (base_row + page_size >= row_limit) {
2205 base_row += page_size - 1;
2206 if (base_row + page_size >= row_limit) {
2207 base_row = row_limit - page_size - 1;
2212 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2214 color_legend(helpwin, TRUE);
2228 #endif /* USE_WIDEC_SUPPORT */
2231 change_color(short current, int field, int value, int usebase)
2233 short red, green, blue;
2235 color_content(current, &red, &green, &blue);
2239 red = (short) (usebase ? (red + value) : value);
2242 green = (short) (usebase ? (green + value) : value);
2245 blue = (short) (usebase ? (blue + value) : value);
2249 if (init_color(current, red, green, blue) == ERR)
2254 init_all_colors(void)
2258 for (c = 0; c < COLORS; ++c)
2261 all_colors[c].green,
2262 all_colors[c].blue);
2265 #define scaled_rgb(n) ((255 * (n)) / 1000)
2269 /* display the color test pattern, without trying to edit colors */
2273 int this_c = 0, value = 0, field = 0;
2276 int page_size = (LINES - 6);
2281 for (i = 0; i < max_colors; i++)
2282 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2284 mvprintw(LINES - 2, 0, "Number: %d", value);
2287 short red, green, blue;
2290 mvaddstr(0, 20, "Color RGB Value Editing");
2293 for (i = (short) top_color;
2294 (i - top_color < page_size)
2295 && (i < max_colors); i++) {
2298 sprintf(numeric, "[%d]", i);
2299 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2300 (i == current ? '>' : ' '),
2301 (i < (int) SIZEOF(the_color_names)
2302 ? the_color_names[i] : numeric));
2303 attrset(COLOR_PAIR(i));
2307 color_content((short) i, &red, &green, &blue);
2309 if (current == i && field == 0)
2311 printw("%04d", red);
2312 if (current == i && field == 0)
2315 if (current == i && field == 1)
2317 printw("%04d", green);
2318 if (current == i && field == 1)
2321 if (current == i && field == 2)
2323 printw("%04d", blue);
2324 if (current == i && field == 2)
2327 printw(" ( %3d %3d %3d )",
2333 mvaddstr(LINES - 3, 0,
2334 "Use up/down to select a color, left/right to change fields.");
2335 mvaddstr(LINES - 2, 0,
2336 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2338 move(2 + current - top_color, 0);
2342 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2349 current -= (page_size - 1);
2356 if (current < (max_colors - 1))
2357 current += (page_size - 1);
2364 current = (current == 0 ? (max_colors - 1) : current - 1);
2369 current = (current == (max_colors - 1) ? 0 : current + 1);
2373 field = (field == 2 ? 0 : field + 1);
2377 field = (field == 0 ? 2 : field - 1);
2390 value = value * 10 + (this_c - '0');
2394 change_color((short) current, field, value, 1);
2398 change_color((short) current, field, -value, 1);
2402 change_color((short) current, field, value, 0);
2407 P(" RGB Value Editing Help");
2409 P("You are in the RGB value editor. Use the arrow keys to select one of");
2410 P("the fields in one of the RGB triples of the current colors; the one");
2411 P("currently selected will be reverse-video highlighted.");
2413 P("To change a field, enter the digits of the new value; they are echoed");
2414 P("as entered. Finish by typing `='. The change will take effect instantly.");
2415 P("To increment or decrement a value, use the same procedure, but finish");
2416 P("with a `+' or `-'.");
2418 P("Press 'm' to invoke the top-level menu with the current color settings.");
2419 P("To quit, do ESC");
2441 if (current >= max_colors)
2442 current = max_colors - 1;
2443 if (current < top_color)
2444 top_color = current;
2445 if (current - top_color >= page_size)
2446 top_color = current - (page_size - 1);
2448 mvprintw(LINES - 1, 0, "Number: %d", value);
2456 * ncurses does not reset each color individually when calling endwin().
2463 /****************************************************************************
2465 * Soft-key label test
2467 ****************************************************************************/
2472 #define SLK_WORK (SLK_HELP + 3)
2477 static const char *table[] =
2479 "Available commands are:"
2481 ,"^L -- repaint this message and activate soft keys"
2482 ,"a/d -- activate/disable soft keys"
2483 ,"c -- set centered format for labels"
2484 ,"l -- set left-justified format for labels"
2485 ,"r -- set right-justified format for labels"
2486 ,"[12345678] -- set label; labels are numbered 1 through 8"
2487 ,"e -- erase stdscr (should not erase labels)"
2488 ,"s -- test scrolling of shortened screen"
2490 ,"F/B -- cycle through foreground/background colors"
2492 ,"ESC -- return to main menu"
2494 ,"Note: if activating the soft keys causes your terminal to scroll up"
2495 ,"one line, your terminal auto-scrolls when anything is written to the"
2496 ,"last screen position. The ncurses code does not yet handle this"
2502 for (j = 0; j < SIZEOF(table); ++j) {
2510 call_slk_color(short fg, short bg)
2512 init_pair(1, bg, fg);
2514 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2522 /* exercise the soft keys */
2528 short fg = COLOR_BLACK;
2529 short bg = COLOR_WHITE;
2535 call_slk_color(fg, bg);
2545 mvaddstr(0, 20, "Soft Key Exerciser");
2560 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2561 while ((c = Getchar()) != 'Q' && (c != ERR))
2589 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2591 if ((s = slk_label(c - '0')) != 0) {
2594 wGetstring(stdscr, buf, 8);
2595 slk_set((c - '0'), buf, fmt);
2607 fg = (short) ((fg + 1) % COLORS);
2608 call_slk_color(fg, bg);
2613 bg = (short) ((bg + 1) % COLORS);
2614 call_slk_color(fg, bg);
2618 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2620 wnoutrefresh(stdscr);
2627 } while (!isQuit(c = Getchar()));
2635 #if USE_WIDEC_SUPPORT
2639 /* exercise the soft keys */
2642 wchar_t buf[SLKLEN + 1];
2644 short fg = COLOR_BLACK;
2645 short bg = COLOR_WHITE;
2649 call_slk_color(fg, bg);
2656 attr_on(WA_BOLD, NULL);
2657 mvaddstr(0, 20, "Soft Key Exerciser");
2658 attr_off(WA_BOLD, NULL);
2672 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2673 while ((c = Getchar()) != 'Q' && (c != ERR))
2701 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2703 if ((s = slk_label(c - '0')) != 0) {
2704 char *temp = strdup(s);
2705 size_t used = strlen(temp);
2706 size_t want = SLKLEN;
2711 while (want > 0 && used != 0) {
2712 const char *base = s;
2713 memset(&state, 0, sizeof(state));
2714 test = mbsrtowcs(0, &base, 0, &state);
2715 if (test == (size_t) -1) {
2717 } else if (test > want) {
2720 memset(&state, 0, sizeof(state));
2721 mbsrtowcs(buf, &base, want, &state);
2727 wGet_wstring(stdscr, buf, SLKLEN);
2728 slk_wset((c - '0'), buf, fmt);
2739 fg = (short) ((fg + 1) % COLORS);
2740 call_slk_color(fg, bg);
2745 bg = (short) ((bg + 1) % COLORS);
2746 call_slk_color(fg, bg);
2749 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2751 wnoutrefresh(stdscr);
2757 } while (!isQuit(c = Getchar()));
2765 #endif /* SLK_INIT */
2767 /****************************************************************************
2769 * Alternate character-set stuff
2771 ****************************************************************************/
2776 } attrs_to_cycle[] = {
2777 { A_NORMAL, "normal" },
2779 { A_REVERSE, "reverse" },
2780 { A_UNDERLINE, "underline" },
2785 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2791 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2796 *at_code = SIZEOF(attrs_to_cycle) - 1;
2805 *attr = attrs_to_cycle[*at_code].attr;
2810 cycle_colors(int ch, int *fg, int *bg, short *pair)
2812 bool result = FALSE;
2822 if ((*fg += 1) >= COLORS)
2830 if ((*bg += 1) >= COLORS)
2838 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2841 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2850 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2851 * terminal to perform functions. The remaining codes can be graphic.
2854 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
2856 bool C1 = (first == 128);
2858 unsigned last = first + 31;
2863 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2864 C1 ? "C1" : "GR", first, last);
2868 for (code = first; code <= last; code++) {
2870 int row = 2 + ((int) (code - first) % 16);
2871 int col = ((int) (code - first) / 16) * COLS / 2;
2873 sprintf(tmp, "%3u (0x%x)", code, code);
2874 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2878 nodelay(stdscr, TRUE);
2879 echochar(code | attr | COLOR_PAIR(pair));
2881 /* (yes, this _is_ crude) */
2882 while ((reply = Getchar()) != ERR) {
2883 addch(UChar(reply));
2886 nodelay(stdscr, FALSE);
2888 } while (--count > 0);
2895 show_pc_chars(int repeat, attr_t attr, short pair)
2901 mvprintw(0, 20, "Display of PC Character Codes");
2905 for (code = 0; code < 16; ++code) {
2906 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
2908 for (code = 0; code < 256; code++) {
2910 int row = 3 + (int) (code / 16) + (code >= 128);
2911 int col = 8 + (int) (code % 16) * PC_COLS;
2912 if ((code % 16) == 0)
2913 mvprintw(row, 0, "0x%02x:", code);
2924 * Skip the ones that do not work.
2928 addch(code | A_ALTCHARSET | attr | COLOR_PAIR(pair));
2931 } while (--count > 0);
2936 show_box_chars(int repeat, attr_t attr, short pair)
2939 attr |= COLOR_PAIR(pair);
2943 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
2948 mvhline(LINES / 2, 0, ACS_HLINE | attr, COLS);
2949 mvvline(0, COLS / 2, ACS_VLINE | attr, LINES);
2950 mvaddch(0, COLS / 2, ACS_TTEE | attr);
2951 mvaddch(LINES / 2, COLS / 2, ACS_PLUS | attr);
2952 mvaddch(LINES - 1, COLS / 2, ACS_BTEE | attr);
2953 mvaddch(LINES / 2, 0, ACS_LTEE | attr);
2954 mvaddch(LINES / 2, COLS - 1, ACS_RTEE | attr);
2960 show_1_acs(int n, int repeat, const char *name, chtype code)
2962 const int height = 16;
2963 int row = 2 + (n % height);
2964 int col = (n / height) * COLS / 2;
2966 mvprintw(row, col, "%*s : ", COLS / 4, name);
2969 } while (--repeat > 0);
2974 show_acs_chars(int repeat, attr_t attr, short pair)
2975 /* display the ACS character set */
2979 #define BOTH(name) #name, (name | attr | COLOR_PAIR(pair))
2983 mvaddstr(0, 20, "Display of the ACS Character Set");
2987 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
2988 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
2989 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
2990 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
2992 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
2993 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
2994 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
2995 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
2997 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
2998 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3001 * HPUX's ACS definitions are broken here. Just give up.
3003 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3004 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3005 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3006 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3007 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3009 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3010 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3011 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3012 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3013 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3014 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3015 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3016 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3017 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3019 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3020 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3021 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3023 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3024 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3025 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3026 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3027 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3028 n = show_1_acs(n, repeat, BOTH(ACS_S9));
3036 char *term = getenv("TERM");
3037 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3040 chtype attr = A_NORMAL;
3043 int fg = COLOR_BLACK;
3044 int bg = COLOR_BLACK;
3045 unsigned at_code = 0;
3047 void (*last_show_acs) (int, attr_t, short) = 0;
3055 ToggleAcs(last_show_acs, show_acs_chars);
3059 ToggleAcs(last_show_acs, show_pc_chars);
3064 ToggleAcs(last_show_acs, show_box_chars);
3090 if (repeat < (COLS / 4))
3098 if (cycle_attr(c, &at_code, &attr)
3099 || cycle_colors(c, &fg, &bg, &pair)) {
3106 if (last_show_acs != 0)
3107 last_show_acs(repeat, attr, pair);
3109 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3111 mvprintw(LINES - 3, 0,
3112 "Note: ANSI terminals may not display C1 characters.");
3113 mvprintw(LINES - 2, 0,
3114 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3117 mvprintw(LINES - 1, 0,
3118 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3119 attrs_to_cycle[at_code].name,
3122 mvprintw(LINES - 1, 0,
3123 "v/V cycles through video attributes (%s).",
3124 attrs_to_cycle[at_code].name);
3127 } while (!isQuit(c = Getchar()));
3134 #if USE_WIDEC_SUPPORT
3136 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3138 int count = getcchar(src, NULL, NULL, NULL, 0);
3145 if ((wch = typeMalloc(wchar_t, (unsigned) count + 1)) != 0) {
3146 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
3147 attr |= (ignore_attr & A_ALTCHARSET);
3148 setcchar(dst, wch, attr, pair, 0);
3157 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3161 int last = first + 31;
3165 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3168 for (code = first; (int) code <= last; code++) {
3169 int row = 2 + ((code - first) % 16);
3170 int col = ((code - first) / 16) * COLS / 2;
3176 memset(&codes, 0, sizeof(codes));
3178 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3179 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3180 setcchar(&temp, codes, attr, pair, 0);
3183 * Give non-spacing characters something to combine with. If we
3184 * don't, they'll bunch up in a heap on the space after the ":".
3185 * Mark them with reverse-video to make them simpler to find on
3188 if (wcwidth(code) == 0)
3189 addch(space | A_REVERSE);
3191 * This could use add_wch(), but is done for comparison with the
3192 * normal 'f' test (and to make a test-case for echo_wchar()).
3193 * The screen will flicker because the erase() at the top of the
3194 * function is met by the builtin refresh() in echo_wchar().
3198 * The repeat-count may make text wrap - avoid that.
3200 getyx(stdscr, y, x);
3201 if (x >= col + (COLS / 2) - 2)
3203 } while (--count > 0);
3208 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3210 const int height = 16;
3211 int row = 2 + (n % height);
3212 int col = (n / height) * COLS / 2;
3214 mvprintw(row, col, "%*s : ", COLS / 4, name);
3215 while (repeat-- >= 0) {
3221 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3224 show_wacs_chars(int repeat, attr_t attr, short pair)
3225 /* display the wide-ACS character set */
3231 /*#define BOTH2(name) #name, &(name) */
3232 #define BOTH2(name) #name, MERGE_ATTR(name)
3236 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3240 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3241 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3242 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3243 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3245 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3246 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3247 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3248 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3250 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3251 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3253 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3254 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3255 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3256 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3258 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3259 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3260 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3261 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3262 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3263 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3264 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3265 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3266 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3268 #ifdef CURSES_WACS_ARRAY
3269 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3270 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3271 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3273 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3274 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3275 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3276 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3277 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3278 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3284 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3287 show_wbox_chars(int repeat, attr_t attr, short pair)
3294 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3298 attr_set(attr, pair, 0);
3299 box_set(stdscr, 0, 0);
3300 attr_set(A_NORMAL, 0, 0);
3302 mvhline_set(LINES / 2, 0, MERGE_ATTR(WACS_HLINE), COLS);
3303 mvvline_set(0, COLS / 2, MERGE_ATTR(WACS_VLINE), LINES);
3304 mvadd_wch(0, COLS / 2, MERGE_ATTR(WACS_TTEE));
3305 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(WACS_PLUS));
3306 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(WACS_BTEE));
3307 mvadd_wch(LINES / 2, 0, MERGE_ATTR(WACS_LTEE));
3308 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(WACS_RTEE));
3316 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3318 const int height = 16;
3319 int row = 2 + (n % height);
3320 int col = (n / height) * COLS / 2;
3323 mvprintw(row, col, "%*s : ", COLS / 4, name);
3324 attr_set(attr, pair, 0);
3325 addstr(strcpy(temp, code));
3326 attr_set(A_NORMAL, 0, 0);
3330 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3333 show_utf8_chars(int repeat, attr_t attr, short pair)
3340 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3344 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3345 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3346 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3347 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3349 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3350 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3351 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3352 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3354 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3355 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3357 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3358 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3359 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3360 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3362 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3363 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3364 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3365 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3366 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3367 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3368 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3369 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3370 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3371 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3372 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3373 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3375 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3376 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3377 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3378 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3379 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3380 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3385 /* display the wide-ACS character set */
3387 wide_acs_display(void)
3393 chtype attr = A_NORMAL;
3394 int fg = COLOR_BLACK;
3395 int bg = COLOR_BLACK;
3396 unsigned at_code = 0;
3398 void (*last_show_wacs) (int, attr_t, short) = 0;
3406 ToggleAcs(last_show_wacs, show_wacs_chars);
3409 ToggleAcs(last_show_wacs, show_wbox_chars);
3412 ToggleAcs(last_show_wacs, show_utf8_chars);
3415 if (c < 256 && isdigit(c)) {
3418 } else if (c == '+') {
3421 } else if (c == '-' && digit > 0) {
3424 } else if (c == '>' && repeat < (COLS / 4)) {
3426 } else if (c == '<' && repeat > 1) {
3428 } else if (c == '_') {
3429 space = (space == ' ') ? '_' : ' ';
3431 } else if (cycle_attr(c, &at_code, &attr)
3432 || cycle_colors(c, &fg, &bg, &pair)) {
3433 if (last_show_wacs != 0)
3441 if (last_show_wacs != 0)
3442 last_show_wacs(repeat, attr, pair);
3444 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3446 mvprintw(LINES - 3, 0,
3447 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3449 mvprintw(LINES - 2, 0,
3450 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3451 attrs_to_cycle[at_code].name,
3454 mvprintw(LINES - 2, 0,
3455 "v/V cycles through video attributes (%s).",
3456 attrs_to_cycle[at_code].name);
3459 } while (!isQuit(c = Getchar()));
3469 * Graphic-rendition test (adapted from vttest)
3472 test_sgr_attributes(void)
3476 for (pass = 0; pass < 2; pass++) {
3477 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3479 /* Use non-default colors if possible to exercise bce a little */
3481 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3482 normal |= COLOR_PAIR(1);
3486 mvprintw(1, 20, "Graphic rendition test pattern:");
3488 mvprintw(4, 1, "vanilla");
3490 #define set_sgr(mask) bkgdset((normal^(mask)));
3492 mvprintw(4, 40, "bold");
3494 set_sgr(A_UNDERLINE);
3495 mvprintw(6, 6, "underline");
3497 set_sgr(A_BOLD | A_UNDERLINE);
3498 mvprintw(6, 45, "bold underline");
3501 mvprintw(8, 1, "blink");
3503 set_sgr(A_BLINK | A_BOLD);
3504 mvprintw(8, 40, "bold blink");
3506 set_sgr(A_UNDERLINE | A_BLINK);
3507 mvprintw(10, 6, "underline blink");
3509 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3510 mvprintw(10, 45, "bold underline blink");
3513 mvprintw(12, 1, "negative");
3515 set_sgr(A_BOLD | A_REVERSE);
3516 mvprintw(12, 40, "bold negative");
3518 set_sgr(A_UNDERLINE | A_REVERSE);
3519 mvprintw(14, 6, "underline negative");
3521 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3522 mvprintw(14, 45, "bold underline negative");
3524 set_sgr(A_BLINK | A_REVERSE);
3525 mvprintw(16, 1, "blink negative");
3527 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3528 mvprintw(16, 40, "bold blink negative");
3530 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3531 mvprintw(18, 6, "underline blink negative");
3533 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3534 mvprintw(18, 45, "bold underline blink negative");
3537 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3543 bkgdset(A_NORMAL | BLANK);
3548 /****************************************************************************
3550 * Windows and scrolling tester.
3552 ****************************************************************************/
3554 #define BOTLINES 4 /* number of line stolen from screen bottom */
3560 #define FRAME struct frame
3569 #if defined(NCURSES_VERSION)
3570 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3571 #define is_keypad(win) (win)->_use_keypad
3572 #define is_scrollok(win) (win)->_scroll
3573 #elif !defined(is_keypad)
3574 #define is_keypad(win) FALSE
3575 #define is_scrollok(win) FALSE
3578 #define is_keypad(win) FALSE
3579 #define is_scrollok(win) FALSE
3583 frame_win(FRAME * curp)
3585 return (curp != 0) ? curp->wind : stdscr;
3588 /* We need to know if these flags are actually set, so don't look in FRAME.
3589 * These names are known to work with SVr4 curses as well as ncurses. The
3590 * _use_keypad name does not work with Solaris 8.
3593 HaveKeypad(FRAME * curp)
3595 WINDOW *win = frame_win(curp);
3597 return is_keypad(win);
3601 HaveScroll(FRAME * curp)
3603 WINDOW *win = frame_win(curp);
3605 return is_scrollok(win);
3609 newwin_legend(FRAME * curp)
3611 static const struct {
3616 "^C = create window", 0
3619 "^N = next window", 0
3622 "^P = previous window", 0
3625 "^F = scroll forward", 0
3628 "^B = scroll backward", 0
3631 "^K = keypad(%s)", 1
3634 "^S = scrollok(%s)", 2
3637 "^W = save window to file", 0
3640 "^R = restore window", 0
3653 bool do_keypad = HaveKeypad(curp);
3654 bool do_scroll = HaveScroll(curp);
3658 for (n = 0; n < SIZEOF(legend); n++) {
3659 switch (legend[n].code) {
3661 strcpy(buf, legend[n].msg);
3664 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3667 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3670 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3673 x = getcurx(stdscr);
3674 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3681 transient(FRAME * curp, NCURSES_CONST char *msg)
3683 newwin_legend(curp);
3685 mvaddstr(LINES - 1, 0, msg);
3691 printw("%s characters are echoed, window should %sscroll.",
3692 HaveKeypad(curp) ? "Non-arrow" : "All other",
3693 HaveScroll(curp) ? "" : "not ");
3698 newwin_report(FRAME * curp)
3699 /* report on the cursor's current position, then restore it */
3701 WINDOW *win = frame_win(curp);
3705 transient(curp, (char *) 0);
3707 move(LINES - 1, COLS - 17);
3708 printw("Y = %2d X = %2d", y, x);
3716 selectcell(int uli, int ulj, int lri, int lrj)
3717 /* arrows keys move cursor, return location at current on non-arrow key */
3719 static pair res; /* result cell */
3720 int si = lri - uli + 1; /* depth of the select area */
3721 int sj = lrj - ulj + 1; /* width of the select area */
3722 int i = 0, j = 0; /* offsets into the select area */
3727 move(uli + i, ulj + j);
3728 newwin_report((FRAME *) 0);
3730 switch (Getchar()) {
3744 return ((pair *) 0);
3745 #ifdef NCURSES_MOUSE_VERSION
3751 if (event.y > uli && event.x > ulj) {
3772 outerbox(pair ul, pair lr, bool onoff)
3773 /* draw or erase a box *outside* the given pair of corners */
3775 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3776 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3777 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3778 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3779 move(ul.y - 1, ul.x);
3780 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3781 move(ul.y, ul.x - 1);
3782 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3783 move(lr.y + 1, ul.x);
3784 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3785 move(ul.y, lr.x + 1);
3786 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3791 /* Ask user for a window definition */
3798 addstr("Use arrows to move cursor, anything else to mark corner 1");
3800 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3801 return ((WINDOW *) 0);
3802 memcpy(&ul, tmp, sizeof(pair));
3803 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3806 addstr("Use arrows to move cursor, anything else to mark corner 2");
3808 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
3810 return ((WINDOW *) 0);
3811 memcpy(&lr, tmp, sizeof(pair));
3813 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
3815 outerbox(ul, lr, TRUE);
3826 newwin_move(FRAME * curp, int dy, int dx)
3828 WINDOW *win = frame_win(curp);
3832 getyx(win, cur_y, cur_x);
3833 getmaxyx(win, max_y, max_x);
3834 if ((cur_x += dx) < 0)
3836 else if (cur_x >= max_x)
3838 if ((cur_y += dy) < 0)
3840 else if (cur_y >= max_y)
3842 wmove(win, cur_y, cur_x);
3846 delete_framed(FRAME * fp, bool showit)
3851 fp->last->next = fp->next;
3852 fp->next->last = fp->last;
3860 np = (fp == fp->next) ? 0 : fp->next;
3867 acs_and_scroll(void)
3868 /* Demonstrate windows */
3871 FRAME *current = (FRAME *) 0, *neww;
3872 WINDOW *usescr = stdscr;
3873 #if HAVE_PUTWIN && HAVE_GETWIN
3877 #define DUMPFILE "screendump"
3879 #ifdef NCURSES_MOUSE_VERSION
3880 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
3885 transient((FRAME *) 0, (char *) 0);
3888 if ((neww = typeCalloc(FRAME, 1)) == 0) {
3891 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
3896 if (current == 0) { /* First element, */
3897 neww->next = neww; /* so point it at itself */
3900 neww->next = current->next;
3901 neww->last = current;
3902 neww->last->next = neww;
3903 neww->next->last = neww;
3906 /* SVr4 curses sets the keypad on all newly-created windows to
3907 * false. Someone reported that PDCurses makes new windows inherit
3908 * this flag. Remove the following 'keypad()' call to test this
3910 keypad(current->wind, TRUE);
3911 current->do_keypad = HaveKeypad(current);
3912 current->do_scroll = HaveScroll(current);
3915 case CTRL('N'): /* go to next window */
3917 current = current->next;
3920 case CTRL('P'): /* go to previous window */
3922 current = current->last;
3925 case CTRL('F'): /* scroll current window forward */
3927 wscrl(frame_win(current), 1);
3930 case CTRL('B'): /* scroll current window backwards */
3932 wscrl(frame_win(current), -1);
3935 case CTRL('K'): /* toggle keypad mode for current */
3937 current->do_keypad = !current->do_keypad;
3938 keypad(current->wind, current->do_keypad);
3944 current->do_scroll = !current->do_scroll;
3945 scrollok(current->wind, current->do_scroll);
3949 #if HAVE_PUTWIN && HAVE_GETWIN
3950 case CTRL('W'): /* save and delete window */
3951 if ((current != 0) && (current == current->next)) {
3952 transient(current, "Will not save/delete ONLY window");
3954 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
3955 transient(current, "Can't open screen dump file");
3957 (void) putwin(frame_win(current), fp);
3960 current = delete_framed(current, TRUE);
3964 case CTRL('R'): /* restore window */
3965 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
3966 transient(current, "Can't open screen dump file");
3968 if ((neww = typeCalloc(FRAME, 1)) != 0) {
3970 neww->next = current ? current->next : 0;
3971 neww->last = current;
3972 neww->last->next = neww;
3973 neww->next->last = neww;
3975 neww->wind = getwin(fp);
3977 wrefresh(neww->wind);
3985 case CTRL('X'): /* resize window */
3992 addstr("Use arrows to move cursor, anything else to mark new corner");
3995 getbegyx(current->wind, ul.y, ul.x);
3997 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
3998 if (tmp == (pair *) 0) {
4003 getmaxyx(current->wind, lr.y, lr.x);
4006 outerbox(ul, lr, FALSE);
4007 wnoutrefresh(stdscr);
4009 /* strictly cosmetic hack for the test */
4010 getmaxyx(current->wind, my, mx);
4011 if (my > tmp->y - ul.y) {
4012 getyx(current->wind, lr.y, lr.x);
4013 wmove(current->wind, tmp->y - ul.y + 1, 0);
4014 wclrtobot(current->wind);
4015 wmove(current->wind, lr.y, lr.x);
4017 if (mx > tmp->x - ul.x)
4018 for (i = 0; i < my; i++) {
4019 wmove(current->wind, i, tmp->x - ul.x + 1);
4020 wclrtoeol(current->wind);
4022 wnoutrefresh(current->wind);
4024 memcpy(&lr, tmp, sizeof(pair));
4025 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4027 getbegyx(current->wind, ul.y, ul.x);
4028 getmaxyx(current->wind, lr.y, lr.x);
4031 outerbox(ul, lr, TRUE);
4032 wnoutrefresh(stdscr);
4034 wnoutrefresh(current->wind);
4040 #endif /* HAVE_WRESIZE */
4042 case KEY_F(10): /* undocumented --- use this to test area clears */
4043 selectcell(0, 0, LINES - 1, COLS - 1);
4049 newwin_move(current, -1, 0);
4052 newwin_move(current, 1, 0);
4055 newwin_move(current, 0, -1);
4058 newwin_move(current, 0, 1);
4066 getyx(frame_win(current), y, x);
4070 x = getmaxx(frame_win(current)) - 1;
4072 mvwdelch(frame_win(current), y, x);
4082 waddch(current->wind, (chtype) c);
4087 newwin_report(current);
4088 usescr = frame_win(current);
4091 (!isQuit(c = wGetchar(usescr))
4095 while (current != 0)
4096 current = delete_framed(current, FALSE);
4098 scrollok(stdscr, TRUE); /* reset to driver's default */
4099 #ifdef NCURSES_MOUSE_VERSION
4100 mousemask(0, (mmask_t *) 0);
4107 /****************************************************************************
4111 ****************************************************************************/
4114 static int nap_msec = 1;
4116 static NCURSES_CONST char *mod[] =
4126 /*+-------------------------------------------------------------------------
4128 --------------------------------------------------------------------------*/
4130 wait_a_while(int msec GCC_UNUSED)
4140 else if (msec > 1000)
4141 sleep((unsigned) msec / 1000);
4145 } /* end of wait_a_while */
4147 /*+-------------------------------------------------------------------------
4149 --------------------------------------------------------------------------*/
4151 saywhat(NCURSES_CONST char *text)
4153 wmove(stdscr, LINES - 1, 0);
4155 if (text != 0 && *text != '\0') {
4156 waddstr(stdscr, text);
4157 waddstr(stdscr, "; ");
4159 waddstr(stdscr, "press any key to continue");
4160 } /* end of saywhat */
4162 /*+-------------------------------------------------------------------------
4163 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4164 --------------------------------------------------------------------------*/
4166 mkpanel(short color, int rows, int cols, int tly, int tlx)
4171 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4172 if ((pan = new_panel(win)) == 0) {
4174 } else if (use_colors) {
4175 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4178 init_pair(color, fg, bg);
4179 wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
4181 wbkgdset(win, A_BOLD | ' ');
4185 } /* end of mkpanel */
4187 /*+-------------------------------------------------------------------------
4189 --------------------------------------------------------------------------*/
4191 rmpanel(PANEL * pan)
4193 WINDOW *win = panel_window(pan);
4196 } /* end of rmpanel */
4198 /*+-------------------------------------------------------------------------
4200 --------------------------------------------------------------------------*/
4206 } /* end of pflush */
4208 /*+-------------------------------------------------------------------------
4210 --------------------------------------------------------------------------*/
4216 for (y = 0; y < LINES - 1; y++) {
4217 for (x = 0; x < COLS; x++)
4218 wprintw(stdscr, "%d", (y + x) % 10);
4223 fill_panel(PANEL * pan)
4225 WINDOW *win = panel_window(pan);
4226 const char *userptr = (const char *) panel_userptr(pan);
4227 int num = (userptr && *userptr) ? userptr[1] : '?';
4231 wprintw(win, "-pan%c-", num);
4234 for (y = 2; y < getmaxy(win) - 1; y++) {
4235 for (x = 1; x < getmaxx(win) - 1; x++) {
4237 waddch(win, UChar(num));
4242 #if USE_WIDEC_SUPPORT
4244 init_wide_panel(void)
4249 for (digit = 0; digit < 10; ++digit)
4250 make_fullwidth_digit(&temp[digit], digit);
4254 getyx(stdscr, y, x);
4255 digit = (y + x / 2) % 10;
4256 } while (add_wch(&temp[digit]) != ERR);
4260 fill_wide_panel(PANEL * pan)
4262 WINDOW *win = panel_window(pan);
4263 const char *userptr = (const char *) panel_userptr(pan);
4264 int num = (userptr && *userptr) ? userptr[1] : '?';
4268 wprintw(win, "-pan%c-", num);
4271 for (y = 2; y < getmaxy(win) - 1; y++) {
4272 for (x = 1; x < getmaxx(win) - 1; x++) {
4274 waddch(win, UChar(num));
4280 #define MAX_PANELS 5
4283 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4285 int which = cmd[1] - '0';
4290 hide_panel(px[which]);
4293 show_panel(px[which]);
4296 top_panel(px[which]);
4299 bottom_panel(px[which]);
4306 wait_a_while(nap_msec);
4310 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4314 PANEL *px[MAX_PANELS + 1];
4316 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4320 for (count = 0; count < 5; count++) {
4321 px[1] = mkpanel(COLOR_RED,
4326 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4328 px[2] = mkpanel(COLOR_GREEN,
4333 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4335 px[3] = mkpanel(COLOR_YELLOW,
4340 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4342 px[4] = mkpanel(COLOR_BLUE,
4347 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4349 px[5] = mkpanel(COLOR_MAGENTA,
4354 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4366 wait_a_while(nap_msec);
4368 saywhat("h3 s1 s2 s4 s5");
4369 move_panel(px[1], 0, 0);
4376 wait_a_while(nap_msec);
4378 canned_panel(px, "s1");
4379 canned_panel(px, "s2");
4382 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4384 wait_a_while(nap_msec);
4386 canned_panel(px, "s3");
4389 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4391 wait_a_while(nap_msec);
4393 canned_panel(px, "b3");
4394 canned_panel(px, "s4");
4395 canned_panel(px, "s5");
4396 canned_panel(px, "t3");
4397 canned_panel(px, "t1");
4398 canned_panel(px, "t2");
4399 canned_panel(px, "t3");
4400 canned_panel(px, "t4");
4402 for (itmp = 0; itmp < 6; itmp++) {
4403 WINDOW *w4 = panel_window(px[4]);
4404 WINDOW *w5 = panel_window(px[5]);
4407 wmove(w4, LINES / 8, 1);
4408 waddstr(w4, mod[itmp]);
4409 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4410 wmove(w5, LINES / 6, 1);
4411 waddstr(w5, mod[itmp]);
4413 wait_a_while(nap_msec);
4416 wmove(w4, LINES / 6, 1);
4417 waddstr(w4, mod[itmp]);
4418 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4419 wmove(w5, LINES / 8, 1);
4420 waddstr(w5, mod[itmp]);
4422 wait_a_while(nap_msec);
4426 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4428 wait_a_while(nap_msec);
4430 canned_panel(px, "t5");
4431 canned_panel(px, "t2");
4432 canned_panel(px, "t1");
4433 canned_panel(px, "d2");
4434 canned_panel(px, "h3");
4435 canned_panel(px, "d1");
4436 canned_panel(px, "d4");
4437 canned_panel(px, "d5");
4438 canned_panel(px, "d3");
4440 wait_a_while(nap_msec);
4449 #endif /* USE_LIBPANEL */
4451 /****************************************************************************
4455 ****************************************************************************/
4459 static bool pending_pan = FALSE;
4460 static bool show_panner_legend = TRUE;
4463 panner_legend(int line)
4465 static const char *const legend[] =
4467 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4468 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4469 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4470 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4472 int n = ((int) SIZEOF(legend) - (LINES - line));
4473 if (line < LINES && (n >= 0)) {
4475 if (show_panner_legend)
4476 printw("%s", legend[n]);
4478 return show_panner_legend;
4484 panner_h_cleanup(int from_y, int from_x, int to_x)
4486 if (!panner_legend(from_y))
4487 do_h_line(from_y, from_x, ' ', to_x);
4491 panner_v_cleanup(int from_y, int from_x, int to_y)
4493 if (!panner_legend(from_y))
4494 do_v_line(from_y, from_x, ' ', to_y);