1 /****************************************************************************
2 * Copyright (c) 1998-2012,2013 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.393 2013/09/07 19:17:48 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);
170 failed(const char *s)
174 ExitProgram(EXIT_FAILURE);
177 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
178 * though we can rely on negative x/y values to stop the macro.
181 do_h_line(int y, int x, chtype c, int to)
184 MvHLine(y, x, c, (to) - (x));
188 do_v_line(int y, int x, chtype c, int to)
191 MvVLine(y, x, c, (to) - (y));
205 return ((c) == QUIT || (c) == ESCAPE);
207 #define case_QUIT QUIT: case ESCAPE
209 /* Common function to allow ^T to toggle trace-mode in the middle of a test
210 * so that trace-files can be made smaller.
213 wGetchar(WINDOW *win)
217 while ((c = wgetch(win)) == CTRL('T')) {
219 save_trace = _nc_tracing;
220 Trace(("TOGGLE-TRACING OFF"));
223 _nc_tracing = save_trace;
227 Trace(("TOGGLE-TRACING ON"));
234 #define Getchar() wGetchar(stdscr)
236 /* replaces wgetnstr(), since we want to be able to edit values */
238 wGetstring(WINDOW *win, char *buffer, int limit)
245 (void) wattrset(win, A_REVERSE);
247 x = (int) strlen(buffer);
249 if (x > (int) strlen(buffer))
250 x = (int) strlen(buffer);
252 wprintw(win, "%-*s", limit, buffer);
253 wmove(win, y0, x0 + x);
254 switch (ch = wGetchar(win)) {
267 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
285 if (!isprint(ch) || ch >= KEY_MIN) {
287 } else if ((int) strlen(buffer) < limit) {
289 for (j = (int) strlen(buffer) + 1; j > x; --j) {
290 buffer[j] = buffer[j - 1];
292 buffer[x++] = (char) ch;
299 wattroff(win, A_REVERSE);
304 #if USE_WIDEC_SUPPORT
308 return (ch + 0xff10 - '0');
312 make_fullwidth_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
316 *target++ = fullwidth_of(ch);
322 make_narrow_text(wchar_t *target, const char *source)
325 while ((ch = *source++) != 0) {
333 make_fullwidth_digit(cchar_t *target, int digit)
337 source[0] = fullwidth_of(digit + '0');
339 setcchar(target, source, A_NORMAL, 0, 0);
344 wGet_wchar(WINDOW *win, wint_t *result)
348 while ((c = wget_wch(win, result)) == CTRL('T')) {
350 save_trace = _nc_tracing;
351 Trace(("TOGGLE-TRACING OFF"));
354 _nc_tracing = save_trace;
358 Trace(("TOGGLE-TRACING ON"));
361 c = wget_wch(win, result);
365 #define Get_wchar(result) wGet_wchar(stdscr, result)
367 /* replaces wgetn_wstr(), since we want to be able to edit values */
369 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
378 (void) wattrset(win, A_REVERSE);
380 x = (int) wcslen(buffer);
382 if (x > (int) wcslen(buffer))
383 x = (int) wcslen(buffer);
385 /* clear the "window' */
387 wprintw(win, "%*s", limit, " ");
389 /* write the existing buffer contents */
391 waddnwstr(win, buffer, limit);
393 /* positions the cursor past character 'x' */
395 waddnwstr(win, buffer, x);
397 switch (wGet_wchar(win, &ch)) {
437 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
457 } else if ((int) wcslen(buffer) < limit) {
459 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
460 buffer[j] = buffer[j - 1];
462 buffer[x++] = (wchar_t) ch;
469 wattroff(win, A_REVERSE);
480 addstr("Press any key to continue... ");
485 Cannot(const char *what)
487 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
492 ShellOut(bool message)
495 addstr("Shelling out...");
501 IGNORE_RC(system("sh"));
504 addstr("returned from shellout.\n");
508 #ifdef NCURSES_MOUSE_VERSION
510 * This function is the same as _tracemouse(), but we cannot count on that
511 * being available in the non-debug library.
514 mouse_decode(MEVENT const *ep)
516 static char buf[80 + (5 * 10) + (32 * 15)];
518 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
519 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
521 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
523 SHOW(BUTTON1_RELEASED, "release-1");
524 SHOW(BUTTON1_PRESSED, "press-1");
525 SHOW(BUTTON1_CLICKED, "click-1");
526 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
527 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
528 #if NCURSES_MOUSE_VERSION == 1
529 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
532 SHOW(BUTTON2_RELEASED, "release-2");
533 SHOW(BUTTON2_PRESSED, "press-2");
534 SHOW(BUTTON2_CLICKED, "click-2");
535 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
536 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
537 #if NCURSES_MOUSE_VERSION == 1
538 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
541 SHOW(BUTTON3_RELEASED, "release-3");
542 SHOW(BUTTON3_PRESSED, "press-3");
543 SHOW(BUTTON3_CLICKED, "click-3");
544 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
545 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
546 #if NCURSES_MOUSE_VERSION == 1
547 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
550 SHOW(BUTTON4_RELEASED, "release-4");
551 SHOW(BUTTON4_PRESSED, "press-4");
552 SHOW(BUTTON4_CLICKED, "click-4");
553 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
554 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
555 #if NCURSES_MOUSE_VERSION == 1
556 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
559 #if NCURSES_MOUSE_VERSION == 2
560 SHOW(BUTTON5_RELEASED, "release-5");
561 SHOW(BUTTON5_PRESSED, "press-5");
562 SHOW(BUTTON5_CLICKED, "click-5");
563 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
564 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
567 SHOW(BUTTON_CTRL, "ctrl");
568 SHOW(BUTTON_SHIFT, "shift");
569 SHOW(BUTTON_ALT, "alt");
570 SHOW(ALL_MOUSE_EVENTS, "all-events");
571 SHOW(REPORT_MOUSE_POSITION, "position");
575 if (buf[strlen(buf) - 1] == ' ')
576 buf[strlen(buf) - 2] = '\0';
577 (void) strcat(buf, "}");
582 show_mouse(WINDOW *win)
590 outside = !wenclose(win, event.y, event.x);
593 (void) wstandout(win);
594 waddstr(win, "KEY_MOUSE");
595 (void) wstandend(win);
597 waddstr(win, "KEY_MOUSE");
599 wprintw(win, ", %s", mouse_decode(&event));
604 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
608 wmove(win, event.y, event.x);
616 #endif /* NCURSES_MOUSE_VERSION */
618 /****************************************************************************
620 * Character input test
622 ****************************************************************************/
624 #define NUM_GETCH_FLAGS 256
625 typedef bool GetchFlags[NUM_GETCH_FLAGS];
628 setup_getch(WINDOW *win, GetchFlags flags)
630 keypad(win, flags['k']); /* should be redundant, but for testing */
631 meta(win, flags['m']); /* force this to a known state */
639 init_getch(WINDOW *win, GetchFlags flags)
641 memset(flags, FALSE, NUM_GETCH_FLAGS);
642 flags[UChar('k')] = (win == stdscr);
643 flags[UChar('m')] = TRUE;
645 setup_getch(win, flags);
649 wgetch_help(WINDOW *win, GetchFlags flags)
651 static const char *help[] =
653 "e -- toggle echo mode"
654 ,"g -- triggers a getstr test"
655 ,"k -- toggle keypad/literal mode"
656 ,"m -- toggle meta (7-bit/8-bit) mode"
659 ,"w -- create a new window"
661 ,"z -- suspend this process"
665 unsigned chk = ((SIZEOF(help) + 1) / 2);
670 printw("Type any key to see its %s value. Also:\n",
671 flags['k'] ? "keypad" : "literal");
672 for (n = 0; n < SIZEOF(help); ++n) {
673 int row = 1 + (int) (n % chk);
674 int col = (n >= chk) ? COLS / 2 : 0;
675 int flg = ((strstr(help[n], "toggle") != 0)
676 && (flags[UChar(*help[n])] != FALSE));
679 MvPrintw(row, col, "%s", help[n]);
690 wgetch_wrap(WINDOW *win, int first_y)
692 int last_y = getmaxy(win) - 1;
693 int y = getcury(win) + 1;
701 #if defined(KEY_RESIZE) && HAVE_WRESIZE
707 static WINSTACK *winstack = 0;
708 static unsigned len_winstack = 0;
721 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
723 unsigned need = (level + 1) * 2;
725 assert(level < (unsigned) COLS);
729 winstack = typeMalloc(WINSTACK, len_winstack);
730 } else if (need >= len_winstack) {
732 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
735 failed("remember_boxes");
736 winstack[level].text = txt_win;
737 winstack[level].frame = box_win;
740 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
744 /* this chunk is now done in resize_term() */
751 #define slk_repaint() /* nothing */
754 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
756 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
757 * Resize both and paint the box in the parent.
760 resize_boxes(unsigned level, WINDOW *win)
764 int high = LINES - base;
768 wnoutrefresh(stdscr);
772 for (n = 0; n < level; ++n) {
773 wresize(winstack[n].frame, high, wide);
774 wresize(winstack[n].text, high - 2, wide - 2);
777 werase(winstack[n].text);
778 box(winstack[n].frame, 0, 0);
779 wnoutrefresh(winstack[n].frame);
780 wprintw(winstack[n].text,
782 getmaxy(winstack[n].text),
783 getmaxx(winstack[n].text));
784 wnoutrefresh(winstack[n].text);
785 if (winstack[n].text == win)
790 #endif /* resize_boxes */
792 #define forget_boxes() /* nothing */
793 #define remember_boxes(level,text,frame) /* nothing */
797 * Return-code is OK/ERR or a keyname.
802 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
806 wgetch_test(unsigned level, WINDOW *win, int delay)
809 int first_y, first_x;
813 bool blocking = (delay < 0);
815 init_getch(win, flags);
816 wtimeout(win, delay);
817 getyx(win, first_y, first_x);
819 wgetch_help(win, flags);
820 wsetscrreg(win, first_y, getmaxy(win) - 1);
824 while ((c = wGetchar(win)) == ERR) {
827 (void) wprintw(win, "%05d: input error", incount);
830 (void) wprintw(win, "%05d: input timed out", incount);
832 wgetch_wrap(win, first_y);
834 if (c == ERR && blocking) {
836 wgetch_wrap(win, first_y);
837 } else if (isQuit(c)) {
839 } else if (c == 'e') {
840 flags[UChar('e')] = !flags[UChar('e')];
841 setup_getch(win, flags);
842 wgetch_help(win, flags);
843 } else if (c == 'g') {
844 waddstr(win, "getstr test: ");
846 c = wgetnstr(win, buf, sizeof(buf) - 1);
848 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
849 (int) strlen(buf), buf,
852 wgetch_wrap(win, first_y);
853 } else if (c == 'k') {
854 flags[UChar('k')] = !flags[UChar('k')];
855 setup_getch(win, flags);
856 wgetch_help(win, flags);
857 } else if (c == 'm') {
858 flags[UChar('m')] = !flags[UChar('m')];
859 setup_getch(win, flags);
860 wgetch_help(win, flags);
861 } else if (c == 's') {
863 } else if (c == 'w') {
864 int high = getmaxy(win) - 1 - first_y + 1;
865 int wide = getmaxx(win) - first_x;
867 int new_y = first_y + getbegy(win);
868 int new_x = first_x + getbegx(win);
870 getyx(win, old_y, old_x);
871 if (high > 2 && wide > 2) {
872 WINDOW *wb = newwin(high, wide, new_y, new_x);
873 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
878 remember_boxes(level, wi, wb);
879 wgetch_test(level + 1, wi, delay);
883 wgetch_help(win, flags);
884 wmove(win, old_y, old_x);
890 } else if (c == 'z') {
891 kill(getpid(), SIGTSTP);
894 wprintw(win, "Key pressed: %04o ", c);
895 #ifdef NCURSES_MOUSE_VERSION
896 if (c == KEY_MOUSE) {
899 #endif /* NCURSES_MOUSE_VERSION */
901 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
902 if (c == KEY_RESIZE) {
903 resize_boxes(level, win);
906 (void) waddstr(win, keyname(c));
907 } else if (c >= 0x80) {
908 unsigned c2 = (unsigned) c;
909 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
910 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
914 (void) wprintw(win, "%c", UChar(c));
915 else if (c2 != UChar(c))
916 (void) wprintw(win, "M-%s", unctrl(c2));
918 (void) wprintw(win, "%s", unctrl(c2));
919 waddstr(win, " (high-half character)");
922 (void) wprintw(win, "%c (ASCII printable character)", c);
924 (void) wprintw(win, "%s (ASCII control character)",
927 wgetch_wrap(win, first_y);
934 init_getch(win, flags);
938 begin_getch_test(void)
945 #ifdef NCURSES_MOUSE_VERSION
946 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
949 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
951 getnstr(buf, sizeof(buf) - 1);
955 if (isdigit(UChar(buf[0]))) {
956 delay = atoi(buf) * 100;
966 finish_getch_test(void)
968 #ifdef NCURSES_MOUSE_VERSION
969 mousemask(0, (mmask_t *) 0);
980 int delay = begin_getch_test();
983 wgetch_test(0, stdscr, delay);
989 #if USE_WIDEC_SUPPORT
991 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
992 * Resize both and paint the box in the parent.
994 #if defined(KEY_RESIZE) && HAVE_WRESIZE
996 resize_wide_boxes(unsigned level, WINDOW *win)
1000 int high = LINES - base;
1004 wnoutrefresh(stdscr);
1008 for (n = 0; n < level; ++n) {
1009 wresize(winstack[n].frame, high, wide);
1010 wresize(winstack[n].text, high - 2, wide - 2);
1013 werase(winstack[n].text);
1014 box_set(winstack[n].frame, 0, 0);
1015 wnoutrefresh(winstack[n].frame);
1016 wprintw(winstack[n].text,
1018 getmaxy(winstack[n].text),
1019 getmaxx(winstack[n].text));
1020 wnoutrefresh(winstack[n].text);
1021 if (winstack[n].text == win)
1026 #endif /* KEY_RESIZE */
1029 wcstos(const wchar_t *src)
1033 const wchar_t *tmp = src;
1034 #ifndef state_unused
1038 reset_wchars(state);
1039 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1040 unsigned have = (unsigned) need;
1041 if ((result = typeCalloc(char, have + 1)) != 0) {
1043 if (trans_wchars(result, tmp, have, &state) != have) {
1055 wget_wch_test(unsigned level, WINDOW *win, int delay)
1057 wchar_t wchar_buf[BUFSIZ];
1058 wint_t wint_buf[BUFSIZ];
1059 int first_y, first_x;
1063 bool blocking = (delay < 0);
1067 init_getch(win, flags);
1068 wtimeout(win, delay);
1069 getyx(win, first_y, first_x);
1071 wgetch_help(win, flags);
1072 wsetscrreg(win, first_y, getmaxy(win) - 1);
1073 scrollok(win, TRUE);
1076 while ((code = wGet_wchar(win, &c)) == ERR) {
1079 (void) wprintw(win, "%05d: input error", incount);
1082 (void) wprintw(win, "%05d: input timed out", incount);
1084 wgetch_wrap(win, first_y);
1086 if (code == ERR && blocking) {
1087 wprintw(win, "ERR");
1088 wgetch_wrap(win, first_y);
1089 } else if (isQuit((int) c)) {
1091 } else if (c == 'e') {
1092 flags[UChar('e')] = !flags[UChar('e')];
1093 setup_getch(win, flags);
1094 wgetch_help(win, flags);
1095 } else if (c == 'g') {
1096 waddstr(win, "getstr test: ");
1098 code = wgetn_wstr(win, wint_buf, BUFSIZ - 1);
1101 wprintw(win, "wgetn_wstr returns an error.");
1104 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1107 if ((temp = wcstos(wchar_buf)) != 0) {
1108 wprintw(win, "I saw %d characters:\n\t`%s'.",
1109 (int) wcslen(wchar_buf), temp);
1112 wprintw(win, "I saw %d characters (cannot convert).",
1113 (int) wcslen(wchar_buf));
1117 wgetch_wrap(win, first_y);
1118 } else if (c == 'k') {
1119 flags[UChar('k')] = !flags[UChar('k')];
1120 setup_getch(win, flags);
1121 wgetch_help(win, flags);
1122 } else if (c == 'm') {
1123 flags[UChar('m')] = !flags[UChar('m')];
1124 setup_getch(win, flags);
1125 wgetch_help(win, flags);
1126 } else if (c == 's') {
1128 } else if (c == 'w') {
1129 int high = getmaxy(win) - 1 - first_y + 1;
1130 int wide = getmaxx(win) - first_x;
1132 int new_y = first_y + getbegy(win);
1133 int new_x = first_x + getbegx(win);
1135 getyx(win, old_y, old_x);
1136 if (high > 2 && wide > 2) {
1137 WINDOW *wb = newwin(high, wide, new_y, new_x);
1138 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1143 remember_boxes(level, wi, wb);
1144 wget_wch_test(level + 1, wi, delay);
1148 wgetch_help(win, flags);
1149 wmove(win, old_y, old_x);
1154 } else if (c == 'z') {
1155 kill(getpid(), SIGTSTP);
1158 wprintw(win, "Key pressed: %04o ", (int) c);
1159 #ifdef NCURSES_MOUSE_VERSION
1160 if (c == KEY_MOUSE) {
1163 #endif /* NCURSES_MOUSE_VERSION */
1164 if (code == KEY_CODE_YES) {
1165 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1166 if (c == KEY_RESIZE) {
1167 resize_wide_boxes(level, win);
1170 (void) waddstr(win, keyname((wchar_t) c));
1172 (void) waddstr(win, key_name((wchar_t) c));
1173 if (c < 256 && iscntrl(c)) {
1174 (void) wprintw(win, " (control character)");
1176 (void) wprintw(win, " = %#x (printable character)",
1180 wgetch_wrap(win, first_y);
1187 init_getch(win, flags);
1193 int delay = begin_getch_test();
1196 wget_wch_test(0, stdscr, delay);
1198 finish_getch_test();
1203 /****************************************************************************
1205 * Character attributes test
1207 ****************************************************************************/
1209 #if HAVE_SETUPTERM || HAVE_TGETENT
1210 #define get_ncv() TIGETNUM("ncv","NC")
1211 #define get_xmc() TIGETNUM("xmc","sg")
1213 #define get_ncv() -1
1214 #define get_xmc() -1
1221 static int first = TRUE;
1222 static chtype result = 0;
1228 char *area_pointer = parsed;
1230 tgetent(buffer, getenv("TERM"));
1233 if (TIGETSTR("smso", "so"))
1234 result |= A_STANDOUT;
1235 if (TIGETSTR("smul", "us"))
1236 result |= A_UNDERLINE;
1237 if (TIGETSTR("rev", "mr"))
1238 result |= A_REVERSE;
1239 if (TIGETSTR("blink", "mb"))
1241 if (TIGETSTR("dim", "mh"))
1243 if (TIGETSTR("bold", "md"))
1245 if (TIGETSTR("smacs", "ac"))
1246 result |= A_ALTCHARSET;
1252 #define termattrs() my_termattrs()
1255 #define MAX_ATTRSTRING 31
1256 #define LEN_ATTRSTRING 26
1258 static char attr_test_string[MAX_ATTRSTRING + 1];
1261 attr_legend(WINDOW *helpwin)
1266 MvWPrintw(helpwin, row++, col,
1268 MvWPrintw(helpwin, row++, col,
1271 MvWPrintw(helpwin, row++, col,
1272 "Modify the test strings:");
1273 MvWPrintw(helpwin, row++, col,
1274 " A digit sets gaps on each side of displayed attributes");
1275 MvWPrintw(helpwin, row++, col,
1276 " </> shifts the text left/right. ");
1278 MvWPrintw(helpwin, row++, col,
1281 MvWPrintw(helpwin, row++, col,
1282 " f/F/b/F toggle foreground/background background color");
1283 MvWPrintw(helpwin, row++, col,
1284 " t/T toggle text/background color attribute");
1286 MvWPrintw(helpwin, row++, col,
1287 " a/A toggle ACS (alternate character set) mapping");
1288 MvWPrintw(helpwin, row, col,
1289 " v/V toggle video attribute to combine with each line");
1293 show_color_attr(int fg, int bg, int tx)
1296 printw(" Colors (fg %d, bg %d", fg, bg);
1298 printw(", text %d", tx);
1304 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1311 *fg = (short) (*fg + 1);
1314 *fg = (short) (*fg - 1);
1317 *bg = (short) (*bg + 1);
1320 *bg = (short) (*bg - 1);
1323 *tx = (short) (*tx + 1);
1326 *tx = (short) (*tx - 1);
1334 *fg = (short) min_colors;
1335 if (*fg < min_colors)
1336 *fg = (short) (COLORS - 1);
1338 *bg = (short) min_colors;
1339 if (*bg < min_colors)
1340 *bg = (short) (COLORS - 1);
1344 *tx = (short) (COLORS - 1);
1353 adjust_attr_string(int adjust)
1355 int first = ((int) UChar(attr_test_string[0])) + adjust;
1356 int last = first + LEN_ATTRSTRING;
1358 if (first >= ' ' && last <= '~') { /* 32..126 */
1360 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1361 attr_test_string[j] = (char) k;
1362 if (((k + 1 - first) % 5) == 0) {
1363 if (++j >= MAX_ATTRSTRING)
1365 attr_test_string[j] = ' ';
1368 while (j < MAX_ATTRSTRING)
1369 attr_test_string[j++] = ' ';
1370 attr_test_string[j] = '\0';
1377 init_attr_string(void)
1379 attr_test_string[0] = 'a';
1380 adjust_attr_string(0);
1384 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1386 int ncv = get_ncv();
1387 chtype test = attr & (chtype) (~A_ALTCHARSET);
1390 MvPrintw(row, 5, "-->");
1391 MvPrintw(row, 8, "%s mode:", name);
1392 MvPrintw(row, 24, "|");
1394 printw("%*s", skip, " ");
1396 * Just for testing, write text using the alternate character set one
1397 * character at a time (to pass its rendition directly), and use the
1398 * string operation for the other attributes.
1400 if (attr & A_ALTCHARSET) {
1404 for (s = attr_test_string; *s != '\0'; ++s) {
1409 (void) attrset(attr);
1410 addstr(attr_test_string);
1414 printw("%*s", skip, " ");
1416 if (test != A_NORMAL) {
1417 if (!(termattrs() & test)) {
1420 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1421 static const chtype table[] =
1440 for (n = 0; n < SIZEOF(table); n++) {
1441 if ((table[n] & attr) != 0
1442 && ((1 << n) & ncv) != 0) {
1450 if ((termattrs() & test) != test)
1459 NCURSES_CONST char *name;
1462 static const ATTR_TBL attrs_to_test[] = {
1463 { A_STANDOUT, "STANDOUT" },
1464 { A_REVERSE, "REVERSE" },
1466 { A_UNDERLINE, "UNDERLINE" },
1468 { A_BLINK, "BLINK" },
1469 { A_PROTECT, "PROTECT" },
1471 { A_INVIS, "INVISIBLE" },
1474 { A_ITALIC, "ITALIC" },
1476 { A_NORMAL, "NORMAL" },
1481 init_attr_list(ATTR_TBL * target, attr_t attrs)
1483 unsigned result = 0;
1486 for (n = 0; n < SIZEOF(attrs_to_test); ++n) {
1487 attr_t test = attrs_to_test[n].attr;
1488 if (test == A_NORMAL || (test & attrs) != 0) {
1489 target[result++] = attrs_to_test[n];
1496 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc, unsigned limit)
1506 if (ch < 256 && isdigit(ch)) {
1514 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1516 attr_legend(helpwin);
1539 adjust_attr_string(-1);
1542 adjust_attr_string(1);
1548 error = cycle_color_attr(ch, fg, bg, tx);
1558 /* test text attributes */
1561 int skip = get_xmc();
1562 short fg = COLOR_BLACK; /* color pair 0 is special */
1563 short bg = COLOR_BLACK;
1567 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1568 unsigned my_size = init_attr_list(my_list, termattrs());
1574 n = skip; /* make it easy */
1580 chtype normal = A_NORMAL | BLANK;
1581 chtype extras = (chtype) ac;
1584 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1587 if (init_pair(pair, fg, bg) == ERR) {
1590 normal |= (chtype) COLOR_PAIR(pair);
1595 if (init_pair(pair, tx, bg) == ERR) {
1598 extras |= (chtype) COLOR_PAIR(pair);
1607 MvAddStr(0, 20, "Character attribute test display");
1609 for (j = 0; j < my_size; ++j) {
1610 bool arrow = (j == k);
1611 row = show_attr(row, n, arrow,
1619 "This terminal does %shave the magic-cookie glitch",
1620 get_xmc() > -1 ? "" : "not ");
1621 MvPrintw(row + 1, 8, "Enter '?' for help.");
1622 show_color_attr(fg, bg, tx);
1623 printw(" ACS (%d)", ac != 0);
1626 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1628 bkgdset(A_NORMAL | BLANK);
1632 Cannot("does not support video attributes.");
1636 #if USE_WIDEC_SUPPORT
1637 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1640 wide_adjust_attr_string(int adjust)
1642 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1643 int last = first + LEN_ATTRSTRING;
1645 if (first >= ' ' && last <= '~') { /* 32..126 */
1647 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1648 wide_attr_test_string[j] = k;
1649 if (((k + 1 - first) % 5) == 0) {
1650 if (++j >= MAX_ATTRSTRING)
1652 wide_attr_test_string[j] = ' ';
1655 while (j < MAX_ATTRSTRING)
1656 wide_attr_test_string[j++] = ' ';
1657 wide_attr_test_string[j] = '\0';
1664 wide_init_attr_string(void)
1666 wide_attr_test_string[0] = 'a';
1667 wide_adjust_attr_string(0);
1671 set_wide_background(short pair)
1678 setcchar(&normal, blank, A_NORMAL, pair, 0);
1684 get_wide_background(void)
1686 attr_t result = A_NORMAL;
1692 memset(&ch, 0, sizeof(ch));
1693 if (getbkgrnd(&ch) != ERR) {
1694 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1702 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1704 int ncv = get_ncv();
1705 chtype test = attr & ~WA_ALTCHARSET;
1708 MvPrintw(row, 5, "-->");
1709 MvPrintw(row, 8, "%s mode:", name);
1710 MvPrintw(row, 24, "|");
1712 printw("%*s", skip, " ");
1715 * Just for testing, write text using the alternate character set one
1716 * character at a time (to pass its rendition directly), and use the
1717 * string operation for the other attributes.
1719 if (attr & WA_ALTCHARSET) {
1723 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1727 setcchar(&ch, fill, attr, pair, 0);
1731 attr_t old_attr = 0;
1734 (void) attr_get(&old_attr, &old_pair, 0);
1735 (void) attr_set(attr, pair, 0);
1736 addwstr(wide_attr_test_string);
1737 (void) attr_set(old_attr, old_pair, 0);
1740 printw("%*s", skip, " ");
1742 if (test != A_NORMAL) {
1743 if (!(term_attrs() & test)) {
1746 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1747 static const attr_t table[] =
1761 for (n = 0; n < SIZEOF(table); n++) {
1762 if ((table[n] & attr) != 0
1763 && ((1 << n) & ncv) != 0) {
1771 if ((term_attrs() & test) != test)
1779 wide_attr_getc(int *skip,
1780 short *fg, short *bg,
1782 unsigned *kc, unsigned limit)
1792 if (ch < 256 && isdigit(ch)) {
1800 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1801 box_set(helpwin, 0, 0);
1802 attr_legend(helpwin);
1825 wide_adjust_attr_string(-1);
1828 wide_adjust_attr_string(1);
1834 error = cycle_color_attr(ch, fg, bg, tx);
1843 wide_attr_test(void)
1844 /* test text attributes using wide-character calls */
1847 int skip = get_xmc();
1848 short fg = COLOR_BLACK; /* color pair 0 is special */
1849 short bg = COLOR_BLACK;
1853 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
1854 unsigned my_size = init_attr_list(my_list, term_attrs());
1860 n = skip; /* make it easy */
1862 wide_init_attr_string();
1870 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1873 if (init_pair(pair, fg, bg) == ERR) {
1880 if (init_pair(extras, tx, bg) == ERR) {
1885 set_wide_background(pair);
1888 box_set(stdscr, 0, 0);
1889 MvAddStr(0, 20, "Character attribute test display");
1891 for (j = 0; j < my_size; ++j) {
1892 row = wide_show_attr(row, n, j == k,
1901 "This terminal does %shave the magic-cookie glitch",
1902 get_xmc() > -1 ? "" : "not ");
1903 MvPrintw(row + 1, 8, "Enter '?' for help.");
1904 show_color_attr(fg, bg, tx);
1905 printw(" ACS (%d)", ac != 0);
1908 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k, my_size));
1910 set_wide_background(0);
1914 Cannot("does not support extended video attributes.");
1919 /****************************************************************************
1921 * Color support tests
1923 ****************************************************************************/
1925 static NCURSES_CONST char *the_color_names[] =
1946 show_color_name(int y, int x, int color, bool wide)
1948 if (move(y, x) != ERR) {
1953 sprintf(temp, "%02d", color);
1955 } else if (color >= 8) {
1956 sprintf(temp, "[%02d]", color);
1957 } else if (color < 0) {
1958 strcpy(temp, "default");
1960 sprintf(temp, "%.*s", 16, the_color_names[color]);
1962 printw("%-*.*s", width, width, temp);
1967 color_legend(WINDOW *helpwin, bool wide)
1972 MvWPrintw(helpwin, row++, col,
1975 MvWPrintw(helpwin, row++, col,
1976 "Use up/down arrow to scroll through the display if it is");
1977 MvWPrintw(helpwin, row++, col,
1978 "longer than one screen. Control/N and Control/P can be used");
1979 MvWPrintw(helpwin, row++, col,
1980 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1981 MvWPrintw(helpwin, row++, col,
1982 "full screen; control/B and control/F can be used here.");
1984 MvWPrintw(helpwin, row++, col,
1986 MvWPrintw(helpwin, row++, col,
1987 " a/A toggle altcharset off/on");
1988 MvWPrintw(helpwin, row++, col,
1989 " b/B toggle bold off/on");
1990 MvWPrintw(helpwin, row++, col,
1991 " n/N toggle text/number on/off");
1992 MvWPrintw(helpwin, row++, col,
1993 " r/R toggle reverse on/off");
1994 MvWPrintw(helpwin, row++, col,
1995 " w/W toggle width between 8/16 colors");
1996 #if USE_WIDEC_SUPPORT
1998 MvWPrintw(helpwin, row++, col,
1999 "Wide characters:");
2000 MvWPrintw(helpwin, row, col,
2001 " x/X toggle text between ASCII and wide-character");
2008 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
2010 /* generate a color test pattern */
2017 int grid_top = top + 3;
2018 int page_size = (LINES - grid_top);
2019 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
2025 bool opt_acsc = FALSE;
2026 bool opt_bold = FALSE;
2027 bool opt_revs = FALSE;
2028 bool opt_nums = FALSE;
2029 bool opt_wide = FALSE;
2032 if (COLORS * COLORS == COLOR_PAIRS) {
2033 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2034 if (pairs_max > limit)
2037 if (pairs_max > COLOR_PAIRS)
2038 pairs_max = COLOR_PAIRS;
2044 /* this assumes an 80-column line */
2048 per_row = (COLORS > 8) ? 16 : 8;
2054 per_row -= min_colors;
2056 row_limit = (pairs_max + per_row - 1) / per_row;
2059 (void) printw("There are %d color pairs and %d colors%s\n",
2061 min_colors ? " besides 'default'" : "");
2064 MvPrintw(top + 1, 0,
2065 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2068 opt_bold ? "on" : "off");
2070 /* show color names/numbers across the top */
2071 for (i = 0; i < per_row; i++)
2072 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2074 /* show a grid of colors, with color names/ numbers on the left */
2075 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
2076 int row = grid_top + (i / per_row) - base_row;
2077 int col = (i % per_row + 1) * width;
2080 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
2081 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
2082 if (row >= 0 && move(row, col) != ERR) {
2083 short fg = InxToFG(i);
2084 short bg = InxToBG(i);
2086 init_pair(pair, fg, bg);
2087 attron((attr_t) COLOR_PAIR(pair));
2089 attron((attr_t) A_ALTCHARSET);
2091 attron((attr_t) A_BOLD);
2093 attron((attr_t) A_REVERSE);
2096 sprintf(numbered, "{%02X}", i);
2099 printw("%-*.*s", width, width, hello);
2100 (void) attrset(A_NORMAL);
2102 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2103 show_color_name(row, 0, InxToBG(i), opt_wide);
2111 switch (wGetchar(stdscr)) {
2140 set_color_test(opt_wide, FALSE);
2143 set_color_test(opt_wide, TRUE);
2147 if (base_row <= 0) {
2155 if (base_row + page_size >= row_limit) {
2164 if (base_row <= 0) {
2167 base_row -= (page_size - 1);
2175 if (base_row + page_size >= row_limit) {
2178 base_row += page_size - 1;
2179 if (base_row + page_size >= row_limit) {
2180 base_row = row_limit - page_size - 1;
2185 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2187 color_legend(helpwin, FALSE);
2202 #if USE_WIDEC_SUPPORT
2203 /* generate a color test pattern */
2205 wide_color_test(void)
2210 int grid_top = top + 3;
2211 int page_size = (LINES - grid_top);
2212 int pairs_max = (unsigned short) (-1);
2218 bool opt_acsc = FALSE;
2219 bool opt_bold = FALSE;
2220 bool opt_revs = FALSE;
2221 bool opt_wide = FALSE;
2222 bool opt_nums = FALSE;
2223 bool opt_xchr = FALSE;
2227 if (COLORS * COLORS == COLOR_PAIRS) {
2228 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2229 if (pairs_max > limit)
2232 if (pairs_max > COLOR_PAIRS)
2233 pairs_max = COLOR_PAIRS;
2239 /* this assumes an 80-column line */
2243 per_row = (COLORS > 8) ? 16 : 8;
2249 per_row -= min_colors;
2252 make_fullwidth_text(buffer, hello);
2256 make_narrow_text(buffer, hello);
2259 row_limit = (pairs_max + per_row - 1) / per_row;
2262 (void) printw("There are %d color pairs and %d colors%s\n",
2264 min_colors ? " besides 'default'" : "");
2267 MvPrintw(top + 1, 0,
2268 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2271 opt_bold ? "on" : "off");
2273 /* show color names/numbers across the top */
2274 for (i = 0; i < per_row; i++)
2275 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2277 /* show a grid of colors, with color names/ numbers on the left */
2278 for (i = (base_row * per_row); i < pairs_max; i++) {
2279 int row = grid_top + (i / per_row) - base_row;
2280 int col = (i % per_row + 1) * width;
2281 short pair = (short) i;
2283 if (row >= 0 && move(row, col) != ERR) {
2284 init_pair(pair, InxToFG(i), InxToBG(i));
2285 (void) color_set(pair, NULL);
2287 attr_on((attr_t) A_ALTCHARSET, NULL);
2289 attr_on((attr_t) A_BOLD, NULL);
2291 attr_on((attr_t) A_REVERSE, NULL);
2294 sprintf(numbered, "{%02X}", i);
2296 make_fullwidth_text(buffer, numbered);
2298 make_narrow_text(buffer, numbered);
2301 addnwstr(buffer, width);
2302 (void) attr_set(A_NORMAL, 0, NULL);
2304 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2305 show_color_name(row, 0, InxToBG(i), opt_wide);
2313 switch (wGetchar(stdscr)) {
2342 set_color_test(opt_wide, FALSE);
2345 set_color_test(opt_wide, TRUE);
2355 if (base_row <= 0) {
2363 if (base_row + page_size >= row_limit) {
2372 if (base_row <= 0) {
2375 base_row -= (page_size - 1);
2383 if (base_row + page_size >= row_limit) {
2386 base_row += page_size - 1;
2387 if (base_row + page_size >= row_limit) {
2388 base_row = row_limit - page_size - 1;
2393 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2395 color_legend(helpwin, TRUE);
2409 #endif /* USE_WIDEC_SUPPORT */
2412 change_color(short current, int field, int value, int usebase)
2414 short red, green, blue;
2416 color_content(current, &red, &green, &blue);
2420 red = (short) (usebase ? (red + value) : value);
2423 green = (short) (usebase ? (green + value) : value);
2426 blue = (short) (usebase ? (blue + value) : value);
2430 if (init_color(current, red, green, blue) == ERR)
2435 init_all_colors(void)
2439 for (c = 0; c < COLORS; ++c)
2442 all_colors[c].green,
2443 all_colors[c].blue);
2446 #define scaled_rgb(n) ((255 * (n)) / 1000)
2450 /* display the color test pattern, without trying to edit colors */
2454 int this_c = 0, value = 0, field = 0;
2457 int page_size = (LINES - 6);
2462 for (i = 0; i < max_colors; i++)
2463 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2465 MvPrintw(LINES - 2, 0, "Number: %d", value);
2468 short red, green, blue;
2471 MvAddStr(0, 20, "Color RGB Value Editing");
2474 for (i = (short) top_color;
2475 (i - top_color < page_size)
2476 && (i < max_colors); i++) {
2479 sprintf(numeric, "[%d]", i);
2480 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2481 (i == current ? '>' : ' '),
2482 (i < (int) SIZEOF(the_color_names)
2483 ? the_color_names[i] : numeric));
2484 (void) attrset((attr_t) COLOR_PAIR(i));
2486 (void) attrset(A_NORMAL);
2488 color_content((short) i, &red, &green, &blue);
2490 if (current == i && field == 0)
2492 printw("%04d", red);
2493 if (current == i && field == 0)
2494 (void) attrset(A_NORMAL);
2496 if (current == i && field == 1)
2498 printw("%04d", green);
2499 if (current == i && field == 1)
2500 (void) attrset(A_NORMAL);
2502 if (current == i && field == 2)
2504 printw("%04d", blue);
2505 if (current == i && field == 2)
2506 (void) attrset(A_NORMAL);
2507 (void) attrset(A_NORMAL);
2508 printw(" ( %3d %3d %3d )",
2514 MvAddStr(LINES - 3, 0,
2515 "Use up/down to select a color, left/right to change fields.");
2516 MvAddStr(LINES - 2, 0,
2517 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2519 move(2 + current - top_color, 0);
2523 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2530 current -= (page_size - 1);
2537 if (current < (max_colors - 1))
2538 current += (page_size - 1);
2545 current = (current == 0 ? (max_colors - 1) : current - 1);
2550 current = (current == (max_colors - 1) ? 0 : current + 1);
2554 field = (field == 2 ? 0 : field + 1);
2558 field = (field == 0 ? 2 : field - 1);
2571 value = value * 10 + (this_c - '0');
2575 change_color((short) current, field, value, 1);
2579 change_color((short) current, field, -value, 1);
2583 change_color((short) current, field, value, 0);
2588 P(" RGB Value Editing Help");
2590 P("You are in the RGB value editor. Use the arrow keys to select one of");
2591 P("the fields in one of the RGB triples of the current colors; the one");
2592 P("currently selected will be reverse-video highlighted.");
2594 P("To change a field, enter the digits of the new value; they are echoed");
2595 P("as entered. Finish by typing `='. The change will take effect instantly.");
2596 P("To increment or decrement a value, use the same procedure, but finish");
2597 P("with a `+' or `-'.");
2599 P("Press 'm' to invoke the top-level menu with the current color settings.");
2600 P("To quit, do ESC");
2609 for (i = 0; i < max_colors; i++)
2610 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2624 if (current >= max_colors)
2625 current = max_colors - 1;
2626 if (current < top_color)
2627 top_color = current;
2628 if (current - top_color >= page_size)
2629 top_color = current - (page_size - 1);
2631 MvPrintw(LINES - 1, 0, "Number: %d", value);
2639 * ncurses does not reset each color individually when calling endwin().
2646 /****************************************************************************
2648 * Alternate character-set stuff
2650 ****************************************************************************/
2652 cycle_attr(int ch, unsigned *at_code, chtype *attr, ATTR_TBL * list, unsigned limit)
2658 if ((*at_code += 1) >= limit)
2663 *at_code = limit - 1;
2672 *attr = list[*at_code].attr;
2677 cycle_colors(int ch, int *fg, int *bg, short *pair)
2679 bool result = FALSE;
2689 if ((*fg += 1) >= COLORS)
2697 if ((*bg += 1) >= COLORS)
2705 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2708 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2717 /****************************************************************************
2719 * Soft-key label test
2721 ****************************************************************************/
2726 #define SLK_WORK (SLK_HELP + 3)
2731 static const char *table[] =
2733 "Available commands are:"
2735 ,"^L -- repaint this message and activate soft keys"
2736 ,"a/d -- activate/disable soft keys"
2737 ,"c -- set centered format for labels"
2738 ,"l -- set left-justified format for labels"
2739 ,"r -- set right-justified format for labels"
2740 ,"[12345678] -- set label; labels are numbered 1 through 8"
2741 ,"e -- erase stdscr (should not erase labels)"
2742 ,"s -- test scrolling of shortened screen"
2743 ,"v/V -- cycle through video attributes"
2745 ,"F/f/B/b -- cycle through foreground/background colors"
2747 ,"ESC -- return to main menu"
2749 ,"Note: if activating the soft keys causes your terminal to scroll up"
2750 ,"one line, your terminal auto-scrolls when anything is written to the"
2751 ,"last screen position. The ncurses code does not yet handle this"
2757 for (j = 0; j < SIZEOF(table); ++j) {
2765 call_slk_color(int fg, int bg)
2767 init_pair(1, (short) bg, (short) fg);
2769 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2779 /* exercise the soft keys */
2784 chtype attr = A_NORMAL;
2785 unsigned at_code = 0;
2787 int fg = COLOR_BLACK;
2788 int bg = COLOR_WHITE;
2791 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
2792 unsigned my_size = init_attr_list(my_list, termattrs());
2797 call_slk_color(fg, bg);
2807 MvAddStr(0, 20, "Soft Key Exerciser");
2822 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2823 while ((c = Getchar()) != 'Q' && (c != ERR))
2851 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2853 if ((s = slk_label(c - '0')) != 0) {
2856 wGetstring(stdscr, buf, 8);
2857 slk_set((c - '0'), buf, fmt);
2866 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2868 wnoutrefresh(stdscr);
2873 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
2880 if (cycle_colors(c, &fg, &bg, &pair)) {
2882 call_slk_color(fg, bg);
2892 } while (!isQuit(c = Getchar()));
2900 #if USE_WIDEC_SUPPORT
2904 /* exercise the soft keys */
2907 wchar_t buf[SLKLEN + 1];
2909 chtype attr = A_NORMAL;
2910 unsigned at_code = 0;
2911 int fg = COLOR_BLACK;
2912 int bg = COLOR_WHITE;
2914 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
2915 unsigned my_size = init_attr_list(my_list, term_attrs());
2919 call_slk_color(fg, bg);
2926 attr_on(WA_BOLD, NULL);
2927 MvAddStr(0, 20, "Soft Key Exerciser");
2928 attr_off(WA_BOLD, NULL);
2942 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2943 while ((c = Getchar()) != 'Q' && (c != ERR))
2971 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2973 if ((s = slk_label(c - '0')) != 0) {
2974 char *temp = strdup(s);
2975 size_t used = strlen(temp);
2976 size_t want = SLKLEN;
2978 #ifndef state_unused
2983 while (want > 0 && used != 0) {
2984 const char *base = s;
2985 reset_mbytes(state);
2986 test = count_mbytes(base, 0, &state);
2987 if (test == (size_t) -1) {
2989 } else if (test > want) {
2992 reset_mbytes(state);
2993 trans_mbytes(buf, base, want, &state);
2999 wGet_wstring(stdscr, buf, SLKLEN);
3000 slk_wset((c - '0'), buf, fmt);
3011 fg = (short) ((fg + 1) % COLORS);
3012 call_slk_color(fg, bg);
3017 bg = (short) ((bg + 1) % COLORS);
3018 call_slk_color(fg, bg);
3021 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
3023 wnoutrefresh(stdscr);
3027 if (cycle_attr(c, &at_code, &attr, my_list, my_size)) {
3028 slk_attr_set(attr, (short) (fg || bg), NULL);
3034 if (cycle_colors(c, &fg, &bg, &pair)) {
3036 call_slk_color(fg, bg);
3046 } while (!isQuit(c = Getchar()));
3054 #endif /* SLK_INIT */
3057 show_256_chars(int repeat, attr_t attr, short pair)
3060 unsigned last = 255;
3066 MvPrintw(0, 20, "Display of Character Codes %#0x to %#0x",
3071 for (code = first; code <= last; ++code) {
3072 int row = (int) (2 + (code / 16));
3073 int col = (int) (5 * (code % 16));
3074 IGNORE_RC(mvaddch(row, col, colored_chtype(code, attr, pair)));
3075 for (count = 1; count < repeat; ++count) {
3076 addch(colored_chtype(code, attr, pair));
3083 * Show a slice of 32 characters, allowing those to be repeated up to the
3086 * ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3087 * terminal to perform functions. The remaining codes can be graphic.
3090 show_upper_chars(int base, int pagesize, int repeat, attr_t attr, short pair)
3093 unsigned first = (unsigned) base;
3094 unsigned last = first + (unsigned) pagesize - 2;
3095 bool C1 = (first == 128);
3100 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3101 C1 ? "C1" : "GR", first, last);
3105 for (code = first; code <= last; code++) {
3107 int row = 2 + ((int) (code - first) % (pagesize / 2));
3108 int col = ((int) (code - first) / (pagesize / 2)) * COLS / 2;
3110 sprintf(tmp, "%3u (0x%x)", code, code);
3111 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3115 nodelay(stdscr, TRUE);
3116 echochar(colored_chtype(code, attr, pair));
3118 /* (yes, this _is_ crude) */
3119 while ((reply = Getchar()) != ERR) {
3120 addch(UChar(reply));
3123 nodelay(stdscr, FALSE);
3125 } while (--count > 0);
3132 show_pc_chars(int repeat, attr_t attr, short pair)
3138 MvPrintw(0, 20, "Display of PC Character Codes");
3142 for (code = 0; code < 16; ++code) {
3143 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3145 for (code = 0; code < 256; code++) {
3147 int row = 3 + (int) (code / 16) + (code >= 128);
3148 int col = 8 + (int) (code % 16) * PC_COLS;
3149 if ((code % 16) == 0)
3150 MvPrintw(row, 0, "0x%02x:", code);
3161 * Skip the ones that do not work.
3165 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3168 } while (--count > 0);
3173 show_box_chars(int repeat, attr_t attr, short pair)
3177 attr |= (attr_t) COLOR_PAIR(pair);
3181 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3186 colored_chtype(ACS_VLINE, attr, pair),
3187 colored_chtype(ACS_VLINE, attr, pair),
3188 colored_chtype(ACS_HLINE, attr, pair),
3189 colored_chtype(ACS_HLINE, attr, pair),
3190 colored_chtype(ACS_ULCORNER, attr, pair),
3191 colored_chtype(ACS_URCORNER, attr, pair),
3192 colored_chtype(ACS_LLCORNER, attr, pair),
3193 colored_chtype(ACS_LRCORNER, attr, pair));
3194 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3195 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3196 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3197 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3198 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3199 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3200 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3206 show_1_acs(int n, int repeat, const char *name, chtype code)
3208 const int height = 16;
3209 int row = 2 + (n % height);
3210 int col = (n / height) * COLS / 2;
3212 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3215 } while (--repeat > 0);
3220 show_acs_chars(int repeat, attr_t attr, short pair)
3221 /* display the ACS character set */
3225 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3229 MvAddStr(0, 20, "Display of the ACS Character Set");
3233 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3234 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3235 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3236 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3238 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3239 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3240 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3241 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3243 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3244 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3247 * HPUX's ACS definitions are broken here. Just give up.
3249 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3250 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3251 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3252 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3253 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3255 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3256 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3257 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3258 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3259 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3260 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3261 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3262 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3263 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3265 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3266 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3267 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3269 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3270 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3271 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3272 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3273 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3274 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3283 char *term = getenv("TERM");
3284 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3287 chtype attr = A_NORMAL;
3290 int fg = COLOR_BLACK;
3291 int bg = COLOR_BLACK;
3292 unsigned at_code = 0;
3294 void (*last_show_acs) (int, attr_t, short) = 0;
3295 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3296 unsigned my_size = init_attr_list(my_list, termattrs());
3304 ToggleAcs(last_show_acs, show_acs_chars);
3308 ToggleAcs(last_show_acs, show_pc_chars);
3313 if (pagesize == 32) {
3320 ToggleAcs(last_show_acs, show_box_chars);
3346 if (repeat < (COLS / 4))
3354 if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3355 || cycle_colors(c, &fg, &bg, &pair)) {
3362 if (pagesize != 32) {
3363 show_256_chars(repeat, attr, pair);
3364 } else if (last_show_acs != 0) {
3365 last_show_acs(repeat, attr, pair);
3367 show_upper_chars(digit * pagesize + 128, pagesize, repeat, attr, pair);
3370 MvPrintw(LINES - 3, 0,
3371 "Note: ANSI terminals may not display C1 characters.");
3372 MvPrintw(LINES - 2, 0,
3373 "Select: a=ACS, w=all x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3376 MvPrintw(LINES - 1, 0,
3377 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3378 my_list[at_code].name,
3381 MvPrintw(LINES - 1, 0,
3382 "v/V cycles through video attributes (%s).",
3383 my_list[at_code].name);
3386 } while (!isQuit(c = Getchar()));
3393 #if USE_WIDEC_SUPPORT
3395 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3401 TEST_CCHAR(src, count, {
3402 attr |= (test_attrs & A_ALTCHARSET);
3403 setcchar(dst, test_wch, attr, pair, NULL);
3413 * Header/legend take up no more than 8 lines, leaving 16 lines on a 24-line
3414 * display. If there are no repeats, we could normally display 16 lines of 64
3415 * characters (1024 total). However, taking repeats and double-width cells
3416 * into account, use 256 characters for the page.
3419 show_paged_widechars(int base,
3426 int first = base * pagesize;
3427 int last = first + pagesize - 1;
3435 MvPrintw(0, 20, "Display of Character Codes %#x to %#x", first, last);
3438 for (code = first; (int) code <= last; code++) {
3439 int row = (2 + ((int) code - first) / per_line);
3440 int col = 5 * ((int) code % per_line);
3443 memset(&codes, 0, sizeof(codes));
3445 setcchar(&temp, codes, attr, pair, 0);
3447 if (wcwidth(code) == 0 && code != 0) {
3448 addch((chtype) space |
3449 (A_REVERSE ^ attr) |
3450 (attr_t) COLOR_PAIR(pair));
3453 for (count = 1; count < repeat; ++count) {
3460 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3464 int last = first + 31;
3468 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3471 for (code = first; (int) code <= last; code++) {
3472 int row = 2 + ((code - first) % 16);
3473 int col = ((code - first) / 16) * COLS / 2;
3479 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3480 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3482 memset(&codes, 0, sizeof(codes));
3484 setcchar(&temp, codes, attr, pair, 0);
3488 * Give non-spacing characters something to combine with. If we
3489 * don't, they'll bunch up in a heap on the space after the ":".
3490 * Mark them with reverse-video to make them simpler to find on
3493 if (wcwidth(code) == 0) {
3494 addch((chtype) space |
3495 (A_REVERSE ^ attr) |
3496 (attr_t) COLOR_PAIR(pair));
3499 * This uses echo_wchar(), for comparison with the normal 'f'
3500 * test (and to make a test-case for echo_wchar()). The screen
3501 * may flicker because the erase() at the top of the function
3502 * is met by the builtin refresh() in echo_wchar().
3506 * The repeat-count may make text wrap - avoid that.
3508 getyx(stdscr, y, x);
3510 if (x >= col + (COLS / 2) - 2)
3512 } while (--count > 0);
3517 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3519 const int height = 16;
3520 int row = 2 + (n % height);
3521 int col = (n / height) * COLS / 2;
3523 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3524 while (--repeat >= 0) {
3530 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3533 show_wacs_chars(int repeat, attr_t attr, short pair)
3534 /* display the wide-ACS character set */
3540 /*#define BOTH2(name) #name, &(name) */
3541 #define BOTH2(name) #name, MERGE_ATTR(name)
3545 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3549 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3550 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3551 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3552 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3554 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3555 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3556 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3557 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3559 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3560 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3562 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3563 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3564 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3565 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3567 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3568 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3569 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3570 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3571 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3572 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3573 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3574 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3575 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3577 #ifdef CURSES_WACS_ARRAY
3578 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3579 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3580 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3582 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3583 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3584 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3585 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3586 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3587 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3593 show_wacs_chars_double(int repeat, attr_t attr, short pair)
3594 /* display the wide-ACS character set */
3600 /*#define BOTH2(name) #name, &(name) */
3601 #define BOTH2(name) #name, MERGE_ATTR(name)
3605 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3609 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3610 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3611 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3612 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3614 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3615 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3616 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3617 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3619 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3620 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3622 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3623 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3624 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3625 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3627 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3628 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3629 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3630 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3631 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3632 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3633 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3634 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3635 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3637 #ifdef CURSES_WACS_ARRAY
3638 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3639 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3640 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3642 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3643 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3644 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3645 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3646 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3647 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3654 show_wacs_chars_thick(int repeat, attr_t attr, short pair)
3655 /* display the wide-ACS character set */
3661 /*#define BOTH2(name) #name, &(name) */
3662 #define BOTH2(name) #name, MERGE_ATTR(name)
3666 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3670 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
3671 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
3672 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
3673 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
3675 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
3676 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
3677 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
3678 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
3680 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
3681 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
3683 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3684 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3685 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3686 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3688 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3689 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3690 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3691 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3692 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3693 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3694 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3695 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3696 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3698 #ifdef CURSES_WACS_ARRAY
3699 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3700 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3701 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3703 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3704 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3705 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3706 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3707 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3708 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3715 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3718 show_wbox_chars(int repeat, attr_t attr, short pair)
3725 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3730 MERGE_ATTR(0, WACS_VLINE),
3731 MERGE_ATTR(1, WACS_VLINE),
3732 MERGE_ATTR(2, WACS_HLINE),
3733 MERGE_ATTR(3, WACS_HLINE),
3734 MERGE_ATTR(4, WACS_ULCORNER),
3735 MERGE_ATTR(5, WACS_URCORNER),
3736 MERGE_ATTR(6, WACS_LLCORNER),
3737 MERGE_ATTR(7, WACS_LRCORNER));
3739 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3740 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3741 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3742 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3743 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3744 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3745 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3753 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3755 const int height = 16;
3756 int row = 2 + (n % height);
3757 int col = (n / height) * COLS / 2;
3760 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3761 (void) attr_set(attr, pair, 0);
3762 addstr(strncpy(temp, code, 20));
3763 (void) attr_set(A_NORMAL, 0, 0);
3767 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3770 show_utf8_chars(int repeat, attr_t attr, short pair)
3777 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3781 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3782 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3783 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3784 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3786 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3787 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3788 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3789 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3791 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3792 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3794 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3795 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3796 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3797 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3799 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3800 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3801 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3802 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3803 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3804 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3805 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3806 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3807 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3808 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3809 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3810 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3812 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3813 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3814 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3815 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3816 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3817 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3822 /* display the wide-ACS character set */
3824 wide_acs_display(void)
3831 chtype attr = A_NORMAL;
3832 int fg = COLOR_BLACK;
3833 int bg = COLOR_BLACK;
3834 unsigned at_code = 0;
3836 void (*last_show_wacs) (int, attr_t, short) = 0;
3837 ATTR_TBL my_list[SIZEOF(attrs_to_test)];
3838 unsigned my_size = init_attr_list(my_list, term_attrs());
3846 ToggleAcs(last_show_wacs, show_wacs_chars);
3850 ToggleAcs(last_show_wacs, show_wacs_chars_double);
3855 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
3859 if (pagesize == 32) {
3866 ToggleAcs(last_show_wacs, show_wbox_chars);
3869 ToggleAcs(last_show_wacs, show_utf8_chars);
3872 if (c < 256 && isdigit(c)) {
3875 } else if (c == '+') {
3878 } else if (c == '-' && digit > 0) {
3881 } else if (c == '>' && repeat < (COLS / 4)) {
3883 } else if (c == '<' && repeat > 1) {
3885 } else if (c == '_') {
3886 space = (space == ' ') ? '_' : ' ';
3888 } else if (cycle_attr(c, &at_code, &attr, my_list, my_size)
3889 || cycle_colors(c, &fg, &bg, &pair)) {
3890 if (last_show_wacs != 0)
3898 if (pagesize != 32) {
3899 show_paged_widechars(digit, pagesize, repeat, space, attr, pair);
3900 } else if (last_show_wacs != 0) {
3901 last_show_wacs(repeat, attr, pair);
3903 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3906 MvPrintw(LINES - 4, 0,
3907 "Select: a/d/t WACS, w=all x=box, u UTF-8, ^L repaint");
3908 MvPrintw(LINES - 3, 2,
3909 "0-9,+/- non-ASCII, </> repeat, _ space, ESC=quit");
3911 MvPrintw(LINES - 2, 2,
3912 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3913 my_list[at_code].name,
3916 MvPrintw(LINES - 2, 2,
3917 "v/V cycles through video attributes (%s).",
3918 my_list[at_code].name);
3921 } while (!isQuit(c = Getchar()));
3931 * Graphic-rendition test (adapted from vttest)
3934 test_sgr_attributes(void)
3938 for (pass = 0; pass < 2; pass++) {
3939 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3941 /* Use non-default colors if possible to exercise bce a little */
3943 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3944 normal |= (chtype) COLOR_PAIR(1);
3948 MvPrintw(1, 20, "Graphic rendition test pattern:");
3950 MvPrintw(4, 1, "vanilla");
3952 #define set_sgr(mask) bkgdset((normal^(mask)));
3954 MvPrintw(4, 40, "bold");
3956 set_sgr(A_UNDERLINE);
3957 MvPrintw(6, 6, "underline");
3959 set_sgr(A_BOLD | A_UNDERLINE);
3960 MvPrintw(6, 45, "bold underline");
3963 MvPrintw(8, 1, "blink");
3965 set_sgr(A_BLINK | A_BOLD);
3966 MvPrintw(8, 40, "bold blink");
3968 set_sgr(A_UNDERLINE | A_BLINK);
3969 MvPrintw(10, 6, "underline blink");
3971 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3972 MvPrintw(10, 45, "bold underline blink");
3975 MvPrintw(12, 1, "negative");
3977 set_sgr(A_BOLD | A_REVERSE);
3978 MvPrintw(12, 40, "bold negative");
3980 set_sgr(A_UNDERLINE | A_REVERSE);
3981 MvPrintw(14, 6, "underline negative");
3983 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3984 MvPrintw(14, 45, "bold underline negative");
3986 set_sgr(A_BLINK | A_REVERSE);
3987 MvPrintw(16, 1, "blink negative");
3989 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3990 MvPrintw(16, 40, "bold blink negative");
3992 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3993 MvPrintw(18, 6, "underline blink negative");
3995 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3996 MvPrintw(18, 45, "bold underline blink negative");
3999 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
4005 bkgdset(A_NORMAL | BLANK);
4010 /****************************************************************************
4012 * Windows and scrolling tester.
4014 ****************************************************************************/
4016 #define BOTLINES 4 /* number of line stolen from screen bottom */
4022 #define FRAME struct frame
4031 #if defined(NCURSES_VERSION)
4032 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
4033 #define is_keypad(win) (win)->_use_keypad
4034 #define is_scrollok(win) (win)->_scroll
4035 #elif !defined(is_keypad)
4036 #define is_keypad(win) FALSE
4037 #define is_scrollok(win) FALSE
4040 #define is_keypad(win) FALSE
4041 #define is_scrollok(win) FALSE
4045 frame_win(FRAME * curp)
4047 return (curp != 0) ? curp->wind : stdscr;
4050 /* We need to know if these flags are actually set, so don't look in FRAME.
4051 * These names are known to work with SVr4 curses as well as ncurses. The
4052 * _use_keypad name does not work with Solaris 8.
4055 HaveKeypad(FRAME * curp)
4057 WINDOW *win = frame_win(curp);
4059 return is_keypad(win);
4063 HaveScroll(FRAME * curp)
4065 WINDOW *win = frame_win(curp);
4067 return is_scrollok(win);
4071 newwin_legend(FRAME * curp)
4073 static const struct {
4078 "^C = create window", 0
4081 "^N = next window", 0
4084 "^P = previous window", 0
4087 "^F = scroll forward", 0
4090 "^B = scroll backward", 0
4093 "^K = keypad(%s)", 1
4096 "^S = scrollok(%s)", 2
4099 "^W = save window to file", 0
4102 "^R = restore window", 0
4115 bool do_keypad = HaveKeypad(curp);
4116 bool do_scroll = HaveScroll(curp);
4120 for (n = 0; n < SIZEOF(legend); n++) {
4121 switch (legend[n].code) {
4123 strcpy(buf, legend[n].msg);
4126 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
4129 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
4132 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
4135 x = getcurx(stdscr);
4136 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
4143 transient(FRAME * curp, NCURSES_CONST char *msg)
4145 newwin_legend(curp);
4147 MvAddStr(LINES - 1, 0, msg);
4153 printw("%s characters are echoed, window should %sscroll.",
4154 HaveKeypad(curp) ? "Non-arrow" : "All other",
4155 HaveScroll(curp) ? "" : "not ");
4160 newwin_report(FRAME * curp)
4161 /* report on the cursor's current position, then restore it */
4163 WINDOW *win = frame_win(curp);
4167 transient(curp, (char *) 0);
4169 move(LINES - 1, COLS - 17);
4170 printw("Y = %2d X = %2d", y, x);
4178 selectcell(int uli, int ulj, int lri, int lrj)
4179 /* arrows keys move cursor, return location at current on non-arrow key */
4181 static pair res; /* result cell */
4182 int si = lri - uli + 1; /* depth of the select area */
4183 int sj = lrj - ulj + 1; /* width of the select area */
4184 int i = 0, j = 0; /* offsets into the select area */
4189 move(uli + i, ulj + j);
4190 newwin_report((FRAME *) 0);
4192 switch (Getchar()) {
4206 return ((pair *) 0);
4207 #ifdef NCURSES_MOUSE_VERSION
4213 if (event.y > uli && event.x > ulj) {
4234 outerbox(pair ul, pair lr, bool onoff)
4235 /* draw or erase a box *outside* the given pair of corners */
4237 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4238 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4239 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4240 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4241 move(ul.y - 1, ul.x);
4242 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4243 move(ul.y, ul.x - 1);
4244 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4245 move(lr.y + 1, ul.x);
4246 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4247 move(ul.y, lr.x + 1);
4248 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4253 /* Ask user for a window definition */
4260 addstr("Use arrows to move cursor, anything else to mark corner 1");
4262 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4263 return ((WINDOW *) 0);
4264 memcpy(&ul, tmp, sizeof(pair));
4265 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4268 addstr("Use arrows to move cursor, anything else to mark corner 2");
4270 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4272 return ((WINDOW *) 0);
4273 memcpy(&lr, tmp, sizeof(pair));
4275 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4277 outerbox(ul, lr, TRUE);
4289 newwin_move(FRAME * curp, int dy, int dx)
4291 WINDOW *win = frame_win(curp);
4295 getyx(win, cur_y, cur_x);
4296 getmaxyx(win, max_y, max_x);
4297 if ((cur_x += dx) < 0)
4299 else if (cur_x >= max_x)
4301 if ((cur_y += dy) < 0)
4303 else if (cur_y >= max_y)
4305 wmove(win, cur_y, cur_x);
4309 delete_framed(FRAME * fp, bool showit)
4314 fp->last->next = fp->next;
4315 fp->next->last = fp->last;
4323 np = (fp == fp->next) ? 0 : fp->next;
4330 acs_and_scroll(void)
4331 /* Demonstrate windows */
4334 FRAME *current = (FRAME *) 0, *neww;
4336 #if HAVE_PUTWIN && HAVE_GETWIN
4340 #define DUMPFILE "screendump"
4342 #ifdef NCURSES_MOUSE_VERSION
4343 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4348 transient((FRAME *) 0, (char *) 0);
4351 if ((neww = typeCalloc(FRAME, 1)) == 0) {
4352 failed("acs_and_scroll");
4355 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4356 failed("acs_and_scroll");
4361 if (current == 0) { /* First element, */
4362 neww->next = neww; /* so point it at itself */
4365 neww->next = current->next;
4366 neww->last = current;
4367 neww->last->next = neww;
4368 neww->next->last = neww;
4371 /* SVr4 curses sets the keypad on all newly-created windows to
4372 * false. Someone reported that PDCurses makes new windows inherit
4373 * this flag. Remove the following 'keypad()' call to test this
4375 keypad(current->wind, TRUE);
4376 current->do_keypad = HaveKeypad(current);
4377 current->do_scroll = HaveScroll(current);
4380 case CTRL('N'): /* go to next window */
4382 current = current->next;
4385 case CTRL('P'): /* go to previous window */
4387 current = current->last;
4390 case CTRL('F'): /* scroll current window forward */
4392 wscrl(frame_win(current), 1);
4395 case CTRL('B'): /* scroll current window backwards */
4397 wscrl(frame_win(current), -1);
4400 case CTRL('K'): /* toggle keypad mode for current */
4402 current->do_keypad = !current->do_keypad;
4403 keypad(current->wind, current->do_keypad);
4409 current->do_scroll = !current->do_scroll;
4410 scrollok(current->wind, current->do_scroll);
4414 #if HAVE_PUTWIN && HAVE_GETWIN
4415 case CTRL('W'): /* save and delete window */
4416 if ((current != 0) && (current == current->next)) {
4417 transient(current, "Will not save/delete ONLY window");
4419 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4420 transient(current, "Can't open screen dump file");
4422 (void) putwin(frame_win(current), fp);
4425 current = delete_framed(current, TRUE);
4429 case CTRL('R'): /* restore window */
4430 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4431 transient(current, "Can't open screen dump file");
4433 if ((neww = typeCalloc(FRAME, 1)) != 0) {
4435 neww->next = current ? current->next : 0;
4436 neww->last = current;
4437 if (neww->last != 0)
4438 neww->last->next = neww;
4439 if (neww->next != 0)
4440 neww->next->last = neww;
4442 neww->wind = getwin(fp);
4444 wrefresh(neww->wind);
4446 failed("acs_and_scroll");
4454 case CTRL('X'): /* resize window */
4461 addstr("Use arrows to move cursor, anything else to mark new corner");
4464 getbegyx(current->wind, ul.y, ul.x);
4466 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4467 if (tmp == (pair *) 0) {
4472 getmaxyx(current->wind, lr.y, lr.x);
4475 outerbox(ul, lr, FALSE);
4476 wnoutrefresh(stdscr);
4478 /* strictly cosmetic hack for the test */
4479 getmaxyx(current->wind, my, mx);
4480 if (my > tmp->y - ul.y) {
4481 getyx(current->wind, lr.y, lr.x);
4482 wmove(current->wind, tmp->y - ul.y + 1, 0);
4483 wclrtobot(current->wind);
4484 wmove(current->wind, lr.y, lr.x);
4486 if (mx > tmp->x - ul.x)
4487 for (i = 0; i < my; i++) {
4488 wmove(current->wind, i, tmp->x - ul.x + 1);
4489 wclrtoeol(current->wind);
4491 wnoutrefresh(current->wind);
4493 memcpy(&lr, tmp, sizeof(pair));
4494 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4496 getbegyx(current->wind, ul.y, ul.x);
4497 getmaxyx(current->wind, lr.y, lr.x);
4500 outerbox(ul, lr, TRUE);
4501 wnoutrefresh(stdscr);
4503 wnoutrefresh(current->wind);
4509 #endif /* HAVE_WRESIZE */
4511 case KEY_F(10): /* undocumented --- use this to test area clears */
4512 selectcell(0, 0, LINES - 1, COLS - 1);
4518 newwin_move(current, -1, 0);
4521 newwin_move(current, 1, 0);
4524 newwin_move(current, 0, -1);
4527 newwin_move(current, 0, 1);
4535 getyx(frame_win(current), y, x);
4539 x = getmaxx(frame_win(current)) - 1;
4541 (void) mvwdelch(frame_win(current), y, x);
4551 waddch(current->wind, (chtype) c);
4556 newwin_report(current);
4557 usescr = frame_win(current);
4560 (!isQuit(c = wGetchar(usescr))
4564 while (current != 0)
4565 current = delete_framed(current, FALSE);
4567 scrollok(stdscr, TRUE); /* reset to driver's default */
4568 #ifdef NCURSES_MOUSE_VERSION
4569 mousemask(0, (mmask_t *) 0);
4576 /****************************************************************************
4580 ****************************************************************************/
4583 static int nap_msec = 1;
4585 static NCURSES_CONST char *mod[] =
4595 /*+-------------------------------------------------------------------------
4597 --------------------------------------------------------------------------*/
4599 wait_a_while(int msec GCC_UNUSED)
4609 else if (msec > 1000)
4610 sleep((unsigned) msec / 1000);
4614 } /* end of wait_a_while */
4616 /*+-------------------------------------------------------------------------
4618 --------------------------------------------------------------------------*/
4620 saywhat(NCURSES_CONST char *text)
4622 wmove(stdscr, LINES - 1, 0);
4624 if (text != 0 && *text != '\0') {
4625 waddstr(stdscr, text);
4626 waddstr(stdscr, "; ");
4628 waddstr(stdscr, "press any key to continue");
4629 } /* end of saywhat */
4631 /*+-------------------------------------------------------------------------
4632 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4633 --------------------------------------------------------------------------*/
4635 mkpanel(short color, int rows, int cols, int tly, int tlx)
4640 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4641 if ((pan = new_panel(win)) == 0) {
4643 } else if (use_colors) {
4644 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4647 init_pair(color, fg, bg);
4648 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
4650 wbkgdset(win, A_BOLD | ' ');
4654 } /* end of mkpanel */
4656 /*+-------------------------------------------------------------------------
4658 --------------------------------------------------------------------------*/
4660 rmpanel(PANEL * pan)
4662 WINDOW *win = panel_window(pan);
4665 } /* end of rmpanel */
4667 /*+-------------------------------------------------------------------------
4669 --------------------------------------------------------------------------*/
4675 } /* end of pflush */
4677 /*+-------------------------------------------------------------------------
4679 --------------------------------------------------------------------------*/
4685 for (y = 0; y < LINES - 1; y++) {
4686 for (x = 0; x < COLS; x++)
4687 wprintw(stdscr, "%d", (y + x) % 10);
4692 fill_panel(PANEL * pan)
4694 WINDOW *win = panel_window(pan);
4695 const char *userptr = (const char *) panel_userptr(pan);
4696 int num = (userptr && *userptr) ? userptr[1] : '?';
4700 wprintw(win, "-pan%c-", num);
4703 for (y = 2; y < getmaxy(win) - 1; y++) {
4704 for (x = 1; x < getmaxx(win) - 1; x++) {
4706 waddch(win, UChar(num));
4711 #if USE_WIDEC_SUPPORT
4713 init_wide_panel(void)
4718 for (digit = 0; digit < 10; ++digit)
4719 make_fullwidth_digit(&temp[digit], digit);
4723 getyx(stdscr, y, x);
4724 digit = (y + x / 2) % 10;
4725 } while (add_wch(&temp[digit]) != ERR);
4729 fill_wide_panel(PANEL * pan)
4731 WINDOW *win = panel_window(pan);
4732 const char *userptr = (const char *) panel_userptr(pan);
4733 int num = (userptr && *userptr) ? userptr[1] : '?';
4737 wprintw(win, "-pan%c-", num);
4740 for (y = 2; y < getmaxy(win) - 1; y++) {
4741 for (x = 1; x < getmaxx(win) - 1; x++) {
4743 waddch(win, UChar(num));
4749 #define MAX_PANELS 5
4752 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4754 int which = cmd[1] - '0';
4759 hide_panel(px[which]);
4762 show_panel(px[which]);
4765 top_panel(px[which]);
4768 bottom_panel(px[which]);
4775 wait_a_while(nap_msec);
4779 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4783 PANEL *px[MAX_PANELS + 1];
4785 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4789 for (count = 0; count < 5; count++) {
4790 px[1] = mkpanel(COLOR_RED,
4795 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4797 px[2] = mkpanel(COLOR_GREEN,
4802 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4804 px[3] = mkpanel(COLOR_YELLOW,
4809 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4811 px[4] = mkpanel(COLOR_BLUE,
4816 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4818 px[5] = mkpanel(COLOR_MAGENTA,
4823 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4835 wait_a_while(nap_msec);
4837 saywhat("h3 s1 s2 s4 s5");
4838 move_panel(px[1], 0, 0);
4845 wait_a_while(nap_msec);
4847 canned_panel(px, "s1");
4848 canned_panel(px, "s2");
4851 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4853 wait_a_while(nap_msec);
4855 canned_panel(px, "s3");
4858 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4860 wait_a_while(nap_msec);
4862 canned_panel(px, "b3");
4863 canned_panel(px, "s4");
4864 canned_panel(px, "s5");
4865 canned_panel(px, "t3");
4866 canned_panel(px, "t1");
4867 canned_panel(px, "t2");
4868 canned_panel(px, "t3");
4869 canned_panel(px, "t4");
4871 for (itmp = 0; itmp < 6; itmp++) {
4872 WINDOW *w4 = panel_window(px[4]);
4873 WINDOW *w5 = panel_window(px[5]);
4876 wmove(w4, LINES / 8, 1);
4877 waddstr(w4, mod[itmp]);
4878 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4879 wmove(w5, LINES / 6, 1);
4880 waddstr(w5, mod[itmp]);
4882 wait_a_while(nap_msec);
4885 wmove(w4, LINES / 6, 1);
4886 waddstr(w4, mod[itmp]);
4887 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4888 wmove(w5, LINES / 8, 1);
4889 waddstr(w5, mod[itmp]);
4891 wait_a_while(nap_msec);
4895 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4897 wait_a_while(nap_msec);
4899 canned_panel(px, "t5");
4900 canned_panel(px, "t2");
4901 canned_panel(px, "t1");
4902 canned_panel(px, "d2");
4903 canned_panel(px, "h3");
4904 canned_panel(px, "d1");
4905 canned_panel(px, "d4");
4906 canned_panel(px, "d5");
4907 canned_panel(px, "d3");
4909 wait_a_while(nap_msec);
4918 #endif /* USE_LIBPANEL */
4920 /****************************************************************************
4924 ****************************************************************************/
4928 static bool pending_pan = FALSE;
4929 static bool show_panner_legend = TRUE;
4932 panner_legend(int line)
4934 static const char *const legend[] =
4936 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4937 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4938 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4939 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4941 int n = ((int) SIZEOF(legend) - (LINES - line));
4943 if (move(line, 0) != ERR) {
4944 if (show_panner_legend)
4945 printw("%s", legend[n]);
4947 return show_panner_legend;
4954 panner_h_cleanup(int from_y, int from_x, int to_x)
4956 if (!panner_legend(from_y))
4957 do_h_line(from_y, from_x, ' ', to_x);
4961 panner_v_cleanup(int from_y, int from_x, int to_y)
4963 if (!panner_legend(from_y))
4964 do_v_line(from_y, from_x, ' ', to_y);
4968 fill_pad(WINDOW *panpad, bool pan_lines)
4971 unsigned gridcount = 0;
4973 wmove(panpad, 0, 0);
4974 for (y = 0; y < getmaxy(panpad); y++) {
4975 for (x = 0; x < getmaxx(panpad); x++) {
4976 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4977 if (y == 0 && x == 0)
4978 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4980 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4981 else if (y == 0 || x == 0)
4982 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4984 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4985 (int) (gridcount++ % 26)));
4986 } else if (y % GRIDSIZE == 0)
4987 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4988 else if (x % GRIDSIZE == 0)
4989 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4991 waddch(panpad, ' ');
4998 int top_x, int top_y, int porty, int portx,
4999 int (*pgetc) (WINDOW *))
5001 #if HAVE_GETTIMEOFDAY
5002 struct timeval before, after;
5005 bool pan_lines = FALSE;
5006 bool scrollers = TRUE;
5009 int pxmax, pymax, lowend, highend, c;
5011 getmaxyx(pad, pymax, pxmax);
5012 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
5016 #ifdef NCURSES_VERSION
5018 * During shell-out, the user may have resized the window. Adjust
5019 * the port size of the pad to accommodate this. Ncurses automatically
5020 * resizes all of the normal windows to fit on the new screen.
5038 show_panner_legend = !show_panner_legend;
5039 panner_legend(LINES - 4);
5040 panner_legend(LINES - 3);
5041 panner_legend(LINES - 2);
5042 panner_legend(LINES - 1);
5045 pan_lines = !pan_lines;
5046 fill_pad(pad, pan_lines);
5047 pending_pan = FALSE;
5050 #if HAVE_GETTIMEOFDAY
5054 panner_legend(LINES - 1);
5058 scrollers = !scrollers;
5061 /* Move the top-left corner of the pad, keeping the bottom-right
5064 case 'h': /* increase-columns: move left edge to left */
5068 panner_v_cleanup(top_y, top_x, porty);
5073 case 'j': /* decrease-lines: move top-edge down */
5077 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
5082 case 'k': /* increase-lines: move top-edge up */
5087 panner_h_cleanup(top_y, top_x, portx);
5091 case 'l': /* decrease-columns: move left-edge to right */
5095 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
5100 /* Move the bottom-right corner of the pad, keeping the top-left
5103 case KEY_IC: /* increase-columns: move right-edge to right */
5104 if (portx >= pxmax || portx >= COLS)
5107 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
5112 case KEY_IL: /* increase-lines: move bottom-edge down */
5113 if (porty >= pymax || porty >= LINES)
5116 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
5121 case KEY_DC: /* decrease-columns: move bottom edge up */
5126 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
5130 case KEY_DL: /* decrease-lines */
5135 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
5139 case KEY_LEFT: /* pan leftwards */
5146 case KEY_RIGHT: /* pan rightwards */
5147 if (basex + portx - (pymax > porty) < pxmax)
5153 case KEY_UP: /* pan upwards */
5160 case KEY_DOWN: /* pan downwards */
5161 if (basey + porty - (pxmax > portx) < pymax)
5176 basey = pymax - porty;
5186 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5187 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5188 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5190 if (scrollers && (pxmax > portx - 1)) {
5191 int length = (portx - top_x - 1);
5192 float ratio = ((float) length) / ((float) pxmax);
5194 lowend = (int) ((float) top_x + ((float) basex * ratio));
5195 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5197 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5198 if (highend < portx) {
5200 do_h_line(porty - 1, lowend, ' ', highend + 1);
5202 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5205 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5207 if (scrollers && (pymax > porty - 1)) {
5208 int length = (porty - top_y - 1);
5209 float ratio = ((float) length) / ((float) pymax);
5211 lowend = (int) ((float) top_y + ((float) basey * ratio));
5212 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5214 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5215 if (highend < porty) {
5217 do_v_line(lowend, portx - 1, ' ', highend + 1);
5219 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5222 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5224 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5225 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5226 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5229 #if HAVE_GETTIMEOFDAY
5230 gettimeofday(&before, 0);
5232 wnoutrefresh(stdscr);
5237 porty - (pxmax > portx) - 1,
5238 portx - (pymax > porty) - 1);
5241 #if HAVE_GETTIMEOFDAY
5242 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5245 gettimeofday(&after, 0);
5246 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5247 move(LINES - 1, COLS - 12);
5248 printw("Secs: %2.03f", elapsed);
5255 ((c = pgetc(pad)) != KEY_EXIT);
5257 scrollok(stdscr, TRUE); /* reset to driver's default */
5261 padgetch(WINDOW *win)
5267 if ((pending_pan = (count > 0)) != FALSE) {
5269 pending_pan = (count != 0);
5272 switch (c = wGetchar(win)) {
5308 case ERR: /* FALLTHRU */
5314 if (c >= '0' && c <= '9') {
5315 count = count * 10 + (c - '0');
5329 #define PAD_HIGH 200
5330 #define PAD_WIDE 200
5334 /* Demonstrate pads. */
5336 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5339 Cannot("cannot create requested pad");
5343 fill_pad(panpad, FALSE);
5345 panner_legend(LINES - 4);
5346 panner_legend(LINES - 3);
5347 panner_legend(LINES - 2);
5348 panner_legend(LINES - 1);
5350 keypad(panpad, TRUE);
5352 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5353 * We'll still be able to widen it during a test, since that's required
5354 * for testing boundaries.
5356 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
5363 /****************************************************************************
5365 * Tests from John Burnell's PDCurses tester
5367 ****************************************************************************/
5370 Continue(WINDOW *win)
5374 MvWAddStr(win, 10, 1, " Press any key to continue");
5380 flushinp_test(WINDOW *win)
5381 /* Input test, adapted from John Burnell's PDCurses tester */
5383 int w, h, bx, by, sw, sh, i;
5388 getmaxyx(win, h, w);
5389 getbegyx(win, by, bx);
5392 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5397 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5398 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
5401 (void) wattrset(subWin, A_BOLD);
5402 box(subWin, ACS_VLINE, ACS_HLINE);
5403 MvWAddStr(subWin, 2, 1, "This is a subwindow");
5407 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5408 * it only happened to "work" on SVr4 because that implementation does not
5409 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5410 * test behavior, we're using 'cbreak()', which will allow a single
5411 * character to return without needing a newline. - T.Dickey 1997/10/11.
5414 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
5416 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
5417 MvWAddStr(win, 3, 1,
5418 "These should be discarded (not echoed) after the subwindow goes away.");
5421 for (i = 0; i < 5; i++) {
5422 MvWPrintw(subWin, 1, 1, "Time = %d", i);
5434 MvWAddStr(win, 2, 1,
5435 "If you were still typing when the window timer expired,");
5436 MvWAddStr(win, 3, 1,
5437 "or else you typed nothing at all while it was running,");
5438 MvWAddStr(win, 4, 1,
5439 "test was invalid. You'll see garbage or nothing at all. ");
5440 MvWAddStr(win, 6, 1, "Press a key");
5446 MvWAddStr(win, 12, 0,
5447 "If you see any key other than what you typed, flushinp() is broken.");
5456 "What you typed should now have been deleted; if not, wdelch() failed.");
5462 /****************************************************************************
5466 ****************************************************************************/
5474 menu_virtualize(int c)
5476 if (c == '\n' || c == KEY_EXIT)
5477 return (MAX_COMMAND + 1);
5479 return (REQ_SCR_ULINE);
5481 return (REQ_SCR_DLINE);
5482 else if (c == 'b' || c == KEY_NPAGE)
5483 return (REQ_SCR_UPAGE);
5484 else if (c == 'f' || c == KEY_PPAGE)
5485 return (REQ_SCR_DPAGE);
5486 else if (c == 'n' || c == KEY_DOWN)
5487 return (REQ_NEXT_ITEM);
5488 else if (c == 'p' || c == KEY_UP)
5489 return (REQ_PREV_ITEM);
5491 return (REQ_TOGGLE_ITEM);
5499 static CONST_MENUS char *animals[] =
5512 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5513 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5521 ITEM *items[SIZEOF(animals)];
5523 CONST_MENUS char **ap;
5524 int mrows, mcols, c;
5527 #ifdef NCURSES_MOUSE_VERSION
5528 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5530 MvAddStr(0, 0, "This is the menu test:");
5531 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
5532 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
5534 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
5535 MvAddStr(5, 0, " Press return to exit.");
5538 for (ap = animals; *ap; ap++) {
5539 if ((*ip = new_item(*ap, "")) != 0)
5544 m = new_menu(items);
5546 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
5547 scale_menu(m, &mrows, &mcols);
5549 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5550 set_menu_win(m, menuwin);
5551 keypad(menuwin, TRUE);
5554 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5558 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
5559 if (c == E_NOT_POSTED)
5561 if (c == E_REQUEST_DENIED)
5566 MvPrintw(LINES - 2, 0,
5567 "You chose: %s\n", item_name(current_item(m)));
5568 (void) addstr("Press any key to continue...");
5575 for (ip = items; *ip; ip++)
5577 #ifdef NCURSES_MOUSE_VERSION
5578 mousemask(0, (mmask_t *) 0);
5583 #define T_TBL(name) { #name, name }
5589 T_TBL(TRACE_DISABLE),
5592 T_TBL(TRACE_UPDATE),
5594 T_TBL(TRACE_CHARPUT),
5595 T_TBL(TRACE_ORDINARY),
5597 T_TBL(TRACE_VIRTPUT),
5598 T_TBL(TRACE_IEVENT),
5600 T_TBL(TRACE_ICALLS),
5601 T_TBL(TRACE_CCALLS),
5602 T_TBL(TRACE_DATABASE),
5604 T_TBL(TRACE_MAXIMUM),
5611 tracetrace(unsigned tlevel)
5618 for (n = 0; t_tbl[n].name != 0; n++)
5619 need += strlen(t_tbl[n].name) + 2;
5620 buf = typeMalloc(char, need);
5622 failed("tracetrace");
5624 sprintf(buf, "0x%02x = {", tlevel);
5626 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5628 for (n = 1; t_tbl[n].name != 0; n++)
5629 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5630 strcat(buf, t_tbl[n].name);
5634 if (buf[strlen(buf) - 2] == ',')
5635 buf[strlen(buf) - 2] = '\0';
5636 return (strcat(buf, "}"));
5639 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5643 run_trace_menu(MENU * m)
5649 bool changed = FALSE;
5650 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5651 case E_UNKNOWN_COMMAND:
5654 items = menu_items(m);
5655 i = current_item(m);
5656 if (i == items[0]) {
5657 if (item_value(i)) {
5658 for (p = items + 1; *p != 0; p++)
5659 if (item_value(*p)) {
5660 set_item_value(*p, FALSE);
5665 for (p = items + 1; *p != 0; p++)
5666 if (item_value(*p)) {
5667 set_item_value(items[0], FALSE);
5680 /* interactively set the trace level */
5683 ITEM *items[SIZEOF(t_tbl)];
5690 MvAddStr(0, 0, "Interactively set trace level:");
5691 MvAddStr(2, 0, " Press space bar to toggle a selection.");
5692 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
5693 MvAddStr(4, 0, " Press return to set the trace level.");
5694 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5698 for (n = 0; t_tbl[n].name != 0; n++) {
5699 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
5705 m = new_menu(items);
5707 set_menu_format(m, 0, 2);
5708 scale_menu(m, &mrows, &mcols);
5710 menu_opts_off(m, O_ONEVALUE);
5711 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5712 set_menu_win(m, menuwin);
5713 keypad(menuwin, TRUE);
5716 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5720 for (ip = menu_items(m); *ip; ip++) {
5721 unsigned mask = t_tbl[item_index(*ip)].mask;
5723 set_item_value(*ip, _nc_tracing == 0);
5724 else if ((mask & _nc_tracing) == mask)
5725 set_item_value(*ip, TRUE);
5728 while (run_trace_menu(m))
5732 for (ip = menu_items(m); *ip; ip++)
5733 if (item_value(*ip))
5734 newtrace |= t_tbl[item_index(*ip)].mask;
5736 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5738 MvPrintw(LINES - 2, 0,
5739 "Trace level is %s\n", tracetrace(_nc_tracing));
5740 (void) addstr("Press any key to continue...");
5747 for (ip = items; *ip; ip++)
5751 #endif /* USE_LIBMENU */
5753 /****************************************************************************
5757 ****************************************************************************/
5760 make_label(int frow, int fcol, NCURSES_CONST char *label)
5762 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5765 set_field_buffer(f, 0, label);
5766 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
5772 make_field(int frow, int fcol, int rows, int cols, bool secure)
5774 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5777 set_field_back(f, A_UNDERLINE);
5778 set_field_userptr(f, (void *) 0);
5784 display_form(FORM * f)
5789 scale_form(f, &rows, &cols);
5791 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5793 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5796 if (post_form(f) != E_OK)
5802 erase_form(FORM * f)
5804 WINDOW *w = form_win(f);
5805 WINDOW *s = form_sub(f);
5815 edit_secure(FIELD * me, int c)
5817 int rows, cols, frow, fcol, nrow, nbuf;
5819 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5821 char *source = field_buffer(me, 1);
5822 size_t have = (source ? strlen(source) : 0) + 1;
5823 size_t need = 80 + have;
5824 char *temp = malloc(need);
5828 strncpy(temp, source ? source : "", have + 1);
5829 len = (long) (char *) field_userptr(me);
5831 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5832 temp[len++] = (char) c;
5834 set_field_buffer(me, 1, temp);
5854 case REQ_RIGHT_CHAR:
5856 c = 0; /* we don't want to do inline editing */
5861 set_field_buffer(me, 1, temp);
5868 set_field_buffer(me, 1, temp);
5873 set_field_userptr(me, (void *) len);
5881 form_virtualize(FORM * f, WINDOW *w)
5884 static const struct {
5888 { CTRL('A'), REQ_NEXT_CHOICE },
5889 { CTRL('B'), REQ_PREV_WORD },
5890 { CTRL('C'), REQ_CLR_EOL },
5891 { CTRL('D'), REQ_DOWN_FIELD },
5892 { CTRL('E'), REQ_END_FIELD },
5893 { CTRL('F'), REQ_NEXT_PAGE },
5894 { CTRL('G'), REQ_DEL_WORD },
5895 { CTRL('H'), REQ_DEL_PREV },
5896 { CTRL('I'), REQ_INS_CHAR },
5897 { CTRL('K'), REQ_CLR_EOF },
5898 { CTRL('L'), REQ_LEFT_FIELD },
5899 { CTRL('M'), REQ_NEW_LINE },
5900 { CTRL('N'), REQ_NEXT_FIELD },
5901 { CTRL('O'), REQ_INS_LINE },
5902 { CTRL('P'), REQ_PREV_FIELD },
5903 { CTRL('R'), REQ_RIGHT_FIELD },
5904 { CTRL('S'), REQ_BEG_FIELD },
5905 { CTRL('U'), REQ_UP_FIELD },
5906 { CTRL('V'), REQ_DEL_CHAR },
5907 { CTRL('W'), REQ_NEXT_WORD },
5908 { CTRL('X'), REQ_CLR_FIELD },
5909 { CTRL('Y'), REQ_DEL_LINE },
5910 { CTRL('Z'), REQ_PREV_CHOICE },
5911 { ESCAPE, MAX_FORM_COMMAND + 1 },
5912 { KEY_BACKSPACE, REQ_DEL_PREV },
5913 { KEY_DOWN, REQ_DOWN_CHAR },
5914 { KEY_END, REQ_LAST_FIELD },
5915 { KEY_HOME, REQ_FIRST_FIELD },
5916 { KEY_LEFT, REQ_LEFT_CHAR },
5917 { KEY_LL, REQ_LAST_FIELD },
5918 { KEY_NEXT, REQ_NEXT_FIELD },
5919 { KEY_NPAGE, REQ_NEXT_PAGE },
5920 { KEY_PPAGE, REQ_PREV_PAGE },
5921 { KEY_PREVIOUS, REQ_PREV_FIELD },
5922 { KEY_RIGHT, REQ_RIGHT_CHAR },
5923 { KEY_UP, REQ_UP_CHAR },
5924 { QUIT, MAX_FORM_COMMAND + 1 }
5928 static int mode = REQ_INS_MODE;
5929 int c = wGetchar(w);
5931 FIELD *me = current_field(f);
5932 bool current = TRUE;
5934 if (c == CTRL(']')) {
5935 if (mode == REQ_INS_MODE) {
5936 mode = REQ_OVL_MODE;
5938 mode = REQ_INS_MODE;
5942 for (n = 0; n < SIZEOF(lookup); n++) {
5943 if (lookup[n].code == c) {
5944 c = lookup[n].result;
5949 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5952 * Force the field that the user is typing into to be in reverse video,
5953 * while the other fields are shown underlined.
5968 case REQ_LEFT_FIELD:
5970 case REQ_RIGHT_CHAR:
5974 current = (c < KEY_MAX);
5978 c = edit_secure(me, c);
5979 set_field_back(me, A_REVERSE);
5981 c = edit_secure(me, c);
5982 set_field_back(me, A_UNDERLINE);
5988 my_form_driver(FORM * form, int c)
5990 if (c == (MAX_FORM_COMMAND + 1)
5991 && form_driver(form, REQ_VALIDATION) == E_OK)
5999 #ifdef NCURSES_VERSION
6000 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
6001 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
6003 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
6004 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
6008 * Allow a middle initial, optionally with a '.' to end it.
6011 FIELDCHECK_CB(mi_field_check)
6013 char *s = field_buffer(fld, 0);
6017 for (n = 0; s[n] != '\0'; ++n) {
6024 } else if (isspace(UChar(s[n]))) {
6029 if (!isspace(UChar(s[n])))
6035 /* force the form to display a leading capital */
6036 if (islower(UChar(s[0]))) {
6037 s[0] = (char) toupper(UChar(s[0]));
6038 set_field_buffer(fld, 0, s);
6044 CHAR_CHECK_CB(mi_char_check)
6046 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
6050 * Passwords should be at least 6 characters.
6053 FIELDCHECK_CB(pw_field_check)
6055 char *s = field_buffer(fld, 0);
6058 for (n = 0; s[n] != '\0'; ++n) {
6059 if (isspace(UChar(s[n]))) {
6068 CHAR_CHECK_CB(pw_char_check)
6070 return (isgraph(ch) ? TRUE : FALSE);
6078 FIELD *f[12], *secure;
6079 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
6080 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
6081 int finished = 0, c;
6084 #ifdef NCURSES_MOUSE_VERSION
6085 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6089 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
6090 addstr("^N -- go to next field ^P -- go to previous field\n");
6091 addstr("Home -- go to first field End -- go to last field\n");
6092 addstr("^L -- go to field to left ^R -- go to field to right\n");
6093 addstr("^U -- move upward to field ^D -- move downward to field\n");
6094 addstr("^W -- go to next word ^B -- go to previous word\n");
6095 addstr("^S -- go to start of field ^E -- go to end of field\n");
6096 addstr("^H -- delete previous char ^Y -- delete line\n");
6097 addstr("^G -- delete current word ^C -- clear to end of line\n");
6098 addstr("^K -- clear to end of field ^X -- clear field\n");
6099 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
6101 MvAddStr(4, 57, "Forms Entry Test");
6105 /* describe the form */
6106 memset(f, 0, sizeof(f));
6107 f[n++] = make_label(0, 15, "Sample Form");
6109 f[n++] = make_label(2, 0, "Last Name");
6110 f[n++] = make_field(3, 0, 1, 18, FALSE);
6111 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6113 f[n++] = make_label(2, 20, "First Name");
6114 f[n++] = make_field(3, 20, 1, 12, FALSE);
6115 set_field_type(f[n - 1], TYPE_ALPHA, 1);
6117 f[n++] = make_label(2, 34, "Middle Name");
6118 f[n++] = make_field(3, 34, 1, 12, FALSE);
6119 set_field_type(f[n - 1], fty_middle);
6121 f[n++] = make_label(5, 0, "Comments");
6122 f[n++] = make_field(6, 0, 4, 46, FALSE);
6124 f[n++] = make_label(5, 20, "Password:");
6126 f[n++] = make_field(5, 30, 1, 9, TRUE);
6127 set_field_type(f[n - 1], fty_passwd);
6130 if ((form = new_form(f)) != 0) {
6136 nonl(); /* lets us read ^M's */
6138 switch (form_driver(form, c = form_virtualize(form, w))) {
6140 MvAddStr(5, 57, field_buffer(secure, 1));
6144 case E_UNKNOWN_COMMAND:
6145 finished = my_form_driver(form, c);
6157 for (c = 0; f[c] != 0; c++)
6159 free_fieldtype(fty_middle);
6160 free_fieldtype(fty_passwd);
6164 #ifdef NCURSES_MOUSE_VERSION
6165 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6168 #endif /* USE_LIBFORM */
6170 /****************************************************************************
6174 ****************************************************************************/
6177 fillwin(WINDOW *win, char ch)
6182 getmaxyx(win, y1, x1);
6183 for (y = 0; y < y1; y++) {
6185 for (x = 0; x < x1; x++)
6186 waddch(win, UChar(ch));
6191 crosswin(WINDOW *win, char ch)
6196 getmaxyx(win, y1, x1);
6197 for (y = 0; y < y1; y++) {
6198 for (x = 0; x < x1; x++)
6199 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
6200 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
6202 waddch(win, UChar(ch));
6207 #define OVERLAP_FLAVORS 5
6210 overlap_helpitem(int state, int item, char *message)
6212 int row = (item / 2);
6213 int col = ((item % 2) ? COLS / 2 : 0);
6215 move(LINES - 6 + row, col);
6216 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6221 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6223 short cpair = (short) (1 + (flavor * 2) + col);
6227 (void) wattrset(win, A_NORMAL);
6230 (void) wattrset(win, A_BOLD);
6233 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6234 (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_NORMAL));
6237 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6238 (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD));
6244 overlap_test_2_attr(WINDOW *win, int flavor, int col)
6246 short cpair = (short) (9 + (flavor * 2) + col);
6256 init_pair(cpair, COLOR_RED, COLOR_GREEN);
6257 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
6260 wbkgdset(win, ' ' | A_NORMAL);
6266 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
6271 const char *ths, *tht;
6275 state += OVERLAP_FLAVORS;
6276 state = state % OVERLAP_FLAVORS;
6277 assert(state >= 0 && state < OVERLAP_FLAVORS);
6279 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
6282 ths = col ? "B" : "A";
6283 tht = col ? "A" : "B";
6288 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
6296 overlap_test_1_attr(stdscr, flavors[row], col);
6297 sprintf(msg, "fill window %s with letter %s.", ths, ths);
6305 switch (flavors[row]) {
6307 sprintf(msg, "cross pattern in window %s.", ths);
6310 sprintf(msg, "draw box in window %s.", ths);
6313 sprintf(msg, "set background of window %s.", ths);
6316 sprintf(msg, "reset background of window %s.", ths);
6322 sprintf(msg, "clear window %s.", ths);
6326 switch (flavors[row]) {
6328 sprintf(msg, "overwrite %s onto %s.", ths, tht);
6331 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
6334 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
6337 sprintf(msg, "overlay %s onto %s.", ths, tht);
6342 overlap_helpitem(state, item, msg);
6343 (void) wattrset(stdscr, A_NORMAL);
6344 wbkgdset(stdscr, ' ' | A_NORMAL);
6347 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
6348 state, flavors[state]);
6354 overlap_test_0(WINDOW *a, WINDOW *b)
6364 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
6366 overlap_test_1_attr(a, flavor, col);
6368 (void) wattrset(a, A_NORMAL);
6372 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6374 overlap_test_2_attr(a, flavor, col);
6383 /* done in overlap_test_2_attr */
6386 /* done in overlap_test_2_attr */
6392 overlap_test_3(WINDOW *a)
6399 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
6406 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
6409 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
6417 /* test effects of overlapping windows */
6422 int state, flavor[OVERLAP_FLAVORS];
6424 WINDOW *win1 = newwin(9, 20, 3, 3);
6425 WINDOW *win2 = newwin(9, 20, 9, 16);
6431 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
6432 printw("the shared region of two overlapping windows A and B. The cross\n");
6433 printw("pattern in each window does not overlap the other.\n");
6435 memset(flavor, 0, sizeof(flavor));
6436 state = overlap_help(0, flavor);
6438 while (!isQuit(ch = Getchar()))
6440 case 'a': /* refresh window A first, then B */
6441 overlap_test_0(win1, win2);
6444 case 'b': /* refresh window B first, then A */
6445 overlap_test_0(win2, win1);
6448 case 'c': /* fill window A so it's visible */
6449 overlap_test_1(flavor[1], 0, win1, 'A');
6452 case 'd': /* fill window B so it's visible */
6453 overlap_test_1(flavor[1], 1, win2, 'B');
6456 case 'e': /* cross test pattern in window A */
6457 overlap_test_2(flavor[2], 0, win1, 'A');
6460 case 'f': /* cross test pattern in window A */
6461 overlap_test_2(flavor[2], 1, win2, 'B');
6464 case 'g': /* clear window A */
6465 overlap_test_3(win1);
6468 case 'h': /* clear window B */
6469 overlap_test_3(win2);
6472 case 'i': /* overwrite A onto B */
6473 overlap_test_4(flavor[4], win1, win2);
6476 case 'j': /* overwrite B onto A */
6477 overlap_test_4(flavor[4], win2, win1);
6482 state = overlap_help(state + 1, flavor);
6487 state = overlap_help(state - 1, flavor);
6492 state = overlap_help(state, flavor);
6496 state = overlap_help(state, flavor);
6511 /****************************************************************************
6515 ****************************************************************************/
6518 do_single_test(const char c)
6519 /* perform a single specified test */
6526 #if USE_WIDEC_SUPPORT
6536 #if USE_WIDEC_SUPPORT
6544 Cannot("does not support color.");
6549 #if USE_WIDEC_SUPPORT
6552 Cannot("does not support color.");
6560 Cannot("does not support color.");
6561 else if (!can_change_color())
6562 Cannot("has hardwired color values.");
6572 #if USE_WIDEC_SUPPORT
6583 #if USE_WIDEC_SUPPORT
6591 demo_panels(init_panel, fill_panel);
6595 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6597 demo_panels(init_wide_panel, fill_wide_panel);
6606 flushinp_test(stdscr);
6610 test_sgr_attributes();
6633 #if USE_LIBMENU && defined(TRACE)
6652 static const char *const tbl[] =
6654 "Usage: ncurses [options]"
6657 #ifdef NCURSES_VERSION
6658 ," -a f,b set default-colors (assumed white-on-black)"
6659 ," -d use default-colors if terminal supports them"
6661 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
6663 ," -e fmt specify format for soft-keys test (e)"
6666 ," -f rip-off footer line (can repeat)"
6667 ," -h rip-off header line (can repeat)"
6669 ," -m do not use colors"
6670 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6672 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6674 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714)
6675 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
6678 ," -t mask specify default trace-level (may toggle with ^T)"
6682 for (n = 0; n < SIZEOF(tbl); n++)
6683 fprintf(stderr, "%s\n", tbl[n]);
6684 ExitProgram(EXIT_FAILURE);
6688 set_terminal_modes(void)
6693 scrollok(stdscr, TRUE);
6694 idlok(stdscr, TRUE);
6695 keypad(stdscr, TRUE);
6700 announce_sig(int sig)
6702 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6708 rip_footer(WINDOW *win, int cols)
6710 wbkgd(win, A_REVERSE);
6713 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
6719 rip_header(WINDOW *win, int cols)
6721 wbkgd(win, A_REVERSE);
6724 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
6728 #endif /* HAVE_RIPOFFLINE */
6736 (void) puts("This is the ncurses main menu");
6737 (void) puts("a = keyboard and mouse input test");
6738 #if USE_WIDEC_SUPPORT
6739 (void) puts("A = wide-character keyboard and mouse input test");
6741 (void) puts("b = character attribute test");
6742 #if USE_WIDEC_SUPPORT
6743 (void) puts("B = wide-character attribute test");
6745 (void) puts("c = color test pattern");
6746 #if USE_WIDEC_SUPPORT
6747 (void) puts("C = color test pattern using wide-character calls");
6750 (void) puts("d = edit RGB color values");
6752 (void) puts("e = exercise soft keys");
6753 #if USE_WIDEC_SUPPORT
6754 (void) puts("E = exercise soft keys using wide-characters");
6757 (void) puts("f = display ACS characters");
6758 #if USE_WIDEC_SUPPORT
6759 (void) puts("F = display Wide-ACS characters");
6761 (void) puts("g = display windows and scrolling");
6762 (void) puts("i = test of flushinp()");
6763 (void) puts("k = display character attributes");
6765 (void) puts("m = menu code test");
6768 (void) puts("o = exercise panels library");
6769 #if USE_WIDEC_SUPPORT
6770 (void) puts("O = exercise panels with wide-characters");
6773 (void) puts("p = exercise pad features");
6774 (void) puts("q = quit");
6776 (void) puts("r = exercise forms code");
6778 (void) puts("s = overlapping-refresh test");
6779 #if USE_LIBMENU && defined(TRACE)
6780 (void) puts("t = set trace level");
6782 (void) puts("? = repeat this command summary");
6784 (void) fputs("> ", stdout);
6785 (void) fflush(stdout); /* necessary under SVr4 curses */
6788 * This used to be an 'fgets()' call (until 1996/10). However with
6789 * some runtime libraries, mixing stream I/O and 'read()' causes the
6790 * input stream to be flushed when switching between the two.
6795 if (read(fileno(stdin), &ch, 1) <= 0) {
6799 } else if (command == 0 && !isspace(UChar(ch))) {
6801 } else if (ch == '\n' || ch == '\r') {
6802 if ((command == 'd') && !top) {
6803 (void) fputs("Do not nest test-d\n", stdout);
6808 (void) fputs("> ", stdout);
6809 (void) fflush(stdout);
6813 if (do_single_test(command)) {
6815 * This may be overkill; it's intended to reset everything back
6816 * to the initial terminal modes so that tests don't get in
6820 set_terminal_modes();
6825 if (command == '?') {
6826 (void) puts("This is the ncurses capability tester.");
6828 puts("You may select a test from the main menu by typing the");
6830 puts("key letter of the choice (the letter to left of the =)");
6832 puts("at the > prompt. Type `q' to exit.");
6840 /*+-------------------------------------------------------------------------
6842 --------------------------------------------------------------------------*/
6844 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6845 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6848 main(int argc, char *argv[])
6852 #ifdef NCURSES_VERSION
6853 int default_fg = COLOR_WHITE;
6854 int default_bg = COLOR_BLACK;
6855 bool assumed_colors = FALSE;
6856 bool default_colors = FALSE;
6858 char *palette_file = 0;
6859 bool monochrome = FALSE;
6861 setlocale(LC_ALL, "");
6863 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:")) != -1) {
6865 #ifdef NCURSES_VERSION
6867 assumed_colors = TRUE;
6868 switch (sscanf(optarg, "%d,%d", &default_fg, &default_bg)) {
6870 default_fg = COLOR_WHITE;
6873 default_bg = COLOR_BLACK;
6878 default_colors = TRUE;
6885 my_e_param = atoi(optarg);
6886 #ifdef NCURSES_VERSION
6887 if (my_e_param > 3) /* allow extended layouts */
6896 ripoffline(-1, rip_footer);
6899 ripoffline(1, rip_header);
6901 #endif /* HAVE_RIPOFFLINE */
6906 palette_file = optarg;
6910 nap_msec = (int) atol(optarg);
6913 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714)
6920 save_trace = (unsigned) strtol(optarg, 0, 0);
6929 * If there's no menus (unlikely for ncurses!), then we'll have to set
6930 * tracing on initially, just in case the user wants to test something that
6931 * doesn't involve wGetchar.
6934 /* enable debugging */
6938 if (!isatty(fileno(stdin)))
6940 #endif /* USE_LIBMENU */
6944 /* tell it we're going to play with soft keys */
6945 slk_init(my_e_param);
6949 /* set up null signal catcher so we can see what interrupts to getch do */
6950 signal(SIGUSR1, announce_sig);
6953 /* we must initialize the curses data structure only once */
6957 /* tests, in general, will want these modes */
6958 use_colors = (bool) (monochrome ? FALSE : has_colors());
6962 #ifdef NCURSES_VERSION_PATCH
6963 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6964 #if HAVE_USE_DEFAULT_COLORS
6965 if (default_colors) {
6966 use_default_colors();
6969 #if HAVE_ASSUME_DEFAULT_COLORS
6971 assume_default_colors(default_fg, default_bg);
6974 #else /* normal SVr4 curses */
6975 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6977 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6979 if (can_change_color()) {
6981 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
6983 failed("all_colors");
6984 for (cp = 0; cp < max_colors; ++cp) {
6986 &all_colors[cp].red,
6987 &all_colors[cp].green,
6988 &all_colors[cp].blue);
6990 if (palette_file != 0) {
6991 FILE *fp = fopen(palette_file, "r");
6993 char buffer[BUFSIZ];
6994 int red, green, blue;
6996 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6997 if (sscanf(buffer, "scale:%d", &c) == 1) {
6999 } else if (sscanf(buffer, "%d:%d %d %d",
7008 all_colors[c].red = (short) ((red * 1000) / scale);
7009 all_colors[c].green = (short) ((green * 1000) / scale);
7010 all_colors[c].blue = (short) ((blue * 1000) / scale);
7018 set_terminal_modes();
7022 * Return to terminal mode, so we're guaranteed of being able to
7023 * select terminal commands even if the capabilities are wrong.
7027 #if HAVE_CURSES_VERSION
7028 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
7029 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
7030 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
7031 NCURSES_VERSION_MAJOR,
7032 NCURSES_VERSION_MINOR,
7033 NCURSES_VERSION_PATCH);
7035 (void) puts("Welcome to ncurses. Press ? for help.");
7040 ExitProgram(EXIT_SUCCESS);
7043 /* ncurses.c ends here */