1 /****************************************************************************
2 * Copyright (c) 1998-2008,2009 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.343 2009/07/30 09:13:37 tom Exp $
45 ***************************************************************************/
47 #include <test.priv.h>
50 #undef mvwdelch /* HPUX 11.23 macro will not compile */
54 #if HAVE_SYS_TIME_H && HAVE_SYS_TIME_SELECT
58 #include <sys/select.h>
74 #ifdef NCURSES_VERSION
76 #define NCURSES_CONST_PARAM const void
79 static unsigned save_trace = TRACE_ORDINARY | TRACE_ICALLS | TRACE_CALLS;
80 extern unsigned _nc_tracing;
85 #define NCURSES_CONST_PARAM char
87 #define mmask_t chtype /* not specified in XSI */
90 #ifdef CURSES_ACS_ARRAY
91 #define ACS_S3 (CURSES_ACS_ARRAY['p']) /* scan line 3 */
92 #define ACS_S7 (CURSES_ACS_ARRAY['r']) /* scan line 7 */
93 #define ACS_LEQUAL (CURSES_ACS_ARRAY['y']) /* less/equal */
94 #define ACS_GEQUAL (CURSES_ACS_ARRAY['z']) /* greater/equal */
95 #define ACS_PI (CURSES_ACS_ARRAY['{']) /* Pi */
96 #define ACS_NEQUAL (CURSES_ACS_ARRAY['|']) /* not equal */
97 #define ACS_STERLING (CURSES_ACS_ARRAY['}']) /* UK pound sign */
99 #define ACS_S3 (A_ALTCHARSET + 'p') /* scan line 3 */
100 #define ACS_S7 (A_ALTCHARSET + 'r') /* scan line 7 */
101 #define ACS_LEQUAL (A_ALTCHARSET + 'y') /* less/equal */
102 #define ACS_GEQUAL (A_ALTCHARSET + 'z') /* greater/equal */
103 #define ACS_PI (A_ALTCHARSET + '{') /* Pi */
104 #define ACS_NEQUAL (A_ALTCHARSET + '|') /* not equal */
105 #define ACS_STERLING (A_ALTCHARSET + '}') /* UK pound sign */
109 #ifdef CURSES_WACS_ARRAY
110 #define WACS_S3 (&(CURSES_WACS_ARRAY['p'])) /* scan line 3 */
111 #define WACS_S7 (&(CURSES_WACS_ARRAY['r'])) /* scan line 7 */
112 #define WACS_LEQUAL (&(CURSES_WACS_ARRAY['y'])) /* less/equal */
113 #define WACS_GEQUAL (&(CURSES_WACS_ARRAY['z'])) /* greater/equal */
114 #define WACS_PI (&(CURSES_WACS_ARRAY['{'])) /* Pi */
115 #define WACS_NEQUAL (&(CURSES_WACS_ARRAY['|'])) /* not equal */
116 #define WACS_STERLING (&(CURSES_WACS_ARRAY['}'])) /* UK pound sign */
122 #define count_wchars(src, len, state) wcsrtombs(0, &src, len, state)
123 #define trans_wchars(dst, src, len, state) wcsrtombs(dst, &src, len, state)
124 #define reset_wchars(state) memset(&state, 0, sizeof(state))
125 #elif HAVE_WCSTOMBS && HAVE_MBTOWC && HAVE_MBLEN
126 #define count_wchars(src, len, state) wcstombs(0, src, len)
127 #define trans_wchars(dst, src, len, state) wcstombs(dst, src, len)
128 #define reset_wchars(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
133 #define count_mbytes(src, len, state) mbsrtowcs(0, &src, len, state)
134 #define trans_mbytes(dst, src, len, state) mbsrtowcs(dst, &src, len, state)
135 #define reset_mbytes(state) memset(&state, 0, sizeof(state))
136 #elif HAVE_MBSTOWCS && HAVE_MBTOWC && HAVE_MBLEN
137 #define count_mbytes(src, len, state) mbstowcs(0, src, len)
138 #define trans_mbytes(dst, src, len, state) mbstowcs(dst, src, len)
139 #define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
143 #define ToggleAcs(temp,real) temp = ((temp == real) ? 0 : real)
145 #define P(string) printw("%s\n", string)
147 #define BLANK ' ' /* this is the background character */
150 static int max_colors; /* the actual number of colors we'll use */
151 static int min_colors; /* the minimum color code */
152 static bool use_colors; /* true if we use colors */
155 static int max_pairs; /* ...and the number of color pairs */
163 static RGB_DATA *all_colors;
165 static void main_menu(bool);
167 /* The behavior of mvhline, mvvline for negative/zero length is unspecified,
168 * though we can rely on negative x/y values to stop the macro.
171 do_h_line(int y, int x, chtype c, int to)
174 mvhline(y, x, c, (to) - (x));
178 do_v_line(int y, int x, chtype c, int to)
181 mvvline(y, x, c, (to) - (y));
195 return ((c) == QUIT || (c) == ESCAPE);
197 #define case_QUIT QUIT: case ESCAPE
199 /* Common function to allow ^T to toggle trace-mode in the middle of a test
200 * so that trace-files can be made smaller.
203 wGetchar(WINDOW *win)
207 while ((c = wgetch(win)) == CTRL('T')) {
209 save_trace = _nc_tracing;
210 Trace(("TOGGLE-TRACING OFF"));
213 _nc_tracing = save_trace;
217 Trace(("TOGGLE-TRACING ON"));
224 #define Getchar() wGetchar(stdscr)
226 /* replaces wgetnstr(), since we want to be able to edit values */
228 wGetstring(WINDOW *win, char *buffer, int limit)
235 wattrset(win, A_REVERSE);
237 x = (int) strlen(buffer);
239 if (x > (int) strlen(buffer))
240 x = (int) strlen(buffer);
242 wprintw(win, "%-*s", limit, buffer);
243 wmove(win, y0, x0 + x);
244 switch (ch = wGetchar(win)) {
257 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
275 if (!isprint(ch) || ch >= KEY_MIN) {
277 } else if ((int) strlen(buffer) < limit) {
279 for (j = (int) strlen(buffer) + 1; j > x; --j) {
280 buffer[j] = buffer[j - 1];
282 buffer[x++] = (char) ch;
289 wattroff(win, A_REVERSE);
294 #if USE_WIDEC_SUPPORT
298 return (ch + 0xff10 - '0');
302 make_fullwidth_text(wchar_t *target, const char *source)
305 while ((ch = *source++) != 0) {
306 *target++ = fullwidth_of(ch);
312 make_narrow_text(wchar_t *target, const char *source)
315 while ((ch = *source++) != 0) {
323 make_fullwidth_digit(cchar_t *target, int digit)
327 source[0] = fullwidth_of(digit + '0');
329 setcchar(target, source, A_NORMAL, 0, 0);
334 wGet_wchar(WINDOW *win, wint_t *result)
338 while ((c = wget_wch(win, result)) == CTRL('T')) {
340 save_trace = _nc_tracing;
341 Trace(("TOGGLE-TRACING OFF"));
344 _nc_tracing = save_trace;
348 Trace(("TOGGLE-TRACING ON"));
351 c = wget_wch(win, result);
355 #define Get_wchar(result) wGet_wchar(stdscr, result)
357 /* replaces wgetn_wstr(), since we want to be able to edit values */
359 wGet_wstring(WINDOW *win, wchar_t *buffer, int limit)
368 wattrset(win, A_REVERSE);
370 x = (int) wcslen(buffer);
372 if (x > (int) wcslen(buffer))
373 x = (int) wcslen(buffer);
375 /* clear the "window' */
377 wprintw(win, "%*s", limit, " ");
379 /* write the existing buffer contents */
381 waddnwstr(win, buffer, limit);
383 /* positions the cursor past character 'x' */
385 waddnwstr(win, buffer, x);
387 switch (wGet_wchar(win, &ch)) {
427 for (j = --x; (buffer[j] = buffer[j + 1]) != '\0'; ++j) {
447 } else if ((int) wcslen(buffer) < limit) {
449 for (j = (int) wcslen(buffer) + 1; j > x; --j) {
450 buffer[j] = buffer[j - 1];
452 buffer[x++] = (wchar_t) ch;
459 wattroff(win, A_REVERSE);
470 addstr("Press any key to continue... ");
475 Cannot(const char *what)
477 printw("\nThis %s terminal %s\n\n", getenv("TERM"), what);
482 ShellOut(bool message)
485 addstr("Shelling out...");
494 addstr("returned from shellout.\n");
498 #ifdef NCURSES_MOUSE_VERSION
500 * This function is the same as _tracemouse(), but we cannot count on that
501 * being available in the non-debug library.
504 mouse_decode(MEVENT const *ep)
506 static char buf[80 + (5 * 10) + (32 * 15)];
508 (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
509 ep->id, ep->x, ep->y, ep->z, (unsigned long) ep->bstate);
511 #define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
513 SHOW(BUTTON1_RELEASED, "release-1");
514 SHOW(BUTTON1_PRESSED, "press-1");
515 SHOW(BUTTON1_CLICKED, "click-1");
516 SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
517 SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
518 #if NCURSES_MOUSE_VERSION == 1
519 SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
522 SHOW(BUTTON2_RELEASED, "release-2");
523 SHOW(BUTTON2_PRESSED, "press-2");
524 SHOW(BUTTON2_CLICKED, "click-2");
525 SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
526 SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
527 #if NCURSES_MOUSE_VERSION == 1
528 SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
531 SHOW(BUTTON3_RELEASED, "release-3");
532 SHOW(BUTTON3_PRESSED, "press-3");
533 SHOW(BUTTON3_CLICKED, "click-3");
534 SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
535 SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
536 #if NCURSES_MOUSE_VERSION == 1
537 SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
540 SHOW(BUTTON4_RELEASED, "release-4");
541 SHOW(BUTTON4_PRESSED, "press-4");
542 SHOW(BUTTON4_CLICKED, "click-4");
543 SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
544 SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
545 #if NCURSES_MOUSE_VERSION == 1
546 SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
549 #if NCURSES_MOUSE_VERSION == 2
550 SHOW(BUTTON5_RELEASED, "release-5");
551 SHOW(BUTTON5_PRESSED, "press-5");
552 SHOW(BUTTON5_CLICKED, "click-5");
553 SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
554 SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
557 SHOW(BUTTON_CTRL, "ctrl");
558 SHOW(BUTTON_SHIFT, "shift");
559 SHOW(BUTTON_ALT, "alt");
560 SHOW(ALL_MOUSE_EVENTS, "all-events");
561 SHOW(REPORT_MOUSE_POSITION, "position");
565 if (buf[strlen(buf) - 1] == ' ')
566 buf[strlen(buf) - 2] = '\0';
567 (void) strcat(buf, "}");
570 #endif /* NCURSES_MOUSE_VERSION */
572 /****************************************************************************
574 * Character input test
576 ****************************************************************************/
578 #define NUM_GETCH_FLAGS 256
579 typedef bool GetchFlags[NUM_GETCH_FLAGS];
582 setup_getch(WINDOW *win, GetchFlags flags)
584 keypad(win, flags['k']); /* should be redundant, but for testing */
585 meta(win, flags['m']); /* force this to a known state */
593 init_getch(WINDOW *win, GetchFlags flags)
595 memset(flags, FALSE, NUM_GETCH_FLAGS);
596 flags[UChar('k')] = (win == stdscr);
597 flags[UChar('m')] = TRUE;
599 setup_getch(win, flags);
603 wgetch_help(WINDOW *win, GetchFlags flags)
605 static const char *help[] =
607 "e -- toggle echo mode"
608 ,"g -- triggers a getstr test"
609 ,"k -- toggle keypad/literal mode"
610 ,"m -- toggle meta (7-bit/8-bit) mode"
613 ,"w -- create a new window"
615 ,"z -- suspend this process"
619 unsigned chk = ((SIZEOF(help) + 1) / 2);
624 printw("Type any key to see its %s value. Also:\n",
625 flags['k'] ? "keypad" : "literal");
626 for (n = 0; n < SIZEOF(help); ++n) {
627 int row = 1 + (int) (n % chk);
628 int col = (n >= chk) ? COLS / 2 : 0;
629 int flg = ((strstr(help[n], "toggle") != 0)
630 && (flags[UChar(*help[n])] != FALSE));
633 mvprintw(row, col, "%s", help[n]);
644 wgetch_wrap(WINDOW *win, int first_y)
646 int last_y = getmaxy(win) - 1;
647 int y = getcury(win) + 1;
655 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
661 static WINSTACK *winstack = 0;
662 static unsigned len_winstack = 0;
675 remember_boxes(unsigned level, WINDOW *txt_win, WINDOW *box_win)
677 unsigned need = (level + 1) * 2;
679 assert(level < (unsigned) COLS);
683 winstack = typeMalloc(WINSTACK, len_winstack);
684 } else if (need >= len_winstack) {
686 winstack = typeRealloc(WINSTACK, len_winstack, winstack);
688 winstack[level].text = txt_win;
689 winstack[level].frame = box_win;
692 #if USE_SOFTKEYS && (NCURSES_VERSION_PATCH < 20071229) && NCURSES_EXT_FUNCS
696 /* this chunk is now done in resize_term() */
703 #define slk_repaint() /* nothing */
707 * For wgetch_test(), we create pairs of windows - one for a box, one for text.
708 * Resize both and paint the box in the parent.
711 resize_boxes(unsigned level, WINDOW *win)
715 int high = LINES - base;
719 wnoutrefresh(stdscr);
723 for (n = 0; n < level; ++n) {
724 wresize(winstack[n].frame, high, wide);
725 wresize(winstack[n].text, high - 2, wide - 2);
728 werase(winstack[n].text);
729 box(winstack[n].frame, 0, 0);
730 wnoutrefresh(winstack[n].frame);
731 wprintw(winstack[n].text,
733 getmaxy(winstack[n].text),
734 getmaxx(winstack[n].text));
735 wnoutrefresh(winstack[n].text);
736 if (winstack[n].text == win)
742 #define forget_boxes() /* nothing */
743 #define remember_boxes(level,text,frame) /* nothing */
747 wgetch_test(unsigned level, WINDOW *win, int delay)
750 int first_y, first_x;
754 bool blocking = (delay < 0);
756 init_getch(win, flags);
757 wtimeout(win, delay);
758 getyx(win, first_y, first_x);
760 wgetch_help(win, flags);
761 wsetscrreg(win, first_y, getmaxy(win) - 1);
765 while ((c = wGetchar(win)) == ERR) {
768 (void) wprintw(win, "%05d: input error", incount);
771 (void) wprintw(win, "%05d: input timed out", incount);
773 wgetch_wrap(win, first_y);
775 if (c == ERR && blocking) {
777 wgetch_wrap(win, first_y);
778 } else if (isQuit(c)) {
780 } else if (c == 'e') {
781 flags[UChar('e')] = !flags[UChar('e')];
782 setup_getch(win, flags);
783 wgetch_help(win, flags);
784 } else if (c == 'g') {
785 waddstr(win, "getstr test: ");
787 wgetnstr(win, buf, sizeof(buf) - 1);
789 wprintw(win, "I saw %d characters:\n\t`%s'.", (int) strlen(buf), buf);
791 wgetch_wrap(win, first_y);
792 } else if (c == 'k') {
793 flags[UChar('k')] = !flags[UChar('k')];
794 setup_getch(win, flags);
795 wgetch_help(win, flags);
796 } else if (c == 'm') {
797 flags[UChar('m')] = !flags[UChar('m')];
798 setup_getch(win, flags);
799 wgetch_help(win, flags);
800 } else if (c == 's') {
802 } else if (c == 'w') {
803 int high = getmaxy(win) - 1 - first_y + 1;
804 int wide = getmaxx(win) - first_x;
806 int new_y = first_y + getbegy(win);
807 int new_x = first_x + getbegx(win);
809 getyx(win, old_y, old_x);
810 if (high > 2 && wide > 2) {
811 WINDOW *wb = newwin(high, wide, new_y, new_x);
812 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
817 remember_boxes(level, wi, wb);
818 wgetch_test(level + 1, wi, delay);
822 wgetch_help(win, flags);
823 wmove(win, old_y, old_x);
829 } else if (c == 'z') {
830 kill(getpid(), SIGTSTP);
833 wprintw(win, "Key pressed: %04o ", c);
834 #ifdef NCURSES_MOUSE_VERSION
835 if (c == KEY_MOUSE) {
840 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
842 move(event.y, event.x);
846 #endif /* NCURSES_MOUSE_VERSION */
848 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
849 if (c == KEY_RESIZE) {
850 resize_boxes(level, win);
853 (void) waddstr(win, keyname(c));
854 } else if (c >= 0x80) {
855 unsigned c2 = (unsigned) c;
856 #if !(defined(NCURSES_VERSION) || defined(_XOPEN_CURSES))
857 /* at least Solaris SVR4 curses breaks unctrl(128), etc. */
861 (void) wprintw(win, "%c", UChar(c));
862 else if (c2 != UChar(c))
863 (void) wprintw(win, "M-%s", unctrl(c2));
865 (void) wprintw(win, "%s", unctrl(c2));
866 waddstr(win, " (high-half character)");
869 (void) wprintw(win, "%c (ASCII printable character)", c);
871 (void) wprintw(win, "%s (ASCII control character)",
874 wgetch_wrap(win, first_y);
881 init_getch(win, flags);
885 begin_getch_test(void)
892 #ifdef NCURSES_MOUSE_VERSION
893 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
896 (void) printw("Delay in 10ths of a second (<CR> for blocking input)? ");
898 getnstr(buf, sizeof(buf) - 1);
902 if (isdigit(UChar(buf[0]))) {
903 delay = atoi(buf) * 100;
913 finish_getch_test(void)
915 #ifdef NCURSES_MOUSE_VERSION
916 mousemask(0, (mmask_t *) 0);
927 int delay = begin_getch_test();
930 wgetch_test(0, stdscr, delay);
936 #if USE_WIDEC_SUPPORT
938 * For wget_wch_test(), we create pairs of windows - one for a box, one for text.
939 * Resize both and paint the box in the parent.
941 #if defined(KEY_RESIZE) && HAVE_WRESIZE
943 resize_wide_boxes(unsigned level, WINDOW *win)
947 int high = LINES - base;
951 wnoutrefresh(stdscr);
955 for (n = 0; n < level; ++n) {
956 wresize(winstack[n].frame, high, wide);
957 wresize(winstack[n].text, high - 2, wide - 2);
960 werase(winstack[n].text);
961 box_set(winstack[n].frame, 0, 0);
962 wnoutrefresh(winstack[n].frame);
963 wprintw(winstack[n].text,
965 getmaxy(winstack[n].text),
966 getmaxx(winstack[n].text));
967 wnoutrefresh(winstack[n].text);
968 if (winstack[n].text == win)
973 #endif /* KEY_RESIZE */
976 wcstos(const wchar_t *src)
980 const wchar_t *tmp = src;
986 if ((need = (int) count_wchars(tmp, 0, &state)) > 0) {
987 unsigned have = (unsigned) need;
988 if ((result = typeCalloc(char, have + 1)) != 0) {
990 if (trans_wchars(result, tmp, have, &state) != have) {
1000 wget_wch_test(unsigned level, WINDOW *win, int delay)
1002 wchar_t wchar_buf[BUFSIZ];
1003 wint_t wint_buf[BUFSIZ];
1004 int first_y, first_x;
1008 bool blocking = (delay < 0);
1012 init_getch(win, flags);
1013 wtimeout(win, delay);
1014 getyx(win, first_y, first_x);
1016 wgetch_help(win, flags);
1017 wsetscrreg(win, first_y, getmaxy(win) - 1);
1018 scrollok(win, TRUE);
1021 while ((code = wGet_wchar(win, &c)) == ERR) {
1024 (void) wprintw(win, "%05d: input error", incount);
1027 (void) wprintw(win, "%05d: input timed out", incount);
1029 wgetch_wrap(win, first_y);
1031 if (code == ERR && blocking) {
1032 wprintw(win, "ERR");
1033 wgetch_wrap(win, first_y);
1034 } else if (isQuit((int) c)) {
1036 } else if (c == 'e') {
1037 flags[UChar('e')] = !flags[UChar('e')];
1038 setup_getch(win, flags);
1039 wgetch_help(win, flags);
1040 } else if (c == 'g') {
1041 waddstr(win, "getstr test: ");
1043 code = wgetn_wstr(win, wint_buf, sizeof(wint_buf) - 1);
1046 wprintw(win, "wgetn_wstr returns an error.");
1049 for (n = 0; (wchar_buf[n] = (wchar_t) wint_buf[n]) != 0; ++n) {
1052 if ((temp = wcstos(wchar_buf)) != 0) {
1053 wprintw(win, "I saw %d characters:\n\t`%s'.",
1054 (int) wcslen(wchar_buf), temp);
1057 wprintw(win, "I saw %d characters (cannot convert).",
1058 (int) wcslen(wchar_buf));
1062 wgetch_wrap(win, first_y);
1063 } else if (c == 'k') {
1064 flags[UChar('k')] = !flags[UChar('k')];
1065 setup_getch(win, flags);
1066 wgetch_help(win, flags);
1067 } else if (c == 'm') {
1068 flags[UChar('m')] = !flags[UChar('m')];
1069 setup_getch(win, flags);
1070 wgetch_help(win, flags);
1071 } else if (c == 's') {
1073 } else if (c == 'w') {
1074 int high = getmaxy(win) - 1 - first_y + 1;
1075 int wide = getmaxx(win) - first_x;
1077 int new_y = first_y + getbegy(win);
1078 int new_x = first_x + getbegx(win);
1080 getyx(win, old_y, old_x);
1081 if (high > 2 && wide > 2) {
1082 WINDOW *wb = newwin(high, wide, new_y, new_x);
1083 WINDOW *wi = newwin(high - 2, wide - 2, new_y + 1, new_x + 1);
1088 remember_boxes(level, wi, wb);
1089 wget_wch_test(level + 1, wi, delay);
1093 wgetch_help(win, flags);
1094 wmove(win, old_y, old_x);
1099 } else if (c == 'z') {
1100 kill(getpid(), SIGTSTP);
1103 wprintw(win, "Key pressed: %04o ", (int) c);
1104 #ifdef NCURSES_MOUSE_VERSION
1105 if (c == KEY_MOUSE) {
1109 wprintw(win, "KEY_MOUSE, %s", mouse_decode(&event));
1111 move(event.y, event.x);
1115 #endif /* NCURSES_MOUSE_VERSION */
1116 if (code == KEY_CODE_YES) {
1117 #if defined(KEY_RESIZE) && HAVE_WRESIZE
1118 if (c == KEY_RESIZE) {
1119 resize_wide_boxes(level, win);
1122 (void) waddstr(win, keyname((wchar_t) c));
1124 (void) waddstr(win, key_name((wchar_t) c));
1125 if (c < 256 && iscntrl(c)) {
1126 (void) wprintw(win, " (control character)");
1128 (void) wprintw(win, " = %#x (printable character)",
1132 wgetch_wrap(win, first_y);
1139 init_getch(win, flags);
1145 int delay = begin_getch_test();
1148 wget_wch_test(0, stdscr, delay);
1150 finish_getch_test();
1155 /****************************************************************************
1157 * Character attributes test
1159 ****************************************************************************/
1161 #if HAVE_SETUPTERM || HAVE_TGETENT
1162 #define get_ncv() TIGETNUM("ncv","NC")
1163 #define get_xmc() TIGETNUM("xmc","sg")
1165 #define get_ncv() -1
1166 #define get_xmc() -1
1173 static int first = TRUE;
1174 static chtype result = 0;
1180 char *area_pointer = parsed;
1182 tgetent(buffer, getenv("TERM"));
1185 if (TIGETSTR("smso", "so"))
1186 result |= A_STANDOUT;
1187 if (TIGETSTR("smul", "us"))
1188 result |= A_UNDERLINE;
1189 if (TIGETSTR("rev", "mr"))
1190 result |= A_REVERSE;
1191 if (TIGETSTR("blink", "mb"))
1193 if (TIGETSTR("dim", "mh"))
1195 if (TIGETSTR("bold", "md"))
1197 if (TIGETSTR("smacs", "ac"))
1198 result |= A_ALTCHARSET;
1204 #define termattrs() my_termattrs()
1207 #define MAX_ATTRSTRING 31
1208 #define LEN_ATTRSTRING 26
1210 static char attr_test_string[MAX_ATTRSTRING + 1];
1213 attr_legend(WINDOW *helpwin)
1218 mvwprintw(helpwin, row++, col,
1220 mvwprintw(helpwin, row++, col,
1223 mvwprintw(helpwin, row++, col,
1224 "Modify the test strings:");
1225 mvwprintw(helpwin, row++, col,
1226 " A digit sets gaps on each side of displayed attributes");
1227 mvwprintw(helpwin, row++, col,
1228 " </> shifts the text left/right. ");
1230 mvwprintw(helpwin, row++, col,
1233 mvwprintw(helpwin, row++, col,
1234 " f/F/b/F toggle foreground/background background color");
1235 mvwprintw(helpwin, row++, col,
1236 " t/T toggle text/background color attribute");
1238 mvwprintw(helpwin, row++, col,
1239 " a/A toggle ACS (alternate character set) mapping");
1240 mvwprintw(helpwin, row++, col,
1241 " v/V toggle video attribute to combine with each line");
1245 show_color_attr(int fg, int bg, int tx)
1248 printw(" Colors (fg %d, bg %d", fg, bg);
1250 printw(", text %d", tx);
1256 cycle_color_attr(int ch, short *fg, short *bg, short *tx)
1263 *fg = (short) (*fg + 1);
1266 *fg = (short) (*fg - 1);
1269 *bg = (short) (*bg + 1);
1272 *bg = (short) (*bg - 1);
1275 *tx = (short) (*tx + 1);
1278 *tx = (short) (*tx - 1);
1286 *fg = (short) min_colors;
1287 if (*fg < min_colors)
1288 *fg = (short) (COLORS - 1);
1290 *bg = (short) min_colors;
1291 if (*bg < min_colors)
1292 *bg = (short) (COLORS - 1);
1296 *tx = (short) (COLORS - 1);
1305 adjust_attr_string(int adjust)
1307 int first = ((int) UChar(attr_test_string[0])) + adjust;
1308 int last = first + LEN_ATTRSTRING;
1310 if (first >= ' ' && last <= '~') { /* 32..126 */
1312 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1313 attr_test_string[j] = (char) k;
1314 if (((k + 1 - first) % 5) == 0) {
1315 if (++j >= MAX_ATTRSTRING)
1317 attr_test_string[j] = ' ';
1320 while (j < MAX_ATTRSTRING)
1321 attr_test_string[j++] = ' ';
1322 attr_test_string[j] = '\0';
1329 init_attr_string(void)
1331 attr_test_string[0] = 'a';
1332 adjust_attr_string(0);
1336 show_attr(int row, int skip, bool arrow, chtype attr, const char *name)
1338 int ncv = get_ncv();
1339 chtype test = attr & (chtype) (~A_ALTCHARSET);
1342 mvprintw(row, 5, "-->");
1343 mvprintw(row, 8, "%s mode:", name);
1344 mvprintw(row, 24, "|");
1346 printw("%*s", skip, " ");
1348 * Just for testing, write text using the alternate character set one
1349 * character at a time (to pass its rendition directly), and use the
1350 * string operation for the other attributes.
1352 if (attr & A_ALTCHARSET) {
1356 for (s = attr_test_string; *s != '\0'; ++s) {
1362 addstr(attr_test_string);
1366 printw("%*s", skip, " ");
1368 if (test != A_NORMAL) {
1369 if (!(termattrs() & test)) {
1372 if (ncv > 0 && (getbkgd(stdscr) & A_COLOR)) {
1373 static const chtype table[] =
1389 for (n = 0; n < SIZEOF(table); n++) {
1390 if ((table[n] & attr) != 0
1391 && ((1 << n) & ncv) != 0) {
1399 if ((termattrs() & test) != test)
1406 static const struct {
1408 NCURSES_CONST char * name;
1409 } attrs_to_test[] = {
1410 { A_STANDOUT, "STANDOUT" },
1411 { A_REVERSE, "REVERSE" },
1413 { A_UNDERLINE, "UNDERLINE" },
1415 { A_BLINK, "BLINK" },
1416 { A_PROTECT, "PROTECT" },
1418 { A_INVIS, "INVISIBLE" },
1420 { A_NORMAL, "NORMAL" },
1425 attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1435 if (ch < 256 && isdigit(ch)) {
1443 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1445 attr_legend(helpwin);
1458 *kc = SIZEOF(attrs_to_test) - 1;
1464 if (*kc >= SIZEOF(attrs_to_test))
1468 adjust_attr_string(-1);
1471 adjust_attr_string(1);
1477 error = cycle_color_attr(ch, fg, bg, tx);
1487 /* test text attributes */
1490 int skip = get_xmc();
1491 short fg = COLOR_BLACK; /* color pair 0 is special */
1492 short bg = COLOR_BLACK;
1500 n = skip; /* make it easy */
1501 k = SIZEOF(attrs_to_test) - 1;
1506 chtype normal = A_NORMAL | BLANK;
1507 chtype extras = (chtype) ac;
1510 short pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1513 if (init_pair(pair, fg, bg) == ERR) {
1516 normal |= COLOR_PAIR(pair);
1521 if (init_pair(pair, tx, bg) == ERR) {
1524 extras |= COLOR_PAIR(pair);
1533 mvaddstr(0, 20, "Character attribute test display");
1535 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1536 bool arrow = (j == k);
1537 row = show_attr(row, n, arrow,
1539 attrs_to_test[j].attr |
1540 attrs_to_test[k].attr,
1541 attrs_to_test[j].name);
1545 "This terminal does %shave the magic-cookie glitch",
1546 get_xmc() > -1 ? "" : "not ");
1547 mvprintw(row + 1, 8, "Enter '?' for help.");
1548 show_color_attr(fg, bg, tx);
1549 printw(" ACS (%d)", ac != 0);
1552 } while (attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1554 bkgdset(A_NORMAL | BLANK);
1559 #if USE_WIDEC_SUPPORT
1560 static wchar_t wide_attr_test_string[MAX_ATTRSTRING + 1];
1563 wide_adjust_attr_string(int adjust)
1565 int first = ((int) UChar(wide_attr_test_string[0])) + adjust;
1566 int last = first + LEN_ATTRSTRING;
1568 if (first >= ' ' && last <= '~') { /* 32..126 */
1570 for (j = 0, k = first; j < MAX_ATTRSTRING && k <= last; ++j, ++k) {
1571 wide_attr_test_string[j] = k;
1572 if (((k + 1 - first) % 5) == 0) {
1573 if (++j >= MAX_ATTRSTRING)
1575 wide_attr_test_string[j] = ' ';
1578 while (j < MAX_ATTRSTRING)
1579 wide_attr_test_string[j++] = ' ';
1580 wide_attr_test_string[j] = '\0';
1587 wide_init_attr_string(void)
1589 wide_attr_test_string[0] = 'a';
1590 wide_adjust_attr_string(0);
1594 set_wide_background(short pair)
1601 setcchar(&normal, blank, A_NORMAL, pair, 0);
1607 get_wide_background(void)
1609 attr_t result = A_NORMAL;
1615 if (getbkgrnd(&ch) != ERR) {
1616 if (getcchar(&ch, wch, &attr, &pair, 0) != ERR) {
1624 wide_show_attr(int row, int skip, bool arrow, chtype attr, short pair, const char *name)
1626 int ncv = get_ncv();
1627 chtype test = attr & ~WA_ALTCHARSET;
1630 mvprintw(row, 5, "-->");
1631 mvprintw(row, 8, "%s mode:", name);
1632 mvprintw(row, 24, "|");
1634 printw("%*s", skip, " ");
1637 * Just for testing, write text using the alternate character set one
1638 * character at a time (to pass its rendition directly), and use the
1639 * string operation for the other attributes.
1641 if (attr & WA_ALTCHARSET) {
1645 for (s = wide_attr_test_string; *s != L'\0'; ++s) {
1649 setcchar(&ch, fill, attr, pair, 0);
1656 attr_get(&old_attr, &old_pair, 0);
1657 attr_set(attr, pair, 0);
1658 addwstr(wide_attr_test_string);
1659 attr_set(old_attr, old_pair, 0);
1662 printw("%*s", skip, " ");
1664 if (test != A_NORMAL) {
1665 if (!(term_attrs() & test)) {
1668 if (ncv > 0 && (get_wide_background() & A_COLOR)) {
1669 static const attr_t table[] =
1683 for (n = 0; n < SIZEOF(table); n++) {
1684 if ((table[n] & attr) != 0
1685 && ((1 << n) & ncv) != 0) {
1693 if ((term_attrs() & test) != test)
1701 wide_attr_getc(int *skip, short *fg, short *bg, short *tx, int *ac, unsigned *kc)
1711 if (ch < 256 && isdigit(ch)) {
1719 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
1720 box_set(helpwin, 0, 0);
1721 attr_legend(helpwin);
1734 *kc = SIZEOF(attrs_to_test) - 1;
1740 if (*kc >= SIZEOF(attrs_to_test))
1744 wide_adjust_attr_string(-1);
1747 wide_adjust_attr_string(1);
1753 error = cycle_color_attr(ch, fg, bg, tx);
1762 wide_attr_test(void)
1763 /* test text attributes using wide-character calls */
1766 int skip = get_xmc();
1767 short fg = COLOR_BLACK; /* color pair 0 is special */
1768 short bg = COLOR_BLACK;
1776 n = skip; /* make it easy */
1777 k = SIZEOF(attrs_to_test) - 1;
1778 wide_init_attr_string();
1786 pair = (short) (fg != COLOR_BLACK || bg != COLOR_BLACK);
1789 if (init_pair(pair, fg, bg) == ERR) {
1796 if (init_pair(extras, tx, bg) == ERR) {
1801 set_wide_background(pair);
1804 box_set(stdscr, 0, 0);
1805 mvaddstr(0, 20, "Character attribute test display");
1807 for (j = 0; j < SIZEOF(attrs_to_test); ++j) {
1808 row = wide_show_attr(row, n, j == k,
1810 attrs_to_test[j].attr |
1811 attrs_to_test[k].attr,
1813 attrs_to_test[j].name);
1817 "This terminal does %shave the magic-cookie glitch",
1818 get_xmc() > -1 ? "" : "not ");
1819 mvprintw(row + 1, 8, "Enter '?' for help.");
1820 show_color_attr(fg, bg, tx);
1821 printw(" ACS (%d)", ac != 0);
1824 } while (wide_attr_getc(&n, &fg, &bg, &tx, &ac, &k));
1826 set_wide_background(0);
1832 /****************************************************************************
1834 * Color support tests
1836 ****************************************************************************/
1838 static NCURSES_CONST char *the_color_names[] =
1859 show_color_name(int y, int x, int color, bool wide)
1861 if (move(y, x) != ERR) {
1866 sprintf(temp, "%02d", color);
1868 } else if (color >= 8) {
1869 sprintf(temp, "[%02d]", color);
1870 } else if (color < 0) {
1871 strcpy(temp, "default");
1873 strcpy(temp, the_color_names[color]);
1875 printw("%-*.*s", width, width, temp);
1880 color_legend(WINDOW *helpwin, bool wide)
1885 mvwprintw(helpwin, row++, col,
1888 mvwprintw(helpwin, row++, col,
1889 "Use up/down arrow to scroll through the display if it is");
1890 mvwprintw(helpwin, row++, col,
1891 "longer than one screen. Control/N and Control/P can be used");
1892 mvwprintw(helpwin, row++, col,
1893 "in place of up/down arrow. Use pageup/pagedown to scroll a");
1894 mvwprintw(helpwin, row++, col,
1895 "full screen; control/B and control/F can be used here.");
1897 mvwprintw(helpwin, row++, col,
1899 mvwprintw(helpwin, row++, col,
1900 " a/A toggle altcharset off/on");
1901 mvwprintw(helpwin, row++, col,
1902 " b/B toggle bold off/on");
1903 mvwprintw(helpwin, row++, col,
1904 " n/N toggle text/number on/off");
1905 mvwprintw(helpwin, row++, col,
1906 " r/R toggle reverse on/off");
1907 mvwprintw(helpwin, row++, col,
1908 " w/W toggle width between 8/16 colors");
1909 #if USE_WIDEC_SUPPORT
1911 mvwprintw(helpwin, row++, col,
1912 "Wide characters:");
1913 mvwprintw(helpwin, row++, col,
1914 " x/X toggle text between ASCII and wide-character");
1921 #define set_color_test(name, value) if (name != value) { name = value; base_row = 0; }
1923 /* generate a color test pattern */
1930 int grid_top = top + 3;
1931 int page_size = (LINES - grid_top);
1932 int pairs_max = PAIR_NUMBER(A_COLOR) + 1;
1938 bool opt_acsc = FALSE;
1939 bool opt_bold = FALSE;
1940 bool opt_revs = FALSE;
1941 bool opt_nums = FALSE;
1942 bool opt_wide = FALSE;
1945 if (COLORS * COLORS == COLOR_PAIRS) {
1946 int limit = (COLORS - min_colors) * (COLORS - min_colors);
1947 if (pairs_max > limit)
1950 if (pairs_max > COLOR_PAIRS)
1951 pairs_max = COLOR_PAIRS;
1957 /* this assumes an 80-column line */
1961 per_row = (COLORS > 8) ? 16 : 8;
1967 per_row -= min_colors;
1969 row_limit = (pairs_max + per_row - 1) / per_row;
1972 (void) printw("There are %d color pairs and %d colors%s\n",
1974 min_colors ? " besides 'default'" : "");
1977 (void) mvprintw(top + 1, 0,
1978 "%dx%d matrix of foreground/background colors, bold *%s*\n",
1981 opt_bold ? "on" : "off");
1983 /* show color names/numbers across the top */
1984 for (i = 0; i < per_row; i++)
1985 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
1987 /* show a grid of colors, with color names/ numbers on the left */
1988 for (i = (short) (base_row * per_row); i < pairs_max; i++) {
1989 int row = grid_top + (i / per_row) - base_row;
1990 int col = (i % per_row + 1) * width;
1993 #define InxToFG(i) (short) ((i % (COLORS - min_colors)) + min_colors)
1994 #define InxToBG(i) (short) ((i / (COLORS - min_colors)) + min_colors)
1995 if (row >= 0 && move(row, col) != ERR) {
1996 short fg = InxToFG(i);
1997 short bg = InxToBG(i);
1999 init_pair(pair, fg, bg);
2000 attron((attr_t) COLOR_PAIR(pair));
2002 attron((attr_t) A_ALTCHARSET);
2004 attron((attr_t) A_BOLD);
2006 attron((attr_t) A_REVERSE);
2009 sprintf(numbered, "{%02X}", i);
2012 printw("%-*.*s", width, width, hello);
2015 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2016 show_color_name(row, 0, InxToBG(i), opt_wide);
2024 switch (wGetchar(stdscr)) {
2053 set_color_test(opt_wide, FALSE);
2056 set_color_test(opt_wide, TRUE);
2060 if (base_row <= 0) {
2068 if (base_row + page_size >= row_limit) {
2077 if (base_row <= 0) {
2080 base_row -= (page_size - 1);
2088 if (base_row + page_size >= row_limit) {
2091 base_row += page_size - 1;
2092 if (base_row + page_size >= row_limit) {
2093 base_row = row_limit - page_size - 1;
2098 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2100 color_legend(helpwin, FALSE);
2115 #if USE_WIDEC_SUPPORT
2116 /* generate a color test pattern */
2118 wide_color_test(void)
2124 int grid_top = top + 3;
2125 int page_size = (LINES - grid_top);
2126 int pairs_max = (unsigned short) (-1);
2132 bool opt_acsc = FALSE;
2133 bool opt_bold = FALSE;
2134 bool opt_revs = FALSE;
2135 bool opt_wide = FALSE;
2136 bool opt_nums = FALSE;
2137 bool opt_xchr = FALSE;
2141 if (COLORS * COLORS == COLOR_PAIRS) {
2142 int limit = (COLORS - min_colors) * (COLORS - min_colors);
2143 if (pairs_max > limit)
2146 if (pairs_max > COLOR_PAIRS)
2147 pairs_max = COLOR_PAIRS;
2153 /* this assumes an 80-column line */
2157 per_row = (COLORS > 8) ? 16 : 8;
2163 per_row -= min_colors;
2166 make_fullwidth_text(buffer, hello);
2170 make_narrow_text(buffer, hello);
2173 row_limit = (pairs_max + per_row - 1) / per_row;
2176 (void) printw("There are %d color pairs and %d colors%s\n",
2178 min_colors ? " besides 'default'" : "");
2181 (void) mvprintw(top + 1, 0,
2182 "%dx%d matrix of foreground/background colors, bold *%s*\n",
2185 opt_bold ? "on" : "off");
2187 /* show color names/numbers across the top */
2188 for (i = 0; i < per_row; i++)
2189 show_color_name(top + 2, (i + 1) * width, i + min_colors, opt_wide);
2191 /* show a grid of colors, with color names/ numbers on the left */
2192 for (i = (base_row * per_row); i < pairs_max; i++) {
2193 int row = grid_top + (i / per_row) - base_row;
2194 int col = (i % per_row + 1) * width;
2195 short pair = (short) i;
2197 if (row >= 0 && move(row, col) != ERR) {
2198 init_pair(pair, InxToFG(i), InxToBG(i));
2199 color_set(pair, NULL);
2201 attr_on((attr_t) A_ALTCHARSET, NULL);
2203 attr_on((attr_t) A_BOLD, NULL);
2205 attr_on((attr_t) A_REVERSE, NULL);
2208 sprintf(numbered, "{%02X}", i);
2210 make_fullwidth_text(buffer, numbered);
2212 make_narrow_text(buffer, numbered);
2215 addnwstr(buffer, width);
2216 attr_set(A_NORMAL, 0, NULL);
2218 if ((i % per_row) == 0 && InxToFG(i) == min_colors) {
2219 show_color_name(row, 0, InxToBG(i), opt_wide);
2227 switch (c = wGetchar(stdscr)) {
2256 set_color_test(opt_wide, FALSE);
2259 set_color_test(opt_wide, TRUE);
2269 if (base_row <= 0) {
2277 if (base_row + page_size >= row_limit) {
2286 if (base_row <= 0) {
2289 base_row -= (page_size - 1);
2297 if (base_row + page_size >= row_limit) {
2300 base_row += page_size - 1;
2301 if (base_row + page_size >= row_limit) {
2302 base_row = row_limit - page_size - 1;
2307 if ((helpwin = newwin(LINES - 1, COLS - 2, 0, 0)) != 0) {
2309 color_legend(helpwin, TRUE);
2323 #endif /* USE_WIDEC_SUPPORT */
2326 change_color(short current, int field, int value, int usebase)
2328 short red, green, blue;
2330 color_content(current, &red, &green, &blue);
2334 red = (short) (usebase ? (red + value) : value);
2337 green = (short) (usebase ? (green + value) : value);
2340 blue = (short) (usebase ? (blue + value) : value);
2344 if (init_color(current, red, green, blue) == ERR)
2349 init_all_colors(void)
2353 for (c = 0; c < COLORS; ++c)
2356 all_colors[c].green,
2357 all_colors[c].blue);
2360 #define scaled_rgb(n) ((255 * (n)) / 1000)
2364 /* display the color test pattern, without trying to edit colors */
2368 int this_c = 0, value = 0, field = 0;
2371 int page_size = (LINES - 6);
2376 for (i = 0; i < max_colors; i++)
2377 init_pair((short) i, (short) COLOR_WHITE, (short) i);
2379 mvprintw(LINES - 2, 0, "Number: %d", value);
2382 short red, green, blue;
2385 mvaddstr(0, 20, "Color RGB Value Editing");
2388 for (i = (short) top_color;
2389 (i - top_color < page_size)
2390 && (i < max_colors); i++) {
2393 sprintf(numeric, "[%d]", i);
2394 mvprintw(2 + i - top_color, 0, "%c %-8s:",
2395 (i == current ? '>' : ' '),
2396 (i < (int) SIZEOF(the_color_names)
2397 ? the_color_names[i] : numeric));
2398 attrset(COLOR_PAIR(i));
2402 color_content((short) i, &red, &green, &blue);
2404 if (current == i && field == 0)
2406 printw("%04d", red);
2407 if (current == i && field == 0)
2410 if (current == i && field == 1)
2412 printw("%04d", green);
2413 if (current == i && field == 1)
2416 if (current == i && field == 2)
2418 printw("%04d", blue);
2419 if (current == i && field == 2)
2422 printw(" ( %3d %3d %3d )",
2428 mvaddstr(LINES - 3, 0,
2429 "Use up/down to select a color, left/right to change fields.");
2430 mvaddstr(LINES - 2, 0,
2431 "Modify field by typing nnn=, nnn-, or nnn+. ? for help.");
2433 move(2 + current - top_color, 0);
2437 if (this_c < 256 && isdigit(this_c) && !isdigit(last_c))
2444 current -= (page_size - 1);
2451 if (current < (max_colors - 1))
2452 current += (page_size - 1);
2459 current = (current == 0 ? (max_colors - 1) : current - 1);
2464 current = (current == (max_colors - 1) ? 0 : current + 1);
2468 field = (field == 2 ? 0 : field + 1);
2472 field = (field == 0 ? 2 : field - 1);
2485 value = value * 10 + (this_c - '0');
2489 change_color((short) current, field, value, 1);
2493 change_color((short) current, field, -value, 1);
2497 change_color((short) current, field, value, 0);
2502 P(" RGB Value Editing Help");
2504 P("You are in the RGB value editor. Use the arrow keys to select one of");
2505 P("the fields in one of the RGB triples of the current colors; the one");
2506 P("currently selected will be reverse-video highlighted.");
2508 P("To change a field, enter the digits of the new value; they are echoed");
2509 P("as entered. Finish by typing `='. The change will take effect instantly.");
2510 P("To increment or decrement a value, use the same procedure, but finish");
2511 P("with a `+' or `-'.");
2513 P("Press 'm' to invoke the top-level menu with the current color settings.");
2514 P("To quit, do ESC");
2536 if (current >= max_colors)
2537 current = max_colors - 1;
2538 if (current < top_color)
2539 top_color = current;
2540 if (current - top_color >= page_size)
2541 top_color = current - (page_size - 1);
2543 mvprintw(LINES - 1, 0, "Number: %d", value);
2551 * ncurses does not reset each color individually when calling endwin().
2558 /****************************************************************************
2560 * Soft-key label test
2562 ****************************************************************************/
2567 #define SLK_WORK (SLK_HELP + 3)
2572 static const char *table[] =
2574 "Available commands are:"
2576 ,"^L -- repaint this message and activate soft keys"
2577 ,"a/d -- activate/disable soft keys"
2578 ,"c -- set centered format for labels"
2579 ,"l -- set left-justified format for labels"
2580 ,"r -- set right-justified format for labels"
2581 ,"[12345678] -- set label; labels are numbered 1 through 8"
2582 ,"e -- erase stdscr (should not erase labels)"
2583 ,"s -- test scrolling of shortened screen"
2585 ,"F/B -- cycle through foreground/background colors"
2587 ,"ESC -- return to main menu"
2589 ,"Note: if activating the soft keys causes your terminal to scroll up"
2590 ,"one line, your terminal auto-scrolls when anything is written to the"
2591 ,"last screen position. The ncurses code does not yet handle this"
2597 for (j = 0; j < SIZEOF(table); ++j) {
2605 call_slk_color(short fg, short bg)
2607 init_pair(1, bg, fg);
2609 mvprintw(SLK_WORK, 0, "Colors %d/%d\n", fg, bg);
2617 /* exercise the soft keys */
2623 short fg = COLOR_BLACK;
2624 short bg = COLOR_WHITE;
2630 call_slk_color(fg, bg);
2640 mvaddstr(0, 20, "Soft Key Exerciser");
2655 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2656 while ((c = Getchar()) != 'Q' && (c != ERR))
2684 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2686 if ((s = slk_label(c - '0')) != 0) {
2689 wGetstring(stdscr, buf, 8);
2690 slk_set((c - '0'), buf, fmt);
2702 fg = (short) ((fg + 1) % COLORS);
2703 call_slk_color(fg, bg);
2708 bg = (short) ((bg + 1) % COLORS);
2709 call_slk_color(fg, bg);
2713 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2715 wnoutrefresh(stdscr);
2722 } while (!isQuit(c = Getchar()));
2730 #if USE_WIDEC_SUPPORT
2734 /* exercise the soft keys */
2737 wchar_t buf[SLKLEN + 1];
2739 short fg = COLOR_BLACK;
2740 short bg = COLOR_WHITE;
2744 call_slk_color(fg, bg);
2751 attr_on(WA_BOLD, NULL);
2752 mvaddstr(0, 20, "Soft Key Exerciser");
2753 attr_off(WA_BOLD, NULL);
2767 mvprintw(SLK_WORK, 0, "Press Q to stop the scrolling-test: ");
2768 while ((c = Getchar()) != 'Q' && (c != ERR))
2796 (void) mvaddstr(SLK_WORK, 0, "Please enter the label value: ");
2798 if ((s = slk_label(c - '0')) != 0) {
2799 char *temp = strdup(s);
2800 size_t used = strlen(temp);
2801 size_t want = SLKLEN;
2803 #ifndef state_unused
2808 while (want > 0 && used != 0) {
2809 const char *base = s;
2810 reset_mbytes(state);
2811 test = count_mbytes(base, 0, &state);
2812 if (test == (size_t) -1) {
2814 } else if (test > want) {
2817 reset_mbytes(state);
2818 trans_mbytes(buf, base, want, &state);
2824 wGet_wstring(stdscr, buf, SLKLEN);
2825 slk_wset((c - '0'), buf, fmt);
2836 fg = (short) ((fg + 1) % COLORS);
2837 call_slk_color(fg, bg);
2842 bg = (short) ((bg + 1) % COLORS);
2843 call_slk_color(fg, bg);
2846 #if defined(NCURSES_VERSION) && defined(KEY_RESIZE) && HAVE_WRESIZE
2848 wnoutrefresh(stdscr);
2854 } while (!isQuit(c = Getchar()));
2862 #endif /* SLK_INIT */
2864 /****************************************************************************
2866 * Alternate character-set stuff
2868 ****************************************************************************/
2873 } attrs_to_cycle[] = {
2874 { A_NORMAL, "normal" },
2876 { A_BLINK, "blink" },
2877 { A_REVERSE, "reverse" },
2878 { A_UNDERLINE, "underline" },
2883 cycle_attr(int ch, unsigned *at_code, chtype *attr)
2889 if ((*at_code += 1) >= SIZEOF(attrs_to_cycle))
2894 *at_code = SIZEOF(attrs_to_cycle) - 1;
2903 *attr = attrs_to_cycle[*at_code].attr;
2908 cycle_colors(int ch, int *fg, int *bg, short *pair)
2910 bool result = FALSE;
2920 if ((*fg += 1) >= COLORS)
2928 if ((*bg += 1) >= COLORS)
2936 *pair = (short) (*fg != COLOR_BLACK || *bg != COLOR_BLACK);
2939 if (init_pair(*pair, (short) *fg, (short) *bg) == ERR) {
2948 /* ISO 6429: codes 0x80 to 0x9f may be control characters that cause the
2949 * terminal to perform functions. The remaining codes can be graphic.
2952 show_upper_chars(unsigned first, int repeat, attr_t attr, short pair)
2954 bool C1 = (first == 128);
2956 unsigned last = first + 31;
2961 mvprintw(0, 20, "Display of %s Character Codes %d to %d",
2962 C1 ? "C1" : "GR", first, last);
2966 for (code = first; code <= last; code++) {
2968 int row = 2 + ((int) (code - first) % 16);
2969 int col = ((int) (code - first) / 16) * COLS / 2;
2971 sprintf(tmp, "%3u (0x%x)", code, code);
2972 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
2976 nodelay(stdscr, TRUE);
2977 echochar(colored_chtype(code, attr, pair));
2979 /* (yes, this _is_ crude) */
2980 while ((reply = Getchar()) != ERR) {
2981 addch(UChar(reply));
2984 nodelay(stdscr, FALSE);
2986 } while (--count > 0);
2993 show_pc_chars(int repeat, attr_t attr, short pair)
2999 mvprintw(0, 20, "Display of PC Character Codes");
3003 for (code = 0; code < 16; ++code) {
3004 mvprintw(2, (int) code * PC_COLS + 8, "%X", code);
3006 for (code = 0; code < 256; code++) {
3008 int row = 3 + (int) (code / 16) + (code >= 128);
3009 int col = 8 + (int) (code % 16) * PC_COLS;
3010 if ((code % 16) == 0)
3011 mvprintw(row, 0, "0x%02x:", code);
3022 * Skip the ones that do not work.
3026 addch(colored_chtype(code, A_ALTCHARSET | attr, pair));
3029 } while (--count > 0);
3034 show_box_chars(int repeat, attr_t attr, short pair)
3037 attr |= COLOR_PAIR(pair);
3041 mvaddstr(0, 20, "Display of the ACS Line-Drawing Set");
3046 colored_chtype(ACS_VLINE, attr, pair),
3047 colored_chtype(ACS_VLINE, attr, pair),
3048 colored_chtype(ACS_HLINE, attr, pair),
3049 colored_chtype(ACS_HLINE, attr, pair),
3050 colored_chtype(ACS_ULCORNER, attr, pair),
3051 colored_chtype(ACS_URCORNER, attr, pair),
3052 colored_chtype(ACS_LLCORNER, attr, pair),
3053 colored_chtype(ACS_LRCORNER, attr, pair));
3054 mvhline(LINES / 2, 0, colored_chtype(ACS_HLINE, attr, pair), COLS);
3055 mvvline(0, COLS / 2, colored_chtype(ACS_VLINE, attr, pair), LINES);
3056 mvaddch(0, COLS / 2, colored_chtype(ACS_TTEE, attr, pair));
3057 mvaddch(LINES / 2, COLS / 2, colored_chtype(ACS_PLUS, attr, pair));
3058 mvaddch(LINES - 1, COLS / 2, colored_chtype(ACS_BTEE, attr, pair));
3059 mvaddch(LINES / 2, 0, colored_chtype(ACS_LTEE, attr, pair));
3060 mvaddch(LINES / 2, COLS - 1, colored_chtype(ACS_RTEE, attr, pair));
3066 show_1_acs(int n, int repeat, const char *name, chtype code)
3068 const int height = 16;
3069 int row = 2 + (n % height);
3070 int col = (n / height) * COLS / 2;
3072 mvprintw(row, col, "%*s : ", COLS / 4, name);
3075 } while (--repeat > 0);
3080 show_acs_chars(int repeat, attr_t attr, short pair)
3081 /* display the ACS character set */
3085 #define BOTH(name) #name, colored_chtype(name, attr, pair)
3089 mvaddstr(0, 20, "Display of the ACS Character Set");
3093 n = show_1_acs(0, repeat, BOTH(ACS_ULCORNER));
3094 n = show_1_acs(n, repeat, BOTH(ACS_URCORNER));
3095 n = show_1_acs(n, repeat, BOTH(ACS_LLCORNER));
3096 n = show_1_acs(n, repeat, BOTH(ACS_LRCORNER));
3098 n = show_1_acs(n, repeat, BOTH(ACS_LTEE));
3099 n = show_1_acs(n, repeat, BOTH(ACS_RTEE));
3100 n = show_1_acs(n, repeat, BOTH(ACS_TTEE));
3101 n = show_1_acs(n, repeat, BOTH(ACS_BTEE));
3103 n = show_1_acs(n, repeat, BOTH(ACS_HLINE));
3104 n = show_1_acs(n, repeat, BOTH(ACS_VLINE));
3107 * HPUX's ACS definitions are broken here. Just give up.
3109 #if !(defined(__hpux) && !defined(NCURSES_VERSION))
3110 n = show_1_acs(n, repeat, BOTH(ACS_LARROW));
3111 n = show_1_acs(n, repeat, BOTH(ACS_RARROW));
3112 n = show_1_acs(n, repeat, BOTH(ACS_UARROW));
3113 n = show_1_acs(n, repeat, BOTH(ACS_DARROW));
3115 n = show_1_acs(n, repeat, BOTH(ACS_BLOCK));
3116 n = show_1_acs(n, repeat, BOTH(ACS_BOARD));
3117 n = show_1_acs(n, repeat, BOTH(ACS_LANTERN));
3118 n = show_1_acs(n, repeat, BOTH(ACS_BULLET));
3119 n = show_1_acs(n, repeat, BOTH(ACS_CKBOARD));
3120 n = show_1_acs(n, repeat, BOTH(ACS_DEGREE));
3121 n = show_1_acs(n, repeat, BOTH(ACS_DIAMOND));
3122 n = show_1_acs(n, repeat, BOTH(ACS_PLMINUS));
3123 n = show_1_acs(n, repeat, BOTH(ACS_PLUS));
3125 n = show_1_acs(n, repeat, BOTH(ACS_GEQUAL));
3126 n = show_1_acs(n, repeat, BOTH(ACS_NEQUAL));
3127 n = show_1_acs(n, repeat, BOTH(ACS_LEQUAL));
3129 n = show_1_acs(n, repeat, BOTH(ACS_STERLING));
3130 n = show_1_acs(n, repeat, BOTH(ACS_PI));
3131 n = show_1_acs(n, repeat, BOTH(ACS_S1));
3132 n = show_1_acs(n, repeat, BOTH(ACS_S3));
3133 n = show_1_acs(n, repeat, BOTH(ACS_S7));
3134 n = show_1_acs(n, repeat, BOTH(ACS_S9));
3142 char *term = getenv("TERM");
3143 const char *pch_kludge = ((term != 0 && strstr(term, "linux"))
3146 chtype attr = A_NORMAL;
3149 int fg = COLOR_BLACK;
3150 int bg = COLOR_BLACK;
3151 unsigned at_code = 0;
3153 void (*last_show_acs) (int, attr_t, short) = 0;
3161 ToggleAcs(last_show_acs, show_acs_chars);
3165 ToggleAcs(last_show_acs, show_pc_chars);
3170 ToggleAcs(last_show_acs, show_box_chars);
3196 if (repeat < (COLS / 4))
3204 if (cycle_attr(c, &at_code, &attr)
3205 || cycle_colors(c, &fg, &bg, &pair)) {
3212 if (last_show_acs != 0)
3213 last_show_acs(repeat, attr, pair);
3215 show_upper_chars((unsigned) (digit * 32 + 128), repeat, attr, pair);
3217 mvprintw(LINES - 3, 0,
3218 "Note: ANSI terminals may not display C1 characters.");
3219 mvprintw(LINES - 2, 0,
3220 "Select: a=ACS, x=box, %s0=C1, 1-3,+/- non-ASCII, </> repeat, ESC=quit",
3223 mvprintw(LINES - 1, 0,
3224 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3225 attrs_to_cycle[at_code].name,
3228 mvprintw(LINES - 1, 0,
3229 "v/V cycles through video attributes (%s).",
3230 attrs_to_cycle[at_code].name);
3233 } while (!isQuit(c = Getchar()));
3240 #if USE_WIDEC_SUPPORT
3242 merge_wide_attr(cchar_t *dst, const cchar_t *src, attr_t attr, short pair)
3248 TEST_CCHAR(src, count, {
3249 attr |= (test_attrs & A_ALTCHARSET);
3250 setcchar(dst, test_wch, attr, pair, NULL);
3260 show_upper_widechars(int first, int repeat, int space, attr_t attr, short pair)
3264 int last = first + 31;
3268 mvprintw(0, 20, "Display of Character Codes %d to %d", first, last);
3271 for (code = first; (int) code <= last; code++) {
3272 int row = 2 + ((code - first) % 16);
3273 int col = ((code - first) / 16) * COLS / 2;
3279 memset(&codes, 0, sizeof(codes));
3281 sprintf(tmp, "%3ld (0x%lx)", (long) code, (long) code);
3282 mvprintw(row, col, "%*s: ", COLS / 4, tmp);
3283 setcchar(&temp, codes, attr, pair, 0);
3286 * Give non-spacing characters something to combine with. If we
3287 * don't, they'll bunch up in a heap on the space after the ":".
3288 * Mark them with reverse-video to make them simpler to find on
3291 if (wcwidth(code) == 0)
3292 addch(space | (A_REVERSE ^ attr) | COLOR_PAIR(pair));
3294 * This could use add_wch(), but is done for comparison with the
3295 * normal 'f' test (and to make a test-case for echo_wchar()).
3296 * The screen will flicker because the erase() at the top of the
3297 * function is met by the builtin refresh() in echo_wchar().
3301 * The repeat-count may make text wrap - avoid that.
3303 getyx(stdscr, y, x);
3304 if (x >= col + (COLS / 2) - 2)
3306 } while (--count > 0);
3311 show_1_wacs(int n, int repeat, const char *name, const cchar_t *code)
3313 const int height = 16;
3314 int row = 2 + (n % height);
3315 int col = (n / height) * COLS / 2;
3317 mvprintw(row, col, "%*s : ", COLS / 4, name);
3318 while (--repeat >= 0) {
3324 #define MERGE_ATTR(wch) merge_wide_attr(&temp, wch, attr, pair)
3327 show_wacs_chars(int repeat, attr_t attr, short pair)
3328 /* display the wide-ACS character set */
3334 /*#define BOTH2(name) #name, &(name) */
3335 #define BOTH2(name) #name, MERGE_ATTR(name)
3339 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3343 n = show_1_wacs(0, repeat, BOTH2(WACS_ULCORNER));
3344 n = show_1_wacs(n, repeat, BOTH2(WACS_URCORNER));
3345 n = show_1_wacs(n, repeat, BOTH2(WACS_LLCORNER));
3346 n = show_1_wacs(n, repeat, BOTH2(WACS_LRCORNER));
3348 n = show_1_wacs(n, repeat, BOTH2(WACS_LTEE));
3349 n = show_1_wacs(n, repeat, BOTH2(WACS_RTEE));
3350 n = show_1_wacs(n, repeat, BOTH2(WACS_TTEE));
3351 n = show_1_wacs(n, repeat, BOTH2(WACS_BTEE));
3353 n = show_1_wacs(n, repeat, BOTH2(WACS_HLINE));
3354 n = show_1_wacs(n, repeat, BOTH2(WACS_VLINE));
3356 n = show_1_wacs(n, repeat, BOTH2(WACS_LARROW));
3357 n = show_1_wacs(n, repeat, BOTH2(WACS_RARROW));
3358 n = show_1_wacs(n, repeat, BOTH2(WACS_UARROW));
3359 n = show_1_wacs(n, repeat, BOTH2(WACS_DARROW));
3361 n = show_1_wacs(n, repeat, BOTH2(WACS_BLOCK));
3362 n = show_1_wacs(n, repeat, BOTH2(WACS_BOARD));
3363 n = show_1_wacs(n, repeat, BOTH2(WACS_LANTERN));
3364 n = show_1_wacs(n, repeat, BOTH2(WACS_BULLET));
3365 n = show_1_wacs(n, repeat, BOTH2(WACS_CKBOARD));
3366 n = show_1_wacs(n, repeat, BOTH2(WACS_DEGREE));
3367 n = show_1_wacs(n, repeat, BOTH2(WACS_DIAMOND));
3368 n = show_1_wacs(n, repeat, BOTH2(WACS_PLMINUS));
3369 n = show_1_wacs(n, repeat, BOTH2(WACS_PLUS));
3371 #ifdef CURSES_WACS_ARRAY
3372 n = show_1_wacs(n, repeat, BOTH2(WACS_GEQUAL));
3373 n = show_1_wacs(n, repeat, BOTH2(WACS_NEQUAL));
3374 n = show_1_wacs(n, repeat, BOTH2(WACS_LEQUAL));
3376 n = show_1_wacs(n, repeat, BOTH2(WACS_STERLING));
3377 n = show_1_wacs(n, repeat, BOTH2(WACS_PI));
3378 n = show_1_wacs(n, repeat, BOTH2(WACS_S1));
3379 n = show_1_wacs(n, repeat, BOTH2(WACS_S3));
3380 n = show_1_wacs(n, repeat, BOTH2(WACS_S7));
3381 n = show_1_wacs(n, repeat, BOTH2(WACS_S9));
3387 #define MERGE_ATTR(n,wch) merge_wide_attr(&temp[n], wch, attr, pair)
3390 show_wbox_chars(int repeat, attr_t attr, short pair)
3397 mvaddstr(0, 20, "Display of the Wide-ACS Line-Drawing Set");
3402 MERGE_ATTR(0, WACS_VLINE),
3403 MERGE_ATTR(1, WACS_VLINE),
3404 MERGE_ATTR(2, WACS_HLINE),
3405 MERGE_ATTR(3, WACS_HLINE),
3406 MERGE_ATTR(4, WACS_ULCORNER),
3407 MERGE_ATTR(5, WACS_URCORNER),
3408 MERGE_ATTR(6, WACS_LLCORNER),
3409 MERGE_ATTR(7, WACS_LRCORNER));
3411 mvhline_set(LINES / 2, 0, MERGE_ATTR(0, WACS_HLINE), COLS);
3412 mvvline_set(0, COLS / 2, MERGE_ATTR(0, WACS_VLINE), LINES);
3413 mvadd_wch(0, COLS / 2, MERGE_ATTR(0, WACS_TTEE));
3414 mvadd_wch(LINES / 2, COLS / 2, MERGE_ATTR(0, WACS_PLUS));
3415 mvadd_wch(LINES - 1, COLS / 2, MERGE_ATTR(0, WACS_BTEE));
3416 mvadd_wch(LINES / 2, 0, MERGE_ATTR(0, WACS_LTEE));
3417 mvadd_wch(LINES / 2, COLS - 1, MERGE_ATTR(0, WACS_RTEE));
3425 show_2_wacs(int n, const char *name, const char *code, attr_t attr, short pair)
3427 const int height = 16;
3428 int row = 2 + (n % height);
3429 int col = (n / height) * COLS / 2;
3432 mvprintw(row, col, "%*s : ", COLS / 4, name);
3433 attr_set(attr, pair, 0);
3434 addstr(strcpy(temp, code));
3435 attr_set(A_NORMAL, 0, 0);
3439 #define SHOW_UTF8(n, name, code) show_2_wacs(n, name, code, attr, pair)
3442 show_utf8_chars(int repeat, attr_t attr, short pair)
3449 mvaddstr(0, 20, "Display of the Wide-ACS Character Set");
3453 n = SHOW_UTF8(0, "WACS_ULCORNER", "\342\224\214");
3454 n = SHOW_UTF8(n, "WACS_URCORNER", "\342\224\220");
3455 n = SHOW_UTF8(n, "WACS_LLCORNER", "\342\224\224");
3456 n = SHOW_UTF8(n, "WACS_LRCORNER", "\342\224\230");
3458 n = SHOW_UTF8(n, "WACS_LTEE", "\342\224\234");
3459 n = SHOW_UTF8(n, "WACS_RTEE", "\342\224\244");
3460 n = SHOW_UTF8(n, "WACS_TTEE", "\342\224\254");
3461 n = SHOW_UTF8(n, "WACS_BTEE", "\342\224\264");
3463 n = SHOW_UTF8(n, "WACS_HLINE", "\342\224\200");
3464 n = SHOW_UTF8(n, "WACS_VLINE", "\342\224\202");
3466 n = SHOW_UTF8(n, "WACS_LARROW", "\342\206\220");
3467 n = SHOW_UTF8(n, "WACS_RARROW", "\342\206\222");
3468 n = SHOW_UTF8(n, "WACS_UARROW", "\342\206\221");
3469 n = SHOW_UTF8(n, "WACS_DARROW", "\342\206\223");
3471 n = SHOW_UTF8(n, "WACS_BLOCK", "\342\226\256");
3472 n = SHOW_UTF8(n, "WACS_BOARD", "\342\226\222");
3473 n = SHOW_UTF8(n, "WACS_LANTERN", "\342\230\203");
3474 n = SHOW_UTF8(n, "WACS_BULLET", "\302\267");
3475 n = SHOW_UTF8(n, "WACS_CKBOARD", "\342\226\222");
3476 n = SHOW_UTF8(n, "WACS_DEGREE", "\302\260");
3477 n = SHOW_UTF8(n, "WACS_DIAMOND", "\342\227\206");
3478 n = SHOW_UTF8(n, "WACS_PLMINUS", "\302\261");
3479 n = SHOW_UTF8(n, "WACS_PLUS", "\342\224\274");
3480 n = SHOW_UTF8(n, "WACS_GEQUAL", "\342\211\245");
3481 n = SHOW_UTF8(n, "WACS_NEQUAL", "\342\211\240");
3482 n = SHOW_UTF8(n, "WACS_LEQUAL", "\342\211\244");
3484 n = SHOW_UTF8(n, "WACS_STERLING", "\302\243");
3485 n = SHOW_UTF8(n, "WACS_PI", "\317\200");
3486 n = SHOW_UTF8(n, "WACS_S1", "\342\216\272");
3487 n = SHOW_UTF8(n, "WACS_S3", "\342\216\273");
3488 n = SHOW_UTF8(n, "WACS_S7", "\342\216\274");
3489 n = SHOW_UTF8(n, "WACS_S9", "\342\216\275");
3494 /* display the wide-ACS character set */
3496 wide_acs_display(void)
3502 chtype attr = A_NORMAL;
3503 int fg = COLOR_BLACK;
3504 int bg = COLOR_BLACK;
3505 unsigned at_code = 0;
3507 void (*last_show_wacs) (int, attr_t, short) = 0;
3515 ToggleAcs(last_show_wacs, show_wacs_chars);
3518 ToggleAcs(last_show_wacs, show_wbox_chars);
3521 ToggleAcs(last_show_wacs, show_utf8_chars);
3524 if (c < 256 && isdigit(c)) {
3527 } else if (c == '+') {
3530 } else if (c == '-' && digit > 0) {
3533 } else if (c == '>' && repeat < (COLS / 4)) {
3535 } else if (c == '<' && repeat > 1) {
3537 } else if (c == '_') {
3538 space = (space == ' ') ? '_' : ' ';
3540 } else if (cycle_attr(c, &at_code, &attr)
3541 || cycle_colors(c, &fg, &bg, &pair)) {
3542 if (last_show_wacs != 0)
3550 if (last_show_wacs != 0)
3551 last_show_wacs(repeat, attr, pair);
3553 show_upper_widechars(digit * 32 + 128, repeat, space, attr, pair);
3555 mvprintw(LINES - 3, 0,
3556 "Select: a WACS, x box, u UTF-8, 0-9,+/- non-ASCII, </> repeat, ESC=quit");
3558 mvprintw(LINES - 2, 0,
3559 "v/V, f/F, b/B cycle through video attributes (%s) and color %d/%d.",
3560 attrs_to_cycle[at_code].name,
3563 mvprintw(LINES - 2, 0,
3564 "v/V cycles through video attributes (%s).",
3565 attrs_to_cycle[at_code].name);
3568 } while (!isQuit(c = Getchar()));
3578 * Graphic-rendition test (adapted from vttest)
3581 test_sgr_attributes(void)
3585 for (pass = 0; pass < 2; pass++) {
3586 chtype normal = ((pass == 0 ? A_NORMAL : A_REVERSE)) | BLANK;
3588 /* Use non-default colors if possible to exercise bce a little */
3590 init_pair(1, COLOR_WHITE, COLOR_BLUE);
3591 normal |= COLOR_PAIR(1);
3595 mvprintw(1, 20, "Graphic rendition test pattern:");
3597 mvprintw(4, 1, "vanilla");
3599 #define set_sgr(mask) bkgdset((normal^(mask)));
3601 mvprintw(4, 40, "bold");
3603 set_sgr(A_UNDERLINE);
3604 mvprintw(6, 6, "underline");
3606 set_sgr(A_BOLD | A_UNDERLINE);
3607 mvprintw(6, 45, "bold underline");
3610 mvprintw(8, 1, "blink");
3612 set_sgr(A_BLINK | A_BOLD);
3613 mvprintw(8, 40, "bold blink");
3615 set_sgr(A_UNDERLINE | A_BLINK);
3616 mvprintw(10, 6, "underline blink");
3618 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK);
3619 mvprintw(10, 45, "bold underline blink");
3622 mvprintw(12, 1, "negative");
3624 set_sgr(A_BOLD | A_REVERSE);
3625 mvprintw(12, 40, "bold negative");
3627 set_sgr(A_UNDERLINE | A_REVERSE);
3628 mvprintw(14, 6, "underline negative");
3630 set_sgr(A_BOLD | A_UNDERLINE | A_REVERSE);
3631 mvprintw(14, 45, "bold underline negative");
3633 set_sgr(A_BLINK | A_REVERSE);
3634 mvprintw(16, 1, "blink negative");
3636 set_sgr(A_BOLD | A_BLINK | A_REVERSE);
3637 mvprintw(16, 40, "bold blink negative");
3639 set_sgr(A_UNDERLINE | A_BLINK | A_REVERSE);
3640 mvprintw(18, 6, "underline blink negative");
3642 set_sgr(A_BOLD | A_UNDERLINE | A_BLINK | A_REVERSE);
3643 mvprintw(18, 45, "bold underline blink negative");
3646 mvprintw(LINES - 2, 1, "%s background. ", pass == 0 ? "Dark" :
3652 bkgdset(A_NORMAL | BLANK);
3657 /****************************************************************************
3659 * Windows and scrolling tester.
3661 ****************************************************************************/
3663 #define BOTLINES 4 /* number of line stolen from screen bottom */
3669 #define FRAME struct frame
3678 #if defined(NCURSES_VERSION)
3679 #if (NCURSES_VERSION_PATCH < 20070331) && NCURSES_EXT_FUNCS
3680 #define is_keypad(win) (win)->_use_keypad
3681 #define is_scrollok(win) (win)->_scroll
3682 #elif !defined(is_keypad)
3683 #define is_keypad(win) FALSE
3684 #define is_scrollok(win) FALSE
3687 #define is_keypad(win) FALSE
3688 #define is_scrollok(win) FALSE
3692 frame_win(FRAME * curp)
3694 return (curp != 0) ? curp->wind : stdscr;
3697 /* We need to know if these flags are actually set, so don't look in FRAME.
3698 * These names are known to work with SVr4 curses as well as ncurses. The
3699 * _use_keypad name does not work with Solaris 8.
3702 HaveKeypad(FRAME * curp)
3704 WINDOW *win = frame_win(curp);
3706 return is_keypad(win);
3710 HaveScroll(FRAME * curp)
3712 WINDOW *win = frame_win(curp);
3714 return is_scrollok(win);
3718 newwin_legend(FRAME * curp)
3720 static const struct {
3725 "^C = create window", 0
3728 "^N = next window", 0
3731 "^P = previous window", 0
3734 "^F = scroll forward", 0
3737 "^B = scroll backward", 0
3740 "^K = keypad(%s)", 1
3743 "^S = scrollok(%s)", 2
3746 "^W = save window to file", 0
3749 "^R = restore window", 0
3762 bool do_keypad = HaveKeypad(curp);
3763 bool do_scroll = HaveScroll(curp);
3767 for (n = 0; n < SIZEOF(legend); n++) {
3768 switch (legend[n].code) {
3770 strcpy(buf, legend[n].msg);
3773 sprintf(buf, legend[n].msg, do_keypad ? "yes" : "no");
3776 sprintf(buf, legend[n].msg, do_scroll ? "yes" : "no");
3779 sprintf(buf, legend[n].msg, do_keypad ? "/ESC" : "");
3782 x = getcurx(stdscr);
3783 addstr((COLS < (x + 3 + (int) strlen(buf))) ? "\n" : (n ? ", " : ""));
3790 transient(FRAME * curp, NCURSES_CONST char *msg)
3792 newwin_legend(curp);
3794 mvaddstr(LINES - 1, 0, msg);
3800 printw("%s characters are echoed, window should %sscroll.",
3801 HaveKeypad(curp) ? "Non-arrow" : "All other",
3802 HaveScroll(curp) ? "" : "not ");
3807 newwin_report(FRAME * curp)
3808 /* report on the cursor's current position, then restore it */
3810 WINDOW *win = frame_win(curp);
3814 transient(curp, (char *) 0);
3816 move(LINES - 1, COLS - 17);
3817 printw("Y = %2d X = %2d", y, x);
3825 selectcell(int uli, int ulj, int lri, int lrj)
3826 /* arrows keys move cursor, return location at current on non-arrow key */
3828 static pair res; /* result cell */
3829 int si = lri - uli + 1; /* depth of the select area */
3830 int sj = lrj - ulj + 1; /* width of the select area */
3831 int i = 0, j = 0; /* offsets into the select area */
3836 move(uli + i, ulj + j);
3837 newwin_report((FRAME *) 0);
3839 switch (Getchar()) {
3853 return ((pair *) 0);
3854 #ifdef NCURSES_MOUSE_VERSION
3860 if (event.y > uli && event.x > ulj) {
3881 outerbox(pair ul, pair lr, bool onoff)
3882 /* draw or erase a box *outside* the given pair of corners */
3884 mvaddch(ul.y - 1, lr.x - 1, onoff ? ACS_ULCORNER : ' ');
3885 mvaddch(ul.y - 1, lr.x + 1, onoff ? ACS_URCORNER : ' ');
3886 mvaddch(lr.y + 1, lr.x + 1, onoff ? ACS_LRCORNER : ' ');
3887 mvaddch(lr.y + 1, ul.x - 1, onoff ? ACS_LLCORNER : ' ');
3888 move(ul.y - 1, ul.x);
3889 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3890 move(ul.y, ul.x - 1);
3891 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3892 move(lr.y + 1, ul.x);
3893 hline(onoff ? ACS_HLINE : ' ', lr.x - ul.x + 1);
3894 move(ul.y, lr.x + 1);
3895 vline(onoff ? ACS_VLINE : ' ', lr.y - ul.y + 1);
3900 /* Ask user for a window definition */
3907 addstr("Use arrows to move cursor, anything else to mark corner 1");
3909 if ((tmp = selectcell(2, 1, LINES - BOTLINES - 2, COLS - 2)) == (pair *) 0)
3910 return ((WINDOW *) 0);
3911 memcpy(&ul, tmp, sizeof(pair));
3912 mvaddch(ul.y - 1, ul.x - 1, ACS_ULCORNER);
3915 addstr("Use arrows to move cursor, anything else to mark corner 2");
3917 if ((tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2)) ==
3919 return ((WINDOW *) 0);
3920 memcpy(&lr, tmp, sizeof(pair));
3922 rwindow = subwin(stdscr, lr.y - ul.y + 1, lr.x - ul.x + 1, ul.y, ul.x);
3924 outerbox(ul, lr, TRUE);
3935 newwin_move(FRAME * curp, int dy, int dx)
3937 WINDOW *win = frame_win(curp);
3941 getyx(win, cur_y, cur_x);
3942 getmaxyx(win, max_y, max_x);
3943 if ((cur_x += dx) < 0)
3945 else if (cur_x >= max_x)
3947 if ((cur_y += dy) < 0)
3949 else if (cur_y >= max_y)
3951 wmove(win, cur_y, cur_x);
3955 delete_framed(FRAME * fp, bool showit)
3960 fp->last->next = fp->next;
3961 fp->next->last = fp->last;
3969 np = (fp == fp->next) ? 0 : fp->next;
3976 acs_and_scroll(void)
3977 /* Demonstrate windows */
3980 FRAME *current = (FRAME *) 0, *neww;
3981 WINDOW *usescr = stdscr;
3982 #if HAVE_PUTWIN && HAVE_GETWIN
3986 #define DUMPFILE "screendump"
3988 #ifdef NCURSES_MOUSE_VERSION
3989 mousemask(BUTTON1_CLICKED, (mmask_t *) 0);
3994 transient((FRAME *) 0, (char *) 0);
3997 if ((neww = typeCalloc(FRAME, 1)) == 0) {
4000 if ((neww->wind = getwindow()) == (WINDOW *) 0) {
4005 if (current == 0) { /* First element, */
4006 neww->next = neww; /* so point it at itself */
4009 neww->next = current->next;
4010 neww->last = current;
4011 neww->last->next = neww;
4012 neww->next->last = neww;
4015 /* SVr4 curses sets the keypad on all newly-created windows to
4016 * false. Someone reported that PDCurses makes new windows inherit
4017 * this flag. Remove the following 'keypad()' call to test this
4019 keypad(current->wind, TRUE);
4020 current->do_keypad = HaveKeypad(current);
4021 current->do_scroll = HaveScroll(current);
4024 case CTRL('N'): /* go to next window */
4026 current = current->next;
4029 case CTRL('P'): /* go to previous window */
4031 current = current->last;
4034 case CTRL('F'): /* scroll current window forward */
4036 wscrl(frame_win(current), 1);
4039 case CTRL('B'): /* scroll current window backwards */
4041 wscrl(frame_win(current), -1);
4044 case CTRL('K'): /* toggle keypad mode for current */
4046 current->do_keypad = !current->do_keypad;
4047 keypad(current->wind, current->do_keypad);
4053 current->do_scroll = !current->do_scroll;
4054 scrollok(current->wind, current->do_scroll);
4058 #if HAVE_PUTWIN && HAVE_GETWIN
4059 case CTRL('W'): /* save and delete window */
4060 if ((current != 0) && (current == current->next)) {
4061 transient(current, "Will not save/delete ONLY window");
4063 } else if ((fp = fopen(DUMPFILE, "w")) == (FILE *) 0) {
4064 transient(current, "Can't open screen dump file");
4066 (void) putwin(frame_win(current), fp);
4069 current = delete_framed(current, TRUE);
4073 case CTRL('R'): /* restore window */
4074 if ((fp = fopen(DUMPFILE, "r")) == (FILE *) 0) {
4075 transient(current, "Can't open screen dump file");
4077 if ((neww = typeCalloc(FRAME, 1)) != 0) {
4079 neww->next = current ? current->next : 0;
4080 neww->last = current;
4081 neww->last->next = neww;
4082 neww->next->last = neww;
4084 neww->wind = getwin(fp);
4086 wrefresh(neww->wind);
4094 case CTRL('X'): /* resize window */
4101 addstr("Use arrows to move cursor, anything else to mark new corner");
4104 getbegyx(current->wind, ul.y, ul.x);
4106 tmp = selectcell(ul.y, ul.x, LINES - BOTLINES - 2, COLS - 2);
4107 if (tmp == (pair *) 0) {
4112 getmaxyx(current->wind, lr.y, lr.x);
4115 outerbox(ul, lr, FALSE);
4116 wnoutrefresh(stdscr);
4118 /* strictly cosmetic hack for the test */
4119 getmaxyx(current->wind, my, mx);
4120 if (my > tmp->y - ul.y) {
4121 getyx(current->wind, lr.y, lr.x);
4122 wmove(current->wind, tmp->y - ul.y + 1, 0);
4123 wclrtobot(current->wind);
4124 wmove(current->wind, lr.y, lr.x);
4126 if (mx > tmp->x - ul.x)
4127 for (i = 0; i < my; i++) {
4128 wmove(current->wind, i, tmp->x - ul.x + 1);
4129 wclrtoeol(current->wind);
4131 wnoutrefresh(current->wind);
4133 memcpy(&lr, tmp, sizeof(pair));
4134 (void) wresize(current->wind, lr.y - ul.y + 0, lr.x - ul.x + 0);
4136 getbegyx(current->wind, ul.y, ul.x);
4137 getmaxyx(current->wind, lr.y, lr.x);
4140 outerbox(ul, lr, TRUE);
4141 wnoutrefresh(stdscr);
4143 wnoutrefresh(current->wind);
4149 #endif /* HAVE_WRESIZE */
4151 case KEY_F(10): /* undocumented --- use this to test area clears */
4152 selectcell(0, 0, LINES - 1, COLS - 1);
4158 newwin_move(current, -1, 0);
4161 newwin_move(current, 1, 0);
4164 newwin_move(current, 0, -1);
4167 newwin_move(current, 0, 1);
4175 getyx(frame_win(current), y, x);
4179 x = getmaxx(frame_win(current)) - 1;
4181 mvwdelch(frame_win(current), y, x);
4191 waddch(current->wind, (chtype) c);
4196 newwin_report(current);
4197 usescr = frame_win(current);
4200 (!isQuit(c = wGetchar(usescr))
4204 while (current != 0)
4205 current = delete_framed(current, FALSE);
4207 scrollok(stdscr, TRUE); /* reset to driver's default */
4208 #ifdef NCURSES_MOUSE_VERSION
4209 mousemask(0, (mmask_t *) 0);
4216 /****************************************************************************
4220 ****************************************************************************/
4223 static int nap_msec = 1;
4225 static NCURSES_CONST char *mod[] =
4235 /*+-------------------------------------------------------------------------
4237 --------------------------------------------------------------------------*/
4239 wait_a_while(int msec GCC_UNUSED)
4249 else if (msec > 1000)
4250 sleep((unsigned) msec / 1000);
4254 } /* end of wait_a_while */
4256 /*+-------------------------------------------------------------------------
4258 --------------------------------------------------------------------------*/
4260 saywhat(NCURSES_CONST char *text)
4262 wmove(stdscr, LINES - 1, 0);
4264 if (text != 0 && *text != '\0') {
4265 waddstr(stdscr, text);
4266 waddstr(stdscr, "; ");
4268 waddstr(stdscr, "press any key to continue");
4269 } /* end of saywhat */
4271 /*+-------------------------------------------------------------------------
4272 mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
4273 --------------------------------------------------------------------------*/
4275 mkpanel(short color, int rows, int cols, int tly, int tlx)
4280 if ((win = newwin(rows, cols, tly, tlx)) != 0) {
4281 if ((pan = new_panel(win)) == 0) {
4283 } else if (use_colors) {
4284 short fg = (short) ((color == COLOR_BLUE) ? COLOR_WHITE : COLOR_BLACK);
4287 init_pair(color, fg, bg);
4288 wbkgdset(win, (chtype) (COLOR_PAIR(color) | ' '));
4290 wbkgdset(win, A_BOLD | ' ');
4294 } /* end of mkpanel */
4296 /*+-------------------------------------------------------------------------
4298 --------------------------------------------------------------------------*/
4300 rmpanel(PANEL * pan)
4302 WINDOW *win = panel_window(pan);
4305 } /* end of rmpanel */
4307 /*+-------------------------------------------------------------------------
4309 --------------------------------------------------------------------------*/
4315 } /* end of pflush */
4317 /*+-------------------------------------------------------------------------
4319 --------------------------------------------------------------------------*/
4325 for (y = 0; y < LINES - 1; y++) {
4326 for (x = 0; x < COLS; x++)
4327 wprintw(stdscr, "%d", (y + x) % 10);
4332 fill_panel(PANEL * pan)
4334 WINDOW *win = panel_window(pan);
4335 const char *userptr = (const char *) panel_userptr(pan);
4336 int num = (userptr && *userptr) ? userptr[1] : '?';
4340 wprintw(win, "-pan%c-", num);
4343 for (y = 2; y < getmaxy(win) - 1; y++) {
4344 for (x = 1; x < getmaxx(win) - 1; x++) {
4346 waddch(win, UChar(num));
4351 #if USE_WIDEC_SUPPORT
4353 init_wide_panel(void)
4358 for (digit = 0; digit < 10; ++digit)
4359 make_fullwidth_digit(&temp[digit], digit);
4363 getyx(stdscr, y, x);
4364 digit = (y + x / 2) % 10;
4365 } while (add_wch(&temp[digit]) != ERR);
4369 fill_wide_panel(PANEL * pan)
4371 WINDOW *win = panel_window(pan);
4372 const char *userptr = (const char *) panel_userptr(pan);
4373 int num = (userptr && *userptr) ? userptr[1] : '?';
4377 wprintw(win, "-pan%c-", num);
4380 for (y = 2; y < getmaxy(win) - 1; y++) {
4381 for (x = 1; x < getmaxx(win) - 1; x++) {
4383 waddch(win, UChar(num));
4389 #define MAX_PANELS 5
4392 canned_panel(PANEL * px[MAX_PANELS + 1], NCURSES_CONST char *cmd)
4394 int which = cmd[1] - '0';
4399 hide_panel(px[which]);
4402 show_panel(px[which]);
4405 top_panel(px[which]);
4408 bottom_panel(px[which]);
4415 wait_a_while(nap_msec);
4419 demo_panels(void (*InitPanel) (void), void (*FillPanel) (PANEL *))
4423 PANEL *px[MAX_PANELS + 1];
4425 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4429 for (count = 0; count < 5; count++) {
4430 px[1] = mkpanel(COLOR_RED,
4435 set_panel_userptr(px[1], (NCURSES_CONST void *) "p1");
4437 px[2] = mkpanel(COLOR_GREEN,
4442 set_panel_userptr(px[2], (NCURSES_CONST void *) "p2");
4444 px[3] = mkpanel(COLOR_YELLOW,
4449 set_panel_userptr(px[3], (NCURSES_CONST void *) "p3");
4451 px[4] = mkpanel(COLOR_BLUE,
4456 set_panel_userptr(px[4], (NCURSES_CONST void *) "p4");
4458 px[5] = mkpanel(COLOR_MAGENTA,
4463 set_panel_userptr(px[5], (NCURSES_CONST void *) "p5");
4475 wait_a_while(nap_msec);
4477 saywhat("h3 s1 s2 s4 s5");
4478 move_panel(px[1], 0, 0);
4485 wait_a_while(nap_msec);
4487 canned_panel(px, "s1");
4488 canned_panel(px, "s2");
4491 move_panel(px[2], LINES / 3 + 1, COLS / 8);
4493 wait_a_while(nap_msec);
4495 canned_panel(px, "s3");
4498 move_panel(px[3], LINES / 4 + 1, COLS / 15);
4500 wait_a_while(nap_msec);
4502 canned_panel(px, "b3");
4503 canned_panel(px, "s4");
4504 canned_panel(px, "s5");
4505 canned_panel(px, "t3");
4506 canned_panel(px, "t1");
4507 canned_panel(px, "t2");
4508 canned_panel(px, "t3");
4509 canned_panel(px, "t4");
4511 for (itmp = 0; itmp < 6; itmp++) {
4512 WINDOW *w4 = panel_window(px[4]);
4513 WINDOW *w5 = panel_window(px[5]);
4516 wmove(w4, LINES / 8, 1);
4517 waddstr(w4, mod[itmp]);
4518 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4519 wmove(w5, LINES / 6, 1);
4520 waddstr(w5, mod[itmp]);
4522 wait_a_while(nap_msec);
4525 wmove(w4, LINES / 6, 1);
4526 waddstr(w4, mod[itmp]);
4527 move_panel(px[5], LINES / 3 - 1, (itmp * 10) + 6);
4528 wmove(w5, LINES / 8, 1);
4529 waddstr(w5, mod[itmp]);
4531 wait_a_while(nap_msec);
4535 move_panel(px[4], LINES / 6, itmp * (COLS / 8));
4537 wait_a_while(nap_msec);
4539 canned_panel(px, "t5");
4540 canned_panel(px, "t2");
4541 canned_panel(px, "t1");
4542 canned_panel(px, "d2");
4543 canned_panel(px, "h3");
4544 canned_panel(px, "d1");
4545 canned_panel(px, "d4");
4546 canned_panel(px, "d5");
4547 canned_panel(px, "d3");
4549 wait_a_while(nap_msec);
4558 #endif /* USE_LIBPANEL */
4560 /****************************************************************************
4564 ****************************************************************************/
4568 static bool pending_pan = FALSE;
4569 static bool show_panner_legend = TRUE;
4572 panner_legend(int line)
4574 static const char *const legend[] =
4576 "Use arrow keys (or U,D,L,R) to pan, ESC to quit, ! to shell-out.",
4577 "Use +,- (or j,k) to grow/shrink the panner vertically.",
4578 "Use <,> (or h,l) to grow/shrink the panner horizontally.",
4579 "Number repeats. Toggle legend:? filler:a timer:t scrollmark:s."
4581 int n = ((int) SIZEOF(legend) - (LINES - line));
4582 if (line < LINES && (n >= 0)) {
4584 if (show_panner_legend)
4585 printw("%s", legend[n]);
4587 return show_panner_legend;
4593 panner_h_cleanup(int from_y, int from_x, int to_x)
4595 if (!panner_legend(from_y))
4596 do_h_line(from_y, from_x, ' ', to_x);
4600 panner_v_cleanup(int from_y, int from_x, int to_y)
4602 if (!panner_legend(from_y))
4603 do_v_line(from_y, from_x, ' ', to_y);
4607 fill_pad(WINDOW *panpad, bool pan_lines)
4610 unsigned gridcount = 0;
4612 wmove(panpad, 0, 0);
4613 for (y = 0; y < getmaxy(panpad); y++) {
4614 for (x = 0; x < getmaxx(panpad); x++) {
4615 if (y % GRIDSIZE == 0 && x % GRIDSIZE == 0) {
4616 if (y == 0 && x == 0)
4617 waddch(panpad, pan_lines ? ACS_ULCORNER : '+');
4619 waddch(panpad, pan_lines ? ACS_TTEE : '+');
4620 else if (y == 0 || x == 0)
4621 waddch(panpad, pan_lines ? ACS_LTEE : '+');
4623 waddch(panpad, (chtype) ((pan_lines ? 'a' : 'A') +
4624 (int) (gridcount++ % 26)));
4625 } else if (y % GRIDSIZE == 0)
4626 waddch(panpad, pan_lines ? ACS_HLINE : '-');
4627 else if (x % GRIDSIZE == 0)
4628 waddch(panpad, pan_lines ? ACS_VLINE : '|');
4630 waddch(panpad, ' ');
4637 int top_x, int top_y, int porty, int portx,
4638 int (*pgetc) (WINDOW *))
4640 #if HAVE_GETTIMEOFDAY
4641 struct timeval before, after;
4644 bool pan_lines = FALSE;
4645 bool scrollers = TRUE;
4648 int pxmax, pymax, lowend, highend, c;
4650 getmaxyx(pad, pymax, pxmax);
4651 scrollok(stdscr, FALSE); /* we don't want stdscr to scroll! */
4655 #ifdef NCURSES_VERSION
4657 * During shell-out, the user may have resized the window. Adjust
4658 * the port size of the pad to accommodate this. Ncurses automatically
4659 * resizes all of the normal windows to fit on the new screen.
4677 show_panner_legend = !show_panner_legend;
4678 panner_legend(LINES - 4);
4679 panner_legend(LINES - 3);
4680 panner_legend(LINES - 2);
4681 panner_legend(LINES - 1);
4684 pan_lines = !pan_lines;
4685 fill_pad(pad, pan_lines);
4686 pending_pan = FALSE;
4689 #if HAVE_GETTIMEOFDAY
4693 panner_legend(LINES - 1);
4697 scrollers = !scrollers;
4700 /* Move the top-left corner of the pad, keeping the bottom-right
4703 case 'h': /* increase-columns: move left edge to left */
4707 panner_v_cleanup(top_y, top_x, porty);
4712 case 'j': /* decrease-lines: move top-edge down */
4716 panner_h_cleanup(top_y - 1, top_x - (top_x > 0), portx);
4721 case 'k': /* increase-lines: move top-edge up */
4726 panner_h_cleanup(top_y, top_x, portx);
4730 case 'l': /* decrease-columns: move left-edge to right */
4734 panner_v_cleanup(top_y - (top_y > 0), top_x - 1, porty);
4739 /* Move the bottom-right corner of the pad, keeping the top-left
4742 case KEY_IC: /* increase-columns: move right-edge to right */
4743 if (portx >= pxmax || portx >= COLS)
4746 panner_v_cleanup(top_y - (top_y > 0), portx - 1, porty);
4751 case KEY_IL: /* increase-lines: move bottom-edge down */
4752 if (porty >= pymax || porty >= LINES)
4755 panner_h_cleanup(porty - 1, top_x - (top_x > 0), portx);
4760 case KEY_DC: /* decrease-columns: move bottom edge up */
4765 panner_v_cleanup(top_y - (top_y > 0), portx, porty);
4769 case KEY_DL: /* decrease-lines */
4774 panner_h_cleanup(porty, top_x - (top_x > 0), portx);
4778 case KEY_LEFT: /* pan leftwards */
4785 case KEY_RIGHT: /* pan rightwards */
4786 if (basex + portx - (pymax > porty) < pxmax)
4792 case KEY_UP: /* pan upwards */
4799 case KEY_DOWN: /* pan downwards */
4800 if (basey + porty - (pxmax > portx) < pymax)
4815 basey = pymax - porty;
4825 mvaddch(top_y - 1, top_x - 1, ACS_ULCORNER);
4826 do_v_line(top_y, top_x - 1, ACS_VLINE, porty);
4827 do_h_line(top_y - 1, top_x, ACS_HLINE, portx);
4829 if (scrollers && (pxmax > portx - 1)) {
4830 int length = (portx - top_x - 1);
4831 float ratio = ((float) length) / ((float) pxmax);
4833 lowend = (int) ((float) top_x + ((float) basex * ratio));
4834 highend = (int) ((float) top_x + ((float) (basex + length) * ratio));
4836 do_h_line(porty - 1, top_x, ACS_HLINE, lowend);
4837 if (highend < portx) {
4839 do_h_line(porty - 1, lowend, ' ', highend + 1);
4841 do_h_line(porty - 1, highend + 1, ACS_HLINE, portx);
4844 do_h_line(porty - 1, top_x, ACS_HLINE, portx);
4846 if (scrollers && (pymax > porty - 1)) {
4847 int length = (porty - top_y - 1);
4848 float ratio = ((float) length) / ((float) pymax);
4850 lowend = (int) ((float) top_y + ((float) basey * ratio));
4851 highend = (int) ((float) top_y + ((float) (basey + length) * ratio));
4853 do_v_line(top_y, portx - 1, ACS_VLINE, lowend);
4854 if (highend < porty) {
4856 do_v_line(lowend, portx - 1, ' ', highend + 1);
4858 do_v_line(highend + 1, portx - 1, ACS_VLINE, porty);
4861 do_v_line(top_y, portx - 1, ACS_VLINE, porty);
4863 mvaddch(top_y - 1, portx - 1, ACS_URCORNER);
4864 mvaddch(porty - 1, top_x - 1, ACS_LLCORNER);
4865 mvaddch(porty - 1, portx - 1, ACS_LRCORNER);
4868 #if HAVE_GETTIMEOFDAY
4869 gettimeofday(&before, 0);
4871 wnoutrefresh(stdscr);
4876 porty - (pxmax > portx) - 1,
4877 portx - (pymax > porty) - 1);
4880 #if HAVE_GETTIMEOFDAY
4883 gettimeofday(&after, 0);
4884 elapsed = (after.tv_sec + after.tv_usec / 1.0e6)
4885 - (before.tv_sec + before.tv_usec / 1.0e6);
4886 move(LINES - 1, COLS - 12);
4887 printw("Secs: %2.03f", elapsed);
4894 ((c = pgetc(pad)) != KEY_EXIT);
4896 scrollok(stdscr, TRUE); /* reset to driver's default */
4900 padgetch(WINDOW *win)
4906 if ((pending_pan = (count > 0)) != FALSE) {
4908 pending_pan = (count != 0);
4911 switch (c = wGetchar(win)) {
4947 case ERR: /* FALLTHRU */
4953 if (c >= '0' && c <= '9') {
4954 count = count * 10 + (c - '0');
4968 #define PAD_HIGH 200
4969 #define PAD_WIDE 200
4973 /* Demonstrate pads. */
4975 WINDOW *panpad = newpad(PAD_HIGH, PAD_WIDE);
4978 Cannot("cannot create requested pad");
4982 fill_pad(panpad, FALSE);
4984 panner_legend(LINES - 4);
4985 panner_legend(LINES - 3);
4986 panner_legend(LINES - 2);
4987 panner_legend(LINES - 1);
4989 keypad(panpad, TRUE);
4991 /* Make the pad (initially) narrow enough that a trace file won't wrap.
4992 * We'll still be able to widen it during a test, since that's required
4993 * for testing boundaries.
4995 panner(panpad, 2, 2, LINES - 5, COLS - 15, padgetch);
5002 /****************************************************************************
5004 * Tests from John Burnell's PDCurses tester
5006 ****************************************************************************/
5009 Continue(WINDOW *win)
5013 mvwaddstr(win, 10, 1, " Press any key to continue");
5019 flushinp_test(WINDOW *win)
5020 /* Input test, adapted from John Burnell's PDCurses tester */
5022 int w, h, bx, by, sw, sh, i;
5027 getmaxyx(win, h, w);
5028 getbegyx(win, by, bx);
5031 if ((subWin = subwin(win, sh, sw, by + h - sh - 2, bx + w - sw - 2)) == 0)
5036 init_pair(2, COLOR_CYAN, COLOR_BLUE);
5037 wbkgd(subWin, COLOR_PAIR(2) | ' ');
5040 wattrset(subWin, A_BOLD);
5041 box(subWin, ACS_VLINE, ACS_HLINE);
5042 mvwaddstr(subWin, 2, 1, "This is a subwindow");
5046 * This used to set 'nocbreak()'. However, Alexander Lukyanov says that
5047 * it only happened to "work" on SVr4 because that implementation does not
5048 * emulate nocbreak+noecho mode, whereas ncurses does. To get the desired
5049 * test behavior, we're using 'cbreak()', which will allow a single
5050 * character to return without needing a newline. - T.Dickey 1997/10/11.
5053 mvwaddstr(win, 0, 1, "This is a test of the flushinp() call.");
5055 mvwaddstr(win, 2, 1, "Type random keys for 5 seconds.");
5056 mvwaddstr(win, 3, 1,
5057 "These should be discarded (not echoed) after the subwindow goes away.");
5060 for (i = 0; i < 5; i++) {
5061 mvwprintw(subWin, 1, 1, "Time = %d", i);
5073 mvwaddstr(win, 2, 1,
5074 "If you were still typing when the window timer expired,");
5075 mvwaddstr(win, 3, 1,
5076 "or else you typed nothing at all while it was running,");
5077 mvwaddstr(win, 4, 1,
5078 "test was invalid. You'll see garbage or nothing at all. ");
5079 mvwaddstr(win, 6, 1, "Press a key");
5085 mvwaddstr(win, 12, 0,
5086 "If you see any key other than what you typed, flushinp() is broken.");
5095 "What you typed should now have been deleted; if not, wdelch() failed.");
5101 /****************************************************************************
5105 ****************************************************************************/
5113 menu_virtualize(int c)
5115 if (c == '\n' || c == KEY_EXIT)
5116 return (MAX_COMMAND + 1);
5118 return (REQ_SCR_ULINE);
5120 return (REQ_SCR_DLINE);
5121 else if (c == 'b' || c == KEY_NPAGE)
5122 return (REQ_SCR_UPAGE);
5123 else if (c == 'f' || c == KEY_PPAGE)
5124 return (REQ_SCR_DPAGE);
5125 else if (c == 'n' || c == KEY_DOWN)
5126 return (REQ_NEXT_ITEM);
5127 else if (c == 'p' || c == KEY_UP)
5128 return (REQ_PREV_ITEM);
5130 return (REQ_TOGGLE_ITEM);
5138 static CONST_MENUS char *animals[] =
5151 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5152 "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
5160 ITEM *items[SIZEOF(animals)];
5162 CONST_MENUS char **ap;
5163 int mrows, mcols, c;
5166 #ifdef NCURSES_MOUSE_VERSION
5167 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5169 mvaddstr(0, 0, "This is the menu test:");
5170 mvaddstr(2, 0, " Use up and down arrow to move the select bar.");
5171 mvaddstr(3, 0, " 'n' and 'p' act like arrows.");
5173 " 'b' and 'f' scroll up/down (page), 'u' and 'd' (line).");
5174 mvaddstr(5, 0, " Press return to exit.");
5177 for (ap = animals; *ap; ap++) {
5178 if ((*ip = new_item(*ap, "")) != 0)
5183 m = new_menu(items);
5185 set_menu_format(m, (SIZEOF(animals) + 1) / 2, 1);
5186 scale_menu(m, &mrows, &mcols);
5188 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5189 set_menu_win(m, menuwin);
5190 keypad(menuwin, TRUE);
5193 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5197 while ((c = menu_driver(m, menu_virtualize(wGetchar(menuwin)))) != E_UNKNOWN_COMMAND) {
5198 if (c == E_NOT_POSTED)
5200 if (c == E_REQUEST_DENIED)
5205 (void) mvprintw(LINES - 2, 0,
5206 "You chose: %s\n", item_name(current_item(m)));
5207 (void) addstr("Press any key to continue...");
5214 for (ip = items; *ip; ip++)
5216 #ifdef NCURSES_MOUSE_VERSION
5217 mousemask(0, (mmask_t *) 0);
5222 #define T_TBL(name) { #name, name }
5228 T_TBL(TRACE_DISABLE),
5231 T_TBL(TRACE_UPDATE),
5233 T_TBL(TRACE_CHARPUT),
5234 T_TBL(TRACE_ORDINARY),
5236 T_TBL(TRACE_VIRTPUT),
5237 T_TBL(TRACE_IEVENT),
5239 T_TBL(TRACE_ICALLS),
5240 T_TBL(TRACE_CCALLS),
5241 T_TBL(TRACE_DATABASE),
5243 T_TBL(TRACE_MAXIMUM),
5250 tracetrace(unsigned tlevel)
5257 for (n = 0; t_tbl[n].name != 0; n++)
5258 need += strlen(t_tbl[n].name) + 2;
5259 buf = typeMalloc(char, need);
5261 sprintf(buf, "0x%02x = {", tlevel);
5263 sprintf(buf + strlen(buf), "%s, ", t_tbl[0].name);
5265 for (n = 1; t_tbl[n].name != 0; n++)
5266 if ((tlevel & t_tbl[n].mask) == t_tbl[n].mask) {
5267 strcat(buf, t_tbl[n].name);
5271 if (buf[strlen(buf) - 2] == ',')
5272 buf[strlen(buf) - 2] = '\0';
5273 return (strcat(buf, "}"));
5276 /* fake a dynamically reconfigurable menu using the 0th entry to deselect
5280 run_trace_menu(MENU * m)
5286 bool changed = FALSE;
5287 switch (menu_driver(m, menu_virtualize(wGetchar(menu_win(m))))) {
5288 case E_UNKNOWN_COMMAND:
5291 items = menu_items(m);
5292 i = current_item(m);
5293 if (i == items[0]) {
5294 if (item_value(i)) {
5295 for (p = items + 1; *p != 0; p++)
5296 if (item_value(*p)) {
5297 set_item_value(*p, FALSE);
5302 for (p = items + 1; *p != 0; p++)
5303 if (item_value(*p)) {
5304 set_item_value(items[0], FALSE);
5317 /* interactively set the trace level */
5320 ITEM *items[SIZEOF(t_tbl)];
5327 mvaddstr(0, 0, "Interactively set trace level:");
5328 mvaddstr(2, 0, " Press space bar to toggle a selection.");
5329 mvaddstr(3, 0, " Use up and down arrow to move the select bar.");
5330 mvaddstr(4, 0, " Press return to set the trace level.");
5331 mvprintw(6, 0, "(Current trace level is %s)", tracetrace(_nc_tracing));
5335 for (n = 0; t_tbl[n].name != 0; n++) {
5336 if ((*ip = new_item(t_tbl[n].name, "")) != 0) {
5342 m = new_menu(items);
5344 set_menu_format(m, 0, 2);
5345 scale_menu(m, &mrows, &mcols);
5347 menu_opts_off(m, O_ONEVALUE);
5348 menuwin = newwin(mrows + 2, mcols + 2, MENU_Y, MENU_X);
5349 set_menu_win(m, menuwin);
5350 keypad(menuwin, TRUE);
5353 set_menu_sub(m, derwin(menuwin, mrows, mcols, 1, 1));
5357 for (ip = menu_items(m); *ip; ip++) {
5358 unsigned mask = t_tbl[item_index(*ip)].mask;
5360 set_item_value(*ip, _nc_tracing == 0);
5361 else if ((mask & _nc_tracing) == mask)
5362 set_item_value(*ip, TRUE);
5365 while (run_trace_menu(m))
5369 for (ip = menu_items(m); *ip; ip++)
5370 if (item_value(*ip))
5371 newtrace |= t_tbl[item_index(*ip)].mask;
5373 Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
5375 (void) mvprintw(LINES - 2, 0,
5376 "Trace level is %s\n", tracetrace(_nc_tracing));
5377 (void) addstr("Press any key to continue...");
5384 for (ip = items; *ip; ip++)
5388 #endif /* USE_LIBMENU */
5390 /****************************************************************************
5394 ****************************************************************************/
5397 make_label(int frow, int fcol, NCURSES_CONST char *label)
5399 FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
5402 set_field_buffer(f, 0, label);
5403 set_field_opts(f, (int) (field_opts(f) & ~O_ACTIVE));
5409 make_field(int frow, int fcol, int rows, int cols, bool secure)
5411 FIELD *f = new_field(rows, cols, frow, fcol, 0, secure ? 1 : 0);
5414 set_field_back(f, A_UNDERLINE);
5415 set_field_userptr(f, (void *) 0);
5421 display_form(FORM * f)
5426 scale_form(f, &rows, &cols);
5428 if ((w = newwin(rows + 2, cols + 4, 0, 0)) != (WINDOW *) 0) {
5430 set_form_sub(f, derwin(w, rows, cols, 1, 2));
5435 if (post_form(f) != E_OK)
5440 erase_form(FORM * f)
5442 WINDOW *w = form_win(f);
5443 WINDOW *s = form_sub(f);
5453 edit_secure(FIELD * me, int c)
5455 int rows, cols, frow, fcol, nrow, nbuf;
5457 if (field_info(me, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK
5459 char *source = field_buffer(me, 1);
5463 strcpy(temp, source ? source : "");
5464 len = (long) (char *) field_userptr(me);
5466 if (isgraph(c) && (len + 1) < (int) sizeof(temp)) {
5467 temp[len++] = (char) c;
5469 set_field_buffer(me, 1, temp);
5489 case REQ_RIGHT_CHAR:
5491 c = 0; /* we don't want to do inline editing */
5496 set_field_buffer(me, 1, temp);
5503 set_field_buffer(me, 1, temp);
5508 set_field_userptr(me, (void *) len);
5514 form_virtualize(FORM * f, WINDOW *w)
5517 static const struct {
5521 { CTRL('A'), REQ_NEXT_CHOICE },
5522 { CTRL('B'), REQ_PREV_WORD },
5523 { CTRL('C'), REQ_CLR_EOL },
5524 { CTRL('D'), REQ_DOWN_FIELD },
5525 { CTRL('E'), REQ_END_FIELD },
5526 { CTRL('F'), REQ_NEXT_PAGE },
5527 { CTRL('G'), REQ_DEL_WORD },
5528 { CTRL('H'), REQ_DEL_PREV },
5529 { CTRL('I'), REQ_INS_CHAR },
5530 { CTRL('K'), REQ_CLR_EOF },
5531 { CTRL('L'), REQ_LEFT_FIELD },
5532 { CTRL('M'), REQ_NEW_LINE },
5533 { CTRL('N'), REQ_NEXT_FIELD },
5534 { CTRL('O'), REQ_INS_LINE },
5535 { CTRL('P'), REQ_PREV_FIELD },
5536 { CTRL('R'), REQ_RIGHT_FIELD },
5537 { CTRL('S'), REQ_BEG_FIELD },
5538 { CTRL('U'), REQ_UP_FIELD },
5539 { CTRL('V'), REQ_DEL_CHAR },
5540 { CTRL('W'), REQ_NEXT_WORD },
5541 { CTRL('X'), REQ_CLR_FIELD },
5542 { CTRL('Y'), REQ_DEL_LINE },
5543 { CTRL('Z'), REQ_PREV_CHOICE },
5544 { ESCAPE, MAX_FORM_COMMAND + 1 },
5545 { KEY_BACKSPACE, REQ_DEL_PREV },
5546 { KEY_DOWN, REQ_DOWN_CHAR },
5547 { KEY_END, REQ_LAST_FIELD },
5548 { KEY_HOME, REQ_FIRST_FIELD },
5549 { KEY_LEFT, REQ_LEFT_CHAR },
5550 { KEY_LL, REQ_LAST_FIELD },
5551 { KEY_NEXT, REQ_NEXT_FIELD },
5552 { KEY_NPAGE, REQ_NEXT_PAGE },
5553 { KEY_PPAGE, REQ_PREV_PAGE },
5554 { KEY_PREVIOUS, REQ_PREV_FIELD },
5555 { KEY_RIGHT, REQ_RIGHT_CHAR },
5556 { KEY_UP, REQ_UP_CHAR },
5557 { QUIT, MAX_FORM_COMMAND + 1 }
5561 static int mode = REQ_INS_MODE;
5562 int c = wGetchar(w);
5564 FIELD *me = current_field(f);
5565 bool current = TRUE;
5567 if (c == CTRL(']')) {
5568 if (mode == REQ_INS_MODE) {
5569 mode = REQ_OVL_MODE;
5571 mode = REQ_INS_MODE;
5575 for (n = 0; n < SIZEOF(lookup); n++) {
5576 if (lookup[n].code == c) {
5577 c = lookup[n].result;
5582 mvprintw(0, COLS - 6, "(%s)", mode == REQ_INS_MODE ? "INS" : "OVL");
5585 * Force the field that the user is typing into to be in reverse video,
5586 * while the other fields are shown underlined.
5601 case REQ_LEFT_FIELD:
5603 case REQ_RIGHT_CHAR:
5607 current = (c < KEY_MAX);
5611 c = edit_secure(me, c);
5612 set_field_back(me, A_REVERSE);
5614 c = edit_secure(me, c);
5615 set_field_back(me, A_UNDERLINE);
5621 my_form_driver(FORM * form, int c)
5623 if (c == (MAX_FORM_COMMAND + 1)
5624 && form_driver(form, REQ_VALIDATION) == E_OK)
5632 #ifdef NCURSES_VERSION
5633 #define FIELDCHECK_CB(func) bool func(FIELD * fld, const void * data GCC_UNUSED)
5634 #define CHAR_CHECK_CB(func) bool func(int ch, const void *data GCC_UNUSED)
5636 #define FIELDCHECK_CB(func) int func(FIELD * fld, char * data GCC_UNUSED)
5637 #define CHAR_CHECK_CB(func) int func(int ch, char *data GCC_UNUSED)
5641 * Allow a middle initial, optionally with a '.' to end it.
5644 FIELDCHECK_CB(mi_field_check)
5646 char *s = field_buffer(fld, 0);
5650 for (n = 0; s[n] != '\0'; ++n) {
5657 } else if (isspace(UChar(s[n]))) {
5662 if (!isspace(UChar(s[n])))
5668 /* force the form to display a leading capital */
5669 if (islower(UChar(s[0]))) {
5670 s[0] = (char) toupper(UChar(s[0]));
5671 set_field_buffer(fld, 0, s);
5677 CHAR_CHECK_CB(mi_char_check)
5679 return ((isalpha(ch) || ch == '.') ? TRUE : FALSE);
5683 * Passwords should be at least 6 characters.
5686 FIELDCHECK_CB(pw_field_check)
5688 char *s = field_buffer(fld, 0);
5691 for (n = 0; s[n] != '\0'; ++n) {
5692 if (isspace(UChar(s[n]))) {
5701 CHAR_CHECK_CB(pw_char_check)
5703 return (isgraph(ch) ? TRUE : FALSE);
5711 FIELD *f[12], *secure;
5712 FIELDTYPE *fty_middle = new_fieldtype(mi_field_check, mi_char_check);
5713 FIELDTYPE *fty_passwd = new_fieldtype(pw_field_check, pw_char_check);
5714 int finished = 0, c;
5717 #ifdef NCURSES_MOUSE_VERSION
5718 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5722 addstr("Defined edit/traversal keys: ^Q/ESC- exit form\n");
5723 addstr("^N -- go to next field ^P -- go to previous field\n");
5724 addstr("Home -- go to first field End -- go to last field\n");
5725 addstr("^L -- go to field to left ^R -- go to field to right\n");
5726 addstr("^U -- move upward to field ^D -- move downward to field\n");
5727 addstr("^W -- go to next word ^B -- go to previous word\n");
5728 addstr("^S -- go to start of field ^E -- go to end of field\n");
5729 addstr("^H -- delete previous char ^Y -- delete line\n");
5730 addstr("^G -- delete current word ^C -- clear to end of line\n");
5731 addstr("^K -- clear to end of field ^X -- clear field\n");
5732 addstr("Arrow keys move within a field as you would expect. ^] toggles overlay mode.");
5734 mvaddstr(4, 57, "Forms Entry Test");
5738 /* describe the form */
5739 memset(f, 0, sizeof(f));
5740 f[n++] = make_label(0, 15, "Sample Form");
5742 f[n++] = make_label(2, 0, "Last Name");
5743 f[n++] = make_field(3, 0, 1, 18, FALSE);
5744 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5746 f[n++] = make_label(2, 20, "First Name");
5747 f[n++] = make_field(3, 20, 1, 12, FALSE);
5748 set_field_type(f[n - 1], TYPE_ALPHA, 1);
5750 f[n++] = make_label(2, 34, "Middle Name");
5751 f[n++] = make_field(3, 34, 1, 12, FALSE);
5752 set_field_type(f[n - 1], fty_middle);
5754 f[n++] = make_label(5, 0, "Comments");
5755 f[n++] = make_field(6, 0, 4, 46, FALSE);
5757 f[n++] = make_label(5, 20, "Password:");
5759 f[n++] = make_field(5, 30, 1, 9, TRUE);
5760 set_field_type(f[n - 1], fty_passwd);
5761 f[n++] = (FIELD *) 0;
5763 if ((form = new_form(f)) != 0) {
5769 nonl(); /* lets us read ^M's */
5771 switch (form_driver(form, c = form_virtualize(form, w))) {
5773 mvaddstr(5, 57, field_buffer(secure, 1));
5777 case E_UNKNOWN_COMMAND:
5778 finished = my_form_driver(form, c);
5790 for (c = 0; f[c] != 0; c++)
5792 free_fieldtype(fty_middle);
5793 free_fieldtype(fty_passwd);
5797 #ifdef NCURSES_MOUSE_VERSION
5798 mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
5801 #endif /* USE_LIBFORM */
5803 /****************************************************************************
5807 ****************************************************************************/
5810 fillwin(WINDOW *win, char ch)
5815 getmaxyx(win, y1, x1);
5816 for (y = 0; y < y1; y++) {
5818 for (x = 0; x < x1; x++)
5819 waddch(win, UChar(ch));
5824 crosswin(WINDOW *win, char ch)
5829 getmaxyx(win, y1, x1);
5830 for (y = 0; y < y1; y++) {
5831 for (x = 0; x < x1; x++)
5832 if (((x > (x1 - 1) / 3) && (x <= (2 * (x1 - 1)) / 3))
5833 || (((y > (y1 - 1) / 3) && (y <= (2 * (y1 - 1)) / 3)))) {
5835 waddch(win, UChar(ch));
5840 #define OVERLAP_FLAVORS 5
5843 overlap_helpitem(int state, int item, char *message)
5845 int row = (item / 2);
5846 int col = ((item % 2) ? COLS / 2 : 0);
5848 move(LINES - 6 + row, col);
5849 printw("%c%c = %s", state == row ? '>' : ' ', 'a' + item, message);
5854 overlap_test_1_attr(WINDOW *win, int flavor, int col)
5856 short cpair = (short) (1 + (flavor * 2) + col);
5860 wattrset(win, A_NORMAL);
5863 wattrset(win, A_BOLD);
5866 init_pair(cpair, COLOR_BLUE, COLOR_WHITE);
5867 wattrset(win, COLOR_PAIR(cpair) | A_NORMAL);
5870 init_pair(cpair, COLOR_WHITE, COLOR_BLUE);
5871 wattrset(win, COLOR_PAIR(cpair) | A_BOLD);
5877 overlap_test_2_attr(WINDOW *win, int flavor, int col)
5879 short cpair = (short) (9 + (flavor * 2) + col);
5889 init_pair(cpair, COLOR_RED, COLOR_GREEN);
5890 wbkgdset(win, colored_chtype(' ', A_BLINK, cpair));
5893 wbkgdset(win, ' ' | A_NORMAL);
5899 overlap_help(int state, int flavors[OVERLAP_FLAVORS])
5904 const char *ths, *tht;
5908 state += OVERLAP_FLAVORS;
5909 state = state % OVERLAP_FLAVORS;
5910 assert(state >= 0 && state < OVERLAP_FLAVORS);
5912 for (item = 0; item < (2 * OVERLAP_FLAVORS); ++item) {
5915 ths = col ? "B" : "A";
5916 tht = col ? "A" : "B";
5921 sprintf(msg, "refresh %s, then %s, then doupdate.", ths, tht);
5929 overlap_test_1_attr(stdscr, flavors[row], col);
5930 sprintf(msg, "fill window %s with letter %s.", ths, ths);
5938 switch (flavors[row]) {
5940 sprintf(msg, "cross pattern in window %s.", ths);
5943 sprintf(msg, "draw box in window %s.", ths);
5946 sprintf(msg, "set background of window %s.", ths);
5949 sprintf(msg, "reset background of window %s.", ths);
5955 sprintf(msg, "clear window %s.", ths);
5959 switch (flavors[row]) {
5961 sprintf(msg, "overwrite %s onto %s.", ths, tht);
5964 sprintf(msg, "copywin(FALSE) %s onto %s.", ths, tht);
5967 sprintf(msg, "copywin(TRUE) %s onto %s.", ths, tht);
5970 sprintf(msg, "overlay %s onto %s.", ths, tht);
5975 overlap_helpitem(state, item, msg);
5976 wattrset(stdscr, A_NORMAL);
5977 wbkgdset(stdscr, ' ' | A_NORMAL);
5980 printw("^Q/ESC = terminate test. Up/down/space select test variations (%d %d).",
5981 state, flavors[state]);
5987 overlap_test_0(WINDOW *a, WINDOW *b)
5997 overlap_test_1(int flavor, int col, WINDOW *a, char fill)
5999 overlap_test_1_attr(a, flavor, col);
6001 wattrset(a, A_NORMAL);
6005 overlap_test_2(int flavor, int col, WINDOW *a, char fill)
6007 overlap_test_2_attr(a, flavor, col);
6016 /* done in overlap_test_2_attr */
6019 /* done in overlap_test_2_attr */
6025 overlap_test_3(WINDOW *a)
6032 overlap_test_4(int flavor, WINDOW *a, WINDOW *b)
6039 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), FALSE);
6042 copywin(a, b, 0, 0, 0, 0, getmaxy(b), getmaxx(b), TRUE);
6050 /* test effects of overlapping windows */
6055 int state, flavor[OVERLAP_FLAVORS];
6057 WINDOW *win1 = newwin(9, 20, 3, 3);
6058 WINDOW *win2 = newwin(9, 20, 9, 16);
6064 printw("This test shows the behavior of wnoutrefresh() with respect to\n");
6065 printw("the shared region of two overlapping windows A and B. The cross\n");
6066 printw("pattern in each window does not overlap the other.\n");
6068 memset(flavor, 0, sizeof(flavor));
6069 state = overlap_help(0, flavor);
6071 while (!isQuit(ch = Getchar()))
6073 case 'a': /* refresh window A first, then B */
6074 overlap_test_0(win1, win2);
6077 case 'b': /* refresh window B first, then A */
6078 overlap_test_0(win2, win1);
6081 case 'c': /* fill window A so it's visible */
6082 overlap_test_1(flavor[1], 0, win1, 'A');
6085 case 'd': /* fill window B so it's visible */
6086 overlap_test_1(flavor[1], 1, win2, 'B');
6089 case 'e': /* cross test pattern in window A */
6090 overlap_test_2(flavor[2], 0, win1, 'A');
6093 case 'f': /* cross test pattern in window A */
6094 overlap_test_2(flavor[2], 1, win2, 'B');
6097 case 'g': /* clear window A */
6098 overlap_test_3(win1);
6101 case 'h': /* clear window B */
6102 overlap_test_3(win2);
6105 case 'i': /* overwrite A onto B */
6106 overlap_test_4(flavor[4], win1, win2);
6109 case 'j': /* overwrite B onto A */
6110 overlap_test_4(flavor[4], win2, win1);
6115 state = overlap_help(state + 1, flavor);
6120 state = overlap_help(state - 1, flavor);
6125 state = overlap_help(state, flavor);
6129 state = overlap_help(state, flavor);
6144 /****************************************************************************
6148 ****************************************************************************/
6151 do_single_test(const char c)
6152 /* perform a single specified test */
6159 #if USE_WIDEC_SUPPORT
6169 #if USE_WIDEC_SUPPORT
6177 Cannot("does not support color.");
6182 #if USE_WIDEC_SUPPORT
6185 Cannot("does not support color.");
6193 Cannot("does not support color.");
6194 else if (!can_change_color())
6195 Cannot("has hardwired color values.");
6206 #if USE_WIDEC_SUPPORT
6215 #if USE_WIDEC_SUPPORT
6223 demo_panels(init_panel, fill_panel);
6227 #if USE_WIDEC_SUPPORT && USE_LIBPANEL
6229 demo_panels(init_wide_panel, fill_wide_panel);
6238 flushinp_test(stdscr);
6242 test_sgr_attributes();
6265 #if USE_LIBMENU && defined(TRACE)
6284 static const char *const tbl[] =
6286 "Usage: ncurses [options]"
6289 #ifdef NCURSES_VERSION
6290 ," -a f,b set default-colors (assumed white-on-black)"
6291 ," -d use default-colors if terminal supports them"
6294 ," -e fmt specify format for soft-keys test (e)"
6297 ," -f rip-off footer line (can repeat)"
6298 ," -h rip-off header line (can repeat)"
6300 ," -m do not use colors"
6301 ," -p file rgb values to use in 'd' rather than ncurses's builtin"
6303 ," -s msec specify nominal time for panel-demo (default: 1, to hold)"
6306 ," -t mask specify default trace-level (may toggle with ^T)"
6310 for (n = 0; n < SIZEOF(tbl); n++)
6311 fprintf(stderr, "%s\n", tbl[n]);
6312 ExitProgram(EXIT_FAILURE);
6316 set_terminal_modes(void)
6321 scrollok(stdscr, TRUE);
6322 idlok(stdscr, TRUE);
6323 keypad(stdscr, TRUE);
6328 announce_sig(int sig)
6330 (void) fprintf(stderr, "Handled signal %d\r\n", sig);
6336 rip_footer(WINDOW *win, int cols)
6338 wbkgd(win, A_REVERSE);
6341 wprintw(win, "footer: window %p, %d columns", win, cols);
6347 rip_header(WINDOW *win, int cols)
6349 wbkgd(win, A_REVERSE);
6352 wprintw(win, "header: window %p, %d columns", win, cols);
6356 #endif /* HAVE_RIPOFFLINE */
6364 (void) puts("This is the ncurses main menu");
6365 (void) puts("a = keyboard and mouse input test");
6366 #if USE_WIDEC_SUPPORT
6367 (void) puts("A = wide-character keyboard and mouse input test");
6369 (void) puts("b = character attribute test");
6370 #if USE_WIDEC_SUPPORT
6371 (void) puts("B = wide-character attribute test");
6373 (void) puts("c = color test pattern");
6374 #if USE_WIDEC_SUPPORT
6375 (void) puts("C = color test pattern using wide-character calls");
6378 (void) puts("d = edit RGB color values");
6380 (void) puts("e = exercise soft keys");
6381 #if USE_WIDEC_SUPPORT
6382 (void) puts("E = exercise soft keys using wide-characters");
6385 (void) puts("f = display ACS characters");
6386 #if USE_WIDEC_SUPPORT
6387 (void) puts("F = display Wide-ACS characters");
6389 (void) puts("g = display windows and scrolling");
6390 (void) puts("i = test of flushinp()");
6391 (void) puts("k = display character attributes");
6393 (void) puts("m = menu code test");
6396 (void) puts("o = exercise panels library");
6397 #if USE_WIDEC_SUPPORT
6398 (void) puts("O = exercise panels with wide-characters");
6401 (void) puts("p = exercise pad features");
6402 (void) puts("q = quit");
6404 (void) puts("r = exercise forms code");
6406 (void) puts("s = overlapping-refresh test");
6407 #if USE_LIBMENU && defined(TRACE)
6408 (void) puts("t = set trace level");
6410 (void) puts("? = repeat this command summary");
6412 (void) fputs("> ", stdout);
6413 (void) fflush(stdout); /* necessary under SVr4 curses */
6416 * This used to be an 'fgets()' call. However (on Linux, at least)
6417 * mixing stream I/O and 'read()' (used in the library) causes the
6418 * input stream to be flushed when switching between the two.
6423 if (read(fileno(stdin), &ch, 1) <= 0) {
6427 } else if (command == 0 && !isspace(UChar(ch))) {
6429 } else if (ch == '\n' || ch == '\r') {
6430 if ((command == 'd') && !top) {
6431 (void) fputs("Do not nest test-d\n", stdout);
6436 (void) fputs("> ", stdout);
6437 (void) fflush(stdout);
6441 if (do_single_test(command)) {
6443 * This may be overkill; it's intended to reset everything back
6444 * to the initial terminal modes so that tests don't get in
6448 set_terminal_modes();
6453 if (command == '?') {
6454 (void) puts("This is the ncurses capability tester.");
6456 puts("You may select a test from the main menu by typing the");
6458 puts("key letter of the choice (the letter to left of the =)");
6460 puts("at the > prompt. Type `q' to exit.");
6468 /*+-------------------------------------------------------------------------
6470 --------------------------------------------------------------------------*/
6472 #define okCOLOR(n) ((n) >= 0 && (n) < max_colors)
6473 #define okRGB(n) ((n) >= 0 && (n) <= 1000)
6476 main(int argc, char *argv[])
6480 #ifdef NCURSES_VERSION
6481 int default_fg = COLOR_WHITE;
6482 int default_bg = COLOR_BLACK;
6483 bool assumed_colors = FALSE;
6484 bool default_colors = FALSE;
6486 char *palette_file = 0;
6487 bool monochrome = FALSE;
6489 setlocale(LC_ALL, "");
6491 while ((c = getopt(argc, argv, "a:de:fhmp:s:t:")) != -1) {
6493 #ifdef NCURSES_VERSION
6495 assumed_colors = TRUE;
6496 sscanf(optarg, "%d,%d", &default_fg, &default_bg);
6499 default_colors = TRUE;
6503 my_e_param = atoi(optarg);
6504 #ifdef NCURSES_VERSION
6505 if (my_e_param > 3) /* allow extended layouts */
6514 ripoffline(-1, rip_footer);
6517 ripoffline(1, rip_header);
6519 #endif /* HAVE_RIPOFFLINE */
6524 palette_file = optarg;
6528 nap_msec = atol(optarg);
6533 save_trace = (unsigned) strtol(optarg, 0, 0);
6542 * If there's no menus (unlikely for ncurses!), then we'll have to set
6543 * tracing on initially, just in case the user wants to test something that
6544 * doesn't involve wGetchar.
6547 /* enable debugging */
6551 if (!isatty(fileno(stdin)))
6553 #endif /* USE_LIBMENU */
6557 /* tell it we're going to play with soft keys */
6558 slk_init(my_e_param);
6562 /* set up null signal catcher so we can see what interrupts to getch do */
6563 signal(SIGUSR1, announce_sig);
6566 /* we must initialize the curses data structure only once */
6570 /* tests, in general, will want these modes */
6571 use_colors = monochrome ? FALSE : has_colors();
6575 #ifdef NCURSES_VERSION_PATCH
6576 max_colors = COLORS; /* was > 16 ? 16 : COLORS */
6577 #if HAVE_USE_DEFAULT_COLORS
6578 if (default_colors) {
6579 use_default_colors();
6582 #if NCURSES_VERSION_PATCH >= 20000708
6583 else if (assumed_colors)
6584 assume_default_colors(default_fg, default_bg);
6587 #else /* normal SVr4 curses */
6588 max_colors = COLORS; /* was > 8 ? 8 : COLORS */
6590 max_pairs = COLOR_PAIRS; /* was > 256 ? 256 : COLOR_PAIRS */
6592 if (can_change_color()) {
6594 all_colors = typeMalloc(RGB_DATA, (unsigned) max_colors);
6595 for (cp = 0; cp < max_colors; ++cp) {
6597 &all_colors[cp].red,
6598 &all_colors[cp].green,
6599 &all_colors[cp].blue);
6601 if (palette_file != 0) {
6602 FILE *fp = fopen(palette_file, "r");
6604 char buffer[BUFSIZ];
6605 int red, green, blue;
6607 while (fgets(buffer, sizeof(buffer), fp) != 0) {
6608 if (sscanf(buffer, "scale:%d", &c) == 1) {
6610 } else if (sscanf(buffer, "%d:%d %d %d",
6619 all_colors[c].red = (short) ((red * 1000) / scale);
6620 all_colors[c].green = (short) ((green * 1000) / scale);
6621 all_colors[c].blue = (short) ((blue * 1000) / scale);
6629 set_terminal_modes();
6633 * Return to terminal mode, so we're guaranteed of being able to
6634 * select terminal commands even if the capabilities are wrong.
6638 #if HAVE_CURSES_VERSION
6639 (void) printf("Welcome to %s. Press ? for help.\n", curses_version());
6640 #elif defined(NCURSES_VERSION_MAJOR) && defined(NCURSES_VERSION_MINOR) && defined(NCURSES_VERSION_PATCH)
6641 (void) printf("Welcome to ncurses %d.%d.%d. Press ? for help.\n",
6642 NCURSES_VERSION_MAJOR,
6643 NCURSES_VERSION_MINOR,
6644 NCURSES_VERSION_PATCH);
6646 (void) puts("Welcome to ncurses. Press ? for help.");
6651 ExitProgram(EXIT_SUCCESS);
6654 /* ncurses.c ends here */