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.329 2008/09/27 14:34:58 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 */
122 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
123 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
124 #define reset_wchars(state) memset(&state, 0, sizeof(state))
125 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
126 #define count_wchars(src, len, state) wcstombs(0, src, len)
127 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
128 #define reset_wchars(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
133 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
134 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
135 #define reset_mbytes(state) memset(&state, 0, sizeof(state))
136 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
137 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
138 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
139 #define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
143 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
145 #define P(string) printw("%s\n", string)
147 #define BLANK ' ' /* this is the background character */
150 static int max_colors; /* the actual number of colors we'll use */
151 static int min_colors; /* the minimum color code */
152 static bool use_colors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
163 static RGB_DATA *all_colors;
165 static void main_menu(bool);
167 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
168 * though we can rely on negative x/y values to stop the macro.
171 do_h_line(int y, int x, chtype c, int to)
174 mvhline(y, x, c, (to) - (x));
178 do_v_line(int y, int x, chtype c, int to)
181 mvvline(y, x, c, (to) - (y));
195 return ((c) == QUIT || (c) == ESCAPE);
197 #define case_QUIT QUIT: case ESCAPE
199 /* Common function to allow ^T to toggle trace-mode in the middle of a test
200 * so that trace-files can be made smaller.
203 wGetchar(WINDOW *win)
207 while ((c = wgetch(win)) == CTRL('T')) {
209 save_trace = _nc_tracing;
210 Trace(("TOGGLE-TRACING OFF"));
213 _nc_tracing = save_trace;
217 Trace(("TOGGLE-TRACING ON"));
224 #define Getchar() wGetchar(stdscr)
226 /* replaces wgetnstr(), since we want to be able to edit values */
228 wGetstring(WINDOW *win, char *buffer, int limit)
235 wattrset(win, A_REVERSE);
237 x = (int) strlen(buffer);
239 if (x > (int) strlen(buffer))
240 x = (int) strlen(buffer);
242 wprintw(win, "%-*s", limit, buffer);
243 wmove(win, y0, x0 + x);
244 switch (ch = wGetchar(win)) {
257 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
275 if (!isprint(ch) || ch >= KEY_MIN) {
277 } else if ((int) strlen(buffer) < limit) {
279 for (j = (int) strlen(buffer) + 1; j > x; --j) {
280 buffer[j] = buffer[j - 1];
282 buffer[x++] = (char) ch;
289 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
298 return (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_of(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
322 make_fullwidth_digit(cchar_t *target, int digit)
326 source[0] = fullwidth_of(digit + '0');
328 setcchar(target, source, A_NORMAL, 0, 0);
332 wGet_wchar(WINDOW *win, wint_t *result)
336 while ((c = wget_wch(win, result)) == CTRL('T')) {
338 save_trace = _nc_tracing;
339 Trace(("TOGGLE-TRACING OFF"));
342 _nc_tracing = save_trace;
346 Trace(("TOGGLE-TRACING ON"));
349 c = wget_wch(win, result);
353 #define Get_wchar(result) wGet_wchar(stdscr, result)
355 /* replaces wgetn_wstr(), since we want to be able to edit values */
357 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
366 wattrset(win, A_REVERSE);
368 x = (int) wcslen(buffer);
370 if (x > (int) wcslen(buffer))
371 x = (int) wcslen(buffer);
373 /* clear the "window' */
375 wprintw(win, "%*s", limit, " ");
377 /* write the existing buffer contents */
379 waddnwstr(win, buffer, limit);
381 /* positions the cursor past character 'x' */
383 waddnwstr(win, buffer, x);
385 switch (wGet_wchar(win, &ch)) {
425 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
445 } else if ((int) wcslen(buffer) < limit) {
447 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
448 buffer[j] = buffer[j - 1];
450 buffer[x++] = (wchar_t) ch;
457 wattroff(win, A_REVERSE);
468 addstr("Press any key to continue... ");
473 Cannot(const char *what)
475 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
480 ShellOut(bool message)
483 addstr("Shelling out...");
488 addstr("returned from shellout.\n");
492 #ifdef NCURSES_MOUSE_VERSION
494 * This function is the same as _tracemouse(), but we cannot count on that
495 * being available in the non-debug library.
498 mouse_decode(MEVENT const *ep)
500 static char buf[80 + (5 * 10) + (32 * 15)];
502 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
503 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
505 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
507 SHOW(BUTTON1_RELEASED, "release-1");
508 SHOW(BUTTON1_PRESSED, "press-1");
509 SHOW(BUTTON1_CLICKED, "click-1");
510 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
511 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
512 #if NCURSES_MOUSE_VERSION == 1
513 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
516 SHOW(BUTTON2_RELEASED, "release-2");
517 SHOW(BUTTON2_PRESSED, "press-2");
518 SHOW(BUTTON2_CLICKED, "click-2");
519 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
520 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
521 #if NCURSES_MOUSE_VERSION == 1
522 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
525 SHOW(BUTTON3_RELEASED, "release-3");
526 SHOW(BUTTON3_PRESSED, "press-3");
527 SHOW(BUTTON3_CLICKED, "click-3");
528 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
529 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
530 #if NCURSES_MOUSE_VERSION == 1
531 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
534 SHOW(BUTTON4_RELEASED, "release-4");
535 SHOW(BUTTON4_PRESSED, "press-4");
536 SHOW(BUTTON4_CLICKED, "click-4");
537 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
538 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
539 #if NCURSES_MOUSE_VERSION == 1
540 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
543 #if NCURSES_MOUSE_VERSION == 2
544 SHOW(BUTTON5_RELEASED, "release-5");
545 SHOW(BUTTON5_PRESSED, "press-5");
546 SHOW(BUTTON5_CLICKED, "click-5");
547 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
548 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
551 SHOW(BUTTON_CTRL, "ctrl");
552 SHOW(BUTTON_SHIFT, "shift");
553 SHOW(BUTTON_ALT, "alt");
554 SHOW(ALL_MOUSE_EVENTS, "all-events");
555 SHOW(REPORT_MOUSE_POSITION, "position");
559 if (buf[strlen(buf) - 1] == ' ')
560 buf[strlen(buf) - 2] = '\0';
561 (void) strcat(buf, "}");
564 #endif /* NCURSES_MOUSE_VERSION */
566 /****************************************************************************
568 * Character input test
570 ****************************************************************************/
573 setup_getch(WINDOW *win, bool flags[])
575 keypad(win, flags['k']); /* should be redundant, but for testing */
576 meta(win, flags['m']); /* force this to a known state */
584 wgetch_help(WINDOW *win, bool flags[])
586 static const char *help[] =
588 "e -- toggle echo mode"
589 ,"g -- triggers a getstr test"
590 ,"k -- toggle keypad/literal mode"
591 ,"m -- toggle meta (7-bit/8-bit) mode"
594 ,"w -- create a new window"
596 ,"z -- suspend this process"
600 unsigned chk = ((SIZEOF(help) + 1) / 2);
605 printw("Type any key to see its %s value. Also:\n",
606 flags['k'] ? "keypad" : "literal");
607 for (n = 0; n < SIZEOF(help); ++n) {
608 int row = 1 + (int) (n % chk);
609 int col = (n >= chk) ? COLS / 2 : 0;
610 int flg = ((strstr(help[n], "toggle") != 0)
611 && (flags[UChar(*help[n])] != FALSE));
614 mvprintw(row, col, "%s", help[n]);
625 wgetch_wrap(WINDOW *win, int first_y)
627 int last_y = getmaxy(win) - 1;
628 int y = getcury(win) + 1;
636 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
642 static WINSTACK *winstack = 0;
643 static unsigned len_winstack = 0;
656 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
658 unsigned need = (level + 1) * 2;
660 assert(level < COLS);
664 winstack = typeMalloc(WINSTACK, len_winstack);
665 } else if (need >= len_winstack) {
667 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
669 winstack[level].text = txt_win;
670 winstack[level].frame = box_win;
673 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
677 /* this chunk is now done in resize_term() */
684 #define slk_repaint() /* nothing */
688 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
689 * Resize both and paint the box in the parent.
692 resize_boxes(unsigned level, WINDOW *win)
696 int high = LINES - base;
700 wnoutrefresh(stdscr);
704 for (n = 0; n < level; ++n) {
705 wresize(winstack[n].frame, high, wide);
706 wresize(winstack[n].text, high - 2, wide - 2);
709 werase(winstack[n].text);
710 box(winstack[n].frame, 0, 0);
711 wnoutrefresh(winstack[n].frame);
712 wprintw(winstack[n].text,
714 getmaxy(winstack[n].text),
715 getmaxx(winstack[n].text));
716 wnoutrefresh(winstack[n].text);
717 if (winstack[n].text == win)
723 #define forget_boxes() /* nothing */
724 #define remember_boxes(level,text,frame) /* nothing */
728 wgetch_test(unsigned level, WINDOW *win, int delay)
731 int first_y, first_x;
735 bool blocking = (delay < 0);
737 memset(flags, FALSE, sizeof(flags));
738 flags[UChar('k')] = (win == stdscr);
740 setup_getch(win, flags);
741 wtimeout(win, delay);
742 getyx(win, first_y, first_x);
744 wgetch_help(win, flags);
745 wsetscrreg(win, first_y, getmaxy(win) - 1);
749 while ((c = wGetchar(win)) == ERR) {
752 (void) wprintw(win, "%05d: input error", incount);
755 (void) wprintw(win, "%05d: input timed out", incount);
757 wgetch_wrap(win, first_y);
759 if (c == ERR && blocking) {
761 wgetch_wrap(win, first_y);
762 } else if (isQuit(c)) {
764 } else if (c == 'e') {
765 flags[UChar('e')] = !flags[UChar('e')];
766 setup_getch(win, flags);
767 wgetch_help(win, flags);
768 } else if (c == 'g') {
769 waddstr(win, "getstr test: ");
771 wgetnstr(win, buf, sizeof(buf) - 1);
773 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
775 wgetch_wrap(win, first_y);
776 } else if (c == 'k') {
777 flags[UChar('k')] = !flags[UChar('k')];
778 setup_getch(win, flags);
779 wgetch_help(win, flags);
780 } else if (c == 'm') {
781 flags[UChar('m')] = !flags[UChar('m')];
782 setup_getch(win, flags);
783 wgetch_help(win, flags);
784 } else if (c == 's') {
786 } else if (c == 'w') {
787 int high = getmaxy(win) - 1 - first_y + 1;
788 int wide = getmaxx(win) - first_x;
790 int new_y = first_y + getbegy(win);
791 int new_x = first_x + getbegx(win);
793 getyx(win, old_y, old_x);
794 if (high > 2 && wide > 2) {
795 WINDOW *wb = newwin(high, wide, new_y, new_x);
796 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
801 remember_boxes(level, wi, wb);
802 wgetch_test(level + 1, wi, delay);
806 wgetch_help(win, flags);
807 wmove(win, old_y, old_x);
813 } else if (c == 'z') {
814 kill(getpid(), SIGTSTP);
817 wprintw(win, "Key pressed: %04o ", c);
818 #ifdef NCURSES_MOUSE_VERSION
819 if (c == KEY_MOUSE) {
824 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
826 move(event.y, event.x);
830 #endif /* NCURSES_MOUSE_VERSION */
832 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
833 if (c == KEY_RESIZE) {
834 resize_boxes(level, win);
837 (void) waddstr(win, keyname(c));
838 } else if (c > 0x80) {
839 unsigned c2 = (unsigned) (c & 0x7f);
841 (void) wprintw(win, "M-%c", UChar(c2));
843 (void) wprintw(win, "M-%s", unctrl(c2));
844 waddstr(win, " (high-half character)");
847 (void) wprintw(win, "%c (ASCII printable character)", c);
849 (void) wprintw(win, "%s (ASCII control character)",
852 wgetch_wrap(win, first_y);
860 begin_getch_test(void)
867 #ifdef NCURSES_MOUSE_VERSION
868 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
871 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
873 getnstr(buf, sizeof(buf) - 1);
877 if (isdigit(UChar(buf[0]))) {
878 delay = atoi(buf) * 100;
888 finish_getch_test(void)
890 #ifdef NCURSES_MOUSE_VERSION
891 mousemask(0, (mmask_t *) 0);
902 int delay = begin_getch_test();
905 wgetch_test(0, stdscr, delay);
910 #if USE_WIDEC_SUPPORT
912 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
913 * Resize both and paint the box in the parent.
915 #if defined(KEY_RESIZE) && HAVE_WRESIZE
917 resize_wide_boxes(unsigned level, WINDOW *win)
921 int high = LINES - base;
925 wnoutrefresh(stdscr);
929 for (n = 0; n < level; ++n) {
930 wresize(winstack[n].frame, high, wide);
931 wresize(winstack[n].text, high - 2, wide - 2);
934 werase(winstack[n].text);
935 box_set(winstack[n].frame, 0, 0);
936 wnoutrefresh(winstack[n].frame);
937 wprintw(winstack[n].text,
939 getmaxy(winstack[n].text),
940 getmaxx(winstack[n].text));
941 wnoutrefresh(winstack[n].text);
942 if (winstack[n].text == win)
947 #endif /* KEY_RESIZE */
950 wcstos(const wchar_t *src)
954 const wchar_t *tmp = src;
960 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
961 unsigned have = (unsigned) need;
962 if ((result = typeCalloc(char, have + 1)) != 0) {
964 if (trans_wchars(result, tmp, have, &state) != have) {
974 wget_wch_test(unsigned level, WINDOW *win, int delay)
976 wchar_t wchar_buf[BUFSIZ];
977 wint_t wint_buf[BUFSIZ];
978 int first_y, first_x;
982 bool blocking = (delay < 0);
986 memset(flags, FALSE, sizeof(flags));
987 flags[UChar('k')] = (win == stdscr);
989 setup_getch(win, flags);
990 wtimeout(win, delay);
991 getyx(win, first_y, first_x);
993 wgetch_help(win, flags);
994 wsetscrreg(win, first_y, getmaxy(win) - 1);
998 while ((code = wGet_wchar(win, &c)) == ERR) {
1001 (void) wprintw(win, "%05d: input error", incount);
1004 (void) wprintw(win, "%05d: input timed out", incount);
1006 wgetch_wrap(win, first_y);
1008 if (code == ERR && blocking) {
1009 wprintw(win, "ERR");
1010 wgetch_wrap(win, first_y);
1011 } else if (isQuit((int) c)) {
1013 } else if (c == 'e') {
1014 flags[UChar('e')] = !flags[UChar('e')];
1015 setup_getch(win, flags);
1016 wgetch_help(win, flags);
1017 } else if (c == 'g') {
1018 waddstr(win, "getstr test: ");
1020 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1023 wprintw(win, "wgetn_wstr returns an error.");
1026 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1029 if ((temp = wcstos(wchar_buf)) != 0) {
1030 wprintw(win, "I saw %d characters:\n\t`%s'.",
1031 (int) wcslen(wchar_buf), temp);
1034 wprintw(win, "I saw %d characters (cannot convert).",
1035 (int) wcslen(wchar_buf));
1039 wgetch_wrap(win, first_y);
1040 } else if (c == 'k') {
1041 flags[UChar('k')] = !flags[UChar('k')];
1042 setup_getch(win, flags);
1043 wgetch_help(win, flags);
1044 } else if (c == 'm') {
1045 flags[UChar('m')] = !flags[UChar('m')];
1046 setup_getch(win, flags);
1047 wgetch_help(win, flags);
1048 } else if (c == 's') {
1050 } else if (c == 'w') {
1051 int high = getmaxy(win) - 1 - first_y + 1;
1052 int wide = getmaxx(win) - first_x;
1054 int new_y = first_y + getbegy(win);
1055 int new_x = first_x + getbegx(win);
1057 getyx(win, old_y, old_x);
1058 if (high > 2 && wide > 2) {
1059 WINDOW *wb = newwin(high, wide, new_y, new_x);
1060 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1065 remember_boxes(level, wi, wb);
1066 wget_wch_test(level + 1, wi, delay);
1070 wgetch_help(win, flags);
1071 wmove(win, old_y, old_x);
1076 } else if (c == 'z') {
1077 kill(getpid(), SIGTSTP);
1080 wprintw(win, "Key pressed: %04o ", (int) c);
1081 #ifdef NCURSES_MOUSE_VERSION
1082 if (c == KEY_MOUSE) {
1086 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1088 move(event.y, event.x);
1092 #endif /* NCURSES_MOUSE_VERSION */
1093 if (code == KEY_CODE_YES) {
1094 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1095 if (c == KEY_RESIZE) {
1096 resize_wide_boxes(level, win);
1099 (void) waddstr(win, key_name((wchar_t) c));
1101 if (c < 256 && iscntrl(c)) {
1102 (void) wprintw(win, "%s (control character)", unctrl(c));
1104 wchar_t c2 = (wchar_t) c;
1105 waddnwstr(win, &c2, 1);
1106 (void) wprintw(win, " = %#x (printable character)", (unsigned) c);
1109 wgetch_wrap(win, first_y);
1119 int delay = begin_getch_test();
1122 wget_wch_test(0, stdscr, delay);
1124 finish_getch_test();
1128 /****************************************************************************
1130 * Character attributes test
1132 ****************************************************************************/
1134 #if HAVE_SETUPTERM || HAVE_TGETENT
1135 #define get_ncv() TIGETNUM("ncv","NC")
1136 #define get_xmc() TIGETNUM("xmc","sg")
1138 #define get_ncv() -1
1139 #define get_xmc() -1
1146 static int first = TRUE;
1147 static chtype result = 0;
1153 char *area_pointer = parsed;
1155 tgetent(buffer, getenv("TERM"));
1158 if (TIGETSTR("smso", "so"))
1159 result |= A_STANDOUT;
1160 if (TIGETSTR("smul", "us"))
1161 result |= A_UNDERLINE;
1162 if (TIGETSTR("rev", "mr"))
1163 result |= A_REVERSE;
1164 if (TIGETSTR("blink", "mb"))
1166 if (TIGETSTR("dim", "mh"))
1168 if (TIGETSTR("bold", "md"))
1170 if (TIGETSTR("smacs", "ac"))
1171 result |= A_ALTCHARSET;
1177 #define termattrs() my_termattrs()
1180 #define MAX_ATTRSTRING 31
1181 #define LEN_ATTRSTRING 26
1183 static char attr_test_string[MAX_ATTRSTRING + 1];
1186 attr_legend(WINDOW *helpwin)
1191 mvwprintw(helpwin, row++, col,
1193 mvwprintw(helpwin, row++, col,
1196 mvwprintw(helpwin, row++, col,
1197 "Modify the test strings:");
1198 mvwprintw(helpwin, row++, col,
1199 " A digit sets gaps on each side of displayed attributes");
1200 mvwprintw(helpwin, row++, col,
1201 " </> shifts the text left/right. ");
1203 mvwprintw(helpwin, row++, col,
1206 mvwprintw(helpwin, row++, col,
1207 " f/F/b/F toggle foreground/background background color");
1208 mvwprintw(helpwin, row++, col,
1209 " t/T toggle text/background color attribute");
1211 mvwprintw(helpwin, row++, col,
1212 " a/A toggle ACS (alternate character set) mapping");
1213 mvwprintw(helpwin, row++, col,
1214 " v/V toggle video attribute to combine with each line");
1218 show_color_attr(int fg, int bg, int tx)
1221 printw(" Colors (fg %d, bg %d", fg, bg);
1223 printw(", text %d", tx);
1229 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1236 *fg = (short) (*fg + 1);
1239 *fg = (short) (*fg - 1);
1242 *bg = (short) (*bg + 1);
1245 *bg = (short) (*bg - 1);
1248 *tx = (short) (*tx + 1);
1251 *tx = (short) (*tx - 1);
1259 *fg = (short) min_colors;
1260 if (*fg < min_colors)
1261 *fg = (short) (COLORS - 1);
1263 *bg = (short) min_colors;
1264 if (*bg < min_colors)
1265 *bg = (short) (COLORS - 1);
1269 *tx = (short) (COLORS - 1);
1278 adjust_attr_string(int adjust)
1280 int first = ((int) UChar(attr_test_string[0])) + adjust;
1281 int last = first + LEN_ATTRSTRING;
1283 if (first >= ' ' && last <= '~') { /* 32..126 */
1285 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1286 attr_test_string[j] = (char) k;
1287 if (((k + 1 - first) % 5) == 0) {
1288 if (++j >= MAX_ATTRSTRING)
1290 attr_test_string[j] = ' ';
1293 while (j < MAX_ATTRSTRING)
1294 attr_test_string[j++] = ' ';
1295 attr_test_string[j] = '\0';
1302 init_attr_string(void)
1304 attr_test_string[0] = 'a';
1305 adjust_attr_string(0);
1309 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1311 int ncv = get_ncv();
1312 chtype test = attr & (chtype) (~A_ALTCHARSET);
1315 mvprintw(row, 5, "-->");
1316 mvprintw(row, 8, "%s mode:", name);
1317 mvprintw(row, 24, "|");
1319 printw("%*s", skip, " ");
1321 * Just for testing, write text using the alternate character set one
1322 * character at a time (to pass its rendition directly), and use the
1323 * string operation for the other attributes.
1325 if (attr & A_ALTCHARSET) {
1329 for (s = attr_test_string; *s != '\0'; ++s) {
1335 addstr(attr_test_string);
1339 printw("%*s", skip, " ");
1341 if (test != A_NORMAL) {
1342 if (!(termattrs() & test)) {
1345 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1346 static const chtype table[] =
1362 for (n = 0; n < SIZEOF(table); n++) {
1363 if ((table[n] & attr) != 0
1364 && ((1 << n) & ncv) != 0) {
1372 if ((termattrs() & test) != test)
1379 static const struct {
1381 NCURSES_CONST char * name;
1382 } attrs_to_test[] = {
1383 { A_STANDOUT, "STANDOUT" },
1384 { A_REVERSE, "REVERSE" },
1386 { A_UNDERLINE, "UNDERLINE" },
1388 { A_BLINK, "BLINK" },
1389 { A_PROTECT, "PROTECT" },
1391 { A_INVIS, "INVISIBLE" },
1393 { A_NORMAL, "NORMAL" },
1398 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1408 if (ch < 256 && isdigit(ch)) {
1416 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1418 attr_legend(helpwin);
1431 *kc = SIZEOF(attrs_to_test) - 1;
1437 if (*kc >= SIZEOF(attrs_to_test))
1441 adjust_attr_string(-1);
1444 adjust_attr_string(1);
1450 error = cycle_color_attr(ch, fg, bg, tx);
1460 /* test text attributes */
1463 int skip = get_xmc();
1464 short fg = COLOR_BLACK; /* color pair 0 is special */
1465 short bg = COLOR_BLACK;
1473 n = skip; /* make it easy */
1474 k = SIZEOF(attrs_to_test) - 1;
1479 chtype normal = A_NORMAL | BLANK;
1480 chtype extras = (chtype) ac;
1483 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1486 if (init_pair(pair, fg, bg) == ERR) {
1489 normal |= COLOR_PAIR(pair);
1494 if (init_pair(pair, tx, bg) == ERR) {
1497 extras |= COLOR_PAIR(pair);
1506 mvaddstr(0, 20, "Character attribute test display");
1508 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1509 bool arrow = (j == k);
1510 row = show_attr(row, n, arrow,
1512 attrs_to_test[j].attr |
1513 attrs_to_test[k].attr,
1514 attrs_to_test[j].name);
1518 "This terminal does %shave the magic-cookie glitch",
1519 get_xmc() > -1 ? "" : "not ");
1520 mvprintw(row + 1, 8, "Enter '?' for help.");
1521 show_color_attr(fg, bg, tx);
1522 printw(" ACS (%d)", ac != 0);
1525 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1527 bkgdset(A_NORMAL | BLANK);
1532 #if USE_WIDEC_SUPPORT
1533 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1536 wide_adjust_attr_string(int adjust)
1538 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1539 int last = first + LEN_ATTRSTRING;
1541 if (first >= ' ' && last <= '~') { /* 32..126 */
1543 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1544 wide_attr_test_string[j] = k;
1545 if (((k + 1 - first) % 5) == 0) {
1546 if (++j >= MAX_ATTRSTRING)
1548 wide_attr_test_string[j] = ' ';
1551 while (j < MAX_ATTRSTRING)
1552 wide_attr_test_string[j++] = ' ';
1553 wide_attr_test_string[j] = '\0';
1560 wide_init_attr_string(void)
1562 wide_attr_test_string[0] = 'a';
1563 wide_adjust_attr_string(0);
1567 set_wide_background(short pair)
1574 setcchar(&normal, blank, A_NORMAL, pair, 0);
1580 get_wide_background(void)
1582 attr_t result = A_NORMAL;
1588 if (getbkgrnd(&ch) != ERR) {
1589 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1597 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1599 int ncv = get_ncv();
1600 chtype test = attr & ~WA_ALTCHARSET;
1603 mvprintw(row, 5, "-->");
1604 mvprintw(row, 8, "%s mode:", name);
1605 mvprintw(row, 24, "|");
1607 printw("%*s", skip, " ");
1610 * Just for testing, write text using the alternate character set one
1611 * character at a time (to pass its rendition directly), and use the
1612 * string operation for the other attributes.
1614 if (attr & WA_ALTCHARSET) {
1618 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1622 setcchar(&ch, fill, attr, pair, 0);
1629 attr_get(&old_attr, &old_pair, 0);
1630 attr_set(attr, pair, 0);
1631 addwstr(wide_attr_test_string);
1632 attr_set(old_attr, old_pair, 0);
1635 printw("%*s", skip, " ");
1637 if (test != A_NORMAL) {
1638 if (!(term_attrs() & test)) {
1641 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1642 static const attr_t table[] =
1656 for (n = 0; n < SIZEOF(table); n++) {
1657 if ((table[n] & attr) != 0
1658 && ((1 << n) & ncv) != 0) {
1666 if ((term_attrs() & test) != test)
1674 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1684 if (ch < 256 && isdigit(ch)) {
1692 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1693 box_set(helpwin, 0, 0);
1694 attr_legend(helpwin);
1707 *kc = SIZEOF(attrs_to_test) - 1;
1713 if (*kc >= SIZEOF(attrs_to_test))
1717 wide_adjust_attr_string(-1);
1720 wide_adjust_attr_string(1);
1726 error = cycle_color_attr(ch, fg, bg, tx);
1735 wide_attr_test(void)
1736 /* test text attributes using wide-character calls */
1739 int skip = get_xmc();
1740 short fg = COLOR_BLACK; /* color pair 0 is special */
1741 short bg = COLOR_BLACK;
1749 n = skip; /* make it easy */
1750 k = SIZEOF(attrs_to_test) - 1;
1751 wide_init_attr_string();
1759 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1762 if (init_pair(pair, fg, bg) == ERR) {
1769 if (init_pair(extras, tx, bg) == ERR) {
1774 set_wide_background(pair);
1777 box_set(stdscr, 0, 0);
1778 mvaddstr(0, 20, "Character attribute test display");
1780 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1781 row = wide_show_attr(row, n, j == k,
1783 attrs_to_test[j].attr |
1784 attrs_to_test[k].attr,
1786 attrs_to_test[j].name);
1790 "This terminal does %shave the magic-cookie glitch",
1791 get_xmc() > -1 ? "" : "not ");
1792 mvprintw(row + 1, 8, "Enter '?' for help.");
1793 show_color_attr(fg, bg, tx);
1794 printw(" ACS (%d)", ac != 0);
1797 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1799 set_wide_background(0);
1805 /****************************************************************************
1807 * Color support tests
1809 ****************************************************************************/
1811 static NCURSES_CONST char *the_color_names[] =
1832 show_color_name(int y, int x, int color, bool wide)
1834 if (move(y, x) != ERR) {
1839 sprintf(temp, "%02d", color);
1841 } else if (color >= 8) {
1842 sprintf(temp, "[%02d]", color);
1844 strcpy(temp, the_color_names[color]);
1846 printw("%-*.*s", width, width, temp);
1851 color_legend(WINDOW *helpwin, bool wide)
1856 mvwprintw(helpwin, row++, col,
1859 mvwprintw(helpwin, row++, col,
1860 "Use up/down arrow to scroll through the display if it is");
1861 mvwprintw(helpwin, row++, col,
1862 "longer than one screen. Control/N and Control/P can be used");
1863 mvwprintw(helpwin, row++, col,
1864 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1865 mvwprintw(helpwin, row++, col,
1866 "full screen; control/B and control/F can be used here.");
1868 mvwprintw(helpwin, row++, col,
1870 mvwprintw(helpwin, row++, col,
1871 " a/A toggle altcharset off/on");
1872 mvwprintw(helpwin, row++, col,
1873 " b/B toggle bold off/on");
1874 mvwprintw(helpwin, row++, col,
1875 " n/N toggle text/number on/off");
1876 mvwprintw(helpwin, row++, col,
1877 " w/W toggle width between 8/16 colors");
1878 #if USE_WIDEC_SUPPORT
1880 mvwprintw(helpwin, row++, col,
1881 "Wide characters:");
1882 mvwprintw(helpwin, row++, col,
1883 " x/X toggle text between ASCII and wide-character");
1890 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1892 /* generate a color test pattern */
1899 int grid_top = top + 3;
1900 int page_size = (LINES - grid_top);
1901 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1907 bool opt_acsc = FALSE;
1908 bool opt_bold = FALSE;
1909 bool opt_wide = FALSE;
1910 bool opt_nums = FALSE;
1913 if (pairs_max > COLOR_PAIRS)
1914 pairs_max = COLOR_PAIRS;
1919 /* this assumes an 80-column line */
1923 per_row = (COLORS > 8) ? 16 : 8;
1930 row_limit = (pairs_max + per_row - 1) / per_row;
1933 (void) printw("There are %d color pairs and %d colors\n",
1937 (void) mvprintw(top + 1, 0,
1938 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1941 opt_bold ? "on" : "off");
1943 /* show color names/numbers across the top */
1944 for (i = 0; i < per_row; i++)
1945 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
1947 /* show a grid of colors, with color names/ numbers on the left */
1948 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
1949 int row = grid_top + (i / per_row) - base_row;
1950 int col = (i % per_row + 1) * width;
1953 if (row >= 0 && move(row, col) != ERR) {
1954 short fg = (short) (i % COLORS);
1955 short bg = (short) (i / COLORS);
1957 init_pair(pair, fg, bg);
1958 attron((attr_t) COLOR_PAIR(pair));
1960 attron((attr_t) A_ALTCHARSET);
1962 attron((attr_t) A_BOLD);
1965 sprintf(numbered, "{%02X}", i);
1968 printw("%-*.*s", width, width, hello);
1971 if ((i % per_row) == 0 && (i % COLORS) == 0) {
1972 show_color_name(row, 0, i / COLORS, opt_wide);
1980 switch (wGetchar(stdscr)) {
2003 set_color_test(opt_wide, FALSE);
2006 set_color_test(opt_wide, TRUE);
2010 if (base_row <= 0) {
2018 if (base_row + page_size >= row_limit) {
2027 if (base_row <= 0) {
2030 base_row -= (page_size - 1);
2038 if (base_row + page_size >= row_limit) {
2041 base_row += page_size - 1;
2042 if (base_row + page_size >= row_limit) {
2043 base_row = row_limit - page_size - 1;
2048 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2050 color_legend(helpwin, FALSE);
2065 #if USE_WIDEC_SUPPORT
2066 /* generate a color test pattern */
2068 wide_color_test(void)
2074 int grid_top = top + 3;
2075 int page_size = (LINES - grid_top);
2076 int pairs_max = COLOR_PAIRS;
2082 bool opt_acsc = FALSE;
2083 bool opt_bold = FALSE;
2084 bool opt_wide = FALSE;
2085 bool opt_nums = FALSE;
2086 bool opt_xchr = FALSE;
2093 /* this assumes an 80-column line */
2097 per_row = (COLORS > 8) ? 16 : 8;
2104 make_fullwidth_text(buffer, hello);
2108 make_narrow_text(buffer, hello);
2111 row_limit = (pairs_max + per_row - 1) / per_row;
2114 (void) printw("There are %d color pairs and %d colors\n",
2118 (void) mvprintw(top + 1, 0,
2119 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2122 opt_bold ? "on" : "off");
2124 /* show color names/numbers across the top */
2125 for (i = 0; i < per_row; i++)
2126 show_color_name(top + 2, (i + 1) * width, i, opt_wide);
2128 /* show a grid of colors, with color names/ numbers on the left */
2129 for (i = (base_row * per_row); i < pairs_max; i++) {
2130 int row = grid_top + (i / per_row) - base_row;
2131 int col = (i % per_row + 1) * width;
2132 short pair = (short) i;
2134 if (row >= 0 && move(row, col) != ERR) {
2135 init_pair(pair, (short) (i % COLORS), (short) (i / COLORS));
2136 color_set(pair, NULL);
2138 attr_on((attr_t) A_ALTCHARSET, NULL);
2140 attr_on((attr_t) A_BOLD, NULL);
2143 sprintf(numbered, "{%02X}", i);
2145 make_fullwidth_text(buffer, numbered);
2147 make_narrow_text(buffer, numbered);
2150 addnwstr(buffer, width);
2151 attr_set(A_NORMAL, 0, NULL);
2153 if ((i % per_row) == 0 && (i % COLORS) == 0) {
2154 show_color_name(row, 0, i / COLORS, opt_wide);
2162 switch (c = wGetchar(stdscr)) {
2185 set_color_test(opt_wide, FALSE);
2188 set_color_test(opt_wide, TRUE);
2198 if (base_row <= 0) {
2206 if (base_row + page_size >= row_limit) {
2215 if (base_row <= 0) {
2218 base_row -= (page_size - 1);
2226 if (base_row + page_size >= row_limit) {
2229 base_row += page_size - 1;
2230 if (base_row + page_size >= row_limit) {
2231 base_row = row_limit - page_size - 1;
2236 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2238 color_legend(helpwin, TRUE);
2252 #endif /* USE_WIDEC_SUPPORT */
2255 change_color(short current, int field, int value, int usebase)
2257 short red, green, blue;
2259 color_content(current, &red, &green, &blue);
2263 red = (short) (usebase ? (red + value) : value);
2266 green = (short) (usebase ? (green + value) : value);
2269 blue = (short) (usebase ? (blue + value) : value);
2273 if (init_color(current, red, green, blue) == ERR)
2278 init_all_colors(void)
2282 for (c = 0; c < COLORS; ++c)
2285 all_colors[c].green,
2286 all_colors[c].blue);
2289 #define scaled_rgb(n) ((255 * (n)) / 1000)
2293 /* display the color test pattern, without trying to edit colors */
2297 int this_c = 0, value = 0, field = 0;
2300 int page_size = (LINES - 6);
2305 for (i = 0; i < max_colors; i++)
2306 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2308 mvprintw(LINES - 2, 0, "Number: %d", value);
2311 short red, green, blue;
2314 mvaddstr(0, 20, "Color RGB Value Editing");
2317 for (i = (short) top_color;
2318 (i - top_color < page_size)
2319 && (i < max_colors); i++) {
2322 sprintf(numeric, "[%d]", i);
2323 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2324 (i == current ? '>' : ' '),
2325 (i < (int) SIZEOF(the_color_names)
2326 ? the_color_names[i] : numeric));
2327 attrset(COLOR_PAIR(i));
2331 color_content((short) i, &red, &green, &blue);
2333 if (current == i && field == 0)
2335 printw("%04d", red);
2336 if (current == i && field == 0)
2339 if (current == i && field == 1)
2341 printw("%04d", green);
2342 if (current == i && field == 1)
2345 if (current == i && field == 2)
2347 printw("%04d", blue);
2348 if (current == i && field == 2)
2351 printw(" ( %3d %3d %3d )",
2357 mvaddstr(LINES - 3, 0,
2358 "Use up/down to select a color, left/right to change fields.");
2359 mvaddstr(LINES - 2, 0,
2360 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2362 move(2 + current - top_color, 0);
2366 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2373 current -= (page_size - 1);
2380 if (current < (max_colors - 1))
2381 current += (page_size - 1);
2388 current = (current == 0 ? (max_colors - 1) : current - 1);
2393 current = (current == (max_colors - 1) ? 0 : current + 1);
2397 field = (field == 2 ? 0 : field + 1);
2401 field = (field == 0 ? 2 : field - 1);
2414 value = value * 10 + (this_c - '0');
2418 change_color((short) current, field, value, 1);
2422 change_color((short) current, field, -value, 1);
2426 change_color((short) current, field, value, 0);
2431 P(" RGB Value Editing Help");
2433 P("You are in the RGB value editor. Use the arrow keys to select one of");
2434 P("the fields in one of the RGB triples of the current colors; the one");
2435 P("currently selected will be reverse-video highlighted.");
2437 P("To change a field, enter the digits of the new value; they are echoed");
2438 P("as entered. Finish by typing `='. The change will take effect instantly.");
2439 P("To increment or decrement a value, use the same procedure, but finish");
2440 P("with a `+' or `-'.");
2442 P("Press 'm' to invoke the top-level menu with the current color settings.");
2443 P("To quit, do ESC");
2465 if (current >= max_colors)
2466 current = max_colors - 1;
2467 if (current < top_color)
2468 top_color = current;
2469 if (current - top_color >= page_size)
2470 top_color = current - (page_size - 1);
2472 mvprintw(LINES - 1, 0, "Number: %d", value);
2480 * ncurses does not reset each color individually when calling endwin().
2487 /****************************************************************************
2489 * Soft-key label test
2491 ****************************************************************************/
2496 #define SLK_WORK (SLK_HELP + 3)
2501 static const char *table[] =
2503 "Available commands are:"
2505 ,"^L -- repaint this message and activate soft keys"
2506 ,"a/d -- activate/disable soft keys"
2507 ,"c -- set centered format for labels"
2508 ,"l -- set left-justified format for labels"
2509 ,"r -- set right-justified format for labels"
2510 ,"[12345678] -- set label; labels are numbered 1 through 8"
2511 ,"e -- erase stdscr (should not erase labels)"
2512 ,"s -- test scrolling of shortened screen"
2514 ,"F/B -- cycle through foreground/background colors"
2516 ,"ESC -- return to main menu"
2518 ,"Note: if activating the soft keys causes your terminal to scroll up"
2519 ,"one line, your terminal auto-scrolls when anything is written to the"
2520 ,"last screen position. The ncurses code does not yet handle this"
2526 for (j = 0; j < SIZEOF(table); ++j) {
2534 call_slk_color(short fg, short bg)
2536 init_pair(1, bg, fg);
2538 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2546 /* exercise the soft keys */
2552 short fg = COLOR_BLACK;
2553 short bg = COLOR_WHITE;
2559 call_slk_color(fg, bg);
2569 mvaddstr(0, 20, "Soft Key Exerciser");
2584 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2585 while ((c = Getchar()) != 'Q' && (c != ERR))
2613 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2615 if ((s = slk_label(c - '0')) != 0) {
2618 wGetstring(stdscr, buf, 8);
2619 slk_set((c - '0'), buf, fmt);
2631 fg = (short) ((fg + 1) % COLORS);
2632 call_slk_color(fg, bg);
2637 bg = (short) ((bg + 1) % COLORS);
2638 call_slk_color(fg, bg);
2642 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2644 wnoutrefresh(stdscr);
2651 } while (!isQuit(c = Getchar()));
2659 #if USE_WIDEC_SUPPORT
2663 /* exercise the soft keys */
2666 wchar_t buf[SLKLEN + 1];
2668 short fg = COLOR_BLACK;
2669 short bg = COLOR_WHITE;
2673 call_slk_color(fg, bg);
2680 attr_on(WA_BOLD, NULL);
2681 mvaddstr(0, 20, "Soft Key Exerciser");
2682 attr_off(WA_BOLD, NULL);
2696 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2697 while ((c = Getchar()) != 'Q' && (c != ERR))
2725 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2727 if ((s = slk_label(c - '0')) != 0) {
2728 char *temp = strdup(s);
2729 size_t used = strlen(temp);
2730 size_t want = SLKLEN;
2732 #ifndef state_unused
2737 while (want > 0 && used != 0) {
2738 const char *base = s;
2739 reset_mbytes(state);
2740 test = count_mbytes(base, 0, &state);
2741 if (test == (size_t) -1) {
2743 } else if (test > want) {
2746 reset_mbytes(state);
2747 trans_mbytes(buf, base, want, &state);
2753 wGet_wstring(stdscr, buf, SLKLEN);
2754 slk_wset((c - '0'), buf, fmt);
2765 fg = (short) ((fg + 1) % COLORS);
2766 call_slk_color(fg, bg);
2771 bg = (short) ((bg + 1) % COLORS);
2772 call_slk_color(fg, bg);
2775 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2777 wnoutrefresh(stdscr);
2783 } while (!isQuit(c = Getchar()));
2791 #endif /* SLK_INIT */
2793 /****************************************************************************
2795 * Alternate character-set stuff
2797 ****************************************************************************/
2802 } attrs_to_cycle[] = {
2803 { A_NORMAL, "normal" },
2805 { A_REVERSE, "reverse" },
2806 { A_UNDERLINE, "underline" },
2811 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2817 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2822 *at_code = SIZEOF(attrs_to_cycle) - 1;
2831 *attr = attrs_to_cycle[*at_code].attr;
2836 cycle_colors(int ch, int *fg, int *bg, short *pair)
2838 bool result = FALSE;
2848 if ((*fg += 1) >= COLORS)
2856 if ((*bg += 1) >= COLORS)
2864 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2867 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2876 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2877 * terminal to perform functions. The remaining codes can be graphic.
2880 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
2882 bool C1 = (first == 128);
2884 unsigned last = first + 31;
2889 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2890 C1 ? "C1" : "GR", first, last);
2894 for (code = first; code <= last; code++) {
2896 int row = 2 + ((int) (code - first) % 16);
2897 int col = ((int) (code - first) / 16) * COLS / 2;
2899 sprintf(tmp, "%3u (0x%x)", code, code);
2900 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2904 nodelay(stdscr, TRUE);
2905 echochar(code | attr | COLOR_PAIR(pair));
2907 /* (yes, this _is_ crude) */
2908 while ((reply = Getchar()) != ERR) {
2909 addch(UChar(reply));
2912 nodelay(stdscr, FALSE);
2914 } while (--count > 0);
2921 show_pc_chars(int repeat, attr_t attr, short pair)
2927 mvprintw(0, 20, "Display of PC Character Codes");
2931 for (code = 0; code < 16; ++code) {
2932 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
2934 for (code = 0; code < 256; code++) {
2936 int row = 3 + (int) (code / 16) + (code >= 128);
2937 int col = 8 + (int) (code % 16) * PC_COLS;
2938 if ((code % 16) == 0)
2939 mvprintw(row, 0, "0x%02x:", code);
2950 * Skip the ones that do not work.
2954 addch(code | A_ALTCHARSET | attr | COLOR_PAIR(pair));
2957 } while (--count > 0);
2962 show_box_chars(int repeat, attr_t attr, short pair)
2965 attr |= COLOR_PAIR(pair);
2969 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
2974 mvhline(LINES / 2, 0, ACS_HLINE | attr, COLS);
2975 mvvline(0, COLS / 2, ACS_VLINE | attr, LINES);
2976 mvaddch(0, COLS / 2, ACS_TTEE | attr);
2977 mvaddch(LINES / 2, COLS / 2, ACS_PLUS | attr);
2978 mvaddch(LINES - 1, COLS / 2, ACS_BTEE | attr);
2979 mvaddch(LINES / 2, 0, ACS_LTEE | attr);
2980 mvaddch(LINES / 2, COLS - 1, ACS_RTEE | attr);
2986 show_1_acs(int n, int repeat, const char *name, chtype code)
2988 const int height = 16;
2989 int row = 2 + (n % height);
2990 int col = (n / height) * COLS / 2;
2992 mvprintw(row, col, "%*s : ", COLS / 4, name);
2995 } while (--repeat > 0);
3000 show_acs_chars(int repeat, attr_t attr, short pair)
3001 /* display the ACS character set */
3005 #define BOTH(name) #name, (name | attr | COLOR_PAIR(pair))
3009 mvaddstr(0, 20, "Display of the ACS Character Set");
3013 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3014 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3015 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3016 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3018 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3019 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3020 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3021 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3023 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3024 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3027 * HPUX's ACS definitions are broken here. Just give up.
3029 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3030 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3031 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3032 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3033 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3035 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3036 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3037 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3038 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3039 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3040 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3041 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3042 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3043 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3045 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3046 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3047 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3049 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3050 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3051 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3052 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3053 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3054 n = show_1_acs(n, repeat, BOTH(ACS_S9));
3062 char *term = getenv("TERM");
3063 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3066 chtype attr = A_NORMAL;
3069 int fg = COLOR_BLACK;
3070 int bg = COLOR_BLACK;
3071 unsigned at_code = 0;
3073 void (*last_show_acs) (int, attr_t, short) = 0;
3081 ToggleAcs(last_show_acs, show_acs_chars);
3085 ToggleAcs(last_show_acs, show_pc_chars);
3090 ToggleAcs(last_show_acs, show_box_chars);
3116 if (repeat < (COLS / 4))
3124 if (cycle_attr(c, &at_code, &attr)
3125 || cycle_colors(c, &fg, &bg, &pair)) {
3132 if (last_show_acs != 0)
3133 last_show_acs(repeat, attr, pair);
3135 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3137 mvprintw(LINES - 3, 0,
3138 "Note: ANSI terminals may not display C1 characters.");
3139 mvprintw(LINES - 2, 0,
3140 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3143 mvprintw(LINES - 1, 0,
3144 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3145 attrs_to_cycle[at_code].name,
3148 mvprintw(LINES - 1, 0,
3149 "v/V cycles through video attributes (%s).",
3150 attrs_to_cycle[at_code].name);
3153 } while (!isQuit(c = Getchar()));
3160 #if USE_WIDEC_SUPPORT
3162 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3164 int count = getcchar(src, NULL, NULL, NULL, 0);
3171 if ((wch = typeMalloc(wchar_t, (unsigned) count + 1)) != 0) {
3172 if (getcchar(src, wch, &ignore_attr, &ignore_pair, 0) != ERR) {
3173 attr |= (ignore_attr & A_ALTCHARSET);
3174 setcchar(dst, wch, attr, pair, 0);
3183 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3187 int last = first + 31;
3191 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3194 for (code = first; (int) code <= last; code++) {
3195 int row = 2 + ((code - first) % 16);
3196 int col = ((code - first) / 16) * COLS / 2;
3202 memset(&codes, 0, sizeof(codes));
3204 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3205 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3206 setcchar(&temp, codes, attr, pair, 0);
3209 * Give non-spacing characters something to combine with. If we
3210 * don't, they'll bunch up in a heap on the space after the ":".
3211 * Mark them with reverse-video to make them simpler to find on
3214 if (wcwidth(code) == 0)
3215 addch(space | A_REVERSE);
3217 * This could use add_wch(), but is done for comparison with the
3218 * normal 'f' test (and to make a test-case for echo_wchar()).
3219 * The screen will flicker because the erase() at the top of the
3220 * function is met by the builtin refresh() in echo_wchar().
3224 * The repeat-count may make text wrap - avoid that.
3226 getyx(stdscr, y, x);
3227 if (x >= col + (COLS / 2) - 2)
3229 } while (--count > 0);
3234 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3236 const int height = 16;
3237 int row = 2 + (n % height);
3238 int col = (n / height) * COLS / 2;
3240 mvprintw(row, col, "%*s : ", COLS / 4, name);
3241 while (repeat-- >= 0) {
3247 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3250 show_wacs_chars(int repeat, attr_t attr, short pair)
3251 /* display the wide-ACS character set */
3257 /*#define BOTH2(name) #name, &(name) */
3258 #define BOTH2(name) #name, MERGE_ATTR(name)
3262 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3266 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3267 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3268 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3269 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3271 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3272 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3273 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3274 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3276 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3277 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3279 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3280 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3281 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3282 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3284 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3285 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3286 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3287 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3288 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3289 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3290 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3291 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3292 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3294 #ifdef CURSES_WACS_ARRAY
3295 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3296 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3297 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3299 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3300 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3301 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3302 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3303 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3304 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3310 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3313 show_wbox_chars(int repeat, attr_t attr, short pair)
3320 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3324 attr_set(attr, pair, 0);
3325 box_set(stdscr, 0, 0);
3326 attr_set(A_NORMAL, 0, 0);
3328 mvhline_set(LINES / 2, 0, MERGE_ATTR(WACS_HLINE), COLS);
3329 mvvline_set(0, COLS / 2, MERGE_ATTR(WACS_VLINE), LINES);
3330 mvadd_wch(0, COLS / 2, MERGE_ATTR(WACS_TTEE));
3331 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(WACS_PLUS));
3332 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(WACS_BTEE));
3333 mvadd_wch(LINES / 2, 0, MERGE_ATTR(WACS_LTEE));
3334 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(WACS_RTEE));
3342 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3344 const int height = 16;
3345 int row = 2 + (n % height);
3346 int col = (n / height) * COLS / 2;
3349 mvprintw(row, col, "%*s : ", COLS / 4, name);
3350 attr_set(attr, pair, 0);
3351 addstr(strcpy(temp, code));
3352 attr_set(A_NORMAL, 0, 0);
3356 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3359 show_utf8_chars(int repeat, attr_t attr, short pair)
3366 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3370 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3371 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3372 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3373 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3375 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3376 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3377 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3378 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3380 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3381 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3383 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3384 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3385 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3386 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3388 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3389 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3390 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3391 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3392 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3393 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3394 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3395 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3396 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3397 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3398 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3399 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3401 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3402 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3403 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3404 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3405 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3406 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3411 /* display the wide-ACS character set */
3413 wide_acs_display(void)
3419 chtype attr = A_NORMAL;
3420 int fg = COLOR_BLACK;
3421 int bg = COLOR_BLACK;
3422 unsigned at_code = 0;
3424 void (*last_show_wacs) (int, attr_t, short) = 0;
3432 ToggleAcs(last_show_wacs, show_wacs_chars);
3435 ToggleAcs(last_show_wacs, show_wbox_chars);
3438 ToggleAcs(last_show_wacs, show_utf8_chars);
3441 if (c < 256 && isdigit(c)) {
3444 } else if (c == '+') {
3447 } else if (c == '-' && digit > 0) {
3450 } else if (c == '>' && repeat < (COLS / 4)) {
3452 } else if (c == '<' && repeat > 1) {
3454 } else if (c == '_') {
3455 space = (space == ' ') ? '_' : ' ';
3457 } else if (cycle_attr(c, &at_code, &attr)
3458 || cycle_colors(c, &fg, &bg, &pair)) {
3459 if (last_show_wacs != 0)
3467 if (last_show_wacs != 0)
3468 last_show_wacs(repeat, attr, pair);
3470 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3472 mvprintw(LINES - 3, 0,
3473 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3475 mvprintw(LINES - 2, 0,
3476 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3477 attrs_to_cycle[at_code].name,
3480 mvprintw(LINES - 2, 0,
3481 "v/V cycles through video attributes (%s).",
3482 attrs_to_cycle[at_code].name);
3485 } while (!isQuit(c = Getchar()));
3495 * Graphic-rendition test (adapted from vttest)
3498 test_sgr_attributes(void)
3502 for (pass = 0; pass < 2; pass++) {
3503 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3505 /* Use non-default colors if possible to exercise bce a little */
3507 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3508 normal |= COLOR_PAIR(1);
3512 mvprintw(1, 20, "Graphic rendition test pattern:");
3514 mvprintw(4, 1, "vanilla");
3516 #define set_sgr(mask) bkgdset((normal^(mask)));
3518 mvprintw(4, 40, "bold");
3520 set_sgr(A_UNDERLINE);
3521 mvprintw(6, 6, "underline");
3523 set_sgr(A_BOLD | A_UNDERLINE);
3524 mvprintw(6, 45, "bold underline");
3527 mvprintw(8, 1, "blink");
3529 set_sgr(A_BLINK | A_BOLD);
3530 mvprintw(8, 40, "bold blink");
3532 set_sgr(A_UNDERLINE | A_BLINK);
3533 mvprintw(10, 6, "underline blink");
3535 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3536 mvprintw(10, 45, "bold underline blink");
3539 mvprintw(12, 1, "negative");
3541 set_sgr(A_BOLD | A_REVERSE);
3542 mvprintw(12, 40, "bold negative");
3544 set_sgr(A_UNDERLINE | A_REVERSE);
3545 mvprintw(14, 6, "underline negative");
3547 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3548 mvprintw(14, 45, "bold underline negative");
3550 set_sgr(A_BLINK | A_REVERSE);
3551 mvprintw(16, 1, "blink negative");
3553 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3554 mvprintw(16, 40, "bold blink negative");
3556 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3557 mvprintw(18, 6, "underline blink negative");
3559 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3560 mvprintw(18, 45, "bold underline blink negative");
3563 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3569 bkgdset(A_NORMAL | BLANK);
3574 /****************************************************************************
3576 * Windows and scrolling tester.
3578 ****************************************************************************/
3580 #define BOTLINES 4 /* number of line stolen from screen bottom */
3586 #define FRAME struct frame
3595 #if defined(NCURSES_VERSION)
3596 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3597 #define is_keypad(win) (win)->_use_keypad
3598 #define is_scrollok(win) (win)->_scroll
3599 #elif !defined(is_keypad)
3600 #define is_keypad(win) FALSE
3601 #define is_scrollok(win) FALSE
3604 #define is_keypad(win) FALSE
3605 #define is_scrollok(win) FALSE
3609 frame_win(FRAME * curp)
3611 return (curp != 0) ? curp->wind : stdscr;
3614 /* We need to know if these flags are actually set, so don't look in FRAME.
3615 * These names are known to work with SVr4 curses as well as ncurses. The
3616 * _use_keypad name does not work with Solaris 8.
3619 HaveKeypad(FRAME * curp)
3621 WINDOW *win = frame_win(curp);
3623 return is_keypad(win);
3627 HaveScroll(FRAME * curp)
3629 WINDOW *win = frame_win(curp);
3631 return is_scrollok(win);
3635 newwin_legend(FRAME * curp)
3637 static const struct {
3642 "^C = create window", 0
3645 "^N = next window", 0
3648 "^P = previous window", 0
3651 "^F = scroll forward", 0
3654 "^B = scroll backward", 0
3657 "^K = keypad(%s)", 1
3660 "^S = scrollok(%s)", 2
3663 "^W = save window to file", 0
3666 "^R = restore window", 0
3679 bool do_keypad = HaveKeypad(curp);
3680 bool do_scroll = HaveScroll(curp);
3684 for (n = 0; n < SIZEOF(legend); n++) {
3685 switch (legend[n].code) {
3687 strcpy(buf, legend[n].msg);
3690 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3693 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3696 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3699 x = getcurx(stdscr);
3700 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3707 transient(FRAME * curp, NCURSES_CONST char *msg)
3709 newwin_legend(curp);
3711 mvaddstr(LINES - 1, 0, msg);
3717 printw("%s characters are echoed, window should %sscroll.",
3718 HaveKeypad(curp) ? "Non-arrow" : "All other",
3719 HaveScroll(curp) ? "" : "not ");
3724 newwin_report(FRAME * curp)
3725 /* report on the cursor's current position, then restore it */
3727 WINDOW *win = frame_win(curp);
3731 transient(curp, (char *) 0);
3733 move(LINES - 1, COLS - 17);
3734 printw("Y = %2d X = %2d", y, x);
3742 selectcell(int uli, int ulj, int lri, int lrj)
3743 /* arrows keys move cursor, return location at current on non-arrow key */
3745 static pair res; /* result cell */
3746 int si = lri - uli + 1; /* depth of the select area */
3747 int sj = lrj - ulj + 1; /* width of the select area */
3748 int i = 0, j = 0; /* offsets into the select area */
3753 move(uli + i, ulj + j);
3754 newwin_report((FRAME *) 0);
3756 switch (Getchar()) {
3770 return ((pair *) 0);
3771 #ifdef NCURSES_MOUSE_VERSION
3777 if (event.y > uli && event.x > ulj) {
3798 outerbox(pair ul, pair lr, bool onoff)
3799 /* draw or erase a box *outside* the given pair of corners */
3801 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3802 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3803 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3804 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3805 move(ul.y - 1, ul.x);
3806 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3807 move(ul.y, ul.x - 1);
3808 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3809 move(lr.y + 1, ul.x);
3810 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3811 move(ul.y, lr.x + 1);
3812 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3817 /* Ask user for a window definition */
3824 addstr("Use arrows to move cursor, anything else to mark corner 1");
3826 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3827 return ((WINDOW *) 0);
3828 memcpy(&ul, tmp, sizeof(pair));
3829 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3832 addstr("Use arrows to move cursor, anything else to mark corner 2");
3834 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
3836 return ((WINDOW *) 0);
3837 memcpy(&lr, tmp, sizeof(pair));
3839 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
3841 outerbox(ul, lr, TRUE);
3852 newwin_move(FRAME * curp, int dy, int dx)
3854 WINDOW *win = frame_win(curp);
3858 getyx(win, cur_y, cur_x);
3859 getmaxyx(win, max_y, max_x);
3860 if ((cur_x += dx) < 0)
3862 else if (cur_x >= max_x)
3864 if ((cur_y += dy) < 0)
3866 else if (cur_y >= max_y)
3868 wmove(win, cur_y, cur_x);
3872 delete_framed(FRAME * fp, bool showit)
3877 fp->last->next = fp->next;
3878 fp->next->last = fp->last;
3886 np = (fp == fp->next) ? 0 : fp->next;
3893 acs_and_scroll(void)
3894 /* Demonstrate windows */
3897 FRAME *current = (FRAME *) 0, *neww;
3898 WINDOW *usescr = stdscr;
3899 #if HAVE_PUTWIN && HAVE_GETWIN
3903 #define DUMPFILE "screendump"
3905 #ifdef NCURSES_MOUSE_VERSION
3906 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
3911 transient((FRAME *) 0, (char *) 0);
3914 if ((neww = typeCalloc(FRAME, 1)) == 0) {
3917 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
3922 if (current == 0) { /* First element, */
3923 neww->next = neww; /* so point it at itself */
3926 neww->next = current->next;
3927 neww->last = current;
3928 neww->last->next = neww;
3929 neww->next->last = neww;
3932 /* SVr4 curses sets the keypad on all newly-created windows to
3933 * false. Someone reported that PDCurses makes new windows inherit
3934 * this flag. Remove the following 'keypad()' call to test this
3936 keypad(current->wind, TRUE);
3937 current->do_keypad = HaveKeypad(current);
3938 current->do_scroll = HaveScroll(current);
3941 case CTRL('N'): /* go to next window */
3943 current = current->next;
3946 case CTRL('P'): /* go to previous window */
3948 current = current->last;
3951 case CTRL('F'): /* scroll current window forward */
3953 wscrl(frame_win(current), 1);
3956 case CTRL('B'): /* scroll current window backwards */
3958 wscrl(frame_win(current), -1);
3961 case CTRL('K'): /* toggle keypad mode for current */
3963 current->do_keypad = !current->do_keypad;
3964 keypad(current->wind, current->do_keypad);
3970 current->do_scroll = !current->do_scroll;
3971 scrollok(current->wind, current->do_scroll);
3975 #if HAVE_PUTWIN && HAVE_GETWIN
3976 case CTRL('W'): /* save and delete window */
3977 if ((current != 0) && (current == current->next)) {
3978 transient(current, "Will not save/delete ONLY window");
3980 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
3981 transient(current, "Can't open screen dump file");
3983 (void) putwin(frame_win(current), fp);
3986 current = delete_framed(current, TRUE);
3990 case CTRL('R'): /* restore window */
3991 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
3992 transient(current, "Can't open screen dump file");
3994 if ((neww = typeCalloc(FRAME, 1)) != 0) {
3996 neww->next = current ? current->next : 0;
3997 neww->last = current;
3998 neww->last->next = neww;
3999 neww->next->last = neww;
4001 neww->wind = getwin(fp);
4003 wrefresh(neww->wind);
4011 case CTRL('X'): /* resize window */
4018 addstr("Use arrows to move cursor, anything else to mark new corner");
4021 getbegyx(current->wind, ul.y, ul.x);
4023 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4024 if (tmp == (pair *) 0) {
4029 getmaxyx(current->wind, lr.y, lr.x);
4032 outerbox(ul, lr, FALSE);
4033 wnoutrefresh(stdscr);
4035 /* strictly cosmetic hack for the test */
4036 getmaxyx(current->wind, my, mx);
4037 if (my > tmp->y - ul.y) {
4038 getyx(current->wind, lr.y, lr.x);
4039 wmove(current->wind, tmp->y - ul.y + 1, 0);
4040 wclrtobot(current->wind);
4041 wmove(current->wind, lr.y, lr.x);
4043 if (mx > tmp->x - ul.x)
4044 for (i = 0; i < my; i++) {
4045 wmove(current->wind, i, tmp->x - ul.x + 1);
4046 wclrtoeol(current->wind);
4048 wnoutrefresh(current->wind);
4050 memcpy(&lr, tmp, sizeof(pair));
4051 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4053 getbegyx(current->wind, ul.y, ul.x);
4054 getmaxyx(current->wind, lr.y, lr.x);
4057 outerbox(ul, lr, TRUE);
4058 wnoutrefresh(stdscr);
4060 wnoutrefresh(current->wind);
4066 #endif /* HAVE_WRESIZE */
4068 case KEY_F(10): /* undocumented --- use this to test area clears */
4069 selectcell(0, 0, LINES - 1, COLS - 1);
4075 newwin_move(current, -1, 0);
4078 newwin_move(current, 1, 0);
4081 newwin_move(current, 0, -1);
4084 newwin_move(current, 0, 1);
4092 getyx(frame_win(current), y, x);
4096 x = getmaxx(frame_win(current)) - 1;
4098 mvwdelch(frame_win(current), y, x);
4108 waddch(current->wind, (chtype) c);
4113 newwin_report(current);
4114 usescr = frame_win(current);
4117 (!isQuit(c = wGetchar(usescr))
4121 while (current != 0)
4122 current = delete_framed(current, FALSE);
4124 scrollok(stdscr, TRUE); /* reset to driver's default */
4125 #ifdef NCURSES_MOUSE_VERSION
4126 mousemask(0, (mmask_t *) 0);
4133 /****************************************************************************
4137 ****************************************************************************/
4140 static int nap_msec = 1;
4142 static NCURSES_CONST char *mod[] =
4152 /*+-------------------------------------------------------------------------
4154 --------------------------------------------------------------------------*/
4156 wait_a_while(int msec GCC_UNUSED)
4166 else if (msec > 1000)
4167 sleep((unsigned) msec / 1000);
4171 } /* end of wait_a_while */
4173 /*+-------------------------------------------------------------------------
4175 --------------------------------------------------------------------------*/
4177 saywhat(NCURSES_CONST char *text)
4179 wmove(stdscr, LINES - 1, 0);
4181 if (text != 0 && *text != '\0') {
4182 waddstr(stdscr, text);
4183 waddstr(stdscr, "; ");
4185 waddstr(stdscr, "press any key to continue");
4186 } /* end of saywhat */
4188 /*+-------------------------------------------------------------------------
4189 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4190 --------------------------------------------------------------------------*/
4192 mkpanel(short color, int rows, int cols, int tly, int tlx)
4197 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4198 if ((pan = new_panel(win)) == 0) {
4200 } else if (use_colors) {
4201 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4204 init_pair(color, fg, bg);
4205 wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
4207 wbkgdset(win, A_BOLD | ' ');
4211 } /* end of mkpanel */
4213 /*+-------------------------------------------------------------------------
4215 --------------------------------------------------------------------------*/
4217 rmpanel(PANEL * pan)
4219 WINDOW *win = panel_window(pan);
4222 } /* end of rmpanel */
4224 /*+-------------------------------------------------------------------------
4226 --------------------------------------------------------------------------*/
4232 } /* end of pflush */
4234 /*+-------------------------------------------------------------------------
4236 --------------------------------------------------------------------------*/
4242 for (y = 0; y < LINES - 1; y++) {
4243 for (x = 0; x < COLS; x++)
4244 wprintw(stdscr, "%d", (y + x) % 10);
4249 fill_panel(PANEL * pan)
4251 WINDOW *win = panel_window(pan);
4252 const char *userptr = (const char *) panel_userptr(pan);
4253 int num = (userptr && *userptr) ? userptr[1] : '?';
4257 wprintw(win, "-pan%c-", num);
4260 for (y = 2; y < getmaxy(win) - 1; y++) {
4261 for (x = 1; x < getmaxx(win) - 1; x++) {
4263 waddch(win, UChar(num));
4268 #if USE_WIDEC_SUPPORT
4270 init_wide_panel(void)
4275 for (digit = 0; digit < 10; ++digit)
4276 make_fullwidth_digit(&temp[digit], digit);
4280 getyx(stdscr, y, x);
4281 digit = (y + x / 2) % 10;
4282 } while (add_wch(&temp[digit]) != ERR);
4286 fill_wide_panel(PANEL * pan)
4288 WINDOW *win = panel_window(pan);
4289 const char *userptr = (const char *) panel_userptr(pan);
4290 int num = (userptr && *userptr) ? userptr[1] : '?';
4294 wprintw(win, "-pan%c-", num);
4297 for (y = 2; y < getmaxy(win) - 1; y++) {
4298 for (x = 1; x < getmaxx(win) - 1; x++) {
4300 waddch(win, UChar(num));
4306 #define MAX_PANELS 5
4309 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4311 int which = cmd[1] - '0';
4316 hide_panel(px[which]);
4319 show_panel(px[which]);
4322 top_panel(px[which]);
4325 bottom_panel(px[which]);
4332 wait_a_while(nap_msec);
4336 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4340 PANEL *px[MAX_PANELS + 1];
4342 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4346 for (count = 0; count < 5; count++) {
4347 px[1] = mkpanel(COLOR_RED,
4352 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4354 px[2] = mkpanel(COLOR_GREEN,
4359 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4361 px[3] = mkpanel(COLOR_YELLOW,
4366 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4368 px[4] = mkpanel(COLOR_BLUE,
4373 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4375 px[5] = mkpanel(COLOR_MAGENTA,
4380 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4392 wait_a_while(nap_msec);
4394 saywhat("h3 s1 s2 s4 s5");
4395 move_panel(px[1], 0, 0);
4402 wait_a_while(nap_msec);
4404 canned_panel(px, "s1");
4405 canned_panel(px, "s2");
4408 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4410 wait_a_while(nap_msec);
4412 canned_panel(px, "s3");
4415 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4417 wait_a_while(nap_msec);
4419 canned_panel(px, "b3");
4420 canned_panel(px, "s4");
4421 canned_panel(px, "s5");
4422 canned_panel(px, "t3");
4423 canned_panel(px, "t1");
4424 canned_panel(px, "t2");
4425 canned_panel(px, "t3");
4426 canned_panel(px, "t4");
4428 for (itmp = 0; itmp < 6; itmp++) {
4429 WINDOW *w4 = panel_window(px[4]);
4430 WINDOW *w5 = panel_window(px[5]);
4433 wmove(w4, LINES / 8, 1);
4434 waddstr(w4, mod[itmp]);
4435 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4436 wmove(w5, LINES / 6, 1);
4437 waddstr(w5, mod[itmp]);
4439 wait_a_while(nap_msec);
4442 wmove(w4, LINES / 6, 1);
4443 waddstr(w4, mod[itmp]);
4444 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4445 wmove(w5, LINES / 8, 1);
4446 waddstr(w5, mod[itmp]);
4448 wait_a_while(nap_msec);
4452 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4454 wait_a_while(nap_msec);
4456 canned_panel(px, "t5");
4457 canned_panel(px, "t2");
4458 canned_panel(px, "t1");
4459 canned_panel(px, "d2");
4460 canned_panel(px, "h3");
4461 canned_panel(px, "d1");
4462 canned_panel(px, "d4");
4463 canned_panel(px, "d5");
4464 canned_panel(px, "d3");
4466 wait_a_while(nap_msec);
4475 #endif /* USE_LIBPANEL */
4477 /****************************************************************************
4481 ****************************************************************************/
4485 static bool pending_pan = FALSE;
4486 static bool show_panner_legend = TRUE;
4489 panner_legend(int line)
4491 static const char *const legend[] =
4493 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4494 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4495 "Use <,> (or h,l) to grow/shrink the panner horizontally.",