1 /****************************************************************************
2 * Copyright (c) 1998-2011,2012 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.377 2012/09/08 23:58:58 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
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 */
165 static RGB_DATA *all_colors;
167 static void main_menu(bool);
169 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
170 * though we can rely on negative x/y values to stop the macro.
173 do_h_line(int y, int x, chtype c, int to)
176 MvHLine(y, x, c, (to) - (x));
180 do_v_line(int y, int x, chtype c, int to)
183 MvVLine(y, x, c, (to) - (y));
197 return ((c) == QUIT || (c) == ESCAPE);
199 #define case_QUIT QUIT: case ESCAPE
201 /* Common function to allow ^T to toggle trace-mode in the middle of a test
202 * so that trace-files can be made smaller.
205 wGetchar(WINDOW *win)
209 while ((c = wgetch(win)) == CTRL('T')) {
211 save_trace = _nc_tracing;
212 Trace(("TOGGLE-TRACING OFF"));
215 _nc_tracing = save_trace;
219 Trace(("TOGGLE-TRACING ON"));
226 #define Getchar() wGetchar(stdscr)
228 /* replaces wgetnstr(), since we want to be able to edit values */
230 wGetstring(WINDOW *win, char *buffer, int limit)
237 (void) wattrset(win, A_REVERSE);
239 x = (int) strlen(buffer);
241 if (x > (int) strlen(buffer))
242 x = (int) strlen(buffer);
244 wprintw(win, "%-*s", limit, buffer);
245 wmove(win, y0, x0 + x);
246 switch (ch = wGetchar(win)) {
259 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
277 if (!isprint(ch) || ch >= KEY_MIN) {
279 } else if ((int) strlen(buffer) < limit) {
281 for (j = (int) strlen(buffer) + 1; j > x; --j) {
282 buffer[j] = buffer[j - 1];
284 buffer[x++] = (char) ch;
291 wattroff(win, A_REVERSE);
296 #if USE_WIDEC_SUPPORT
300 return (ch + 0xff10 - '0');
304 make_fullwidth_text(wchar_t *target, const char *source)
307 while ((ch = *source++) != 0) {
308 *target++ = fullwidth_of(ch);
314 make_narrow_text(wchar_t *target, const char *source)
317 while ((ch = *source++) != 0) {
325 make_fullwidth_digit(cchar_t *target, int digit)
329 source[0] = fullwidth_of(digit + '0');
331 setcchar(target, source, A_NORMAL, 0, 0);
336 wGet_wchar(WINDOW *win, wint_t *result)
340 while ((c = wget_wch(win, result)) == CTRL('T')) {
342 save_trace = _nc_tracing;
343 Trace(("TOGGLE-TRACING OFF"));
346 _nc_tracing = save_trace;
350 Trace(("TOGGLE-TRACING ON"));
353 c = wget_wch(win, result);
357 #define Get_wchar(result) wGet_wchar(stdscr, result)
359 /* replaces wgetn_wstr(), since we want to be able to edit values */
361 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
370 (void) wattrset(win, A_REVERSE);
372 x = (int) wcslen(buffer);
374 if (x > (int) wcslen(buffer))
375 x = (int) wcslen(buffer);
377 /* clear the "window' */
379 wprintw(win, "%*s", limit, " ");
381 /* write the existing buffer contents */
383 waddnwstr(win, buffer, limit);
385 /* positions the cursor past character 'x' */
387 waddnwstr(win, buffer, x);
389 switch (wGet_wchar(win, &ch)) {
429 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
449 } else if ((int) wcslen(buffer) < limit) {
451 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
452 buffer[j] = buffer[j - 1];
454 buffer[x++] = (wchar_t) ch;
461 wattroff(win, A_REVERSE);
472 addstr("Press any key to continue... ");
477 Cannot(const char *what)
479 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
484 ShellOut(bool message)
487 addstr("Shelling out...");
493 IGNORE_RC(system("sh"));
496 addstr("returned from shellout.\n");
500 #ifdef NCURSES_MOUSE_VERSION
502 * This function is the same as _tracemouse(), but we cannot count on that
503 * being available in the non-debug library.
506 mouse_decode(MEVENT const *ep)
508 static char buf[80 + (5 * 10) + (32 * 15)];
510 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
511 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
513 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
515 SHOW(BUTTON1_RELEASED, "release-1");
516 SHOW(BUTTON1_PRESSED, "press-1");
517 SHOW(BUTTON1_CLICKED, "click-1");
518 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
519 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
520 #if NCURSES_MOUSE_VERSION == 1
521 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
524 SHOW(BUTTON2_RELEASED, "release-2");
525 SHOW(BUTTON2_PRESSED, "press-2");
526 SHOW(BUTTON2_CLICKED, "click-2");
527 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
528 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
529 #if NCURSES_MOUSE_VERSION == 1
530 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
533 SHOW(BUTTON3_RELEASED, "release-3");
534 SHOW(BUTTON3_PRESSED, "press-3");
535 SHOW(BUTTON3_CLICKED, "click-3");
536 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
537 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
538 #if NCURSES_MOUSE_VERSION == 1
539 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
542 SHOW(BUTTON4_RELEASED, "release-4");
543 SHOW(BUTTON4_PRESSED, "press-4");
544 SHOW(BUTTON4_CLICKED, "click-4");
545 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
546 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
547 #if NCURSES_MOUSE_VERSION == 1
548 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
551 #if NCURSES_MOUSE_VERSION == 2
552 SHOW(BUTTON5_RELEASED, "release-5");
553 SHOW(BUTTON5_PRESSED, "press-5");
554 SHOW(BUTTON5_CLICKED, "click-5");
555 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
556 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
559 SHOW(BUTTON_CTRL, "ctrl");
560 SHOW(BUTTON_SHIFT, "shift");
561 SHOW(BUTTON_ALT, "alt");
562 SHOW(ALL_MOUSE_EVENTS, "all-events");
563 SHOW(REPORT_MOUSE_POSITION, "position");
567 if (buf[strlen(buf) - 1] == ' ')
568 buf[strlen(buf) - 2] = '\0';
569 (void) strcat(buf, "}");
574 show_mouse(WINDOW *win)
582 outside = !wenclose(win, event.y, event.x);
585 (void) wstandout(win);
586 waddstr(win, "KEY_MOUSE");
587 (void) wstandend(win);
589 waddstr(win, "KEY_MOUSE");
591 wprintw(win, ", %s", mouse_decode(&event));
596 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
600 wmove(win, event.y, event.x);
608 #endif /* NCURSES_MOUSE_VERSION */
610 /****************************************************************************
612 * Character input test
614 ****************************************************************************/
616 #define NUM_GETCH_FLAGS 256
617 typedef bool GetchFlags[NUM_GETCH_FLAGS];
620 setup_getch(WINDOW *win, GetchFlags flags)
622 keypad(win, flags['k']); /* should be redundant, but for testing */
623 meta(win, flags['m']); /* force this to a known state */
631 init_getch(WINDOW *win, GetchFlags flags)
633 memset(flags, FALSE, NUM_GETCH_FLAGS);
634 flags[UChar('k')] = (win == stdscr);
635 flags[UChar('m')] = TRUE;
637 setup_getch(win, flags);
641 wgetch_help(WINDOW *win, GetchFlags flags)
643 static const char *help[] =
645 "e -- toggle echo mode"
646 ,"g -- triggers a getstr test"
647 ,"k -- toggle keypad/literal mode"
648 ,"m -- toggle meta (7-bit/8-bit) mode"
651 ,"w -- create a new window"
653 ,"z -- suspend this process"
657 unsigned chk = ((SIZEOF(help) + 1) / 2);
662 printw("Type any key to see its %s value. Also:\n",
663 flags['k'] ? "keypad" : "literal");
664 for (n = 0; n < SIZEOF(help); ++n) {
665 int row = 1 + (int) (n % chk);
666 int col = (n >= chk) ? COLS / 2 : 0;
667 int flg = ((strstr(help[n], "toggle") != 0)
668 && (flags[UChar(*help[n])] != FALSE));
671 MvPrintw(row, col, "%s", help[n]);
682 wgetch_wrap(WINDOW *win, int first_y)
684 int last_y = getmaxy(win) - 1;
685 int y = getcury(win) + 1;
693 #if defined(KEY_RESIZE) && HAVE_WRESIZE
699 static WINSTACK *winstack = 0;
700 static unsigned len_winstack = 0;
713 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
715 unsigned need = (level + 1) * 2;
717 assert(level < (unsigned) COLS);
721 winstack = typeMalloc(WINSTACK, len_winstack);
722 } else if (need >= len_winstack) {
724 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
726 winstack[level].text = txt_win;
727 winstack[level].frame = box_win;
730 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
734 /* this chunk is now done in resize_term() */
741 #define slk_repaint() /* nothing */
744 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
746 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
747 * Resize both and paint the box in the parent.
750 resize_boxes(unsigned level, WINDOW *win)
754 int high = LINES - base;
758 wnoutrefresh(stdscr);
762 for (n = 0; n < level; ++n) {
763 wresize(winstack[n].frame, high, wide);
764 wresize(winstack[n].text, high - 2, wide - 2);
767 werase(winstack[n].text);
768 box(winstack[n].frame, 0, 0);
769 wnoutrefresh(winstack[n].frame);
770 wprintw(winstack[n].text,
772 getmaxy(winstack[n].text),
773 getmaxx(winstack[n].text));
774 wnoutrefresh(winstack[n].text);
775 if (winstack[n].text == win)
780 #endif /* resize_boxes */
782 #define forget_boxes() /* nothing */
783 #define remember_boxes(level,text,frame) /* nothing */
787 * Return-code is OK/ERR or a keyname.
792 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
796 wgetch_test(unsigned level, WINDOW *win, int delay)
799 int first_y, first_x;
803 bool blocking = (delay < 0);
805 init_getch(win, flags);
806 wtimeout(win, delay);
807 getyx(win, first_y, first_x);
809 wgetch_help(win, flags);
810 wsetscrreg(win, first_y, getmaxy(win) - 1);
814 while ((c = wGetchar(win)) == ERR) {
817 (void) wprintw(win, "%05d: input error", incount);
820 (void) wprintw(win, "%05d: input timed out", incount);
822 wgetch_wrap(win, first_y);
824 if (c == ERR && blocking) {
826 wgetch_wrap(win, first_y);
827 } else if (isQuit(c)) {
829 } else if (c == 'e') {
830 flags[UChar('e')] = !flags[UChar('e')];
831 setup_getch(win, flags);
832 wgetch_help(win, flags);
833 } else if (c == 'g') {
834 waddstr(win, "getstr test: ");
836 c = wgetnstr(win, buf, sizeof(buf) - 1);
838 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
839 (int) strlen(buf), buf,
842 wgetch_wrap(win, first_y);
843 } else if (c == 'k') {
844 flags[UChar('k')] = !flags[UChar('k')];
845 setup_getch(win, flags);
846 wgetch_help(win, flags);
847 } else if (c == 'm') {
848 flags[UChar('m')] = !flags[UChar('m')];
849 setup_getch(win, flags);
850 wgetch_help(win, flags);
851 } else if (c == 's') {
853 } else if (c == 'w') {
854 int high = getmaxy(win) - 1 - first_y + 1;
855 int wide = getmaxx(win) - first_x;
857 int new_y = first_y + getbegy(win);
858 int new_x = first_x + getbegx(win);
860 getyx(win, old_y, old_x);
861 if (high > 2 && wide > 2) {
862 WINDOW *wb = newwin(high, wide, new_y, new_x);
863 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
868 remember_boxes(level, wi, wb);
869 wgetch_test(level + 1, wi, delay);
873 wgetch_help(win, flags);
874 wmove(win, old_y, old_x);
880 } else if (c == 'z') {
881 kill(getpid(), SIGTSTP);
884 wprintw(win, "Key pressed: %04o ", c);
885 #ifdef NCURSES_MOUSE_VERSION
886 if (c == KEY_MOUSE) {
889 #endif /* NCURSES_MOUSE_VERSION */
891 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
892 if (c == KEY_RESIZE) {
893 resize_boxes(level, win);
896 (void) waddstr(win, keyname(c));
897 } else if (c >= 0x80) {
898 unsigned c2 = (unsigned) c;
899 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
900 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
904 (void) wprintw(win, "%c", UChar(c));
905 else if (c2 != UChar(c))
906 (void) wprintw(win, "M-%s", unctrl(c2));
908 (void) wprintw(win, "%s", unctrl(c2));
909 waddstr(win, " (high-half character)");
912 (void) wprintw(win, "%c (ASCII printable character)", c);
914 (void) wprintw(win, "%s (ASCII control character)",
917 wgetch_wrap(win, first_y);
924 init_getch(win, flags);
928 begin_getch_test(void)
935 #ifdef NCURSES_MOUSE_VERSION
936 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
939 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
941 getnstr(buf, sizeof(buf) - 1);
945 if (isdigit(UChar(buf[0]))) {
946 delay = atoi(buf) * 100;
956 finish_getch_test(void)
958 #ifdef NCURSES_MOUSE_VERSION
959 mousemask(0, (mmask_t *) 0);
970 int delay = begin_getch_test();
973 wgetch_test(0, stdscr, delay);
979 #if USE_WIDEC_SUPPORT
981 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
982 * Resize both and paint the box in the parent.
984 #if defined(KEY_RESIZE) && HAVE_WRESIZE
986 resize_wide_boxes(unsigned level, WINDOW *win)
990 int high = LINES - base;
994 wnoutrefresh(stdscr);
998 for (n = 0; n < level; ++n) {
999 wresize(winstack[n].frame, high, wide);
1000 wresize(winstack[n].text, high - 2, wide - 2);
1003 werase(winstack[n].text);
1004 box_set(winstack[n].frame, 0, 0);
1005 wnoutrefresh(winstack[n].frame);
1006 wprintw(winstack[n].text,
1008 getmaxy(winstack[n].text),
1009 getmaxx(winstack[n].text));
1010 wnoutrefresh(winstack[n].text);
1011 if (winstack[n].text == win)
1016 #endif /* KEY_RESIZE */
1019 wcstos(const wchar_t *src)
1023 const wchar_t *tmp = src;
1024 #ifndef state_unused
1028 reset_wchars(state);
1029 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1030 unsigned have = (unsigned) need;
1031 if ((result = typeCalloc(char, have + 1)) != 0) {
1033 if (trans_wchars(result, tmp, have, &state) != have) {
1043 wget_wch_test(unsigned level, WINDOW *win, int delay)
1045 wchar_t wchar_buf[BUFSIZ];
1046 wint_t wint_buf[BUFSIZ];
1047 int first_y, first_x;
1051 bool blocking = (delay < 0);
1055 init_getch(win, flags);
1056 wtimeout(win, delay);
1057 getyx(win, first_y, first_x);
1059 wgetch_help(win, flags);
1060 wsetscrreg(win, first_y, getmaxy(win) - 1);
1061 scrollok(win, TRUE);
1064 while ((code = wGet_wchar(win, &c)) == ERR) {
1067 (void) wprintw(win, "%05d: input error", incount);
1070 (void) wprintw(win, "%05d: input timed out", incount);
1072 wgetch_wrap(win, first_y);
1074 if (code == ERR && blocking) {
1075 wprintw(win, "ERR");
1076 wgetch_wrap(win, first_y);
1077 } else if (isQuit((int) c)) {
1079 } else if (c == 'e') {
1080 flags[UChar('e')] = !flags[UChar('e')];
1081 setup_getch(win, flags);
1082 wgetch_help(win, flags);
1083 } else if (c == 'g') {
1084 waddstr(win, "getstr test: ");
1086 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1089 wprintw(win, "wgetn_wstr returns an error.");
1092 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1095 if ((temp = wcstos(wchar_buf)) != 0) {
1096 wprintw(win, "I saw %d characters:\n\t`%s'.",
1097 (int) wcslen(wchar_buf), temp);
1100 wprintw(win, "I saw %d characters (cannot convert).",
1101 (int) wcslen(wchar_buf));
1105 wgetch_wrap(win, first_y);
1106 } else if (c == 'k') {
1107 flags[UChar('k')] = !flags[UChar('k')];
1108 setup_getch(win, flags);
1109 wgetch_help(win, flags);
1110 } else if (c == 'm') {
1111 flags[UChar('m')] = !flags[UChar('m')];
1112 setup_getch(win, flags);
1113 wgetch_help(win, flags);
1114 } else if (c == 's') {
1116 } else if (c == 'w') {
1117 int high = getmaxy(win) - 1 - first_y + 1;
1118 int wide = getmaxx(win) - first_x;
1120 int new_y = first_y + getbegy(win);
1121 int new_x = first_x + getbegx(win);
1123 getyx(win, old_y, old_x);
1124 if (high > 2 && wide > 2) {
1125 WINDOW *wb = newwin(high, wide, new_y, new_x);
1126 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1131 remember_boxes(level, wi, wb);
1132 wget_wch_test(level + 1, wi, delay);
1136 wgetch_help(win, flags);
1137 wmove(win, old_y, old_x);
1142 } else if (c == 'z') {
1143 kill(getpid(), SIGTSTP);
1146 wprintw(win, "Key pressed: %04o ", (int) c);
1147 #ifdef NCURSES_MOUSE_VERSION
1148 if (c == KEY_MOUSE) {
1151 #endif /* NCURSES_MOUSE_VERSION */
1152 if (code == KEY_CODE_YES) {
1153 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1154 if (c == KEY_RESIZE) {
1155 resize_wide_boxes(level, win);
1158 (void) waddstr(win, keyname((wchar_t) c));
1160 (void) waddstr(win, key_name((wchar_t) c));
1161 if (c < 256 && iscntrl(c)) {
1162 (void) wprintw(win, " (control character)");
1164 (void) wprintw(win, " = %#x (printable character)",
1168 wgetch_wrap(win, first_y);
1175 init_getch(win, flags);
1181 int delay = begin_getch_test();
1184 wget_wch_test(0, stdscr, delay);
1186 finish_getch_test();
1191 /****************************************************************************
1193 * Character attributes test
1195 ****************************************************************************/
1197 #if HAVE_SETUPTERM || HAVE_TGETENT
1198 #define get_ncv() TIGETNUM("ncv","NC")
1199 #define get_xmc() TIGETNUM("xmc","sg")
1201 #define get_ncv() -1
1202 #define get_xmc() -1
1209 static int first = TRUE;
1210 static chtype result = 0;
1216 char *area_pointer = parsed;
1218 tgetent(buffer, getenv("TERM"));
1221 if (TIGETSTR("smso", "so"))
1222 result |= A_STANDOUT;
1223 if (TIGETSTR("smul", "us"))
1224 result |= A_UNDERLINE;
1225 if (TIGETSTR("rev", "mr"))
1226 result |= A_REVERSE;
1227 if (TIGETSTR("blink", "mb"))
1229 if (TIGETSTR("dim", "mh"))
1231 if (TIGETSTR("bold", "md"))
1233 if (TIGETSTR("smacs", "ac"))
1234 result |= A_ALTCHARSET;
1240 #define termattrs() my_termattrs()
1243 #define MAX_ATTRSTRING 31
1244 #define LEN_ATTRSTRING 26
1246 static char attr_test_string[MAX_ATTRSTRING + 1];
1249 attr_legend(WINDOW *helpwin)
1254 MvWPrintw(helpwin, row++, col,
1256 MvWPrintw(helpwin, row++, col,
1259 MvWPrintw(helpwin, row++, col,
1260 "Modify the test strings:");
1261 MvWPrintw(helpwin, row++, col,
1262 " A digit sets gaps on each side of displayed attributes");
1263 MvWPrintw(helpwin, row++, col,
1264 " </> shifts the text left/right. ");
1266 MvWPrintw(helpwin, row++, col,
1269 MvWPrintw(helpwin, row++, col,
1270 " f/F/b/F toggle foreground/background background color");
1271 MvWPrintw(helpwin, row++, col,
1272 " t/T toggle text/background color attribute");
1274 MvWPrintw(helpwin, row++, col,
1275 " a/A toggle ACS (alternate character set) mapping");
1276 MvWPrintw(helpwin, row, col,
1277 " v/V toggle video attribute to combine with each line");
1281 show_color_attr(int fg, int bg, int tx)
1284 printw(" Colors (fg %d, bg %d", fg, bg);
1286 printw(", text %d", tx);
1292 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1299 *fg = (short) (*fg + 1);
1302 *fg = (short) (*fg - 1);
1305 *bg = (short) (*bg + 1);
1308 *bg = (short) (*bg - 1);
1311 *tx = (short) (*tx + 1);
1314 *tx = (short) (*tx - 1);
1322 *fg = (short) min_colors;
1323 if (*fg < min_colors)
1324 *fg = (short) (COLORS - 1);
1326 *bg = (short) min_colors;
1327 if (*bg < min_colors)
1328 *bg = (short) (COLORS - 1);
1332 *tx = (short) (COLORS - 1);
1341 adjust_attr_string(int adjust)
1343 int first = ((int) UChar(attr_test_string[0])) + adjust;
1344 int last = first + LEN_ATTRSTRING;
1346 if (first >= ' ' && last <= '~') { /* 32..126 */
1348 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1349 attr_test_string[j] = (char) k;
1350 if (((k + 1 - first) % 5) == 0) {
1351 if (++j >= MAX_ATTRSTRING)
1353 attr_test_string[j] = ' ';
1356 while (j < MAX_ATTRSTRING)
1357 attr_test_string[j++] = ' ';
1358 attr_test_string[j] = '\0';
1365 init_attr_string(void)
1367 attr_test_string[0] = 'a';
1368 adjust_attr_string(0);
1372 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1374 int ncv = get_ncv();
1375 chtype test = attr & (chtype) (~A_ALTCHARSET);
1378 MvPrintw(row, 5, "-->");
1379 MvPrintw(row, 8, "%s mode:", name);
1380 MvPrintw(row, 24, "|");
1382 printw("%*s", skip, " ");
1384 * Just for testing, write text using the alternate character set one
1385 * character at a time (to pass its rendition directly), and use the
1386 * string operation for the other attributes.
1388 if (attr & A_ALTCHARSET) {
1392 for (s = attr_test_string; *s != '\0'; ++s) {
1397 (void) attrset(attr);
1398 addstr(attr_test_string);
1402 printw("%*s", skip, " ");
1404 if (test != A_NORMAL) {
1405 if (!(termattrs() & test)) {
1408 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1409 static const chtype table[] =
1425 for (n = 0; n < SIZEOF(table); n++) {
1426 if ((table[n] & attr) != 0
1427 && ((1 << n) & ncv) != 0) {
1435 if ((termattrs() & test) != test)
1442 static const struct {
1444 NCURSES_CONST char * name;
1445 } attrs_to_test[] = {
1446 { A_STANDOUT, "STANDOUT" },
1447 { A_REVERSE, "REVERSE" },
1449 { A_UNDERLINE, "UNDERLINE" },
1451 { A_BLINK, "BLINK" },
1452 { A_PROTECT, "PROTECT" },
1454 { A_INVIS, "INVISIBLE" },
1456 { A_NORMAL, "NORMAL" },
1461 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1471 if (ch < 256 && isdigit(ch)) {
1479 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1481 attr_legend(helpwin);
1494 *kc = SIZEOF(attrs_to_test) - 1;
1500 if (*kc >= SIZEOF(attrs_to_test))
1504 adjust_attr_string(-1);
1507 adjust_attr_string(1);
1513 error = cycle_color_attr(ch, fg, bg, tx);
1523 /* test text attributes */
1526 int skip = get_xmc();
1527 short fg = COLOR_BLACK; /* color pair 0 is special */
1528 short bg = COLOR_BLACK;
1536 n = skip; /* make it easy */
1537 k = SIZEOF(attrs_to_test) - 1;
1542 chtype normal = A_NORMAL | BLANK;
1543 chtype extras = (chtype) ac;
1546 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1549 if (init_pair(pair, fg, bg) == ERR) {
1552 normal |= (chtype) COLOR_PAIR(pair);
1557 if (init_pair(pair, tx, bg) == ERR) {
1560 extras |= (chtype) COLOR_PAIR(pair);
1569 MvAddStr(0, 20, "Character attribute test display");
1571 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1572 bool arrow = (j == k);
1573 row = show_attr(row, n, arrow,
1575 attrs_to_test[j].attr |
1576 attrs_to_test[k].attr,
1577 attrs_to_test[j].name);
1581 "This terminal does %shave the magic-cookie glitch",
1582 get_xmc() > -1 ? "" : "not ");
1583 MvPrintw(row + 1, 8, "Enter '?' for help.");
1584 show_color_attr(fg, bg, tx);
1585 printw(" ACS (%d)", ac != 0);
1588 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1590 bkgdset(A_NORMAL | BLANK);
1595 #if USE_WIDEC_SUPPORT
1596 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1599 wide_adjust_attr_string(int adjust)
1601 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1602 int last = first + LEN_ATTRSTRING;
1604 if (first >= ' ' && last <= '~') { /* 32..126 */
1606 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1607 wide_attr_test_string[j] = k;
1608 if (((k + 1 - first) % 5) == 0) {
1609 if (++j >= MAX_ATTRSTRING)
1611 wide_attr_test_string[j] = ' ';
1614 while (j < MAX_ATTRSTRING)
1615 wide_attr_test_string[j++] = ' ';
1616 wide_attr_test_string[j] = '\0';
1623 wide_init_attr_string(void)
1625 wide_attr_test_string[0] = 'a';
1626 wide_adjust_attr_string(0);
1630 set_wide_background(short pair)
1637 setcchar(&normal, blank, A_NORMAL, pair, 0);
1643 get_wide_background(void)
1645 attr_t result = A_NORMAL;
1651 if (getbkgrnd(&ch) != ERR) {
1652 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1660 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1662 int ncv = get_ncv();
1663 chtype test = attr & ~WA_ALTCHARSET;
1666 MvPrintw(row, 5, "-->");
1667 MvPrintw(row, 8, "%s mode:", name);
1668 MvPrintw(row, 24, "|");
1670 printw("%*s", skip, " ");
1673 * Just for testing, write text using the alternate character set one
1674 * character at a time (to pass its rendition directly), and use the
1675 * string operation for the other attributes.
1677 if (attr & WA_ALTCHARSET) {
1681 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1685 setcchar(&ch, fill, attr, pair, 0);
1689 attr_t old_attr = 0;
1692 (void) attr_get(&old_attr, &old_pair, 0);
1693 (void) attr_set(attr, pair, 0);
1694 addwstr(wide_attr_test_string);
1695 (void) attr_set(old_attr, old_pair, 0);
1698 printw("%*s", skip, " ");
1700 if (test != A_NORMAL) {
1701 if (!(term_attrs() & test)) {
1704 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1705 static const attr_t table[] =
1719 for (n = 0; n < SIZEOF(table); n++) {
1720 if ((table[n] & attr) != 0
1721 && ((1 << n) & ncv) != 0) {
1729 if ((term_attrs() & test) != test)
1737 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1747 if (ch < 256 && isdigit(ch)) {
1755 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1756 box_set(helpwin, 0, 0);
1757 attr_legend(helpwin);
1770 *kc = SIZEOF(attrs_to_test) - 1;
1776 if (*kc >= SIZEOF(attrs_to_test))
1780 wide_adjust_attr_string(-1);
1783 wide_adjust_attr_string(1);
1789 error = cycle_color_attr(ch, fg, bg, tx);
1798 wide_attr_test(void)
1799 /* test text attributes using wide-character calls */
1802 int skip = get_xmc();
1803 short fg = COLOR_BLACK; /* color pair 0 is special */
1804 short bg = COLOR_BLACK;
1812 n = skip; /* make it easy */
1813 k = SIZEOF(attrs_to_test) - 1;
1814 wide_init_attr_string();
1822 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1825 if (init_pair(pair, fg, bg) == ERR) {
1832 if (init_pair(extras, tx, bg) == ERR) {
1837 set_wide_background(pair);
1840 box_set(stdscr, 0, 0);
1841 MvAddStr(0, 20, "Character attribute test display");
1843 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1844 row = wide_show_attr(row, n, j == k,
1846 attrs_to_test[j].attr |
1847 attrs_to_test[k].attr),
1849 attrs_to_test[j].name);
1853 "This terminal does %shave the magic-cookie glitch",
1854 get_xmc() > -1 ? "" : "not ");
1855 MvPrintw(row + 1, 8, "Enter '?' for help.");
1856 show_color_attr(fg, bg, tx);
1857 printw(" ACS (%d)", ac != 0);
1860 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1862 set_wide_background(0);
1868 /****************************************************************************
1870 * Color support tests
1872 ****************************************************************************/
1874 static NCURSES_CONST char *the_color_names[] =
1895 show_color_name(int y, int x, int color, bool wide)
1897 if (move(y, x) != ERR) {
1902 sprintf(temp, "%02d", color);
1904 } else if (color >= 8) {
1905 sprintf(temp, "[%02d]", color);
1906 } else if (color < 0) {
1907 strcpy(temp, "default");
1909 strcpy(temp, the_color_names[color]);
1911 printw("%-*.*s", width, width, temp);
1916 color_legend(WINDOW *helpwin, bool wide)
1921 MvWPrintw(helpwin, row++, col,
1924 MvWPrintw(helpwin, row++, col,
1925 "Use up/down arrow to scroll through the display if it is");
1926 MvWPrintw(helpwin, row++, col,
1927 "longer than one screen. Control/N and Control/P can be used");
1928 MvWPrintw(helpwin, row++, col,
1929 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1930 MvWPrintw(helpwin, row++, col,
1931 "full screen; control/B and control/F can be used here.");
1933 MvWPrintw(helpwin, row++, col,
1935 MvWPrintw(helpwin, row++, col,
1936 " a/A toggle altcharset off/on");
1937 MvWPrintw(helpwin, row++, col,
1938 " b/B toggle bold off/on");
1939 MvWPrintw(helpwin, row++, col,
1940 " n/N toggle text/number on/off");
1941 MvWPrintw(helpwin, row++, col,
1942 " r/R toggle reverse on/off");
1943 MvWPrintw(helpwin, row++, col,
1944 " w/W toggle width between 8/16 colors");
1945 #if USE_WIDEC_SUPPORT
1947 MvWPrintw(helpwin, row++, col,
1948 "Wide characters:");
1949 MvWPrintw(helpwin, row, col,
1950 " x/X toggle text between ASCII and wide-character");
1957 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1959 /* generate a color test pattern */
1966 int grid_top = top + 3;
1967 int page_size = (LINES - grid_top);
1968 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1974 bool opt_acsc = FALSE;
1975 bool opt_bold = FALSE;
1976 bool opt_revs = FALSE;
1977 bool opt_nums = FALSE;
1978 bool opt_wide = FALSE;
1981 if (COLORS * COLORS == COLOR_PAIRS) {
1982 int limit = (COLORS - min_colors) * (COLORS - min_colors);
1983 if (pairs_max > limit)
1986 if (pairs_max > COLOR_PAIRS)
1987 pairs_max = COLOR_PAIRS;
1993 /* this assumes an 80-column line */
1997 per_row = (COLORS > 8) ? 16 : 8;
2003 per_row -= min_colors;
2005 row_limit = (pairs_max + per_row - 1) / per_row;
2008 (void) printw("There are %d color pairs and %d colors%s\n",
2010 min_colors ? " besides 'default'" : "");
2013 MvPrintw(top + 1, 0,
2014 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2017 opt_bold ? "on" : "off");
2019 /* show color names/numbers across the top */
2020 for (i = 0; i < per_row; i++)
2021 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2023 /* show a grid of colors, with color names/ numbers on the left */
2024 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
2025 int row = grid_top + (i / per_row) - base_row;
2026 int col = (i % per_row + 1) * width;
2029 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
2030 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
2031 if (row >= 0 && move(row, col) != ERR) {
2032 short fg = InxToFG(i);
2033 short bg = InxToBG(i);
2035 init_pair(pair, fg, bg);
2036 attron((attr_t) COLOR_PAIR(pair));
2038 attron((attr_t) A_ALTCHARSET);
2040 attron((attr_t) A_BOLD);
2042 attron((attr_t) A_REVERSE);
2045 sprintf(numbered, "{%02X}", i);
2048 printw("%-*.*s", width, width, hello);
2049 (void) attrset(A_NORMAL);
2051 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2052 show_color_name(row, 0, InxToBG(i), opt_wide);
2060 switch (wGetchar(stdscr)) {
2089 set_color_test(opt_wide, FALSE);
2092 set_color_test(opt_wide, TRUE);
2096 if (base_row <= 0) {
2104 if (base_row + page_size >= row_limit) {
2113 if (base_row <= 0) {
2116 base_row -= (page_size - 1);
2124 if (base_row + page_size >= row_limit) {
2127 base_row += page_size - 1;
2128 if (base_row + page_size >= row_limit) {
2129 base_row = row_limit - page_size - 1;
2134 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2136 color_legend(helpwin, FALSE);
2151 #if USE_WIDEC_SUPPORT
2152 /* generate a color test pattern */
2154 wide_color_test(void)
2159 int grid_top = top + 3;
2160 int page_size = (LINES - grid_top);
2161 int pairs_max = (unsigned short) (-1);
2167 bool opt_acsc = FALSE;
2168 bool opt_bold = FALSE;
2169 bool opt_revs = FALSE;
2170 bool opt_wide = FALSE;
2171 bool opt_nums = FALSE;
2172 bool opt_xchr = FALSE;
2176 if (COLORS * COLORS == COLOR_PAIRS) {
2177 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2178 if (pairs_max > limit)
2181 if (pairs_max > COLOR_PAIRS)
2182 pairs_max = COLOR_PAIRS;
2188 /* this assumes an 80-column line */
2192 per_row = (COLORS > 8) ? 16 : 8;
2198 per_row -= min_colors;
2201 make_fullwidth_text(buffer, hello);
2205 make_narrow_text(buffer, hello);
2208 row_limit = (pairs_max + per_row - 1) / per_row;
2211 (void) printw("There are %d color pairs and %d colors%s\n",
2213 min_colors ? " besides 'default'" : "");
2216 MvPrintw(top + 1, 0,
2217 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2220 opt_bold ? "on" : "off");
2222 /* show color names/numbers across the top */
2223 for (i = 0; i < per_row; i++)
2224 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2226 /* show a grid of colors, with color names/ numbers on the left */
2227 for (i = (base_row * per_row); i < pairs_max; i++) {
2228 int row = grid_top + (i / per_row) - base_row;
2229 int col = (i % per_row + 1) * width;
2230 short pair = (short) i;
2232 if (row >= 0 && move(row, col) != ERR) {
2233 init_pair(pair, InxToFG(i), InxToBG(i));
2234 color_set(pair, NULL);
2236 attr_on((attr_t) A_ALTCHARSET, NULL);
2238 attr_on((attr_t) A_BOLD, NULL);
2240 attr_on((attr_t) A_REVERSE, NULL);
2243 sprintf(numbered, "{%02X}", i);
2245 make_fullwidth_text(buffer, numbered);
2247 make_narrow_text(buffer, numbered);
2250 addnwstr(buffer, width);
2251 (void) attr_set(A_NORMAL, 0, NULL);
2253 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2254 show_color_name(row, 0, InxToBG(i), opt_wide);
2262 switch (wGetchar(stdscr)) {
2291 set_color_test(opt_wide, FALSE);
2294 set_color_test(opt_wide, TRUE);
2304 if (base_row <= 0) {
2312 if (base_row + page_size >= row_limit) {
2321 if (base_row <= 0) {
2324 base_row -= (page_size - 1);
2332 if (base_row + page_size >= row_limit) {
2335 base_row += page_size - 1;
2336 if (base_row + page_size >= row_limit) {
2337 base_row = row_limit - page_size - 1;
2342 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2344 color_legend(helpwin, TRUE);
2358 #endif /* USE_WIDEC_SUPPORT */
2361 change_color(short current, int field, int value, int usebase)
2363 short red, green, blue;
2365 color_content(current, &red, &green, &blue);
2369 red = (short) (usebase ? (red + value) : value);
2372 green = (short) (usebase ? (green + value) : value);
2375 blue = (short) (usebase ? (blue + value) : value);
2379 if (init_color(current, red, green, blue) == ERR)
2384 init_all_colors(void)
2388 for (c = 0; c < COLORS; ++c)
2391 all_colors[c].green,
2392 all_colors[c].blue);
2395 #define scaled_rgb(n) ((255 * (n)) / 1000)
2399 /* display the color test pattern, without trying to edit colors */
2403 int this_c = 0, value = 0, field = 0;
2406 int page_size = (LINES - 6);
2411 for (i = 0; i < max_colors; i++)
2412 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2414 MvPrintw(LINES - 2, 0, "Number: %d", value);
2417 short red, green, blue;
2420 MvAddStr(0, 20, "Color RGB Value Editing");
2423 for (i = (short) top_color;
2424 (i - top_color < page_size)
2425 && (i < max_colors); i++) {
2428 sprintf(numeric, "[%d]", i);
2429 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2430 (i == current ? '>' : ' '),
2431 (i < (int) SIZEOF(the_color_names)
2432 ? the_color_names[i] : numeric));
2433 (void) attrset((attr_t) COLOR_PAIR(i));
2435 (void) attrset(A_NORMAL);
2437 color_content((short) i, &red, &green, &blue);
2439 if (current == i && field == 0)
2441 printw("%04d", red);
2442 if (current == i && field == 0)
2443 (void) attrset(A_NORMAL);
2445 if (current == i && field == 1)
2447 printw("%04d", green);
2448 if (current == i && field == 1)
2449 (void) attrset(A_NORMAL);
2451 if (current == i && field == 2)
2453 printw("%04d", blue);
2454 if (current == i && field == 2)
2455 (void) attrset(A_NORMAL);
2456 (void) attrset(A_NORMAL);
2457 printw(" ( %3d %3d %3d )",
2463 MvAddStr(LINES - 3, 0,
2464 "Use up/down to select a color, left/right to change fields.");
2465 MvAddStr(LINES - 2, 0,
2466 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2468 move(2 + current - top_color, 0);
2472 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2479 current -= (page_size - 1);
2486 if (current < (max_colors - 1))
2487 current += (page_size - 1);
2494 current = (current == 0 ? (max_colors - 1) : current - 1);
2499 current = (current == (max_colors - 1) ? 0 : current + 1);
2503 field = (field == 2 ? 0 : field + 1);
2507 field = (field == 0 ? 2 : field - 1);
2520 value = value * 10 + (this_c - '0');
2524 change_color((short) current, field, value, 1);
2528 change_color((short) current, field, -value, 1);
2532 change_color((short) current, field, value, 0);
2537 P(" RGB Value Editing Help");
2539 P("You are in the RGB value editor. Use the arrow keys to select one of");
2540 P("the fields in one of the RGB triples of the current colors; the one");
2541 P("currently selected will be reverse-video highlighted.");
2543 P("To change a field, enter the digits of the new value; they are echoed");
2544 P("as entered. Finish by typing `='. The change will take effect instantly.");
2545 P("To increment or decrement a value, use the same procedure, but finish");
2546 P("with a `+' or `-'.");
2548 P("Press 'm' to invoke the top-level menu with the current color settings.");
2549 P("To quit, do ESC");
2558 for (i = 0; i < max_colors; i++)
2559 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2573 if (current >= max_colors)
2574 current = max_colors - 1;
2575 if (current < top_color)
2576 top_color = current;
2577 if (current - top_color >= page_size)
2578 top_color = current - (page_size - 1);
2580 MvPrintw(LINES - 1, 0, "Number: %d", value);
2588 * ncurses does not reset each color individually when calling endwin().
2595 /****************************************************************************
2597 * Alternate character-set stuff
2599 ****************************************************************************/
2604 } attrs_to_cycle[] = {
2605 { A_NORMAL, "normal" },
2607 { A_BLINK, "blink" },
2608 { A_REVERSE, "reverse" },
2609 { A_UNDERLINE, "underline" },
2614 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2620 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2625 *at_code = SIZEOF(attrs_to_cycle) - 1;
2634 *attr = attrs_to_cycle[*at_code].attr;
2639 cycle_colors(int ch, int *fg, int *bg, short *pair)
2641 bool result = FALSE;
2651 if ((*fg += 1) >= COLORS)
2659 if ((*bg += 1) >= COLORS)
2667 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2670 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2679 /****************************************************************************
2681 * Soft-key label test
2683 ****************************************************************************/
2688 #define SLK_WORK (SLK_HELP + 3)
2693 static const char *table[] =
2695 "Available commands are:"
2697 ,"^L -- repaint this message and activate soft keys"
2698 ,"a/d -- activate/disable soft keys"
2699 ,"c -- set centered format for labels"
2700 ,"l -- set left-justified format for labels"
2701 ,"r -- set right-justified format for labels"
2702 ,"[12345678] -- set label; labels are numbered 1 through 8"
2703 ,"e -- erase stdscr (should not erase labels)"
2704 ,"s -- test scrolling of shortened screen"
2705 ,"v/V -- cycle through video attributes"
2707 ,"F/f/B/b -- cycle through foreground/background colors"
2709 ,"ESC -- return to main menu"
2711 ,"Note: if activating the soft keys causes your terminal to scroll up"
2712 ,"one line, your terminal auto-scrolls when anything is written to the"
2713 ,"last screen position. The ncurses code does not yet handle this"
2719 for (j = 0; j < SIZEOF(table); ++j) {
2727 call_slk_color(int fg, int bg)
2729 init_pair(1, (short) bg, (short) fg);
2731 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2741 /* exercise the soft keys */
2746 chtype attr = A_NORMAL;
2747 unsigned at_code = 0;
2749 int fg = COLOR_BLACK;
2750 int bg = COLOR_WHITE;
2757 call_slk_color(fg, bg);
2767 MvAddStr(0, 20, "Soft Key Exerciser");
2782 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2783 while ((c = Getchar()) != 'Q' && (c != ERR))
2811 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2813 if ((s = slk_label(c - '0')) != 0) {
2816 wGetstring(stdscr, buf, 8);
2817 slk_set((c - '0'), buf, fmt);
2826 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2828 wnoutrefresh(stdscr);
2833 if (cycle_attr(c, &at_code, &attr)) {
2840 if (cycle_colors(c, &fg, &bg, &pair)) {
2842 call_slk_color(fg, bg);
2852 } while (!isQuit(c = Getchar()));
2860 #if USE_WIDEC_SUPPORT
2864 /* exercise the soft keys */
2867 wchar_t buf[SLKLEN + 1];
2869 chtype attr = A_NORMAL;
2870 unsigned at_code = 0;
2871 int fg = COLOR_BLACK;
2872 int bg = COLOR_WHITE;
2877 call_slk_color(fg, bg);
2884 attr_on(WA_BOLD, NULL);
2885 MvAddStr(0, 20, "Soft Key Exerciser");
2886 attr_off(WA_BOLD, NULL);
2900 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2901 while ((c = Getchar()) != 'Q' && (c != ERR))
2929 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2931 if ((s = slk_label(c - '0')) != 0) {
2932 char *temp = strdup(s);
2933 size_t used = strlen(temp);
2934 size_t want = SLKLEN;
2936 #ifndef state_unused
2941 while (want > 0 && used != 0) {
2942 const char *base = s;
2943 reset_mbytes(state);
2944 test = count_mbytes(base, 0, &state);
2945 if (test == (size_t) -1) {
2947 } else if (test > want) {
2950 reset_mbytes(state);
2951 trans_mbytes(buf, base, want, &state);
2957 wGet_wstring(stdscr, buf, SLKLEN);
2958 slk_wset((c - '0'), buf, fmt);
2969 fg = (short) ((fg + 1) % COLORS);
2970 call_slk_color(fg, bg);
2975 bg = (short) ((bg + 1) % COLORS);
2976 call_slk_color(fg, bg);
2979 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2981 wnoutrefresh(stdscr);
2985 if (cycle_attr(c, &at_code, &attr)) {
2986 slk_attr_set(attr, (short) (fg || bg), NULL);
2992 if (cycle_colors(c, &fg, &bg, &pair)) {
2994 call_slk_color(fg, bg);
3004 } while (!isQuit(c = Getchar()));
3012 #endif /* SLK_INIT */
3015 show_256_chars(int repeat, attr_t attr, short pair)
3018 unsigned last = 255;
3024 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3029 for (code = first; code <= last; ++code) {
3030 int row = (int) (2 + (code / 16));
3031 int col = (int) (5 * (code % 16));
3032 mvaddch(row, col, colored_chtype(code, attr, pair));
3033 for (count = 1; count < repeat; ++count) {
3034 addch(colored_chtype(code, attr, pair));
3041 * Show a slice of 32 characters, allowing those to be repeated up to the
3044 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3045 * terminal to perform functions. The remaining codes can be graphic.
3048 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, short pair)
3051 unsigned first = (unsigned) base;
3052 unsigned last = first + (unsigned) pagesize - 2;
3053 bool C1 = (first == 128);
3058 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3059 C1 ? "C1" : "GR", first, last);
3063 for (code = first; code <= last; code++) {
3065 int row = 2 + ((int) (code - first) % (pagesize / 2));
3066 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3068 sprintf(tmp, "%3u (0x%x)", code, code);
3069 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3073 nodelay(stdscr, TRUE);
3074 echochar(colored_chtype(code, attr, pair));
3076 /* (yes, this _is_ crude) */
3077 while ((reply = Getchar()) != ERR) {
3078 addch(UChar(reply));
3081 nodelay(stdscr, FALSE);
3083 } while (--count > 0);
3090 show_pc_chars(int repeat, attr_t attr, short pair)
3096 MvPrintw(0, 20, "Display of PC Character Codes");
3100 for (code = 0; code < 16; ++code) {
3101 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3103 for (code = 0; code < 256; code++) {
3105 int row = 3 + (int) (code / 16) + (code >= 128);
3106 int col = 8 + (int) (code % 16) * PC_COLS;
3107 if ((code % 16) == 0)
3108 MvPrintw(row, 0, "0x%02x:", code);
3119 * Skip the ones that do not work.
3123 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3126 } while (--count > 0);
3131 show_box_chars(int repeat, attr_t attr, short pair)
3135 attr |= (attr_t) COLOR_PAIR(pair);
3139 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3144 colored_chtype(ACS_VLINE, attr, pair),
3145 colored_chtype(ACS_VLINE, attr, pair),
3146 colored_chtype(ACS_HLINE, attr, pair),
3147 colored_chtype(ACS_HLINE, attr, pair),
3148 colored_chtype(ACS_ULCORNER, attr, pair),
3149 colored_chtype(ACS_URCORNER, attr, pair),
3150 colored_chtype(ACS_LLCORNER, attr, pair),
3151 colored_chtype(ACS_LRCORNER, attr, pair));
3152 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3153 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3154 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3155 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3156 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3157 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3158 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3164 show_1_acs(int n, int repeat, const char *name, chtype code)
3166 const int height = 16;
3167 int row = 2 + (n % height);
3168 int col = (n / height) * COLS / 2;
3170 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3173 } while (--repeat > 0);
3178 show_acs_chars(int repeat, attr_t attr, short pair)
3179 /* display the ACS character set */
3183 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3187 MvAddStr(0, 20, "Display of the ACS Character Set");
3191 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3192 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3193 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3194 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3196 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3197 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3198 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3199 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3201 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3202 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3205 * HPUX's ACS definitions are broken here. Just give up.
3207 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3208 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3209 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3210 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3211 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3213 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3214 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3215 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3216 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3217 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3218 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3219 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3220 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3221 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3223 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3224 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3225 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3227 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3228 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3229 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3230 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3231 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3232 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3241 char *term = getenv("TERM");
3242 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3245 chtype attr = A_NORMAL;
3248 int fg = COLOR_BLACK;
3249 int bg = COLOR_BLACK;
3250 unsigned at_code = 0;
3252 void (*last_show_acs) (int, attr_t, short) = 0;
3260 ToggleAcs(last_show_acs, show_acs_chars);
3264 ToggleAcs(last_show_acs, show_pc_chars);
3269 if (pagesize == 32) {
3276 ToggleAcs(last_show_acs, show_box_chars);
3302 if (repeat < (COLS / 4))
3310 if (cycle_attr(c, &at_code, &attr)
3311 || cycle_colors(c, &fg, &bg, &pair)) {
3318 if (pagesize != 32) {
3319 show_256_chars(repeat, attr, pair);
3320 } else if (last_show_acs != 0) {
3321 last_show_acs(repeat, attr, pair);
3323 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3326 MvPrintw(LINES - 3, 0,
3327 "Note: ANSI terminals may not display C1 characters.");
3328 MvPrintw(LINES - 2, 0,
3329 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3332 MvPrintw(LINES - 1, 0,
3333 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3334 attrs_to_cycle[at_code].name,
3337 MvPrintw(LINES - 1, 0,
3338 "v/V cycles through video attributes (%s).",
3339 attrs_to_cycle[at_code].name);
3342 } while (!isQuit(c = Getchar()));
3349 #if USE_WIDEC_SUPPORT
3351 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3357 TEST_CCHAR(src, count, {
3358 attr |= (test_attrs & A_ALTCHARSET);
3359 setcchar(dst, test_wch, attr, pair, NULL);
3369 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3370 * display. If there are no repeats, we could normally display 16 lines of 64
3371 * characters (1024 total). However, taking repeats and double-width cells
3372 * into account, use 256 characters for the page.
3375 show_paged_widechars(int base,
3382 int first = base * pagesize;
3383 int last = first + pagesize - 1;
3391 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3394 for (code = first; (int) code <= last; code++) {
3395 int row = (2 + ((int) code - first) / per_line);
3396 int col = 5 * ((int) code % per_line);
3399 memset(&codes, 0, sizeof(codes));
3401 setcchar(&temp, codes, attr, pair, 0);
3403 if (wcwidth(code) == 0 && code != 0) {
3404 addch((chtype) space |
3405 (A_REVERSE ^ attr) |
3406 (attr_t) COLOR_PAIR(pair));
3409 for (count = 1; count < repeat; ++count) {
3416 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3420 int last = first + 31;
3424 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3427 for (code = first; (int) code <= last; code++) {
3428 int row = 2 + ((code - first) % 16);
3429 int col = ((code - first) / 16) * COLS / 2;
3435 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3436 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3438 memset(&codes, 0, sizeof(codes));
3440 setcchar(&temp, codes, attr, pair, 0);
3444 * Give non-spacing characters something to combine with. If we
3445 * don't, they'll bunch up in a heap on the space after the ":".
3446 * Mark them with reverse-video to make them simpler to find on
3449 if (wcwidth(code) == 0) {
3450 addch((chtype) space |
3451 (A_REVERSE ^ attr) |
3452 (attr_t) COLOR_PAIR(pair));
3455 * This uses echo_wchar(), for comparison with the normal 'f'
3456 * test (and to make a test-case for echo_wchar()). The screen
3457 * may flicker because the erase() at the top of the function
3458 * is met by the builtin refresh() in echo_wchar().
3462 * The repeat-count may make text wrap - avoid that.
3464 getyx(stdscr, y, x);
3466 if (x >= col + (COLS / 2) - 2)
3468 } while (--count > 0);
3473 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3475 const int height = 16;
3476 int row = 2 + (n % height);
3477 int col = (n / height) * COLS / 2;
3479 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3480 while (--repeat >= 0) {
3486 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3489 show_wacs_chars(int repeat, attr_t attr, short pair)
3490 /* display the wide-ACS character set */
3496 /*#define BOTH2(name) #name, &(name) */
3497 #define BOTH2(name) #name, MERGE_ATTR(name)
3501 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3505 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3506 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3507 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3508 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3510 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3511 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3512 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3513 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3515 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3516 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3518 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3519 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3520 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3521 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3523 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3524 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3525 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3526 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3527 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3528 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3529 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3530 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3531 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3533 #ifdef CURSES_WACS_ARRAY
3534 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3535 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3536 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3538 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3539 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3540 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3541 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3542 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3543 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3549 show_wacs_chars_double(int repeat, attr_t attr, short pair)
3550 /* display the wide-ACS character set */
3556 /*#define BOTH2(name) #name, &(name) */
3557 #define BOTH2(name) #name, MERGE_ATTR(name)
3561 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3565 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3566 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3567 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3568 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3570 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3571 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3572 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3573 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3575 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3576 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3578 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3579 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3580 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3581 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3583 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3584 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3585 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3586 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3587 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3588 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3589 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3590 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3591 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3593 #ifdef CURSES_WACS_ARRAY
3594 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3595 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3596 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3598 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3599 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3600 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3601 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3602 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3603 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3610 show_wacs_chars_thick(int repeat, attr_t attr, short pair)
3611 /* display the wide-ACS character set */
3617 /*#define BOTH2(name) #name, &(name) */
3618 #define BOTH2(name) #name, MERGE_ATTR(name)
3622 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3626 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
3627 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
3628 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
3629 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
3631 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
3632 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
3633 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
3634 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
3636 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
3637 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
3639 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3640 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3641 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3642 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3644 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3645 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3646 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3647 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3648 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3649 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3650 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3651 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3652 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3654 #ifdef CURSES_WACS_ARRAY
3655 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3656 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3657 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3659 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3660 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3661 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3662 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3663 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3664 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3671 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3674 show_wbox_chars(int repeat, attr_t attr, short pair)
3681 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3686 MERGE_ATTR(0, WACS_VLINE),
3687 MERGE_ATTR(1, WACS_VLINE),
3688 MERGE_ATTR(2, WACS_HLINE),
3689 MERGE_ATTR(3, WACS_HLINE),
3690 MERGE_ATTR(4, WACS_ULCORNER),
3691 MERGE_ATTR(5, WACS_URCORNER),
3692 MERGE_ATTR(6, WACS_LLCORNER),
3693 MERGE_ATTR(7, WACS_LRCORNER));
3695 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3696 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3697 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3698 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3699 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3700 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3701 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3709 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3711 const int height = 16;
3712 int row = 2 + (n % height);
3713 int col = (n / height) * COLS / 2;
3716 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3717 (void) attr_set(attr, pair, 0);
3718 addstr(strcpy(temp, code));
3719 (void) attr_set(A_NORMAL, 0, 0);
3723 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3726 show_utf8_chars(int repeat, attr_t attr, short pair)
3733 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3737 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3738 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3739 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3740 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3742 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3743 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3744 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3745 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3747 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3748 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3750 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3751 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3752 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3753 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3755 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3756 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3757 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3758 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3759 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3760 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3761 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3762 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3763 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3764 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3765 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3766 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3768 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3769 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3770 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3771 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3772 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3773 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3778 /* display the wide-ACS character set */
3780 wide_acs_display(void)
3787 chtype attr = A_NORMAL;
3788 int fg = COLOR_BLACK;
3789 int bg = COLOR_BLACK;
3790 unsigned at_code = 0;
3792 void (*last_show_wacs) (int, attr_t, short) = 0;
3800 ToggleAcs(last_show_wacs, show_wacs_chars);
3804 ToggleAcs(last_show_wacs, show_wacs_chars_double);
3809 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
3813 if (pagesize == 32) {
3820 ToggleAcs(last_show_wacs, show_wbox_chars);
3823 ToggleAcs(last_show_wacs, show_utf8_chars);
3826 if (c < 256 && isdigit(c)) {
3829 } else if (c == '+') {
3832 } else if (c == '-' && digit > 0) {
3835 } else if (c == '>' && repeat < (COLS / 4)) {
3837 } else if (c == '<' && repeat > 1) {
3839 } else if (c == '_') {
3840 space = (space == ' ') ? '_' : ' ';
3842 } else if (cycle_attr(c, &at_code, &attr)
3843 || cycle_colors(c, &fg, &bg, &pair)) {
3844 if (last_show_wacs != 0)
3852 if (pagesize != 32) {
3853 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
3854 } else if (last_show_wacs != 0) {
3855 last_show_wacs(repeat, attr, pair);
3857 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3860 MvPrintw(LINES - 4, 0,
3861 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
3862 MvPrintw(LINES - 3, 2,
3863 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
3865 MvPrintw(LINES - 2, 2,
3866 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3867 attrs_to_cycle[at_code].name,
3870 MvPrintw(LINES - 2, 2,
3871 "v/V cycles through video attributes (%s).",
3872 attrs_to_cycle[at_code].name);
3875 } while (!isQuit(c = Getchar()));
3885 * Graphic-rendition test (adapted from vttest)
3888 test_sgr_attributes(void)
3892 for (pass = 0; pass < 2; pass++) {
3893 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3895 /* Use non-default colors if possible to exercise bce a little */
3897 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3898 normal |= COLOR_PAIR(1);
3902 MvPrintw(1, 20, "Graphic rendition test pattern:");
3904 MvPrintw(4, 1, "vanilla");
3906 #define set_sgr(mask) bkgdset((normal^(mask)));
3908 MvPrintw(4, 40, "bold");
3910 set_sgr(A_UNDERLINE);
3911 MvPrintw(6, 6, "underline");
3913 set_sgr(A_BOLD | A_UNDERLINE);
3914 MvPrintw(6, 45, "bold underline");
3917 MvPrintw(8, 1, "blink");
3919 set_sgr(A_BLINK | A_BOLD);
3920 MvPrintw(8, 40, "bold blink");
3922 set_sgr(A_UNDERLINE | A_BLINK);
3923 MvPrintw(10, 6, "underline blink");
3925 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3926 MvPrintw(10, 45, "bold underline blink");
3929 MvPrintw(12, 1, "negative");
3931 set_sgr(A_BOLD | A_REVERSE);
3932 MvPrintw(12, 40, "bold negative");
3934 set_sgr(A_UNDERLINE | A_REVERSE);
3935 MvPrintw(14, 6, "underline negative");
3937 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3938 MvPrintw(14, 45, "bold underline negative");
3940 set_sgr(A_BLINK | A_REVERSE);
3941 MvPrintw(16, 1, "blink negative");
3943 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3944 MvPrintw(16, 40, "bold blink negative");
3946 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3947 MvPrintw(18, 6, "underline blink negative");
3949 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3950 MvPrintw(18, 45, "bold underline blink negative");
3953 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3959 bkgdset(A_NORMAL | BLANK);
3964 /****************************************************************************
3966 * Windows and scrolling tester.
3968 ****************************************************************************/
3970 #define BOTLINES 4 /* number of line stolen from screen bottom */
3976 #define FRAME struct frame
3985 #if defined(NCURSES_VERSION)
3986 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3987 #define is_keypad(win) (win)->_use_keypad
3988 #define is_scrollok(win) (win)->_scroll
3989 #elif !defined(is_keypad)
3990 #define is_keypad(win) FALSE
3991 #define is_scrollok(win) FALSE
3994 #define is_keypad(win) FALSE
3995 #define is_scrollok(win) FALSE
3999 frame_win(FRAME * curp)
4001 return (curp != 0) ? curp->wind : stdscr;
4004 /* We need to know if these flags are actually set, so don't look in FRAME.
4005 * These names are known to work with SVr4 curses as well as ncurses. The
4006 * _use_keypad name does not work with Solaris 8.
4009 HaveKeypad(FRAME * curp)
4011 WINDOW *win = frame_win(curp);
4013 return is_keypad(win);
4017 HaveScroll(FRAME * curp)
4019 WINDOW *win = frame_win(curp);
4021 return is_scrollok(win);
4025 newwin_legend(FRAME * curp)
4027 static const struct {
4032 "^C = create window", 0
4035 "^N = next window", 0
4038 "^P = previous window", 0
4041 "^F = scroll forward", 0
4044 "^B = scroll backward", 0
4047 "^K = keypad(%s)", 1
4050 "^S = scrollok(%s)", 2
4053 "^W = save window to file", 0
4056 "^R = restore window", 0
4069 bool do_keypad = HaveKeypad(curp);
4070 bool do_scroll = HaveScroll(curp);
4074 for (n = 0; n < SIZEOF(legend); n++) {
4075 switch (legend[n].code) {
4077 strcpy(buf, legend[n].msg);
4080 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
4083 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
4086 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
4089 x = getcurx(stdscr);
4090 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4097 transient(FRAME * curp, NCURSES_CONST char *msg)
4099 newwin_legend(curp);
4101 MvAddStr(LINES - 1, 0, msg);
4107 printw("%s characters are echoed, window should %sscroll.",
4108 HaveKeypad(curp) ? "Non-arrow" : "All other",
4109 HaveScroll(curp) ? "" : "not ");
4114 newwin_report(FRAME * curp)
4115 /* report on the cursor's current position, then restore it */
4117 WINDOW *win = frame_win(curp);
4121 transient(curp, (char *) 0);
4123 move(LINES - 1, COLS - 17);
4124 printw("Y = %2d X = %2d", y, x);
4132 selectcell(int uli, int ulj, int lri, int lrj)
4133 /* arrows keys move cursor, return location at current on non-arrow key */
4135 static pair res; /* result cell */
4136 int si = lri - uli + 1; /* depth of the select area */
4137 int sj = lrj - ulj + 1; /* width of the select area */
4138 int i = 0, j = 0; /* offsets into the select area */
4143 move(uli + i, ulj + j);
4144 newwin_report((FRAME *) 0);
4146 switch (Getchar()) {
4160 return ((pair *) 0);
4161 #ifdef NCURSES_MOUSE_VERSION
4167 if (event.y > uli && event.x > ulj) {
4188 outerbox(pair ul, pair lr, bool onoff)
4189 /* draw or erase a box *outside* the given pair of corners */
4191 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4192 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4193 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4194 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4195 move(ul.y - 1, ul.x);
4196 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4197 move(ul.y, ul.x - 1);
4198 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4199 move(lr.y + 1, ul.x);
4200 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4201 move(ul.y, lr.x + 1);
4202 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4207 /* Ask user for a window definition */
4214 addstr("Use arrows to move cursor, anything else to mark corner 1");
4216 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4217 return ((WINDOW *) 0);
4218 memcpy(&ul, tmp, sizeof(pair));
4219 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4222 addstr("Use arrows to move cursor, anything else to mark corner 2");
4224 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4226 return ((WINDOW *) 0);
4227 memcpy(&lr, tmp, sizeof(pair));
4229 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4231 outerbox(ul, lr, TRUE);
4242 newwin_move(FRAME * curp, int dy, int dx)
4244 WINDOW *win = frame_win(curp);
4248 getyx(win, cur_y, cur_x);
4249 getmaxyx(win, max_y, max_x);
4250 if ((cur_x += dx) < 0)
4252 else if (cur_x >= max_x)
4254 if ((cur_y += dy) < 0)
4256 else if (cur_y >= max_y)
4258 wmove(win, cur_y, cur_x);
4262 delete_framed(FRAME * fp, bool showit)
4267 fp->last->next = fp->next;
4268 fp->next->last = fp->last;
4276 np = (fp == fp->next) ? 0 : fp->next;
4283 acs_and_scroll(void)
4284 /* Demonstrate windows */
4287 FRAME *current = (FRAME *) 0, *neww;
4289 #if HAVE_PUTWIN && HAVE_GETWIN
4293 #define DUMPFILE "screendump"
4295 #ifdef NCURSES_MOUSE_VERSION
4296 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4301 transient((FRAME *) 0, (char *) 0);
4304 if ((neww = typeCalloc(FRAME, 1)) == 0) {
4307 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4312 if (current == 0) { /* First element, */
4313 neww->next = neww; /* so point it at itself */
4316 neww->next = current->next;
4317 neww->last = current;
4318 neww->last->next = neww;
4319 neww->next->last = neww;
4322 /* SVr4 curses sets the keypad on all newly-created windows to
4323 * false. Someone reported that PDCurses makes new windows inherit
4324 * this flag. Remove the following 'keypad()' call to test this
4326 keypad(current->wind, TRUE);
4327 current->do_keypad = HaveKeypad(current);
4328 current->do_scroll = HaveScroll(current);
4331 case CTRL('N'): /* go to next window */
4333 current = current->next;
4336 case CTRL('P'): /* go to previous window */
4338 current = current->last;
4341 case CTRL('F'): /* scroll current window forward */
4343 wscrl(frame_win(current), 1);
4346 case CTRL('B'): /* scroll current window backwards */
4348 wscrl(frame_win(current), -1);
4351 case CTRL('K'): /* toggle keypad mode for current */
4353 current->do_keypad = !current->do_keypad;
4354 keypad(current->wind, current->do_keypad);
4360 current->do_scroll = !current->do_scroll;
4361 scrollok(current->wind, current->do_scroll);
4365 #if HAVE_PUTWIN && HAVE_GETWIN
4366 case CTRL('W'): /* save and delete window */
4367 if ((current != 0) && (current == current->next)) {
4368 transient(current, "Will not save/delete ONLY window");
4370 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4371 transient(current, "Can't open screen dump file");
4373 (void) putwin(frame_win(current), fp);
4376 current = delete_framed(current, TRUE);
4380 case CTRL('R'): /* restore window */
4381 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4382 transient(current, "Can't open screen dump file");
4384 if ((neww = typeCalloc(FRAME, 1)) != 0) {
4386 neww->next = current ? current->next : 0;
4387 neww->last = current;
4388 if (neww->last != 0)
4389 neww->last->next = neww;
4390 if (neww->next != 0)
4391 neww->next->last = neww;
4393 neww->wind = getwin(fp);
4395 wrefresh(neww->wind);
4403 case CTRL('X'): /* resize window */
4410 addstr("Use arrows to move cursor, anything else to mark new corner");
4413 getbegyx(current->wind, ul.y, ul.x);
4415 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4416 if (tmp == (pair *) 0) {
4421 getmaxyx(current->wind, lr.y, lr.x);
4424 outerbox(ul, lr, FALSE);
4425 wnoutrefresh(stdscr);
4427 /* strictly cosmetic hack for the test */
4428 getmaxyx(current->wind, my, mx);
4429 if (my > tmp->y - ul.y) {
4430 getyx(current->wind, lr.y, lr.x);
4431 wmove(current->wind, tmp->y - ul.y + 1, 0);
4432 wclrtobot(current->wind);
4433 wmove(current->wind, lr.y, lr.x);
4435 if (mx > tmp->x - ul.x)
4436 for (i = 0; i < my; i++) {
4437 wmove(current->wind, i, tmp->x - ul.x + 1);
4438 wclrtoeol(current->wind);
4440 wnoutrefresh(current->wind);
4442 memcpy(&lr, tmp, sizeof(pair));
4443 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4445 getbegyx(current->wind, ul.y, ul.x);
4446 getmaxyx(current->wind, lr.y, lr.x);
4449 outerbox(ul, lr, TRUE);
4450 wnoutrefresh(stdscr);
4452 wnoutrefresh(current->wind);
4458 #endif /* HAVE_WRESIZE */
4460 case KEY_F(10): /* undocumented --- use this to test area clears */
4461 selectcell(0, 0, LINES - 1, COLS - 1);
4467 newwin_move(current, -1, 0);
4470 newwin_move(current, 1, 0);
4473 newwin_move(current, 0, -1);
4476 newwin_move(current, 0, 1);
4484 getyx(frame_win(current), y, x);
4488 x = getmaxx(frame_win(current)) - 1;
4490 (void) mvwdelch(frame_win(current), y, x);
4500 waddch(current->wind, (chtype) c);
4505 newwin_report(current);
4506 usescr = frame_win(current);
4509 (!isQuit(c = wGetchar(usescr))
4513 while (current != 0)
4514 current = delete_framed(current, FALSE);
4516 scrollok(stdscr, TRUE); /* reset to driver's default */
4517 #ifdef NCURSES_MOUSE_VERSION
4518 mousemask(0, (mmask_t *) 0);
4525 /****************************************************************************
4529 ****************************************************************************/
4532 static int nap_msec = 1;
4534 static NCURSES_CONST char *mod[] =
4544 /*+-------------------------------------------------------------------------
4546 --------------------------------------------------------------------------*/
4548 wait_a_while(int msec GCC_UNUSED)
4558 else if (msec > 1000)
4559 sleep((unsigned) msec / 1000);
4563 } /* end of wait_a_while */
4565 /*+-------------------------------------------------------------------------
4567 --------------------------------------------------------------------------*/
4569 saywhat(NCURSES_CONST char *text)
4571 wmove(stdscr, LINES - 1, 0);
4573 if (text != 0 && *text != '\0') {
4574 waddstr(stdscr, text);
4575 waddstr(stdscr, "; ");
4577 waddstr(stdscr, "press any key to continue");
4578 } /* end of saywhat */
4580 /*+-------------------------------------------------------------------------
4581 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4582 --------------------------------------------------------------------------*/
4584 mkpanel(short color, int rows, int cols, int tly, int tlx)
4589 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4590 if ((pan = new_panel(win)) == 0) {
4592 } else if (use_colors) {
4593 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4596 init_pair(color, fg, bg);
4597 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
4599 wbkgdset(win, A_BOLD | ' ');
4603 } /* end of mkpanel */
4605 /*+-------------------------------------------------------------------------
4607 --------------------------------------------------------------------------*/
4609 rmpanel(PANEL * pan)
4611 WINDOW *win = panel_window(pan);
4614 } /* end of rmpanel */
4616 /*+-------------------------------------------------------------------------
4618 --------------------------------------------------------------------------*/
4624 } /* end of pflush */
4626 /*+-------------------------------------------------------------------------
4628 --------------------------------------------------------------------------*/
4634 for (y = 0; y < LINES - 1; y++) {
4635 for (x = 0; x < COLS; x++)
4636 wprintw(stdscr, "%d", (y + x) % 10);
4641 fill_panel(PANEL * pan)
4643 WINDOW *win = panel_window(pan);
4644 const char *userptr = (const char *) panel_userptr(pan);
4645 int num = (userptr && *userptr) ? userptr[1] : '?';
4649 wprintw(win, "-pan%c-", num);
4652 for (y = 2; y < getmaxy(win) - 1; y++) {
4653 for (x = 1; x < getmaxx(win) - 1; x++) {
4655 waddch(win, UChar(num));
4660 #if USE_WIDEC_SUPPORT
4662 init_wide_panel(void)
4667 for (digit = 0; digit < 10; ++digit)
4668 make_fullwidth_digit(&temp[digit], digit);
4672 getyx(stdscr, y, x);
4673 digit = (y + x / 2) % 10;
4674 } while (add_wch(&temp[digit]) != ERR);
4678 fill_wide_panel(PANEL * pan)
4680 WINDOW *win = panel_window(pan);
4681 const char *userptr = (const char *) panel_userptr(pan);
4682 int num = (userptr && *userptr) ? userptr[1] : '?';
4686 wprintw(win, "-pan%c-", num);
4689 for (y = 2; y < getmaxy(win) - 1; y++) {
4690 for (x = 1; x < getmaxx(win) - 1; x++) {
4692 waddch(win, UChar(num));
4698 #define MAX_PANELS 5
4701 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4703 int which = cmd[1] - '0';
4708 hide_panel(px[which]);
4711 show_panel(px[which]);
4714 top_panel(px[which]);
4717 bottom_panel(px[which]);
4724 wait_a_while(nap_msec);
4728 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4732 PANEL *px[MAX_PANELS + 1];
4734 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4738 for (count = 0; count < 5; count++) {
4739 px[1] = mkpanel(COLOR_RED,
4744 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4746 px[2] = mkpanel(COLOR_GREEN,
4751 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4753 px[3] = mkpanel(COLOR_YELLOW,
4758 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4760 px[4] = mkpanel(COLOR_BLUE,
4765 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4767 px[5] = mkpanel(COLOR_MAGENTA,
4772 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4784 wait_a_while(nap_msec);
4786 saywhat("h3 s1 s2 s4 s5");
4787 move_panel(px[1], 0, 0);
4794 wait_a_while(nap_msec);
4796 canned_panel(px, "s1");
4797 canned_panel(px, "s2");
4800 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4802 wait_a_while(nap_msec);
4804 canned_panel(px, "s3");
4807 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4809 wait_a_while(nap_msec);
4811 canned_panel(px, "b3");
4812 canned_panel(px, "s4");
4813 canned_panel(px, "s5");
4814 canned_panel(px, "t3");
4815 canned_panel(px, "t1");
4816 canned_panel(px, "t2");
4817 canned_panel(px, "t3");
4818 canned_panel(px, "t4");
4820 for (itmp = 0; itmp < 6; itmp++) {
4821 WINDOW *w4 = panel_window(px[4]);
4822 WINDOW *w5 = panel_window(px[5]);
4825 wmove(w4, LINES / 8, 1);
4826 waddstr(w4, mod[itmp]);
4827 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4828 wmove(w5, LINES / 6, 1);
4829 waddstr(w5, mod[itmp]);
4831 wait_a_while(nap_msec);
4834 wmove(w4, LINES / 6, 1);
4835 waddstr(w4, mod[itmp]);
4836 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4837 wmove(w5, LINES / 8, 1);
4838 waddstr(w5, mod[itmp]);
4840 wait_a_while(nap_msec);
4844 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4846 wait_a_while(nap_msec);
4848 canned_panel(px, "t5");
4849 canned_panel(px, "t2");
4850 canned_panel(px, "t1");
4851 canned_panel(px, "d2");
4852 canned_panel(px, "h3");
4853 canned_panel(px, "d1");
4854 canned_panel(px, "d4");
4855 canned_panel(px, "d5");
4856 canned_panel(px, "d3");
4858 wait_a_while(nap_msec);
4867 #endif /* USE_LIBPANEL */
4869 /****************************************************************************
4873 ****************************************************************************/
4877 static bool pending_pan = FALSE;
4878 static bool show_panner_legend = TRUE;
4881 panner_legend(int line)
4883 static const char *const legend[] =
4885 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4886 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4887 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4888 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4890 int n = ((int) SIZEOF(legend) - (LINES - line));
4892 if (move(line, 0) != ERR) {
4893 if (show_panner_legend)
4894 printw("%s", legend[n]);
4896 return show_panner_legend;
4903 panner_h_cleanup(int from_y, int from_x, int to_x)
4905 if (!panner_legend(from_y))
4906 do_h_line(from_y, from_x, ' ', to_x);
4910 panner_v_cleanup(int from_y, int from_x, int to_y)
4912 if (!panner_legend(from_y))
4913 do_v_line(from_y, from_x, ' ', to_y);
4917 fill_pad(WINDOW *panpad, bool pan_lines)
4920 unsigned gridcount = 0;
4922 wmove(panpad, 0, 0);
4923 for (y = 0; y < getmaxy(panpad); y++) {
4924 for (x = 0; x < getmaxx(panpad); x++) {
4925 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4926 if (y == 0 && x == 0)
4927 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4929 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4930 else if (y == 0 || x == 0)
4931 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4933 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4934 (int) (gridcount++ % 26)));
4935 } else if (y % GRIDSIZE == 0)
4936 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4937 else if (x % GRIDSIZE == 0)
4938 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4940 waddch(panpad, ' ');
4947 int top_x, int top_y, int porty, int portx,
4948 int (*pgetc) (WINDOW *))
4950 #if HAVE_GETTIMEOFDAY
4951 struct timeval before, after;
4954 bool pan_lines = FALSE;
4955 bool scrollers = TRUE;
4958 int pxmax, pymax, lowend, highend, c;
4960 getmaxyx(pad, pymax, pxmax);
4961 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4965 #ifdef NCURSES_VERSION
4967 * During shell-out, the user may have resized the window. Adjust
4968 * the port size of the pad to accommodate this. Ncurses automatically
4969 * resizes all of the normal windows to fit on the new screen.
4987 show_panner_legend = !show_panner_legend;
4988 panner_legend(LINES - 4);
4989 panner_legend(LINES - 3);
4990 panner_legend(LINES - 2);
4991 panner_legend(LINES - 1);
4994 pan_lines = !pan_lines;
4995 fill_pad(pad, pan_lines);
4996 pending_pan = FALSE;
4999 #if HAVE_GETTIMEOFDAY
5003 panner_legend(LINES - 1);
5007 scrollers = !scrollers;
5010 /* Move the top-left corner of the pad, keeping the bottom-right
5013 case 'h': /* increase-columns: move left edge to left */
5017 panner_v_cleanup(top_y, top_x, porty);
5022 case 'j': /* decrease-lines: move top-edge down */
5026 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5031 case 'k': /* increase-lines: move top-edge up */
5036 panner_h_cleanup(top_y, top_x, portx);
5040 case 'l': /* decrease-columns: move left-edge to right */
5044 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5049 /* Move the bottom-right corner of the pad, keeping the top-left
5052 case KEY_IC: /* increase-columns: move right-edge to right */
5053 if (portx >= pxmax || portx >= COLS)
5056 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5061 case KEY_IL: /* increase-lines: move bottom-edge down */
5062 if (porty >= pymax || porty >= LINES)
5065 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5070 case KEY_DC: /* decrease-columns: move bottom edge up */
5075 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5079 case KEY_DL: /* decrease-lines */
5084 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5088 case KEY_LEFT: /* pan leftwards */
5095 case KEY_RIGHT: /* pan rightwards */
5096 if (basex + portx - (pymax > porty) < pxmax)
5102 case KEY_UP: /* pan upwards */
5109 case KEY_DOWN: /* pan downwards */
5110 if (basey + porty - (pxmax > portx) < pymax)
5125 basey = pymax - porty;
5135 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5136 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5137 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5139 if (scrollers && (pxmax > portx - 1)) {
5140 int length = (portx - top_x - 1);
5141 float ratio = ((float) length) / ((float) pxmax);
5143 lowend = (int) ((float) top_x + ((float) basex * ratio));
5144 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5146 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5147 if (highend < portx) {
5149 do_h_line(porty - 1, lowend, ' ', highend + 1);
5151 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5154 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5156 if (scrollers && (pymax > porty - 1)) {
5157 int length = (porty - top_y - 1);
5158 float ratio = ((float) length) / ((float) pymax);
5160 lowend = (int) ((float) top_y + ((float) basey * ratio));
5161 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5163 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5164 if (highend < porty) {
5166 do_v_line(lowend, portx - 1, ' ', highend + 1);
5168 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5171 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5173 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5174 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5175 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5178 #if HAVE_GETTIMEOFDAY
5179 gettimeofday(&before, 0);
5181 wnoutrefresh(stdscr);
5186 porty - (pxmax > portx) - 1,
5187 portx - (pymax > porty) - 1);
5190 #if HAVE_GETTIMEOFDAY
5191 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5194 gettimeofday(&after, 0);
5195 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5196 move(LINES - 1, COLS - 12);
5197 printw("Secs: %2.03f", elapsed);
5204 ((c = pgetc(pad)) != KEY_EXIT);
5206 scrollok(stdscr, TRUE); /* reset to driver's default */
5210 padgetch(WINDOW *win)
5216 if ((pending_pan = (count > 0)) != FALSE) {
5218 pending_pan = (count != 0);
5221 switch (c = wGetchar(win)) {
5257 case ERR: /* FALLTHRU */
5263 if (c >= '0' && c <= '9') {
5264 count = count * 10 + (c - '0');
5278 #define PAD_HIGH 200
5279 #define PAD_WIDE 200
5283 /* Demonstrate pads. */
5285 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5288 Cannot("cannot create requested pad");
5292 fill_pad(panpad, FALSE);
5294 panner_legend(LINES - 4);
5295 panner_legend(LINES - 3);
5296 panner_legend(LINES - 2);
5297 panner_legend(LINES - 1);
5299 keypad(panpad, TRUE);
5301 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5302 * We'll still be able to widen it during a test, since that's required
5303 * for testing boundaries.
5305 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
5312 /****************************************************************************
5314 * Tests from John Burnell's PDCurses tester
5316 ****************************************************************************/
5319 Continue(WINDOW *win)
5323 MvWAddStr(win, 10, 1, " Press any key to continue");
5329 flushinp_test(WINDOW *win)
5330 /* Input test, adapted from John Burnell's PDCurses tester */
5332 int w, h, bx, by, sw, sh, i;
5337 getmaxyx(win, h, w);
5338 getbegyx(win, by, bx);
5341 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5346 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5347 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
5350 (void) wattrset(subWin, A_BOLD);
5351 box(subWin, ACS_VLINE, ACS_HLINE);
5352 MvWAddStr(subWin, 2, 1, "This is a subwindow");
5356 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5357 * it only happened to "work" on SVr4 because that implementation does not
5358 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5359 * test behavior, we're using 'cbreak()', which will allow a single
5360 * character to return without needing a newline. - T.Dickey 1997/10/11.
5363 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
5365 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
5366 MvWAddStr(win, 3, 1,
5367 "These should be discarded (not echoed) after the subwindow goes away.");
5370 for (i = 0; i < 5; i++) {
5371 MvWPrintw(subWin, 1, 1, "Time = %d", i);
5383 MvWAddStr(win, 2, 1,
5384 "If you were still typing when the window timer expired,");
5385 MvWAddStr(win, 3, 1,
5386 "or else you typed nothing at all while it was running,");
5387 MvWAddStr(win, 4, 1,
5388 "test was invalid. You'll see garbage or nothing at all. ");
5389 MvWAddStr(win, 6, 1, "Press a key");
5395 MvWAddStr(win, 12, 0,
5396 "If you see any key other than what you typed, flushinp() is broken.");
5405 "What you typed should now have been deleted; if not, wdelch() failed.");
5411 /****************************************************************************
5415 ****************************************************************************/
5423 menu_virtualize(int c)
5425 if (c == '\n' || c == KEY_EXIT)
5426 return (MAX_COMMAND + 1);
5428 return (REQ_SCR_ULINE);
5430 return (REQ_SCR_DLINE);
5431 else if (c == 'b' || c == KEY_NPAGE)
5432 return (REQ_SCR_UPAGE);
5433 else if (c == 'f' || c == KEY_PPAGE)
5434 return (REQ_SCR_DPAGE);
5435 else if (c == 'n' || c == KEY_DOWN)
5436 return (REQ_NEXT_ITEM);
5437 else if (c == 'p' || c == KEY_UP)
5438 return (REQ_PREV_ITEM);
5440 return (REQ_TOGGLE_ITEM);
5448 static CONST_MENUS char *animals[] =
5461 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5462 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5470 ITEM *items[SIZEOF(animals)];
5472 CONST_MENUS char **ap;
5473 int mrows, mcols, c;
5476 #ifdef NCURSES_MOUSE_VERSION
5477 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5479 MvAddStr(0, 0, "This is the menu test:");
5480 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
5481 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
5483 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
5484 MvAddStr(5, 0, " Press return to exit.");
5487 for (ap = animals; *ap; ap++) {
5488 if ((*ip = new_item(*ap, "")) != 0)
5493 m = new_menu(items);
5495 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
5496 scale_menu(m, &mrows, &mcols);
5498 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5499 set_menu_win(m, menuwin);
5500 keypad(menuwin, TRUE);
5503 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5507 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
5508 if (c == E_NOT_POSTED)
5510 if (c == E_REQUEST_DENIED)
5515 MvPrintw(LINES - 2, 0,
5516 "You chose: %s\n", item_name(current_item(m)));
5517 (void) addstr("Press any key to continue...");
5524 for (ip = items; *ip; ip++)
5526 #ifdef NCURSES_MOUSE_VERSION
5527 mousemask(0, (mmask_t *) 0);
5532 #define T_TBL(name) { #name, name }
5538 T_TBL(TRACE_DISABLE),
5541 T_TBL(TRACE_UPDATE),
5543 T_TBL(TRACE_CHARPUT),
5544 T_TBL(TRACE_ORDINARY),
5546 T_TBL(TRACE_VIRTPUT),
5547 T_TBL(TRACE_IEVENT),
5549 T_TBL(TRACE_ICALLS),
5550 T_TBL(TRACE_CCALLS),
5551 T_TBL(TRACE_DATABASE),
5553 T_TBL(TRACE_MAXIMUM),
5560 tracetrace(unsigned tlevel)
5567 for (n = 0; t_tbl[n].name != 0; n++)
5568 need += strlen(t_tbl[n].name) + 2;
5569 buf = typeMalloc(char, need);
5571 sprintf(buf, "0x%02x = {", tlevel);
5573 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5575 for (n = 1; t_tbl[n].name != 0; n++)
5576 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5577 strcat(buf, t_tbl[n].name);
5581 if (buf[strlen(buf) - 2] == ',')
5582 buf[strlen(buf) - 2] = '\0';
5583 return (strcat(buf, "}"));
5586 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5590 run_trace_menu(MENU * m)
5596 bool changed = FALSE;
5597 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5598 case E_UNKNOWN_COMMAND:
5601 items = menu_items(m);
5602 i = current_item(m);
5603 if (i == items[0]) {
5604 if (item_value(i)) {
5605 for (p = items + 1; *p != 0; p++)
5606 if (item_value(*p)) {
5607 set_item_value(*p, FALSE);
5612 for (p = items + 1; *p != 0; p++)
5613 if (item_value(*p)) {
5614 set_item_value(items[0], FALSE);
5627 /* interactively set the trace level */
5630 ITEM *items[SIZEOF(t_tbl)];
5637 MvAddStr(0, 0, "Interactively set trace level:");
5638 MvAddStr(2, 0, " Press space bar to toggle a selection.");
5639 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
5640 MvAddStr(4, 0, " Press return to set the trace level.");
5641 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5645 for (n = 0; t_tbl[n].name != 0; n++) {
5646 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
5652 m = new_menu(items);
5654 set_menu_format(m, 0, 2);
5655 scale_menu(m, &mrows, &mcols);
5657 menu_opts_off(m, O_ONEVALUE);
5658 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5659 set_menu_win(m, menuwin);
5660 keypad(menuwin, TRUE);
5663 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5667 for (ip = menu_items(m); *ip; ip++) {
5668 unsigned mask = t_tbl[item_index(*ip)].mask;
5670 set_item_value(*ip, _nc_tracing == 0);
5671 else if ((mask & _nc_tracing) == mask)
5672 set_item_value(*ip, TRUE);
5675 while (run_trace_menu(m))
5679 for (ip = menu_items(m); *ip; ip++)
5680 if (item_value(*ip))
5681 newtrace |= t_tbl[item_index(*ip)].mask;
5683 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5685 MvPrintw(LINES - 2, 0,
5686 "Trace level is %s\n", tracetrace(_nc_tracing));
5687 (void) addstr("Press any key to continue...");
5694 for (ip = items; *ip; ip++)
5698 #endif /* USE_LIBMENU */
5700 /****************************************************************************
5704 ****************************************************************************/
5707 make_label(int frow, int fcol, NCURSES_CONST char *label)
5709 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5712 set_field_buffer(f, 0, label);
5713 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
5719 make_field(int frow, int fcol, int rows, int cols, bool secure)
5721 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5724 set_field_back(f, A_UNDERLINE);
5725 set_field_userptr(f, (void *) 0);
5731 display_form(FORM * f)
5736 scale_form(f, &rows, &cols);
5738 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5740 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5745 if (post_form(f) != E_OK)
5750 erase_form(FORM * f)
5752 WINDOW *w = form_win(f);
5753 WINDOW *s = form_sub(f);
5763 edit_secure(FIELD * me, int c)
5765 int rows, cols, frow, fcol, nrow, nbuf;
5767 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5769 char *source = field_buffer(me, 1);
5773 strcpy(temp, source ? source : "");
5774 len = (long) (char *) field_userptr(me);
5776 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5777 temp[len++] = (char) c;
5779 set_field_buffer(me, 1, temp);
5799 case REQ_RIGHT_CHAR:
5801 c = 0; /* we don't want to do inline editing */
5806 set_field_buffer(me, 1, temp);
5813 set_field_buffer(me, 1, temp);
5818 set_field_userptr(me, (void *) len);
5824 form_virtualize(FORM * f, WINDOW *w)
5827 static const struct {
5831 { CTRL('A'), REQ_NEXT_CHOICE },
5832 { CTRL('B'), REQ_PREV_WORD },
5833 { CTRL('C'), REQ_CLR_EOL },
5834 { CTRL('D'), REQ_DOWN_FIELD },
5835 { CTRL('E'), REQ_END_FIELD },
5836 { CTRL('F'), REQ_NEXT_PAGE },
5837 { CTRL('G'), REQ_DEL_WORD },
5838 { CTRL('H'), REQ_DEL_PREV },
5839 { CTRL('I'), REQ_INS_CHAR },
5840 { CTRL('K'), REQ_CLR_EOF },
5841 { CTRL('L'), REQ_LEFT_FIELD },
5842 { CTRL('M'), REQ_NEW_LINE },
5843 { CTRL('N'), REQ_NEXT_FIELD },
5844 { CTRL('O'), REQ_INS_LINE },
5845 { CTRL('P'), REQ_PREV_FIELD },
5846 { CTRL('R'), REQ_RIGHT_FIELD },
5847 { CTRL('S'), REQ_BEG_FIELD },
5848 { CTRL('U'), REQ_UP_FIELD },
5849 { CTRL('V'), REQ_DEL_CHAR },
5850 { CTRL('W'), REQ_NEXT_WORD },
5851 { CTRL('X'), REQ_CLR_FIELD },
5852 { CTRL('Y'), REQ_DEL_LINE },
5853 { CTRL('Z'), REQ_PREV_CHOICE },
5854 { ESCAPE, MAX_FORM_COMMAND + 1 },
5855 { KEY_BACKSPACE, REQ_DEL_PREV },
5856 { KEY_DOWN, REQ_DOWN_CHAR },
5857 { KEY_END, REQ_LAST_FIELD },
5858 { KEY_HOME, REQ_FIRST_FIELD },
5859 { KEY_LEFT, REQ_LEFT_CHAR },
5860 { KEY_LL, REQ_LAST_FIELD },
5861 { KEY_NEXT, REQ_NEXT_FIELD },
5862 { KEY_NPAGE, REQ_NEXT_PAGE },
5863 { KEY_PPAGE, REQ_PREV_PAGE },
5864 { KEY_PREVIOUS, REQ_PREV_FIELD },
5865 { KEY_RIGHT, REQ_RIGHT_CHAR },
5866 { KEY_UP, REQ_UP_CHAR },
5867 { QUIT, MAX_FORM_COMMAND + 1 }
5871 static int mode = REQ_INS_MODE;
5872 int c = wGetchar(w);
5874 FIELD *me = current_field(f);
5875 bool current = TRUE;
5877 if (c == CTRL(']')) {
5878 if (mode == REQ_INS_MODE) {
5879 mode = REQ_OVL_MODE;
5881 mode = REQ_INS_MODE;
5885 for (n = 0; n < SIZEOF(lookup); n++) {
5886 if (lookup[n].code == c) {
5887 c = lookup[n].result;
5892 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5895 * Force the field that the user is typing into to be in reverse video,
5896 * while the other fields are shown underlined.
5911 case REQ_LEFT_FIELD:
5913 case REQ_RIGHT_CHAR:
5917 current = (c < KEY_MAX);
5921 c = edit_secure(me, c);
5922 set_field_back(me, A_REVERSE);
5924 c = edit_secure(me, c);
5925 set_field_back(me, A_UNDERLINE);
5931 my_form_driver(FORM * form, int c)
5933 if (c == (MAX_FORM_COMMAND + 1)
5934 && form_driver(form, REQ_VALIDATION) == E_OK)
5942 #ifdef NCURSES_VERSION
5943 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5944 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5946 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5947 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5951 * Allow a middle initial, optionally with a '.' to end it.
5954 FIELDCHECK_CB(mi_field_check)
5956 char *s = field_buffer(fld, 0);
5960 for (n = 0; s[n] != '\0'; ++n) {
5967 } else if (isspace(UChar(s[n]))) {
5972 if (!isspace(UChar(s[n])))
5978 /* force the form to display a leading capital */
5979 if (islower(UChar(s[0]))) {
5980 s[0] = (char) toupper(UChar(s[0]));
5981 set_field_buffer(fld, 0, s);
5987 CHAR_CHECK_CB(mi_char_check)
5989 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5993 * Passwords should be at least 6 characters.
5996 FIELDCHECK_CB(pw_field_check)
5998 char *s = field_buffer(fld, 0);
6001 for (n = 0; s[n] != '\0'; ++n) {
6002 if (isspace(UChar(s[n]))) {
6011 CHAR_CHECK_CB(pw_char_check)
6013 return (isgraph(ch) ? TRUE : FALSE);
6021 FIELD *f[12], *secure;
6022 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6023 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6024 int finished = 0, c;
6027 #ifdef NCURSES_MOUSE_VERSION
6028 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6032 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6033 addstr("^N -- go to next field ^P -- go to previous field\n");
6034 addstr("Home -- go to first field End -- go to last field\n");
6035 addstr("^L -- go to field to left ^R -- go to field to right\n");
6036 addstr("^U -- move upward to field ^D -- move downward to field\n");
6037 addstr("^W -- go to next word ^B -- go to previous word\n");
6038 addstr("^S -- go to start of field ^E -- go to end of field\n");
6039 addstr("^H -- delete previous char ^Y -- delete line\n");
6040 addstr("^G -- delete current word ^C -- clear to end of line\n");
6041 addstr("^K -- clear to end of field ^X -- clear field\n");
6042 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6044 MvAddStr(4, 57, "Forms Entry Test");
6048 /* describe the form */
6049 memset(f, 0, sizeof(f));
6050 f[n++] = make_label(0, 15, "Sample Form");
6052 f[n++] = make_label(2, 0, "Last Name");
6053 f[n++] = make_field(3, 0, 1, 18, FALSE);
6054 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6056 f[n++] = make_label(2, 20, "First Name");
6057 f[n++] = make_field(3, 20, 1, 12, FALSE);
6058 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6060 f[n++] = make_label(2, 34, "Middle Name");
6061 f[n++] = make_field(3, 34, 1, 12, FALSE);
6062 set_field_type(f[n - 1], fty_middle);
6064 f[n++] = make_label(5, 0, "Comments");
6065 f[n++] = make_field(6, 0, 4, 46, FALSE);
6067 f[n++] = make_label(5, 20, "Password:");
6069 f[n++] = make_field(5, 30, 1, 9, TRUE);
6070 set_field_type(f[n - 1], fty_passwd);
6073 if ((form = new_form(f)) != 0) {
6079 nonl(); /* lets us read ^M's */
6081 switch (form_driver(form, c = form_virtualize(form, w))) {
6083 MvAddStr(5, 57, field_buffer(secure, 1));
6087 case E_UNKNOWN_COMMAND:
6088 finished = my_form_driver(form, c);
6100 for (c = 0; f[c] != 0; c++)
6102 free_fieldtype(fty_middle);
6103 free_fieldtype(fty_passwd);
6107 #ifdef NCURSES_MOUSE_VERSION
6108 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6111 #endif /* USE_LIBFORM */
6113 /****************************************************************************
6117 ****************************************************************************/
6120 fillwin(WINDOW *win, char ch)
6125 getmaxyx(win, y1, x1);
6126 for (y = 0; y < y1; y++) {
6128 for (x = 0; x < x1; x++)
6129 waddch(win, UChar(ch));
6134 crosswin(WINDOW *win, char ch)
6139 getmaxyx(win, y1, x1);
6140 for (y = 0; y < y1; y++) {
6141 for (x = 0; x < x1; x++)
6142 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
6143 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
6145 waddch(win, UChar(ch));
6150 #define OVERLAP_FLAVORS 5
6153 overlap_helpitem(int state, int item, char *message)
6155 int row = (item / 2);
6156 int col = ((item % 2) ? COLS / 2 : 0);
6158 move(LINES - 6 + row, col);
6159 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6164 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6166 short cpair = (short) (1 + (flavor * 2) + col);
6170 (void) wattrset(win, A_NORMAL);
6173 (void) wattrset(win, A_BOLD);
6176 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6177 (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_NORMAL));
6180 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6181 (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD));
6187 overlap_test_2_attr(WINDOW *win, int flavor, int col)
6189 short cpair = (short) (9 + (flavor * 2) + col);
6199 init_pair(cpair, COLOR_RED, COLOR_GREEN);
6200 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
6203 wbkgdset(win, ' ' | A_NORMAL);
6209 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
6214 const char *ths, *tht;
6218 state += OVERLAP_FLAVORS;
6219 state = state % OVERLAP_FLAVORS;
6220 assert(state >= 0 && state < OVERLAP_FLAVORS);
6222 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
6225 ths = col ? "B" : "A";
6226 tht = col ? "A" : "B";
6231 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
6239 overlap_test_1_attr(stdscr, flavors[row], col);
6240 sprintf(msg, "fill window %s with letter %s.", ths, ths);
6248 switch (flavors[row]) {
6250 sprintf(msg, "cross pattern in window %s.", ths);
6253 sprintf(msg, "draw box in window %s.", ths);
6256 sprintf(msg, "set background of window %s.", ths);
6259 sprintf(msg, "reset background of window %s.", ths);
6265 sprintf(msg, "clear window %s.", ths);
6269 switch (flavors[row]) {
6271 sprintf(msg, "overwrite %s onto %s.", ths, tht);
6274 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
6277 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
6280 sprintf(msg, "overlay %s onto %s.", ths, tht);
6285 overlap_helpitem(state, item, msg);
6286 (void) wattrset(stdscr, A_NORMAL);
6287 wbkgdset(stdscr, ' ' | A_NORMAL);
6290 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
6291 state, flavors[state]);
6297 overlap_test_0(WINDOW *a, WINDOW *b)
6307 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
6309 overlap_test_1_attr(a, flavor, col);
6311 (void) wattrset(a, A_NORMAL);
6315 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6317 overlap_test_2_attr(a, flavor, col);
6326 /* done in overlap_test_2_attr */
6329 /* done in overlap_test_2_attr */
6335 overlap_test_3(WINDOW *a)
6342 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
6349 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
6352 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
6360 /* test effects of overlapping windows */
6365 int state, flavor[OVERLAP_FLAVORS];
6367 WINDOW *win1 = newwin(9, 20, 3, 3);
6368 WINDOW *win2 = newwin(9, 20, 9, 16);
6374 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
6375 printw("the shared region of two overlapping windows A and B. The cross\n");
6376 printw("pattern in each window does not overlap the other.\n");
6378 memset(flavor, 0, sizeof(flavor));
6379 state = overlap_help(0, flavor);
6381 while (!isQuit(ch = Getchar()))
6383 case 'a': /* refresh window A first, then B */
6384 overlap_test_0(win1, win2);
6387 case 'b': /* refresh window B first, then A */
6388 overlap_test_0(win2, win1);
6391 case 'c': /* fill window A so it's visible */
6392 overlap_test_1(flavor[1], 0, win1, 'A');
6395 case 'd': /* fill window B so it's visible */
6396 overlap_test_1(flavor[1], 1, win2, 'B');
6399 case 'e': /* cross test pattern in window A */
6400 overlap_test_2(flavor[2], 0, win1, 'A');
6403 case 'f': /* cross test pattern in window A */
6404 overlap_test_2(flavor[2], 1, win2, 'B');
6407 case 'g': /* clear window A */
6408 overlap_test_3(win1);
6411 case 'h': /* clear window B */
6412 overlap_test_3(win2);
6415 case 'i': /* overwrite A onto B */
6416 overlap_test_4(flavor[4], win1, win2);
6419 case 'j': /* overwrite B onto A */
6420 overlap_test_4(flavor[4], win2, win1);
6425 state = overlap_help(state + 1, flavor);
6430 state = overlap_help(state - 1, flavor);
6435 state = overlap_help(state, flavor);
6439 state = overlap_help(state, flavor);
6454 /****************************************************************************
6458 ****************************************************************************/
6461 do_single_test(const char c)
6462 /* perform a single specified test */
6469 #if USE_WIDEC_SUPPORT
6479 #if USE_WIDEC_SUPPORT
6487 Cannot("does not support color.");
6492 #if USE_WIDEC_SUPPORT
6495 Cannot("does not support color.");
6503 Cannot("does not support color.");
6504 else if (!can_change_color())
6505 Cannot("has hardwired color values.");
6515 #if USE_WIDEC_SUPPORT
6526 #if USE_WIDEC_SUPPORT
6534 demo_panels(init_panel, fill_panel);
6538 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6540 demo_panels(init_wide_panel, fill_wide_panel);
6549 flushinp_test(stdscr);
6553 test_sgr_attributes();
6576 #if USE_LIBMENU && defined(TRACE)
6595 static const char *const tbl[] =
6597 "Usage: ncurses [options]"
6600 #ifdef NCURSES_VERSION
6601 ," -a f,b set default-colors (assumed white-on-black)"
6602 ," -d use default-colors if terminal supports them"
6604 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
6606 ," -e fmt specify format for soft-keys test (e)"
6609 ," -f rip-off footer line (can repeat)"
6610 ," -h rip-off header line (can repeat)"
6612 ," -m do not use colors"
6613 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6615 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6617 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714)
6618 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
6621 ," -t mask specify default trace-level (may toggle with ^T)"
6625 for (n = 0; n < SIZEOF(tbl); n++)
6626 fprintf(stderr, "%s\n", tbl[n]);
6627 ExitProgram(EXIT_FAILURE);
6631 set_terminal_modes(void)
6636 scrollok(stdscr, TRUE);
6637 idlok(stdscr, TRUE);
6638 keypad(stdscr, TRUE);
6643 announce_sig(int sig)
6645 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6651 rip_footer(WINDOW *win, int cols)
6653 wbkgd(win, A_REVERSE);
6656 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
6662 rip_header(WINDOW *win, int cols)
6664 wbkgd(win, A_REVERSE);
6667 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
6671 #endif /* HAVE_RIPOFFLINE */
6679 (void) puts("This is the ncurses main menu");
6680 (void) puts("a = keyboard and mouse input test");
6681 #if USE_WIDEC_SUPPORT
6682 (void) puts("A = wide-character keyboard and mouse input test");
6684 (void) puts("b = character attribute test");
6685 #if USE_WIDEC_SUPPORT
6686 (void) puts("B = wide-character attribute test");
6688 (void) puts("c = color test pattern");
6689 #if USE_WIDEC_SUPPORT
6690 (void) puts("C = color test pattern using wide-character calls");
6693 (void) puts("d = edit RGB color values");
6695 (void) puts("e = exercise soft keys");
6696 #if USE_WIDEC_SUPPORT
6697 (void) puts("E = exercise soft keys using wide-characters");
6700 (void) puts("f = display ACS characters");
6701 #if USE_WIDEC_SUPPORT
6702 (void) puts("F = display Wide-ACS characters");
6704 (void) puts("g = display windows and scrolling");
6705 (void) puts("i = test of flushinp()");
6706 (void) puts("k = display character attributes");
6708 (void) puts("m = menu code test");
6711 (void) puts("o = exercise panels library");
6712 #if USE_WIDEC_SUPPORT
6713 (void) puts("O = exercise panels with wide-characters");
6716 (void) puts("p = exercise pad features");
6717 (void) puts("q = quit");
6719 (void) puts("r = exercise forms code");
6721 (void) puts("s = overlapping-refresh test");
6722 #if USE_LIBMENU && defined(TRACE)
6723 (void) puts("t = set trace level");
6725 (void) puts("? = repeat this command summary");
6727 (void) fputs("> ", stdout);
6728 (void) fflush(stdout); /* necessary under SVr4 curses */
6731 * This used to be an 'fgets()' call (until 1996/10). However with
6732 * some runtime libraries, mixing stream I/O and 'read()' causes the
6733 * input stream to be flushed when switching between the two.
6738 if (read(fileno(stdin), &ch, 1) <= 0) {
6742 } else if (command == 0 && !isspace(UChar(ch))) {
6744 } else if (ch == '\n' || ch == '\r') {
6745 if ((command == 'd') && !top) {
6746 (void) fputs("Do not nest test-d\n", stdout);
6751 (void) fputs("> ", stdout);
6752 (void) fflush(stdout);
6756 if (do_single_test(command)) {
6758 * This may be overkill; it's intended to reset everything back
6759 * to the initial terminal modes so that tests don't get in
6763 set_terminal_modes();
6768 if (command == '?') {
6769 (void) puts("This is the ncurses capability tester.");
6771 puts("You may select a test from the main menu by typing the");
6773 puts("key letter of the choice (the letter to left of the =)");
6775 puts("at the > prompt. Type `q' to exit.");
6783 /*+-------------------------------------------------------------------------
6785 --------------------------------------------------------------------------*/
6787 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6788 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6791 main(int argc, char *argv[])
6795 #ifdef NCURSES_VERSION
6796 int default_fg = COLOR_WHITE;
6797 int default_bg = COLOR_BLACK;
6798 bool assumed_colors = FALSE;
6799 bool default_colors = FALSE;
6801 char *palette_file = 0;
6802 bool monochrome = FALSE;
6804 setlocale(LC_ALL, "");
6806 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:")) != -1) {
6808 #ifdef NCURSES_VERSION
6810 assumed_colors = TRUE;
6811 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6814 default_colors = TRUE;
6821 my_e_param = atoi(optarg);
6822 #ifdef NCURSES_VERSION
6823 if (my_e_param > 3) /* allow extended layouts */
6832 ripoffline(-1, rip_footer);
6835 ripoffline(1, rip_header);
6837 #endif /* HAVE_RIPOFFLINE */
6842 palette_file = optarg;
6846 nap_msec = (int) atol(optarg);
6849 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714)
6856 save_trace = (unsigned) strtol(optarg, 0, 0);
6865 * If there's no menus (unlikely for ncurses!), then we'll have to set
6866 * tracing on initially, just in case the user wants to test something that
6867 * doesn't involve wGetchar.
6870 /* enable debugging */
6874 if (!isatty(fileno(stdin)))
6876 #endif /* USE_LIBMENU */
6880 /* tell it we're going to play with soft keys */
6881 slk_init(my_e_param);
6885 /* set up null signal catcher so we can see what interrupts to getch do */
6886 signal(SIGUSR1, announce_sig);
6889 /* we must initialize the curses data structure only once */
6893 /* tests, in general, will want these modes */
6894 use_colors = monochrome ? FALSE : has_colors();
6898 #ifdef NCURSES_VERSION_PATCH
6899 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6900 #if HAVE_USE_DEFAULT_COLORS
6901 if (default_colors) {
6902 use_default_colors();
6905 #if HAVE_ASSUME_DEFAULT_COLORS
6907 assume_default_colors(default_fg, default_bg);
6910 #else /* normal SVr4 curses */
6911 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6913 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6915 if (can_change_color()) {
6917 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
6918 for (cp = 0; cp < max_colors; ++cp) {
6920 &all_colors[cp].red,
6921 &all_colors[cp].green,
6922 &all_colors[cp].blue);
6924 if (palette_file != 0) {
6925 FILE *fp = fopen(palette_file, "r");
6927 char buffer[BUFSIZ];
6928 int red, green, blue;
6930 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6931 if (sscanf(buffer, "scale:%d", &c) == 1) {
6933 } else if (sscanf(buffer, "%d:%d %d %d",
6942 all_colors[c].red = (short) ((red * 1000) / scale);
6943 all_colors[c].green = (short) ((green * 1000) / scale);
6944 all_colors[c].blue = (short) ((blue * 1000) / scale);
6952 set_terminal_modes();
6956 * Return to terminal mode, so we're guaranteed of being able to
6957 * select terminal commands even if the capabilities are wrong.
6961 #if HAVE_CURSES_VERSION
6962 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6963 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6964 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6965 NCURSES_VERSION_MAJOR,
6966 NCURSES_VERSION_MINOR,
6967 NCURSES_VERSION_PATCH);
6969 (void) puts("Welcome to ncurses. Press ? for help.");
6974 ExitProgram(EXIT_SUCCESS);
6977 /* ncurses.c ends here */