1 /****************************************************************************
2 * Copyright (c) 1998-2014,2015 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.425 2015/11/29 01:26:41 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
110 #ifdef CURSES_WACS_ARRAY
111 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
112 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
113 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
114 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
115 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
116 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
117 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
124 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
125 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
126 #define reset_wchars(state) init_mb(state)
127 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
128 #define count_wchars(src, len, state) wcstombs(0, src, len)
129 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
130 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
135 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
136 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
137 #define reset_mbytes(state) init_mb(state)
138 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
139 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
140 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
141 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
145 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
147 #define P(string) printw("%s\n", string)
149 #define BLANK ' ' /* this is the background character */
152 static int max_colors; /* the actual number of colors we'll use */
153 static int min_colors; /* the minimum color code */
154 static bool use_colors; /* true if we use colors */
157 static int max_pairs; /* ...and the number of color pairs */
161 NCURSES_COLOR_T green;
162 NCURSES_COLOR_T blue;
165 static RGB_DATA *all_colors;
167 static void main_menu(bool);
170 failed(const char *s)
174 ExitProgram(EXIT_FAILURE);
177 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
178 * though we can rely on negative x/y values to stop the macro.
181 do_h_line(int y, int x, chtype c, int to)
184 MvHLine(y, x, c, (to) - (x));
188 do_v_line(int y, int x, chtype c, int to)
191 MvVLine(y, x, c, (to) - (y));
205 return ((c) == QUIT || (c) == ESCAPE);
207 #define case_QUIT QUIT: case ESCAPE
209 /* Common function to allow ^T to toggle trace-mode in the middle of a test
210 * so that trace-files can be made smaller.
213 wGetchar(WINDOW *win)
217 while ((c = wgetch(win)) == CTRL('T')) {
219 save_trace = _nc_tracing;
220 Trace(("TOGGLE-TRACING OFF"));
223 _nc_tracing = save_trace;
227 Trace(("TOGGLE-TRACING ON"));
234 #define Getchar() wGetchar(stdscr)
236 /* replaces wgetnstr(), since we want to be able to edit values */
238 wGetstring(WINDOW *win, char *buffer, int limit)
245 (void) wattrset(win, A_REVERSE);
247 x = (int) strlen(buffer);
249 if (x > (int) strlen(buffer))
250 x = (int) strlen(buffer);
252 wprintw(win, "%-*s", limit, buffer);
253 wmove(win, y0, x0 + x);
254 switch (ch = wGetchar(win)) {
267 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
285 if (!isprint(ch) || ch >= KEY_MIN) {
287 } else if ((int) strlen(buffer) < limit) {
289 for (j = (int) strlen(buffer) + 1; j > x; --j) {
290 buffer[j] = buffer[j - 1];
292 buffer[x++] = (char) ch;
299 wattroff(win, A_REVERSE);
304 #if USE_WIDEC_SUPPORT
306 fullwidth_digit(int ch)
308 return (wchar_t) (ch + 0xff10 - '0');
312 make_fullwidth_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = fullwidth_digit(ch);
322 make_narrow_text(wchar_t *target, const char *source)
325 while ((ch = *source++) != 0) {
326 *target++ = (wchar_t) ch;
333 make_fullwidth_digit(cchar_t *target, int digit)
337 source[0] = fullwidth_digit(digit + '0');
339 setcchar(target, source, A_NORMAL, 0, 0);
344 wGet_wchar(WINDOW *win, wint_t *result)
348 while ((c = wget_wch(win, result)) == CTRL('T')) {
350 save_trace = _nc_tracing;
351 Trace(("TOGGLE-TRACING OFF"));
354 _nc_tracing = save_trace;
358 Trace(("TOGGLE-TRACING ON"));
361 c = wget_wch(win, result);
365 #define Get_wchar(result) wGet_wchar(stdscr, result)
367 /* replaces wgetn_wstr(), since we want to be able to edit values */
369 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
378 (void) wattrset(win, A_REVERSE);
380 x = (int) wcslen(buffer);
382 if (x > (int) wcslen(buffer))
383 x = (int) wcslen(buffer);
385 /* clear the "window' */
387 wprintw(win, "%*s", limit, " ");
389 /* write the existing buffer contents */
391 waddnwstr(win, buffer, limit);
393 /* positions the cursor past character 'x' */
395 waddnwstr(win, buffer, x);
397 switch (wGet_wchar(win, &ch)) {
437 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
457 } else if ((int) wcslen(buffer) < limit) {
459 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
460 buffer[j] = buffer[j - 1];
462 buffer[x++] = (wchar_t) ch;
469 wattroff(win, A_REVERSE);
480 addstr("Press any key to continue... ");
485 Cannot(const char *what)
487 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
492 ShellOut(bool message)
495 addstr("Shelling out...");
501 IGNORE_RC(system("sh"));
504 addstr("returned from shellout.\n");
508 #ifdef NCURSES_MOUSE_VERSION
510 * This function is the same as _tracemouse(), but we cannot count on that
511 * being available in the non-debug library.
514 mouse_decode(MEVENT const *ep)
516 static char buf[80 + (5 * 10) + (32 * 15)];
518 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
519 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
521 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
523 SHOW(BUTTON1_RELEASED, "release-1");
524 SHOW(BUTTON1_PRESSED, "press-1");
525 SHOW(BUTTON1_CLICKED, "click-1");
526 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
527 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
528 #if NCURSES_MOUSE_VERSION == 1
529 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
532 SHOW(BUTTON2_RELEASED, "release-2");
533 SHOW(BUTTON2_PRESSED, "press-2");
534 SHOW(BUTTON2_CLICKED, "click-2");
535 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
536 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
537 #if NCURSES_MOUSE_VERSION == 1
538 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
541 SHOW(BUTTON3_RELEASED, "release-3");
542 SHOW(BUTTON3_PRESSED, "press-3");
543 SHOW(BUTTON3_CLICKED, "click-3");
544 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
545 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
546 #if NCURSES_MOUSE_VERSION == 1
547 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
550 SHOW(BUTTON4_RELEASED, "release-4");
551 SHOW(BUTTON4_PRESSED, "press-4");
552 SHOW(BUTTON4_CLICKED, "click-4");
553 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
554 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
555 #if NCURSES_MOUSE_VERSION == 1
556 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
559 #if NCURSES_MOUSE_VERSION == 2
560 SHOW(BUTTON5_RELEASED, "release-5");
561 SHOW(BUTTON5_PRESSED, "press-5");
562 SHOW(BUTTON5_CLICKED, "click-5");
563 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
564 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
567 SHOW(BUTTON_CTRL, "ctrl");
568 SHOW(BUTTON_SHIFT, "shift");
569 SHOW(BUTTON_ALT, "alt");
570 SHOW(ALL_MOUSE_EVENTS, "all-events");
571 SHOW(REPORT_MOUSE_POSITION, "position");
575 if (buf[strlen(buf) - 1] == ' ')
576 buf[strlen(buf) - 2] = '\0';
577 (void) strcat(buf, "}");
582 show_mouse(WINDOW *win)
590 outside = !wenclose(win, event.y, event.x);
593 (void) wstandout(win);
594 waddstr(win, "KEY_MOUSE");
595 (void) wstandend(win);
597 waddstr(win, "KEY_MOUSE");
599 wprintw(win, ", %s", mouse_decode(&event));
604 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
608 wmove(win, event.y, event.x);
616 #endif /* NCURSES_MOUSE_VERSION */
618 /****************************************************************************
620 * Character input test
622 ****************************************************************************/
624 #define NUM_GETCH_FLAGS 256
625 typedef bool GetchFlags[NUM_GETCH_FLAGS];
628 setup_getch(WINDOW *win, GetchFlags flags)
630 keypad(win, flags['k']); /* should be redundant, but for testing */
631 meta(win, flags['m']); /* force this to a known state */
639 init_getch(WINDOW *win, GetchFlags flags, int delay)
641 memset(flags, FALSE, NUM_GETCH_FLAGS);
642 flags[UChar('k')] = (win == stdscr);
643 flags[UChar('m')] = TRUE;
644 flags[UChar('t')] = (delay != 0);
646 setup_getch(win, flags);
650 blocking_getch(GetchFlags flags, int delay)
652 return ((delay < 0) && flags['t']);
656 wgetch_help(WINDOW *win, GetchFlags flags)
658 static const char *help[] =
660 "e -- toggle echo mode"
661 ,"g -- triggers a getstr test"
662 ,"k -- toggle keypad/literal mode"
663 ,"m -- toggle meta (7-bit/8-bit) mode"
666 ,"t -- toggle timeout"
667 ,"w -- create a new window"
669 ,"z -- suspend this process"
673 unsigned chk = ((SIZEOF(help) + 1) / 2);
678 printw("Type any key to see its %s value. Also:\n",
679 flags['k'] ? "keypad" : "literal");
680 for (n = 0; n < SIZEOF(help); ++n) {
681 int row = 1 + (int) (n % chk);
682 int col = (n >= chk) ? COLS / 2 : 0;
683 int flg = ((strstr(help[n], "toggle") != 0)
684 && (flags[UChar(*help[n])] != FALSE));
687 MvPrintw(row, col, "%s", help[n]);
698 wgetch_wrap(WINDOW *win, int first_y)
700 int last_y = getmaxy(win) - 1;
701 int y = getcury(win) + 1;
709 #if defined(KEY_RESIZE) && HAVE_WRESIZE
715 static WINSTACK *winstack = 0;
716 static unsigned len_winstack = 0;
729 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
731 unsigned need = (level + 1) * 2;
733 assert(level < (unsigned) COLS);
737 winstack = typeMalloc(WINSTACK, len_winstack);
738 } else if (need >= len_winstack) {
740 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
743 failed("remember_boxes");
744 winstack[level].text = txt_win;
745 winstack[level].frame = box_win;
748 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
752 /* this chunk is now done in resize_term() */
759 #define slk_repaint() /* nothing */
762 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
764 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
765 * Resize both and paint the box in the parent.
768 resize_boxes(unsigned level, WINDOW *win)
772 int high = LINES - base;
776 wnoutrefresh(stdscr);
780 for (n = 0; n < level; ++n) {
781 wresize(winstack[n].frame, high, wide);
782 wresize(winstack[n].text, high - 2, wide - 2);
785 werase(winstack[n].text);
786 box(winstack[n].frame, 0, 0);
787 wnoutrefresh(winstack[n].frame);
788 wprintw(winstack[n].text,
790 getmaxy(winstack[n].text),
791 getmaxx(winstack[n].text));
792 wnoutrefresh(winstack[n].text);
793 if (winstack[n].text == win)
798 #endif /* resize_boxes */
800 #define forget_boxes() /* nothing */
801 #define remember_boxes(level,text,frame) /* nothing */
805 * Return-code is OK/ERR or a keyname.
810 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
814 wgetch_test(unsigned level, WINDOW *win, int delay)
817 int first_y, first_x;
822 init_getch(win, flags, delay);
823 notimeout(win, FALSE);
824 wtimeout(win, delay);
825 getyx(win, first_y, first_x);
827 wgetch_help(win, flags);
828 wsetscrreg(win, first_y, getmaxy(win) - 1);
832 while ((c = wGetchar(win)) == ERR) {
834 if (blocking_getch(flags, delay)) {
835 (void) wprintw(win, "%05d: input error", incount);
838 (void) wprintw(win, "%05d: input timed out", incount);
840 wgetch_wrap(win, first_y);
842 if (c == ERR && blocking_getch(flags, delay)) {
844 wgetch_wrap(win, first_y);
845 } else if (isQuit(c)) {
847 } else if (c == 'e') {
848 flags[UChar('e')] = !flags[UChar('e')];
849 setup_getch(win, flags);
850 wgetch_help(win, flags);
851 } else if (c == 'g') {
852 waddstr(win, "getstr test: ");
854 c = wgetnstr(win, buf, sizeof(buf) - 1);
856 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
857 (int) strlen(buf), buf,
860 wgetch_wrap(win, first_y);
861 } else if (c == 'k') {
862 flags[UChar('k')] = !flags[UChar('k')];
863 setup_getch(win, flags);
864 wgetch_help(win, flags);
865 } else if (c == 'm') {
866 flags[UChar('m')] = !flags[UChar('m')];
867 setup_getch(win, flags);
868 wgetch_help(win, flags);
869 } else if (c == 's') {
871 } else if (c == 't') {
872 notimeout(win, flags[UChar('t')]);
873 flags[UChar('t')] = !flags[UChar('t')];
874 wgetch_help(win, flags);
875 } else if (c == 'w') {
876 int high = getmaxy(win) - 1 - first_y + 1;
877 int wide = getmaxx(win) - first_x;
879 int new_y = first_y + getbegy(win);
880 int new_x = first_x + getbegx(win);
882 getyx(win, old_y, old_x);
883 if (high > 2 && wide > 2) {
884 WINDOW *wb = newwin(high, wide, new_y, new_x);
885 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
890 remember_boxes(level, wi, wb);
891 wgetch_test(level + 1, wi, delay);
895 wgetch_help(win, flags);
896 wmove(win, old_y, old_x);
902 } else if (c == 'z') {
903 kill(getpid(), SIGTSTP);
906 wprintw(win, "Key pressed: %04o ", c);
907 #ifdef NCURSES_MOUSE_VERSION
908 if (c == KEY_MOUSE) {
911 #endif /* NCURSES_MOUSE_VERSION */
913 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
914 if (c == KEY_RESIZE) {
915 resize_boxes(level, win);
918 (void) waddstr(win, keyname(c));
919 } else if (c >= 0x80) {
920 unsigned c2 = (unsigned) c;
921 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
922 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
926 (void) wprintw(win, "%c", UChar(c));
927 else if (c2 != UChar(c))
928 (void) wprintw(win, "M-%s", unctrl(c2));
930 (void) wprintw(win, "%s", unctrl(c2));
931 waddstr(win, " (high-half character)");
934 (void) wprintw(win, "%c (ASCII printable character)", c);
936 (void) wprintw(win, "%s (ASCII control character)",
939 wgetch_wrap(win, first_y);
946 init_getch(win, flags, delay);
950 begin_getch_test(void)
957 #ifdef NCURSES_MOUSE_VERSION
958 mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, (mmask_t *) 0);
961 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
963 getnstr(buf, sizeof(buf) - 1);
967 if (isdigit(UChar(buf[0]))) {
968 delay = atoi(buf) * 100;
978 finish_getch_test(void)
980 #ifdef NCURSES_MOUSE_VERSION
981 mousemask(0, (mmask_t *) 0);
992 int delay = begin_getch_test();
995 wgetch_test(0, stdscr, delay);
1001 #if USE_WIDEC_SUPPORT
1003 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
1004 * Resize both and paint the box in the parent.
1006 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1008 resize_wide_boxes(unsigned level, WINDOW *win)
1012 int high = LINES - base;
1016 wnoutrefresh(stdscr);
1020 for (n = 0; n < level; ++n) {
1021 wresize(winstack[n].frame, high, wide);
1022 wresize(winstack[n].text, high - 2, wide - 2);
1025 werase(winstack[n].text);
1026 box_set(winstack[n].frame, 0, 0);
1027 wnoutrefresh(winstack[n].frame);
1028 wprintw(winstack[n].text,
1030 getmaxy(winstack[n].text),
1031 getmaxx(winstack[n].text));
1032 wnoutrefresh(winstack[n].text);
1033 if (winstack[n].text == win)
1038 #endif /* KEY_RESIZE */
1041 wcstos(const wchar_t *src)
1045 const wchar_t *tmp = src;
1046 #ifndef state_unused
1050 reset_wchars(state);
1051 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1052 unsigned have = (unsigned) need;
1053 if ((result = typeCalloc(char, have + 1)) != 0) {
1055 if (trans_wchars(result, tmp, have, &state) != have) {
1067 wget_wch_test(unsigned level, WINDOW *win, int delay)
1069 wchar_t wchar_buf[BUFSIZ];
1070 wint_t wint_buf[BUFSIZ];
1071 int first_y, first_x;
1078 init_getch(win, flags, delay);
1079 notimeout(win, FALSE);
1080 wtimeout(win, delay);
1081 getyx(win, first_y, first_x);
1083 wgetch_help(win, flags);
1084 wsetscrreg(win, first_y, getmaxy(win) - 1);
1085 scrollok(win, TRUE);
1088 while ((code = wGet_wchar(win, &c)) == ERR) {
1090 if (blocking_getch(flags, delay)) {
1091 (void) wprintw(win, "%05d: input error", incount);
1094 (void) wprintw(win, "%05d: input timed out", incount);
1096 wgetch_wrap(win, first_y);
1098 if (code == ERR && blocking_getch(flags, delay)) {
1099 wprintw(win, "ERR");
1100 wgetch_wrap(win, first_y);
1101 } else if (isQuit((int) c)) {
1103 } else if (c == 'e') {
1104 flags[UChar('e')] = !flags[UChar('e')];
1105 setup_getch(win, flags);
1106 wgetch_help(win, flags);
1107 } else if (c == 'g') {
1108 waddstr(win, "getstr test: ");
1110 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1113 wprintw(win, "wgetn_wstr returns an error.");
1116 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1119 if ((temp = wcstos(wchar_buf)) != 0) {
1120 wprintw(win, "I saw %d characters:\n\t`%s'.",
1121 (int) wcslen(wchar_buf), temp);
1124 wprintw(win, "I saw %d characters (cannot convert).",
1125 (int) wcslen(wchar_buf));
1129 wgetch_wrap(win, first_y);
1130 } else if (c == 'k') {
1131 flags[UChar('k')] = !flags[UChar('k')];
1132 setup_getch(win, flags);
1133 wgetch_help(win, flags);
1134 } else if (c == 'm') {
1135 flags[UChar('m')] = !flags[UChar('m')];
1136 setup_getch(win, flags);
1137 wgetch_help(win, flags);
1138 } else if (c == 's') {
1140 } else if (c == 't') {
1141 notimeout(win, flags[UChar('t')]);
1142 flags[UChar('t')] = !flags[UChar('t')];
1143 wgetch_help(win, flags);
1144 } else if (c == 'w') {
1145 int high = getmaxy(win) - 1 - first_y + 1;
1146 int wide = getmaxx(win) - first_x;
1148 int new_y = first_y + getbegy(win);
1149 int new_x = first_x + getbegx(win);
1151 getyx(win, old_y, old_x);
1152 if (high > 2 && wide > 2) {
1153 WINDOW *wb = newwin(high, wide, new_y, new_x);
1154 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1159 remember_boxes(level, wi, wb);
1160 wget_wch_test(level + 1, wi, delay);
1164 wgetch_help(win, flags);
1165 wmove(win, old_y, old_x);
1170 } else if (c == 'z') {
1171 kill(getpid(), SIGTSTP);
1174 wprintw(win, "Key pressed: %04o ", (int) c);
1175 #ifdef NCURSES_MOUSE_VERSION
1176 if (c == KEY_MOUSE) {
1179 #endif /* NCURSES_MOUSE_VERSION */
1180 if (code == KEY_CODE_YES) {
1181 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1182 if (c == KEY_RESIZE) {
1183 resize_wide_boxes(level, win);
1186 (void) waddstr(win, keyname((wchar_t) c));
1188 (void) waddstr(win, key_name((wchar_t) c));
1189 if (c < 256 && iscntrl(c)) {
1190 (void) wprintw(win, " (control character)");
1192 (void) wprintw(win, " = %#x (printable character)",
1196 wgetch_wrap(win, first_y);
1203 init_getch(win, flags, delay);
1209 int delay = begin_getch_test();
1212 wget_wch_test(0, stdscr, delay);
1214 finish_getch_test();
1219 /****************************************************************************
1221 * Character attributes test
1223 ****************************************************************************/
1225 #if HAVE_SETUPTERM || HAVE_TGETENT
1226 #define get_ncv() TIGETNUM("ncv","NC")
1227 #define get_xmc() TIGETNUM("xmc","sg")
1229 #define get_ncv() -1
1230 #define get_xmc() -1
1237 static int first = TRUE;
1238 static chtype result = 0;
1244 char *area_pointer = parsed;
1246 tgetent(buffer, getenv("TERM"));
1249 if (TIGETSTR("smso", "so"))
1250 result |= A_STANDOUT;
1251 if (TIGETSTR("smul", "us"))
1252 result |= A_UNDERLINE;
1253 if (TIGETSTR("rev", "mr"))
1254 result |= A_REVERSE;
1255 if (TIGETSTR("blink", "mb"))
1257 if (TIGETSTR("dim", "mh"))
1259 if (TIGETSTR("bold", "md"))
1261 if (TIGETSTR("smacs", "ac"))
1262 result |= A_ALTCHARSET;
1268 #define termattrs() my_termattrs()
1271 #define ATTRSTRING_1ST 32 /* ' ' */
1272 #define ATTRSTRING_END 126 /* '~' */
1274 #define COLS_PRE_ATTRS 5
1275 #define COLS_AFT_ATTRS 15
1276 #define COL_ATTRSTRING (COLS_PRE_ATTRS + 17)
1277 #define LEN_ATTRSTRING (COLS - (COL_ATTRSTRING + COLS_AFT_ATTRS))
1278 #define MAX_ATTRSTRING (ATTRSTRING_END + 1 - ATTRSTRING_1ST)
1280 static char attr_test_string[MAX_ATTRSTRING + 1];
1283 attr_legend(WINDOW *helpwin)
1288 MvWPrintw(helpwin, row++, col,
1290 MvWPrintw(helpwin, row++, col,
1293 MvWPrintw(helpwin, row++, col,
1294 "Modify the test strings:");
1295 MvWPrintw(helpwin, row++, col,
1296 " A digit sets gaps on each side of displayed attributes");
1297 MvWPrintw(helpwin, row++, col,
1298 " </> shifts the text left/right. ");
1300 MvWPrintw(helpwin, row++, col,
1303 MvWPrintw(helpwin, row++, col,
1304 " f/F/b/F toggle foreground/background background color");
1305 MvWPrintw(helpwin, row++, col,
1306 " t/T toggle text/background color attribute");
1308 MvWPrintw(helpwin, row++, col,
1309 " a/A toggle ACS (alternate character set) mapping");
1310 MvWPrintw(helpwin, row, col,
1311 " v/V toggle video attribute to combine with each line");
1312 #if USE_WIDEC_SUPPORT
1313 MvWPrintw(helpwin, row, col,
1314 " w/W toggle normal/wide (double-width) test-characters");
1319 show_color_attr(int fg, int bg, int tx)
1322 printw(" Colors (fg %d, bg %d", fg, bg);
1324 printw(", text %d", tx);
1330 cycle_color_attr(int ch, NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg, NCURSES_COLOR_T *tx)
1337 *fg = (NCURSES_COLOR_T) (*fg + 1);
1340 *fg = (NCURSES_COLOR_T) (*fg - 1);
1343 *bg = (NCURSES_COLOR_T) (*bg + 1);
1346 *bg = (NCURSES_COLOR_T) (*bg - 1);
1349 *tx = (NCURSES_COLOR_T) (*tx + 1);
1352 *tx = (NCURSES_COLOR_T) (*tx - 1);
1360 *fg = (NCURSES_COLOR_T) min_colors;
1361 if (*fg < min_colors)
1362 *fg = (NCURSES_COLOR_T) (COLORS - 1);
1364 *bg = (NCURSES_COLOR_T) min_colors;
1365 if (*bg < min_colors)
1366 *bg = (NCURSES_COLOR_T) (COLORS - 1);
1370 *tx = (NCURSES_COLOR_T) (COLORS - 1);
1379 adjust_attr_string(int adjust)
1381 char save = attr_test_string[0];
1382 int first = ((int) UChar(save)) + adjust;
1385 if (first >= ATTRSTRING_1ST) {
1386 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1387 if (k > ATTRSTRING_END)
1389 attr_test_string[j] = (char) k;
1390 if (((k + 1 - first) % 5) == 0) {
1391 if (++j >= MAX_ATTRSTRING)
1393 attr_test_string[j] = ' ';
1396 if ((LEN_ATTRSTRING - j) > 5) {
1397 attr_test_string[0] = save;
1398 adjust_attr_string(adjust - 1);
1400 while (j < MAX_ATTRSTRING)
1401 attr_test_string[j++] = ' ';
1402 attr_test_string[j] = '\0';
1408 * Prefer the right-end of the string for starting, since that maps to the
1409 * VT100 line-drawing.
1412 default_attr_string(void)
1414 int result = (ATTRSTRING_END - LEN_ATTRSTRING);
1415 result += (LEN_ATTRSTRING / 5);
1416 if (result < ATTRSTRING_1ST)
1417 result = ATTRSTRING_1ST;
1422 init_attr_string(void)
1424 attr_test_string[0] = (char) default_attr_string();
1425 adjust_attr_string(0);
1429 show_attr(WINDOW *win, int row, int skip, bool arrow, chtype attr, const char *name)
1431 int ncv = get_ncv();
1432 chtype test = attr & (chtype) (~(A_ALTCHARSET | A_CHARTEXT));
1435 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1436 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1437 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1439 printw("%*s", skip, " ");
1441 * Just for testing, write text using the alternate character set one
1442 * character at a time (to pass its rendition directly), and use the
1443 * string operation for the other attributes.
1447 if (attr & A_ALTCHARSET) {
1451 for (s = attr_test_string; *s != '\0'; ++s) {
1453 (void) waddch(win, ch | attr);
1456 (void) wattrset(win, AttrArg(attr, 0));
1457 (void) waddstr(win, attr_test_string);
1458 (void) wattroff(win, (int) attr);
1461 printw("%*s", skip, " ");
1462 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1463 if (test != A_NORMAL) {
1464 if (!(termattrs() & test)) {
1467 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1468 static const chtype table[] =
1487 for (n = 0; n < SIZEOF(table); n++) {
1488 if ((table[n] & attr) != 0
1489 && ((1 << n) & ncv) != 0) {
1497 if ((termattrs() & test) != test) {
1507 NCURSES_CONST char *name;
1510 static const ATTR_TBL attrs_to_test[] = {
1511 { A_STANDOUT, "STANDOUT" },
1512 { A_REVERSE, "REVERSE" },
1514 { A_UNDERLINE, "UNDERLINE" },
1516 { A_BLINK, "BLINK" },
1517 { A_PROTECT, "PROTECT" },
1519 { A_INVIS, "INVISIBLE" },
1522 { A_ITALIC, "ITALIC" },
1524 { A_NORMAL, "NORMAL" },
1529 init_attr_list(ATTR_TBL * target, attr_t attrs)
1531 unsigned result = 0;
1534 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1535 attr_t test = attrs_to_test[n].attr;
1536 if (test == A_NORMAL || (test & attrs) != 0) {
1537 target[result++] = attrs_to_test[n];
1544 attr_getc(int *skip,
1545 NCURSES_COLOR_T *fg,
1546 NCURSES_COLOR_T *bg,
1547 NCURSES_COLOR_T *tx,
1560 if (ch < 256 && isdigit(ch)) {
1568 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1570 attr_legend(helpwin);
1593 adjust_attr_string(-1);
1596 adjust_attr_string(1);
1602 error = cycle_color_attr(ch, fg, bg, tx);
1612 /* test text attributes */
1615 int skip = get_xmc();
1616 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1617 NCURSES_COLOR_T bg = COLOR_BLACK;
1618 NCURSES_COLOR_T tx = -1;
1621 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1622 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1623 unsigned my_size = init_attr_list(my_list, termattrs());
1626 for (j = 0; j < my_size; ++j) {
1627 my_wins[j] = subwin(stdscr,
1629 2 + (int) (2 * j), COL_ATTRSTRING);
1630 scrollok(my_wins[j], FALSE);
1636 n = skip; /* make it easy */
1642 chtype normal = A_NORMAL | BLANK;
1643 chtype extras = (chtype) ac;
1646 NCURSES_PAIRS_T pair = 0;
1647 if ((fg != COLOR_BLACK) || (bg != COLOR_BLACK)) {
1649 if (init_pair(pair, fg, bg) == ERR) {
1652 normal |= (chtype) COLOR_PAIR(pair);
1657 if (init_pair(pair, tx, bg) == ERR) {
1660 extras |= (chtype) COLOR_PAIR(pair);
1670 MvAddStr(0, 20, "Character attribute test display");
1672 for (j = 0; j < my_size; ++j) {
1673 bool arrow = (j == k);
1674 row = show_attr(my_wins[j], row, n, arrow,
1682 MvPrintw(row, COLS_PRE_ATTRS,
1683 "This terminal does %shave the magic-cookie glitch",
1684 get_xmc() > -1 ? "" : "not ");
1685 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
1686 show_color_attr(fg, bg, tx);
1687 printw(" ACS (%d)", ac != 0);
1690 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1692 bkgdset(A_NORMAL | BLANK);
1696 Cannot("does not support video attributes.");
1700 #if USE_WIDEC_SUPPORT
1701 static bool use_fullwidth;
1702 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1704 #define FULL_LO 0xff00
1705 #define FULL_HI 0xff5e
1706 #define HALF_LO 0x20
1708 #define isFullWidth(ch) ((int)(ch) >= FULL_LO && (int)(ch) <= FULL_HI)
1709 #define ToNormalWidth(ch) (wchar_t) (((int)(ch) - FULL_LO) + HALF_LO)
1710 #define ToFullWidth(ch) (wchar_t) (((int)(ch) - HALF_LO) + FULL_LO)
1713 * Returns an ASCII code in [32..126]
1716 normal_wchar(int ch)
1718 wchar_t result = (wchar_t) ch;
1719 if (isFullWidth(ch))
1720 result = ToNormalWidth(ch);
1725 * Returns either an ASCII code in in [32..126] or full-width in
1726 * [0xff00..0xff5e], according to use_fullwidth setting.
1729 target_wchar(int ch)
1731 wchar_t result = (wchar_t) ch;
1732 if (use_fullwidth) {
1733 if (!isFullWidth(ch))
1734 result = ToFullWidth(ch);
1736 if (isFullWidth(ch))
1737 result = ToNormalWidth(ch);
1743 wide_adjust_attr_string(int adjust)
1745 wchar_t save = wide_attr_test_string[0];
1746 int first = ((int) normal_wchar(save)) + adjust;
1749 if (first >= ATTRSTRING_1ST) {
1750 for (j = 0, k = first; j < MAX_ATTRSTRING; ++j, ++k) {
1751 if (k > ATTRSTRING_END)
1753 wide_attr_test_string[j] = target_wchar(k);
1754 if (((k + 1 - first) % 5) == 0) {
1755 if (++j >= MAX_ATTRSTRING)
1757 wide_attr_test_string[j] = ' ';
1760 if ((LEN_ATTRSTRING - j) > 5) {
1761 wide_attr_test_string[0] = save;
1762 wide_adjust_attr_string(adjust - 1);
1764 while (j < MAX_ATTRSTRING)
1765 wide_attr_test_string[j++] = ' ';
1766 wide_attr_test_string[j] = '\0';
1772 wide_init_attr_string(void)
1774 use_fullwidth = FALSE;
1775 wide_attr_test_string[0] = (wchar_t) default_attr_string();
1776 wide_adjust_attr_string(0);
1780 set_wide_background(NCURSES_PAIRS_T pair)
1787 setcchar(&normal, blank, A_NORMAL, pair, 0);
1793 get_wide_background(void)
1795 attr_t result = A_NORMAL;
1798 NCURSES_PAIRS_T pair;
1801 memset(&ch, 0, sizeof(ch));
1802 if (getbkgrnd(&ch) != ERR) {
1803 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1811 wide_show_attr(WINDOW *win,
1816 NCURSES_PAIRS_T pair,
1819 int ncv = get_ncv();
1820 chtype test = attr & ~WA_ALTCHARSET;
1823 MvPrintw(row, COLS_PRE_ATTRS - 3, "-->");
1824 MvPrintw(row, COLS_PRE_ATTRS, "%s mode:", name);
1825 MvPrintw(row, COL_ATTRSTRING - 1, "|");
1827 printw("%*s", skip, " ");
1830 * Just for testing, write text using the alternate character set one
1831 * character at a time (to pass its rendition directly), and use the
1832 * string operation for the other attributes.
1836 if (attr & WA_ALTCHARSET) {
1840 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1844 setcchar(&ch, fill, attr, pair, 0);
1845 (void) wadd_wch(win, &ch);
1848 attr_t old_attr = 0;
1849 NCURSES_PAIRS_T old_pair = 0;
1851 (void) (wattr_get) (win, &old_attr, &old_pair, 0);
1852 (void) wattr_set(win, attr, pair, 0);
1853 (void) waddwstr(win, wide_attr_test_string);
1854 (void) wattr_set(win, old_attr, old_pair, 0);
1857 printw("%*s", skip, " ");
1858 MvPrintw(row, COL_ATTRSTRING + LEN_ATTRSTRING, "|");
1859 if (test != A_NORMAL) {
1860 if (!(term_attrs() & test)) {
1863 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1864 static const attr_t table[] =
1878 for (n = 0; n < SIZEOF(table); n++) {
1879 if ((table[n] & attr) != 0
1880 && ((1 << n) & ncv) != 0) {
1888 if ((term_attrs() & test) != test) {
1897 wide_attr_getc(int *skip,
1898 NCURSES_COLOR_T *fg, NCURSES_COLOR_T *bg,
1899 NCURSES_COLOR_T *tx, int *ac,
1900 unsigned *kc, unsigned limit)
1910 if (ch < 256 && isdigit(ch)) {
1918 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1919 box_set(helpwin, 0, 0);
1920 attr_legend(helpwin);
1943 use_fullwidth = FALSE;
1944 wide_adjust_attr_string(0);
1947 use_fullwidth = TRUE;
1948 wide_adjust_attr_string(0);
1951 wide_adjust_attr_string(-1);
1954 wide_adjust_attr_string(1);
1960 error = cycle_color_attr(ch, fg, bg, tx);
1969 wide_attr_test(void)
1970 /* test text attributes using wide-character calls */
1973 int skip = get_xmc();
1974 NCURSES_COLOR_T fg = COLOR_BLACK; /* color pair 0 is special */
1975 NCURSES_COLOR_T bg = COLOR_BLACK;
1976 NCURSES_COLOR_T tx = -1;
1979 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1980 WINDOW *my_wins[SIZEOF(attrs_to_test)];
1981 unsigned my_size = init_attr_list(my_list, term_attrs());
1984 for (j = 0; j < my_size; ++j) {
1985 my_wins[j] = subwin(stdscr,
1987 2 + (int) (2 * j), COL_ATTRSTRING);
1988 scrollok(my_wins[j], FALSE);
1994 n = skip; /* make it easy */
1996 wide_init_attr_string();
2000 NCURSES_PAIRS_T pair = 0;
2001 NCURSES_PAIRS_T extras = 0;
2004 pair = (NCURSES_PAIRS_T) (fg != COLOR_BLACK || bg != COLOR_BLACK);
2007 if (init_pair(pair, fg, bg) == ERR) {
2014 if (init_pair(extras, tx, bg) == ERR) {
2019 set_wide_background(pair);
2022 box_set(stdscr, 0, 0);
2023 MvAddStr(0, 20, "Character attribute test display");
2025 for (j = 0; j < my_size; ++j) {
2026 row = wide_show_attr(my_wins[j], row, n, (j == k),
2034 MvPrintw(row, COLS_PRE_ATTRS,
2035 "This terminal does %shave the magic-cookie glitch",
2036 get_xmc() > -1 ? "" : "not ");
2037 MvPrintw(row + 1, COLS_PRE_ATTRS, "Enter '?' for help.");
2038 show_color_attr(fg, bg, tx);
2039 printw(" ACS (%d)", ac != 0);
2042 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
2044 set_wide_background(0);
2048 Cannot("does not support extended video attributes.");
2053 /****************************************************************************
2055 * Color support tests
2057 ****************************************************************************/
2059 static NCURSES_CONST char *the_color_names[] =
2080 show_color_name(int y, int x, int color, bool wide)
2082 if (move(y, x) != ERR) {
2087 sprintf(temp, "%02d", color);
2089 } else if (color >= 8) {
2090 sprintf(temp, "[%02d]", color);
2091 } else if (color < 0) {
2092 strcpy(temp, "default");
2094 sprintf(temp, "%.*s", 16, the_color_names[color]);
2096 printw("%-*.*s", width, width, temp);
2101 color_legend(WINDOW *helpwin, bool wide)
2106 MvWPrintw(helpwin, row++, col,
2109 MvWPrintw(helpwin, row++, col,
2110 "Use up/down arrow to scroll through the display if it is");
2111 MvWPrintw(helpwin, row++, col,
2112 "longer than one screen. Control/N and Control/P can be used");
2113 MvWPrintw(helpwin, row++, col,
2114 "in place of up/down arrow. Use pageup/pagedown to scroll a");
2115 MvWPrintw(helpwin, row++, col,
2116 "full screen; control/B and control/F can be used here.");
2118 MvWPrintw(helpwin, row++, col,
2120 MvWPrintw(helpwin, row++, col,
2121 " a/A toggle altcharset off/on");
2122 MvWPrintw(helpwin, row++, col,
2123 " b/B toggle bold off/on");
2125 MvWPrintw(helpwin, row++, col,
2126 " c/C cycle used-colors through 8,16,...,COLORS");
2128 MvWPrintw(helpwin, row++, col,
2129 " n/N toggle text/number on/off");
2130 MvWPrintw(helpwin, row++, col,
2131 " r/R toggle reverse on/off");
2132 MvWPrintw(helpwin, row++, col,
2133 " w/W toggle width between 8/16 colors");
2134 #if USE_WIDEC_SUPPORT
2136 MvWPrintw(helpwin, row++, col,
2137 "Wide characters:");
2138 MvWPrintw(helpwin, row, col,
2139 " x/X toggle text between ASCII and wide-character");
2146 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2149 color_cycle(int current, int step)
2151 int result = current;
2157 if ((result * 2) > COLORS) {
2160 while ((result * 2) < current) {
2166 if (current >= COLORS) {
2171 if (result > COLORS)
2177 /* generate a color test pattern */
2184 int grid_top = top + 3;
2185 int page_size = (LINES - grid_top);
2187 int colors_max = COLORS;
2193 bool opt_acsc = FALSE;
2194 bool opt_bold = FALSE;
2195 bool opt_revs = FALSE;
2196 bool opt_nums = FALSE;
2197 bool opt_wide = FALSE;
2203 pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2204 if (colors_max * colors_max <= COLOR_PAIRS) {
2205 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2206 if (pairs_max > limit)
2209 if (pairs_max > COLOR_PAIRS)
2210 pairs_max = COLOR_PAIRS;
2213 /* this assumes an 80-column line */
2217 per_row = (colors_max > 8) ? 16 : 8;
2223 per_row -= min_colors;
2225 row_limit = (pairs_max + per_row - 1) / per_row;
2228 (void) printw("There are %d color pairs and %d colors",
2230 if (colors_max != COLORS)
2231 (void) printw(" (using %d colors)", colors_max);
2233 (void) addstr(" besides 'default'");
2236 MvPrintw(top + 1, 0,
2237 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2240 opt_bold ? "on" : "off");
2242 /* show color names/numbers across the top */
2243 for (i = 0; i < per_row; i++)
2244 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2246 /* show a grid of colors, with color names/ numbers on the left */
2247 for (i = (NCURSES_PAIRS_T) (base_row * per_row); i < pairs_max; i++) {
2248 int row = grid_top + (i / per_row) - base_row;
2249 int col = (i % per_row + 1) * width;
2250 NCURSES_PAIRS_T pair = i;
2252 #define InxToFG(i) (NCURSES_COLOR_T) ((i % (colors_max - min_colors)) + min_colors)
2253 #define InxToBG(i) (NCURSES_COLOR_T) ((i / (colors_max - min_colors)) + min_colors)
2254 if (row >= 0 && move(row, col) != ERR) {
2255 NCURSES_COLOR_T fg = InxToFG(i);
2256 NCURSES_COLOR_T bg = InxToBG(i);
2258 init_pair(pair, fg, bg);
2259 attron(COLOR_PAIR(pair));
2261 attron(A_ALTCHARSET);
2268 sprintf(numbered, "{%02X}", (int) i);
2271 printw("%-*.*s", width, width, hello);
2272 (void) attrset(A_NORMAL);
2274 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2275 show_color_name(row, 0, InxToBG(i), opt_wide);
2283 switch (wGetchar(stdscr)) {
2297 colors_max = color_cycle(colors_max, -1);
2300 colors_max = color_cycle(colors_max, 1);
2318 set_color_test(opt_wide, FALSE);
2321 set_color_test(opt_wide, TRUE);
2325 if (base_row <= 0) {
2333 if (base_row + page_size >= row_limit) {
2342 if (base_row <= 0) {
2345 base_row -= (page_size - 1);
2353 if (base_row + page_size >= row_limit) {
2356 base_row += page_size - 1;
2357 if (base_row + page_size >= row_limit) {
2358 base_row = row_limit - page_size - 1;
2363 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2365 color_legend(helpwin, FALSE);
2380 #if USE_WIDEC_SUPPORT
2381 /* generate a color test pattern */
2383 wide_color_test(void)
2388 int grid_top = top + 3;
2389 int page_size = (LINES - grid_top);
2390 int pairs_max = (unsigned short) (-1);
2391 int colors_max = COLORS;
2397 bool opt_acsc = FALSE;
2398 bool opt_bold = FALSE;
2399 bool opt_revs = FALSE;
2400 bool opt_wide = FALSE;
2401 bool opt_nums = FALSE;
2402 bool opt_xchr = FALSE;
2409 pairs_max = (unsigned short) (-1);
2410 if (colors_max * colors_max <= COLOR_PAIRS) {
2411 int limit = (colors_max - min_colors) * (colors_max - min_colors);
2412 if (pairs_max > limit)
2415 if (pairs_max > COLOR_PAIRS)
2416 pairs_max = COLOR_PAIRS;
2419 /* this assumes an 80-column line */
2423 per_row = (colors_max > 8) ? 16 : 8;
2429 per_row -= min_colors;
2432 make_fullwidth_text(buffer, hello);
2436 make_narrow_text(buffer, hello);
2439 row_limit = (pairs_max + per_row - 1) / per_row;
2442 (void) printw("There are %d color pairs and %d colors",
2444 if (colors_max != COLORS)
2445 (void) printw(" (using %d colors)", colors_max);
2447 (void) addstr(" besides 'default'");
2450 MvPrintw(top + 1, 0,
2451 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2454 opt_bold ? "on" : "off");
2456 /* show color names/numbers across the top */
2457 for (i = 0; i < per_row; i++)
2458 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2460 /* show a grid of colors, with color names/ numbers on the left */
2461 for (i = (base_row * per_row); i < pairs_max; i++) {
2462 int row = grid_top + (i / per_row) - base_row;
2463 int col = (i % per_row + 1) * width;
2464 NCURSES_PAIRS_T pair = (NCURSES_PAIRS_T) i;
2466 if (row >= 0 && move(row, col) != ERR) {
2467 init_pair(pair, InxToFG(i), InxToBG(i));
2468 (void) color_set(pair, NULL);
2470 attr_on(A_ALTCHARSET, NULL);
2472 attr_on(A_BOLD, NULL);
2474 attr_on(A_REVERSE, NULL);
2477 sprintf(numbered, "{%02X}", i);
2479 make_fullwidth_text(buffer, numbered);
2481 make_narrow_text(buffer, numbered);
2484 addnwstr(buffer, width);
2485 (void) attr_set(A_NORMAL, 0, NULL);
2487 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2488 show_color_name(row, 0, InxToBG(i), opt_wide);
2496 switch (wGetchar(stdscr)) {
2510 colors_max = color_cycle(colors_max, -1);
2513 colors_max = color_cycle(colors_max, 1);
2531 set_color_test(opt_wide, FALSE);
2534 set_color_test(opt_wide, TRUE);
2544 if (base_row <= 0) {
2552 if (base_row + page_size >= row_limit) {
2561 if (base_row <= 0) {
2564 base_row -= (page_size - 1);
2572 if (base_row + page_size >= row_limit) {
2575 base_row += page_size - 1;
2576 if (base_row + page_size >= row_limit) {
2577 base_row = row_limit - page_size - 1;
2582 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2584 color_legend(helpwin, TRUE);
2598 #endif /* USE_WIDEC_SUPPORT */
2601 change_color(NCURSES_PAIRS_T current, int field, int value, int usebase)
2603 NCURSES_COLOR_T red, green, blue;
2605 color_content(current, &red, &green, &blue);
2609 red = (NCURSES_COLOR_T) (usebase ? (red + value) : value);
2612 green = (NCURSES_COLOR_T) (usebase ? (green + value) : value);
2615 blue = (NCURSES_COLOR_T) (usebase ? (blue + value) : value);
2619 if (init_color(current, red, green, blue) == ERR)
2624 init_all_colors(void)
2628 for (c = 0; c < COLORS; ++c)
2631 all_colors[c].green,
2632 all_colors[c].blue);
2635 #define scaled_rgb(n) ((255 * (n)) / 1000)
2639 /* display the color test pattern, without trying to edit colors */
2643 int this_c = 0, value = 0, field = 0;
2646 int page_size = (LINES - 6);
2651 for (i = 0; i < max_colors; i++)
2652 init_pair((NCURSES_PAIRS_T) i,
2653 (NCURSES_COLOR_T) COLOR_WHITE,
2654 (NCURSES_COLOR_T) i);
2656 MvPrintw(LINES - 2, 0, "Number: %d", value);
2659 NCURSES_COLOR_T red, green, blue;
2662 MvAddStr(0, 20, "Color RGB Value Editing");
2665 for (i = (NCURSES_COLOR_T) top_color;
2666 (i - top_color < page_size)
2667 && (i < max_colors); i++) {
2670 sprintf(numeric, "[%d]", i);
2671 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2672 (i == current ? '>' : ' '),
2673 (i < (int) SIZEOF(the_color_names)
2674 ? the_color_names[i] : numeric));
2675 (void) attrset(AttrArg(COLOR_PAIR(i), 0));
2677 (void) attrset(A_NORMAL);
2679 color_content((NCURSES_PAIRS_T) i, &red, &green, &blue);
2681 if (current == i && field == 0)
2683 printw("%04d", (int) red);
2684 if (current == i && field == 0)
2685 (void) attrset(A_NORMAL);
2687 if (current == i && field == 1)
2689 printw("%04d", (int) green);
2690 if (current == i && field == 1)
2691 (void) attrset(A_NORMAL);
2693 if (current == i && field == 2)
2695 printw("%04d", (int) blue);
2696 if (current == i && field == 2)
2697 (void) attrset(A_NORMAL);
2698 (void) attrset(A_NORMAL);
2699 printw(" ( %3d %3d %3d )",
2700 (int) scaled_rgb(red),
2701 (int) scaled_rgb(green),
2702 (int) scaled_rgb(blue));
2705 MvAddStr(LINES - 3, 0,
2706 "Use up/down to select a color, left/right to change fields.");
2707 MvAddStr(LINES - 2, 0,
2708 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2710 move(2 + current - top_color, 0);
2714 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2721 current -= (page_size - 1);
2728 if (current < (max_colors - 1))
2729 current += (page_size - 1);
2736 current = (current == 0 ? (max_colors - 1) : current - 1);
2741 current = (current == (max_colors - 1) ? 0 : current + 1);
2745 field = (field == 2 ? 0 : field + 1);
2749 field = (field == 0 ? 2 : field - 1);
2762 value = value * 10 + (this_c - '0');
2766 change_color((NCURSES_PAIRS_T) current, field, value, 1);
2770 change_color((NCURSES_PAIRS_T) current, field, -value, 1);
2774 change_color((NCURSES_PAIRS_T) current, field, value, 0);
2779 P(" RGB Value Editing Help");
2781 P("You are in the RGB value editor. Use the arrow keys to select one of");
2782 P("the fields in one of the RGB triples of the current colors; the one");
2783 P("currently selected will be reverse-video highlighted.");
2785 P("To change a field, enter the digits of the new value; they are echoed");
2786 P("as entered. Finish by typing `='. The change will take effect instantly.");
2787 P("To increment or decrement a value, use the same procedure, but finish");
2788 P("with a `+' or `-'.");
2790 P("Press 'm' to invoke the top-level menu with the current color settings.");
2791 P("To quit, do ESC");
2800 for (i = 0; i < max_colors; i++)
2801 init_pair((NCURSES_PAIRS_T) i,
2802 (NCURSES_COLOR_T) COLOR_WHITE,
2803 (NCURSES_COLOR_T) i);
2817 if (current >= max_colors)
2818 current = max_colors - 1;
2819 if (current < top_color)
2820 top_color = current;
2821 if (current - top_color >= page_size)
2822 top_color = current - (page_size - 1);
2824 MvPrintw(LINES - 1, 0, "Number: %d", value);
2832 * ncurses does not reset each color individually when calling endwin().
2839 /****************************************************************************
2841 * Alternate character-set stuff
2843 ****************************************************************************/
2845 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
2851 if ((*at_code += 1) >= limit)
2856 *at_code = limit - 1;
2865 *attr = list[*at_code].attr;
2870 cycle_colors(int ch, int *fg, int *bg, NCURSES_PAIRS_T *pair)
2872 bool result = FALSE;
2882 if ((*fg += 1) >= COLORS)
2890 if ((*bg += 1) >= COLORS)
2898 *pair = (NCURSES_PAIRS_T) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2901 if (init_pair(*pair,
2902 (NCURSES_COLOR_T) *fg,
2903 (NCURSES_COLOR_T) *bg) == ERR) {
2912 /****************************************************************************
2914 * Soft-key label test
2916 ****************************************************************************/
2921 #define SLK_WORK (SLK_HELP + 3)
2926 static const char *table[] =
2928 "Available commands are:"
2930 ,"^L -- repaint this message and activate soft keys"
2931 ,"a/d -- activate/disable soft keys"
2932 ,"c -- set centered format for labels"
2933 ,"l -- set left-justified format for labels"
2934 ,"r -- set right-justified format for labels"
2935 ,"[12345678] -- set label; labels are numbered 1 through 8"
2936 ,"e -- erase stdscr (should not erase labels)"
2937 ,"s -- test scrolling of shortened screen"
2938 ,"v/V -- cycle through video attributes"
2940 ,"F/f/B/b -- cycle through foreground/background colors"
2942 ,"ESC -- return to main menu"
2944 ,"Note: if activating the soft keys causes your terminal to scroll up"
2945 ,"one line, your terminal auto-scrolls when anything is written to the"
2946 ,"last screen position. The ncurses code does not yet handle this"
2952 for (j = 0; j < SIZEOF(table); ++j) {
2960 call_slk_color(int fg, int bg)
2962 init_pair(1, (NCURSES_COLOR_T) bg, (NCURSES_COLOR_T) fg);
2964 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2974 /* exercise the soft keys */
2979 chtype attr = A_NORMAL;
2980 unsigned at_code = 0;
2982 int fg = COLOR_BLACK;
2983 int bg = COLOR_WHITE;
2984 NCURSES_PAIRS_T pair = 0;
2986 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
2987 unsigned my_size = init_attr_list(my_list, termattrs());
2992 call_slk_color(fg, bg);
3002 MvAddStr(0, 20, "Soft Key Exerciser");
3017 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3018 while ((c = Getchar()) != 'Q' && (c != ERR))
3046 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3048 if ((s = slk_label(c - '0')) != 0) {
3049 strncpy(buf, s, (size_t) 8);
3051 wGetstring(stdscr, buf, 8);
3052 slk_set((c - '0'), buf, fmt);
3061 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3063 wnoutrefresh(stdscr);
3068 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3075 if (cycle_colors(c, &fg, &bg, &pair)) {
3077 call_slk_color(fg, bg);
3087 } while (!isQuit(c = Getchar()));
3095 #if USE_WIDEC_SUPPORT
3099 /* exercise the soft keys */
3102 wchar_t buf[SLKLEN + 1];
3104 chtype attr = A_NORMAL;
3105 unsigned at_code = 0;
3106 int fg = COLOR_BLACK;
3107 int bg = COLOR_WHITE;
3108 NCURSES_PAIRS_T pair = 0;
3109 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3110 unsigned my_size = init_attr_list(my_list, term_attrs());
3114 call_slk_color(fg, bg);
3121 attr_on(WA_BOLD, NULL);
3122 MvAddStr(0, 20, "Soft Key Exerciser");
3123 attr_off(WA_BOLD, NULL);
3137 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
3138 while ((c = Getchar()) != 'Q' && (c != ERR))
3166 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
3168 if ((s = slk_label(c - '0')) != 0) {
3169 char *temp = strdup(s);
3170 size_t used = strlen(temp);
3171 size_t want = SLKLEN;
3173 #ifndef state_unused
3178 while (want > 0 && used != 0) {
3179 const char *base = s;
3180 reset_mbytes(state);
3181 test = count_mbytes(base, 0, &state);
3182 if (test == (size_t) -1) {
3184 } else if (test > want) {
3187 reset_mbytes(state);
3188 trans_mbytes(buf, base, want, &state);
3194 wGet_wstring(stdscr, buf, SLKLEN);
3195 slk_wset((c - '0'), buf, fmt);
3206 fg = (NCURSES_COLOR_T) ((fg + 1) % COLORS);
3207 call_slk_color(fg, bg);
3212 bg = (NCURSES_COLOR_T) ((bg + 1) % COLORS);
3213 call_slk_color(fg, bg);
3216 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3218 wnoutrefresh(stdscr);
3222 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3223 slk_attr_set(attr, (NCURSES_COLOR_T) (fg || bg), NULL);
3229 if (cycle_colors(c, &fg, &bg, &pair)) {
3231 call_slk_color(fg, bg);
3241 } while (!isQuit(c = Getchar()));
3249 #endif /* SLK_INIT */
3252 show_256_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3255 unsigned last = 255;
3261 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3266 for (code = first; code <= last; ++code) {
3267 int row = (int) (2 + (code / 16));
3268 int col = (int) (5 * (code % 16));
3269 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3270 for (count = 1; count < repeat; ++count) {
3271 addch(colored_chtype(code, attr, pair));
3278 * Show a slice of 32 characters, allowing those to be repeated up to the
3281 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3282 * terminal to perform functions. The remaining codes can be graphic.
3285 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3288 unsigned first = (unsigned) base;
3289 unsigned last = first + (unsigned) pagesize - 2;
3290 bool C1 = (first == 128);
3295 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3296 C1 ? "C1" : "GR", first, last);
3300 for (code = first; code <= last; code++) {
3302 int row = 2 + ((int) (code - first) % (pagesize / 2));
3303 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3305 sprintf(tmp, "%3u (0x%x)", code, code);
3306 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3310 nodelay(stdscr, TRUE);
3311 echochar(colored_chtype(code, attr, pair));
3313 /* (yes, this _is_ crude) */
3314 while ((reply = Getchar()) != ERR) {
3315 addch(UChar(reply));
3318 nodelay(stdscr, FALSE);
3320 } while (--count > 0);
3327 show_pc_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3333 MvPrintw(0, 20, "Display of PC Character Codes");
3337 for (code = 0; code < 16; ++code) {
3338 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3340 for (code = 0; code < 256; code++) {
3342 int row = 3 + (int) (code / 16) + (code >= 128);
3343 int col = 8 + (int) (code % 16) * PC_COLS;
3344 if ((code % 16) == 0)
3345 MvPrintw(row, 0, "0x%02x:", code);
3356 * Skip the ones that do not work.
3360 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3363 } while (--count > 0);
3368 show_box_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3372 attr |= (attr_t) COLOR_PAIR(pair);
3376 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3381 colored_chtype(ACS_VLINE, attr, pair),
3382 colored_chtype(ACS_VLINE, attr, pair),
3383 colored_chtype(ACS_HLINE, attr, pair),
3384 colored_chtype(ACS_HLINE, attr, pair),
3385 colored_chtype(ACS_ULCORNER, attr, pair),
3386 colored_chtype(ACS_URCORNER, attr, pair),
3387 colored_chtype(ACS_LLCORNER, attr, pair),
3388 colored_chtype(ACS_LRCORNER, attr, pair));
3389 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3390 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3391 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3392 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3393 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3394 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3395 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3401 show_1_acs(int n, int repeat, const char *name, chtype code)
3403 const int height = 16;
3404 int row = 2 + (n % height);
3405 int col = (n / height) * COLS / 2;
3407 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3410 } while (--repeat > 0);
3415 show_acs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3416 /* display the ACS character set */
3420 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3424 MvAddStr(0, 20, "Display of the ACS Character Set");
3428 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3429 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3430 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3431 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3433 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3434 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3435 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3436 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3438 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3439 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3442 * HPUX's ACS definitions are broken here. Just give up.
3444 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3445 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3446 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3447 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3448 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3450 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3451 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3452 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3453 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3454 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3455 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3456 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3457 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3458 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3460 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3461 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3462 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3464 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3465 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3466 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3467 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3468 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3469 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3478 char *term = getenv("TERM");
3479 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3482 chtype attr = A_NORMAL;
3485 int fg = COLOR_BLACK;
3486 int bg = COLOR_BLACK;
3487 unsigned at_code = 0;
3488 NCURSES_PAIRS_T pair = 0;
3489 void (*last_show_acs) (int, attr_t, NCURSES_PAIRS_T) = 0;
3490 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3491 unsigned my_size = init_attr_list(my_list, termattrs());
3499 ToggleAcs(last_show_acs, show_acs_chars);
3503 ToggleAcs(last_show_acs, show_pc_chars);
3508 if (pagesize == 32) {
3515 ToggleAcs(last_show_acs, show_box_chars);
3541 if (repeat < (COLS / 4))
3549 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3550 || cycle_colors(c, &fg, &bg, &pair)) {
3557 if (pagesize != 32) {
3558 show_256_chars(repeat, attr, pair);
3559 } else if (last_show_acs != 0) {
3560 last_show_acs(repeat, attr, pair);
3562 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3565 MvPrintw(LINES - 3, 0,
3566 "Note: ANSI terminals may not display C1 characters.");
3567 MvPrintw(LINES - 2, 0,
3568 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3571 MvPrintw(LINES - 1, 0,
3572 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3573 my_list[at_code].name,
3576 MvPrintw(LINES - 1, 0,
3577 "v/V cycles through video attributes (%s).",
3578 my_list[at_code].name);
3581 } while (!isQuit(c = Getchar()));
3588 #if USE_WIDEC_SUPPORT
3590 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, NCURSES_PAIRS_T pair)
3596 TEST_CCHAR(src, count, {
3597 attr |= (test_attrs & A_ALTCHARSET);
3598 setcchar(dst, test_wch, attr, pair, NULL);
3608 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3609 * display. If there are no repeats, we could normally display 16 lines of 64
3610 * characters (1024 total). However, taking repeats and double-width cells
3611 * into account, use 256 characters for the page.
3614 show_paged_widechars(int base,
3619 NCURSES_PAIRS_T pair)
3621 int first = base * pagesize;
3622 int last = first + pagesize - 1;
3630 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3633 for (code = (wchar_t) first; (int) code <= last; code++) {
3634 int row = (2 + ((int) code - first) / per_line);
3635 int col = 5 * ((int) code % per_line);
3638 memset(&codes, 0, sizeof(codes));
3640 setcchar(&temp, codes, attr, pair, 0);
3642 if (wcwidth(code) == 0 && code != 0) {
3643 addch((chtype) space |
3644 (A_REVERSE ^ attr) |
3645 (attr_t) COLOR_PAIR(pair));
3648 for (count = 1; count < repeat; ++count) {
3655 show_upper_widechars(int first, int repeat, int space, attr_t attr, NCURSES_PAIRS_T pair)
3659 int last = first + 31;
3663 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3666 for (code = (wchar_t) first; (int) code <= last; code++) {
3667 int row = 2 + ((code - first) % 16);
3668 int col = ((code - first) / 16) * COLS / 2;
3674 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3675 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3677 memset(&codes, 0, sizeof(codes));
3679 setcchar(&temp, codes, attr, pair, 0);
3683 * Give non-spacing characters something to combine with. If we
3684 * don't, they'll bunch up in a heap on the space after the ":".
3685 * Mark them with reverse-video to make them simpler to find on
3688 if (wcwidth(code) == 0) {
3689 addch((chtype) space |
3690 (A_REVERSE ^ attr) |
3691 (attr_t) COLOR_PAIR(pair));
3694 * This uses echo_wchar(), for comparison with the normal 'f'
3695 * test (and to make a test-case for echo_wchar()). The screen
3696 * may flicker because the erase() at the top of the function
3697 * is met by the builtin refresh() in echo_wchar().
3701 * The repeat-count may make text wrap - avoid that.
3703 getyx(stdscr, y, x);
3705 if (x >= col + (COLS / 2) - 2)
3707 } while (--count > 0);
3712 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3714 const int height = 16;
3715 int row = 2 + (n % height);
3716 int col = (n / height) * COLS / 2;
3718 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3719 while (--repeat >= 0) {
3725 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3728 show_wacs_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3729 /* display the wide-ACS character set */
3735 /*#define BOTH2(name) #name, &(name) */
3736 #define BOTH2(name) #name, MERGE_ATTR(name)
3740 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3744 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3745 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3746 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3747 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3749 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3750 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3751 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3752 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3754 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3755 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3757 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3758 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3759 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3760 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3762 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3763 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3764 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3765 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3766 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3767 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3768 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3769 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3770 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3772 #ifdef CURSES_WACS_ARRAY
3773 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3774 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3775 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3777 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3778 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3779 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3780 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3781 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3782 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3788 show_wacs_chars_double(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3789 /* display the wide-ACS character set */
3795 /*#define BOTH2(name) #name, &(name) */
3796 #define BOTH2(name) #name, MERGE_ATTR(name)
3800 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3804 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3805 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3806 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3807 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3809 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3810 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3811 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3812 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3814 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3815 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3817 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3818 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3819 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3820 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3822 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3823 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3824 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3825 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3826 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3827 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3828 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3829 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3830 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3832 #ifdef CURSES_WACS_ARRAY
3833 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3834 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3835 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3837 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3838 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3839 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3840 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3841 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3842 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3849 show_wacs_chars_thick(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3850 /* display the wide-ACS character set */
3856 /*#define BOTH2(name) #name, &(name) */
3857 #define BOTH2(name) #name, MERGE_ATTR(name)
3861 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3865 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
3866 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
3867 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
3868 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
3870 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
3871 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
3872 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
3873 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
3875 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
3876 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
3878 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3879 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3880 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3881 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3883 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3884 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3885 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3886 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3887 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3888 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3889 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3890 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3891 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3893 #ifdef CURSES_WACS_ARRAY
3894 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3895 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3896 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3898 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3899 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3900 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3901 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3902 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3903 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3910 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3913 show_wbox_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3920 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3925 MERGE_ATTR(0, WACS_VLINE),
3926 MERGE_ATTR(1, WACS_VLINE),
3927 MERGE_ATTR(2, WACS_HLINE),
3928 MERGE_ATTR(3, WACS_HLINE),
3929 MERGE_ATTR(4, WACS_ULCORNER),
3930 MERGE_ATTR(5, WACS_URCORNER),
3931 MERGE_ATTR(6, WACS_LLCORNER),
3932 MERGE_ATTR(7, WACS_LRCORNER));
3934 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3935 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3936 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3937 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3938 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3939 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3940 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3948 show_2_wacs(int n, const char *name, const char *code, attr_t attr, NCURSES_PAIRS_T pair)
3950 const int height = 16;
3951 int row = 2 + (n % height);
3952 int col = (n / height) * COLS / 2;
3955 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3956 (void) attr_set(attr, pair, 0);
3957 addstr(strncpy(temp, code, 20));
3958 (void) attr_set(A_NORMAL, 0, 0);
3962 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3965 show_utf8_chars(int repeat, attr_t attr, NCURSES_PAIRS_T pair)
3972 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3976 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3977 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3978 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3979 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3981 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3982 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3983 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3984 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3986 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3987 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3989 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3990 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3991 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3992 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3994 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3995 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3996 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3997 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3998 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3999 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
4000 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
4001 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
4002 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
4003 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
4004 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
4005 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
4007 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
4008 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
4009 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
4010 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
4011 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
4012 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
4017 /* display the wide-ACS character set */
4019 wide_acs_display(void)
4026 chtype attr = A_NORMAL;
4027 int fg = COLOR_BLACK;
4028 int bg = COLOR_BLACK;
4029 unsigned at_code = 0;
4030 NCURSES_PAIRS_T pair = 0;
4031 void (*last_show_wacs) (int, attr_t, NCURSES_PAIRS_T) = 0;
4032 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
4033 unsigned my_size = init_attr_list(my_list, term_attrs());
4041 ToggleAcs(last_show_wacs, show_wacs_chars);
4045 ToggleAcs(last_show_wacs, show_wacs_chars_double);
4050 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
4054 if (pagesize == 32) {
4061 ToggleAcs(last_show_wacs, show_wbox_chars);
4064 ToggleAcs(last_show_wacs, show_utf8_chars);
4067 if (c < 256 && isdigit(c)) {
4070 } else if (c == '+') {
4073 } else if (c == '-' && digit > 0) {
4076 } else if (c == '>' && repeat < (COLS / 4)) {
4078 } else if (c == '<' && repeat > 1) {
4080 } else if (c == '_') {
4081 space = (space == ' ') ? '_' : ' ';
4083 } else if (cycle_attr(c, &at_code, &attr, my_list, my_size)
4084 || cycle_colors(c, &fg, &bg, &pair)) {
4085 if (last_show_wacs != 0)
4093 if (pagesize != 32) {
4094 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
4095 } else if (last_show_wacs != 0) {
4096 last_show_wacs(repeat, attr, pair);
4098 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
4101 MvPrintw(LINES - 4, 0,
4102 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
4103 MvPrintw(LINES - 3, 2,
4104 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
4106 MvPrintw(LINES - 2, 2,
4107 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
4108 my_list[at_code].name,
4111 MvPrintw(LINES - 2, 2,
4112 "v/V cycles through video attributes (%s).",
4113 my_list[at_code].name);
4116 } while (!isQuit(c = Getchar()));
4126 * Graphic-rendition test (adapted from vttest)
4129 test_sgr_attributes(void)
4133 for (pass = 0; pass < 2; pass++) {
4134 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
4136 /* Use non-default colors if possible to exercise bce a little */
4138 init_pair(1, COLOR_WHITE, COLOR_BLUE);
4139 normal |= (chtype) COLOR_PAIR(1);
4143 MvPrintw(1, 20, "Graphic rendition test pattern:");
4145 MvPrintw(4, 1, "vanilla");
4147 #define set_sgr(mask) bkgdset((normal^(mask)));
4149 MvPrintw(4, 40, "bold");
4151 set_sgr(A_UNDERLINE);
4152 MvPrintw(6, 6, "underline");
4154 set_sgr(A_BOLD | A_UNDERLINE);
4155 MvPrintw(6, 45, "bold underline");
4158 MvPrintw(8, 1, "blink");
4160 set_sgr(A_BLINK | A_BOLD);
4161 MvPrintw(8, 40, "bold blink");
4163 set_sgr(A_UNDERLINE | A_BLINK);
4164 MvPrintw(10, 6, "underline blink");
4166 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
4167 MvPrintw(10, 45, "bold underline blink");
4170 MvPrintw(12, 1, "negative");
4172 set_sgr(A_BOLD | A_REVERSE);
4173 MvPrintw(12, 40, "bold negative");
4175 set_sgr(A_UNDERLINE | A_REVERSE);
4176 MvPrintw(14, 6, "underline negative");
4178 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
4179 MvPrintw(14, 45, "bold underline negative");
4181 set_sgr(A_BLINK | A_REVERSE);
4182 MvPrintw(16, 1, "blink negative");
4184 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
4185 MvPrintw(16, 40, "bold blink negative");
4187 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
4188 MvPrintw(18, 6, "underline blink negative");
4190 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
4191 MvPrintw(18, 45, "bold underline blink negative");
4194 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4200 bkgdset(A_NORMAL | BLANK);
4205 /****************************************************************************
4207 * Windows and scrolling tester.
4209 ****************************************************************************/
4211 #define BOTLINES 4 /* number of line stolen from screen bottom */
4217 #define FRAME struct frame
4226 #if defined(NCURSES_VERSION)
4227 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
4228 #define is_keypad(win) (win)->_use_keypad
4229 #define is_scrollok(win) (win)->_scroll
4230 #elif !defined(is_keypad)
4231 #define is_keypad(win) FALSE
4232 #define is_scrollok(win) FALSE
4235 #define is_keypad(win) FALSE
4236 #define is_scrollok(win) FALSE
4240 frame_win(FRAME * curp)
4242 return (curp != 0) ? curp->wind : stdscr;
4245 /* We need to know if these flags are actually set, so don't look in FRAME.
4246 * These names are known to work with SVr4 curses as well as ncurses. The
4247 * _use_keypad name does not work with Solaris 8.
4250 HaveKeypad(FRAME * curp)
4252 WINDOW *win = frame_win(curp);
4254 return is_keypad(win);
4258 HaveScroll(FRAME * curp)
4260 WINDOW *win = frame_win(curp);
4262 return is_scrollok(win);
4266 newwin_legend(FRAME * curp)
4268 static const struct {
4273 "^C = create window", 0
4276 "^N = next window", 0
4279 "^P = previous window", 0
4282 "^F = scroll forward", 0
4285 "^B = scroll backward", 0
4288 "^K = keypad(%s)", 1
4291 "^S = scrollok(%s)", 2
4294 "^W = save window to file", 0
4297 "^R = restore window", 0
4310 bool do_keypad = HaveKeypad(curp);
4311 bool do_scroll = HaveScroll(curp);
4315 for (n = 0; n < SIZEOF(legend); n++) {
4316 switch (legend[n].code) {
4318 strcpy(buf, legend[n].msg);
4321 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
4324 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
4327 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
4330 x = getcurx(stdscr);
4331 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4338 transient(FRAME * curp, NCURSES_CONST char *msg)
4340 newwin_legend(curp);
4342 MvAddStr(LINES - 1, 0, msg);
4348 printw("%s characters are echoed, window should %sscroll.",
4349 HaveKeypad(curp) ? "Non-arrow" : "All other",
4350 HaveScroll(curp) ? "" : "not ");
4355 newwin_report(FRAME * curp)
4356 /* report on the cursor's current position, then restore it */
4358 WINDOW *win = frame_win(curp);
4362 transient(curp, (char *) 0);
4364 move(LINES - 1, COLS - 17);
4365 printw("Y = %2d X = %2d", y, x);
4373 selectcell(int uli, int ulj, int lri, int lrj)
4374 /* arrows keys move cursor, return location at current on non-arrow key */
4376 static pair res; /* result cell */
4377 int si = lri - uli + 1; /* depth of the select area */
4378 int sj = lrj - ulj + 1; /* width of the select area */
4379 int i = 0, j = 0; /* offsets into the select area */
4384 move(uli + i, ulj + j);
4385 newwin_report((FRAME *) 0);
4387 switch (Getchar()) {
4401 return ((pair *) 0);
4402 #ifdef NCURSES_MOUSE_VERSION
4408 if (event.y > uli && event.x > ulj) {
4429 outerbox(pair ul, pair lr, bool onoff)
4430 /* draw or erase a box *outside* the given pair of corners */
4432 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4433 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4434 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4435 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4436 move(ul.y - 1, ul.x);
4437 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4438 move(ul.y, ul.x - 1);
4439 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4440 move(lr.y + 1, ul.x);
4441 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4442 move(ul.y, lr.x + 1);
4443 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4448 /* Ask user for a window definition */
4455 addstr("Use arrows to move cursor, anything else to mark corner 1");
4457 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4458 return ((WINDOW *) 0);
4459 memcpy(&ul, tmp, sizeof(pair));
4460 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4463 addstr("Use arrows to move cursor, anything else to mark corner 2");
4465 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4467 return ((WINDOW *) 0);
4468 memcpy(&lr, tmp, sizeof(pair));
4470 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4472 outerbox(ul, lr, TRUE);
4484 newwin_move(FRAME * curp, int dy, int dx)
4486 WINDOW *win = frame_win(curp);
4490 getyx(win, cur_y, cur_x);
4491 getmaxyx(win, max_y, max_x);
4492 if ((cur_x += dx) < 0)
4494 else if (cur_x >= max_x)
4496 if ((cur_y += dy) < 0)
4498 else if (cur_y >= max_y)
4500 wmove(win, cur_y, cur_x);
4504 delete_framed(FRAME * fp, bool showit)
4509 fp->last->next = fp->next;
4510 fp->next->last = fp->last;
4518 np = (fp == fp->next) ? 0 : fp->next;
4525 acs_and_scroll(void)
4526 /* Demonstrate windows */
4529 FRAME *current = (FRAME *) 0, *neww;
4531 #if HAVE_PUTWIN && HAVE_GETWIN
4535 #define DUMPFILE "screendump"
4537 #ifdef NCURSES_MOUSE_VERSION
4538 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4543 transient((FRAME *) 0, (char *) 0);
4546 if ((neww = typeCalloc(FRAME, (size_t) 1)) == 0) {
4547 failed("acs_and_scroll");
4550 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4551 failed("acs_and_scroll");
4556 if (current == 0) { /* First element, */
4557 neww->next = neww; /* so point it at itself */
4560 neww->next = current->next;
4561 neww->last = current;
4562 neww->last->next = neww;
4563 neww->next->last = neww;
4566 /* SVr4 curses sets the keypad on all newly-created windows to
4567 * false. Someone reported that PDCurses makes new windows inherit
4568 * this flag. Remove the following 'keypad()' call to test this
4570 keypad(current->wind, TRUE);
4571 current->do_keypad = HaveKeypad(current);
4572 current->do_scroll = HaveScroll(current);
4575 case CTRL('N'): /* go to next window */
4577 current = current->next;
4580 case CTRL('P'): /* go to previous window */
4582 current = current->last;
4585 case CTRL('F'): /* scroll current window forward */
4587 wscrl(frame_win(current), 1);
4590 case CTRL('B'): /* scroll current window backwards */
4592 wscrl(frame_win(current), -1);
4595 case CTRL('K'): /* toggle keypad mode for current */
4597 current->do_keypad = !current->do_keypad;
4598 keypad(current->wind, current->do_keypad);
4604 current->do_scroll = !current->do_scroll;
4605 scrollok(current->wind, current->do_scroll);
4609 #if HAVE_PUTWIN && HAVE_GETWIN
4610 case CTRL('W'): /* save and delete window */
4611 if ((current != 0) && (current == current->next)) {
4612 transient(current, "Will not save/delete ONLY window");
4614 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4615 transient(current, "Can't open screen dump file");
4617 (void) putwin(frame_win(current), fp);
4620 current = delete_framed(current, TRUE);
4624 case CTRL('R'): /* restore window */
4625 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4626 transient(current, "Can't open screen dump file");
4628 if ((neww = typeCalloc(FRAME, (size_t) 1)) != 0) {
4630 neww->next = current ? current->next : 0;
4631 neww->last = current;
4632 if (neww->last != 0)
4633 neww->last->next = neww;
4634 if (neww->next != 0)
4635 neww->next->last = neww;
4637 neww->wind = getwin(fp);
4639 wrefresh(neww->wind);
4641 failed("acs_and_scroll");
4649 case CTRL('X'): /* resize window */
4656 addstr("Use arrows to move cursor, anything else to mark new corner");
4659 getbegyx(current->wind, ul.y, ul.x);
4661 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4662 if (tmp == (pair *) 0) {
4667 getmaxyx(current->wind, lr.y, lr.x);
4670 outerbox(ul, lr, FALSE);
4671 wnoutrefresh(stdscr);
4673 /* strictly cosmetic hack for the test */
4674 getmaxyx(current->wind, my, mx);
4675 if (my > tmp->y - ul.y) {
4676 getyx(current->wind, lr.y, lr.x);
4677 wmove(current->wind, tmp->y - ul.y + 1, 0);
4678 wclrtobot(current->wind);
4679 wmove(current->wind, lr.y, lr.x);
4681 if (mx > tmp->x - ul.x)
4682 for (i = 0; i < my; i++) {
4683 wmove(current->wind, i, tmp->x - ul.x + 1);
4684 wclrtoeol(current->wind);
4686 wnoutrefresh(current->wind);
4688 memcpy(&lr, tmp, sizeof(pair));
4689 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4691 getbegyx(current->wind, ul.y, ul.x);
4692 getmaxyx(current->wind, lr.y, lr.x);
4695 outerbox(ul, lr, TRUE);
4696 wnoutrefresh(stdscr);
4698 wnoutrefresh(current->wind);
4704 #endif /* HAVE_WRESIZE */
4706 case KEY_F(10): /* undocumented --- use this to test area clears */
4707 selectcell(0, 0, LINES - 1, COLS - 1);
4713 newwin_move(current, -1, 0);
4716 newwin_move(current, 1, 0);
4719 newwin_move(current, 0, -1);
4722 newwin_move(current, 0, 1);
4730 getyx(frame_win(current), y, x);
4734 x = getmaxx(frame_win(current)) - 1;
4736 (void) mvwdelch(frame_win(current), y, x);
4746 waddch(current->wind, (chtype) c);
4751 newwin_report(current);
4752 usescr = frame_win(current);
4755 (!isQuit(c = wGetchar(usescr))
4759 while (current != 0)
4760 current = delete_framed(current, FALSE);
4762 scrollok(stdscr, TRUE); /* reset to driver's default */
4763 #ifdef NCURSES_MOUSE_VERSION
4764 mousemask(0, (mmask_t *) 0);
4771 /****************************************************************************
4775 ****************************************************************************/
4778 static int nap_msec = 1;
4780 static NCURSES_CONST char *mod[] =
4790 /*+-------------------------------------------------------------------------
4792 --------------------------------------------------------------------------*/
4794 wait_a_while(int msec GCC_UNUSED)
4804 else if (msec > 1000)
4805 sleep((unsigned) msec / 1000);
4809 } /* end of wait_a_while */
4811 /*+-------------------------------------------------------------------------
4813 --------------------------------------------------------------------------*/
4815 saywhat(NCURSES_CONST char *text)
4817 wmove(stdscr, LINES - 1, 0);
4819 if (text != 0 && *text != '\0') {
4820 waddstr(stdscr, text);
4821 waddstr(stdscr, "; ");
4823 waddstr(stdscr, "press any key to continue");
4824 } /* end of saywhat */
4826 /*+-------------------------------------------------------------------------
4827 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4828 --------------------------------------------------------------------------*/
4830 mkpanel(NCURSES_COLOR_T color, int rows, int cols, int tly, int tlx)
4835 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4836 if ((pan = new_panel(win)) == 0) {
4838 } else if (use_colors) {
4839 NCURSES_COLOR_T fg = (NCURSES_COLOR_T) ((color == COLOR_BLUE)
4842 NCURSES_COLOR_T bg = color;
4844 init_pair(color, fg, bg);
4845 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
4847 wbkgdset(win, A_BOLD | ' ');
4851 } /* end of mkpanel */
4853 /*+-------------------------------------------------------------------------
4855 --------------------------------------------------------------------------*/
4857 rmpanel(PANEL * pan)
4859 WINDOW *win = panel_window(pan);
4862 } /* end of rmpanel */
4864 /*+-------------------------------------------------------------------------
4866 --------------------------------------------------------------------------*/
4872 } /* end of pflush */
4874 /*+-------------------------------------------------------------------------
4876 --------------------------------------------------------------------------*/
4878 init_panel(WINDOW *win)
4882 for (y = 0; y < LINES - 1; y++) {
4883 for (x = 0; x < COLS; x++)
4884 wprintw(win, "%d", (y + x) % 10);
4889 fill_panel(PANEL * pan)
4891 WINDOW *win = panel_window(pan);
4892 const char *userptr = (const char *) panel_userptr(pan);
4893 int num = (userptr && *userptr) ? userptr[1] : '?';
4897 wprintw(win, "-pan%c-", num);
4900 for (y = 2; y < getmaxy(win) - 1; y++) {
4901 for (x = 1; x < getmaxx(win) - 1; x++) {
4903 waddch(win, UChar(num));
4908 #if USE_WIDEC_SUPPORT
4910 init_wide_panel(WINDOW *win)
4915 for (digit = 0; digit < 10; ++digit)
4916 make_fullwidth_digit(&temp[digit], digit);
4920 getyx(stdscr, y, x);
4921 digit = (y + x / 2) % 10;
4922 } while (wadd_wch(win, &temp[digit]) != ERR);
4926 fill_wide_panel(PANEL * pan)
4928 WINDOW *win = panel_window(pan);
4929 const char *userptr = (const char *) panel_userptr(pan);
4930 int num = (userptr && *userptr) ? userptr[1] : '?';
4934 wprintw(win, "-pan%c-", num);
4937 for (y = 2; y < getmaxy(win) - 1; y++) {
4938 for (x = 1; x < getmaxx(win) - 1; x++) {
4940 waddch(win, UChar(num));
4946 #define MAX_PANELS 5
4949 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4951 int which = cmd[1] - '0';
4956 hide_panel(px[which]);
4959 show_panel(px[which]);
4962 top_panel(px[which]);
4965 bottom_panel(px[which]);
4972 wait_a_while(nap_msec);
4976 demo_panels(void (*InitPanel) (WINDOW *), void (*FillPanel) (PANEL *))
4980 PANEL *px[MAX_PANELS + 1];
4982 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4986 for (count = 0; count < 5; count++) {
4987 px[1] = mkpanel(COLOR_RED,
4992 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4994 px[2] = mkpanel(COLOR_GREEN,
4999 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
5001 px[3] = mkpanel(COLOR_YELLOW,
5006 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
5008 px[4] = mkpanel(COLOR_BLUE,
5013 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
5015 px[5] = mkpanel(COLOR_MAGENTA,
5020 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
5032 wait_a_while(nap_msec);
5034 saywhat("h3 s1 s2 s4 s5");
5035 move_panel(px[1], 0, 0);
5042 wait_a_while(nap_msec);
5044 canned_panel(px, "s1");
5045 canned_panel(px, "s2");
5048 move_panel(px[2], LINES / 3 + 1, COLS / 8);
5050 wait_a_while(nap_msec);
5052 canned_panel(px, "s3");
5055 move_panel(px[3], LINES / 4 + 1, COLS / 15);
5057 wait_a_while(nap_msec);
5059 canned_panel(px, "b3");
5060 canned_panel(px, "s4");
5061 canned_panel(px, "s5");
5062 canned_panel(px, "t3");
5063 canned_panel(px, "t1");
5064 canned_panel(px, "t2");
5065 canned_panel(px, "t3");
5066 canned_panel(px, "t4");
5068 for (itmp = 0; itmp < 6; itmp++) {
5069 WINDOW *w4 = panel_window(px[4]);
5070 WINDOW *w5 = panel_window(px[5]);
5073 wmove(w4, LINES / 8, 1);
5074 waddstr(w4, mod[itmp]);
5075 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5076 wmove(w5, LINES / 6, 1);
5077 waddstr(w5, mod[itmp]);
5079 wait_a_while(nap_msec);
5082 wmove(w4, LINES / 6, 1);
5083 waddstr(w4, mod[itmp]);
5084 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
5085 wmove(w5, LINES / 8, 1);
5086 waddstr(w5, mod[itmp]);
5088 wait_a_while(nap_msec);
5092 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
5094 wait_a_while(nap_msec);
5096 canned_panel(px, "t5");
5097 canned_panel(px, "t2");
5098 canned_panel(px, "t1");
5099 canned_panel(px, "d2");
5100 canned_panel(px, "h3");
5101 canned_panel(px, "d1");
5102 canned_panel(px, "d4");
5103 canned_panel(px, "d5");
5104 canned_panel(px, "d3");
5106 wait_a_while(nap_msec);
5115 #endif /* USE_LIBPANEL */
5117 /****************************************************************************
5121 ****************************************************************************/
5125 static bool pending_pan = FALSE;
5126 static bool show_panner_legend = TRUE;
5129 panner_legend(int line)
5131 static const char *const legend[] =
5133 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
5134 "Use +,- (or j,k) to grow/shrink the panner vertically.",
5135 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
5136 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
5138 int n = ((int) SIZEOF(legend) - (LINES - line));
5140 if (move(line, 0) != ERR) {
5141 if (show_panner_legend)
5142 printw("%s", legend[n]);
5144 return show_panner_legend;
5151 panner_h_cleanup(int from_y, int from_x, int to_x)
5153 if (!panner_legend(from_y))
5154 do_h_line(from_y, from_x, ' ', to_x);
5158 panner_v_cleanup(int from_y, int from_x, int to_y)
5160 if (!panner_legend(from_y))
5161 do_v_line(from_y, from_x, ' ', to_y);
5165 fill_pad(WINDOW *panpad, bool pan_lines, bool colored)
5168 unsigned gridcount = 0;
5172 fill = (chtype) COLOR_PAIR(1);
5175 wmove(panpad, 0, 0);
5176 for (y = 0; y < getmaxy(panpad); y++) {
5177 for (x = 0; x < getmaxx(panpad); x++) {
5178 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
5179 if (y == 0 && x == 0)
5180 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
5182 waddch(panpad, pan_lines ? ACS_TTEE : '+');
5183 else if (y == 0 || x == 0)
5184 waddch(panpad, pan_lines ? ACS_LTEE : '+');
5186 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
5187 (int) (gridcount++ % 26)) | fill);
5188 } else if (y % GRIDSIZE == 0)
5189 waddch(panpad, pan_lines ? ACS_HLINE : '-');
5190 else if (x % GRIDSIZE == 0)
5191 waddch(panpad, pan_lines ? ACS_VLINE : '|');
5193 waddch(panpad, ' ');
5200 int top_x, int top_y, int porty, int portx,
5201 int (*pgetc) (WINDOW *),
5204 #if HAVE_GETTIMEOFDAY
5205 struct timeval before, after;
5208 bool pan_lines = FALSE;
5209 bool scrollers = TRUE;
5212 int pxmax, pymax, lowend, highend, c;
5214 getmaxyx(pad, pymax, pxmax);
5215 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5219 #ifdef NCURSES_VERSION
5221 * During shell-out, the user may have resized the window. Adjust
5222 * the port size of the pad to accommodate this. Ncurses automatically
5223 * resizes all of the normal windows to fit on the new screen.
5241 show_panner_legend = !show_panner_legend;
5242 panner_legend(LINES - 4);
5243 panner_legend(LINES - 3);
5244 panner_legend(LINES - 2);
5245 panner_legend(LINES - 1);
5248 pan_lines = !pan_lines;
5249 fill_pad(pad, pan_lines, colored);
5250 pending_pan = FALSE;
5253 #if HAVE_GETTIMEOFDAY
5257 panner_legend(LINES - 1);
5261 scrollers = !scrollers;
5264 /* Move the top-left corner of the pad, keeping the bottom-right
5267 case 'h': /* increase-columns: move left edge to left */
5271 panner_v_cleanup(top_y, top_x, porty);
5276 case 'j': /* decrease-lines: move top-edge down */
5280 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5285 case 'k': /* increase-lines: move top-edge up */
5290 panner_h_cleanup(top_y, top_x, portx);
5294 case 'l': /* decrease-columns: move left-edge to right */
5298 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5303 /* Move the bottom-right corner of the pad, keeping the top-left
5306 case KEY_IC: /* increase-columns: move right-edge to right */
5307 if (portx >= pxmax || portx >= COLS)
5310 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5315 case KEY_IL: /* increase-lines: move bottom-edge down */
5316 if (porty >= pymax || porty >= LINES)
5319 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5324 case KEY_DC: /* decrease-columns: move bottom edge up */
5329 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5333 case KEY_DL: /* decrease-lines */
5338 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5342 case KEY_LEFT: /* pan leftwards */
5349 case KEY_RIGHT: /* pan rightwards */
5350 if (basex + portx - (pymax > porty) < pxmax)
5356 case KEY_UP: /* pan upwards */
5363 case KEY_DOWN: /* pan downwards */
5364 if (basey + porty - (pxmax > portx) < pymax)
5379 basey = pymax - porty;
5389 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5390 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5391 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5393 if (scrollers && (pxmax > portx - 1)) {
5394 int length = (portx - top_x - 1);
5395 float ratio = ((float) length) / ((float) pxmax);
5397 lowend = (int) ((float) top_x + ((float) basex * ratio));
5398 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5400 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5401 if (highend < portx) {
5403 do_h_line(porty - 1, lowend, ' ', highend + 1);
5405 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5408 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5410 if (scrollers && (pymax > porty - 1)) {
5411 int length = (porty - top_y - 1);
5412 float ratio = ((float) length) / ((float) pymax);
5414 lowend = (int) ((float) top_y + ((float) basey * ratio));
5415 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5417 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5418 if (highend < porty) {
5420 do_v_line(lowend, portx - 1, ' ', highend + 1);
5422 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5425 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5427 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5428 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5429 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5432 #if HAVE_GETTIMEOFDAY
5433 gettimeofday(&before, 0);
5435 wnoutrefresh(stdscr);
5440 porty - (pxmax > portx) - 1,
5441 portx - (pymax > porty) - 1);
5444 #if HAVE_GETTIMEOFDAY
5445 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5448 gettimeofday(&after, 0);
5449 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5450 move(LINES - 1, COLS - 12);
5451 printw("Secs: %2.03f", elapsed);
5458 ((c = pgetc(pad)) != KEY_EXIT);
5460 scrollok(stdscr, TRUE); /* reset to driver's default */
5464 padgetch(WINDOW *win)
5470 if ((pending_pan = (count > 0)) != FALSE) {
5472 pending_pan = (count != 0);
5475 switch (c = wGetchar(win)) {
5511 case ERR: /* FALLTHRU */
5517 if (c >= '0' && c <= '9') {
5518 count = count * 10 + (c - '0');
5532 #define PAD_HIGH 200
5533 #define PAD_WIDE 200
5536 demo_pad(bool colored)
5537 /* Demonstrate pads. */
5539 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5542 Cannot("cannot create requested pad");
5546 if (colored && use_colors) {
5547 init_pair(1, COLOR_BLACK, COLOR_GREEN);
5548 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5549 wbkgd(panpad, (chtype) (COLOR_PAIR(2) | ' '));
5552 fill_pad(panpad, FALSE, colored);
5554 panner_legend(LINES - 4);
5555 panner_legend(LINES - 3);
5556 panner_legend(LINES - 2);
5557 panner_legend(LINES - 1);
5559 keypad(panpad, TRUE);
5561 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5562 * We'll still be able to widen it during a test, since that's required
5563 * for testing boundaries.
5565 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch, colored);
5572 /****************************************************************************
5574 * Tests from John Burnell's PDCurses tester
5576 ****************************************************************************/
5579 Continue(WINDOW *win)
5583 MvWAddStr(win, 10, 1, " Press any key to continue");
5589 flushinp_test(WINDOW *win)
5590 /* Input test, adapted from John Burnell's PDCurses tester */
5592 int w, h, bx, by, sw, sh, i;
5597 getmaxyx(win, h, w);
5598 getbegyx(win, by, bx);
5601 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5606 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5607 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
5610 (void) wattrset(subWin, A_BOLD);
5611 box(subWin, ACS_VLINE, ACS_HLINE);
5612 MvWAddStr(subWin, 2, 1, "This is a subwindow");
5616 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5617 * it only happened to "work" on SVr4 because that implementation does not
5618 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5619 * test behavior, we're using 'cbreak()', which will allow a single
5620 * character to return without needing a newline. - T.Dickey 1997/10/11.
5623 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
5625 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
5626 MvWAddStr(win, 3, 1,
5627 "These should be discarded (not echoed) after the subwindow goes away.");
5630 for (i = 0; i < 5; i++) {
5631 MvWPrintw(subWin, 1, 1, "Time = %d", i);
5643 MvWAddStr(win, 2, 1,
5644 "If you were still typing when the window timer expired,");
5645 MvWAddStr(win, 3, 1,
5646 "or else you typed nothing at all while it was running,");
5647 MvWAddStr(win, 4, 1,
5648 "test was invalid. You'll see garbage or nothing at all. ");
5649 MvWAddStr(win, 6, 1, "Press a key");
5655 MvWAddStr(win, 12, 0,
5656 "If you see any key other than what you typed, flushinp() is broken.");
5665 "What you typed should now have been deleted; if not, wdelch() failed.");
5671 /****************************************************************************
5675 ****************************************************************************/
5683 menu_virtualize(int c)
5685 if (c == '\n' || c == KEY_EXIT)
5686 return (MAX_COMMAND + 1);
5688 return (REQ_SCR_ULINE);
5690 return (REQ_SCR_DLINE);
5691 else if (c == 'b' || c == KEY_NPAGE)
5692 return (REQ_SCR_UPAGE);
5693 else if (c == 'f' || c == KEY_PPAGE)
5694 return (REQ_SCR_DPAGE);
5695 else if (c == 'n' || c == KEY_DOWN)
5696 return (REQ_NEXT_ITEM);
5697 else if (c == 'p' || c == KEY_UP)
5698 return (REQ_PREV_ITEM);
5700 return (REQ_TOGGLE_ITEM);
5708 static CONST_MENUS char *animals[] =
5721 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5722 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5730 ITEM *items[SIZEOF(animals)];
5732 CONST_MENUS char **ap;
5733 int mrows, mcols, c;
5736 #ifdef NCURSES_MOUSE_VERSION
5737 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5739 MvAddStr(0, 0, "This is the menu test:");
5740 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
5741 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
5743 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
5744 MvAddStr(5, 0, " Press return to exit.");
5747 for (ap = animals; *ap; ap++) {
5748 if ((*ip = new_item(*ap, "")) != 0)
5753 m = new_menu(items);
5755 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
5756 scale_menu(m, &mrows, &mcols);
5758 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5759 set_menu_win(m, menuwin);
5760 keypad(menuwin, TRUE);
5763 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5767 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
5768 if (c == E_NOT_POSTED)
5770 if (c == E_REQUEST_DENIED)
5775 MvPrintw(LINES - 2, 0,
5776 "You chose: %s\n", item_name(current_item(m)));
5777 (void) addstr("Press any key to continue...");
5784 for (ip = items; *ip; ip++)
5786 #ifdef NCURSES_MOUSE_VERSION
5787 mousemask(0, (mmask_t *) 0);
5792 #define T_TBL(name) { #name, name }
5798 T_TBL(TRACE_DISABLE),
5801 T_TBL(TRACE_UPDATE),
5803 T_TBL(TRACE_CHARPUT),
5804 T_TBL(TRACE_ORDINARY),
5806 T_TBL(TRACE_VIRTPUT),
5807 T_TBL(TRACE_IEVENT),
5809 T_TBL(TRACE_ICALLS),
5810 T_TBL(TRACE_CCALLS),
5811 T_TBL(TRACE_DATABASE),
5813 T_TBL(TRACE_MAXIMUM),
5820 tracetrace(unsigned tlevel)
5827 for (n = 0; t_tbl[n].name != 0; n++)
5828 need += strlen(t_tbl[n].name) + 2;
5829 buf = typeMalloc(char, need);
5831 failed("tracetrace");
5833 sprintf(buf, "0x%02x = {", tlevel);
5835 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5837 for (n = 1; t_tbl[n].name != 0; n++)
5838 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5839 strcat(buf, t_tbl[n].name);
5843 if (buf[strlen(buf) - 2] == ',')
5844 buf[strlen(buf) - 2] = '\0';
5845 return (strcat(buf, "}"));
5848 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5852 run_trace_menu(MENU * m)
5858 bool changed = FALSE;
5859 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5860 case E_UNKNOWN_COMMAND:
5863 items = menu_items(m);
5864 i = current_item(m);
5865 if (i == items[0]) {
5866 if (item_value(i)) {
5867 for (p = items + 1; *p != 0; p++)
5868 if (item_value(*p)) {
5869 set_item_value(*p, FALSE);
5874 for (p = items + 1; *p != 0; p++)
5875 if (item_value(*p)) {
5876 set_item_value(items[0], FALSE);
5889 /* interactively set the trace level */
5892 ITEM *items[SIZEOF(t_tbl)];
5899 MvAddStr(0, 0, "Interactively set trace level:");
5900 MvAddStr(2, 0, " Press space bar to toggle a selection.");
5901 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
5902 MvAddStr(4, 0, " Press return to set the trace level.");
5903 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5907 for (n = 0; t_tbl[n].name != 0; n++) {
5908 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
5914 m = new_menu(items);
5916 set_menu_format(m, 0, 2);
5917 scale_menu(m, &mrows, &mcols);
5919 menu_opts_off(m, O_ONEVALUE);
5920 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5921 set_menu_win(m, menuwin);
5922 keypad(menuwin, TRUE);
5925 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5929 for (ip = menu_items(m); *ip; ip++) {
5930 unsigned mask = t_tbl[item_index(*ip)].mask;
5932 set_item_value(*ip, _nc_tracing == 0);
5933 else if ((mask & _nc_tracing) == mask)
5934 set_item_value(*ip, TRUE);
5937 while (run_trace_menu(m))
5941 for (ip = menu_items(m); *ip; ip++)
5942 if (item_value(*ip))
5943 newtrace |= t_tbl[item_index(*ip)].mask;
5945 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5947 MvPrintw(LINES - 2, 0,
5948 "Trace level is %s\n", tracetrace(_nc_tracing));
5949 (void) addstr("Press any key to continue...");
5956 for (ip = items; *ip; ip++)
5960 #endif /* USE_LIBMENU */
5962 /****************************************************************************
5966 ****************************************************************************/
5969 make_label(int frow, int fcol, NCURSES_CONST char *label)
5971 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5974 set_field_buffer(f, 0, label);
5975 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
5981 make_field(int frow, int fcol, int rows, int cols, bool secure)
5983 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5986 set_field_back(f, A_UNDERLINE);
5987 set_field_userptr(f, (void *) 0);
5993 display_form(FORM * f)
5998 scale_form(f, &rows, &cols);
6000 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
6002 set_form_sub(f, derwin(w, rows, cols, 1, 2));
6005 if (post_form(f) != E_OK)
6011 erase_form(FORM * f)
6013 WINDOW *w = form_win(f);
6014 WINDOW *s = form_sub(f);
6024 edit_secure(FIELD * me, int c)
6026 int rows, cols, frow, fcol, nrow, nbuf;
6028 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
6030 char *source = field_buffer(me, 1);
6031 size_t have = (source ? strlen(source) : 0) + 1;
6032 size_t need = 80 + have;
6033 char *temp = malloc(need);
6037 strncpy(temp, source ? source : "", have + 1);
6038 len = (size_t) (char *) field_userptr(me);
6040 if (isgraph(c) && (len + 1) < sizeof(temp)) {
6041 temp[len++] = (char) c;
6043 set_field_buffer(me, 1, temp);
6063 case REQ_RIGHT_CHAR:
6065 c = 0; /* we don't want to do inline editing */
6070 set_field_buffer(me, 1, temp);
6077 set_field_buffer(me, 1, temp);
6082 set_field_userptr(me, (void *) len);
6090 form_virtualize(FORM * f, WINDOW *w)
6093 static const struct {
6097 { CTRL('A'), REQ_NEXT_CHOICE },
6098 { CTRL('B'), REQ_PREV_WORD },
6099 { CTRL('C'), REQ_CLR_EOL },
6100 { CTRL('D'), REQ_DOWN_FIELD },
6101 { CTRL('E'), REQ_END_FIELD },
6102 { CTRL('F'), REQ_NEXT_PAGE },
6103 { CTRL('G'), REQ_DEL_WORD },
6104 { CTRL('H'), REQ_DEL_PREV },
6105 { CTRL('I'), REQ_INS_CHAR },
6106 { CTRL('K'), REQ_CLR_EOF },
6107 { CTRL('L'), REQ_LEFT_FIELD },
6108 { CTRL('M'), REQ_NEW_LINE },
6109 { CTRL('N'), REQ_NEXT_FIELD },
6110 { CTRL('O'), REQ_INS_LINE },
6111 { CTRL('P'), REQ_PREV_FIELD },
6112 { CTRL('R'), REQ_RIGHT_FIELD },
6113 { CTRL('S'), REQ_BEG_FIELD },
6114 { CTRL('U'), REQ_UP_FIELD },
6115 { CTRL('V'), REQ_DEL_CHAR },
6116 { CTRL('W'), REQ_NEXT_WORD },
6117 { CTRL('X'), REQ_CLR_FIELD },
6118 { CTRL('Y'), REQ_DEL_LINE },
6119 { CTRL('Z'), REQ_PREV_CHOICE },
6120 { ESCAPE, MAX_FORM_COMMAND + 1 },
6121 { KEY_BACKSPACE, REQ_DEL_PREV },
6122 { KEY_DOWN, REQ_DOWN_CHAR },
6123 { KEY_END, REQ_LAST_FIELD },
6124 { KEY_HOME, REQ_FIRST_FIELD },
6125 { KEY_LEFT, REQ_LEFT_CHAR },
6126 { KEY_LL, REQ_LAST_FIELD },
6127 { KEY_NEXT, REQ_NEXT_FIELD },
6128 { KEY_NPAGE, REQ_NEXT_PAGE },
6129 { KEY_PPAGE, REQ_PREV_PAGE },
6130 { KEY_PREVIOUS, REQ_PREV_FIELD },
6131 { KEY_RIGHT, REQ_RIGHT_CHAR },
6132 { KEY_UP, REQ_UP_CHAR },
6133 { QUIT, MAX_FORM_COMMAND + 1 }
6137 static int mode = REQ_INS_MODE;
6138 int c = wGetchar(w);
6140 FIELD *me = current_field(f);
6141 bool current = TRUE;
6143 if (c == CTRL(']')) {
6144 if (mode == REQ_INS_MODE) {
6145 mode = REQ_OVL_MODE;
6147 mode = REQ_INS_MODE;
6151 for (n = 0; n < SIZEOF(lookup); n++) {
6152 if (lookup[n].code == c) {
6153 c = lookup[n].result;
6158 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
6161 * Force the field that the user is typing into to be in reverse video,
6162 * while the other fields are shown underlined.
6177 case REQ_LEFT_FIELD:
6179 case REQ_RIGHT_CHAR:
6183 current = (c < KEY_MAX);
6187 c = edit_secure(me, c);
6188 set_field_back(me, A_REVERSE);
6190 c = edit_secure(me, c);
6191 set_field_back(me, A_UNDERLINE);
6197 my_form_driver(FORM * form, int c)
6199 if (c == (MAX_FORM_COMMAND + 1)
6200 && form_driver(form, REQ_VALIDATION) == E_OK)
6208 #ifdef NCURSES_VERSION
6209 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6210 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6212 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6213 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6217 * Allow a middle initial, optionally with a '.' to end it.
6220 FIELDCHECK_CB(mi_field_check)
6222 char *s = field_buffer(fld, 0);
6226 for (n = 0; s[n] != '\0'; ++n) {
6233 } else if (isspace(UChar(s[n]))) {
6238 if (!isspace(UChar(s[n])))
6244 /* force the form to display a leading capital */
6245 if (islower(UChar(s[0]))) {
6246 s[0] = (char) toupper(UChar(s[0]));
6247 set_field_buffer(fld, 0, s);
6253 CHAR_CHECK_CB(mi_char_check)
6255 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6259 * Passwords should be at least 6 characters.
6262 FIELDCHECK_CB(pw_field_check)
6264 char *s = field_buffer(fld, 0);
6267 for (n = 0; s[n] != '\0'; ++n) {
6268 if (isspace(UChar(s[n]))) {
6277 CHAR_CHECK_CB(pw_char_check)
6279 return (isgraph(ch) ? TRUE : FALSE);
6287 FIELD *f[12], *secure;
6288 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6289 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6290 int finished = 0, c;
6293 #ifdef NCURSES_MOUSE_VERSION
6294 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6298 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6299 addstr("^N -- go to next field ^P -- go to previous field\n");
6300 addstr("Home -- go to first field End -- go to last field\n");
6301 addstr("^L -- go to field to left ^R -- go to field to right\n");
6302 addstr("^U -- move upward to field ^D -- move downward to field\n");
6303 addstr("^W -- go to next word ^B -- go to previous word\n");
6304 addstr("^S -- go to start of field ^E -- go to end of field\n");
6305 addstr("^H -- delete previous char ^Y -- delete line\n");
6306 addstr("^G -- delete current word ^C -- clear to end of line\n");
6307 addstr("^K -- clear to end of field ^X -- clear field\n");
6308 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6310 MvAddStr(4, 57, "Forms Entry Test");
6314 /* describe the form */
6315 memset(f, 0, sizeof(f));
6316 f[n++] = make_label(0, 15, "Sample Form");
6318 f[n++] = make_label(2, 0, "Last Name");
6319 f[n++] = make_field(3, 0, 1, 18, FALSE);
6320 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6322 f[n++] = make_label(2, 20, "First Name");
6323 f[n++] = make_field(3, 20, 1, 12, FALSE);
6324 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6326 f[n++] = make_label(2, 34, "Middle Name");
6327 f[n++] = make_field(3, 34, 1, 12, FALSE);
6328 set_field_type(f[n - 1], fty_middle);
6330 f[n++] = make_label(5, 0, "Comments");
6331 f[n++] = make_field(6, 0, 4, 46, FALSE);
6333 f[n++] = make_label(5, 20, "Password:");
6335 f[n++] = make_field(5, 30, 1, 9, TRUE);
6336 set_field_type(f[n - 1], fty_passwd);
6339 if ((form = new_form(f)) != 0) {
6345 nonl(); /* lets us read ^M's */
6347 switch (form_driver(form, c = form_virtualize(form, w))) {
6349 MvAddStr(5, 57, field_buffer(secure, 1));
6353 case E_UNKNOWN_COMMAND:
6354 finished = my_form_driver(form, c);
6366 for (c = 0; f[c] != 0; c++)
6368 free_fieldtype(fty_middle);
6369 free_fieldtype(fty_passwd);
6373 #ifdef NCURSES_MOUSE_VERSION
6374 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6377 #endif /* USE_LIBFORM */
6379 /****************************************************************************
6383 ****************************************************************************/
6386 fillwin(WINDOW *win, char ch)
6391 getmaxyx(win, y1, x1);
6392 for (y = 0; y < y1; y++) {
6394 for (x = 0; x < x1; x++)
6395 waddch(win, UChar(ch));
6400 crosswin(WINDOW *win, char ch)
6405 getmaxyx(win, y1, x1);
6406 for (y = 0; y < y1; y++) {
6407 for (x = 0; x < x1; x++)
6408 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
6409 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
6411 waddch(win, UChar(ch));
6416 #define OVERLAP_FLAVORS 5
6419 overlap_helpitem(int state, int item, char *message)
6421 int row = (item / 2);
6422 int col = ((item % 2) ? COLS / 2 : 0);
6424 move(LINES - 6 + row, col);
6425 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6430 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6432 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (1 + (flavor * 2) + col);
6436 (void) wattrset(win, A_NORMAL);
6439 (void) wattrset(win, A_BOLD);
6442 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6443 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_NORMAL));
6446 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6447 (void) wattrset(win, AttrArg(COLOR_PAIR(cpair), A_BOLD));
6453 overlap_test_2_attr(WINDOW *win, int flavor, int col)
6455 NCURSES_PAIRS_T cpair = (NCURSES_PAIRS_T) (9 + (flavor * 2) + col);
6465 init_pair(cpair, COLOR_RED, COLOR_GREEN);
6466 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
6469 wbkgdset(win, ' ' | A_NORMAL);
6475 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
6480 const char *ths, *tht;
6484 state += OVERLAP_FLAVORS;
6485 state = state % OVERLAP_FLAVORS;
6486 assert(state >= 0 && state < OVERLAP_FLAVORS);
6488 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
6491 ths = col ? "B" : "A";
6492 tht = col ? "A" : "B";
6497 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
6505 overlap_test_1_attr(stdscr, flavors[row], col);
6506 sprintf(msg, "fill window %s with letter %s.", ths, ths);
6514 switch (flavors[row]) {
6516 sprintf(msg, "cross pattern in window %s.", ths);
6519 sprintf(msg, "draw box in window %s.", ths);
6522 sprintf(msg, "set background of window %s.", ths);
6525 sprintf(msg, "reset background of window %s.", ths);
6531 sprintf(msg, "clear window %s.", ths);
6535 switch (flavors[row]) {
6537 sprintf(msg, "overwrite %s onto %s.", ths, tht);
6540 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
6543 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
6546 sprintf(msg, "overlay %s onto %s.", ths, tht);
6551 overlap_helpitem(state, item, msg);
6552 (void) wattrset(stdscr, A_NORMAL);
6553 wbkgdset(stdscr, ' ' | A_NORMAL);
6556 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
6557 state, flavors[state]);
6563 overlap_test_0(WINDOW *a, WINDOW *b)
6573 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
6575 overlap_test_1_attr(a, flavor, col);
6577 (void) wattrset(a, A_NORMAL);
6581 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6583 overlap_test_2_attr(a, flavor, col);
6592 /* done in overlap_test_2_attr */
6595 /* done in overlap_test_2_attr */
6601 overlap_test_3(WINDOW *a)
6608 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
6615 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
6618 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
6626 /* test effects of overlapping windows */
6631 int state, flavor[OVERLAP_FLAVORS];
6633 WINDOW *win1 = newwin(9, 20, 3, 3);
6634 WINDOW *win2 = newwin(9, 20, 9, 16);
6640 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
6641 printw("the shared region of two overlapping windows A and B. The cross\n");
6642 printw("pattern in each window does not overlap the other.\n");
6644 memset(flavor, 0, sizeof(flavor));
6645 state = overlap_help(0, flavor);
6647 while (!isQuit(ch = Getchar()))
6649 case 'a': /* refresh window A first, then B */
6650 overlap_test_0(win1, win2);
6653 case 'b': /* refresh window B first, then A */
6654 overlap_test_0(win2, win1);
6657 case 'c': /* fill window A so it's visible */
6658 overlap_test_1(flavor[1], 0, win1, 'A');
6661 case 'd': /* fill window B so it's visible */
6662 overlap_test_1(flavor[1], 1, win2, 'B');
6665 case 'e': /* cross test pattern in window A */
6666 overlap_test_2(flavor[2], 0, win1, 'A');
6669 case 'f': /* cross test pattern in window A */
6670 overlap_test_2(flavor[2], 1, win2, 'B');
6673 case 'g': /* clear window A */
6674 overlap_test_3(win1);
6677 case 'h': /* clear window B */
6678 overlap_test_3(win2);
6681 case 'i': /* overwrite A onto B */
6682 overlap_test_4(flavor[4], win1, win2);
6685 case 'j': /* overwrite B onto A */
6686 overlap_test_4(flavor[4], win2, win1);
6691 state = overlap_help(state + 1, flavor);
6696 state = overlap_help(state - 1, flavor);
6701 state = overlap_help(state, flavor);
6705 state = overlap_help(state, flavor);
6720 /****************************************************************************
6724 ****************************************************************************/
6727 do_single_test(const char c)
6728 /* perform a single specified test */
6735 #if USE_WIDEC_SUPPORT
6745 #if USE_WIDEC_SUPPORT
6753 Cannot("does not support color.");
6758 #if USE_WIDEC_SUPPORT
6761 Cannot("does not support color.");
6769 Cannot("does not support color.");
6770 else if (!can_change_color())
6771 Cannot("has hardwired color values.");
6781 #if USE_WIDEC_SUPPORT
6792 #if USE_WIDEC_SUPPORT
6800 demo_panels(init_panel, fill_panel);
6804 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6806 demo_panels(init_wide_panel, fill_wide_panel);
6815 flushinp_test(stdscr);
6819 test_sgr_attributes();
6846 #if USE_LIBMENU && defined(TRACE)
6865 static const char *const tbl[] =
6867 "Usage: ncurses [options]"
6870 #ifdef NCURSES_VERSION
6871 ," -a f,b set default-colors (assumed white-on-black)"
6872 ," -d use default-colors if terminal supports them"
6875 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
6878 ," -e fmt specify format for soft-keys test (e)"
6881 ," -f rip-off footer line (can repeat)"
6882 ," -h rip-off header line (can repeat)"
6884 ," -m do not use colors"
6885 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6887 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6889 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(__MINGW32__)
6890 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
6893 ," -t mask specify default trace-level (may toggle with ^T)"
6897 for (n = 0; n < SIZEOF(tbl); n++)
6898 fprintf(stderr, "%s\n", tbl[n]);
6899 ExitProgram(EXIT_FAILURE);
6903 set_terminal_modes(void)
6908 scrollok(stdscr, TRUE);
6909 idlok(stdscr, TRUE);
6910 keypad(stdscr, TRUE);
6915 announce_sig(int sig)
6917 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6923 rip_footer(WINDOW *win, int cols)
6925 wbkgd(win, A_REVERSE);
6928 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
6934 rip_header(WINDOW *win, int cols)
6936 wbkgd(win, A_REVERSE);
6939 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
6943 #endif /* HAVE_RIPOFFLINE */
6951 (void) puts("This is the ncurses main menu");
6952 (void) puts("a = keyboard and mouse input test");
6953 #if USE_WIDEC_SUPPORT
6954 (void) puts("A = wide-character keyboard and mouse input test");
6956 (void) puts("b = character attribute test");
6957 #if USE_WIDEC_SUPPORT
6958 (void) puts("B = wide-character attribute test");
6960 (void) puts("c = color test pattern");
6961 #if USE_WIDEC_SUPPORT
6962 (void) puts("C = color test pattern using wide-character calls");
6965 (void) puts("d = edit RGB color values");
6967 (void) puts("e = exercise soft keys");
6968 #if USE_WIDEC_SUPPORT
6969 (void) puts("E = exercise soft keys using wide-characters");
6972 (void) puts("f = display ACS characters");
6973 #if USE_WIDEC_SUPPORT
6974 (void) puts("F = display Wide-ACS characters");
6976 (void) puts("g = display windows and scrolling");
6977 (void) puts("i = test of flushinp()");
6978 (void) puts("k = display character attributes");
6980 (void) puts("m = menu code test");
6983 (void) puts("o = exercise panels library");
6984 #if USE_WIDEC_SUPPORT
6985 (void) puts("O = exercise panels with wide-characters");
6988 (void) puts("p = exercise pad features");
6989 (void) puts("P = exercise pad features, using color");
6990 (void) puts("q = quit");
6992 (void) puts("r = exercise forms code");
6994 (void) puts("s = overlapping-refresh test");
6995 #if USE_LIBMENU && defined(TRACE)
6996 (void) puts("t = set trace level");
6998 (void) puts("? = repeat this command summary");
7000 (void) fputs("> ", stdout);
7001 (void) fflush(stdout); /* necessary under SVr4 curses */
7004 * This used to be an 'fgets()' call (until 1996/10). However with
7005 * some runtime libraries, mixing stream I/O and 'read()' causes the
7006 * input stream to be flushed when switching between the two.
7011 if (read(fileno(stdin), &ch, (size_t) 1) <= 0) {
7015 } else if (command == 0 && !isspace(UChar(ch))) {
7017 } else if (ch == '\n' || ch == '\r') {
7018 if ((command == 'd') && !top) {
7019 (void) fputs("Do not nest test-d\n", stdout);
7024 (void) fputs("> ", stdout);
7025 (void) fflush(stdout);
7029 if (do_single_test(command)) {
7031 * This may be overkill; it's intended to reset everything back
7032 * to the initial terminal modes so that tests don't get in
7036 set_terminal_modes();
7041 if (command == '?') {
7042 (void) puts("This is the ncurses capability tester.");
7044 puts("You may select a test from the main menu by typing the");
7046 puts("key letter of the choice (the letter to left of the =)");
7048 puts("at the > prompt. Type `q' to exit.");
7056 /*+-------------------------------------------------------------------------
7058 --------------------------------------------------------------------------*/
7060 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
7061 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
7064 main(int argc, char *argv[])
7068 #ifdef NCURSES_VERSION
7069 int default_fg = COLOR_WHITE;
7070 int default_bg = COLOR_BLACK;
7071 bool assumed_colors = FALSE;
7072 bool default_colors = FALSE;
7074 char *palette_file = 0;
7075 bool monochrome = FALSE;
7077 setlocale(LC_ALL, "");
7079 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:")) != -1) {
7081 #ifdef NCURSES_VERSION
7083 assumed_colors = TRUE;
7084 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
7086 default_fg = COLOR_WHITE;
7089 default_bg = COLOR_BLACK;
7094 default_colors = TRUE;
7103 my_e_param = atoi(optarg);
7104 #ifdef NCURSES_VERSION
7105 if (my_e_param > 3) /* allow extended layouts */
7114 ripoffline(-1, rip_footer);
7117 ripoffline(1, rip_header);
7119 #endif /* HAVE_RIPOFFLINE */
7124 palette_file = optarg;
7128 nap_msec = (int) atol(optarg);
7131 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714) && !defined(__MINGW32__)
7138 save_trace = (unsigned) strtol(optarg, 0, 0);
7147 * If there's no menus (unlikely for ncurses!), then we'll have to set
7148 * tracing on initially, just in case the user wants to test something that
7149 * doesn't involve wGetchar.
7152 /* enable debugging */
7156 if (!isatty(fileno(stdin)))
7158 #endif /* USE_LIBMENU */
7162 /* tell it we're going to play with soft keys */
7163 slk_init(my_e_param);
7167 /* set up null signal catcher so we can see what interrupts to getch do */
7168 signal(SIGUSR1, announce_sig);
7171 /* we must initialize the curses data structure only once */
7175 /* tests, in general, will want these modes */
7176 use_colors = (bool) (monochrome ? FALSE : has_colors());
7180 #ifdef NCURSES_VERSION_PATCH
7181 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
7182 #if HAVE_USE_DEFAULT_COLORS
7183 if (default_colors) {
7184 use_default_colors();
7187 #if HAVE_ASSUME_DEFAULT_COLORS
7189 assume_default_colors(default_fg, default_bg);
7192 #else /* normal SVr4 curses */
7193 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
7195 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
7197 if (can_change_color()) {
7199 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
7201 failed("all_colors");
7202 for (cp = 0; cp < max_colors; ++cp) {
7204 &all_colors[cp].red,
7205 &all_colors[cp].green,
7206 &all_colors[cp].blue);
7208 if (palette_file != 0) {
7209 FILE *fp = fopen(palette_file, "r");
7211 char buffer[BUFSIZ];
7212 int red, green, blue;
7214 while (fgets(buffer, sizeof(buffer), fp) != 0) {
7215 if (sscanf(buffer, "scale:%d", &c) == 1) {
7217 } else if (sscanf(buffer, "%d:%d %d %d",
7226 #define Scaled(n) (NCURSES_COLOR_T) (((n) * 1000) / scale)
7227 all_colors[c].red = Scaled(red);
7228 all_colors[c].green = Scaled(green);
7229 all_colors[c].blue = Scaled(blue);
7237 set_terminal_modes();
7241 * Return to terminal mode, so we're guaranteed of being able to
7242 * select terminal commands even if the capabilities are wrong.
7246 #if HAVE_CURSES_VERSION
7247 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
7248 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
7249 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
7250 NCURSES_VERSION_MAJOR,
7251 NCURSES_VERSION_MINOR,
7252 NCURSES_VERSION_PATCH);
7254 (void) puts("Welcome to ncurses. Press ? for help.");
7259 ExitProgram(EXIT_SUCCESS);
7262 /* ncurses.c ends here */