1 /****************************************************************************
2 * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
28 /****************************************************************************
31 ncurses.c --- ncurses library exerciser
37 An interactive test module for the ncurses library.
40 Author: Eric S. Raymond <esr@snark.thyrsus.com> 1993
41 Thomas E. Dickey (beginning revision 1.27 in 1996).
43 $Id: ncurses.c,v 1.373 2012/07/21 17:40:21 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
110 #ifdef CURSES_WACS_ARRAY
111 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
112 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
113 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
114 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
115 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
116 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
117 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
124 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
125 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
126 #define reset_wchars(state) init_mb(state)
127 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
128 #define count_wchars(src, len, state) wcstombs(0, src, len)
129 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
130 #define reset_wchars(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
135 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
136 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
137 #define reset_mbytes(state) init_mb(state)
138 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
139 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
140 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
141 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
145 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
147 #define P(string) printw("%s\n", string)
149 #define BLANK ' ' /* this is the background character */
152 static int max_colors; /* the actual number of colors we'll use */
153 static int min_colors; /* the minimum color code */
154 static bool use_colors; /* true if we use colors */
157 static int max_pairs; /* ...and the number of color pairs */
165 static RGB_DATA *all_colors;
167 static void main_menu(bool);
169 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
170 * though we can rely on negative x/y values to stop the macro.
173 do_h_line(int y, int x, chtype c, int to)
176 MvHLine(y, x, c, (to) - (x));
180 do_v_line(int y, int x, chtype c, int to)
183 MvVLine(y, x, c, (to) - (y));
197 return ((c) == QUIT || (c) == ESCAPE);
199 #define case_QUIT QUIT: case ESCAPE
201 /* Common function to allow ^T to toggle trace-mode in the middle of a test
202 * so that trace-files can be made smaller.
205 wGetchar(WINDOW *win)
209 while ((c = wgetch(win)) == CTRL('T')) {
211 save_trace = _nc_tracing;
212 Trace(("TOGGLE-TRACING OFF"));
215 _nc_tracing = save_trace;
219 Trace(("TOGGLE-TRACING ON"));
226 #define Getchar() wGetchar(stdscr)
228 /* replaces wgetnstr(), since we want to be able to edit values */
230 wGetstring(WINDOW *win, char *buffer, int limit)
237 (void) wattrset(win, A_REVERSE);
239 x = (int) strlen(buffer);
241 if (x > (int) strlen(buffer))
242 x = (int) strlen(buffer);
244 wprintw(win, "%-*s", limit, buffer);
245 wmove(win, y0, x0 + x);
246 switch (ch = wGetchar(win)) {
259 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
277 if (!isprint(ch) || ch >= KEY_MIN) {
279 } else if ((int) strlen(buffer) < limit) {
281 for (j = (int) strlen(buffer) + 1; j > x; --j) {
282 buffer[j] = buffer[j - 1];
284 buffer[x++] = (char) ch;
291 wattroff(win, A_REVERSE);
296 #if USE_WIDEC_SUPPORT
300 return (ch + 0xff10 - '0');
304 make_fullwidth_text(wchar_t *target, const char *source)
307 while ((ch = *source++) != 0) {
308 *target++ = fullwidth_of(ch);
314 make_narrow_text(wchar_t *target, const char *source)
317 while ((ch = *source++) != 0) {
325 make_fullwidth_digit(cchar_t *target, int digit)
329 source[0] = fullwidth_of(digit + '0');
331 setcchar(target, source, A_NORMAL, 0, 0);
336 wGet_wchar(WINDOW *win, wint_t *result)
340 while ((c = wget_wch(win, result)) == CTRL('T')) {
342 save_trace = _nc_tracing;
343 Trace(("TOGGLE-TRACING OFF"));
346 _nc_tracing = save_trace;
350 Trace(("TOGGLE-TRACING ON"));
353 c = wget_wch(win, result);
357 #define Get_wchar(result) wGet_wchar(stdscr, result)
359 /* replaces wgetn_wstr(), since we want to be able to edit values */
361 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
370 (void) wattrset(win, A_REVERSE);
372 x = (int) wcslen(buffer);
374 if (x > (int) wcslen(buffer))
375 x = (int) wcslen(buffer);
377 /* clear the "window' */
379 wprintw(win, "%*s", limit, " ");
381 /* write the existing buffer contents */
383 waddnwstr(win, buffer, limit);
385 /* positions the cursor past character 'x' */
387 waddnwstr(win, buffer, x);
389 switch (wGet_wchar(win, &ch)) {
429 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
449 } else if ((int) wcslen(buffer) < limit) {
451 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
452 buffer[j] = buffer[j - 1];
454 buffer[x++] = (wchar_t) ch;
461 wattroff(win, A_REVERSE);
472 addstr("Press any key to continue... ");
477 Cannot(const char *what)
479 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
484 ShellOut(bool message)
487 addstr("Shelling out...");
493 IGNORE_RC(system("sh"));
496 addstr("returned from shellout.\n");
500 #ifdef NCURSES_MOUSE_VERSION
502 * This function is the same as _tracemouse(), but we cannot count on that
503 * being available in the non-debug library.
506 mouse_decode(MEVENT const *ep)
508 static char buf[80 + (5 * 10) + (32 * 15)];
510 (void) sprintf(buf, "id %2d at (%2d, %2d, %d) state %4lx = {",
511 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
513 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
515 SHOW(BUTTON1_RELEASED, "release-1");
516 SHOW(BUTTON1_PRESSED, "press-1");
517 SHOW(BUTTON1_CLICKED, "click-1");
518 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
519 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
520 #if NCURSES_MOUSE_VERSION == 1
521 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
524 SHOW(BUTTON2_RELEASED, "release-2");
525 SHOW(BUTTON2_PRESSED, "press-2");
526 SHOW(BUTTON2_CLICKED, "click-2");
527 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
528 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
529 #if NCURSES_MOUSE_VERSION == 1
530 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
533 SHOW(BUTTON3_RELEASED, "release-3");
534 SHOW(BUTTON3_PRESSED, "press-3");
535 SHOW(BUTTON3_CLICKED, "click-3");
536 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
537 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
538 #if NCURSES_MOUSE_VERSION == 1
539 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
542 SHOW(BUTTON4_RELEASED, "release-4");
543 SHOW(BUTTON4_PRESSED, "press-4");
544 SHOW(BUTTON4_CLICKED, "click-4");
545 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
546 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
547 #if NCURSES_MOUSE_VERSION == 1
548 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
551 #if NCURSES_MOUSE_VERSION == 2
552 SHOW(BUTTON5_RELEASED, "release-5");
553 SHOW(BUTTON5_PRESSED, "press-5");
554 SHOW(BUTTON5_CLICKED, "click-5");
555 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
556 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
559 SHOW(BUTTON_CTRL, "ctrl");
560 SHOW(BUTTON_SHIFT, "shift");
561 SHOW(BUTTON_ALT, "alt");
562 SHOW(ALL_MOUSE_EVENTS, "all-events");
563 SHOW(REPORT_MOUSE_POSITION, "position");
567 if (buf[strlen(buf) - 1] == ' ')
568 buf[strlen(buf) - 2] = '\0';
569 (void) strcat(buf, "}");
574 show_mouse(WINDOW *win)
582 outside = !wenclose(win, event.y, event.x);
585 (void) wstandout(win);
586 waddstr(win, "KEY_MOUSE");
587 (void) wstandend(win);
589 waddstr(win, "KEY_MOUSE");
591 wprintw(win, ", %s", mouse_decode(&event));
596 show_loc = wmouse_trafo(win, &event.y, &event.x, FALSE);
600 wmove(win, event.y, event.x);
608 #endif /* NCURSES_MOUSE_VERSION */
610 /****************************************************************************
612 * Character input test
614 ****************************************************************************/
616 #define NUM_GETCH_FLAGS 256
617 typedef bool GetchFlags[NUM_GETCH_FLAGS];
620 setup_getch(WINDOW *win, GetchFlags flags)
622 keypad(win, flags['k']); /* should be redundant, but for testing */
623 meta(win, flags['m']); /* force this to a known state */
631 init_getch(WINDOW *win, GetchFlags flags)
633 memset(flags, FALSE, NUM_GETCH_FLAGS);
634 flags[UChar('k')] = (win == stdscr);
635 flags[UChar('m')] = TRUE;
637 setup_getch(win, flags);
641 wgetch_help(WINDOW *win, GetchFlags flags)
643 static const char *help[] =
645 "e -- toggle echo mode"
646 ,"g -- triggers a getstr test"
647 ,"k -- toggle keypad/literal mode"
648 ,"m -- toggle meta (7-bit/8-bit) mode"
651 ,"w -- create a new window"
653 ,"z -- suspend this process"
657 unsigned chk = ((SIZEOF(help) + 1) / 2);
662 printw("Type any key to see its %s value. Also:\n",
663 flags['k'] ? "keypad" : "literal");
664 for (n = 0; n < SIZEOF(help); ++n) {
665 int row = 1 + (int) (n % chk);
666 int col = (n >= chk) ? COLS / 2 : 0;
667 int flg = ((strstr(help[n], "toggle") != 0)
668 && (flags[UChar(*help[n])] != FALSE));
671 MvPrintw(row, col, "%s", help[n]);
682 wgetch_wrap(WINDOW *win, int first_y)
684 int last_y = getmaxy(win) - 1;
685 int y = getcury(win) + 1;
693 #if defined(KEY_RESIZE) && HAVE_WRESIZE
699 static WINSTACK *winstack = 0;
700 static unsigned len_winstack = 0;
713 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
715 unsigned need = (level + 1) * 2;
717 assert(level < (unsigned) COLS);
721 winstack = typeMalloc(WINSTACK, len_winstack);
722 } else if (need >= len_winstack) {
724 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
726 winstack[level].text = txt_win;
727 winstack[level].frame = box_win;
730 #if USE_SOFTKEYS && (defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
734 /* this chunk is now done in resize_term() */
741 #define slk_repaint() /* nothing */
744 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
746 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
747 * Resize both and paint the box in the parent.
750 resize_boxes(unsigned level, WINDOW *win)
754 int high = LINES - base;
758 wnoutrefresh(stdscr);
762 for (n = 0; n < level; ++n) {
763 wresize(winstack[n].frame, high, wide);
764 wresize(winstack[n].text, high - 2, wide - 2);
767 werase(winstack[n].text);
768 box(winstack[n].frame, 0, 0);
769 wnoutrefresh(winstack[n].frame);
770 wprintw(winstack[n].text,
772 getmaxy(winstack[n].text),
773 getmaxx(winstack[n].text));
774 wnoutrefresh(winstack[n].text);
775 if (winstack[n].text == win)
780 #endif /* resize_boxes */
782 #define forget_boxes() /* nothing */
783 #define remember_boxes(level,text,frame) /* nothing */
787 * Return-code is OK/ERR or a keyname.
792 return ((code == OK) ? "OK" : ((code == ERR) ? "ERR" : keyname(code)));
796 wgetch_test(unsigned level, WINDOW *win, int delay)
799 int first_y, first_x;
803 bool blocking = (delay < 0);
805 init_getch(win, flags);
806 wtimeout(win, delay);
807 getyx(win, first_y, first_x);
809 wgetch_help(win, flags);
810 wsetscrreg(win, first_y, getmaxy(win) - 1);
814 while ((c = wGetchar(win)) == ERR) {
817 (void) wprintw(win, "%05d: input error", incount);
820 (void) wprintw(win, "%05d: input timed out", incount);
822 wgetch_wrap(win, first_y);
824 if (c == ERR && blocking) {
826 wgetch_wrap(win, first_y);
827 } else if (isQuit(c)) {
829 } else if (c == 'e') {
830 flags[UChar('e')] = !flags[UChar('e')];
831 setup_getch(win, flags);
832 wgetch_help(win, flags);
833 } else if (c == 'g') {
834 waddstr(win, "getstr test: ");
836 c = wgetnstr(win, buf, sizeof(buf) - 1);
838 wprintw(win, "I saw %d characters:\n\t`%s' (%s).",
839 (int) strlen(buf), buf,
842 wgetch_wrap(win, first_y);
843 } else if (c == 'k') {
844 flags[UChar('k')] = !flags[UChar('k')];
845 setup_getch(win, flags);
846 wgetch_help(win, flags);
847 } else if (c == 'm') {
848 flags[UChar('m')] = !flags[UChar('m')];
849 setup_getch(win, flags);
850 wgetch_help(win, flags);
851 } else if (c == 's') {
853 } else if (c == 'w') {
854 int high = getmaxy(win) - 1 - first_y + 1;
855 int wide = getmaxx(win) - first_x;
857 int new_y = first_y + getbegy(win);
858 int new_x = first_x + getbegx(win);
860 getyx(win, old_y, old_x);
861 if (high > 2 && wide > 2) {
862 WINDOW *wb = newwin(high, wide, new_y, new_x);
863 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
868 remember_boxes(level, wi, wb);
869 wgetch_test(level + 1, wi, delay);
873 wgetch_help(win, flags);
874 wmove(win, old_y, old_x);
880 } else if (c == 'z') {
881 kill(getpid(), SIGTSTP);
884 wprintw(win, "Key pressed: %04o ", c);
885 #ifdef NCURSES_MOUSE_VERSION
886 if (c == KEY_MOUSE) {
889 #endif /* NCURSES_MOUSE_VERSION */
891 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
892 if (c == KEY_RESIZE) {
893 resize_boxes(level, win);
896 (void) waddstr(win, keyname(c));
897 } else if (c >= 0x80) {
898 unsigned c2 = (unsigned) c;
899 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
900 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
904 (void) wprintw(win, "%c", UChar(c));
905 else if (c2 != UChar(c))
906 (void) wprintw(win, "M-%s", unctrl(c2));
908 (void) wprintw(win, "%s", unctrl(c2));
909 waddstr(win, " (high-half character)");
912 (void) wprintw(win, "%c (ASCII printable character)", c);
914 (void) wprintw(win, "%s (ASCII control character)",
917 wgetch_wrap(win, first_y);
924 init_getch(win, flags);
928 begin_getch_test(void)
935 #ifdef NCURSES_MOUSE_VERSION
936 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
939 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
941 getnstr(buf, sizeof(buf) - 1);
945 if (isdigit(UChar(buf[0]))) {
946 delay = atoi(buf) * 100;
956 finish_getch_test(void)
958 #ifdef NCURSES_MOUSE_VERSION
959 mousemask(0, (mmask_t *) 0);
970 int delay = begin_getch_test();
973 wgetch_test(0, stdscr, delay);
979 #if USE_WIDEC_SUPPORT
981 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
982 * Resize both and paint the box in the parent.
984 #if defined(KEY_RESIZE) && HAVE_WRESIZE
986 resize_wide_boxes(unsigned level, WINDOW *win)
990 int high = LINES - base;
994 wnoutrefresh(stdscr);
998 for (n = 0; n < level; ++n) {
999 wresize(winstack[n].frame, high, wide);
1000 wresize(winstack[n].text, high - 2, wide - 2);
1003 werase(winstack[n].text);
1004 box_set(winstack[n].frame, 0, 0);
1005 wnoutrefresh(winstack[n].frame);
1006 wprintw(winstack[n].text,
1008 getmaxy(winstack[n].text),
1009 getmaxx(winstack[n].text));
1010 wnoutrefresh(winstack[n].text);
1011 if (winstack[n].text == win)
1016 #endif /* KEY_RESIZE */
1019 wcstos(const wchar_t *src)
1023 const wchar_t *tmp = src;
1024 #ifndef state_unused
1028 reset_wchars(state);
1029 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
1030 unsigned have = (unsigned) need;
1031 if ((result = typeCalloc(char, have + 1)) != 0) {
1033 if (trans_wchars(result, tmp, have, &state) != have) {
1043 wget_wch_test(unsigned level, WINDOW *win, int delay)
1045 wchar_t wchar_buf[BUFSIZ];
1046 wint_t wint_buf[BUFSIZ];
1047 int first_y, first_x;
1051 bool blocking = (delay < 0);
1055 init_getch(win, flags);
1056 wtimeout(win, delay);
1057 getyx(win, first_y, first_x);
1059 wgetch_help(win, flags);
1060 wsetscrreg(win, first_y, getmaxy(win) - 1);
1061 scrollok(win, TRUE);
1064 while ((code = wGet_wchar(win, &c)) == ERR) {
1067 (void) wprintw(win, "%05d: input error", incount);
1070 (void) wprintw(win, "%05d: input timed out", incount);
1072 wgetch_wrap(win, first_y);
1074 if (code == ERR && blocking) {
1075 wprintw(win, "ERR");
1076 wgetch_wrap(win, first_y);
1077 } else if (isQuit((int) c)) {
1079 } else if (c == 'e') {
1080 flags[UChar('e')] = !flags[UChar('e')];
1081 setup_getch(win, flags);
1082 wgetch_help(win, flags);
1083 } else if (c == 'g') {
1084 waddstr(win, "getstr test: ");
1086 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1089 wprintw(win, "wgetn_wstr returns an error.");
1092 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1095 if ((temp = wcstos(wchar_buf)) != 0) {
1096 wprintw(win, "I saw %d characters:\n\t`%s'.",
1097 (int) wcslen(wchar_buf), temp);
1100 wprintw(win, "I saw %d characters (cannot convert).",
1101 (int) wcslen(wchar_buf));
1105 wgetch_wrap(win, first_y);
1106 } else if (c == 'k') {
1107 flags[UChar('k')] = !flags[UChar('k')];
1108 setup_getch(win, flags);
1109 wgetch_help(win, flags);
1110 } else if (c == 'm') {
1111 flags[UChar('m')] = !flags[UChar('m')];
1112 setup_getch(win, flags);
1113 wgetch_help(win, flags);
1114 } else if (c == 's') {
1116 } else if (c == 'w') {
1117 int high = getmaxy(win) - 1 - first_y + 1;
1118 int wide = getmaxx(win) - first_x;
1120 int new_y = first_y + getbegy(win);
1121 int new_x = first_x + getbegx(win);
1123 getyx(win, old_y, old_x);
1124 if (high > 2 && wide > 2) {
1125 WINDOW *wb = newwin(high, wide, new_y, new_x);
1126 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1131 remember_boxes(level, wi, wb);
1132 wget_wch_test(level + 1, wi, delay);
1136 wgetch_help(win, flags);
1137 wmove(win, old_y, old_x);
1142 } else if (c == 'z') {
1143 kill(getpid(), SIGTSTP);
1146 wprintw(win, "Key pressed: %04o ", (int) c);
1147 #ifdef NCURSES_MOUSE_VERSION
1148 if (c == KEY_MOUSE) {
1151 #endif /* NCURSES_MOUSE_VERSION */
1152 if (code == KEY_CODE_YES) {
1153 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1154 if (c == KEY_RESIZE) {
1155 resize_wide_boxes(level, win);
1158 (void) waddstr(win, keyname((wchar_t) c));
1160 (void) waddstr(win, key_name((wchar_t) c));
1161 if (c < 256 && iscntrl(c)) {
1162 (void) wprintw(win, " (control character)");
1164 (void) wprintw(win, " = %#x (printable character)",
1168 wgetch_wrap(win, first_y);
1175 init_getch(win, flags);
1181 int delay = begin_getch_test();
1184 wget_wch_test(0, stdscr, delay);
1186 finish_getch_test();
1191 /****************************************************************************
1193 * Character attributes test
1195 ****************************************************************************/
1197 #if HAVE_SETUPTERM || HAVE_TGETENT
1198 #define get_ncv() TIGETNUM("ncv","NC")
1199 #define get_xmc() TIGETNUM("xmc","sg")
1201 #define get_ncv() -1
1202 #define get_xmc() -1
1209 static int first = TRUE;
1210 static chtype result = 0;
1216 char *area_pointer = parsed;
1218 tgetent(buffer, getenv("TERM"));
1221 if (TIGETSTR("smso", "so"))
1222 result |= A_STANDOUT;
1223 if (TIGETSTR("smul", "us"))
1224 result |= A_UNDERLINE;
1225 if (TIGETSTR("rev", "mr"))
1226 result |= A_REVERSE;
1227 if (TIGETSTR("blink", "mb"))
1229 if (TIGETSTR("dim", "mh"))
1231 if (TIGETSTR("bold", "md"))
1233 if (TIGETSTR("smacs", "ac"))
1234 result |= A_ALTCHARSET;
1240 #define termattrs() my_termattrs()
1243 #define MAX_ATTRSTRING 31
1244 #define LEN_ATTRSTRING 26
1246 static char attr_test_string[MAX_ATTRSTRING + 1];
1249 attr_legend(WINDOW *helpwin)
1254 MvWPrintw(helpwin, row++, col,
1256 MvWPrintw(helpwin, row++, col,
1259 MvWPrintw(helpwin, row++, col,
1260 "Modify the test strings:");
1261 MvWPrintw(helpwin, row++, col,
1262 " A digit sets gaps on each side of displayed attributes");
1263 MvWPrintw(helpwin, row++, col,
1264 " </> shifts the text left/right. ");
1266 MvWPrintw(helpwin, row++, col,
1269 MvWPrintw(helpwin, row++, col,
1270 " f/F/b/F toggle foreground/background background color");
1271 MvWPrintw(helpwin, row++, col,
1272 " t/T toggle text/background color attribute");
1274 MvWPrintw(helpwin, row++, col,
1275 " a/A toggle ACS (alternate character set) mapping");
1276 MvWPrintw(helpwin, row, col,
1277 " v/V toggle video attribute to combine with each line");
1281 show_color_attr(int fg, int bg, int tx)
1284 printw(" Colors (fg %d, bg %d", fg, bg);
1286 printw(", text %d", tx);
1292 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1299 *fg = (short) (*fg + 1);
1302 *fg = (short) (*fg - 1);
1305 *bg = (short) (*bg + 1);
1308 *bg = (short) (*bg - 1);
1311 *tx = (short) (*tx + 1);
1314 *tx = (short) (*tx - 1);
1322 *fg = (short) min_colors;
1323 if (*fg < min_colors)
1324 *fg = (short) (COLORS - 1);
1326 *bg = (short) min_colors;
1327 if (*bg < min_colors)
1328 *bg = (short) (COLORS - 1);
1332 *tx = (short) (COLORS - 1);
1341 adjust_attr_string(int adjust)
1343 int first = ((int) UChar(attr_test_string[0])) + adjust;
1344 int last = first + LEN_ATTRSTRING;
1346 if (first >= ' ' && last <= '~') { /* 32..126 */
1348 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1349 attr_test_string[j] = (char) k;
1350 if (((k + 1 - first) % 5) == 0) {
1351 if (++j >= MAX_ATTRSTRING)
1353 attr_test_string[j] = ' ';
1356 while (j < MAX_ATTRSTRING)
1357 attr_test_string[j++] = ' ';
1358 attr_test_string[j] = '\0';
1365 init_attr_string(void)
1367 attr_test_string[0] = 'a';
1368 adjust_attr_string(0);
1372 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1374 int ncv = get_ncv();
1375 chtype test = attr & (chtype) (~A_ALTCHARSET);
1378 MvPrintw(row, 5, "-->");
1379 MvPrintw(row, 8, "%s mode:", name);
1380 MvPrintw(row, 24, "|");
1382 printw("%*s", skip, " ");
1384 * Just for testing, write text using the alternate character set one
1385 * character at a time (to pass its rendition directly), and use the
1386 * string operation for the other attributes.
1388 if (attr & A_ALTCHARSET) {
1392 for (s = attr_test_string; *s != '\0'; ++s) {
1397 (void) attrset(attr);
1398 addstr(attr_test_string);
1402 printw("%*s", skip, " ");
1404 if (test != A_NORMAL) {
1405 if (!(termattrs() & test)) {
1408 if (ncv > 0 && stdscr && (getbkgd(stdscr) & A_COLOR)) {
1409 static const chtype table[] =
1425 for (n = 0; n < SIZEOF(table); n++) {
1426 if ((table[n] & attr) != 0
1427 && ((1 << n) & ncv) != 0) {
1435 if ((termattrs() & test) != test)
1442 static const struct {
1444 NCURSES_CONST char * name;
1445 } attrs_to_test[] = {
1446 { A_STANDOUT, "STANDOUT" },
1447 { A_REVERSE, "REVERSE" },
1449 { A_UNDERLINE, "UNDERLINE" },
1451 { A_BLINK, "BLINK" },
1452 { A_PROTECT, "PROTECT" },
1454 { A_INVIS, "INVISIBLE" },
1456 { A_NORMAL, "NORMAL" },
1461 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1471 if (ch < 256 && isdigit(ch)) {
1479 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1481 attr_legend(helpwin);
1494 *kc = SIZEOF(attrs_to_test) - 1;
1500 if (*kc >= SIZEOF(attrs_to_test))
1504 adjust_attr_string(-1);
1507 adjust_attr_string(1);
1513 error = cycle_color_attr(ch, fg, bg, tx);
1523 /* test text attributes */
1526 int skip = get_xmc();
1527 short fg = COLOR_BLACK; /* color pair 0 is special */
1528 short bg = COLOR_BLACK;
1536 n = skip; /* make it easy */
1537 k = SIZEOF(attrs_to_test) - 1;
1542 chtype normal = A_NORMAL | BLANK;
1543 chtype extras = (chtype) ac;
1546 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1549 if (init_pair(pair, fg, bg) == ERR) {
1552 normal |= (chtype) COLOR_PAIR(pair);
1557 if (init_pair(pair, tx, bg) == ERR) {
1560 extras |= (chtype) COLOR_PAIR(pair);
1569 MvAddStr(0, 20, "Character attribute test display");
1571 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1572 bool arrow = (j == k);
1573 row = show_attr(row, n, arrow,
1575 attrs_to_test[j].attr |
1576 attrs_to_test[k].attr,
1577 attrs_to_test[j].name);
1581 "This terminal does %shave the magic-cookie glitch",
1582 get_xmc() > -1 ? "" : "not ");
1583 MvPrintw(row + 1, 8, "Enter '?' for help.");
1584 show_color_attr(fg, bg, tx);
1585 printw(" ACS (%d)", ac != 0);
1588 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1590 bkgdset(A_NORMAL | BLANK);
1595 #if USE_WIDEC_SUPPORT
1596 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1599 wide_adjust_attr_string(int adjust)
1601 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1602 int last = first + LEN_ATTRSTRING;
1604 if (first >= ' ' && last <= '~') { /* 32..126 */
1606 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1607 wide_attr_test_string[j] = k;
1608 if (((k + 1 - first) % 5) == 0) {
1609 if (++j >= MAX_ATTRSTRING)
1611 wide_attr_test_string[j] = ' ';
1614 while (j < MAX_ATTRSTRING)
1615 wide_attr_test_string[j++] = ' ';
1616 wide_attr_test_string[j] = '\0';
1623 wide_init_attr_string(void)
1625 wide_attr_test_string[0] = 'a';
1626 wide_adjust_attr_string(0);
1630 set_wide_background(short pair)
1637 setcchar(&normal, blank, A_NORMAL, pair, 0);
1643 get_wide_background(void)
1645 attr_t result = A_NORMAL;
1651 if (getbkgrnd(&ch) != ERR) {
1652 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1660 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1662 int ncv = get_ncv();
1663 chtype test = attr & ~WA_ALTCHARSET;
1666 MvPrintw(row, 5, "-->");
1667 MvPrintw(row, 8, "%s mode:", name);
1668 MvPrintw(row, 24, "|");
1670 printw("%*s", skip, " ");
1673 * Just for testing, write text using the alternate character set one
1674 * character at a time (to pass its rendition directly), and use the
1675 * string operation for the other attributes.
1677 if (attr & WA_ALTCHARSET) {
1681 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1685 setcchar(&ch, fill, attr, pair, 0);
1689 attr_t old_attr = 0;
1692 (void) attr_get(&old_attr, &old_pair, 0);
1693 (void) attr_set(attr, pair, 0);
1694 addwstr(wide_attr_test_string);
1695 (void) attr_set(old_attr, old_pair, 0);
1698 printw("%*s", skip, " ");
1700 if (test != A_NORMAL) {
1701 if (!(term_attrs() & test)) {
1704 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1705 static const attr_t table[] =
1719 for (n = 0; n < SIZEOF(table); n++) {
1720 if ((table[n] & attr) != 0
1721 && ((1 << n) & ncv) != 0) {
1729 if ((term_attrs() & test) != test)
1737 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1747 if (ch < 256 && isdigit(ch)) {
1755 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1756 box_set(helpwin, 0, 0);
1757 attr_legend(helpwin);
1770 *kc = SIZEOF(attrs_to_test) - 1;
1776 if (*kc >= SIZEOF(attrs_to_test))
1780 wide_adjust_attr_string(-1);
1783 wide_adjust_attr_string(1);
1789 error = cycle_color_attr(ch, fg, bg, tx);
1798 wide_attr_test(void)
1799 /* test text attributes using wide-character calls */
1802 int skip = get_xmc();
1803 short fg = COLOR_BLACK; /* color pair 0 is special */
1804 short bg = COLOR_BLACK;
1812 n = skip; /* make it easy */
1813 k = SIZEOF(attrs_to_test) - 1;
1814 wide_init_attr_string();
1822 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1825 if (init_pair(pair, fg, bg) == ERR) {
1832 if (init_pair(extras, tx, bg) == ERR) {
1837 set_wide_background(pair);
1840 box_set(stdscr, 0, 0);
1841 MvAddStr(0, 20, "Character attribute test display");
1843 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1844 row = wide_show_attr(row, n, j == k,
1846 attrs_to_test[j].attr |
1847 attrs_to_test[k].attr),
1849 attrs_to_test[j].name);
1853 "This terminal does %shave the magic-cookie glitch",
1854 get_xmc() > -1 ? "" : "not ");
1855 MvPrintw(row + 1, 8, "Enter '?' for help.");
1856 show_color_attr(fg, bg, tx);
1857 printw(" ACS (%d)", ac != 0);
1860 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1862 set_wide_background(0);
1868 /****************************************************************************
1870 * Color support tests
1872 ****************************************************************************/
1874 static NCURSES_CONST char *the_color_names[] =
1895 show_color_name(int y, int x, int color, bool wide)
1897 if (move(y, x) != ERR) {
1902 sprintf(temp, "%02d", color);
1904 } else if (color >= 8) {
1905 sprintf(temp, "[%02d]", color);
1906 } else if (color < 0) {
1907 strcpy(temp, "default");
1909 strcpy(temp, the_color_names[color]);
1911 printw("%-*.*s", width, width, temp);
1916 color_legend(WINDOW *helpwin, bool wide)
1921 MvWPrintw(helpwin, row++, col,
1924 MvWPrintw(helpwin, row++, col,
1925 "Use up/down arrow to scroll through the display if it is");
1926 MvWPrintw(helpwin, row++, col,
1927 "longer than one screen. Control/N and Control/P can be used");
1928 MvWPrintw(helpwin, row++, col,
1929 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1930 MvWPrintw(helpwin, row++, col,
1931 "full screen; control/B and control/F can be used here.");
1933 MvWPrintw(helpwin, row++, col,
1935 MvWPrintw(helpwin, row++, col,
1936 " a/A toggle altcharset off/on");
1937 MvWPrintw(helpwin, row++, col,
1938 " b/B toggle bold off/on");
1939 MvWPrintw(helpwin, row++, col,
1940 " n/N toggle text/number on/off");
1941 MvWPrintw(helpwin, row++, col,
1942 " r/R toggle reverse on/off");
1943 MvWPrintw(helpwin, row++, col,
1944 " w/W toggle width between 8/16 colors");
1945 #if USE_WIDEC_SUPPORT
1947 MvWPrintw(helpwin, row++, col,
1948 "Wide characters:");
1949 MvWPrintw(helpwin, row, col,
1950 " x/X toggle text between ASCII and wide-character");
1957 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1959 /* generate a color test pattern */
1966 int grid_top = top + 3;
1967 int page_size = (LINES - grid_top);
1968 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1974 bool opt_acsc = FALSE;
1975 bool opt_bold = FALSE;
1976 bool opt_revs = FALSE;
1977 bool opt_nums = FALSE;
1978 bool opt_wide = FALSE;
1981 if (COLORS * COLORS == COLOR_PAIRS) {
1982 int limit = (COLORS - min_colors) * (COLORS - min_colors);
1983 if (pairs_max > limit)
1986 if (pairs_max > COLOR_PAIRS)
1987 pairs_max = COLOR_PAIRS;
1993 /* this assumes an 80-column line */
1997 per_row = (COLORS > 8) ? 16 : 8;
2003 per_row -= min_colors;
2005 row_limit = (pairs_max + per_row - 1) / per_row;
2008 (void) printw("There are %d color pairs and %d colors%s\n",
2010 min_colors ? " besides 'default'" : "");
2013 MvPrintw(top + 1, 0,
2014 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2017 opt_bold ? "on" : "off");
2019 /* show color names/numbers across the top */
2020 for (i = 0; i < per_row; i++)
2021 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2023 /* show a grid of colors, with color names/ numbers on the left */
2024 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
2025 int row = grid_top + (i / per_row) - base_row;
2026 int col = (i % per_row + 1) * width;
2029 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
2030 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
2031 if (row >= 0 && move(row, col) != ERR) {
2032 short fg = InxToFG(i);
2033 short bg = InxToBG(i);
2035 init_pair(pair, fg, bg);
2036 attron((attr_t) COLOR_PAIR(pair));
2038 attron((attr_t) A_ALTCHARSET);
2040 attron((attr_t) A_BOLD);
2042 attron((attr_t) A_REVERSE);
2045 sprintf(numbered, "{%02X}", i);
2048 printw("%-*.*s", width, width, hello);
2049 (void) attrset(A_NORMAL);
2051 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2052 show_color_name(row, 0, InxToBG(i), opt_wide);
2060 switch (wGetchar(stdscr)) {
2089 set_color_test(opt_wide, FALSE);
2092 set_color_test(opt_wide, TRUE);
2096 if (base_row <= 0) {
2104 if (base_row + page_size >= row_limit) {
2113 if (base_row <= 0) {
2116 base_row -= (page_size - 1);
2124 if (base_row + page_size >= row_limit) {
2127 base_row += page_size - 1;
2128 if (base_row + page_size >= row_limit) {
2129 base_row = row_limit - page_size - 1;
2134 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2136 color_legend(helpwin, FALSE);
2151 #if USE_WIDEC_SUPPORT
2152 /* generate a color test pattern */
2154 wide_color_test(void)
2159 int grid_top = top + 3;
2160 int page_size = (LINES - grid_top);
2161 int pairs_max = (unsigned short) (-1);
2167 bool opt_acsc = FALSE;
2168 bool opt_bold = FALSE;
2169 bool opt_revs = FALSE;
2170 bool opt_wide = FALSE;
2171 bool opt_nums = FALSE;
2172 bool opt_xchr = FALSE;
2176 if (COLORS * COLORS == COLOR_PAIRS) {
2177 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2178 if (pairs_max > limit)
2181 if (pairs_max > COLOR_PAIRS)
2182 pairs_max = COLOR_PAIRS;
2188 /* this assumes an 80-column line */
2192 per_row = (COLORS > 8) ? 16 : 8;
2198 per_row -= min_colors;
2201 make_fullwidth_text(buffer, hello);
2205 make_narrow_text(buffer, hello);
2208 row_limit = (pairs_max + per_row - 1) / per_row;
2211 (void) printw("There are %d color pairs and %d colors%s\n",
2213 min_colors ? " besides 'default'" : "");
2216 MvPrintw(top + 1, 0,
2217 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2220 opt_bold ? "on" : "off");
2222 /* show color names/numbers across the top */
2223 for (i = 0; i < per_row; i++)
2224 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2226 /* show a grid of colors, with color names/ numbers on the left */
2227 for (i = (base_row * per_row); i < pairs_max; i++) {
2228 int row = grid_top + (i / per_row) - base_row;
2229 int col = (i % per_row + 1) * width;
2230 short pair = (short) i;
2232 if (row >= 0 && move(row, col) != ERR) {
2233 init_pair(pair, InxToFG(i), InxToBG(i));
2234 color_set(pair, NULL);
2236 attr_on((attr_t) A_ALTCHARSET, NULL);
2238 attr_on((attr_t) A_BOLD, NULL);
2240 attr_on((attr_t) A_REVERSE, NULL);
2243 sprintf(numbered, "{%02X}", i);
2245 make_fullwidth_text(buffer, numbered);
2247 make_narrow_text(buffer, numbered);
2250 addnwstr(buffer, width);
2251 (void) attr_set(A_NORMAL, 0, NULL);
2253 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2254 show_color_name(row, 0, InxToBG(i), opt_wide);
2262 switch (wGetchar(stdscr)) {
2291 set_color_test(opt_wide, FALSE);
2294 set_color_test(opt_wide, TRUE);
2304 if (base_row <= 0) {
2312 if (base_row + page_size >= row_limit) {
2321 if (base_row <= 0) {
2324 base_row -= (page_size - 1);
2332 if (base_row + page_size >= row_limit) {
2335 base_row += page_size - 1;
2336 if (base_row + page_size >= row_limit) {
2337 base_row = row_limit - page_size - 1;
2342 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2344 color_legend(helpwin, TRUE);
2358 #endif /* USE_WIDEC_SUPPORT */
2361 change_color(short current, int field, int value, int usebase)
2363 short red, green, blue;
2365 color_content(current, &red, &green, &blue);
2369 red = (short) (usebase ? (red + value) : value);
2372 green = (short) (usebase ? (green + value) : value);
2375 blue = (short) (usebase ? (blue + value) : value);
2379 if (init_color(current, red, green, blue) == ERR)
2384 init_all_colors(void)
2388 for (c = 0; c < COLORS; ++c)
2391 all_colors[c].green,
2392 all_colors[c].blue);
2395 #define scaled_rgb(n) ((255 * (n)) / 1000)
2399 /* display the color test pattern, without trying to edit colors */
2403 int this_c = 0, value = 0, field = 0;
2406 int page_size = (LINES - 6);
2411 for (i = 0; i < max_colors; i++)
2412 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2414 MvPrintw(LINES - 2, 0, "Number: %d", value);
2417 short red, green, blue;
2420 MvAddStr(0, 20, "Color RGB Value Editing");
2423 for (i = (short) top_color;
2424 (i - top_color < page_size)
2425 && (i < max_colors); i++) {
2428 sprintf(numeric, "[%d]", i);
2429 MvPrintw(2 + i - top_color, 0, "%c %-8s:",
2430 (i == current ? '>' : ' '),
2431 (i < (int) SIZEOF(the_color_names)
2432 ? the_color_names[i] : numeric));
2433 (void) attrset((attr_t) COLOR_PAIR(i));
2435 (void) attrset(A_NORMAL);
2437 color_content((short) i, &red, &green, &blue);
2439 if (current == i && field == 0)
2441 printw("%04d", red);
2442 if (current == i && field == 0)
2443 (void) attrset(A_NORMAL);
2445 if (current == i && field == 1)
2447 printw("%04d", green);
2448 if (current == i && field == 1)
2449 (void) attrset(A_NORMAL);
2451 if (current == i && field == 2)
2453 printw("%04d", blue);
2454 if (current == i && field == 2)
2455 (void) attrset(A_NORMAL);
2456 (void) attrset(A_NORMAL);
2457 printw(" ( %3d %3d %3d )",
2463 MvAddStr(LINES - 3, 0,
2464 "Use up/down to select a color, left/right to change fields.");
2465 MvAddStr(LINES - 2, 0,
2466 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2468 move(2 + current - top_color, 0);
2472 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2479 current -= (page_size - 1);
2486 if (current < (max_colors - 1))
2487 current += (page_size - 1);
2494 current = (current == 0 ? (max_colors - 1) : current - 1);
2499 current = (current == (max_colors - 1) ? 0 : current + 1);
2503 field = (field == 2 ? 0 : field + 1);
2507 field = (field == 0 ? 2 : field - 1);
2520 value = value * 10 + (this_c - '0');
2524 change_color((short) current, field, value, 1);
2528 change_color((short) current, field, -value, 1);
2532 change_color((short) current, field, value, 0);
2537 P(" RGB Value Editing Help");
2539 P("You are in the RGB value editor. Use the arrow keys to select one of");
2540 P("the fields in one of the RGB triples of the current colors; the one");
2541 P("currently selected will be reverse-video highlighted.");
2543 P("To change a field, enter the digits of the new value; they are echoed");
2544 P("as entered. Finish by typing `='. The change will take effect instantly.");
2545 P("To increment or decrement a value, use the same procedure, but finish");
2546 P("with a `+' or `-'.");
2548 P("Press 'm' to invoke the top-level menu with the current color settings.");
2549 P("To quit, do ESC");
2558 for (i = 0; i < max_colors; i++)
2559 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2573 if (current >= max_colors)
2574 current = max_colors - 1;
2575 if (current < top_color)
2576 top_color = current;
2577 if (current - top_color >= page_size)
2578 top_color = current - (page_size - 1);
2580 MvPrintw(LINES - 1, 0, "Number: %d", value);
2588 * ncurses does not reset each color individually when calling endwin().
2595 /****************************************************************************
2597 * Alternate character-set stuff
2599 ****************************************************************************/
2604 } attrs_to_cycle[] = {
2605 { A_NORMAL, "normal" },
2607 { A_BLINK, "blink" },
2608 { A_REVERSE, "reverse" },
2609 { A_UNDERLINE, "underline" },
2614 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2620 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2625 *at_code = SIZEOF(attrs_to_cycle) - 1;
2634 *attr = attrs_to_cycle[*at_code].attr;
2639 cycle_colors(int ch, int *fg, int *bg, short *pair)
2641 bool result = FALSE;
2651 if ((*fg += 1) >= COLORS)
2659 if ((*bg += 1) >= COLORS)
2667 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2670 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2679 /****************************************************************************
2681 * Soft-key label test
2683 ****************************************************************************/
2688 #define SLK_WORK (SLK_HELP + 3)
2693 static const char *table[] =
2695 "Available commands are:"
2697 ,"^L -- repaint this message and activate soft keys"
2698 ,"a/d -- activate/disable soft keys"
2699 ,"c -- set centered format for labels"
2700 ,"l -- set left-justified format for labels"
2701 ,"r -- set right-justified format for labels"
2702 ,"[12345678] -- set label; labels are numbered 1 through 8"
2703 ,"e -- erase stdscr (should not erase labels)"
2704 ,"s -- test scrolling of shortened screen"
2705 ,"v/V -- cycle through video attributes"
2707 ,"F/f/B/b -- cycle through foreground/background colors"
2709 ,"ESC -- return to main menu"
2711 ,"Note: if activating the soft keys causes your terminal to scroll up"
2712 ,"one line, your terminal auto-scrolls when anything is written to the"
2713 ,"last screen position. The ncurses code does not yet handle this"
2719 for (j = 0; j < SIZEOF(table); ++j) {
2727 call_slk_color(int fg, int bg)
2729 init_pair(1, (short) bg, (short) fg);
2731 MvPrintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2741 /* exercise the soft keys */
2746 chtype attr = A_NORMAL;
2747 unsigned at_code = 0;
2749 int fg = COLOR_BLACK;
2750 int bg = COLOR_WHITE;
2757 call_slk_color(fg, bg);
2767 MvAddStr(0, 20, "Soft Key Exerciser");
2782 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2783 while ((c = Getchar()) != 'Q' && (c != ERR))
2811 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2813 if ((s = slk_label(c - '0')) != 0) {
2816 wGetstring(stdscr, buf, 8);
2817 slk_set((c - '0'), buf, fmt);
2826 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2828 wnoutrefresh(stdscr);
2833 if (cycle_attr(c, &at_code, &attr)) {
2840 if (cycle_colors(c, &fg, &bg, &pair)) {
2842 call_slk_color(fg, bg);
2852 } while (!isQuit(c = Getchar()));
2860 #if USE_WIDEC_SUPPORT
2864 /* exercise the soft keys */
2867 wchar_t buf[SLKLEN + 1];
2869 chtype attr = A_NORMAL;
2870 unsigned at_code = 0;
2871 int fg = COLOR_BLACK;
2872 int bg = COLOR_WHITE;
2877 call_slk_color(fg, bg);
2884 attr_on(WA_BOLD, NULL);
2885 MvAddStr(0, 20, "Soft Key Exerciser");
2886 attr_off(WA_BOLD, NULL);
2900 MvPrintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2901 while ((c = Getchar()) != 'Q' && (c != ERR))
2929 MvAddStr(SLK_WORK, 0, "Please enter the label value: ");
2931 if ((s = slk_label(c - '0')) != 0) {
2932 char *temp = strdup(s);
2933 size_t used = strlen(temp);
2934 size_t want = SLKLEN;
2936 #ifndef state_unused
2941 while (want > 0 && used != 0) {
2942 const char *base = s;
2943 reset_mbytes(state);
2944 test = count_mbytes(base, 0, &state);
2945 if (test == (size_t) -1) {
2947 } else if (test > want) {
2950 reset_mbytes(state);
2951 trans_mbytes(buf, base, want, &state);
2957 wGet_wstring(stdscr, buf, SLKLEN);
2958 slk_wset((c - '0'), buf, fmt);
2969 fg = (short) ((fg + 1) % COLORS);
2970 call_slk_color(fg, bg);
2975 bg = (short) ((bg + 1) % COLORS);
2976 call_slk_color(fg, bg);
2979 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2981 wnoutrefresh(stdscr);
2985 if (cycle_attr(c, &at_code, &attr)) {
2986 slk_attr_set(attr, (short) (fg || bg), NULL);
2992 if (cycle_colors(c, &fg, &bg, &pair)) {
2994 call_slk_color(fg, bg);
3004 } while (!isQuit(c = Getchar()));
3012 #endif /* SLK_INIT */
3014 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
3015 * terminal to perform functions. The remaining codes can be graphic.
3018 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
3020 bool C1 = (first == 128);
3022 unsigned last = first + 31;
3027 MvPrintw(0, 20, "Display of %s Character Codes %d to %d",
3028 C1 ? "C1" : "GR", first, last);
3032 for (code = first; code <= last; code++) {
3034 int row = 2 + ((int) (code - first) % 16);
3035 int col = ((int) (code - first) / 16) * COLS / 2;
3037 sprintf(tmp, "%3u (0x%x)", code, code);
3038 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3042 nodelay(stdscr, TRUE);
3043 echochar(colored_chtype(code, attr, pair));
3045 /* (yes, this _is_ crude) */
3046 while ((reply = Getchar()) != ERR) {
3047 addch(UChar(reply));
3050 nodelay(stdscr, FALSE);
3052 } while (--count > 0);
3059 show_pc_chars(int repeat, attr_t attr, short pair)
3065 MvPrintw(0, 20, "Display of PC Character Codes");
3069 for (code = 0; code < 16; ++code) {
3070 MvPrintw(2, (int) code * PC_COLS + 8, "%X", code);
3072 for (code = 0; code < 256; code++) {
3074 int row = 3 + (int) (code / 16) + (code >= 128);
3075 int col = 8 + (int) (code % 16) * PC_COLS;
3076 if ((code % 16) == 0)
3077 MvPrintw(row, 0, "0x%02x:", code);
3088 * Skip the ones that do not work.
3092 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3095 } while (--count > 0);
3100 show_box_chars(int repeat, attr_t attr, short pair)
3104 attr |= (attr_t) COLOR_PAIR(pair);
3108 MvAddStr(0, 20, "Display of the ACS Line-Drawing Set");
3113 colored_chtype(ACS_VLINE, attr, pair),
3114 colored_chtype(ACS_VLINE, attr, pair),
3115 colored_chtype(ACS_HLINE, attr, pair),
3116 colored_chtype(ACS_HLINE, attr, pair),
3117 colored_chtype(ACS_ULCORNER, attr, pair),
3118 colored_chtype(ACS_URCORNER, attr, pair),
3119 colored_chtype(ACS_LLCORNER, attr, pair),
3120 colored_chtype(ACS_LRCORNER, attr, pair));
3121 MvHLine(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3122 MvVLine(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3123 MvAddCh(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3124 MvAddCh(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3125 MvAddCh(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3126 MvAddCh(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3127 MvAddCh(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3133 show_1_acs(int n, int repeat, const char *name, chtype code)
3135 const int height = 16;
3136 int row = 2 + (n % height);
3137 int col = (n / height) * COLS / 2;
3139 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3142 } while (--repeat > 0);
3147 show_acs_chars(int repeat, attr_t attr, short pair)
3148 /* display the ACS character set */
3152 #define BOTH(name) #name, colored_chtype(name, attr, (chtype) pair)
3156 MvAddStr(0, 20, "Display of the ACS Character Set");
3160 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3161 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3162 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3163 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3165 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3166 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3167 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3168 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3170 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3171 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3174 * HPUX's ACS definitions are broken here. Just give up.
3176 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3177 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3178 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3179 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3180 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3182 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3183 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3184 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3185 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3186 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3187 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3188 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3189 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3190 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3192 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3193 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3194 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3196 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3197 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3198 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3199 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3200 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3201 (void) show_1_acs(n, repeat, BOTH(ACS_S9));
3209 char *term = getenv("TERM");
3210 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3213 chtype attr = A_NORMAL;
3216 int fg = COLOR_BLACK;
3217 int bg = COLOR_BLACK;
3218 unsigned at_code = 0;
3220 void (*last_show_acs) (int, attr_t, short) = 0;
3228 ToggleAcs(last_show_acs, show_acs_chars);
3232 ToggleAcs(last_show_acs, show_pc_chars);
3237 ToggleAcs(last_show_acs, show_box_chars);
3263 if (repeat < (COLS / 4))
3271 if (cycle_attr(c, &at_code, &attr)
3272 || cycle_colors(c, &fg, &bg, &pair)) {
3279 if (last_show_acs != 0)
3280 last_show_acs(repeat, attr, pair);
3282 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3284 MvPrintw(LINES - 3, 0,
3285 "Note: ANSI terminals may not display C1 characters.");
3286 MvPrintw(LINES - 2, 0,
3287 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3290 MvPrintw(LINES - 1, 0,
3291 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3292 attrs_to_cycle[at_code].name,
3295 MvPrintw(LINES - 1, 0,
3296 "v/V cycles through video attributes (%s).",
3297 attrs_to_cycle[at_code].name);
3300 } while (!isQuit(c = Getchar()));
3307 #if USE_WIDEC_SUPPORT
3309 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3315 TEST_CCHAR(src, count, {
3316 attr |= (test_attrs & A_ALTCHARSET);
3317 setcchar(dst, test_wch, attr, pair, NULL);
3327 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3331 int last = first + 31;
3335 MvPrintw(0, 20, "Display of Character Codes %d to %d", first, last);
3338 for (code = first; (int) code <= last; code++) {
3339 int row = 2 + ((code - first) % 16);
3340 int col = ((code - first) / 16) * COLS / 2;
3346 memset(&codes, 0, sizeof(codes));
3348 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3349 MvPrintw(row, col, "%*s: ", COLS / 4, tmp);
3350 setcchar(&temp, codes, attr, pair, 0);
3353 * Give non-spacing characters something to combine with. If we
3354 * don't, they'll bunch up in a heap on the space after the ":".
3355 * Mark them with reverse-video to make them simpler to find on
3358 if (wcwidth(code) == 0) {
3359 addch((chtype) space |
3360 (A_REVERSE ^ attr) |
3361 (attr_t) COLOR_PAIR(pair));
3364 * This could use add_wch(), but is done for comparison with the
3365 * normal 'f' test (and to make a test-case for echo_wchar()).
3366 * The screen will flicker because the erase() at the top of the
3367 * function is met by the builtin refresh() in echo_wchar().
3371 * The repeat-count may make text wrap - avoid that.
3373 getyx(stdscr, y, x);
3375 if (x >= col + (COLS / 2) - 2)
3377 } while (--count > 0);
3382 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3384 const int height = 16;
3385 int row = 2 + (n % height);
3386 int col = (n / height) * COLS / 2;
3388 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3389 while (--repeat >= 0) {
3395 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3398 show_wacs_chars(int repeat, attr_t attr, short pair)
3399 /* display the wide-ACS character set */
3405 /*#define BOTH2(name) #name, &(name) */
3406 #define BOTH2(name) #name, MERGE_ATTR(name)
3410 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3414 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3415 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3416 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3417 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3419 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3420 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3421 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3422 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3424 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3425 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3427 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3428 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3429 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3430 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3432 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3433 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3434 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3435 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3436 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3437 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3438 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3439 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3440 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3442 #ifdef CURSES_WACS_ARRAY
3443 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3444 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3445 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3447 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3448 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3449 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3450 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3451 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3452 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3458 show_wacs_chars_double(int repeat, attr_t attr, short pair)
3459 /* display the wide-ACS character set */
3465 /*#define BOTH2(name) #name, &(name) */
3466 #define BOTH2(name) #name, MERGE_ATTR(name)
3470 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3474 n = show_1_wacs(0, repeat, BOTH2(WACS_D_ULCORNER));
3475 n = show_1_wacs(n, repeat, BOTH2(WACS_D_URCORNER));
3476 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LLCORNER));
3477 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LRCORNER));
3479 n = show_1_wacs(n, repeat, BOTH2(WACS_D_LTEE));
3480 n = show_1_wacs(n, repeat, BOTH2(WACS_D_RTEE));
3481 n = show_1_wacs(n, repeat, BOTH2(WACS_D_TTEE));
3482 n = show_1_wacs(n, repeat, BOTH2(WACS_D_BTEE));
3484 n = show_1_wacs(n, repeat, BOTH2(WACS_D_HLINE));
3485 n = show_1_wacs(n, repeat, BOTH2(WACS_D_VLINE));
3487 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3488 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3489 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3490 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3492 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3493 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3494 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3495 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3496 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3497 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3498 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3499 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3500 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3502 #ifdef CURSES_WACS_ARRAY
3503 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3504 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3505 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3507 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3508 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3509 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3510 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3511 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3512 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3519 show_wacs_chars_thick(int repeat, attr_t attr, short pair)
3520 /* display the wide-ACS character set */
3526 /*#define BOTH2(name) #name, &(name) */
3527 #define BOTH2(name) #name, MERGE_ATTR(name)
3531 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3535 n = show_1_wacs(0, repeat, BOTH2(WACS_T_ULCORNER));
3536 n = show_1_wacs(n, repeat, BOTH2(WACS_T_URCORNER));
3537 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LLCORNER));
3538 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LRCORNER));
3540 n = show_1_wacs(n, repeat, BOTH2(WACS_T_LTEE));
3541 n = show_1_wacs(n, repeat, BOTH2(WACS_T_RTEE));
3542 n = show_1_wacs(n, repeat, BOTH2(WACS_T_TTEE));
3543 n = show_1_wacs(n, repeat, BOTH2(WACS_T_BTEE));
3545 n = show_1_wacs(n, repeat, BOTH2(WACS_T_HLINE));
3546 n = show_1_wacs(n, repeat, BOTH2(WACS_T_VLINE));
3548 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3549 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3550 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3551 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3553 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3554 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3555 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3556 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3557 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3558 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3559 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3560 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3561 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3563 #ifdef CURSES_WACS_ARRAY
3564 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3565 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3566 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3568 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3569 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3570 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3571 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3572 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3573 (void) show_1_wacs(n, repeat, BOTH2(WACS_S9));
3580 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3583 show_wbox_chars(int repeat, attr_t attr, short pair)
3590 MvAddStr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3595 MERGE_ATTR(0, WACS_VLINE),
3596 MERGE_ATTR(1, WACS_VLINE),
3597 MERGE_ATTR(2, WACS_HLINE),
3598 MERGE_ATTR(3, WACS_HLINE),
3599 MERGE_ATTR(4, WACS_ULCORNER),
3600 MERGE_ATTR(5, WACS_URCORNER),
3601 MERGE_ATTR(6, WACS_LLCORNER),
3602 MERGE_ATTR(7, WACS_LRCORNER));
3604 (void) mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3605 (void) mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3606 (void) mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3607 (void) mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3608 (void) mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3609 (void) mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3610 (void) mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3618 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3620 const int height = 16;
3621 int row = 2 + (n % height);
3622 int col = (n / height) * COLS / 2;
3625 MvPrintw(row, col, "%*s : ", COLS / 4, name);
3626 (void) attr_set(attr, pair, 0);
3627 addstr(strcpy(temp, code));
3628 (void) attr_set(A_NORMAL, 0, 0);
3632 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3635 show_utf8_chars(int repeat, attr_t attr, short pair)
3642 MvAddStr(0, 20, "Display of the Wide-ACS Character Set");
3646 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3647 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3648 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3649 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3651 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3652 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3653 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3654 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3656 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3657 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3659 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3660 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3661 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3662 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3664 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3665 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3666 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3667 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3668 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3669 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3670 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3671 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3672 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3673 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3674 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3675 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3677 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3678 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3679 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3680 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3681 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3682 (void) SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3687 /* display the wide-ACS character set */
3689 wide_acs_display(void)
3695 chtype attr = A_NORMAL;
3696 int fg = COLOR_BLACK;
3697 int bg = COLOR_BLACK;
3698 unsigned at_code = 0;
3700 void (*last_show_wacs) (int, attr_t, short) = 0;
3708 ToggleAcs(last_show_wacs, show_wacs_chars);
3712 ToggleAcs(last_show_wacs, show_wacs_chars_double);
3717 ToggleAcs(last_show_wacs, show_wacs_chars_thick);
3721 ToggleAcs(last_show_wacs, show_wbox_chars);
3724 ToggleAcs(last_show_wacs, show_utf8_chars);
3727 if (c < 256 && isdigit(c)) {
3730 } else if (c == '+') {
3733 } else if (c == '-' && digit > 0) {
3736 } else if (c == '>' && repeat < (COLS / 4)) {
3738 } else if (c == '<' && repeat > 1) {
3740 } else if (c == '_') {
3741 space = (space == ' ') ? '_' : ' ';
3743 } else if (cycle_attr(c, &at_code, &attr)
3744 || cycle_colors(c, &fg, &bg, &pair)) {
3745 if (last_show_wacs != 0)
3753 if (last_show_wacs != 0)
3754 last_show_wacs(repeat, attr, pair);
3756 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3758 MvPrintw(LINES - 3, 0,
3759 "Select: a/d/t WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3761 MvPrintw(LINES - 2, 0,
3762 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3763 attrs_to_cycle[at_code].name,
3766 MvPrintw(LINES - 2, 0,
3767 "v/V cycles through video attributes (%s).",
3768 attrs_to_cycle[at_code].name);
3771 } while (!isQuit(c = Getchar()));
3781 * Graphic-rendition test (adapted from vttest)
3784 test_sgr_attributes(void)
3788 for (pass = 0; pass < 2; pass++) {
3789 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3791 /* Use non-default colors if possible to exercise bce a little */
3793 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3794 normal |= COLOR_PAIR(1);
3798 MvPrintw(1, 20, "Graphic rendition test pattern:");
3800 MvPrintw(4, 1, "vanilla");
3802 #define set_sgr(mask) bkgdset((normal^(mask)));
3804 MvPrintw(4, 40, "bold");
3806 set_sgr(A_UNDERLINE);
3807 MvPrintw(6, 6, "underline");
3809 set_sgr(A_BOLD | A_UNDERLINE);
3810 MvPrintw(6, 45, "bold underline");
3813 MvPrintw(8, 1, "blink");
3815 set_sgr(A_BLINK | A_BOLD);
3816 MvPrintw(8, 40, "bold blink");
3818 set_sgr(A_UNDERLINE | A_BLINK);
3819 MvPrintw(10, 6, "underline blink");
3821 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3822 MvPrintw(10, 45, "bold underline blink");
3825 MvPrintw(12, 1, "negative");
3827 set_sgr(A_BOLD | A_REVERSE);
3828 MvPrintw(12, 40, "bold negative");
3830 set_sgr(A_UNDERLINE | A_REVERSE);
3831 MvPrintw(14, 6, "underline negative");
3833 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3834 MvPrintw(14, 45, "bold underline negative");
3836 set_sgr(A_BLINK | A_REVERSE);
3837 MvPrintw(16, 1, "blink negative");
3839 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3840 MvPrintw(16, 40, "bold blink negative");
3842 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3843 MvPrintw(18, 6, "underline blink negative");
3845 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3846 MvPrintw(18, 45, "bold underline blink negative");
3849 MvPrintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3855 bkgdset(A_NORMAL | BLANK);
3860 /****************************************************************************
3862 * Windows and scrolling tester.
3864 ****************************************************************************/
3866 #define BOTLINES 4 /* number of line stolen from screen bottom */
3872 #define FRAME struct frame
3881 #if defined(NCURSES_VERSION)
3882 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3883 #define is_keypad(win) (win)->_use_keypad
3884 #define is_scrollok(win) (win)->_scroll
3885 #elif !defined(is_keypad)
3886 #define is_keypad(win) FALSE
3887 #define is_scrollok(win) FALSE
3890 #define is_keypad(win) FALSE
3891 #define is_scrollok(win) FALSE
3895 frame_win(FRAME * curp)
3897 return (curp != 0) ? curp->wind : stdscr;
3900 /* We need to know if these flags are actually set, so don't look in FRAME.
3901 * These names are known to work with SVr4 curses as well as ncurses. The
3902 * _use_keypad name does not work with Solaris 8.
3905 HaveKeypad(FRAME * curp)
3907 WINDOW *win = frame_win(curp);
3909 return is_keypad(win);
3913 HaveScroll(FRAME * curp)
3915 WINDOW *win = frame_win(curp);
3917 return is_scrollok(win);
3921 newwin_legend(FRAME * curp)
3923 static const struct {
3928 "^C = create window", 0
3931 "^N = next window", 0
3934 "^P = previous window", 0
3937 "^F = scroll forward", 0
3940 "^B = scroll backward", 0
3943 "^K = keypad(%s)", 1
3946 "^S = scrollok(%s)", 2
3949 "^W = save window to file", 0
3952 "^R = restore window", 0
3965 bool do_keypad = HaveKeypad(curp);
3966 bool do_scroll = HaveScroll(curp);
3970 for (n = 0; n < SIZEOF(legend); n++) {
3971 switch (legend[n].code) {
3973 strcpy(buf, legend[n].msg);
3976 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3979 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3982 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3985 x = getcurx(stdscr);
3986 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3993 transient(FRAME * curp, NCURSES_CONST char *msg)
3995 newwin_legend(curp);
3997 MvAddStr(LINES - 1, 0, msg);
4003 printw("%s characters are echoed, window should %sscroll.",
4004 HaveKeypad(curp) ? "Non-arrow" : "All other",
4005 HaveScroll(curp) ? "" : "not ");
4010 newwin_report(FRAME * curp)
4011 /* report on the cursor's current position, then restore it */
4013 WINDOW *win = frame_win(curp);
4017 transient(curp, (char *) 0);
4019 move(LINES - 1, COLS - 17);
4020 printw("Y = %2d X = %2d", y, x);
4028 selectcell(int uli, int ulj, int lri, int lrj)
4029 /* arrows keys move cursor, return location at current on non-arrow key */
4031 static pair res; /* result cell */
4032 int si = lri - uli + 1; /* depth of the select area */
4033 int sj = lrj - ulj + 1; /* width of the select area */
4034 int i = 0, j = 0; /* offsets into the select area */
4039 move(uli + i, ulj + j);
4040 newwin_report((FRAME *) 0);
4042 switch (Getchar()) {
4056 return ((pair *) 0);
4057 #ifdef NCURSES_MOUSE_VERSION
4063 if (event.y > uli && event.x > ulj) {
4084 outerbox(pair ul, pair lr, bool onoff)
4085 /* draw or erase a box *outside* the given pair of corners */
4087 MvAddCh(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
4088 MvAddCh(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
4089 MvAddCh(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
4090 MvAddCh(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
4091 move(ul.y - 1, ul.x);
4092 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4093 move(ul.y, ul.x - 1);
4094 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4095 move(lr.y + 1, ul.x);
4096 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
4097 move(ul.y, lr.x + 1);
4098 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
4103 /* Ask user for a window definition */
4110 addstr("Use arrows to move cursor, anything else to mark corner 1");
4112 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
4113 return ((WINDOW *) 0);
4114 memcpy(&ul, tmp, sizeof(pair));
4115 MvAddCh(ul.y - 1, ul.x - 1, ACS_ULCORNER);
4118 addstr("Use arrows to move cursor, anything else to mark corner 2");
4120 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
4122 return ((WINDOW *) 0);
4123 memcpy(&lr, tmp, sizeof(pair));
4125 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
4127 outerbox(ul, lr, TRUE);
4138 newwin_move(FRAME * curp, int dy, int dx)
4140 WINDOW *win = frame_win(curp);
4144 getyx(win, cur_y, cur_x);
4145 getmaxyx(win, max_y, max_x);
4146 if ((cur_x += dx) < 0)
4148 else if (cur_x >= max_x)
4150 if ((cur_y += dy) < 0)
4152 else if (cur_y >= max_y)
4154 wmove(win, cur_y, cur_x);
4158 delete_framed(FRAME * fp, bool showit)
4163 fp->last->next = fp->next;
4164 fp->next->last = fp->last;
4172 np = (fp == fp->next) ? 0 : fp->next;
4179 acs_and_scroll(void)
4180 /* Demonstrate windows */
4183 FRAME *current = (FRAME *) 0, *neww;
4185 #if HAVE_PUTWIN && HAVE_GETWIN
4189 #define DUMPFILE "screendump"
4191 #ifdef NCURSES_MOUSE_VERSION
4192 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
4197 transient((FRAME *) 0, (char *) 0);
4200 if ((neww = typeCalloc(FRAME, 1)) == 0) {
4203 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4208 if (current == 0) { /* First element, */
4209 neww->next = neww; /* so point it at itself */
4212 neww->next = current->next;
4213 neww->last = current;
4214 neww->last->next = neww;
4215 neww->next->last = neww;
4218 /* SVr4 curses sets the keypad on all newly-created windows to
4219 * false. Someone reported that PDCurses makes new windows inherit
4220 * this flag. Remove the following 'keypad()' call to test this
4222 keypad(current->wind, TRUE);
4223 current->do_keypad = HaveKeypad(current);
4224 current->do_scroll = HaveScroll(current);
4227 case CTRL('N'): /* go to next window */
4229 current = current->next;
4232 case CTRL('P'): /* go to previous window */
4234 current = current->last;
4237 case CTRL('F'): /* scroll current window forward */
4239 wscrl(frame_win(current), 1);
4242 case CTRL('B'): /* scroll current window backwards */
4244 wscrl(frame_win(current), -1);
4247 case CTRL('K'): /* toggle keypad mode for current */
4249 current->do_keypad = !current->do_keypad;
4250 keypad(current->wind, current->do_keypad);
4256 current->do_scroll = !current->do_scroll;
4257 scrollok(current->wind, current->do_scroll);
4261 #if HAVE_PUTWIN && HAVE_GETWIN
4262 case CTRL('W'): /* save and delete window */
4263 if ((current != 0) && (current == current->next)) {
4264 transient(current, "Will not save/delete ONLY window");
4266 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4267 transient(current, "Can't open screen dump file");
4269 (void) putwin(frame_win(current), fp);
4272 current = delete_framed(current, TRUE);
4276 case CTRL('R'): /* restore window */
4277 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4278 transient(current, "Can't open screen dump file");
4280 if ((neww = typeCalloc(FRAME, 1)) != 0) {
4282 neww->next = current ? current->next : 0;
4283 neww->last = current;
4284 if (neww->last != 0)
4285 neww->last->next = neww;
4286 if (neww->next != 0)
4287 neww->next->last = neww;
4289 neww->wind = getwin(fp);
4291 wrefresh(neww->wind);
4299 case CTRL('X'): /* resize window */
4306 addstr("Use arrows to move cursor, anything else to mark new corner");
4309 getbegyx(current->wind, ul.y, ul.x);
4311 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4312 if (tmp == (pair *) 0) {
4317 getmaxyx(current->wind, lr.y, lr.x);
4320 outerbox(ul, lr, FALSE);
4321 wnoutrefresh(stdscr);
4323 /* strictly cosmetic hack for the test */
4324 getmaxyx(current->wind, my, mx);
4325 if (my > tmp->y - ul.y) {
4326 getyx(current->wind, lr.y, lr.x);
4327 wmove(current->wind, tmp->y - ul.y + 1, 0);
4328 wclrtobot(current->wind);
4329 wmove(current->wind, lr.y, lr.x);
4331 if (mx > tmp->x - ul.x)
4332 for (i = 0; i < my; i++) {
4333 wmove(current->wind, i, tmp->x - ul.x + 1);
4334 wclrtoeol(current->wind);
4336 wnoutrefresh(current->wind);
4338 memcpy(&lr, tmp, sizeof(pair));
4339 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4341 getbegyx(current->wind, ul.y, ul.x);
4342 getmaxyx(current->wind, lr.y, lr.x);
4345 outerbox(ul, lr, TRUE);
4346 wnoutrefresh(stdscr);
4348 wnoutrefresh(current->wind);
4354 #endif /* HAVE_WRESIZE */
4356 case KEY_F(10): /* undocumented --- use this to test area clears */
4357 selectcell(0, 0, LINES - 1, COLS - 1);
4363 newwin_move(current, -1, 0);
4366 newwin_move(current, 1, 0);
4369 newwin_move(current, 0, -1);
4372 newwin_move(current, 0, 1);
4380 getyx(frame_win(current), y, x);
4384 x = getmaxx(frame_win(current)) - 1;
4386 (void) mvwdelch(frame_win(current), y, x);
4396 waddch(current->wind, (chtype) c);
4401 newwin_report(current);
4402 usescr = frame_win(current);
4405 (!isQuit(c = wGetchar(usescr))
4409 while (current != 0)
4410 current = delete_framed(current, FALSE);
4412 scrollok(stdscr, TRUE); /* reset to driver's default */
4413 #ifdef NCURSES_MOUSE_VERSION
4414 mousemask(0, (mmask_t *) 0);
4421 /****************************************************************************
4425 ****************************************************************************/
4428 static int nap_msec = 1;
4430 static NCURSES_CONST char *mod[] =
4440 /*+-------------------------------------------------------------------------
4442 --------------------------------------------------------------------------*/
4444 wait_a_while(int msec GCC_UNUSED)
4454 else if (msec > 1000)
4455 sleep((unsigned) msec / 1000);
4459 } /* end of wait_a_while */
4461 /*+-------------------------------------------------------------------------
4463 --------------------------------------------------------------------------*/
4465 saywhat(NCURSES_CONST char *text)
4467 wmove(stdscr, LINES - 1, 0);
4469 if (text != 0 && *text != '\0') {
4470 waddstr(stdscr, text);
4471 waddstr(stdscr, "; ");
4473 waddstr(stdscr, "press any key to continue");
4474 } /* end of saywhat */
4476 /*+-------------------------------------------------------------------------
4477 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4478 --------------------------------------------------------------------------*/
4480 mkpanel(short color, int rows, int cols, int tly, int tlx)
4485 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4486 if ((pan = new_panel(win)) == 0) {
4488 } else if (use_colors) {
4489 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4492 init_pair(color, fg, bg);
4493 wbkgdset(win, (attr_t) (COLOR_PAIR(color) | ' '));
4495 wbkgdset(win, A_BOLD | ' ');
4499 } /* end of mkpanel */
4501 /*+-------------------------------------------------------------------------
4503 --------------------------------------------------------------------------*/
4505 rmpanel(PANEL * pan)
4507 WINDOW *win = panel_window(pan);
4510 } /* end of rmpanel */
4512 /*+-------------------------------------------------------------------------
4514 --------------------------------------------------------------------------*/
4520 } /* end of pflush */
4522 /*+-------------------------------------------------------------------------
4524 --------------------------------------------------------------------------*/
4530 for (y = 0; y < LINES - 1; y++) {
4531 for (x = 0; x < COLS; x++)
4532 wprintw(stdscr, "%d", (y + x) % 10);
4537 fill_panel(PANEL * pan)
4539 WINDOW *win = panel_window(pan);
4540 const char *userptr = (const char *) panel_userptr(pan);
4541 int num = (userptr && *userptr) ? userptr[1] : '?';
4545 wprintw(win, "-pan%c-", num);
4548 for (y = 2; y < getmaxy(win) - 1; y++) {
4549 for (x = 1; x < getmaxx(win) - 1; x++) {
4551 waddch(win, UChar(num));
4556 #if USE_WIDEC_SUPPORT
4558 init_wide_panel(void)
4563 for (digit = 0; digit < 10; ++digit)
4564 make_fullwidth_digit(&temp[digit], digit);
4568 getyx(stdscr, y, x);
4569 digit = (y + x / 2) % 10;
4570 } while (add_wch(&temp[digit]) != ERR);
4574 fill_wide_panel(PANEL * pan)
4576 WINDOW *win = panel_window(pan);
4577 const char *userptr = (const char *) panel_userptr(pan);
4578 int num = (userptr && *userptr) ? userptr[1] : '?';
4582 wprintw(win, "-pan%c-", num);
4585 for (y = 2; y < getmaxy(win) - 1; y++) {
4586 for (x = 1; x < getmaxx(win) - 1; x++) {
4588 waddch(win, UChar(num));
4594 #define MAX_PANELS 5
4597 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4599 int which = cmd[1] - '0';
4604 hide_panel(px[which]);
4607 show_panel(px[which]);
4610 top_panel(px[which]);
4613 bottom_panel(px[which]);
4620 wait_a_while(nap_msec);
4624 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4628 PANEL *px[MAX_PANELS + 1];
4630 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4634 for (count = 0; count < 5; count++) {
4635 px[1] = mkpanel(COLOR_RED,
4640 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4642 px[2] = mkpanel(COLOR_GREEN,
4647 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4649 px[3] = mkpanel(COLOR_YELLOW,
4654 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4656 px[4] = mkpanel(COLOR_BLUE,
4661 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4663 px[5] = mkpanel(COLOR_MAGENTA,
4668 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4680 wait_a_while(nap_msec);
4682 saywhat("h3 s1 s2 s4 s5");
4683 move_panel(px[1], 0, 0);
4690 wait_a_while(nap_msec);
4692 canned_panel(px, "s1");
4693 canned_panel(px, "s2");
4696 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4698 wait_a_while(nap_msec);
4700 canned_panel(px, "s3");
4703 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4705 wait_a_while(nap_msec);
4707 canned_panel(px, "b3");
4708 canned_panel(px, "s4");
4709 canned_panel(px, "s5");
4710 canned_panel(px, "t3");
4711 canned_panel(px, "t1");
4712 canned_panel(px, "t2");
4713 canned_panel(px, "t3");
4714 canned_panel(px, "t4");
4716 for (itmp = 0; itmp < 6; itmp++) {
4717 WINDOW *w4 = panel_window(px[4]);
4718 WINDOW *w5 = panel_window(px[5]);
4721 wmove(w4, LINES / 8, 1);
4722 waddstr(w4, mod[itmp]);
4723 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4724 wmove(w5, LINES / 6, 1);
4725 waddstr(w5, mod[itmp]);
4727 wait_a_while(nap_msec);
4730 wmove(w4, LINES / 6, 1);
4731 waddstr(w4, mod[itmp]);
4732 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4733 wmove(w5, LINES / 8, 1);
4734 waddstr(w5, mod[itmp]);
4736 wait_a_while(nap_msec);
4740 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4742 wait_a_while(nap_msec);
4744 canned_panel(px, "t5");
4745 canned_panel(px, "t2");
4746 canned_panel(px, "t1");
4747 canned_panel(px, "d2");
4748 canned_panel(px, "h3");
4749 canned_panel(px, "d1");
4750 canned_panel(px, "d4");
4751 canned_panel(px, "d5");
4752 canned_panel(px, "d3");
4754 wait_a_while(nap_msec);
4763 #endif /* USE_LIBPANEL */
4765 /****************************************************************************
4769 ****************************************************************************/
4773 static bool pending_pan = FALSE;
4774 static bool show_panner_legend = TRUE;
4777 panner_legend(int line)
4779 static const char *const legend[] =
4781 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4782 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4783 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4784 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4786 int n = ((int) SIZEOF(legend) - (LINES - line));
4788 if (move(line, 0) != ERR) {
4789 if (show_panner_legend)
4790 printw("%s", legend[n]);
4792 return show_panner_legend;
4799 panner_h_cleanup(int from_y, int from_x, int to_x)
4801 if (!panner_legend(from_y))
4802 do_h_line(from_y, from_x, ' ', to_x);
4806 panner_v_cleanup(int from_y, int from_x, int to_y)
4808 if (!panner_legend(from_y))
4809 do_v_line(from_y, from_x, ' ', to_y);
4813 fill_pad(WINDOW *panpad, bool pan_lines)
4816 unsigned gridcount = 0;
4818 wmove(panpad, 0, 0);
4819 for (y = 0; y < getmaxy(panpad); y++) {
4820 for (x = 0; x < getmaxx(panpad); x++) {
4821 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4822 if (y == 0 && x == 0)
4823 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4825 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4826 else if (y == 0 || x == 0)
4827 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4829 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4830 (int) (gridcount++ % 26)));
4831 } else if (y % GRIDSIZE == 0)
4832 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4833 else if (x % GRIDSIZE == 0)
4834 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4836 waddch(panpad, ' ');
4843 int top_x, int top_y, int porty, int portx,
4844 int (*pgetc) (WINDOW *))
4846 #if HAVE_GETTIMEOFDAY
4847 struct timeval before, after;
4850 bool pan_lines = FALSE;
4851 bool scrollers = TRUE;
4854 int pxmax, pymax, lowend, highend, c;
4856 getmaxyx(pad, pymax, pxmax);
4857 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4861 #ifdef NCURSES_VERSION
4863 * During shell-out, the user may have resized the window. Adjust
4864 * the port size of the pad to accommodate this. Ncurses automatically
4865 * resizes all of the normal windows to fit on the new screen.
4883 show_panner_legend = !show_panner_legend;
4884 panner_legend(LINES - 4);
4885 panner_legend(LINES - 3);
4886 panner_legend(LINES - 2);
4887 panner_legend(LINES - 1);
4890 pan_lines = !pan_lines;
4891 fill_pad(pad, pan_lines);
4892 pending_pan = FALSE;
4895 #if HAVE_GETTIMEOFDAY
4899 panner_legend(LINES - 1);
4903 scrollers = !scrollers;
4906 /* Move the top-left corner of the pad, keeping the bottom-right
4909 case 'h': /* increase-columns: move left edge to left */
4913 panner_v_cleanup(top_y, top_x, porty);
4918 case 'j': /* decrease-lines: move top-edge down */
4922 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
4927 case 'k': /* increase-lines: move top-edge up */
4932 panner_h_cleanup(top_y, top_x, portx);
4936 case 'l': /* decrease-columns: move left-edge to right */
4940 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
4945 /* Move the bottom-right corner of the pad, keeping the top-left
4948 case KEY_IC: /* increase-columns: move right-edge to right */
4949 if (portx >= pxmax || portx >= COLS)
4952 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
4957 case KEY_IL: /* increase-lines: move bottom-edge down */
4958 if (porty >= pymax || porty >= LINES)
4961 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
4966 case KEY_DC: /* decrease-columns: move bottom edge up */
4971 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
4975 case KEY_DL: /* decrease-lines */
4980 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
4984 case KEY_LEFT: /* pan leftwards */
4991 case KEY_RIGHT: /* pan rightwards */
4992 if (basex + portx - (pymax > porty) < pxmax)
4998 case KEY_UP: /* pan upwards */
5005 case KEY_DOWN: /* pan downwards */
5006 if (basey + porty - (pxmax > portx) < pymax)
5021 basey = pymax - porty;
5031 MvAddCh(top_y - 1, top_x - 1, ACS_ULCORNER);
5032 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
5033 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
5035 if (scrollers && (pxmax > portx - 1)) {
5036 int length = (portx - top_x - 1);
5037 float ratio = ((float) length) / ((float) pxmax);
5039 lowend = (int) ((float) top_x + ((float) basex * ratio));
5040 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
5042 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
5043 if (highend < portx) {
5045 do_h_line(porty - 1, lowend, ' ', highend + 1);
5047 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
5050 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
5052 if (scrollers && (pymax > porty - 1)) {
5053 int length = (porty - top_y - 1);
5054 float ratio = ((float) length) / ((float) pymax);
5056 lowend = (int) ((float) top_y + ((float) basey * ratio));
5057 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
5059 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
5060 if (highend < porty) {
5062 do_v_line(lowend, portx - 1, ' ', highend + 1);
5064 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
5067 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
5069 MvAddCh(top_y - 1, portx - 1, ACS_URCORNER);
5070 MvAddCh(porty - 1, top_x - 1, ACS_LLCORNER);
5071 MvAddCh(porty - 1, portx - 1, ACS_LRCORNER);
5074 #if HAVE_GETTIMEOFDAY
5075 gettimeofday(&before, 0);
5077 wnoutrefresh(stdscr);
5082 porty - (pxmax > portx) - 1,
5083 portx - (pymax > porty) - 1);
5086 #if HAVE_GETTIMEOFDAY
5087 #define TIMEVAL2S(data) ((double) data.tv_sec + ((double) data.tv_usec / 1.0e6))
5090 gettimeofday(&after, 0);
5091 elapsed = (TIMEVAL2S(after) - TIMEVAL2S(before));
5092 move(LINES - 1, COLS - 12);
5093 printw("Secs: %2.03f", elapsed);
5100 ((c = pgetc(pad)) != KEY_EXIT);
5102 scrollok(stdscr, TRUE); /* reset to driver's default */
5106 padgetch(WINDOW *win)
5112 if ((pending_pan = (count > 0)) != FALSE) {
5114 pending_pan = (count != 0);
5117 switch (c = wGetchar(win)) {
5153 case ERR: /* FALLTHRU */
5159 if (c >= '0' && c <= '9') {
5160 count = count * 10 + (c - '0');
5174 #define PAD_HIGH 200
5175 #define PAD_WIDE 200
5179 /* Demonstrate pads. */
5181 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
5184 Cannot("cannot create requested pad");
5188 fill_pad(panpad, FALSE);
5190 panner_legend(LINES - 4);
5191 panner_legend(LINES - 3);
5192 panner_legend(LINES - 2);
5193 panner_legend(LINES - 1);
5195 keypad(panpad, TRUE);
5197 /* Make the pad (initially) narrow enough that a trace file won't wrap.
5198 * We'll still be able to widen it during a test, since that's required
5199 * for testing boundaries.
5201 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
5208 /****************************************************************************
5210 * Tests from John Burnell's PDCurses tester
5212 ****************************************************************************/
5215 Continue(WINDOW *win)
5219 MvWAddStr(win, 10, 1, " Press any key to continue");
5225 flushinp_test(WINDOW *win)
5226 /* Input test, adapted from John Burnell's PDCurses tester */
5228 int w, h, bx, by, sw, sh, i;
5233 getmaxyx(win, h, w);
5234 getbegyx(win, by, bx);
5237 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5242 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5243 wbkgd(subWin, (chtype) (COLOR_PAIR(2) | ' '));
5246 (void) wattrset(subWin, A_BOLD);
5247 box(subWin, ACS_VLINE, ACS_HLINE);
5248 MvWAddStr(subWin, 2, 1, "This is a subwindow");
5252 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5253 * it only happened to "work" on SVr4 because that implementation does not
5254 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5255 * test behavior, we're using 'cbreak()', which will allow a single
5256 * character to return without needing a newline. - T.Dickey 1997/10/11.
5259 MvWAddStr(win, 0, 1, "This is a test of the flushinp() call.");
5261 MvWAddStr(win, 2, 1, "Type random keys for 5 seconds.");
5262 MvWAddStr(win, 3, 1,
5263 "These should be discarded (not echoed) after the subwindow goes away.");
5266 for (i = 0; i < 5; i++) {
5267 MvWPrintw(subWin, 1, 1, "Time = %d", i);
5279 MvWAddStr(win, 2, 1,
5280 "If you were still typing when the window timer expired,");
5281 MvWAddStr(win, 3, 1,
5282 "or else you typed nothing at all while it was running,");
5283 MvWAddStr(win, 4, 1,
5284 "test was invalid. You'll see garbage or nothing at all. ");
5285 MvWAddStr(win, 6, 1, "Press a key");
5291 MvWAddStr(win, 12, 0,
5292 "If you see any key other than what you typed, flushinp() is broken.");
5301 "What you typed should now have been deleted; if not, wdelch() failed.");
5307 /****************************************************************************
5311 ****************************************************************************/
5319 menu_virtualize(int c)
5321 if (c == '\n' || c == KEY_EXIT)
5322 return (MAX_COMMAND + 1);
5324 return (REQ_SCR_ULINE);
5326 return (REQ_SCR_DLINE);
5327 else if (c == 'b' || c == KEY_NPAGE)
5328 return (REQ_SCR_UPAGE);
5329 else if (c == 'f' || c == KEY_PPAGE)
5330 return (REQ_SCR_DPAGE);
5331 else if (c == 'n' || c == KEY_DOWN)
5332 return (REQ_NEXT_ITEM);
5333 else if (c == 'p' || c == KEY_UP)
5334 return (REQ_PREV_ITEM);
5336 return (REQ_TOGGLE_ITEM);
5344 static CONST_MENUS char *animals[] =
5357 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5358 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5366 ITEM *items[SIZEOF(animals)];
5368 CONST_MENUS char **ap;
5369 int mrows, mcols, c;
5372 #ifdef NCURSES_MOUSE_VERSION
5373 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5375 MvAddStr(0, 0, "This is the menu test:");
5376 MvAddStr(2, 0, " Use up and down arrow to move the select bar.");
5377 MvAddStr(3, 0, " 'n' and 'p' act like arrows.");
5379 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
5380 MvAddStr(5, 0, " Press return to exit.");
5383 for (ap = animals; *ap; ap++) {
5384 if ((*ip = new_item(*ap, "")) != 0)
5389 m = new_menu(items);
5391 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
5392 scale_menu(m, &mrows, &mcols);
5394 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5395 set_menu_win(m, menuwin);
5396 keypad(menuwin, TRUE);
5399 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5403 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
5404 if (c == E_NOT_POSTED)
5406 if (c == E_REQUEST_DENIED)
5411 MvPrintw(LINES - 2, 0,
5412 "You chose: %s\n", item_name(current_item(m)));
5413 (void) addstr("Press any key to continue...");
5420 for (ip = items; *ip; ip++)
5422 #ifdef NCURSES_MOUSE_VERSION
5423 mousemask(0, (mmask_t *) 0);
5428 #define T_TBL(name) { #name, name }
5434 T_TBL(TRACE_DISABLE),
5437 T_TBL(TRACE_UPDATE),
5439 T_TBL(TRACE_CHARPUT),
5440 T_TBL(TRACE_ORDINARY),
5442 T_TBL(TRACE_VIRTPUT),
5443 T_TBL(TRACE_IEVENT),
5445 T_TBL(TRACE_ICALLS),
5446 T_TBL(TRACE_CCALLS),
5447 T_TBL(TRACE_DATABASE),
5449 T_TBL(TRACE_MAXIMUM),
5456 tracetrace(unsigned tlevel)
5463 for (n = 0; t_tbl[n].name != 0; n++)
5464 need += strlen(t_tbl[n].name) + 2;
5465 buf = typeMalloc(char, need);
5467 sprintf(buf, "0x%02x = {", tlevel);
5469 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5471 for (n = 1; t_tbl[n].name != 0; n++)
5472 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5473 strcat(buf, t_tbl[n].name);
5477 if (buf[strlen(buf) - 2] == ',')
5478 buf[strlen(buf) - 2] = '\0';
5479 return (strcat(buf, "}"));
5482 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5486 run_trace_menu(MENU * m)
5492 bool changed = FALSE;
5493 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5494 case E_UNKNOWN_COMMAND:
5497 items = menu_items(m);
5498 i = current_item(m);
5499 if (i == items[0]) {
5500 if (item_value(i)) {
5501 for (p = items + 1; *p != 0; p++)
5502 if (item_value(*p)) {
5503 set_item_value(*p, FALSE);
5508 for (p = items + 1; *p != 0; p++)
5509 if (item_value(*p)) {
5510 set_item_value(items[0], FALSE);
5523 /* interactively set the trace level */
5526 ITEM *items[SIZEOF(t_tbl)];
5533 MvAddStr(0, 0, "Interactively set trace level:");
5534 MvAddStr(2, 0, " Press space bar to toggle a selection.");
5535 MvAddStr(3, 0, " Use up and down arrow to move the select bar.");
5536 MvAddStr(4, 0, " Press return to set the trace level.");
5537 MvPrintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5541 for (n = 0; t_tbl[n].name != 0; n++) {
5542 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
5548 m = new_menu(items);
5550 set_menu_format(m, 0, 2);
5551 scale_menu(m, &mrows, &mcols);
5553 menu_opts_off(m, O_ONEVALUE);
5554 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5555 set_menu_win(m, menuwin);
5556 keypad(menuwin, TRUE);
5559 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5563 for (ip = menu_items(m); *ip; ip++) {
5564 unsigned mask = t_tbl[item_index(*ip)].mask;
5566 set_item_value(*ip, _nc_tracing == 0);
5567 else if ((mask & _nc_tracing) == mask)
5568 set_item_value(*ip, TRUE);
5571 while (run_trace_menu(m))
5575 for (ip = menu_items(m); *ip; ip++)
5576 if (item_value(*ip))
5577 newtrace |= t_tbl[item_index(*ip)].mask;
5579 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5581 MvPrintw(LINES - 2, 0,
5582 "Trace level is %s\n", tracetrace(_nc_tracing));
5583 (void) addstr("Press any key to continue...");
5590 for (ip = items; *ip; ip++)
5594 #endif /* USE_LIBMENU */
5596 /****************************************************************************
5600 ****************************************************************************/
5603 make_label(int frow, int fcol, NCURSES_CONST char *label)
5605 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5608 set_field_buffer(f, 0, label);
5609 set_field_opts(f, (int) ((unsigned) field_opts(f) & ~O_ACTIVE));
5615 make_field(int frow, int fcol, int rows, int cols, bool secure)
5617 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5620 set_field_back(f, A_UNDERLINE);
5621 set_field_userptr(f, (void *) 0);
5627 display_form(FORM * f)
5632 scale_form(f, &rows, &cols);
5634 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5636 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5641 if (post_form(f) != E_OK)
5646 erase_form(FORM * f)
5648 WINDOW *w = form_win(f);
5649 WINDOW *s = form_sub(f);
5659 edit_secure(FIELD * me, int c)
5661 int rows, cols, frow, fcol, nrow, nbuf;
5663 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5665 char *source = field_buffer(me, 1);
5669 strcpy(temp, source ? source : "");
5670 len = (long) (char *) field_userptr(me);
5672 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5673 temp[len++] = (char) c;
5675 set_field_buffer(me, 1, temp);
5695 case REQ_RIGHT_CHAR:
5697 c = 0; /* we don't want to do inline editing */
5702 set_field_buffer(me, 1, temp);
5709 set_field_buffer(me, 1, temp);
5714 set_field_userptr(me, (void *) len);
5720 form_virtualize(FORM * f, WINDOW *w)
5723 static const struct {
5727 { CTRL('A'), REQ_NEXT_CHOICE },
5728 { CTRL('B'), REQ_PREV_WORD },
5729 { CTRL('C'), REQ_CLR_EOL },
5730 { CTRL('D'), REQ_DOWN_FIELD },
5731 { CTRL('E'), REQ_END_FIELD },
5732 { CTRL('F'), REQ_NEXT_PAGE },
5733 { CTRL('G'), REQ_DEL_WORD },
5734 { CTRL('H'), REQ_DEL_PREV },
5735 { CTRL('I'), REQ_INS_CHAR },
5736 { CTRL('K'), REQ_CLR_EOF },
5737 { CTRL('L'), REQ_LEFT_FIELD },
5738 { CTRL('M'), REQ_NEW_LINE },
5739 { CTRL('N'), REQ_NEXT_FIELD },
5740 { CTRL('O'), REQ_INS_LINE },
5741 { CTRL('P'), REQ_PREV_FIELD },
5742 { CTRL('R'), REQ_RIGHT_FIELD },
5743 { CTRL('S'), REQ_BEG_FIELD },
5744 { CTRL('U'), REQ_UP_FIELD },
5745 { CTRL('V'), REQ_DEL_CHAR },
5746 { CTRL('W'), REQ_NEXT_WORD },
5747 { CTRL('X'), REQ_CLR_FIELD },
5748 { CTRL('Y'), REQ_DEL_LINE },
5749 { CTRL('Z'), REQ_PREV_CHOICE },
5750 { ESCAPE, MAX_FORM_COMMAND + 1 },
5751 { KEY_BACKSPACE, REQ_DEL_PREV },
5752 { KEY_DOWN, REQ_DOWN_CHAR },
5753 { KEY_END, REQ_LAST_FIELD },
5754 { KEY_HOME, REQ_FIRST_FIELD },
5755 { KEY_LEFT, REQ_LEFT_CHAR },
5756 { KEY_LL, REQ_LAST_FIELD },
5757 { KEY_NEXT, REQ_NEXT_FIELD },
5758 { KEY_NPAGE, REQ_NEXT_PAGE },
5759 { KEY_PPAGE, REQ_PREV_PAGE },
5760 { KEY_PREVIOUS, REQ_PREV_FIELD },
5761 { KEY_RIGHT, REQ_RIGHT_CHAR },
5762 { KEY_UP, REQ_UP_CHAR },
5763 { QUIT, MAX_FORM_COMMAND + 1 }
5767 static int mode = REQ_INS_MODE;
5768 int c = wGetchar(w);
5770 FIELD *me = current_field(f);
5771 bool current = TRUE;
5773 if (c == CTRL(']')) {
5774 if (mode == REQ_INS_MODE) {
5775 mode = REQ_OVL_MODE;
5777 mode = REQ_INS_MODE;
5781 for (n = 0; n < SIZEOF(lookup); n++) {
5782 if (lookup[n].code == c) {
5783 c = lookup[n].result;
5788 MvPrintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5791 * Force the field that the user is typing into to be in reverse video,
5792 * while the other fields are shown underlined.
5807 case REQ_LEFT_FIELD:
5809 case REQ_RIGHT_CHAR:
5813 current = (c < KEY_MAX);
5817 c = edit_secure(me, c);
5818 set_field_back(me, A_REVERSE);
5820 c = edit_secure(me, c);
5821 set_field_back(me, A_UNDERLINE);
5827 my_form_driver(FORM * form, int c)
5829 if (c == (MAX_FORM_COMMAND + 1)
5830 && form_driver(form, REQ_VALIDATION) == E_OK)
5838 #ifdef NCURSES_VERSION
5839 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5840 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5842 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5843 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5847 * Allow a middle initial, optionally with a '.' to end it.
5850 FIELDCHECK_CB(mi_field_check)
5852 char *s = field_buffer(fld, 0);
5856 for (n = 0; s[n] != '\0'; ++n) {
5863 } else if (isspace(UChar(s[n]))) {
5868 if (!isspace(UChar(s[n])))
5874 /* force the form to display a leading capital */
5875 if (islower(UChar(s[0]))) {
5876 s[0] = (char) toupper(UChar(s[0]));
5877 set_field_buffer(fld, 0, s);
5883 CHAR_CHECK_CB(mi_char_check)
5885 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5889 * Passwords should be at least 6 characters.
5892 FIELDCHECK_CB(pw_field_check)
5894 char *s = field_buffer(fld, 0);
5897 for (n = 0; s[n] != '\0'; ++n) {
5898 if (isspace(UChar(s[n]))) {
5907 CHAR_CHECK_CB(pw_char_check)
5909 return (isgraph(ch) ? TRUE : FALSE);
5917 FIELD *f[12], *secure;
5918 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
5919 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
5920 int finished = 0, c;
5923 #ifdef NCURSES_MOUSE_VERSION
5924 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5928 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
5929 addstr("^N -- go to next field ^P -- go to previous field\n");
5930 addstr("Home -- go to first field End -- go to last field\n");
5931 addstr("^L -- go to field to left ^R -- go to field to right\n");
5932 addstr("^U -- move upward to field ^D -- move downward to field\n");
5933 addstr("^W -- go to next word ^B -- go to previous word\n");
5934 addstr("^S -- go to start of field ^E -- go to end of field\n");
5935 addstr("^H -- delete previous char ^Y -- delete line\n");
5936 addstr("^G -- delete current word ^C -- clear to end of line\n");
5937 addstr("^K -- clear to end of field ^X -- clear field\n");
5938 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
5940 MvAddStr(4, 57, "Forms Entry Test");
5944 /* describe the form */
5945 memset(f, 0, sizeof(f));
5946 f[n++] = make_label(0, 15, "Sample Form");
5948 f[n++] = make_label(2, 0, "Last Name");
5949 f[n++] = make_field(3, 0, 1, 18, FALSE);
5950 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5952 f[n++] = make_label(2, 20, "First Name");
5953 f[n++] = make_field(3, 20, 1, 12, FALSE);
5954 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5956 f[n++] = make_label(2, 34, "Middle Name");
5957 f[n++] = make_field(3, 34, 1, 12, FALSE);
5958 set_field_type(f[n - 1], fty_middle);
5960 f[n++] = make_label(5, 0, "Comments");
5961 f[n++] = make_field(6, 0, 4, 46, FALSE);
5963 f[n++] = make_label(5, 20, "Password:");
5965 f[n++] = make_field(5, 30, 1, 9, TRUE);
5966 set_field_type(f[n - 1], fty_passwd);
5969 if ((form = new_form(f)) != 0) {
5975 nonl(); /* lets us read ^M's */
5977 switch (form_driver(form, c = form_virtualize(form, w))) {
5979 MvAddStr(5, 57, field_buffer(secure, 1));
5983 case E_UNKNOWN_COMMAND:
5984 finished = my_form_driver(form, c);
5996 for (c = 0; f[c] != 0; c++)
5998 free_fieldtype(fty_middle);
5999 free_fieldtype(fty_passwd);
6003 #ifdef NCURSES_MOUSE_VERSION
6004 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
6007 #endif /* USE_LIBFORM */
6009 /****************************************************************************
6013 ****************************************************************************/
6016 fillwin(WINDOW *win, char ch)
6021 getmaxyx(win, y1, x1);
6022 for (y = 0; y < y1; y++) {
6024 for (x = 0; x < x1; x++)
6025 waddch(win, UChar(ch));
6030 crosswin(WINDOW *win, char ch)
6035 getmaxyx(win, y1, x1);
6036 for (y = 0; y < y1; y++) {
6037 for (x = 0; x < x1; x++)
6038 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
6039 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
6041 waddch(win, UChar(ch));
6046 #define OVERLAP_FLAVORS 5
6049 overlap_helpitem(int state, int item, char *message)
6051 int row = (item / 2);
6052 int col = ((item % 2) ? COLS / 2 : 0);
6054 move(LINES - 6 + row, col);
6055 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
6060 overlap_test_1_attr(WINDOW *win, int flavor, int col)
6062 short cpair = (short) (1 + (flavor * 2) + col);
6066 (void) wattrset(win, A_NORMAL);
6069 (void) wattrset(win, A_BOLD);
6072 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
6073 (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_NORMAL));
6076 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
6077 (void) wattrset(win, (int) (COLOR_PAIR(cpair) | A_BOLD));
6083 overlap_test_2_attr(WINDOW *win, int flavor, int col)
6085 short cpair = (short) (9 + (flavor * 2) + col);
6095 init_pair(cpair, COLOR_RED, COLOR_GREEN);
6096 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
6099 wbkgdset(win, ' ' | A_NORMAL);
6105 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
6110 const char *ths, *tht;
6114 state += OVERLAP_FLAVORS;
6115 state = state % OVERLAP_FLAVORS;
6116 assert(state >= 0 && state < OVERLAP_FLAVORS);
6118 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
6121 ths = col ? "B" : "A";
6122 tht = col ? "A" : "B";
6127 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
6135 overlap_test_1_attr(stdscr, flavors[row], col);
6136 sprintf(msg, "fill window %s with letter %s.", ths, ths);
6144 switch (flavors[row]) {
6146 sprintf(msg, "cross pattern in window %s.", ths);
6149 sprintf(msg, "draw box in window %s.", ths);
6152 sprintf(msg, "set background of window %s.", ths);
6155 sprintf(msg, "reset background of window %s.", ths);
6161 sprintf(msg, "clear window %s.", ths);
6165 switch (flavors[row]) {
6167 sprintf(msg, "overwrite %s onto %s.", ths, tht);
6170 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
6173 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
6176 sprintf(msg, "overlay %s onto %s.", ths, tht);
6181 overlap_helpitem(state, item, msg);
6182 (void) wattrset(stdscr, A_NORMAL);
6183 wbkgdset(stdscr, ' ' | A_NORMAL);
6186 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
6187 state, flavors[state]);
6193 overlap_test_0(WINDOW *a, WINDOW *b)
6203 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
6205 overlap_test_1_attr(a, flavor, col);
6207 (void) wattrset(a, A_NORMAL);
6211 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6213 overlap_test_2_attr(a, flavor, col);
6222 /* done in overlap_test_2_attr */
6225 /* done in overlap_test_2_attr */
6231 overlap_test_3(WINDOW *a)
6238 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
6245 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
6248 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
6256 /* test effects of overlapping windows */
6261 int state, flavor[OVERLAP_FLAVORS];
6263 WINDOW *win1 = newwin(9, 20, 3, 3);
6264 WINDOW *win2 = newwin(9, 20, 9, 16);
6270 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
6271 printw("the shared region of two overlapping windows A and B. The cross\n");
6272 printw("pattern in each window does not overlap the other.\n");
6274 memset(flavor, 0, sizeof(flavor));
6275 state = overlap_help(0, flavor);
6277 while (!isQuit(ch = Getchar()))
6279 case 'a': /* refresh window A first, then B */
6280 overlap_test_0(win1, win2);
6283 case 'b': /* refresh window B first, then A */
6284 overlap_test_0(win2, win1);
6287 case 'c': /* fill window A so it's visible */
6288 overlap_test_1(flavor[1], 0, win1, 'A');
6291 case 'd': /* fill window B so it's visible */
6292 overlap_test_1(flavor[1], 1, win2, 'B');
6295 case 'e': /* cross test pattern in window A */
6296 overlap_test_2(flavor[2], 0, win1, 'A');
6299 case 'f': /* cross test pattern in window A */
6300 overlap_test_2(flavor[2], 1, win2, 'B');
6303 case 'g': /* clear window A */
6304 overlap_test_3(win1);
6307 case 'h': /* clear window B */
6308 overlap_test_3(win2);
6311 case 'i': /* overwrite A onto B */
6312 overlap_test_4(flavor[4], win1, win2);
6315 case 'j': /* overwrite B onto A */
6316 overlap_test_4(flavor[4], win2, win1);
6321 state = overlap_help(state + 1, flavor);
6326 state = overlap_help(state - 1, flavor);
6331 state = overlap_help(state, flavor);
6335 state = overlap_help(state, flavor);
6350 /****************************************************************************
6354 ****************************************************************************/
6357 do_single_test(const char c)
6358 /* perform a single specified test */
6365 #if USE_WIDEC_SUPPORT
6375 #if USE_WIDEC_SUPPORT
6383 Cannot("does not support color.");
6388 #if USE_WIDEC_SUPPORT
6391 Cannot("does not support color.");
6399 Cannot("does not support color.");
6400 else if (!can_change_color())
6401 Cannot("has hardwired color values.");
6411 #if USE_WIDEC_SUPPORT
6422 #if USE_WIDEC_SUPPORT
6430 demo_panels(init_panel, fill_panel);
6434 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6436 demo_panels(init_wide_panel, fill_wide_panel);
6445 flushinp_test(stdscr);
6449 test_sgr_attributes();
6472 #if USE_LIBMENU && defined(TRACE)
6491 static const char *const tbl[] =
6493 "Usage: ncurses [options]"
6496 #ifdef NCURSES_VERSION
6497 ," -a f,b set default-colors (assumed white-on-black)"
6498 ," -d use default-colors if terminal supports them"
6500 ," -E call use_env(FALSE) to ignore $LINES and $COLUMNS"
6502 ," -e fmt specify format for soft-keys test (e)"
6505 ," -f rip-off footer line (can repeat)"
6506 ," -h rip-off header line (can repeat)"
6508 ," -m do not use colors"
6509 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6511 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6513 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714)
6514 ," -T call use_tioctl(TRUE) to allow SIGWINCH to override environment"
6517 ," -t mask specify default trace-level (may toggle with ^T)"
6521 for (n = 0; n < SIZEOF(tbl); n++)
6522 fprintf(stderr, "%s\n", tbl[n]);
6523 ExitProgram(EXIT_FAILURE);
6527 set_terminal_modes(void)
6532 scrollok(stdscr, TRUE);
6533 idlok(stdscr, TRUE);
6534 keypad(stdscr, TRUE);
6539 announce_sig(int sig)
6541 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6547 rip_footer(WINDOW *win, int cols)
6549 wbkgd(win, A_REVERSE);
6552 wprintw(win, "footer: window %p, %d columns", (void *) win, cols);
6558 rip_header(WINDOW *win, int cols)
6560 wbkgd(win, A_REVERSE);
6563 wprintw(win, "header: window %p, %d columns", (void *) win, cols);
6567 #endif /* HAVE_RIPOFFLINE */
6575 (void) puts("This is the ncurses main menu");
6576 (void) puts("a = keyboard and mouse input test");
6577 #if USE_WIDEC_SUPPORT
6578 (void) puts("A = wide-character keyboard and mouse input test");
6580 (void) puts("b = character attribute test");
6581 #if USE_WIDEC_SUPPORT
6582 (void) puts("B = wide-character attribute test");
6584 (void) puts("c = color test pattern");
6585 #if USE_WIDEC_SUPPORT
6586 (void) puts("C = color test pattern using wide-character calls");
6589 (void) puts("d = edit RGB color values");
6591 (void) puts("e = exercise soft keys");
6592 #if USE_WIDEC_SUPPORT
6593 (void) puts("E = exercise soft keys using wide-characters");
6596 (void) puts("f = display ACS characters");
6597 #if USE_WIDEC_SUPPORT
6598 (void) puts("F = display Wide-ACS characters");
6600 (void) puts("g = display windows and scrolling");
6601 (void) puts("i = test of flushinp()");
6602 (void) puts("k = display character attributes");
6604 (void) puts("m = menu code test");
6607 (void) puts("o = exercise panels library");
6608 #if USE_WIDEC_SUPPORT
6609 (void) puts("O = exercise panels with wide-characters");
6612 (void) puts("p = exercise pad features");
6613 (void) puts("q = quit");
6615 (void) puts("r = exercise forms code");
6617 (void) puts("s = overlapping-refresh test");
6618 #if USE_LIBMENU && defined(TRACE)
6619 (void) puts("t = set trace level");
6621 (void) puts("? = repeat this command summary");
6623 (void) fputs("> ", stdout);
6624 (void) fflush(stdout); /* necessary under SVr4 curses */
6627 * This used to be an 'fgets()' call (until 1996/10). However with
6628 * some runtime libraries, mixing stream I/O and 'read()' causes the
6629 * input stream to be flushed when switching between the two.
6634 if (read(fileno(stdin), &ch, 1) <= 0) {
6638 } else if (command == 0 && !isspace(UChar(ch))) {
6640 } else if (ch == '\n' || ch == '\r') {
6641 if ((command == 'd') && !top) {
6642 (void) fputs("Do not nest test-d\n", stdout);
6647 (void) fputs("> ", stdout);
6648 (void) fflush(stdout);
6652 if (do_single_test(command)) {
6654 * This may be overkill; it's intended to reset everything back
6655 * to the initial terminal modes so that tests don't get in
6659 set_terminal_modes();
6664 if (command == '?') {
6665 (void) puts("This is the ncurses capability tester.");
6667 puts("You may select a test from the main menu by typing the");
6669 puts("key letter of the choice (the letter to left of the =)");
6671 puts("at the > prompt. Type `q' to exit.");
6679 /*+-------------------------------------------------------------------------
6681 --------------------------------------------------------------------------*/
6683 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6684 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6687 main(int argc, char *argv[])
6691 #ifdef NCURSES_VERSION
6692 int default_fg = COLOR_WHITE;
6693 int default_bg = COLOR_BLACK;
6694 bool assumed_colors = FALSE;
6695 bool default_colors = FALSE;
6697 char *palette_file = 0;
6698 bool monochrome = FALSE;
6700 setlocale(LC_ALL, "");
6702 while ((c = getopt(argc, argv, "a:dEe:fhmp:s:Tt:")) != -1) {
6704 #ifdef NCURSES_VERSION
6706 assumed_colors = TRUE;
6707 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6710 default_colors = TRUE;
6717 my_e_param = atoi(optarg);
6718 #ifdef NCURSES_VERSION
6719 if (my_e_param > 3) /* allow extended layouts */
6728 ripoffline(-1, rip_footer);
6731 ripoffline(1, rip_header);
6733 #endif /* HAVE_RIPOFFLINE */
6738 palette_file = optarg;
6742 nap_msec = (int) atol(optarg);
6745 #if defined(NCURSES_VERSION_PATCH) && (NCURSES_VERSION_PATCH >= 20120714)
6752 save_trace = (unsigned) strtol(optarg, 0, 0);
6761 * If there's no menus (unlikely for ncurses!), then we'll have to set
6762 * tracing on initially, just in case the user wants to test something that
6763 * doesn't involve wGetchar.
6766 /* enable debugging */
6770 if (!isatty(fileno(stdin)))
6772 #endif /* USE_LIBMENU */
6776 /* tell it we're going to play with soft keys */
6777 slk_init(my_e_param);
6781 /* set up null signal catcher so we can see what interrupts to getch do */
6782 signal(SIGUSR1, announce_sig);
6785 /* we must initialize the curses data structure only once */
6789 /* tests, in general, will want these modes */
6790 use_colors = monochrome ? FALSE : has_colors();
6794 #ifdef NCURSES_VERSION_PATCH
6795 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6796 #if HAVE_USE_DEFAULT_COLORS
6797 if (default_colors) {
6798 use_default_colors();
6801 #if HAVE_ASSUME_DEFAULT_COLORS
6803 assume_default_colors(default_fg, default_bg);
6806 #else /* normal SVr4 curses */
6807 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6809 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6811 if (can_change_color()) {
6813 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
6814 for (cp = 0; cp < max_colors; ++cp) {
6816 &all_colors[cp].red,
6817 &all_colors[cp].green,
6818 &all_colors[cp].blue);
6820 if (palette_file != 0) {
6821 FILE *fp = fopen(palette_file, "r");
6823 char buffer[BUFSIZ];
6824 int red, green, blue;
6826 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6827 if (sscanf(buffer, "scale:%d", &c) == 1) {
6829 } else if (sscanf(buffer, "%d:%d %d %d",
6838 all_colors[c].red = (short) ((red * 1000) / scale);
6839 all_colors[c].green = (short) ((green * 1000) / scale);
6840 all_colors[c].blue = (short) ((blue * 1000) / scale);
6848 set_terminal_modes();
6852 * Return to terminal mode, so we're guaranteed of being able to
6853 * select terminal commands even if the capabilities are wrong.
6857 #if HAVE_CURSES_VERSION
6858 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6859 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6860 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6861 NCURSES_VERSION_MAJOR,
6862 NCURSES_VERSION_MINOR,
6863 NCURSES_VERSION_PATCH);
6865 (void) puts("Welcome to ncurses. Press ? for help.");
6870 ExitProgram(EXIT_SUCCESS);
6873 /* ncurses.c ends here */